Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugging threaded perl hangs with perl-5.20.2 #14626

Closed
p5pRT opened this issue Mar 28, 2015 · 23 comments
Closed

debugging threaded perl hangs with perl-5.20.2 #14626

p5pRT opened this issue Mar 28, 2015 · 23 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 28, 2015

Migrated from rt.perl.org#124203 (status was 'resolved')

Searchable as RT124203$

@p5pRT
Copy link
Author

p5pRT commented Mar 28, 2015

From @mblanche

Since switching to perl v >5.18, I'have been having lots of issue with the debugger. Debugging a simple program like

use threads;
my $thr = threads->create(\&sub1);
sub sub1 {
  print("In the thread\n");
}

Using perl -dt hangs for ever, only way is to kill the terminal. I am currently running with perl 5.20.2 using Mac OS X 10.10.2.

I think this is a bug, if not, help would be aprreciated

Marco

$ perl -V
Summary of my perl5 (revision 5 version 20 subversion 2) configuration​:
 
  Platform​:
  osname=darwin, osvers=14.1.0, archname=darwin-2level
  uname='darwin macbookpro.local 14.1.0 darwin kernel version 14.1.0​: thu feb 26 19​:26​:47 pst 2015; root​:xnu-2782.10.73~1release_x86_64 x86_64 '
  config_args='-de -Dprefix=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2 -Aeval​:scriptdir=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib /usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Characteristics of this binary (from libperl)​:
  Compile-time options​: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
  PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_MALLOC_WRAP
  PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV
  USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES
  USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
  USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
  Locally applied patches​:
  Devel​::PatchPerl 1.30
  Built under darwin
  Compiled at Mar 28 2015 11​:36​:50
  %ENV​:
  PERLBREW_BASHRC_VERSION="0.73"
  PERLBREW_HOME="/Users/marcoblanchette/.perlbrew"
  PERLBREW_MANPATH="/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/man"
  PERLBREW_PATH="/Users/marcoblanchette/perl5/perlbrew/bin​:/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/bin"
  PERLBREW_PERL="perl-5.20.2"
  PERLBREW_ROOT="/Users/marcoblanchette/perl5/perlbrew"
  PERLBREW_VERSION="0.73"
  @​INC​:
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/lib/site_perl/5.20.2/darwin-2level
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/lib/site_perl/5.20.2
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/lib/5.20.2/darwin-2level
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/lib/5.20.2
  .

@p5pRT
Copy link
Author

p5pRT commented Mar 28, 2015

From @mblanche

On Sat Mar 28 12​:08​:05 2015, marcoblanchette@​icloud.com wrote​:

Since switching to perl v >5.18, I'have been having lots of issue with
the debugger. Debugging a simple program like

use threads;
my $thr = threads->create(\&sub1);
sub sub1 {
print("In the thread\n");
}

Using perl -dt hangs for ever, only way is to kill the terminal. I am
currently running with perl 5.20.2 using Mac OS X 10.10.2.

I think this is a bug, if not, help would be aprreciated

Marco

$ perl -V
Summary of my perl5 (revision 5 version 20 subversion 2)
configuration​:

Platform​:
osname=darwin, osvers=14.1.0, archname=darwin-2level
uname='darwin macbookpro.local 14.1.0 darwin kernel version 14.1.0​:
thu feb 26 19​:26​:47 pst 2015; root​:xnu-2782.10.73~1release_x86_64
x86_64 '
config_args='-de
-Dprefix=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2
-Aeval​:scriptdir=/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/bin'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing
-pipe -fstack-protector -I/usr/local/include',
optimize='-O3',
cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-
600.0.57)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-
protector -L/usr/local/lib'
libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib
/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lutil -lc
perllibs=-ldl -lm -lutil -lc
libc=, so=dylib, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup
-L/usr/local/lib -fstack-protector'

Characteristics of this binary (from libperl)​:
Compile-time options​: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
PERL_MALLOC_WRAP
PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV
USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES
USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
Locally applied patches​:
Devel​::PatchPerl 1.30
Built under darwin
Compiled at Mar 28 2015 11​:36​:50
%ENV​:
PERLBREW_BASHRC_VERSION="0.73"
PERLBREW_HOME="/Users/marcoblanchette/.perlbrew"
PERLBREW_MANPATH="/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/man"
PERLBREW_PATH="/Users/marcoblanchette/perl5/perlbrew/bin​:/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/bin"
PERLBREW_PERL="perl-5.20.2"
PERLBREW_ROOT="/Users/marcoblanchette/perl5/perlbrew"
PERLBREW_VERSION="0.73"
@​INC​:
/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/lib/site_perl/5.20.2/darwin-2level
/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/lib/site_perl/5.20.2
/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/lib/5.20.2/darwin-2level
/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/lib/5.20.2
.

Sorry, pasted the wrong output of perl -V (testing different config of perl using perlbrew...)

here is the current multi-thread I used

$ perl -V
Summary of my perl5 (revision 5 version 20 subversion 2) configuration​:
 
  Platform​:
  osname=darwin, osvers=14.1.0, archname=darwin-thread-multi-2level
  uname='darwin macbookpro.local 14.1.0 darwin kernel version 14.1.0​: thu feb 26 19​:26​:47 pst 2015; root​:xnu-2782.10.73~1release_x86_64 x86_64 '
  config_args='-de -Dprefix=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi -Dusethreads -Dusemultiplicity -Aeval​:scriptdir=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib /usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Characteristics of this binary (from libperl)​:
  Compile-time options​: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
  PERL_DONT_CREATE_GVSV
  PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
  PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
  PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV
  USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS
  USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE
  USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO
  USE_PERL_ATOF USE_REENTRANT_API
  Locally applied patches​:
  Devel​::PatchPerl 1.30
  Built under darwin
  Compiled at Mar 28 2015 11​:30​:36
  %ENV​:
  PERLBREW_BASHRC_VERSION="0.73"
  PERLBREW_HOME="/Users/marcoblanchette/.perlbrew"
  PERLBREW_MANPATH="/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/man"
  PERLBREW_PATH="/Users/marcoblanchette/perl5/perlbrew/bin​:/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/bin"
  PERLBREW_PERL="perl-5.20.2-thread-multi"
  PERLBREW_ROOT="/Users/marcoblanchette/perl5/perlbrew"
  PERLBREW_VERSION="0.73"
  @​INC​:
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/site_perl/5.20.2/darwin-thread-multi-2level
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/site_perl/5.20.2
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/5.20.2/darwin-thread-multi-2level
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/5.20.2
  .

