hellogcc / 100-gdb-tips Goto Github PK
View Code? Open in Web Editor NEWA collection of gdb tips. 100 maybe just mean many here.
License: Other
A collection of gdb tips. 100 maybe just mean many here.
License: Other
感觉有些实用的东西,比如core dump文件的分析,这在调试工程中是重点分析对象,应该介绍怎样用where、bt等命令分析core dump,从而找出问题所在,这才是关键呢。
做一个吧
这个太常用了
我阅读了“step-and-next-function.md” 以后,
如果函数没有调试信息,我就希望step不要进入函数里面去,
可是,我执行set step-mode off 以后,却发现step,依旧可以进入printf,printf是没有调试信息的函数,
请问是为啥呢?有什么办法可以,让step不要进入没有调试信息的函数里面去吗?
(gdb) set step-mode off
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/lc/Desktop/a.out
Breakpoint 1, main () at ss.c:13
13 int main(void) {
(gdb) s
14 ex_st st = {1, 2, 3, 4, PTHREAD_MUTEX_INITIALIZER};
(gdb)
15 printf("%d,%d,%d,%d\n", st.a, st.b, st.c, st.d);
(gdb)
__printf (format=0x4006d4 "%d,%d,%d,%d\n") at printf.c:28
28 printf.c: No such file or directory.
(gdb)
-pid number
-p number
连接到进程ID 号
-command file
-x file
从file文件执行命令
ex:ps -x | grep 进程名
获取进程id 例: 2018
ex: gdb -pid 2018 -x gdb.txt
gdb.txt文件内容格式如:
b main.cpp:20
c
p a
q
本来想自己写一个md文件上传到分支的, 但创建一看, 编辑格式没找到, 上传了一个空文档
$ gdb --write hello
GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello...done.
(gdb) disassemble /mr drawing
Dump of assembler code for function drawing:
6 {
0x00000000000007d0 <+0>: 55 push %rbp
0x00000000000007d1 <+1>: 48 89 e5 mov %rsp,%rbp
0x00000000000007d4 <+4>: 48 83 ec 10 sub $0x10,%rsp
0x00000000000007d8 <+8>: 89 7d fc mov %edi,-0x4(%rbp)
7 if (n != 0)
0x00000000000007db <+11>: 83 7d fc 00 cmpl $0x0,-0x4(%rbp)
0x00000000000007df <+15>: 74 0e je 0x7ef <drawing+31>
8 puts ("Try again?\nAll you need is a dollar, and a dream.");
0x00000000000007e1 <+17>: 48 8d 3d 40 01 00 00 lea 0x140(%rip),%rdi # 0x928
0x00000000000007e8 <+24>: e8 53 fe ff ff callq 0x640 <puts@plt>
9 else
10 puts ("You win $3000!");
0x00000000000007ef <+31>: 48 8d 3d 64 01 00 00 lea 0x164(%rip),%rdi # 0x95a
0x00000000000007f6 <+38>: e8 45 fe ff ff callq 0x640 <puts@plt>
11 }
0x00000000000007ed <+29>: eb 0c jmp 0x7fb <drawing+43>
0x00000000000007fb <+43>: 90 nop
0x00000000000007fc <+44>: c9 leaveq
0x00000000000007fd <+45>: c3 retq
End of assembler dump.
(gdb) set variable *(short*)0x00000000000007df=0x0ceb
(gdb) disassemble /mr drawing
Dump of assembler code for function drawing:
6 {
0x00000000000007d0 <+0>: 55 push %rbp
0x00000000000007d1 <+1>: 48 89 e5 mov %rsp,%rbp
0x00000000000007d4 <+4>: 48 83 ec 10 sub $0x10,%rsp
0x00000000000007d8 <+8>: 89 7d fc mov %edi,-0x4(%rbp)
7 if (n != 0)
0x00000000000007db <+11>: 83 7d fc 00 cmpl $0x0,-0x4(%rbp)
0x00000000000007df <+15>: eb 0c jmp 0x7ed <drawing+29>
8 puts ("Try again?\nAll you need is a dollar, and a dream.");
0x00000000000007e1 <+17>: 48 8d 3d 40 01 00 00 lea 0x140(%rip),%rdi # 0x928
0x00000000000007e8 <+24>: e8 53 fe ff ff callq 0x640 <puts@plt>
9 else
10 puts ("You win $3000!");
0x00000000000007ef <+31>: 48 8d 3d 64 01 00 00 lea 0x164(%rip),%rdi # 0x95a
0x00000000000007f6 <+38>: e8 45 fe ff ff callq 0x640 <puts@plt>
11 }
0x00000000000007ed <+29>: eb 0c jmp 0x7fb <drawing+43>
0x00000000000007fb <+43>: 90 nop
0x00000000000007fc <+44>: c9 leaveq
0x00000000000007fd <+45>: c3 retq
End of assembler dump.
(gdb) q
Segmentation fault
It's inconvenient for us to view the tips. As we should 1) clone the repository, 2) prepare go build environment, 3) generate html files.
So maybe it's better to publish it as a site (e.x., 100-gbd-tips.github.io). Two ways to do this:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.