diff --git a/scripts/gdb/commands.py b/scripts/gdb/commands.py index 998c15ac63b1506dec88060cd49b8cc8caff4da4..76d255fe2699a7084aad955ae8d2045d662b293c 100644 --- a/scripts/gdb/commands.py +++ b/scripts/gdb/commands.py @@ -1,3 +1,4 @@ +import sys import gdb import re @@ -199,12 +200,14 @@ class MegengineInfo(gdb.Command): return ["opr", "trf"] - -MegengineBacktrace() -MegengineBreakApply() -MegengineUp() -MegengineDown() -MegengineInfo() -MegengineWatch() - -gdb.Breakpoint("mgb::imperative::debug::notify_event(char const*)") \ No newline at end of file +if sys.version_info.major > 2: + MegengineBacktrace() + MegengineBreakApply() + MegengineUp() + MegengineDown() + MegengineInfo() + MegengineWatch() + + gdb.Breakpoint("mgb::imperative::debug::notify_event(char const*)") +else: + print("skip import commands") diff --git a/scripts/gdb/pretty_printers.py b/scripts/gdb/pretty_printers.py index d7dd65b63179dafbb8697c5941975431d5f50188..ef17f4ff331860a1850575a29efe4a47acd47070 100644 --- a/scripts/gdb/pretty_printers.py +++ b/scripts/gdb/pretty_printers.py @@ -1,3 +1,4 @@ +import sys import gdb import gdb.printing import gdb.types @@ -170,23 +171,26 @@ class SpanPrinter: yield "[{}]".format(i), (self.begin+i).dereference() -pp = gdb.printing.RegexpCollectionPrettyPrinter("MegEngine") +if sys.version_info.major > 2: + pp = gdb.printing.RegexpCollectionPrettyPrinter("MegEngine") # megdnn -pp.add_printer('megdnn::SmallVectorImpl', '^megdnn::SmallVector(Impl)?<.*>$', SmallVectorPrinter) -pp.add_printer('megdnn::TensorLayout', '^megdnn::TensorLayout$', ToStringPrinter) -pp.add_printer('megdnn::TensorShape', '^megdnn::TensorShape$', ToStringPrinter) + pp.add_printer('megdnn::SmallVectorImpl', '^megdnn::SmallVector(Impl)?<.*>$', SmallVectorPrinter) + pp.add_printer('megdnn::TensorLayout', '^megdnn::TensorLayout$', ToStringPrinter) + pp.add_printer('megdnn::TensorShape', '^megdnn::TensorShape$', ToStringPrinter) # megbrain -pp.add_printer('mgb::CompNode', '^mgb::CompNode$', ToStringPrinter) -pp.add_printer('mgb::Maybe', '^mgb::Maybe<.*>$', MaybePrinter) + pp.add_printer('mgb::CompNode', '^mgb::CompNode$', ToStringPrinter) + pp.add_printer('mgb::Maybe', '^mgb::Maybe<.*>$', MaybePrinter) # imperative -pp.add_printer('mgb::imperative::LogicalTensorDesc', '^mgb::imperative::LogicalTensorDesc$', LogicalTensorDescPrinter) -pp.add_printer('mgb::imperative::OpDef', '^mgb::imperative::OpDef$', OpDefPrinter) -pp.add_printer('mgb::imperative::Subgraph', '^mgb::imperative::Subgraph$', ReprPrinter) -pp.add_printer('mgb::imperative::EncodedSubgraph', '^mgb::imperative::EncodedSubgraph$', ReprPrinter) + pp.add_printer('mgb::imperative::LogicalTensorDesc', '^mgb::imperative::LogicalTensorDesc$', LogicalTensorDescPrinter) + pp.add_printer('mgb::imperative::OpDef', '^mgb::imperative::OpDef$', OpDefPrinter) + pp.add_printer('mgb::imperative::Subgraph', '^mgb::imperative::Subgraph$', ReprPrinter) + pp.add_printer('mgb::imperative::EncodedSubgraph', '^mgb::imperative::EncodedSubgraph$', ReprPrinter) # imperative dispatch -pp.add_printer('mgb::imperative::ValueRef', '^mgb::imperative::ValueRef$', ToStringPrinter) -pp.add_printer('mgb::imperative::Span', '^mgb::imperative::Span<.*>$', SpanPrinter) -gdb.printing.register_pretty_printer(gdb.current_objfile(), pp) + pp.add_printer('mgb::imperative::ValueRef', '^mgb::imperative::ValueRef$', ToStringPrinter) + pp.add_printer('mgb::imperative::Span', '^mgb::imperative::Span<.*>$', SpanPrinter) + gdb.printing.register_pretty_printer(gdb.current_objfile(), pp) +else: + print("skip import pretty printers") def override_pretty_printer_for(val): @@ -201,4 +205,5 @@ def override_pretty_printer_for(val): return HandlePrinter(val) -gdb.pretty_printers.append(override_pretty_printer_for) +if sys.version_info.major > 2: + gdb.pretty_printers.append(override_pretty_printer_for) diff --git a/scripts/gdb/xmethods.py b/scripts/gdb/xmethods.py index 6f4d326ef0e2593ef4cabd58e3c40a77a40d73c5..9dfc54f87f10eb33c03ebac125ce68356b1eb2d6 100644 --- a/scripts/gdb/xmethods.py +++ b/scripts/gdb/xmethods.py @@ -1,3 +1,4 @@ +import sys import re import gdb @@ -48,4 +49,5 @@ class SmallVectorImplMatcher(gdb.xmethod.XMethodMatcher): return SmallVectorImplWorker_size(class_type.template_argument(0)) -gdb.xmethod.register_xmethod_matcher(None, SmallVectorImplMatcher()) +if sys.version_info.major > 2: + gdb.xmethod.register_xmethod_matcher(None, SmallVectorImplMatcher())