[erlang-questions] printing of Eterm's from gdb

Raimo Niskanen <>
Mon Sep 1 12:29:58 CEST 2008


On Sun, Aug 31, 2008 at 09:48:09AM +0100, Joel Reymont wrote:
> How can I print out Eterm's from within gdb?
> 
> (gdb) where
> #0  size_object (obj=4380267240) at beam/copy.c:157
> 
> (gdb) p obj
> $8 = 4380267240
> 
> (gdb) p erts_printf_eterm_func
> $6 = (int (*)(fmtfn_t, void *, long unsigned int, long int))  
> 0x100059760 <erts_printf_term>
> 
> (gdb) p erts_printf
> $7 = {int (const char *)} 0x100132d90 <erts_printf>
> 
> 	Thanks, Joel

There is a utility we (the ERTS group) use ourselves.
erts/etc/unix/etp-commands
aka Emulator Toolbox for Pathologists.

It is a horrible/amazing set of GDB macros that print
erlang terms rather successfully.

If you start the emulator from another ERTS utility bin/cerl
it will with the right arguments load etp-commands for you:
$ $ERL_TOP/bin/cerl -gdb

...new emacs GDB window pops up...

Current directory is /ldisk/raimo/r12b_dev/
set args -- -root /clearcase/otp/erts -progname /clearcase/otp/erts/bin/cerl  -- -home /home/raimo 
source /clearcase/otp/erts/erts/etc/unix/etp-commands
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-suse-linux"...
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) (gdb) %---------------------------------------------------------------------------
% Use etp-help for a command overview and general help.
%
% To use the Erlang support module, the environment variable ROOTDIR
% must be set to the toplevel installation directory of Erlang/OTP,
% so the etp-commands file becomes:
%     $ROOTDIR/erts/etc/unix/etp-commands
% Also, erl and erlc must be in the path.
%---------------------------------------------------------------------------
etp-set-max-depth 20
etp-set-max-string-length 100
(gdb) break nodes_1
Breakpoint 1 at 0x47de60: file beam/dist.c, line 2069.
(gdb) run
Starting program: /clearcase/otp/erts/bin/x86_64-unknown-linux-gnu/beam -- -root /clearcase/otp/erts -progname /clearcase/otp/erts/bin/cerl  -- -home /home/raimo 
[Thread debugging using libthread_db enabled]
[New Thread 47984520497888 (LWP 20163)]
[New Thread 1073813824 (LWP 20166)]
Eshell V5.6.4  (abort with ^G)
1> erlang:nodes({wrong,0,argument}).
[Switching to Thread 47984520497888 (LWP 20163)]

Breakpoint 1, nodes_1 (A__p=0x2ba4446a9198, A_1=47984522740722)
    at beam/dist.c:2069
(gdb) etp 47984522740722
{wrong,0,argument}.
(gdb) cont
Continuing.
** exception error: bad argument
     in function  nodes/1
        called as nodes({wrong,0,argument})
2> 



The line:
(gdb) etp 47984522740722
is what you want. The number is really an Erlang term in
this case a tagged pointer to the tuple header word on the heap.

(gdb) x/4xg 47984522740722 & ~3
0x2ba4446ec3f0:	0x00000000000000c0	0x000000000004e2cb
0x2ba4446ec400:	0x000000000000000f	0x000000000004e34b
(gdb) etp 0x000000000004e2cb
wrong.
(gdb) etp 0x000000000000000f
0.
(gdb) etp 0x000000000004e34b
argument.
(gdb) 

Try also etp-help, and read the source if you dare.
Have fun!

> 
> --
> wagerlabs.com
> 
> 
> 
> 
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list