Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Recipe

  • Attach gdb to the process

    gdb -p YOUR-PID

  • Advance perl to a point between opcodes. This step may be optional but is a good idea. Omitting this step risks corrupting something. This is semi-equivalent to an "unsafe perl signal."

    set variable PL_sig_pending = 1 b Perl_despatch_signals c
  • Run arbitrary perl. This returns a number which is a (SV*). You'll use this pointer in the next step. See How to dump perl data structures from gdb additionally when on threaded perl builds.

    call Perl_eval_pv("...", 0)

  • Deallocate the scalar returned by the previous eval. This is causing issues for me now. I don't know why. Use the number returned by Perl_eval_pv

    call Perl_sv_free(...)

Complete example

The following is a complete example showing a sample program being launched and gdb loading Carp into the program during its execution and calling the perl function cluck(). Carp::cluck is a convenient function to log the current perl stack to STDERR.

[server ~]$ perl -e 'while(1){foo()};sub foo { sleep 1 }' & [1] 22480 [server ~]$ ps x PID TTY STAT TIME COMMAND 10351 ? S 0:01 sshd: diotalevi@pts/77 10352 pts/77 Ss+ 0:00 -bash 22311 ? S 0:00 sshd: diotalevi@pts/37 22312 pts/37 Ss 0:00 -bash 22354 pts/37 S+ 0:00 screen -x -R 22356 pts/41 Ss 0:00 -/bin/bash 22480 pts/41 S+ 0:00 perl -e while(1){foo()};sub foo { sleep 1 } 22418 pts/51 Ss 0:00 -/bin/bash 22479 pts/51 R+ 0:00 ps x [diotalevi ~]$ gdb -p 22480 GNU gdb Red Hat Linux (6.3.0.0-1.132.EL3rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and y +ou are welcome to change it and/or distribute copies of it under certain cond +itions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for det +ails. This GDB was configured as "i386-redhat-linux-gnu". Attaching to process 22480 warning: The current VSYSCALL page code requires an existing execuitab +le. Use "add-symbol-file-from-memory" to load the VSYSCALL page by hand Reading symbols from /usr/local/bin/perl...(no debugging symbols found +)...done. Using host libthread_db library "/lib/tls/libthread_db.so.1". Reading symbols from /lib/libnsl.so.1...(no debugging symbols found).. +.done. Loaded symbols for /lib/libnsl.so.1 Reading symbols from /lib/libdl.so.2...(no debugging symbols found)... +done. Loaded symbols for /lib/libdl.so.2 Reading symbols from /lib/tls/libm.so.6...(no debugging symbols found) +...done. Loaded symbols for /lib/tls/libm.so.6 Reading symbols from /lib/libcrypt.so.1...(no debugging symbols found) +...done. Loaded symbols for /lib/libcrypt.so.1 Reading symbols from /lib/libutil.so.1... (no debugging symbols found)...done. Loaded symbols for /lib/libutil.so.1 Reading symbols from /lib/tls/libc.so.6...(no debugging symbols found) +...done. Loaded symbols for /lib/tls/libc.so.6 Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found) +...done. Loaded symbols for /lib/ld-linux.so.2 0xb7eebacb in __nanosleep_nocancel () from /lib/tls/libc.so.6 (gdb) set variable PL_sig_pending = 1 (gdb) b Perl_despatch_signals Breakpoint 1 at 0x809ed59 (gdb) c Continuing. Breakpoint 1, 0x0809ed59 in Perl_despatch_signals () (gdb) delete breakpoints Delete all breakpoints? (y or n) y (gdb) call Perl_eval_pv("use Carp; Carp::cluck('Hello world')",0) Hello world at (eval 1) line 1 eval 'use Carp; Carp::cluck(\'Hello world\') ;' called at -e line 1 main::foo() called at -e line 1 $1 = 135614820 (gdb) call Perl_sv_free(135614820) $2 = 135389568

In reply to eval() from gdb by diotalevi

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2024-04-25 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found