提交 7cab9af6 编写于 作者: M Megvii Engine Team

fix(debug): skip load user gdb script if

gdb is build with python2

GitOrigin-RevId: 816a15d774183aefd1dabfea8a1726f6bc4edf74
上级 5f02245c
import sys
import gdb import gdb
import re import re
...@@ -199,12 +200,14 @@ class MegengineInfo(gdb.Command): ...@@ -199,12 +200,14 @@ class MegengineInfo(gdb.Command):
return ["opr", "trf"] return ["opr", "trf"]
if sys.version_info.major > 2:
MegengineBacktrace() MegengineBacktrace()
MegengineBreakApply() MegengineBreakApply()
MegengineUp() MegengineUp()
MegengineDown() MegengineDown()
MegengineInfo() MegengineInfo()
MegengineWatch() MegengineWatch()
gdb.Breakpoint("mgb::imperative::debug::notify_event(char const*)") gdb.Breakpoint("mgb::imperative::debug::notify_event(char const*)")
\ No newline at end of file else:
print("skip import commands")
import sys
import gdb import gdb
import gdb.printing import gdb.printing
import gdb.types import gdb.types
...@@ -170,23 +171,26 @@ class SpanPrinter: ...@@ -170,23 +171,26 @@ class SpanPrinter:
yield "[{}]".format(i), (self.begin+i).dereference() yield "[{}]".format(i), (self.begin+i).dereference()
pp = gdb.printing.RegexpCollectionPrettyPrinter("MegEngine") if sys.version_info.major > 2:
pp = gdb.printing.RegexpCollectionPrettyPrinter("MegEngine")
# megdnn # megdnn
pp.add_printer('megdnn::SmallVectorImpl', '^megdnn::SmallVector(Impl)?<.*>$', SmallVectorPrinter) pp.add_printer('megdnn::SmallVectorImpl', '^megdnn::SmallVector(Impl)?<.*>$', SmallVectorPrinter)
pp.add_printer('megdnn::TensorLayout', '^megdnn::TensorLayout$', ToStringPrinter) pp.add_printer('megdnn::TensorLayout', '^megdnn::TensorLayout$', ToStringPrinter)
pp.add_printer('megdnn::TensorShape', '^megdnn::TensorShape$', ToStringPrinter) pp.add_printer('megdnn::TensorShape', '^megdnn::TensorShape$', ToStringPrinter)
# megbrain # megbrain
pp.add_printer('mgb::CompNode', '^mgb::CompNode$', ToStringPrinter) pp.add_printer('mgb::CompNode', '^mgb::CompNode$', ToStringPrinter)
pp.add_printer('mgb::Maybe', '^mgb::Maybe<.*>$', MaybePrinter) pp.add_printer('mgb::Maybe', '^mgb::Maybe<.*>$', MaybePrinter)
# imperative # imperative
pp.add_printer('mgb::imperative::LogicalTensorDesc', '^mgb::imperative::LogicalTensorDesc$', LogicalTensorDescPrinter) 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::OpDef', '^mgb::imperative::OpDef$', OpDefPrinter)
pp.add_printer('mgb::imperative::Subgraph', '^mgb::imperative::Subgraph$', ReprPrinter) 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::EncodedSubgraph', '^mgb::imperative::EncodedSubgraph$', ReprPrinter)
# imperative dispatch # imperative dispatch
pp.add_printer('mgb::imperative::ValueRef', '^mgb::imperative::ValueRef$', ToStringPrinter) pp.add_printer('mgb::imperative::ValueRef', '^mgb::imperative::ValueRef$', ToStringPrinter)
pp.add_printer('mgb::imperative::Span', '^mgb::imperative::Span<.*>$', SpanPrinter) pp.add_printer('mgb::imperative::Span', '^mgb::imperative::Span<.*>$', SpanPrinter)
gdb.printing.register_pretty_printer(gdb.current_objfile(), pp) gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)
else:
print("skip import pretty printers")
def override_pretty_printer_for(val): def override_pretty_printer_for(val):
...@@ -201,4 +205,5 @@ def override_pretty_printer_for(val): ...@@ -201,4 +205,5 @@ def override_pretty_printer_for(val):
return HandlePrinter(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)
import sys
import re import re
import gdb import gdb
...@@ -48,4 +49,5 @@ class SmallVectorImplMatcher(gdb.xmethod.XMethodMatcher): ...@@ -48,4 +49,5 @@ class SmallVectorImplMatcher(gdb.xmethod.XMethodMatcher):
return SmallVectorImplWorker_size(class_type.template_argument(0)) 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())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册