如何查看 C++ 程序的汇编代码? [英] How can I see the assembly code for a C++ program?

查看:49
本文介绍了如何查看 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,

  • 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.
    Use set disassembly-flavor intel if you prefer Intel syntax.
  • or the disassembly window of Visual Studio on Windows.

这篇关于如何查看 C++ 程序的汇编代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