Factor out a PrintValueNodeGraph() helper from DebugReportGenerator.

- Intended to also be used by CLI to print variables there.
This commit is contained in:
Rene Gollent 2012-12-10 23:13:40 -05:00
parent e8a837faac
commit 2f50903e1d
2 changed files with 76 additions and 1 deletions

View File

@ -11,6 +11,7 @@
#include <DateTime.h> #include <DateTime.h>
#include <Path.h> #include <Path.h>
#include <String.h>
#include <Variant.h> #include <Variant.h>
#include "FunctionInstance.h" #include "FunctionInstance.h"
@ -18,6 +19,9 @@
#include "StackFrame.h" #include "StackFrame.h"
#include "Team.h" #include "Team.h"
#include "Thread.h" #include "Thread.h"
#include "Type.h"
#include "Value.h"
#include "ValueNode.h"
/*static*/ const char* /*static*/ const char*
@ -156,3 +160,66 @@ UiUtils::ReportNameForTeam(::Team* team, char* buffer, size_t bufferSize)
return buffer; return buffer;
} }
/*static*/ void
UiUtils::PrintValueNodeGraph(BString& _output, StackFrame* frame,
ValueNodeChild* child, int32 indentLevel, int32 maxDepth)
{
_output.Append('\t', indentLevel);
_output << child->Name();
ValueNode* node = child->Node();
if (node == NULL) {
_output << ": Unavailable\n";
return;
}
if (node->GetType()->Kind() != TYPE_COMPOUND) {
_output << ": ";
status_t resolutionState = node->LocationAndValueResolutionState();
if (resolutionState == VALUE_NODE_UNRESOLVED)
_output << "Unresolved";
else if (resolutionState == B_OK) {
Value* value = node->GetValue();
if (value != NULL) {
BString valueData;
value->ToString(valueData);
_output << valueData;
} else
_output << "Unavailable";
} else
_output << strerror(resolutionState);
}
if (maxDepth == 0 || node->CountChildren() == 0) {
_output << "\n";
return;
}
_output << " {\n";
if (node->CountChildren() == 1
&& node->GetType()->Kind() == TYPE_ADDRESS
&& node->ChildAt(0)->GetType()->Kind() == TYPE_COMPOUND) {
// for the case of a pointer to a compound type,
// we want to hide the intervening compound node and print
// the children directly.
node = node->ChildAt(0)->Node();
}
for (int32 i = 0; i < node->CountChildren(); i++) {
// don't dump compound nodes if our depth limit won't allow
// us to traverse into their children anyways, and the top
// level node contains no data of intereest.
if (node->ChildAt(i)->GetType()->Kind() != TYPE_COMPOUND
|| maxDepth > 1) {
PrintValueNodeGraph(_output, frame, node->ChildAt(i),
indentLevel + 1, maxDepth - 1);
}
}
_output.Append('\t', indentLevel);
_output << "}\n";
return;
}

View File

@ -10,10 +10,11 @@
#include <image.h> #include <image.h>
class BString;
class BVariant; class BVariant;
class StackFrame; class StackFrame;
class Team; class Team;
class ValueNodeChild;
class UiUtils { class UiUtils {
public: public:
@ -29,6 +30,13 @@ public:
static const char* ReportNameForTeam(::Team* team, static const char* ReportNameForTeam(::Team* team,
char* buffer, size_t bufferSize); char* buffer, size_t bufferSize);
// this function assumes the value nodes have already been resolved
// (if possible).
static void PrintValueNodeGraph(BString& _output,
StackFrame* frame,
ValueNodeChild* child,
int32 indentLevel, int32 maxDepth);
}; };