影视网站wordpress,wordpress问答插件美化,做电影网站教程,沈阳做网站价格文章目录 1.1 gdb 调试回顾1.1.1 gdb list 命令介绍 1.2 反汇编命令 dis 介绍1.2.1 如何设置 gdb 汇编代码的格式 1.1 gdb 调试回顾
在GNU调试器#xff08;GDB#xff09;中#xff0c;有许多命令可以帮助我们调试应用程序。 gdb: 这是一个强大的Unix下的程序调试工具。以… 文章目录 1.1 gdb 调试回顾1.1.1 gdb list 命令介绍 1.2 反汇编命令 dis 介绍1.2.1 如何设置 gdb 汇编代码的格式 1.1 gdb 调试回顾
在GNU调试器GDB中有许多命令可以帮助我们调试应用程序。 gdb: 这是一个强大的Unix下的程序调试工具。以下是使用gdb的一个简单示例
$ gdb ./test在这个例子中我们启动了gdb并将我们的程序test作为参数传递。 可执行程序 test 是由下面代码使用gcc -g -O0 test.c -o test编译出来
#includestdio.h
#includestdlib.hstatic int bar(void)
{char *p NULL;printf(I am barI will core dump\n);printf(%s,p);*p 0x0;return 0;
}static int foo(void)
{int i ;printf(I am foo,I will call bar\n);bar();return 0;
}int main(void)
{printf(I am main, I wll can foo\n);foo();return 0;
}1.1.1 gdb list 命令介绍
llist: llist 命令用于显示当前源代码的行列表包括当前行以及周围的几行代码。这对于查看代码的上下文非常有用。
例如你可以使用llist命令来显示当前行及周围的10行代码
For help, type help.
Type apropos word to search for commands related to word...
Reading symbols from test...
(gdb) list 10
5 {
6 char *p NULL;
7
8 printf(I am barI will core dump\n);
9 printf(%s, p);
10
11 *p 0x0;
12
13 return 0;
14 }
(gdb)这将显示源代码的当前行周围的文本。
1.2 反汇编命令 dis 介绍
dis/disassemble: 这个命令用于查看汇编代码。例如我们可以使用以下命令查看当前函数的汇编代码
(gdb) disassemble或者查看指定函数的汇编代码
[11:01:22]samcodingcos-sam-laptop (*^~^*) ~/test gdb test
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 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:
https://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 test...
(gdb) dis foo
Bad breakpoint number foo
(gdb)从上面的信息可以看到gdb并没有对函数 foo 进行反汇编而是报出错误“Bad breakpoint number ‘foo’”甚是疑惑, 网上搜了一大圈也没找到原因!!
后来发现是在使用gdb时没有设置断点导致的如果按照下面方式则可以进行反汇编
For help, type help.
Type apropos word to search for commands related to word...
Reading symbols from test...
(gdb) b foo
Breakpoint 1 at 0x11bd: file test.c, line 19.
(gdb) dis foo
Bad breakpoint number foo
(gdb) disassemble foo
Dump of assembler code for function foo:0x00000000000011b5 0: endbr640x00000000000011b9 4: push %rbp0x00000000000011ba 5: mov %rsp,%rbp0x00000000000011bd 8: lea 0xe5f(%rip),%rax # 0x20230x00000000000011c4 15: mov %rax,%rdi0x00000000000011c7 18: call 0x1060 putsplt0x00000000000011cc 23: call 0x1169 bar0x00000000000011d1 28: mov $0x0,%eax0x00000000000011d6 33: pop %rbp0x00000000000011d7 34: ret
End of assembler dump.但是目前还不清楚为何使用 dis 命令不生效。 如下是使用 arm gdb 的反汇编示例(前提要有arm gcc 编译出来的 .o文件)
arm-none-eabi-gdb ./build/bsp/sam/sam_demo/common/soc.o
This GDB was configured as --hostx86_64-linux-gnu --targetarm-none-eabi.
Reading symbols from ./build/bsp/sam/sam_demo/common/soc.o...
(gdb) b reboot
Breakpoint 1 at 0x214: file /mnt/user_home/sam/rt-thread/bsp/sam/sam_demo/common/soc.c, line 36.
(gdb) disassemble reboot
Dump of assembler code for function reboot:0x00000208 0: push {r7}0x0000020a 2: sub sp, #200x0000020c 4: add r7, sp, #00x0000020e 6: mov r3, r00x00000210 8: str r1, [r7, #0]0x00000212 10: strb r3, [r7, #7]0x00000214 12: ldr r3, [pc, #24] ; (0x230 reboot40)0x00000216 14: str r3, [r7, #12]0x00000218 16: dmb sy0x0000021c 20: ldr r2, [pc, #20] ; (0x234 reboot44)0x0000021e 22: ldr r3, [r7, #12]0x00000220 24: str r3, [r2, #0]0x00000222 26: nop0x00000224 28: adds r7, #200x00000226 30: mov sp, r70x00000228 32: ldr.w r7, [sp], #40x0000022c 36: bx lr0x0000022e 38: nop0x00000230 40: lsls r3, r4, #120x00000232 42: movs r0, #33 ; 0x210x00000234 44: asrs r0, r0, #20x00000236 46: mov r1, r0
End of assembler dump.
(gdb)另外一种查看汇编代码的方式是使用 x 命令如下显示 pc 开始的 3 条指令
Breakpoint 1, foo () at test.c:19
19 printf(I am foo,I will call bar\n);
(gdb) x/3i $pc0x5555555551bd foo8: lea 0xe5f(%rip),%rax # 0x5555555560230x5555555551c4 foo15: mov %rax,%rdi0x5555555551c7 foo18: call 0x555555555060 putsplt
(gdb)arm gdb 反汇编示例 查看0x0地址开始后面的10条汇编
arm-none-eabi-gdb ./build/bsp/sam/sam_demo/common/soc.o
...
(gdb) x/3i 0x00x0 __NVIC_SetPriority: push {r7}0x2 __NVIC_SetPriority2: sub sp, #120x4 __NVIC_SetPriority4: add r7, sp, #0
(gdb) x/10i 0x000000000x0 __NVIC_SetPriority: push {r7}0x2 __NVIC_SetPriority2: sub sp, #120x4 __NVIC_SetPriority4: add r7, sp, #00x6 __NVIC_SetPriority6: mov r3, r00x8 __NVIC_SetPriority8: str r1, [r7, #0]0xa __NVIC_SetPriority10: strh r3, [r7, #6]0xc __NVIC_SetPriority12: ldrsh.w r3, [r7, #6]0x10 __NVIC_SetPriority16: cmp r3, #00x12 __NVIC_SetPriority18: blt.n 0x2a __NVIC_SetPriority420x14 __NVIC_SetPriority20: ldr r3, [r7, #0]
(gdb)1.2.1 如何设置 gdb 汇编代码的格式
GDB 主要支持两种汇编代码格式 ATT风格这是GDB的默认汇编代码格式是在Unix和GNU系统中常见的格式。在ATT风格的汇编代码中操作数的顺序是“源目标”立即数和绝对地址值以美元符号$作为前缀寄存器名称以百分号%作为前缀。 Intel风格这是在Intel文档和Windows环境中常见的格式。在Intel风格的汇编代码中操作数的顺序是“目标源”立即数和绝对地址值没有特殊的前缀寄存器名称也没有特殊的前缀。
可以使用 show disassembly-flavor 命令查看当前的汇编代码风格。例如
For help, type help.
Type apropos word to search for commands related to word...
Reading symbols from test...
(gdb) dis foo
Bad breakpoint number foo
(gdb) show disassembly-flavor
The disassembly flavor is att.
(gdb)可以看到默认是 ATT风格。
如果你想要改变汇编代码风格你可以使用 set disassembly-flavor 命令来设置新的风格。例如如果你想要设置成Intel风格你可以这样做
(gdb) set disassembly-flavor intel如果你想要设置成ATT风格你可以这样做
(gdb) set disassembly-flavor att
文章转载自: http://www.morning.jljwk.cn.gov.cn.jljwk.cn http://www.morning.lsnbx.cn.gov.cn.lsnbx.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn http://www.morning.xxsrm.cn.gov.cn.xxsrm.cn http://www.morning.knswz.cn.gov.cn.knswz.cn http://www.morning.rcdmp.cn.gov.cn.rcdmp.cn http://www.morning.hkgcx.cn.gov.cn.hkgcx.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.frxsl.cn.gov.cn.frxsl.cn http://www.morning.grbgn.cn.gov.cn.grbgn.cn http://www.morning.nqmwk.cn.gov.cn.nqmwk.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.xyjlh.cn.gov.cn.xyjlh.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.mghgl.cn.gov.cn.mghgl.cn http://www.morning.brfxt.cn.gov.cn.brfxt.cn http://www.morning.ltqzq.cn.gov.cn.ltqzq.cn http://www.morning.zgztn.cn.gov.cn.zgztn.cn http://www.morning.tzzkm.cn.gov.cn.tzzkm.cn http://www.morning.srgnd.cn.gov.cn.srgnd.cn http://www.morning.hmmnb.cn.gov.cn.hmmnb.cn http://www.morning.rtlrz.cn.gov.cn.rtlrz.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.yjfmj.cn.gov.cn.yjfmj.cn http://www.morning.sqmbb.cn.gov.cn.sqmbb.cn http://www.morning.mwpcp.cn.gov.cn.mwpcp.cn http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn http://www.morning.cyfsl.cn.gov.cn.cyfsl.cn http://www.morning.lgsqy.cn.gov.cn.lgsqy.cn http://www.morning.rykmz.cn.gov.cn.rykmz.cn http://www.morning.hlxpz.cn.gov.cn.hlxpz.cn http://www.morning.mfmx.cn.gov.cn.mfmx.cn http://www.morning.jmdpp.cn.gov.cn.jmdpp.cn http://www.morning.dmtwz.cn.gov.cn.dmtwz.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.prsxj.cn.gov.cn.prsxj.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn http://www.morning.tkzqw.cn.gov.cn.tkzqw.cn http://www.morning.sgcdr.com.gov.cn.sgcdr.com http://www.morning.kqfdrqb.cn.gov.cn.kqfdrqb.cn http://www.morning.thntp.cn.gov.cn.thntp.cn http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn http://www.morning.prgnp.cn.gov.cn.prgnp.cn http://www.morning.wglhz.cn.gov.cn.wglhz.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.rydhq.cn.gov.cn.rydhq.cn http://www.morning.npbgj.cn.gov.cn.npbgj.cn http://www.morning.rlsd.cn.gov.cn.rlsd.cn http://www.morning.srgsb.cn.gov.cn.srgsb.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.ckfqt.cn.gov.cn.ckfqt.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.gkxyy.cn.gov.cn.gkxyy.cn http://www.morning.krgjc.cn.gov.cn.krgjc.cn http://www.morning.cjxqx.cn.gov.cn.cjxqx.cn http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn http://www.morning.fkmqg.cn.gov.cn.fkmqg.cn http://www.morning.aa1585.com.gov.cn.aa1585.com http://www.morning.pcqxr.cn.gov.cn.pcqxr.cn http://www.morning.qtzk.cn.gov.cn.qtzk.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.fxzlg.cn.gov.cn.fxzlg.cn http://www.morning.xwgbr.cn.gov.cn.xwgbr.cn http://www.morning.lmhh.cn.gov.cn.lmhh.cn http://www.morning.msgcj.cn.gov.cn.msgcj.cn http://www.morning.fwjfh.cn.gov.cn.fwjfh.cn http://www.morning.kkwgg.cn.gov.cn.kkwgg.cn http://www.morning.hxmqb.cn.gov.cn.hxmqb.cn http://www.morning.mknxd.cn.gov.cn.mknxd.cn http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn http://www.morning.kqfdrqb.cn.gov.cn.kqfdrqb.cn http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn http://www.morning.jxltk.cn.gov.cn.jxltk.cn http://www.morning.rnpt.cn.gov.cn.rnpt.cn http://www.morning.bprsd.cn.gov.cn.bprsd.cn http://www.morning.hyhqd.cn.gov.cn.hyhqd.cn