File: printers.py

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (34 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gdb
import gdb.printing

class expression_ref_printer:
    def __init__(self, val):
        self.val = val

    def to_string(self):
        x = self.val['px']
# Apparently we (Object *) <number> doesn't work, but (reg_var* ) <number> does??
#        return gdb.parse_and_eval('((Object*) %s)->print()' % x)
        return "expression_ref: " + ('%s' % x) # + " " +x.type 

def expression_ref_lookup_function(val):
    if val.type.tag == 'expression_ref':
        return expression_ref_printer(val)
    return None

def register_bali_phy_printers(obj):
    if obj is None:
        obj = gdb
#    obj.pretty_printers.append(expression_ref_lookup_function)

# While I got the infrastructure working, there doesn't seem to be
# an easy way to call the E.px->print() from python.
#
# One suggestion would have bee something like:
#     gdb.parse_and_eval('Object::print(%s)' % x) to call x->print().
#
# From inside gdb, one can run:
#    python print gdb.parse_and_eval('E.px->print()')
# and get
#    "49".
# Apparently this uses the pretty-printer for strings.