I am fairly new to the Perl threads and I got a perl script to debug an exe using GDB and GDBServer. The code snippet is attached below.
sub reset { my $self_ph = shift; $self_ph->kill(); $self_ph->{GDBSERVERTHREAD} = threads::async { `$self_ph->{GDBSERVER} :6000 MyProgram.exe 1> NUL 2> NUL`; threads->exit(); }; Time::HiRes::sleep(0.05); $self_ph->{IN} = new FileHandle; $self_ph->{OUT} = new FileHandle; $self_ph->{PID} = IPC::Open2::open2($self_ph->{IN},$self_ph->{OUT} +, $self_ph->{GDB} . " --silent --interpreter=mi " . $self_ph->{EXE} . " -ex \"set target-async off\" -ex \"target remote :6000\" +" ); $self_ph->{IN_QUEUE} = new Thread::Queue; Time::HiRes::sleep(0.05); $self_ph->{READER} = threads::async { $SIG{'KILL'} = sub { threads->exit(); }; while ( my $content_s = readline( $self_ph->{IN} ) ) { $self_ph->{IN_QUEUE}->enqueue($content_s); } }; $self_ph->{IN}->autoflush(1); $self_ph->{OUT}->autoflush(1); return (1); } sub kill { my $self_ph = shift; if ( defined( $self_ph->{READER} ) ) { $self_ph->{READER}->kill('KILL')->detach(); $self_ph->{READER} = undef; } if ( defined( $self_ph->{GDBSERVERTHREAD} ) ) { `taskkill /F /IM MyProgram.exe`; $self_ph->{GDBSERVERTHREAD}->join(); $self_ph->{GDBSERVERTHREAD} = undef; } if ( 0 != $self_ph->{PID} ) { `taskkill /F /IM gdb.exe`; $self_ph->{PID} = 0; } return (1); }
The reset module starts the gdb.exe and gdbserver.exe and MyProgram.exe. The problem arises with the kill module. When the control reaches the join of the GDBServer the control does not return at all.
I tried detach instead of join but there are warnings and exceptions. Can someone help as to what is wrong in the script or what should be changed so that at the end of kill all the threads are exited correctly and my script does not get terminated?
In reply to Debugging an exe with GDB using PERL by Mj1234
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |