Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Factor formatting utility functions out of RegistersView and

StackTraceView.
  • Loading branch information...
commit 0aae2709deadaa34594c210455211a67df5c097c 1 parent d59fcf5
@anevilyak anevilyak authored
View
45 src/apps/debugger/user_interface/gui/team_window/RegistersView.cpp
@@ -18,6 +18,7 @@
#include "CpuState.h"
#include "GuiSettingsUtils.h"
#include "Register.h"
+#include "UiUtils.h"
// #pragma mark - RegisterValueColumn
@@ -39,7 +40,7 @@ class RegistersView::RegisterValueColumn : public StringTableColumn {
{
char buffer[64];
return StringTableColumn::PrepareField(
- BVariant(_ToString(value, buffer, sizeof(buffer)),
+ BVariant(UiUtils::VariantToString(value, buffer, sizeof(buffer)),
B_VARIANT_DONT_COPY_DATA));
}
@@ -53,9 +54,11 @@ class RegistersView::RegisterValueColumn : public StringTableColumn {
char bufferA[64];
char bufferB[64];
return StringTableColumn::CompareValues(
- BVariant(_ToString(a, bufferA, sizeof(bufferA)),
+ BVariant(UiUtils::VariantToString(a, bufferA,
+ sizeof(bufferA)),
B_VARIANT_DONT_COPY_DATA),
- BVariant(_ToString(b, bufferB, sizeof(bufferB)),
+ BVariant(UiUtils::VariantToString(b, bufferB,
+ sizeof(bufferB)),
B_VARIANT_DONT_COPY_DATA));
}
@@ -73,42 +76,6 @@ class RegistersView::RegisterValueColumn : public StringTableColumn {
uint64 valueB = b.ToUInt64();
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;
- }
};
View
28 src/apps/debugger/user_interface/gui/team_window/StackTraceView.cpp
@@ -20,6 +20,7 @@
#include "Image.h"
#include "StackTrace.h"
#include "TargetAddressTableColumn.h"
+#include "UiUtils.h"
// #pragma mark - FramesTableModel
@@ -77,30 +78,9 @@ class StackTraceView::FramesTableModel : public TableModel {
return true;
case 2:
{
- Image* image = frame->GetImage();
- FunctionInstance* function = frame->Function();
- if (image == NULL && function == NULL) {
- 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());
-
+ char buffer[512];
+ value.SetTo(UiUtils::FunctionNameForFrame(frame, buffer,
+ sizeof(buffer)));
return true;
}
default:
View
74 src/apps/debugger/user_interface/util/UiUtils.cpp
@@ -6,6 +6,15 @@
#include "UiUtils.h"
+#include <stdio.h>
+
+#include <Variant.h>
+
+#include "FunctionInstance.h"
+#include "Image.h"
+#include "StackFrame.h"
+#include "Thread.h"
+
/*static*/ const char*
UiUtils::ThreadStateToString(int state, int stoppedReason)
@@ -35,3 +44,68 @@ UiUtils::ThreadStateToString(int state, int stoppedReason)
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;
+}
View
12 src/apps/debugger/user_interface/util/UiUtils.h
@@ -5,14 +5,24 @@
#ifndef UI_UTILS_H
#define UI_UTILS_H
+#include <size_t.h>
-#include "Thread.h"
+
+class StackFrame;
+
+
+class BVariant;
class UiUtils {
public:
static const char* ThreadStateToString(int state,
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);
};
Please sign in to comment.
Something went wrong with that request. Please try again.