User forums > Help

[solved] Making pretty printers for gdb

(1/2) > >>

visir:
I need to write a simple pretty printer for this:


--- Code: ---Buf *in_file_buf

struct Buf {
    PigList<char> list;
}

template<typename T>
struct PigList {
    T *items;
    size_t length;
    size_t capacity;
}
--- End code ---

I created a <executable-name>-gdb.py with this content


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

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

stahta01:
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.


--- Code: ---(gdb) python print sys.version
2.7.14 (default, Sep 18 2017, 09:26:14)  [GCC 7.2.0 32 bit]

--- End code ---

Tim S.

visir:
Practically same

2.7.14 (default, Sep 18 2017, 09:17:44)  [GCC 7.2.0 64 bit (AMD64)]

visir:
info auto-load python-scripts


--- Code: ---Loaded  Script                                                                 
No      C:\Users\MyUser\Downloads\pig-gdb.py   
--- End code ---

Not loaded, but it sees it...

show auto-load python-scripts


--- Code: ---Auto-loading of Python scripts is on.
--- End code ---

visir:
I think I got it

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Developer_Guide/debuggingprettyprinters.html


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

--- End code ---


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


--- Code: ---info pretty-printer
--- End code ---

It reacted to str(val.type) == 'Buf', but the self.val['list']['items'].string() still doesn't work.

Navigation

[0] Message Index

[#] Next page

Go to full version