gcc plugin for checking gdb's exception handlers

Tom Tromey tromey@redhat.com
Tue Nov 1 15:29:00 GMT 2011


I wrote a GCC plugin, using David Malcolm's excellent Python plugin, to
check for proper use of gdb exceptions in the Python code.  I added new
'gdb_throw' and 'gdb_nothrow' attributes and marked a couple spots in
the sources.  The plugin examines all the calls in a file and writes out
a sort of call graph as Python code.  Then, after rebuilding GDB with
the plugin in place, there is a second program that reads all the data,
propagates the "can-throw" property through the call graph, and reports
errors whenever a nothrow function is discovered to throw.  It reports
the path from the function to the throw, like this:

../../archer/gdb/python/python.c:481: error: function gdbpy_decode_line is marked nothrow but can throw
../../archer/gdb/python/python.c:497: info: via call to get_current_arch
../../archer/gdb/arch-utils.c:758: info: via call to get_selected_frame
../../archer/gdb/frame.c:1360: info: via call to error
../../archer/gdb/utils.c:830: info: via call to throw_verror


I also had it mark cleanup functions as 'nothrow', since I thought that
is either the rule or what the rule should be.  This showed a number of
errors, enough that I am not sure what I want to do about it yet.

I'm attaching the plugin and the analysis program.  If you run it
yourself, please note that it still emits some false reports.  You must
examine each one, especially the ones arising from indirect function
calls, to see whether it is real.

I plan to run it periodically to check for new bugs.  To that end I will
probably put in the needed gdb patch, also attached.

I filed a bug for all the reports in the Python code.

Tom

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: excheck.py
URL: <http://sourceware.org/pipermail/gdb/attachments/20111101/51b5dcab/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: exsummary.py
URL: <http://sourceware.org/pipermail/gdb/attachments/20111101/51b5dcab/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: P
URL: <http://sourceware.org/pipermail/gdb/attachments/20111101/51b5dcab/attachment-0002.ksh>


More information about the Gdb mailing list