手头有C/C++源代码,想查看对应的汇编代码。
1. 工具列表
- Compiler Explorer (https://godbolt.org/)
- GDB
- LLDB
- Visual Studio
- WinDBG
- VSCode
- CLion
- GCC
- 二进制工具 objdump/readelf/otool/…
2. Compiler Explorer
3. GDB
g++ test.cpp
gdb ./a.out
(gdb) disassemble main
3. LLDB
clang++ test.cpp
lldb ./a.out
(lldb) disassemble --name main
4. Visual Studio
若要启用“反汇编”窗口,请在“工具”>“选项”>“调试”下,选择“启用地址级调试” 。
若要在调试期间打开“反汇编”窗口,请选择“窗口”>“反汇编”或按 Alt+8 。
5. WinDBG
微软的WinDBG把反汇编叫做 unassemble. 对于函数的 unassemble, 使用 uf
命令。
WinDBG 经典版和 WinDBG 新版(一般带Preview字样;基本上要从 Windows Store 下载)应该只有UI的差别,内置命令一样。
WinCBD 和 WinDBG 也基本一样。
2023.10.24 今天打开 WinDBG Preview, 提示说已经有正式版了
6. VSCode
安装 CodeLLDB 插件。
编译生成 compile_commands.json 文件。
编写 launch.json 和 tasks.json 来描述构建步骤。
在命令面板中输入 ”打开反汇编视图”
7. CLion
CLion 是商业软件,需要付费购买;或者用开源项目申请License,需要开源项目有一定活跃度。
编译,设置断点,然后按两下 shift
召唤出命令快捷窗口,输入 “disasembly” 召唤出反汇编窗口:
8. GCC
-S
选项能生成汇编文件。
g++ test.cpp -S
9. 二进制工具 objdump/readelf/otool
objdump -d a.out -j .rodata
x. References
- https://www.cnblogs.com/sunylat/p/6250809.html
- https://learn.microsoft.com/zh-cn/visualstudio/debugger/how-to-use-the-disassembly-window?view=vs-2022
- https://lldb.llvm.org/use/map.html
- https://reverseengineering.stackexchange.com/questions/30931/how-to-disassemble-an-entire-function-in-windbg
- https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/uf--unassemble-function-