gcc -g prog.c -o prog
(gdb) print v
$1 = {num1 = 4, num2 = 1999759, more = {val1 = 99 'c', val2 = 100 'd', arr1 = {
0, 573440, 1146880, 1720320, 2293760, 2867200, 3440640, 4014080,
4587520, 5160960}}}
(gdb) set print pretty on
(gdb) print v
$2 = {
num1 = 4,
num2 = 1999759,
more = {
val1 = 99 'c',
val2 = 100 'd',
arr1 = {0, 573440, 1146880, 1720320, 2293760, 2867200, 3440640, 4014080,
4587520, 5160960}
}
}
(gdb) info frame
Stack level 0, frame at 0xbfe59340:
eip = 0x804834a in func_long_calc (c1.c:5); saved eip 0x80483bb
called by frame at 0xbfe59350
source language c.
Arglist at 0xbfe59338, args: i=3
Locals at 0xbfe59338, Previous frame's sp is 0xbfe59340
Saved registers:
ebp at 0xbfe59338, eip at 0xbfe5933c
(gdb) info locals
j = 6
plastic = 1
(gdb) p i
$2 = 567
(gdb) p/x i
$3 = 0x237
(gdb) p/o i
$4 = 01067
(gdb) p/t i
$5 = 1000110111
x/80c arr
x/20dw arr
x/10xg arr
set $foo = 2 * i
show convenience
init-if-undefined $foo = 2 * i
gcc -gdwarf-2 -g3 prog.c -o prog
Breakpoint 1, main () at c_preprocessor_macros.c:14
14 int state = STATE_BAD;
(gdb) p STATE_BAD
$1 = 1
(gdb) info macro STATE_BAD
Defined at /home/choo/work/lin-club/gdb_-_customize_it/gdb_source_examples/c_preprocessor_macros.c:4
#define STATE_BAD 1
Breakpoint 2, main () at c_preprocessor_macros.c:19
19 int person2_qualities = FLAG_SMART | FLAG_TALL | FLAG_HEAVY;
(gdb) macro expand FLAG_SMART | FLAG_TALL | FLAG_HEAVY
expands to: 2 | 4 | 8
return 59
Breakpoint 1, func_long_calc (i=5000) at c1.c:5
5 int j = 5;
(gdb) list 8,10
8 for (plastic = 0; plastic < i; ++plastic) {
9 j += plastic;
10 }
(gdb) break 9 if plastic == 503
Breakpoint 4 at 0x804835a: file c1.c, line 9.
(gdb) cont
Continuing.
Breakpoint 4, func_long_calc (i=5000) at c1.c:9
9 j += plastic;
(gdb) print plastic
$1 = 503
watch *(char*)0x65476 == 0
checkpoint
restart <checkpoint id>
info checkpoints
delete checkpoint <checkpoint id>
struct list_node {
struct list_node *next;
void *data;
};
struct access_data {
unsigned int clock_ticks;
int count;
};
struct list_node *g_access_list_head;
define access_data_first
set $ad_curr = g_access_list_head
if $ad_curr == 0
print "(null)"
else
print *(struct access_data*)$ad_curr->data
end
end
document access_data_first
prints the first node in the global access_data list, or "(null)"
end
define access_data_next
if $ad_curr == 0
print "(null list)"
else
if $ad_curr->next == 0
print "(null next)"
else
set $ad_curr = $ad_curr->next
print *(struct access_data*)$ad_curr->data
end
end
end
Breakpoint 1, main () at c_list_gdb_macros.c:45
45 return 0;
(gdb) source c_list_gdb_macros.macros
(gdb) access_data_first
$1 = {clock_ticks = 0, count = 0}
(gdb) access_data_next
$2 = {clock_ticks = 1, count = 10}
(gdb) access_data_next
$3 = {clock_ticks = 2, count = 20}
(gdb) access_data_next
$4 = {clock_ticks = 3, count = 30}
(gdb) access_data_first
$5 = {clock_ticks = 0, count = 0}
define access_data_at
if $argc == 1
set $access_data_index = 0
set $ad_curr = g_access_list_head
while $access_data_index < $arg0
if $ad_curr == 0
loop_break
else
set $ad_curr = $ad_curr->next
end
set $access_data_index = $access_data_index + 1
end
if $ad_curr != 0
print *(struct access_data*)$ad_curr->data
end
else
print "missing index"
end
end
define hook-echo echo <<<--- end
define hookpost-echo echo --->>>\n end
(gdb) echo Hello World <<<---Hello World--->>> (gdb)
define hook-stop disable breakpoints end define hook-run enable breakpoints end define hook-continue enable breakpoints end
(gdb) info signals Signal Stop Print Pass to program Description SIGHUP Yes Yes Yes Hangup SIGINT Yes Yes No Interrupt SIGQUIT Yes Yes Yes Quit ...
(gdb) handle SIGHUP stop pass Signal Stop Print Pass to program Description SIGHUP No No Yes Hangup
(gdb) info threads 11 Thread 0xb35a8b90 (LWP 23534) 0xb7f3c410 in __kernel_vsyscall () 10 Thread 0xb3da9b90 (LWP 23533) 0xb7f3c410 in __kernel_vsyscall () 9 Thread 0xb45aab90 (LWP 23532) 0xb7f3c410 in __kernel_vsyscall () ... * 1 Thread 0xb7f3a940 (LWP 23522) 0xb7f3c410 in __kernel_vsyscall ()
set scheduler-locking off
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x0804853f in thread_func
at c_threads_sleep.c:24 thread 6
stop only in thread 6
breakpoint already hit 2 times
define my_thread_names set logging off set logging file /tmp/tmp_file_gdb_names set pagination off set logging overwrite on set logging redirect on set logging on thread apply all bt set logging off set logging redirect off set logging overwrite off set pagination on shell ./gdb_bt_to_name.pl /tmp/tmp_file_gdb_names shell rm -f /tmp/tmp_file_gdb_names end
fork()...
set follow-fork-mode <parent|child>
sleep(60), and attach to child with another gdb instance.
set detach-on-fork off
dlopen().
(gdb) b honolulu Function "honolulu" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (honolulu) pending. (gdb) info break Num Type Disp Enb Address What 1 breakpoint keep yhonolulu
gdb /usr/bin/python <script [script parameters]>