如何逐步查看宏扩展? [英] How to see macro expansions step-by-step?
问题描述
我喜欢这个真棒功能。但是我可以用 gcc
或 clang
(或任何工具)做同样的事情吗?
-E
选项使所有宏完全展开。所以我还没有找到任何其他的方法来逐步扩展宏。
Eclipse很大。我希望我不需要在任何地方安装它并始终启动。
这是Eclipse中内置的一项功能。如果这样的工具是作为GCC或Clang工具链的一部分提供的,那么Eclipse就不需要实现它。这种功能可以通过使用 MELT 作为GCC的扩展来实现。 LLVM(Clang是其中的一部分)旨在使这种微不足道。
有一点你必须记住,宏观扩张是一件棘手的事情。在任何给定的时间点,宏定义可能会改变或根本不存在。理论上,您可以使用 gdb
(GCC附带的调试程序)遍历程序,以查看程序中不同点的宏扩展。如果你愿意,你可以尝试在Python中编写 gdb
插件。
It seems Eclipse allows user to "see the expansion Step-by-Step" by pressing F2.
I like this awesome feature. But can I do the same thing with just gcc
or clang
(or any tool)?
-E
option makes all macros fully expanded. So I haven't found any alternative way to expand macros step-by-step.
Eclipse is big. I hope I don't need to install it everywhere and have it launched all the time.
It's a feature built into Eclipse. If such a tool was provided as part of the GCC or Clang toolchain, Eclipse would have no need to implement it. Such a feature could be implemented as an extension to GCC using MELT. LLVM (of which Clang is a part of) is designed to make something like this trivial.
One thing you have to keep in mind that macro expansion is a tricky business. At any given point in time, a macro definition may change or not exist at all. Theoretically you could use gdb
(the debugger that comes with GCC) to step through your program to see macro expansions at different point in the program. If you want, you could try writing a gdb
plugin in Python.
这篇关于如何逐步查看宏扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!