使用info line命令来查看源代码在内存中的地址
(gdb) info line tst.c:func Line 5 of "tst.c" starts at address 0x8048456 and ends at 0x804845d .
#include<stdio.h>
void fun1()
{
int var1;
printf("hello world /n");
----
}
void fun2()
{
int var1;
printf("hello world /n");
fun1();
}
void fun3()
{
int var1;
printf("hello world /n");
fun2();
----
}
int main()
{
fun3();
return 0;
}
:~> gdb myStack
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-suse-linux"...
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) b fun1
Breakpoint 1 at 0x4005b0: file myStack.cpp, line 5.
(gdb) b fun2
Breakpoint 2 at 0x4005ca: file myStack.cpp, line 12.
(gdb) b fun3
Breakpoint 3 at 0x4005e8: file myStack.cpp, line 18.
(gdb) r
Starting program: /data/dreamliang/myStack
Breakpoint 3, fun3 () at myStack.cpp:18
18 printf("hello world /n");
(gdb) bt
#0 fun3 () at myStack.cpp:18
#1 0x0000000000400607 in main () at myStack.cpp:24
(gdb) bt1
Undefined command: "bt1". Try "help".
(gdb) bt
#0 fun3 () at myStack.cpp:18
#1 0x0000000000400607 in main () at myStack.cpp:24
(gdb) bt 1
#0 fun3 () at myStack.cpp:18
(More stack frames follow...)
(gdb) bt 2
#0 fun3 () at myStack.cpp:18
#1 0x0000000000400607 in main () at myStack.cpp:24
(gdb) c
Continuing.
Breakpoint 2, fun2 () at myStack.cpp:12
12 printf("hello world /n");
(gdb) bt
#0 fun2 () at myStack.cpp:12
#1 0x00000000004005fc in fun3 () at myStack.cpp:19
#2 0x0000000000400607 in main () at myStack.cpp:24
(gdb) up 1
#1 0x00000000004005fc in fun3 () at myStack.cpp:19
19 fun2();
(gdb) up 2
#2 0x0000000000400607 in main () at myStack.cpp:24
24 fun3();
(gdb) down 1
#1 0x00000000004005fc in fun3 () at myStack.cpp:19
19 fun2();
(gdb) down 2
#0 fun2 () at myStack.cpp:12
12 printf("hello world /n");
(gdb) f 1
#1 0x00000000004005fc in fun3 () at myStack.cpp:19
19 fun2();
(gdb) f 2
#2 0x0000000000400607 in main () at myStack.cpp:24
24 fun3();