l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 Sep 26 12:32

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] gdb breakpoint redux
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] gdb breakpoint redux

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

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)

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).

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.


Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.