RFC: Make iterator printers fail more gracefully

Jonathan Wakely jwakely@redhat.com
Thu Dec 15 18:55:00 GMT 2016


On 15/12/16 13:11 -0500, David Malcolm wrote:
>On Thu, 2016-12-15 at 17:39 +0000, Jonathan Wakely wrote:
>> This patch tries to improve the user experience when debugging
>> container iterators, for cases where some of the typedefs used by the
>> printers are not in the debuginfo, so gdb.lookup_type() calls fail.
>> That happens if the iterator's operator*() and operator->() haven't
>> been instantiated, or if they've been inlined.
>>
>> Currently this results in an exception:
>>
>> $1 = Python Exception <class 'ValueError'> Cannot find type
>> std::_List_iterator<int>::_Node:
>>
>> If the iterator being printed is part of some other object the whole
>> thing fails due to the exception.
>>
>> With this patch the iterator instead prints:
>>
>> $1 = <insufficient debuginfo for std::list iterator>
>>
>> and if it's a subobject the rest of the object is printed, with that
>> as the value of the iterator.
>>
>> 	* python/libstdcxx/v6/printers.py
>> (StdListIteratorPrinter.to_string):
>> 	Handle exception from failed type lookup and return user
>> -friendly
>> 	string.
>> 	(StdRbtreeIteratorPrinter.__init__): Handle exception from
>> failed
>> 	type lookup.
>> 	(StdRbtreeIteratorPrinter.to_string): Return user-friendly
>> string.
>>
>> Seem reasonable?
>>
>> I consider this a stop-gap until we have Xmethods for all our
>> iterator
>> types, then we'll be able to "print *iter" even without debuginfo for
>> all the iterator's members, and we can disable these printers.
>
>BTW, is it always a ValueError exception?
>
>(I'm a little wary of naked "except:" in Python, as it can catch
>*anything*, including syntax errors in the try/except-guarded code).

Good point. As far as I know, the gdb.lookup_type method will throw a
ValueError in the case I'm trying to fix. If it can throw other things
we can deal with them later by adding other handlers.



More information about the Gcc-patches mailing list