This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Crashing gdb with python-prettyprinting
- From: Joachim Protze <joachim dot protze at wh2 dot tu-dresden dot de>
- To: gdb at sourceware dot org
- Date: Tue, 10 Aug 2010 12:57:04 +0200
- Subject: Re: Crashing gdb with python-prettyprinting
- References: <4C4EFC98.7080105@wh2.tu-dresden.de> <m3k4oc6ayc.fsf@fleche.redhat.com> <4C5FF231.7030203@zih.tu-dresden.de>
I found a little mistake in my condensed version of the python part.
Appended the corrected versions.
-Joachim
----------------- pptest.c -----------------
enum test_enum{
zero,
one,
two,
three,
four,
five,
};
typedef int testint;
enum test_enum get_test_enum(int i){
return (enum test_enum)i;
}
int main(int argc, char* argv[]){
testint a, b, c, d, e, f;
testint arr[]={0,1,2,3,4,5};
a=0;
b=1;
c=2;
d=3;
e=4;
f=5;
return 0;
}
----------------- pptest.py -----------------
import gdb
import re
class pp_test:
"""testprinter with code interaction"""
def __init__(self, id):
self.id = id
def to_string(self):
return str(gdb.parse_and_eval("get_test_enum(%i)" % self.id))
def lookup_function (val):
'''Look-up and return a pretty-printer that can print val.'''
type = val.type;
# If it points to a reference, get the reference.
if type.code == gdb.TYPE_CODE_REF:
type = type.target ()
typename = str(type)
for function in pp_dict:
if function.search (typename):
result = pp_dict[function] (val)
return result
return None
pp_dict = {}
pp_dict[re.compile('^testint$')] = lambda val: pp_test(val)
gdb.pretty_printers = []
gdb.pretty_printers.append (lookup_function)