如何查看由 gcc(任何风格)编译器为 C/C++ 程序生成的汇编代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1354899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:40:21  来源:igfitidea点击:

How can I see the assembly code that is generated by a gcc (any flavor) compiler for a C/C++ program?

c++cassemblycode-generation

提问by vehomzzz

I am trying to optimize a lot of multiplications and pointer arithmetics and would like to see what the compiler does underneath when I put in optimization flags.

我正在尝试优化很多乘法和指针算术,并希望看到当我放入优化标志时编译器在下面做了什么。

--Edit--

- 编辑 -

How to restrict it to a specific function or a code block?

如何将其限制为特定功能或代码块?

--Edit_2--

--编辑_2--

How to let gcc generate a less verbose assembly-code?

如何让 gcc 生成不那么冗长的汇编代码?

回答by P Shved

Add -Sswitch to your command line.

-Sswitch添加到命令行。

Edit: Do not forget that it will place the assembly to the files you specified under -oswitch.

编辑:不要忘记它会将程序集放置到您在-oswitch下指定的文件中。

回答by ChrisW

How to restrict it to a specific function or a code block?

如何将其限制为特定功能或代码块?

Put that function in a separate source file (and use a different command-line parameter for that one source file).

将该函数放在单独的源文件中(并为该源文件使用不同的命令行参数)。

回答by Chris

You could also run that program in a debugger like gdband use a disassembly view. In gdbyou could use the command disass/mto view the assembly mixed with the C code on the current location.

您还可以在调试器中运行该程序gdb并使用反汇编视图。在gdb可以使用的命令disass/m来查看与当前位置的C代码组件的混合。

回答by sean riley

You could stop you program at a breakpoint in the Visual Studio debugger and do "show assembly" and even step through it one instruction at a time.

您可以在 Visual Studio 调试器中的断点处停止编程并执行“显示程序集”,甚至一次单步执行一条指令。