@p5pRT
Copy link
Author

p5pRT commented Mar 28, 2015

From [Unknown Contact. See original ticket]

On Sat Mar 28 12​:08​:05 2015, marcoblanchette@​icloud.com wrote​:

Since switching to perl v >5.18, I'have been having lots of issue with
the debugger. Debugging a simple program like

use threads;
my $thr = threads->create(\&sub1);
sub sub1 {
print("In the thread\n");
}

Using perl -dt hangs for ever, only way is to kill the terminal. I am
currently running with perl 5.20.2 using Mac OS X 10.10.2.

I think this is a bug, if not, help would be aprreciated

Marco

$ perl -V
Summary of my perl5 (revision 5 version 20 subversion 2)
configuration​:

Platform​:
osname=darwin, osvers=14.1.0, archname=darwin-2level
uname='darwin macbookpro.local 14.1.0 darwin kernel version 14.1.0​:
thu feb 26 19​:26​:47 pst 2015; root​:xnu-2782.10.73~1release_x86_64
x86_64 '
config_args='-de
-Dprefix=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2
-Aeval​:scriptdir=/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/bin'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing
-pipe -fstack-protector -I/usr/local/include',
optimize='-O3',
cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-
600.0.57)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-
protector -L/usr/local/lib'
libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib
/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lutil -lc
perllibs=-ldl -lm -lutil -lc
libc=, so=dylib, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup
-L/usr/local/lib -fstack-protector'

Characteristics of this binary (from libperl)​:
Compile-time options​: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
PERL_MALLOC_WRAP
PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV
USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES
USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
Locally applied patches​:
Devel​::PatchPerl 1.30
Built under darwin
Compiled at Mar 28 2015 11​:36​:50
%ENV​:
PERLBREW_BASHRC_VERSION="0.73"
PERLBREW_HOME="/Users/marcoblanchette/.perlbrew"
PERLBREW_MANPATH="/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/man"
PERLBREW_PATH="/Users/marcoblanchette/perl5/perlbrew/bin​:/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/bin"
PERLBREW_PERL="perl-5.20.2"
PERLBREW_ROOT="/Users/marcoblanchette/perl5/perlbrew"
PERLBREW_VERSION="0.73"
@​INC​:
/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/lib/site_perl/5.20.2/darwin-2level
/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/lib/site_perl/5.20.2
/Users/marcoblanchette/perl5/perlbrew/perls/perl-
5.20.2/lib/5.20.2/darwin-2level
/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2/lib/5.20.2
.

Sorry, pasted the wrong output of perl -V (testing different config of perl using perlbrew...)

here is the current multi-thread I used

$ perl -V
Summary of my perl5 (revision 5 version 20 subversion 2) configuration​:
 
  Platform​:
  osname=darwin, osvers=14.1.0, archname=darwin-thread-multi-2level
  uname='darwin macbookpro.local 14.1.0 darwin kernel version 14.1.0​: thu feb 26 19​:26​:47 pst 2015; root​:xnu-2782.10.73~1release_x86_64 x86_64 '
  config_args='-de -Dprefix=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi -Dusethreads -Dusemultiplicity -Aeval​:scriptdir=/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib /usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Characteristics of this binary (from libperl)​:
  Compile-time options​: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
  PERL_DONT_CREATE_GVSV
  PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
  PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
  PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV
  USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS
  USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE
  USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO
  USE_PERL_ATOF USE_REENTRANT_API
  Locally applied patches​:
  Devel​::PatchPerl 1.30
  Built under darwin
  Compiled at Mar 28 2015 11​:30​:36
  %ENV​:
  PERLBREW_BASHRC_VERSION="0.73"
  PERLBREW_HOME="/Users/marcoblanchette/.perlbrew"
  PERLBREW_MANPATH="/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/man"
  PERLBREW_PATH="/Users/marcoblanchette/perl5/perlbrew/bin​:/Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/bin"
  PERLBREW_PERL="perl-5.20.2-thread-multi"
  PERLBREW_ROOT="/Users/marcoblanchette/perl5/perlbrew"
  PERLBREW_VERSION="0.73"
  @​INC​:
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/site_perl/5.20.2/darwin-thread-multi-2level
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/site_perl/5.20.2
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/5.20.2/darwin-thread-multi-2level
  /Users/marcoblanchette/perl5/perlbrew/perls/perl-5.20.2-thread-multi/lib/5.20.2
  .

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

From @jkeenan

On Sat Mar 28 12​:12​:59 2015, marcoblanchette@​icloud.com wrote​:

On Sat Mar 28 12​:08​:05 2015, marcoblanchette@​icloud.com wrote​:

Since switching to perl v >5.18, I'have been having lots of issue
with
the debugger. Debugging a simple program like

use threads;
my $thr = threads->create(\&sub1);
sub sub1 {
print("In the thread\n");
}

Using perl -dt hangs for ever, only way is to kill the terminal. I am
currently running with perl 5.20.2 using Mac OS X 10.10.2.

I think this is a bug, if not, help would be aprreciated

Marco

This sounds a lot like https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

From @khwilliamson

On 03/28/2015 08​:00 PM, James E Keenan via RT wrote​:

On Sat Mar 28 12​:12​:59 2015, marcoblanchette@​icloud.com wrote​:

On Sat Mar 28 12​:08​:05 2015, marcoblanchette@​icloud.com wrote​:

Since switching to perl v >5.18, I'have been having lots of issue
with
the debugger. Debugging a simple program like

use threads;
my $thr = threads->create(\&sub1);
sub sub1 {
print("In the thread\n");
}

Using perl -dt hangs for ever, only way is to kill the terminal. I am
currently running with perl 5.20.2 using Mac OS X 10.10.2.

I think this is a bug, if not, help would be aprreciated

Marco

This sounds a lot like https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127

And since that ticket has a patch, the requester here could apply it and
see if it solves his problem.

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

From vega.james@gmail.com

On Sat, Mar 28, 2015 at 07​:00​:16PM -0700, James E Keenan via RT wrote​:

On Sat Mar 28 12​:12​:59 2015, marcoblanchette@​icloud.com wrote​:

On Sat Mar 28 12​:08​:05 2015, marcoblanchette@​icloud.com wrote​:

Since switching to perl v >5.18, I'have been having lots of issue
with
the debugger. Debugging a simple program like

use threads;
my $thr = threads->create(\&sub1);
sub sub1 {
print("In the thread\n");
}

