please HELP with GDB output redirect to GDB variable !!!

please HELP with GDB output redirect to GDB variable !!!

Post by Darmok and Jelad near Tenag » Thu, 06 Feb 1997 04:00:00



  I'm trying to come up with a user defined command for gdb that
automates a series of steps that I am using *all the time* ;-(
My difficulty is that I don't see any kind of command sequence
in gdb that i can use.

 Let me describe my (repititious) series of steps that I am
using :

I have a C program in my LINUX x86 environment, in which I have coded
an assert statement something like....

(line 50 of source file)     assert( ivar <= 0x13 );

which when compiled yields something like

0x804847a <main+6>:     cmpl   $0x13,0xfffffffc(%ebp)
0x804847e <main+10>:    jle    0x80484a0 <main+44>
0x8048480 <main+12>:    pushl  $0x80484d8
0x8048485 <main+17>:    pushl  $0x9
0x8048487 <main+19>:    pushl  $0x80484dd
0x804848c <main+24>:    pushl  $0x80484e7
0x8048491 <main+29>:    call   0x8048388 <__assert_fail>
0x8048496 <main+34>:    addl   $0x10,%esp
0x8048499 <main+37>:    leal   0x0(%esi),%esi /*just a nop statement*/
0x804849c <main+40>:    jmp    0x80484a0 <main+44>
0x804849e <main+42>:    leal   (%esi),%esi /* another nop */
0x80484a0 <main+44>:    movl   %ebp,%esp

Invariably my program crashes on this assertion, but not
after so many (variable number of ) iterations.
So after I have determined the program crashes here, I set
a breakpoint in the assertion after the condition fails,
like so...

gdb> info line 50
Line 50 of "main.c" starts at address 0x804847a <main+6> and ends
at 0x80484a0 <main+44>
gdb> disassemble 0x804847a 0x80484a0
gdb> # visually scan disassemble to locate sequences of 4 pushl(s)
gdb> #   before call to __assert_fail
gdb> # Set break on first of parameters pushed
gdb> break *0x8048480
gdb> r

call me lazy, but i get tired of typing the series of 4 or 5 lines
above.  The process to find the address to set this break is
completely automatic.  The problem is i don't know how to get
gdb to place it's text output from commands into a gdb variable
or convenience variable.  If that could be done, i can parse
out the informtion until i come up with the target break address.

Now I can run program again and catch it before funny stack business
happens, and have all stack frame information intact.  I am working
under a limitation that if I do let the assertion run full tilt,
gdb + assert() becomes confused and gdb loses access to the bottom
2 or three frames of information, which i need.

I know I could redefine the assert macro to be more in line with
what I need, but I would still like to know if one get read gdb's
output into a variable for future reference also.

  TIA greatly,
     Steve

--

*                                                                              *
I am become a Cantor Dust, the Ghostly Destroyer of Continuity
                                                  - apologies to R. Oppenheimer