aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-08-19 21:15:49 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-08-19 21:15:49 +0000
commit5582fc15e5e21f2b2c25f57fa058f449e1db9811 (patch)
tree05169e5608b85188cb5aff6e9c21d7bc826d9b9f /gcc
parent4f6bdb08bab64b973e465fb45deb751561e3b969 (diff)
downloadgcc-5582fc15e5e21f2b2c25f57fa058f449e1db9811.zip
gcc-5582fc15e5e21f2b2c25f57fa058f449e1db9811.tar.gz
gcc-5582fc15e5e21f2b2c25f57fa058f449e1db9811.tar.bz2
compiler: new debugging output methods/functions
Add new hooks for dumping named objects, package bindings, and top level Gogo package list. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/190877 From-SVN: r274682
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/gogo.cc103
-rw-r--r--gcc/go/gofrontend/gogo.h12
3 files changed, 116 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index b1a6579..94bc2f7 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-b0ba5daa8216a0424b24f74466cedab0b986f3b4
+a453eebae76296a39a1ded5bd2bffa78bedf40bd
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 30523f7..8a24070 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -5430,6 +5430,29 @@ Gogo::convert_named_types_in_bindings(Bindings* bindings)
}
}
+void
+debug_go_gogo(Gogo* gogo)
+{
+ if (gogo != NULL)
+ gogo->debug_dump();
+}
+
+void
+Gogo::debug_dump()
+{
+ std::cerr << "Packages:\n";
+ for (Packages::const_iterator p = this->packages_.begin();
+ p != this->packages_.end();
+ ++p)
+ {
+ const char *tag = " ";
+ if (p->second == this->package_)
+ tag = "* ";
+ std::cerr << tag << "'" << p->first << "' "
+ << p->second->pkgpath() << " " << ((void*)p->second) << "\n";
+ }
+}
+
// Class Function.
Function::Function(Function_type* type, Named_object* enclosing, Block* block,
@@ -8593,6 +8616,61 @@ Named_object::get_id(Gogo* gogo)
return decl_name;
}
+void
+debug_go_named_object(Named_object* no)
+{
+ if (no == NULL)
+ {
+ std::cerr << "<null>";
+ return;
+ }
+ std::cerr << "'" << no->name() << "': ";
+ const char *tag;
+ switch (no->classification())
+ {
+ case Named_object::NAMED_OBJECT_UNINITIALIZED:
+ tag = "uninitialized";
+ break;
+ case Named_object::NAMED_OBJECT_ERRONEOUS:
+ tag = "<error>";
+ break;
+ case Named_object::NAMED_OBJECT_UNKNOWN:
+ tag = "<unknown>";
+ break;
+ case Named_object::NAMED_OBJECT_CONST:
+ tag = "constant";
+ break;
+ case Named_object::NAMED_OBJECT_TYPE:
+ tag = "type";
+ break;
+ case Named_object::NAMED_OBJECT_TYPE_DECLARATION:
+ tag = "type_decl";
+ break;
+ case Named_object::NAMED_OBJECT_VAR:
+ tag = "var";
+ break;
+ case Named_object::NAMED_OBJECT_RESULT_VAR:
+ tag = "result_var";
+ break;
+ case Named_object::NAMED_OBJECT_SINK:
+ tag = "<sink>";
+ break;
+ case Named_object::NAMED_OBJECT_FUNC:
+ tag = "func";
+ break;
+ case Named_object::NAMED_OBJECT_FUNC_DECLARATION:
+ tag = "func_decl";
+ break;
+ case Named_object::NAMED_OBJECT_PACKAGE:
+ tag = "package";
+ break;
+ default:
+ tag = "<unknown named object classification>";
+ break;
+ };
+ std::cerr << tag << "\n";
+}
+
// Get the backend representation for this named object.
void
@@ -9140,6 +9218,31 @@ Bindings::traverse(Traverse* traverse, bool is_global)
return TRAVERSE_CONTINUE;
}
+void
+Bindings::debug_dump()
+{
+ std::set<Named_object*> defs;
+ for (size_t i = 0; i < this->named_objects_.size(); ++i)
+ defs.insert(this->named_objects_[i]);
+ for (Contour::iterator p = this->bindings_.begin();
+ p != this->bindings_.end();
+ ++p)
+ {
+ const char* tag = " ";
+ if (defs.find(p->second) != defs.end())
+ tag = "* ";
+ std::cerr << tag;
+ debug_go_named_object(p->second);
+ }
+}
+
+void
+debug_go_bindings(Bindings* bindings)
+{
+ if (bindings != NULL)
+ bindings->debug_dump();
+}
+
// Class Label.
// Clear any references to this label.
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h
index 6ffdc59..b3ec629 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -341,6 +341,9 @@ class Gogo
set_debug_optimization(bool b)
{ this->debug_optimization_ = b; }
+ // Dump to stderr for debugging
+ void debug_dump();
+
// Return the size threshold used to determine whether to issue
// a nil-check for a given pointer dereference. A threshold of -1
// implies that all potentially faulting dereference ops should
@@ -3068,6 +3071,9 @@ class Bindings
first_declaration()
{ return this->bindings_.empty() ? NULL : this->bindings_.begin()->second; }
+ // Dump to stderr for debugging
+ void debug_dump();
+
private:
Named_object*
add_named_object_to_contour(Contour*, Named_object*);
@@ -3746,4 +3752,10 @@ extern Gogo* go_get_gogo();
// interface.
extern bool saw_errors();
+// For use in the debugger
+extern void debug_go_gogo(Gogo*);
+extern void debug_go_named_object(Named_object*);
+extern void debug_go_bindings(Bindings*);
+
+
#endif // !defined(GO_GOGO_H)