Using perl -dt hangs for ever, only way is to kill the terminal. I am
currently running with perl 5.20.2 using Mac OS X 10.10.2.

I think this is a bug, if not, help would be aprreciated

Marco

This sounds a lot like https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127

Well, the fact that "perl -dt" hangs has existed for a long time. I've
seen that at least as far back as 5.10 (and it's previously been
reported in #120170).

It was just made more apparent by "perl -d" not working with threaded
programs in 5.18.

Cheers,
--
James
GPG Key​: 4096R/331BA3DB 2011-12-05 James McCoy <vega.james@​gmail.com>

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

From @mblanche

Thank you guys, patch from https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127 worked for me. Now, perl -d work fine and entering a thread does not hang the process.

Is this patch expected to make it to a stable release soon?

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

From @mblanche

On Sun Mar 29 09​:16​:39 2015, marcoblanchette@​icloud.com wrote​:

Thank you guys, patch from
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127 worked for me. Now,
perl -d work fine and entering a thread does not hang the process.

Is this patch expected to make it to a stable release soon?

I talked to fast. The patches fix the perl -d to complain but introduces a weird behavior in my environment, using 'n' in the debugger does not step to the next step but roll over the full script, it acts like 'c'...

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2015

From [Unknown Contact. See original ticket]

On Sun Mar 29 09​:16​:39 2015, marcoblanchette@​icloud.com wrote​:

Thank you guys, patch from
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127 worked for me. Now,
perl -d work fine and entering a thread does not hang the process.

Is this patch expected to make it to a stable release soon?

I talked to fast. The patches fix the perl -d to complain but introduces a weird behavior in my environment, using 'n' in the debugger does not step to the next step but roll over the full script, it acts like 'c'...

@p5pRT
Copy link
Author

p5pRT commented Mar 30, 2015

From vega.james@gmail.com

On Sun, Mar 29, 2015 at 09​:42​:18AM -0700, Marco Blanchette via RT wrote​:

On Sun Mar 29 09​:16​:39 2015, marcoblanchette@​icloud.com wrote​:

Thank you guys, patch from
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124127 worked for me. Now,
perl -d work fine and entering a thread does not hang the process.

Is this patch expected to make it to a stable release soon?

I talked to fast. The patches fix the perl -d to complain but
introduces a weird behavior in my environment, using 'n' in the
debugger does not step to the next step but roll over the full script,
it acts like 'c'...

I've sent an updated patch to #124127. Thanks for the feedback!

Cheers,
--
James
GPG Key​: 4096R/331BA3DB 2011-12-05 James McCoy <vega.james@​gmail.com>

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2015

From @tonycoz

Created by @tonycoz

perl blocks in pthread_cond_wait() when attemptting to debug a simple
threaded perl program​:

#!/usr/bin/perl
use strict;
use warnings;
use threads;
use threads​::shared;

sub foo
{
  print "Hello, world!\n";
}

my $thr = threads->create(\&foo);

$thr->join();

exit;

When run​:

tony@​mars​:.../git/perl$ PERL5DB_THREADED=1 ./perl -Ilib -d ../123127.pl
Threads support enabled

Loading DB routines from perl5db.pl version 1.48
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main​::(../123127.pl​:12)​: my $thr = threads->create(\&foo);
[0] DB<1> c
Killed

Backtrace from an attached gdb​:

(gdb) bt
#0 pthread_cond_wait@​@​GLIBC_2.3.2 ()
  at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S​:162
#1 0x00007f995831335e in recursive_lock_acquire (my_perl=0xf1d6a0,
  lock=0xd89e90, file=0x7f9958325f23 "shared.xs", line=1190) at shared.xs​:225
#2 0x00007f995831c460 in Perl_sharedsv_lock (my_perl=0xf1d6a0, ssv=0xdfb220)
  at shared.xs​:1190
#3 0x00007f995831c5c0 in Perl_sharedsv_locksv (my_perl=0xf1d6a0, sv=0x138cfb0)
  at shared.xs​:1205
#4 0x0000000000677419 in Perl_pp_lock (my_perl=0xf1d6a0) at pp.c​:6097
#5 0x000000000056a6ff in Perl_runops_debug (my_perl=0xf1d6a0) at dump.c​:2234
#6 0x000000000046a704 in Perl_call_sv (my_perl=0xf1d6a0, sv=0x14d8f90,
  flags=6) at perl.c​:2740
#7 0x0000000000640455 in perl_clone (proto_perl=0xae7010, flags=2)
  at sv.c​:15088
#8 0x00007f99587512c7 in S_ithread_create (parent_perl=0xae7010,
  init_function=0xd0adc0, stack_size=0, gimme=2, exit_opt=0, params_start=3,
  num_params=0) at threads.xs​:795
#9 0x00007f99587557ca in XS_threads_create (my_perl=0xae7010, cv=0xd686d8)
  at threads.xs​:1105
#10 0x00000000005d8f38 in Perl_pp_entersub (my_perl=0xae7010) at pp_hot.c​:3270
#11 0x000000000056a6ff in Perl_runops_debug (my_perl=0xae7010) at dump.c​:2234
#12 0x0000000000469361 in S_run_body (my_perl=0xae7010, oldscope=1)
  at perl.c​:2443
#13 0x0000000000468795 in perl_run (my_perl=0xae7010) at perl.c​:2371
#14 0x000000000041fc4d in main (argc=4, argv=0x7fff6e2f28c8,
  env=0x7fff6e2f28f0) at perlmain.c​:116

Found while working on #124127.

Perl Info

Flags:
    category=library
    severity=medium

Site configuration information for perl 5.21.11:

Configured by tony at Tue Apr 14 15:02:33 AEST 2015.

Summary of my perl5 (revision 5 version 21 subversion 11) configuration:
  Commit id: b52a68fb3b323d751c4eeab017a4b14c80255d92
  Platform:
    osname=linux, osvers=3.2.0-4-amd64, archname=x86_64-linux-thread-multi
    uname='linux mars 3.2.0-4-amd64 #1 smp debian 3.2.65-1+deb7u1 x86_64 gnulinux '
    config_args='-des -Dusedevel -Dusethreads -Doptimize=-O0 -g -Dprefix=/home/tony/perl/blead -DDEBUGGING'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2',
    optimize='-O0 -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.7.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.13.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.13'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O0 -g -L/usr/local/lib -fstack-protector'



