From 6802d5aafbe1c3c524a2c25ef5839bb74865a1b5 Mon Sep 17 00:00:00 2001 From: Maxim Kalaev Date: Wed, 27 Jun 2012 23:28:32 +0200 Subject: Improving Edge::Dump, introducing Node::Dump - Edge::Dump could crash if called while inputs_ is being extended - Node::Dump prints Node attributes, in-edge and lists of out-edges - Dump functions now accept "prefix" parameter, printed along with the object for easier orientation. For example, edge->Dump("Re-reading deps files"). --- src/graph.cc | 29 ++++++++++++++++++++++++----- src/graph.h | 4 +++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/graph.cc b/src/graph.cc index 5418ecf..56584e3 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -320,18 +320,37 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface, return true; } -void Edge::Dump() { - printf("[ "); - for (vector::iterator i = inputs_.begin(); i != inputs_.end(); ++i) { +void Edge::Dump(const char* prefix) const { + printf("%s[ ", prefix); + for (vector::const_iterator i = inputs_.begin(); + i != inputs_.end() && *i != NULL; ++i) { printf("%s ", (*i)->path().c_str()); } printf("--%s-> ", rule_->name().c_str()); - for (vector::iterator i = outputs_.begin(); i != outputs_.end(); ++i) { + for (vector::const_iterator i = outputs_.begin(); + i != outputs_.end() && *i != NULL; ++i) { printf("%s ", (*i)->path().c_str()); } - printf("]\n"); + printf("] 0x%p\n", this); } bool Edge::is_phony() const { return rule_ == &State::kPhonyRule; } + +void Node::Dump(const char* prefix) const { + printf("%s <%s 0x%p> mtime: %d%s, (:%s), ", + prefix, path().c_str(), this, + mtime(), mtime()?"":" (:missing)", + dirty()?" dirty":" clean"); + if (in_edge()) { + in_edge()->Dump("in-edge: "); + }else{ + printf("no in-edge\n"); + } + printf(" out edges:\n"); + for (vector::const_iterator e = out_edges().begin(); + e != out_edges().end() && *e != NULL; ++e) { + (*e)->Dump(" +- "); + } +} diff --git a/src/graph.h b/src/graph.h index 32a859d..0ef4f3f 100644 --- a/src/graph.h +++ b/src/graph.h @@ -77,6 +77,8 @@ struct Node { const vector& out_edges() const { return out_edges_; } void AddOutEdge(Edge* edge) { out_edges_.push_back(edge); } + void Dump(const char* prefix="") const; + private: string path_; /// Possible values of mtime_: @@ -173,7 +175,7 @@ struct Edge { bool LoadDepFile(State* state, DiskInterface* disk_interface, string* err); - void Dump(); + void Dump(const char* prefix="") const; const Rule* rule_; vector inputs_; -- cgit v0.12