From 9166844f31e7f02de0766bf48def7248ebd799be Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 1 Dec 2022 14:30:16 +0800 Subject: [PATCH] fix(debug): skip load user gdb script if gdb is build with python2 GitOrigin-RevId: 816a15d774183aefd1dabfea8a1726f6bc4edf74 --- scripts/gdb/commands.py | 21 ++++++++++++--------- scripts/gdb/pretty_printers.py | 33 +++++++++++++++++++-------------- scripts/gdb/xmethods.py | 4 +++- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/scripts/gdb/commands.py b/scripts/gdb/commands.py index 998c15ac6..76d255fe2 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 d7dd65b63..ef17f4ff3 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 6f4d326ef..9dfc54f87 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()) -- GitLab