How to see macro expansions step-by-step?
Asked Answered
D

1

12

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.

Duvalier answered 18/2, 2016 at 3:31 Comment(2)
-E option is for gcc . I don't quite understand what alternative you want .Parashah
@Parashah I want a lightweight way to see the step-by-step expansion, like the feature in EclipseDuvalier
D
1

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.

Dalhousie answered 18/2, 2016 at 5:29 Comment(1)
maros are fully expanded at(or before, by preprocessor) compile time, how can gdb see expansion steps at runtime.Bounded

© 2022 - 2024 — McMap. All rights reserved.