From dc306cf371bd5ece54d3965ca7a9938f957ca6ad Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 24 Nov 2020 18:35:12 -0500 Subject: [PATCH] Internal debug: avoid segflt with gdb "pnt" --- src/.gdbinit | 6 +++--- src/V3Ast.cpp | 48 ++++++++++++++++++++++++++++++------------------ src/V3Ast.h | 6 +++--- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/.gdbinit b/src/.gdbinit index 17532d0d2..8e973680f 100644 --- a/src/.gdbinit +++ b/src/.gdbinit @@ -7,21 +7,21 @@ # SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 define pn - call $arg0->dumpGdb() + call AstNode::dumpGdb($arg0) end document pn Verilator: Print single AstNode NODEP end define pnt - call $arg0->dumpTreeGdb() + call AstNode::dumpTreeGdb($arg0) end document pnt Verilator: Print AstNode NODEP's tree end define dtf - call AstNode::dumpTreeFileGdb(0) + call AstNode::dumpTreeFileGdb($arg0, 0) end document dtf Verilator: Dump AstNode tree to file diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 234dd49d9..9e2b9843b 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -1029,28 +1029,40 @@ void AstNode::checkTree() { } // cppcheck-suppress unusedFunction // Debug only -void AstNode::dumpGdb() { // For GDB only // LCOV_EXCL_LINE - dumpGdbHeader(); // LCOV_EXCL_LINE +void AstNode::dumpGdb(const AstNode* nodep) { // For GDB only // LCOV_EXCL_LINE + if (!nodep) { + cout << "" << endl; + return; + } + nodep->dumpGdbHeader(); cout << " "; - dump(cout); - cout << endl; // LCOV_EXCL_LINE -} + nodep->dump(cout); + cout << endl; +} // LCOV_EXCL_STOP // cppcheck-suppress unusedFunction // Debug only -void AstNode::dumpGdbHeader() const { // For GDB only // LCOV_EXCL_LINE - dumpPtrs(cout); // LCOV_EXCL_LINE - cout << " Fileline = " << fileline() << endl; // LCOV_EXCL_LINE -} +void AstNode::dumpGdbHeader() const { // For GDB only // LCOV_EXCL_START + dumpPtrs(cout); + cout << " Fileline = " << fileline() << endl; +} // LCOV_EXCL_STOP // cppcheck-suppress unusedFunction // Debug only -void AstNode::dumpTreeGdb() { // For GDB only // LCOV_EXCL_LINE - dumpGdbHeader(); // LCOV_EXCL_LINE - dumpTree(cout); // LCOV_EXCL_LINE -} +void AstNode::dumpTreeGdb(const AstNode* nodep) { // For GDB only // LCOV_EXCL_START + if (!nodep) { + cout << "" << endl; + return; + } + nodep->dumpGdbHeader(); + nodep->dumpTree(cout); +} // LCOV_EXCL_STOP // cppcheck-suppress unusedFunction // Debug only -void AstNode::dumpTreeFileGdb(const char* filenamep) { // For GDB only // LCOV_EXCL_LINE - string filename - = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); // LCOV_EXCL_LINE - v3Global.rootp()->dumpTreeFile(filename); // LCOV_EXCL_LINE -} +void AstNode::dumpTreeFileGdb(const AstNode* nodep, // LCOV_EXCL_START + const char* filenamep) { // For GDB only + if (!nodep) { + cout << "" << endl; + return; + } + string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); + v3Global.rootp()->dumpTreeFile(filename); +} // LCOV_EXCL_STOP // cppcheck-suppress unusedFunction // Debug only void AstNode::checkIter() const { diff --git a/src/V3Ast.h b/src/V3Ast.h index 5326f1515..01ff69a85 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1761,7 +1761,7 @@ public: string warnOther() const { return fileline()->warnOther(); } virtual void dump(std::ostream& str = std::cout) const; - void dumpGdb(); // For GDB only + static void dumpGdb(const AstNode* nodep); // For GDB only void dumpGdbHeader() const; // METHODS - Tree modifications @@ -1811,12 +1811,12 @@ public: void dumpTree(const string& indent, int maxDepth = 0) const { dumpTree(cout, indent, maxDepth); } - void dumpTreeGdb(); // For GDB only + static void dumpTreeGdb(const AstNode* nodep); // For GDB only void dumpTreeAndNext(std::ostream& os = std::cout, const string& indent = " ", int maxDepth = 0) const; void dumpTreeFile(const string& filename, bool append = false, bool doDump = true, bool doCheck = true); - static void dumpTreeFileGdb(const char* filenamep = nullptr); + static void dumpTreeFileGdb(const AstNode* nodep, const char* filenamep = nullptr); // METHODS - queries // Changes control flow, disable some optimizations