@INC for perl 5.21.11:
    lib
    /home/tony/perl/blead/lib/site_perl/5.21.11/x86_64-linux-thread-multi
    /home/tony/perl/blead/lib/site_perl/5.21.11
    /home/tony/perl/blead/lib/5.21.11/x86_64-linux-thread-multi
    /home/tony/perl/blead/lib/5.21.11
    .


Environment for perl 5.21.11:
    HOME=/home/tony
    LANG=en_AU.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/gcc-5.0-220598/bin/:/opt/gcc-5.0-220598/bin:/home/tony/perl5/perlbrew/bin:/home/tony/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    PERLBREW_BASHRC_VERSION=0.43
    PERLBREW_HOME=/home/tony/.perlbrew
    PERLBREW_PATH=/home/tony/perl5/perlbrew/bin
    PERLBREW_ROOT=/home/tony/perl5/perlbrew
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2015

From @tonycoz

On Tue Apr 14 17​:31​:32 2015, tonyc wrote​:

tony@​mars​:.../git/perl$ PERL5DB_THREADED=1 ./perl -Ilib -d

-dt is implemented as setting PERL5DB_THREADED=1 so this is the same as
#124203, so I've merged it in, since I've provided backtrace info.

Note that the problem still occurred with both my AV fix and the dummy
lock() fix.

Tony

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2015

From @tonycoz

On Tue Apr 14 21​:38​:57 2015, tonyc wrote​:

On Tue Apr 14 17​:31​:32 2015, tonyc wrote​:

tony@​mars​:.../git/perl$ PERL5DB_THREADED=1 ./perl -Ilib -d

-dt is implemented as setting PERL5DB_THREADED=1 so this is the same as
#124203, so I've merged it in, since I've provided backtrace info.

Note that the problem still occurred with both my AV fix and the dummy
lock() fix.

5.14.2 also locks up in the same place, this is an old issue.

5.8.9 locks up when cleaning up the old thread​:

#0 pthread_cond_wait@​@​GLIBC_2.3.2 ()
  at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S​:162
#1 0x00007f7eccd87d33 in recursive_lock_acquire (my_perl=0x14af640,
  lock=0x1176260, file=0x7f7eccd91ec0 "shared.xs", line=1125)
  at shared.xs​:223
#2 0x00007f7eccd8c020 in Perl_sharedsv_lock (my_perl=0x14af640, ssv=0x118b210)
  at shared.xs​:1125
#3 0x00007f7eccd8c095 in Perl_sharedsv_locksv (my_perl=0x14af640,
  sv=0x1578bc0) at shared.xs​:1140
#4 0x00000000004b5f19 in Perl_pp_lock (my_perl=0x14af640) at pp.c​:4928
#5 0x0000000000445054 in Perl_runops_debug (my_perl=0x14af640) at dump.c​:1639
#6 0x0000000000467002 in S_call_body (my_perl=0x14af640, myop=0x7fff0063ca80,
  is_eval=0 '\000') at perl.c​:2804
#7 0x0000000000466ba2 in Perl_call_sv (my_perl=0x14af640, sv=0x15a3b60,
  flags=150) at perl.c​:2731
#8 0x0000000000486b22 in Perl_sv_clear (my_perl=0x14af640, sv=0x15cd450)
  at sv.c​:4642
#9 0x0000000000487562 in Perl_sv_free (my_perl=0x14af640, sv=0x15cd450)
  at sv.c​:4862
#10 0x000000000047c944 in do_clean_objs (my_perl=0x14af640, sv=0x15cd440)
  at sv.c​:426
#11 0x000000000047c79e in S_visit (my_perl=0x14af640,
  f=0x47c84b <do_clean_objs>, flags=524288, mask=524288) at sv.c​:370
#12 0x000000000047cb19 in Perl_sv_clean_objs (my_perl=0x14af640) at sv.c​:471
#13 0x0000000000461bbd in perl_destruct (my_perl=0x14af640) at perl.c​:881
#14 0x00007f7ecd1a2a55 in S_ithread_clear (my_perl=0x1009010, thread=0x148f240)
  at threads.xs​:166
#15 0x00007f7ecd1a7c62 in XS_threads_join (my_perl=0x1009010, cv=0x114d840)
  at threads.xs​:1150
#16 0x000000000047a7b6 in Perl_pp_entersub (my_perl=0x1009010) at pp_hot.c​:2862
#17 0x0000000000445054 in Perl_runops_debug (my_perl=0x1009010) at dump.c​:1639
#18 0x000000000046610a in S_run_body (my_perl=0x1009010, oldscope=1)
  at perl.c​:2448
#19 0x0000000000465a43 in perl_run (my_perl=0x1009010) at perl.c​:2368
#20 0x0000000000421d58 in main (argc=4, argv=0x7fff0063d2e8,
  env=0x7fff0063d310) at perlmain.c​:109

Tony

@p5pRT
Copy link
Author

p5pRT commented Feb 26, 2019

From @tonycoz

On Tue, 14 Apr 2015 23​:26​:52 -0700, tonyc wrote​:

On Tue Apr 14 21​:38​:57 2015, tonyc wrote​:

On Tue Apr 14 17​:31​:32 2015, tonyc wrote​:

tony@​mars​:.../git/perl$ PERL5DB_THREADED=1 ./perl -Ilib -d

-dt is implemented as setting PERL5DB_THREADED=1 so this is the same
as
#124203, so I've merged it in, since I've provided backtrace info.

Note that the problem still occurred with both my AV fix and the
dummy
lock() fix.

5.14.2 also locks up in the same place, this is an old issue.

5.8.9 locks up when cleaning up the old thread​:

I tried bisecting this issue, and it found​:

