Hello Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.