User forums > Help

[solved] Making pretty printers for gdb

<< < (2/2)

visir:
I have no idea what I'm doing

pig-gdb.py:


--- Code: ---
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)

--- End code ---


--- Code: ---python execfile("pig-gdb.py")
--- End code ---

Spam this until it works:

p.py:


--- Code: ---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

--- End code ---


--- Code: ---python execfile("p.py")
--- End code ---

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:
Some hint: issue when I try to auto load GDB python pretty printer
If I remember correctly, if you have a a.dll, and a-gdb.py in the same folder, if your gdb load the a.dll, it should automatically load the py file.

visir:
ollydbg, thanks, this worked.

Final Stable version


--- Code: ---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)



--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version