I need to write a simple pretty printer for this:
Buf *in_file_buf
struct Buf {
PigList<char> list;
}
template<typename T>
struct PigList {
T *items;
size_t length;
size_t capacity;
}
I created a <executable-name>-gdb.py with this content
import gdb
class BufPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
return self.val['list']['items'].string()
gdb.pretty_printers['^Buf *$'] = BufPrinter
Nothing changed.
Extra links:
https://sourceware.org/gdb/onlinedocs/gdb/Python-Auto_002dloading.html
http://wiki.codeblocks.org/index.php/Pretty_Printers
http://tromey.com/blog/?p=524
What version of Python is supported by the gdb you are using?
Note: I have no idea what to do after you find out the version.
(gdb) python print sys.version
2.7.14 (default, Sep 18 2017, 09:26:14) [GCC 7.2.0 32 bit]
Tim S.
info auto-load python-scripts
Loaded Script
No C:\Users\MyUser\Downloads\pig-gdb.py
Not loaded, but it sees it...
show auto-load python-scripts
Auto-loading of Python scripts is on.
I think I got it
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Developer_Guide/debuggingprettyprinters.html
import gdb
class BufPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
return self.val['list']['items'].string()
def lookup_type (val):
print val.type
if str(val.type) == 'Buf':
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
return BufPrinter(val)
else:
print '>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<'
return None
gdb.pretty_printers.append(lookup_type)
python execfile("zig-gdb.py")
It reacted to str(val.type) == 'Buf', but the self.val['list']['items'].string() still doesn't work.
I have no idea what I'm doing
pig-gdb.py:
import gdb
def real_to_string(self):
# print self.val
return self.val['list']['items'].string()
def real_lookup_type(val):
# print val.type
# print 'fsjodifsiohfiosehfoshifhioehsfihseiofhs'
if str(val.type) == 'Buf':
print '!!!!!!!!!!!!!!!!!!!!!!!'
return BufPrinter(val)
else:
print '======================='
return None
class BufPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
return real_to_string(self)
def lookup_type (val):
return real_lookup_type(val)
gdb.pretty_printers.append(lookup_type)
python execfile("pig-gdb.py")
Spam this until it works:
p.py:
def real_to_string(self):
# print self.val
return '"' + self.val['list']['items'].string() + '"'
def real_lookup_type(val):
# print val.type
# print 'fsjodifsiohfiosehfoshifhioehsfihseiofhs'
if str(val.type) == 'Buf':
# print '!!!!!!!!!!!!!!!!!!!!!!!'
return BufPrinter(val)
# else:
# print '=======================>'
# print val.type
# print '<======================='
return None
This worked, but for some reason it doesn't autoload. Well, I guess copypasting an extra line at every debug session isn't that bad. Any ideas?
ollydbg, thanks, this worked.
Final Stable version
import gdb
def real_to_string(self):
# print self.val
return '"' + self.val['list']['items'].string() + '"'
def real_lookup_type(val):
# print val.type
# print 'fsjodifsiohfiosehfoshifhioehsfihseiofhs'
if str(val.type) == 'Buf':
# print '!!!!!!!!!!!!!!!!!!!!!!!'
return BufPrinter(val)
# else:
# print '=======================>'
# print val.type
# print '<======================='
return None
class BufPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
return real_to_string(self)
def lookup_type (val):
return real_lookup_type(val)
gdb.pretty_printers.append(lookup_type)