Add memory dumping helper to UiUtils.

- Adapted from KDL's db/dw et al.
This commit is contained in:
Rene Gollent 2012-12-18 21:32:04 -05:00
parent 55751d083a
commit 779b84b17b
2 changed files with 71 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "UiUtils.h"
#include <ctype.h>
#include <stdio.h>
#include <DateTime.h>
@ -18,6 +19,7 @@
#include "Image.h"
#include "StackFrame.h"
#include "Team.h"
#include "TeamMemoryBlock.h"
#include "Thread.h"
#include "Type.h"
#include "Value.h"
@ -226,3 +228,63 @@ UiUtils::PrintValueNodeGraph(BString& _output, ValueNodeChild* child,
return;
}
/*static*/ void UiUtils::DumpMemory(BString& _output, TeamMemoryBlock* block,
target_addr_t address, int32 itemSize, int32 displayWidth, int32 count)
{
BString data;
int32 j;
for (int32 i = 0; i < count; i++) {
uint8* value;
if ((i % displayWidth) == 0) {
int32 displayed = min_c(displayWidth, (count-i)) * itemSize;
if (i != 0)
_output.Append("\n");
data.SetToFormat("[%#" B_PRIx64 "] ", address + i * itemSize);
_output += data;
char c;
for (j = 0; j < displayed; j++) {
if (!block->Contains(address + displayed))
break;
c = *(block->Data() + address - block->BaseAddress()
+ (i * itemSize) + j);
if (!isprint(c))
c = '.';
_output += c;
}
if (count > displayWidth) {
// make sure the spacing in the last line is correct
for (j = displayed; j < displayWidth * itemSize; j++)
_output += ' ';
}
_output.Append(" ");
}
value = block->Data() + address - block->BaseAddress()
+ i * itemSize;
switch (itemSize) {
case 1:
data.SetToFormat(" %02" B_PRIx8, *(uint8*)value);
break;
case 2:
data.SetToFormat(" %04" B_PRIx16, *(uint16*)value);
break;
case 4:
data.SetToFormat(" %08" B_PRIx32, *(uint32*)value);
break;
case 8:
data.SetToFormat(" %016" B_PRIx64, *(uint64*)value);
break;
}
_output += data;
}
_output.Append("\n");
}

View File

@ -9,13 +9,17 @@
#include <image.h>
#include "Types.h"
class BString;
class BVariant;
class StackFrame;
class Team;
class TeamMemoryBlock;
class ValueNodeChild;
class UiUtils {
public:
static const char* ThreadStateToString(int state,
@ -36,6 +40,11 @@ public:
static void PrintValueNodeGraph(BString& _output,
ValueNodeChild* child,
int32 indentLevel, int32 maxDepth);
static void DumpMemory(BString& _output,
TeamMemoryBlock* block,
target_addr_t address, int32 itemSize,
int32 displayWidth, int32 count);
};