[vox-tech] gdb breakpoint redux
Peter Jay Salzman
vox-tech@lists.lugod.org
Thu, 26 Sep 2002 12:18:13 -0700
ok, here is a list of items which can go into a gdb "expression", in
particular, the "condition" of a breakpoint, which is a boolean
expression.
1. logical operators.
break main if argc > 1
2. all user defined functions in your program.
break main if my_sanity_checker(var) != 0
3. glibc functions provided by libraries with debugging info, provided
they're linked into your code[1].
break main if index(mystring, 'a') == 0
(provided you have libc6-dbg installed)
4. glibc functions provided by libraries without debugging info
that return an int, provided they're linked into your code[1].
break main if strlen(string) == 0
5. glibc functions provided by libraries without debugging info and
which do NOT return an int, provided you use a "trick" of creating
a gdb variable[2] with the proper data type, provided they're linked
into your code[1].
break main if fabs(1.0 + $p(3.1415926535)) < .01
(see below for definition of $p)
[1]:
for statically linked programs, you need to actually _use_ the
function in your code to use it in a gdb expression.
for dynamically linked programs, you either need to use the function in
your code _or_ start the program from within gdb so that gdb can load in
code for the function (it seems like gdb can do this only once the
program has started to execute, not before).
[2]:
a perverse trick. without debugging information, gdb misinterprets
the return of cosine. even if you typecast it.
(gdb) p cos(0)
$4 = 14368
(gdb) p (double)cos(0.0)
$5 = 14336
however, you can get around this:
(gdb) set $p = (double (*) (double)) cos
(gdb) ptype $p
type = double (*)()
(gdb) p $p(0.0)
$2 = 1
(gdb) p $p(3.1415926535)
$11 = -1
which is correct.
ok, so now for the big question.
if someone thinks that any of this is wrong, or has more to add, i'd
appreciate the comment.
pete
--
Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D