This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Debugging Guile with gdb


Maciej Stachowiak <mstachow@mit.edu> writes:

<snip>

> I am having a hard time tracking this bug further because to examine
> SCM values it is necessary to unwrap many layers of complex macros to
> be able to pass something useful to gdb's `print' command. I noticed
> that Guile has some files in it to provide a gdb interface. Will that
> help me in any way? And if so, how do I use it?

<snip>

Maybe you already know about this and are asking something different,
but this information was hard enough for me to find a while ago that it
may be generally useful (perhaps it could be more visible on the web
page, if it's still not).

If you put the below in your $HOME/.gdbinit, then you can use the
various commands to interrogate SCM's much less painfully than expanding 
macros by hand and dereferencing tons of pointers.  E.g., just do: 
"dp win" and you'll get the printable form of a scwm window scheme object.
Highly useful stuff.

Thanks to this group for letting me know about this code a while back...

Greg


# -*- sh -*- 
# Define a bunch of useful functions for debugging Guile.
# Add more as required.

define dp
set $gp=gdb_print($arg0)
output gdb_output
echo \n
end
document dp
Executes (display $arg0) to stdout.
end

define xcar
set $last=((scm_cell*) $arg0)->car
output $last
echo \n
end
document xcar
Print the CAR of $.
end

define xcdr
set $last=((scm_cell*) $arg0)->cdr
output $last
echo \n
end
document xcdr
Print the CDR of $.
end

define xgccdr
set $last=~1L & ((scm_cell*) $arg0)->cdr
output $last
echo \n
end
document xgccdr
Print the CDR of $.
end

define xacar
set $last=&(((scm_cell*) $arg0)->car)
output $last
echo \n
end
document xacar
Print the address of the CAR of $.
end

define xacdr
set $last=&(((scm_cell*) $arg0)->cdr)
output $last
echo \n
end
document xacdr
Print the address of the CDR of $.
end

define ximp
set $last=($ & 6) ? 1 : 0
output $last
echo \n
end
document ximp
Print 1 if $ is immediate, 0 otherwise.
end

define xvarvcell
xcdr
end
document xvarvcell
Print variable cell of $.
end

define xvariablep
set $last=(((scm_cell*) $arg0)->car) == scm_tc16_variable
output $last
echo \n
end
document xvariablep
Print 1 if $ is a variable, 0 otherwise
end

define xuchars
set $last=(unsigned char *) (((scm_cell*) $arg0)->cdr)
output $last
echo \n
end
document xuchars
Print string slot of $.
end

set $NumIsyms = 16
set $BoolF = (((0 + $NumIsyms) << 9) + 0x174L)
set $BoolT = (((1 + $NumIsyms) << 9) + 0x174L)

define xboolp
set $last=($ == $BoolF) || ($ == $BoolT)
output $last
echo \n
end
document xboolp
Print 1 if $ is a boolean, 0 otherwise.
end

define xvelts
set $last=(long *)((scm_cell*) $arg0)->cdr
output $last
echo \n
end
document xvelts
Print the VELTS of $.
end

define xlength
set $last=(((unsigned long)((scm_cell*) $arg0)->car)>>8)
output $last
echo \n
end
document xlength
Print the LENGTH of $.
end

define xncellp
set $last=((sizeof(scm_cell)-1) & (int)$arg0)
output $last
echo \n
end
document xncellp
Is $ a not a cell?
end

define xcellp
set $last=!((sizeof(scm_cell)-1) & (int)$arg0)
output $last
echo \n
end
document xcellp
Is $ a a cell?
end

define xchars
set $last=(char *)(((scm_cell*) $arg0)->cdr)
output $last
echo \n
end
document xchars
The CHARS of $
end

define xslots
set $last=((long *)(*((long *)(char *)(((scm_cell*) $arg0)->cdr)-1)))
output $last
echo \n
end
document xslots
The SLOTS of $
end

define xfunc
set $last=((long *)(*((long *)(char *)(((scm_cell*) $arg0)->cdr)-1))))[0]
output $last
echo \n
end
document xfunc
The FUNC of $
end

define xprops
set $last=((long *)(*((long *)(char *)(((scm_cell*) $arg0)->cdr)-1))))[1]
output $last
echo \n
end
document xprops
The PROPS of $
end

define xaprops
set $last=&(((long *)(*((long *)(char *)(((scm_cell*) $arg0)->cdr)-1)))[1])
output $last
echo \n
end
document xprops
The PROPS of $
end

define xtyp3
set $last=(7 & (int)(((scm_cell*) $arg0)->car))
output $last
echo \n
end
document xtyp3
Print the xtyp3 of $
end

define xtyp7
set $last=0x7f & (int)(((scm_cell*) $arg0)->car)
output $last
echo \n
end
document xtyp7
Print the TYP7 of $
end

define xtyp7s
set $last=0x7d & (int)(((scm_cell*) $arg0)->car)
output $last
echo \n
end
document xtyp7s
Print the TYP77s of $
end

define xtyp16
set $last=0xffff & (int)(((scm_cell*) $arg0)->car)
output $last
echo \n
end
document xtyp16
Print the TYP16 of $
end

define xtyp16s
set $last=0xfeff & (int)(((scm_cell*) $arg0)->car)
output $last
echo \n
end
document xtyp16s
Print the TYP16S of $
end

define xgctyp16
set $last=0xff7f & (int)(((scm_cell*) $arg0)->car)
output $last
echo \n
end
document xgctyp16
Print the GCTYP16 of $
end