查看汇编代码和C代码 [英] View Both Assembly and C code
问题描述
我们有没有办法使用gdb查看汇编代码和c代码.
Do we have a way to view assembly and c code both using gdb.
disassemble function_name仅显示汇编语言,我试图找到一种将c代码轻松映射到汇编语言的方法. 谢谢
disassemble function_name shows only assembly, I was trying to find a way to easliy map c code to assembly. Thanks
推荐答案
您可以在文本用户界面(TUI)模式下运行gdb:
You can run gdb in Text User Interface (TUI) mode:
gdb -tui <your-binary>
(gdb) b main
(gdb) r
(gdb) layout split
layout split
命令将窗口分为两部分-其中一部分显示源代码,另一部分显示相应的程序集.
其他一些技巧:
The layout split
command divides the window into two parts - one of them displaying the source code, the other one the corresponding assembly.
A few others tricks:
- 设置可拆卸口味的intel -如果您更喜欢intel表示法
- 设置print asm-demangle -在程序集视图中对C ++名称进行分拆
- ni -下一条指令
- si -步骤说明
- set disassembly-flavor intel - if your prefer intel notation
- set print asm-demangle - demangles C++ names in assembly view
- ni - next instruction
- si - step instruction
如果您不想使用TUI模式(例如,您的终端不喜欢它),您可以随时执行以下操作:
If you do not want to use the TUI mode (e.g. your terminal does not like it), you can always do:
x /12i $pc
这意味着从当前程序计数器地址打印12条指令-这也适用于上述技巧(分拆,步进指令等).
which means print 12 instructions from current program counter address - this also works with the tricks above (demangling, stepping instructions, etc.).
"x/12i $ pc"技巧在gdb和cgdb中均有效,而布局拆分"仅在gdb中有效.
The "x /12i $pc" trick works in both gdb and cgdb, whereas "layout split" only works in gdb.
享受:)
这篇关于查看汇编代码和C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!