Hi GCC list, I have implemented a GCC plugin that I have found useful for doing dynamic program analysis, debugging, and performance tuning in concurrent code.
The plugin is called CTraps, short for Communication Traps. The main idea behind CTraps is that a compiler pass implemented as a GCC plugin instruments instructions that access memory locations that might be shared between threads. The instrumentation inserts a function call before such accesses. The CTraps runtime library implements the instrumentation function. It uses a "last writer table" to track the thread and instruction that last wrote to shared memory locations. When the program crashes, the last writer table is preserved in the core dump. If a threading bug is to blame for the failure, the last writer table can help diagnose it by revealing unintentional data sharing. In addition to maintaining the last writer table, CTraps exposes a plugin API that allows developers to implement their own plugins. Plugins can define functions that are called on every "communicating" instrumented memory access. An access is communicating if it accesses a memory location that the last writer table indicates was last written by an instruction in another thread. Using this plugin API, developers can implement concurrency debugging analyses, parallelism-aware performance profilers, and more. If you are interested in this project, check it out at https://github.com/blucia0a/CTraps-gcc Check out the included documentation for information on how to build, run, and extend CTraps. Feel free to email me with bug reports, questions, and comments about this work at blu...@gmail.com If you are interested in my other work on program analysis for finding and avoiding bugs in concurrent programs, visit my website: http://brandonlucia.com Thanks! -Brandon Lucia