Skip to content

Commit 6717eab

Browse files
committed
fix import error
1 parent cf5428e commit 6717eab

File tree

9 files changed

+24
-17
lines changed

9 files changed

+24
-17
lines changed

.gdbinit

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
source prelude.py
2-
source commands.py

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# gdb_scripts
22

33
Some python utils for gdb debugging.
4+
5+
# usage
6+
source this package

__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import prelude
2-
import commands
3-
import pretty_printers
2+
3+
from commands import dt
4+
from commands import stackfold
5+
from commands import stackwalk
6+
7+
from pretty_printers import pointer

commands/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
import dt
2-
import stackfold
3-
import stackwalk

common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def is_null(val):
4040

4141
def deref(pointer):
4242
'''dereference pointer to get value'''
43+
# TODO: use loop to support nested pointers
4344
val = pointer
4445
if val.type.code == gdb.TYPE_CODE_PTR:
4546
if is_null(val):

prelude.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import os
33
def add_paths():
4-
pythondir = '/usr/share/gcc-8.3.0/python'
4+
pythondir = '/usr/share/gcc/python'
55
print('add to the python sys.path: '+ pythondir)
66
sys.path.append(pythondir)
77
scripts_folder = os.path.dirname(__file__)

pretty_printers/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
import guid
2-
import pointer

pretty_printers/guid.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# 1 create a printer with to_string method
33
# 2 create a printer matcher
44
# 3 register the printer to the gdb.
5-
import re
65
import gdb.printing
7-
import sys
8-
6+
import re
7+
PAT = re.compile('^(DSS_ID|_GUID)')
98

10-
class GUIDPrinter:
9+
class Printer:
1110
'''
1211
Currently, only tests in Linux
1312
typedef struct _GUID
@@ -43,7 +42,7 @@ def to_string(self):
4342
def build_pretty_printer():
4443
pp = gdb.printing.RegexpCollectionPrettyPrinter("Base")
4544
print('register DSS ID printer.')
46-
pp.add_printer('DSS ID printer', '^(DSS_ID|_GUID)', GUIDPrinter)
45+
pp.add_printer('DSS ID printer', PAT, Printer)
4746
return pp
4847

4948

pretty_printers/pointer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
# # 2 create a printer matcher
44
# # 3 register the printer to the gdb.
55

6-
import re
76
import gdb.printing
87
import gdb
98
import traceback
109
import common
10+
from pretty_printers import guid
11+
1112
gPrinters = {}
13+
def register_pointer_printer(pat, printer_class):
14+
global gPrinters
15+
print(f'register {printer_class} disptacher for pointee {pat}')
16+
gPrinters[pat] = printer_class
17+
18+
register_pointer_printer(guid.PAT, guid.Printer)
1219

1320
def lookup_pretty_printer(val):
1421
try:
@@ -25,7 +32,7 @@ def lookup_pretty_printer(val):
2532
return None
2633

2734

28-
print('register disptacher for pointer.')
35+
2936
gdb.printing.register_pretty_printer(
3037
gdb.current_objfile(),
3138
lookup_pretty_printer, replace=True

0 commit comments

Comments
 (0)