How to see macro expansions step-by-step?

后端 未结 1 1185
刺人心
刺人心 2021-01-17 23:38

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

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 00:00

    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.

    0 讨论(0)
提交回复
热议问题