commit 2cbb2ee
Author​: Rafael Garcia-Suarez <rgarciasuarez@​gmail.com>
Date​: Fri Oct 15 14​:09​:54 2004 +0000

  Implement a new -dt command-line flag, to enable threads under the
  debugger (bug #31666).
 
  Subject​: RE​: [PATCH] debugger handles threads [perl #31666]
  From​: <richard.foley@​ubs.com>
  Date​: Wed, 13 Oct 2004 13​:01​:18 +0200
  Message-ID​: <B374141B0A424D4F9CF143CC51B3ADD903FB9E12@​NZURC900PEX1.ubsgs.ubsgroup.net>
 
  Subject​: Re​: [PATCH] debugger handles threads [perl #31666]
  From​: Yitzchak Scott-Thoennes <sthoenna@​efn.org>
  Date​: Wed, 13 Oct 2004 02​:49​:58 -0700
  Message-ID​: <20041013094957.GA17184@​efn.org>
 
  p4raw-id​: //depot/perl@​23372

which is when the -dt switch and threads support in the debugger was added.

The change from lock-up only during clean up vs lock up when starting the child thread was in​:

commit 9ca4d7f
Author​: Jerry D. Hedden <jdhedden@​cpan.org>
Date​: Sun Sep 10 02​:12​:06 2006 -0700

  Race condition fix in threads.pm
  First patch from​:
 
  Subject​: [PATCH] thread 1.41 - A drama in three parts
  From​: "Jerry D. Hedden" <jdhedden@​cpan.org>
  Message-ID​: <20060910091206.fb30e530d17747c2b054d625b8945d88.321c7cbc94.wbe@​email.secureserver.net>
 
  p4raw-id​: //depot/perl@​28833

so unless there was a tool change (compiler, libc) that introduced this at some point, I don't see that it ever worked.

Tony

@p5pRT
Copy link
Author

p5pRT commented Feb 27, 2019

From @tonycoz

On Mon, 25 Feb 2019 19​:19​:08 -0800, tonyc wrote​:

so unless there was a tool change (compiler, libc) that introduced
this at some point, I don't see that it ever worked.

Here's a fix for it.

I won't repeat the commit message here.

Tony

@p5pRT
Copy link
Author

p5pRT commented Feb 27, 2019

From @tonycoz

124203-db-sub-deadlock.patch
From aecf6bfced0e94a750d0b64454a6472df33aee77 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 27 Feb 2019 12:01:12 +1100
Subject: [PATCH 1/4] add extra lock tracing to threads::shared

This was useful in tracing the cause for the deadlock in #124203.

This can be enabled during a build of perl by adding:

  -Accflags=-DSHARED_TRACE_LOCKS -DDEBUGGING

to the Configure command-line.

To see the trace at run-time add -DU or -DUv to the perl command-line.

The original DEBUG_LOCKS tracing using warn caused extra calls
confusing back traces when trying to debug this problem.
---
 dist/threads-shared/shared.xs | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/dist/threads-shared/shared.xs b/dist/threads-shared/shared.xs
index d0f7d1e070..6cdf094d27 100644
--- a/dist/threads-shared/shared.xs
+++ b/dist/threads-shared/shared.xs
@@ -115,6 +115,17 @@
  * without the prefix (e.g., sv, tmp or obj).
  */
 
+/* this is lower overhead than warn() and less likely to interfere
+   with other parts of perl (like with the debugger.)
+*/
+#ifdef SHARED_TRACE_LOCKS
+#  define TRACE_LOCK(x) DEBUG_U(x)
+#  define TRACE_LOCKv(x) DEBUG_Uv(x)
+#else
+#  define TRACE_LOCK(x)
+#  define TRACE_LOCKv(x)
+#endif
+
 #define PERL_NO_GET_CONTEXT
 #include "EXTERN.h"
 #include "perl.h"
@@ -211,8 +222,24 @@ recursive_lock_release(pTHX_ recursive_lock_t *lock)
         if (--lock->locks == 0) {
             lock->owner = NULL;
             COND_SIGNAL(&lock->cond);
+            TRACE_LOCK(
+                    PerlIO_printf(Perl_debug_log, "shared lock released %p for %p at %s:%d\n",
+                                  lock, aTHX, CopFILE(PL_curcop), CopLINE(PL_curcop))
+                    );
+        }
+        else {
+            TRACE_LOCKv(
+                    PerlIO_printf(Perl_debug_log, "shared lock unbump %p for %p at %s:%d\n",
+                                  lock, aTHX, CopFILE(PL_curcop), CopLINE(PL_curcop))
+                    );
         }
     }
+    else {
+        TRACE_LOCK(
+                PerlIO_printf(Perl_debug_log, "bad shared lock release %p for %p (owned by %p) at %s:%d\n",
+                               lock, aTHX, lock->owner, CopFILE(PL_curcop), CopLINE(PL_curcop))
+                 );
+    }
     MUTEX_UNLOCK(&lock->mutex);
 }
 
@@ -224,8 +251,16 @@ recursive_lock_acquire(pTHX_ recursive_lock_t *lock, const char *file, int line)
     assert(aTHX);
     MUTEX_LOCK(&lock->mutex);
     if (lock->owner == aTHX) {
+        TRACE_LOCKv(
+                 PerlIO_printf(Perl_debug_log, "shared lock bump %p (%p) at %s:%d\n",
+                               lock, lock->owner, CopFILE(PL_curcop), CopLINE(PL_curcop))
+                 );
         lock->locks++;
     } else {
+        TRACE_LOCK(
+                 PerlIO_printf(Perl_debug_log, "shared lock try %p for %p (owned by %p) at %s:%d\n",
+                               lock, aTHX, lock->owner, CopFILE(PL_curcop), CopLINE(PL_curcop))
+                 );
         while (lock->owner) {
 #ifdef DEBUG_LOCKS
             Perl_warn(aTHX_ " %p waiting - owned by %p %s:%d\n",
@@ -233,6 +268,10 @@ recursive_lock_acquire(pTHX_ recursive_lock_t *lock, const char *file, int line)
 #endif
             COND_WAIT(&lock->cond,&lock->mutex);
         }
+        TRACE_LOCK(
+                 PerlIO_printf(Perl_debug_log, "shared lock got %p at %s:%d\n",
+                               lock, CopFILE(PL_curcop), CopLINE(PL_curcop))
+                 );
         lock->locks = 1;
         lock->owner = aTHX;
 #ifdef DEBUG_LOCKS
-- 
2.11.0


From 1b1bd389060a079dcfa37e9b4ad6a417fee261a9 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 27 Feb 2019 12:01:40 +1100
Subject: [PATCH 2/4] (perl #124203) avoid a deadlock in DB::sub

I don't know how this ever worked.

Previously, DB::sub() would hold a lock on $DB::DBGR for it's entire
body, including the call to the subroutine being called.

This could cause problems in two cases:

a) on creation of a new thread, CLONE() is called in the context of
the new interpreter before the new thread is created.  So you'd have a
sequence like:

  threads->new
  DB::sub for threads::new (lock $DBGR)
  call into threads::new which creates a new interpreter
  Cwd::CLONE() (in the new interpreter)
  DB::sub for Cwd::CLONE (in the new interpreter) (deadlock trying to lock $DBGR)

One workaround I tried for this was to prevent pp_entersub calling
DB::sub if we were cloning (by checking PL_ptr_table).  This did
improve matters, but wasn't needed in the final patch.

Note that the recursive lock on $DBGR would have been fine if the new
code was executing in the same interpreter, since the locking code
simply bumps a reference count if the current interpreter already
holds the lock.

b) when the called subroutine blocks.  For the test case this could
happen with the call to $thr->join.  There would be a sequence like:

  (parent) $thr->join
  (parent) DB::sub for threads::join (lock $DBGR)
  (parent) call threads::join and block
  (child) try to call main::sub1
  (child) DB::sub for main::sub1 (deadlock trying to lock $DBGR)

This isn't limited to threads::join obviously, one thread could be
waiting for input, sleeping, or performing a complex calculation.

The solution I chose here was the obvious one - don't hold the lock
for the actual call.

This required some rearrangement of the code and removed some
duplication too.
---
 MANIFEST                |   1 +
 lib/perl5db.pl          | 205 ++++++++++++++++++++++++------------------------
 lib/perl5db.t           |  24 +++++-
 lib/perl5db/t/rt-124203 |   7 ++
 4 files changed, 131 insertions(+), 106 deletions(-)
 create mode 100644 lib/perl5db/t/rt-124203

diff --git a/MANIFEST b/MANIFEST
index 1bc8bc54f6..18b6c97153 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4653,6 +4653,7 @@ lib/perl5db/t/proxy-constants	Tests for the Perl debugger
 lib/perl5db/t/rt-104168		Tests for the Perl debugger
 lib/perl5db/t/rt-120174		Tests for the Perl debugger
 lib/perl5db/t/rt-121509-restart-after-chdir		Tests for the Perl debugger
+lib/perl5db/t/rt-124203		Test threads in the Perl debugger
 lib/perl5db/t/rt-61222		Tests for the Perl debugger
 lib/perl5db/t/rt-66110		Tests for the Perl debugger
 lib/perl5db/t/source-cmd-test.perldb		Tests for the Perl debugger
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 39f76f35fe..745b1173dc 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4144,23 +4144,7 @@ sub _print_frame_message {
 }
 
 sub DB::sub {
-    # lock ourselves under threads
-    lock($DBGR);
-
-    # Whether or not the autoloader was running, a scalar to put the
-    # sub's return value in (if needed), and an array to put the sub's
-    # return value in (if needed).
     my ( $al, $ret, @ret ) = "";
-    if ($sub eq 'threads::new' && $ENV{PERL5DB_THREADED}) {
-        print "creating new thread\n";
-    }
-
-    # If the last ten characters are '::AUTOLOAD', note we've traced
-    # into AUTOLOAD for $sub.
-    if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
-        no strict 'refs';
-        $al = " for $$sub" if defined $$sub;
-    }
 
     # We stack the stack pointer and then increment it to protect us
     # from a situation that might unwind a whole bunch of call frames
@@ -4168,40 +4152,49 @@ sub DB::sub {
     # unwind the same amount when multiple stack frames are unwound.
     local $stack_depth = $stack_depth + 1;    # Protect from non-local exits
 
-    # Expand @stack.
-    $#stack = $stack_depth;
+    {
+        # lock ourselves under threads
+        # While lock() permits recursive locks, there's two cases where it's bad
+        # that we keep a hold on the lock while we call the sub:
+        #  - during cloning, Package::CLONE might be called in the context of the new
+        #    thread, which will deadlock if we hold the lock across the threads::new call
+        #  - for any function that waits any significant time
+        # This also deadlocks if the parent thread joins(), since holding the lock
+        # will prevent any child threads passing this point.
+        # So release the lock for the function call.
+        lock($DBGR);
 
-    # Save current single-step setting.
-    $stack[-1] = $single;
+        # Whether or not the autoloader was running, a scalar to put the
+        # sub's return value in (if needed), and an array to put the sub's
+        # return value in (if needed).
+        if ($sub eq 'threads::new' && $ENV{PERL5DB_THREADED}) {
+            print "creating new thread\n";
+        }
 
-    # Turn off all flags except single-stepping.
-    $single &= 1;
+        # If the last ten characters are '::AUTOLOAD', note we've traced
+        # into AUTOLOAD for $sub.
+        if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
+            no strict 'refs';
+            $al = " for $$sub" if defined $$sub;
+        }
 
-    # If we've gotten really deeply recursed, turn on the flag that will
-    # make us stop with the 'deep recursion' message.
-    $single |= 4 if $stack_depth == $deep;
+        # Expand @stack.
+        $#stack = $stack_depth;
 
-    # If frame messages are on ...
+        # Save current single-step setting.
+        $stack[-1] = $single;
 
-    _print_frame_message($al);
-    # standard frame entry message
+        # Turn off all flags except single-stepping.
+        $single &= 1;
 
-    my $print_exit_msg = sub {
-        # Check for exit trace messages...
-        if ($frame & 2)
-        {
-            if ($frame & 4)    # Extended exit message
-            {
-                _indent_print_line_info(0, "out ");
-                print_trace( $LINEINFO, 0, 1, 1, "$sub$al" );
-            }
-            else
-            {
-                _indent_print_line_info(0, "exited $sub$al\n" );
-            }
-        }
-        return;
-    };
+        # If we've gotten really deeply recursed, turn on the flag that will
+        # make us stop with the 'deep recursion' message.
+        $single |= 4 if $stack_depth == $deep;
+
+        # If frame messages are on ...
+
+        _print_frame_message($al);
+    }
 
     # Determine the sub's return type, and capture appropriately.
     if (wantarray) {
@@ -4209,77 +4202,81 @@ sub DB::sub {
         # Called in array context. call sub and capture output.
         # DB::DB will recursively get control again if appropriate; we'll come
         # back here when the sub is finished.
-        {
-            no strict 'refs';
-            @ret = &$sub;
-        }
+        no strict 'refs';
+        @ret = &$sub;
+    }
+    elsif ( defined wantarray ) {
+        no strict 'refs';
+        # Save the value if it's wanted at all.
+        $ret = &$sub;
+    }
+    else {
+        no strict 'refs';
+        # Void return, explicitly.
+        &$sub;
+        undef $ret;
+    }
+
+    {
+        lock($DBGR);
 
         # Pop the single-step value back off the stack.
         $single |= $stack[ $stack_depth-- ];
 
-        $print_exit_msg->();
+        if ($frame & 2) {
+            if ($frame & 4) {   # Extended exit message
+                _indent_print_line_info(0, "out ");
+                print_trace( $LINEINFO, -1, 1, 1, "$sub$al" );
+            }
+            else {
+                _indent_print_line_info(0, "exited $sub$al\n" );
+            }
+        }
 
-        # Print the return info if we need to.
-        if ( $doret eq $stack_depth or $frame & 16 ) {
+        if (wantarray) {
+            # Print the return info if we need to.
+            if ( $doret eq $stack_depth or $frame & 16 ) {
 
-            # Turn off output record separator.
-            local $\ = '';
-            my $fh = ( $doret eq $stack_depth ? $OUT : $LINEINFO );
+                # Turn off output record separator.
+                local $\ = '';
+                my $fh = ( $doret eq $stack_depth ? $OUT : $LINEINFO );
 
-            # Indent if we're printing because of $frame tracing.
-            if ($frame & 16)
-            {
-                print {$fh} ' ' x $stack_depth;
-            }
+                # Indent if we're printing because of $frame tracing.
+                if ($frame & 16)
+                  {
+                      print {$fh} ' ' x $stack_depth;
+                  }
 
-            # Print the return value.
-            print {$fh} "list context return from $sub:\n";
-            dumpit( $fh, \@ret );
+                # Print the return value.
+                print {$fh} "list context return from $sub:\n";
+                dumpit( $fh, \@ret );
 
-            # And don't print it again.
-            $doret = -2;
-        } ## end if ($doret eq $stack_depth...
+                # And don't print it again.
+                $doret = -2;
+            } ## end if ($doret eq $stack_depth...
             # And we have to return the return value now.
-        @ret;
-    } ## end if (wantarray)
-
-    # Scalar context.
-    else {
-        if ( defined wantarray ) {
-            no strict 'refs';
-            # Save the value if it's wanted at all.
-            $ret = &$sub;
-        }
+            @ret;
+        } ## end if (wantarray)
+        # Scalar context.
         else {
-            no strict 'refs';
-            # Void return, explicitly.
-            &$sub;
-            undef $ret;
-        }
-
-        # Pop the single-step value off the stack.
-        $single |= $stack[ $stack_depth-- ];
-
-        # If we're doing exit messages...
-        $print_exit_msg->();
-
-        # If we are supposed to show the return value... same as before.
-        if ( $doret eq $stack_depth or $frame & 16 and defined wantarray ) {
-            local $\ = '';
-            my $fh = ( $doret eq $stack_depth ? $OUT : $LINEINFO );
-            print $fh ( ' ' x $stack_depth ) if $frame & 16;
-            print $fh (
-                defined wantarray
-                ? "scalar context return from $sub: "
-                : "void context return from $sub\n"
-            );
-            dumpit( $fh, $ret ) if defined wantarray;
-            $doret = -2;
-        } ## end if ($doret eq $stack_depth...
-
-        # Return the appropriate scalar value.
-        $ret;
-    } ## end else [ if (wantarray)
+            # If we are supposed to show the return value... same as before.
+            if ( $doret eq $stack_depth or $frame & 16 and defined wantarray ) {
+                local $\ = '';
+                my $fh = ( $doret eq $stack_depth ? $OUT : $LINEINFO );
+                print $fh ( ' ' x $stack_depth ) if $frame & 16;
+                print $fh (
+                           defined wantarray
+                           ? "scalar context return from $sub: "
+                           : "void context return from $sub\n"
+                          );
+                dumpit( $fh, $ret ) if defined wantarray;
+                $doret = -2;
+            } ## end if ($doret eq $stack_depth...
+
+            # Return the appropriate scalar value.
+            $ret;
+        } ## end else [ if (wantarray)
+    }
 } ## end sub _sub
 
 sub lsub : lvalue {
diff --git a/lib/perl5db.t b/lib/perl5db.t
index 3d432ad52e..cbfe07777b 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -31,8 +31,6 @@ BEGIN {
     $ENV{PERL_RL} = 'Perl'; # Suppress system Term::ReadLine::Gnu
 }
 
-plan(127);
-
 my $rc_filename = '.perldb';
 
 sub rc {
@@ -2901,6 +2899,28 @@ SKIP:
     );
 }
 
