The C and C++ preprocessors are famous for allowing users to write opaque, hard-to-follow code through macros. These downsides are tolerated because m

Search code, repositories, users, issues, pull requests...

submited by
Style Pass
2024-05-09 19:30:19

The C and C++ preprocessors are famous for allowing users to write opaque, hard-to-follow code through macros. These downsides are tolerated because macros also allow code to have a high level of abstraction, which can reduce software complexity and improve developer productivity. Doing the good parts takes dicipline; eliminating the bad parts takes refactoring, and importantly, debugging. PPstep is the debugger that macro writers can use to do that.

To try it out, run ppstep your-source-file.c. ppstep supports common preprocessor flags like --include/-I to add include directories, --define/-D to define macros, and --undefine/-U to undefine macros, if you need to do any of those things too.

You should see a prompt that looks like pp>. From here, you can step forward through preprocessing steps using the step or s commands, and see visually what each step does. You will notice that the prompt will have a suffix added to it to show what the current preprocessing step is, such as called, expanded, rescanned, or lexed. Newly-encountered macro calls, finished macro expansions, and finished macro rescans are each color-coded in the visual output so you can see where changes were made. When you are done, you can use the quit or q commands to exit the prompt.

While stepping, if you want to see the history of pending macro expansions, you can use the backtrace or bt commands. You can also look into the future to see what the anticipated macro rescans will be by using the forwardtrace or ft commands.

Leave a Comment