While running a debugging perl under gdb, you can access the same dumping facility (Perl_do_sv_dump, in perl's dump.c) that Devel::Peek uses. The following is a short example, using a threaded perl. On non-threaded non-multiplicity perls, the Perl_get_context() arguments should be omitted.

I'll set up a nested structure to feed to perl's not operator, and then dump it out from within the not op.

$ gdb perl5.8.7 GNU gdb 6.3.50_2004-12-28-cvs (cygwin-special) 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 "i686-pc-cygwin"... (gdb) set args -we'![a=>{b=>0,c=>1},sub{"foo"}]' (gdb) b Perl_pp_not Function "Perl_pp_not" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (Perl_pp_not) pending. (gdb) r Starting program: /usr/local/bin/perl5.8.7.exe -we'![a=>{b=>0,c=>1},su +b{"foo"}]' Breakpoint 2 at 0x100bbe8f: file pp.c, line 2396. Pending breakpoint "Perl_pp_not" resolved Useless use of not in void context at -e line 1. Breakpoint 2, Perl_pp_not (my_perl=0x103c1f58) at pp.c:2396 2396 dSP; tryAMAGICunSET(not); (gdb) s 2397 *PL_stack_sp = boolSV(!SvTRUE(*PL_stack_sp)); (gdb) call Perl_do_sv_dump(Perl_get_context(),0,Perl_PerlIO_stderr(Per +l_get_con text()),*sp,0,4,0,0) SV = RV(0x103e9824) at 0x103e7588 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x103c323c SV = PVAV(0x103e9c40) at 0x103c323c REFCNT = 2 FLAGS = () IV = 0 NV = 0 ARRAY = 0x103c9ba8 FILL = 2 MAX = 2 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = PV(0x103c3468) at 0x103e7564 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x103c4898 "a"\0 CUR = 1 LEN = 2 Elt No. 1 SV = RV(0x103e981c) at 0x103e7570 REFCNT = 1 FLAGS = (ROK) RV = 0x103c3188 SV = PVHV(0x103e2990) at 0x103c3188 REFCNT = 3 FLAGS = (SHAREKEYS) IV = 2 NV = 0 ARRAY = 0x103e8e48 (0:6, 1:2) hash quality = 125.0% KEYS = 2 FILL = 2 MAX = 7 RITER = -1 EITER = 0x0 Elt "c" HASH = 0xeeba5d59 SV = IV(0x103e9428) at 0x103e74a4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 Elt No. 2 SV = RV(0x103e9820) at 0x103e757c REFCNT = 1 FLAGS = (ROK) RV = 0x103e7504 SV = PVCV(0x103e0f08) at 0x103e7504 REFCNT = 3 FLAGS = (PADBUSY,PADMY,ANON,WEAKOUTSIDE) IV = 0 NV = 0 COMP_STASH = 0x103c30b0 "main" START = 0x103e5608 ===> 1 ROOT = 0x103eaa48 XSUB = 0x0 XSUBANY = 0 GVGV::GV = 0x103e7534 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x404 OUTSIDE_SEQ = 0 PADLIST = 0x103e7510 PADNAME = 0x103e751c(0x103e7ce8) PAD = 0x103e7528(0x10 +3e7c68) OUTSIDE = 0x103c32b4 (MAIN) (gdb)

Perl_do_sv_dump is prototyped:
Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 m +axnest, bool dumpops, STRLEN pvlim)
Most of the parameters can be left as zero; file needs to be a PerlIO* to where the output should go, sv is the sv to dump, and maxnest is how deep to go in complex data structures.

In reply to How to dump perl data structures from gdb by ysth

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.