+SKIP:
+{
+    $Config{usethreads}
+      or skip "need threads to test debugging threads", 1;
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'c',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/rt-124203',
+        }
+    );
+
+    $wrapper->output_like(qr/In the thread/, "[perl #124203] the thread ran");
+
+    $wrapper->output_like(qr/Finished/, "[perl #124203] debugger didn't deadlock");
+}
+
+done_testing();
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
diff --git a/lib/perl5db/t/rt-124203 b/lib/perl5db/t/rt-124203
new file mode 100644
index 0000000000..85ab7b0b27
--- /dev/null
+++ b/lib/perl5db/t/rt-124203
@@ -0,0 +1,7 @@
+use threads;
+my $thr = threads->create(\&sub1);
+sub sub1 {
+   print("In the thread\n");
+}
+$thr->join;
+print "Finished\n";
\ No newline at end of file
-- 
2.11.0


From 7e65dbc1023ce2834deaf1ce3202ca23997cc622 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 27 Feb 2019 15:28:37 +1100
Subject: [PATCH 3/4] bump $threads::shared::VERSION to 1.60

---
 dist/threads-shared/lib/threads/shared.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dist/threads-shared/lib/threads/shared.pm b/dist/threads-shared/lib/threads/shared.pm
index f7e5ff8e73..45ad154979 100644
--- a/dist/threads-shared/lib/threads/shared.pm
+++ b/dist/threads-shared/lib/threads/shared.pm
@@ -8,7 +8,7 @@ use Config;
 
 use Scalar::Util qw(reftype refaddr blessed);
 
