Skip to content

Commit

Permalink
Factor out a PrintValueNodeGraph() helper from DebugReportGenerator.
Browse files Browse the repository at this point in the history
- Intended to also be used by CLI to print variables there.
  • Loading branch information
anevilyak committed Dec 11, 2012
1 parent e8a837f commit 2f50903
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
67 changes: 67 additions & 0 deletions src/apps/debugger/user_interface/util/UiUtils.cpp
Expand Up @@ -11,13 +11,17 @@

#include <DateTime.h>
#include <Path.h>
#include <String.h>
#include <Variant.h>

#include "FunctionInstance.h"
#include "Image.h"
#include "StackFrame.h"
#include "Team.h"
#include "Thread.h"
#include "Type.h"
#include "Value.h"
#include "ValueNode.h"


/*static*/ const char*
Expand Down Expand Up @@ -156,3 +160,66 @@ UiUtils::ReportNameForTeam(::Team* team, char* buffer, size_t bufferSize)
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;
}
10 changes: 9 additions & 1 deletion src/apps/debugger/user_interface/util/UiUtils.h
Expand Up @@ -10,10 +10,11 @@
#include <image.h>


class BString;
class BVariant;
class StackFrame;
class Team;

class ValueNodeChild;

class UiUtils {
public:
Expand All @@ -29,6 +30,13 @@ class UiUtils {

static const char* ReportNameForTeam(::Team* team,
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);
};


Expand Down

0 comments on commit 2f50903

Please sign in to comment.