De
BUG  with
GDB

                                                                                                                                                                << CONTENTS >>

                    Example sessions Debugging with gdb:

                         GDB Debugging with multiple functions:

HP gdb 4.0 for HP Itanium (32 or 64 bit) and target HP-UX 11.2x.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 4.0 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.

>> Warrenty messages (version informations) from gdb ( to avoid this use gdb -q)

(gdb) file test06
Reading symbols from test06...done.
(gdb) info functions
All defined functions:

File test06.c:
void fun(int);
int main();
void subfun();

Non-debugging symbols:
        0x04000ae0  .PLT0
        0x04000ae0  .bortext
        0x04000b20  _etext
        0x04000b20  _etext_f

>> We can find the functions which are being currenly used

(gdb) rbp

Breakpoints set from 1 to 3
Type commands to execute when this breakpoint is hit (one command per line).
End with a line saying just "end".
>info variables
>end

>> Setting break points in all functions. If you enter in to that function execute info variables command there.
>> end(ding) the break point settings

(gdb) r
Starting program: /muthu/gdbtest/test06

Breakpoint 2, main () at test06.c:6
6       int a=10;
All defined variables:

File test06.c:
int a;

Non-debugging symbols:
        0x04000000  __text_start
        0x04000000  __text_start_f
        0x04000194  .note.hpux_options
        0x040001d0  .dynamic
        0x040001d0  _DYNAMIC
        0x04000290  .dynsym
        0x040004b0  .dynstr
        0x04000660  .hash
        0x04000734  .rela.plt
        0x04000740  .IA_64.unwind_hdr
        0x04000740  __unwind_header
        0x04000758  .IA_64.unwind
        0x0400077c  .IA_64.unwind_info
---Type <return> to continue, or q <return> to quit---q
Quit

>> Variables information on the current function (main)

(gdb) s
7       int *b=&a;
(gdb)
8       printf("Address%d\n",&b);
(gdb)
Address2147480996
9       fun(10);
(gdb)

Breakpoint 1, fun (b=10) at test06.c:14

>> gdb is passing the first function fun() after main. So info variables are executed here..

< snip......... for info variables as like in main() >

(gdb)
The Value is 10
15      subfun();
(gdb)

Breakpoint 3, subfun () at test06.c:19
19      printf("you are at sub function\n");
>> gdb is passing the first function fun() after main. So info variables are executed here..
< snip......... for info variables as like in main() >


(gdb) where
#0  subfun () at test06.c:19
#1  0x4000a50:0 in fun (b=10) at test06.c:15
#2  0x4000990:0 in main () at test06.c:9

>> To get the stack trace or to know where we are then use where or backtrace(bt)

(gdb) info frame 
Stack level 0, frame at 0x200000007ffff590:
 ip = 0x4000a80:1 in subfun (test06.c:19); saved ip 0x4000a50:0
 called by frame at 0x200000007ffff590
 source language c.
 Arglist at 0x200000007ffff590, args:
 Locals at 0x200000007ffff590, Previous frame's sp is 0x200000007ffff590
 Saved registers:
  gr32 at 0x20000000679ff2b8, gr33 at 0x20000000679ff2c0,
  gr34 at 0x20000000679ff2c8, gr35 at 0x20000000679ff2d0,
  gr36 at 0x20000000679ff2d8, gr37 at 0x20000000679ff2e0,
  gr38 at 0x20000000679ff2e8, gr39 at 0x20000000679ff2f0,
  gr40 at 0x20000000679ff2f8

>> to know about every frame details in the stack trace use info frame <frame-number>

(gdb) s

you are at sub function
20      }
(gdb) s
fun (b=10) at test06.c:16
16      }
(gdb) where
#0  fun (b=10) at test06.c:16
#1  0x4000990:0 in main () at test06.c:9

>> We are now in fun() and returned from subfun()

(gdb) s
main () at test06.c:10
10      return 0;
(gdb) where
#0  main () at test06.c:10

>> we are now in main() and returned from fun,subfun()

(gdb) s
0x20000000679abcc0:0 in main_opd_entry+0x50 () from /usr/lib/hpux32/dld.so
(gdb)
Single stepping until exit from function main_opd_entry,
which has no line number information.
0x20000000679abc50:0 in enter_main_opd+0x40 () from /usr/lib/hpux32/dld.so
(gdb)
Single stepping until exit from function enter_main_opd,
which has no line number information.
0x20000000679b11d0:0 in dld_main_startup+0xf50 () from /usr/lib/hpux32/dld.so
(gdb)
Single stepping until exit from function dld_main_startup,
which has no line number information.
warning: Cannot insert breakpoint 0: in /usr/lib/hpux32/dld.so
warning: dld.so is a shared library and will never be loaded
warning: as private, so breakpoint 0 has been ignored.
warning: Temporarily disabling shared library breakpoints:
0

Program exited normally.

We can start debugging on big source files easily!!
                  

DEBUGGING EXAMPLES                                                        Muthukumar Kandasamy <[email protected]>
Hosted by www.Geocities.ws

1