-our $VERSION = '1.59'; # Please update the pod, too.
+our $VERSION = '1.60'; # Please update the pod, too.
 my $XS_VERSION = $VERSION;
 $VERSION = eval $VERSION;
 
@@ -196,7 +196,7 @@ threads::shared - Perl extension for sharing data structures between threads
 
 =head1 VERSION
 
-This document describes threads::shared version 1.59
+This document describes threads::shared version 1.60
 
 =head1 SYNOPSIS
 
-- 
2.11.0


From 0799b90d290ea3ea0d601e3cd6b6a724319bc5c1 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 27 Feb 2019 15:29:23 +1100
Subject: [PATCH 4/4] bump $DB::VERSION for perl5db.pl to 1.55

---
 lib/perl5db.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 745b1173dc..be2367cde7 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -529,7 +529,7 @@ BEGIN {
 use vars qw($VERSION $header);
 
 # bump to X.XX in blead, only use X.XX_XX in maint
-$VERSION = '1.54';
+$VERSION = '1.55';
 
 $header = "perl5db.pl version $VERSION";
 
-- 
2.11.0

@p5pRT
Copy link
Author

p5pRT commented Feb 28, 2019

From @tonycoz

On Tue, 26 Feb 2019 20​:51​:31 -0800, tonyc wrote​:

On Mon, 25 Feb 2019 19​:19​:08 -0800, tonyc wrote​:

so unless there was a tool change (compiler, libc) that introduced
this at some point, I don't see that it ever worked.

Here's a fix for it.

I won't repeat the commit message here.

DB​::lsub had the same problem.

Fix attached.

Tony

@p5pRT
Copy link
Author

p5pRT commented Feb 28, 2019

From @tonycoz

0001-perl-124203-fix-a-similar-problem-with-DB-lsub.patch
From dcb4031b9cdafbb9856f0b1cd72ef58f087cb94d Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Thu, 28 Feb 2019 11:53:19 +1100
Subject: (perl #124203) fix a similar problem with DB::lsub

---
 MANIFEST                 |  1 +
 lib/perl5db.pl           | 49 ++++++++++++++++++++++++------------------------
 lib/perl5db.t            | 15 +++++++++++++++
 lib/perl5db/t/rt-124203b | 13 +++++++++++++
 4 files changed, 54 insertions(+), 24 deletions(-)
 create mode 100644 lib/perl5db/t/rt-124203b

diff --git a/MANIFEST b/MANIFEST
index 18b6c97153..268dfcfebd 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4654,6 +4654,7 @@ lib/perl5db/t/rt-104168		Tests for the Perl debugger
 lib/perl5db/t/rt-120174		Tests for the Perl debugger
 lib/perl5db/t/rt-121509-restart-after-chdir		Tests for the Perl debugger
 lib/perl5db/t/rt-124203		Test threads in the Perl debugger
+lib/perl5db/t/rt-124203b	Test threads in the Perl debugger
 lib/perl5db/t/rt-61222		Tests for the Perl debugger
 lib/perl5db/t/rt-66110		Tests for the Perl debugger
 lib/perl5db/t/source-cmd-test.perldb		Tests for the Perl debugger
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index be2367cde7..e8a29da134 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4281,25 +4281,6 @@ sub DB::sub {
 
 sub lsub : lvalue {
 
-    no strict 'refs';
-
-    # lock ourselves under threads
-    lock($DBGR);
-
-    # Whether or not the autoloader was running, a scalar to put the
-    # sub's return value in (if needed), and an array to put the sub's
-    # return value in (if needed).
-    my ( $al, $ret, @ret ) = "";
-    if ($sub =~ /^threads::new$/ && $ENV{PERL5DB_THREADED}) {
-        print "creating new thread\n";
-    }
-
-    # If the last ten characters are C'::AUTOLOAD', note we've traced
-    # into AUTOLOAD for $sub.
-    if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
-        $al = " for $$sub";
-    }
-
     # We stack the stack pointer and then increment it to protect us
     # from a situation that might unwind a whole bunch of call frames
     # at once. Localizing the stack pointer means that it will automatically
@@ -4317,12 +4298,32 @@ sub lsub : lvalue {
     # stack for us.
     local $single = $single & 1;
 
-    # If we've gotten really deeply recursed, turn on the flag that will
-    # make us stop with the 'deep recursion' message.
-    $single |= 4 if $stack_depth == $deep;
+    no strict 'refs';
+    {
+        # lock ourselves under threads
+        lock($DBGR);
+
+        # Whether or not the autoloader was running, a scalar to put the
+        # sub's return value in (if needed), and an array to put the sub's
+        # return value in (if needed).
+        my ( $al, $ret, @ret ) = "";
+        if ($sub =~ /^threads::new$/ && $ENV{PERL5DB_THREADED}) {
+            print "creating new thread\n";
+        }
+
+        # If the last ten characters are C'::AUTOLOAD', note we've traced
+        # into AUTOLOAD for $sub.
+        if ( length($sub) > 10 && substr( $sub, -10, 10 ) eq '::AUTOLOAD' ) {
+            $al = " for $$sub";
+        }
 
-    # If frame messages are on ...
-    _print_frame_message($al);
+        # If we've gotten really deeply recursed, turn on the flag that will
+        # make us stop with the 'deep recursion' message.
+        $single |= 4 if $stack_depth == $deep;
+
+        # If frame messages are on ...
+        _print_frame_message($al);
+    }
 
     # call the original lvalue sub.
     &$sub;
diff --git a/lib/perl5db.t b/lib/perl5db.t
index cbfe07777b..450f4d067b 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -2917,6 +2917,21 @@ SKIP:
     $wrapper->output_like(qr/In the thread/, "[perl #124203] the thread ran");
 
     $wrapper->output_like(qr/Finished/, "[perl #124203] debugger didn't deadlock");
+
+    $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'c',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/rt-124203b',
+        }
+    );
+
+    $wrapper->output_like(qr/In the thread/, "[perl #124203] the thread ran (lvalue)");
+
+    $wrapper->output_like(qr/Finished One/, "[perl #124203] debugger didn't deadlock (lvalue)");
 }
 
 done_testing();
diff --git a/lib/perl5db/t/rt-124203b b/lib/perl5db/t/rt-124203b
new file mode 100644
index 0000000000..a599621566
--- /dev/null
+++ b/lib/perl5db/t/rt-124203b
@@ -0,0 +1,13 @@
+use threads;
+print "PID $$\n";
+my $x;
+sub sub1 {
+  print("In the thread\n");
+}
+sub foo:lvalue {
+  my $thr = threads->create(\&sub1);
+  $thr->join;
+  $x;
+}
+foo() = "One";
+print "Finished $x\n";
-- 
2.11.0

@p5pRT
Copy link
Author

p5pRT commented Mar 21, 2019

From @tonycoz

On Tue, 26 Feb 2019 20​:51​:31 -0800, tonyc wrote​:

On Mon, 25 Feb 2019 19​:19​:08 -0800, tonyc wrote​:

so unless there was a tool change (compiler, libc) that introduced
this at some point, I don't see that it ever worked.

Here's a fix for it.

I won't repeat the commit message here.

These were applied as d22170b through bf3e41f, including the DB​::lsub fix.

Tony

@p5pRT
Copy link
Author

p5pRT commented Mar 21, 2019

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.30.0, this and 160 other issues have been
resolved.

Perl 5.30.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.30.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant