简体   繁体   English

如何逐步看宏扩展?

[英]How to see macro expansions step-by-step?

It seems Eclipse allows user to "see the expansion Step-by-Step" by pressing F2. 似乎Eclipse允许用户通过按F2“逐步查看扩展”。

I like this awesome feature. 我喜欢这个很棒的功能。 But can I do the same thing with just gcc or clang (or any tool)? 但是我可以用gccclang (或任何工具)做同样的事情吗?

-E option makes all macros fully expanded. -E选项使所有宏完全展开。 So I haven't found any alternative way to expand macros step-by-step. 所以我没有找到任何替代方法来逐步扩展宏。

Eclipse is big. Eclipse很大。 I hope I don't need to install it everywhere and have it launched all the time. 我希望我不需要在任何地方安装它并一直启动它。

It's a feature built into Eclipse. 它是Eclipse内置的一个功能。 If such a tool was provided as part of the GCC or Clang toolchain, Eclipse would have no need to implement it. 如果这样的工具是作为GCC或Clang工具链的一部分提供的,那么Eclipse就没有必要实现它。 Such a feature could be implemented as an extension to GCC using MELT . 这样的特征可以作为使用MELT的 GCC的扩展来实现。 LLVM (of which Clang is a part of) is designed to make something like this trivial. LLVM(其中Clang是其中的一部分)旨在使这样的事情变得微不足道。

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. 从理论上讲,您可以使用gdb (GCC附带的调试器)逐步执行程序,以查看程序中不同点的宏扩展。 If you want, you could try writing a gdb plugin in Python. 如果你愿意,你可以尝试用Python编写一个gdb插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM