GDB——使用GDB动态链接到进程

GDB支持链接到一个正在运行的进程。一遍检测它的运行状态。

这里写图片描述

示例过程:

Bakuman@Shaw-vm:~$ su
密码: 
root@Shaw-vm:/home/delphi# cd workspace/
root@Shaw-vm:/home/delphi/workspace# ls
ClearRTOS  embedded  func.c  test.c  test.out
root@Shaw-vm:/home/delphi/workspace# gdb  < ----- 启动gdb
GNU gdb (GDB) 7.2-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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) quit
root@Shaw-vm:/home/delphi/workspace# ps aux  < ---------- 查询系统中进程

Bakuman   8518  0.0  0.0   1684   248 pts/0    S+   16:07   0:00 ./test.out Shaw
root      8522  0.0  0.1   4584  1104 pts/1    R+   16:07   0:00 ps aux
root@Shaw-vm:/home/delphi/workspace# gdb
GNU gdb (GDB) 7.2-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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 8518    < ----------- 链接到目标进程
Attaching to process 8518
Reading symbols from /home/delphi/workspace/test.out...done.
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
0x00dac416 in __kernel_vsyscall ()   < -------- 目标进程停止执行
(gdb) continue
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x08048431 in func () at func.c:7

猜你喜欢

转载自blog.csdn.net/small_prince_/article/details/80681791
GDB