Factor formatting utility functions out of RegistersView and
StackTraceView.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "CpuState.h"
|
#include "CpuState.h"
|
||||||
#include "GuiSettingsUtils.h"
|
#include "GuiSettingsUtils.h"
|
||||||
#include "Register.h"
|
#include "Register.h"
|
||||||
|
#include "UiUtils.h"
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - RegisterValueColumn
|
// #pragma mark - RegisterValueColumn
|
||||||
@@ -39,7 +40,7 @@ protected:
|
|||||||
{
|
{
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
return StringTableColumn::PrepareField(
|
return StringTableColumn::PrepareField(
|
||||||
BVariant(_ToString(value, buffer, sizeof(buffer)),
|
BVariant(UiUtils::VariantToString(value, buffer, sizeof(buffer)),
|
||||||
B_VARIANT_DONT_COPY_DATA));
|
B_VARIANT_DONT_COPY_DATA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,9 +54,11 @@ protected:
|
|||||||
char bufferA[64];
|
char bufferA[64];
|
||||||
char bufferB[64];
|
char bufferB[64];
|
||||||
return StringTableColumn::CompareValues(
|
return StringTableColumn::CompareValues(
|
||||||
BVariant(_ToString(a, bufferA, sizeof(bufferA)),
|
BVariant(UiUtils::VariantToString(a, bufferA,
|
||||||
|
sizeof(bufferA)),
|
||||||
B_VARIANT_DONT_COPY_DATA),
|
B_VARIANT_DONT_COPY_DATA),
|
||||||
BVariant(_ToString(b, bufferB, sizeof(bufferB)),
|
BVariant(UiUtils::VariantToString(b, bufferB,
|
||||||
|
sizeof(bufferB)),
|
||||||
B_VARIANT_DONT_COPY_DATA));
|
B_VARIANT_DONT_COPY_DATA));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,42 +76,6 @@ protected:
|
|||||||
uint64 valueB = b.ToUInt64();
|
uint64 valueB = b.ToUInt64();
|
||||||
return valueA < valueB ? -1 : (valueA == valueB ? 0 : 1);
|
return valueA < valueB ? -1 : (valueA == valueB ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
const char* _ToString(const BVariant& value, char* buffer,
|
|
||||||
size_t bufferSize) const
|
|
||||||
{
|
|
||||||
if (!value.IsNumber())
|
|
||||||
return value.ToString();
|
|
||||||
|
|
||||||
switch (value.Type()) {
|
|
||||||
case B_FLOAT_TYPE:
|
|
||||||
case B_DOUBLE_TYPE:
|
|
||||||
snprintf(buffer, bufferSize, "%g", value.ToDouble());
|
|
||||||
break;
|
|
||||||
case B_INT8_TYPE:
|
|
||||||
case B_UINT8_TYPE:
|
|
||||||
snprintf(buffer, bufferSize, "0x%02x", value.ToUInt8());
|
|
||||||
break;
|
|
||||||
case B_INT16_TYPE:
|
|
||||||
case B_UINT16_TYPE:
|
|
||||||
snprintf(buffer, bufferSize, "0x%04x", value.ToUInt16());
|
|
||||||
break;
|
|
||||||
case B_INT32_TYPE:
|
|
||||||
case B_UINT32_TYPE:
|
|
||||||
snprintf(buffer, bufferSize, "0x%08" B_PRIx32,
|
|
||||||
value.ToUInt32());
|
|
||||||
break;
|
|
||||||
case B_INT64_TYPE:
|
|
||||||
case B_UINT64_TYPE:
|
|
||||||
default:
|
|
||||||
snprintf(buffer, bufferSize, "0x%016" B_PRIx64,
|
|
||||||
value.ToUInt64());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "StackTrace.h"
|
#include "StackTrace.h"
|
||||||
#include "TargetAddressTableColumn.h"
|
#include "TargetAddressTableColumn.h"
|
||||||
|
#include "UiUtils.h"
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - FramesTableModel
|
// #pragma mark - FramesTableModel
|
||||||
@@ -77,30 +78,9 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
Image* image = frame->GetImage();
|
char buffer[512];
|
||||||
FunctionInstance* function = frame->Function();
|
value.SetTo(UiUtils::FunctionNameForFrame(frame, buffer,
|
||||||
if (image == NULL && function == NULL) {
|
sizeof(buffer)));
|
||||||
value.SetTo("?", B_VARIANT_DONT_COPY_DATA);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BString name;
|
|
||||||
target_addr_t baseAddress;
|
|
||||||
if (function != NULL) {
|
|
||||||
name = function->PrettyName();
|
|
||||||
baseAddress = function->Address();
|
|
||||||
} else {
|
|
||||||
name = image->Name();
|
|
||||||
baseAddress = image->Info().TextBase();
|
|
||||||
}
|
|
||||||
|
|
||||||
char offset[32];
|
|
||||||
snprintf(offset, sizeof(offset), " + %#" B_PRIx64,
|
|
||||||
frame->InstructionPointer() - baseAddress);
|
|
||||||
|
|
||||||
name << offset;
|
|
||||||
value.SetTo(name.String());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
|
|
||||||
#include "UiUtils.h"
|
#include "UiUtils.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Variant.h>
|
||||||
|
|
||||||
|
#include "FunctionInstance.h"
|
||||||
|
#include "Image.h"
|
||||||
|
#include "StackFrame.h"
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
|
|
||||||
/*static*/ const char*
|
/*static*/ const char*
|
||||||
UiUtils::ThreadStateToString(int state, int stoppedReason)
|
UiUtils::ThreadStateToString(int state, int stoppedReason)
|
||||||
@@ -35,3 +44,68 @@ UiUtils::ThreadStateToString(int state, int stoppedReason)
|
|||||||
return "Debugged";
|
return "Debugged";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ const char*
|
||||||
|
UiUtils::VariantToString(const BVariant& value, char* buffer,
|
||||||
|
size_t bufferSize)
|
||||||
|
{
|
||||||
|
if (!value.IsNumber())
|
||||||
|
return value.ToString();
|
||||||
|
|
||||||
|
switch (value.Type()) {
|
||||||
|
case B_FLOAT_TYPE:
|
||||||
|
case B_DOUBLE_TYPE:
|
||||||
|
snprintf(buffer, bufferSize, "%g", value.ToDouble());
|
||||||
|
break;
|
||||||
|
case B_INT8_TYPE:
|
||||||
|
case B_UINT8_TYPE:
|
||||||
|
snprintf(buffer, bufferSize, "0x%02x", value.ToUInt8());
|
||||||
|
break;
|
||||||
|
case B_INT16_TYPE:
|
||||||
|
case B_UINT16_TYPE:
|
||||||
|
snprintf(buffer, bufferSize, "0x%04x", value.ToUInt16());
|
||||||
|
break;
|
||||||
|
case B_INT32_TYPE:
|
||||||
|
case B_UINT32_TYPE:
|
||||||
|
snprintf(buffer, bufferSize, "0x%08" B_PRIx32,
|
||||||
|
value.ToUInt32());
|
||||||
|
break;
|
||||||
|
case B_INT64_TYPE:
|
||||||
|
case B_UINT64_TYPE:
|
||||||
|
default:
|
||||||
|
snprintf(buffer, bufferSize, "0x%016" B_PRIx64,
|
||||||
|
value.ToUInt64());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ const char*
|
||||||
|
UiUtils::FunctionNameForFrame(StackFrame* frame, char* buffer,
|
||||||
|
size_t bufferSize)
|
||||||
|
{
|
||||||
|
Image* image = frame->GetImage();
|
||||||
|
FunctionInstance* function = frame->Function();
|
||||||
|
if (image == NULL && function == NULL) {
|
||||||
|
snprintf(buffer, bufferSize, "?");
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
BString name;
|
||||||
|
target_addr_t baseAddress;
|
||||||
|
if (function != NULL) {
|
||||||
|
name = function->PrettyName();
|
||||||
|
baseAddress = function->Address();
|
||||||
|
} else {
|
||||||
|
name = image->Name();
|
||||||
|
baseAddress = image->Info().TextBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buffer, bufferSize, "%s + %#" B_PRIx64,
|
||||||
|
name.String(), frame->InstructionPointer() - baseAddress);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,14 +5,24 @@
|
|||||||
#ifndef UI_UTILS_H
|
#ifndef UI_UTILS_H
|
||||||
#define UI_UTILS_H
|
#define UI_UTILS_H
|
||||||
|
|
||||||
|
#include <size_t.h>
|
||||||
|
|
||||||
#include "Thread.h"
|
|
||||||
|
class StackFrame;
|
||||||
|
|
||||||
|
|
||||||
|
class BVariant;
|
||||||
|
|
||||||
|
|
||||||
class UiUtils {
|
class UiUtils {
|
||||||
public:
|
public:
|
||||||
static const char* ThreadStateToString(int state,
|
static const char* ThreadStateToString(int state,
|
||||||
int stoppedReason);
|
int stoppedReason);
|
||||||
|
|
||||||
|
static const char* VariantToString(const BVariant& value,
|
||||||
|
char* buffer, size_t bufferSize);
|
||||||
|
static const char* FunctionNameForFrame(StackFrame* frame,
|
||||||
|
char* buffer, size_t bufferSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user