上图说gdb不加-g参数可以看到内存地址,我试验的结果却不是这样的:
~/Desktop/hello$ gcc hello.c -o hello
~/Desktop/hello$ ls
hello hello.c
:~/Desktop/hello$ gdb hello
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/shkh/Desktop/hello/hello...(no debugging symbols found)...done.
(gdb) l
No symbol table is loaded. Use the "file" command.
(gdb) file
No executable file now.
No symbol file now.
(gdb) r
Starting program:
No executable file specified.
Use the "file" or "exec-file" command.
(gdb) exec-file
No executable file now.
我的结论:
gdb的使用有一个前提,就是要有源代码,编译的时候加-g参数。
问题来了:
如果我手上没有源码,只有可执行程序,如何通过终端直接读写内存堆栈?