How can I see the assembly code for a C++ program?(如何查看 C++ 程序的汇编代码?)
问题描述
如何查看 C++ 程序的汇编代码?
How can I see the assembly code for a C++ program?
有哪些流行的工具可以做到这一点?
What are the popular tools to do this?
推荐答案
询问编译器
如果您自己构建程序,您可以要求您的编译器发出汇编源代码.对于大多数 UNIX 编译器,使用 -S
开关.
如果您使用的是 GNU 汇编程序,则使用
-g -Wa,-alh
进行编译将在标准输出上提供混合的源代码和程序集(-Wa
询问编译器驱动程序将选项传递给汇编程序,-al
打开汇编列表,-ah
添加高级源代码"列表):
If you are using the GNU assembler, compiling with
-g -Wa,-alh
will give intermixed source and assembly on stdout (-Wa
asks compiler driver to pass options to assembler,-al
turns on assembly listing, and-ah
adds "high-level source" listing):
g++ -g -c -Wa,-alh foo.cc
对于 Visual Studio,使用 /FAsc代码>.
For Visual Studio, use /FAsc
.
如果你有一个编译好的二进制文件,
If you have a compiled binary,
- 在 UNIX 上使用
objdump -d a.out
(也适用于 cygwin), dumpbin/DISASM foo.exe
在 Windows 上.
- use
objdump -d a.out
on UNIX (also works for cygwin), dumpbin /DISASM foo.exe
on Windows.
调试器还可以显示反汇编.
Debuggers could also show disassembly.
- 在 GDB 中使用
disas
命令.
如果您更喜欢 Intel 语法,请使用set disassembly-flavor intel
. - 或 Windows 上 Visual Studio 的反汇编窗口.
- Use
disas
command in GDB.
Useset disassembly-flavor intel
if you prefer Intel syntax. - or the disassembly window of Visual Studio on Windows.
这篇关于如何查看 C++ 程序的汇编代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何查看 C++ 程序的汇编代码?


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01