Debugger: Cleanups.

- Factor out RegistersView's SIMD output formatting functions into
  UiUtils helpers. Adjust RegistersView accordingly.
- Adjust DebugReportGenerator to detect SIMD registers and format
  them appropriately for report output using the aforementioned
  helpers.
This commit is contained in:
Rene Gollent 2015-04-25 22:06:20 -04:00
parent 88e499ca82
commit 2f86484842
4 changed files with 106 additions and 86 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Copyright 2012-2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -589,9 +589,16 @@ DebugReportGenerator::_DumpDebuggedThreadInfo(BFile& _output,
reg = fArchitecture->Registers() + i;
state->GetRegisterValue(reg, value);
char buffer[64];
data.SetToFormat("\t\t\t%5s:\t%s\n", reg->Name(),
UiUtils::VariantToString(value, buffer, sizeof(buffer)));
if (reg->Format() == REGISTER_FORMAT_SIMD) {
data.SetToFormat("\t\t\t%5s:\t%s\n", reg->Name(),
UiUtils::FormatSIMDValue(value, reg->BitSize(),
SIMD_RENDER_FORMAT_INT16, data).String());
} else {
char buffer[64];
data.SetToFormat("\t\t\t%5s:\t%s\n", reg->Name(),
UiUtils::VariantToString(value, buffer, sizeof(buffer)));
}
WRITE_AND_CHECK(_output, data);
}

View File

@ -31,16 +31,6 @@ enum {
};
enum {
SIMD_RENDER_FORMAT_INT8 = 0,
SIMD_RENDER_FORMAT_INT16,
SIMD_RENDER_FORMAT_INT32,
SIMD_RENDER_FORMAT_INT64,
SIMD_RENDER_FORMAT_FLOAT,
SIMD_RENDER_FORMAT_DOUBLE
};
static const char*
GetLabelForSIMDFormat(int format)
{
@ -176,8 +166,11 @@ public:
return false;
if (!fCpuState->GetRegisterValue(reg, value))
value.SetTo("?", B_VARIANT_DONT_COPY_DATA);
else if (reg->Format() == REGISTER_FORMAT_SIMD)
_FormatSIMDValue(reg, value);
else if (reg->Format() == REGISTER_FORMAT_SIMD) {
BString output;
value.SetTo(UiUtils::FormatSIMDValue(value,
reg->BitSize(),fSIMDFormat, output));
}
return true;
default:
return false;
@ -193,74 +186,6 @@ public:
}
private:
void _FormatSIMDValue(const Register* reg, BVariant& _value)
{
BString temp("{");
char* data = (char*)_value.ToPointer();
uint32 count = reg->BitSize() / (_GetSIMDFormatByteSize() * 8);
for (uint32 i = 0; i < count; i ++) {
BString format;
switch (fSIMDFormat) {
case SIMD_RENDER_FORMAT_INT8:
format.SetToFormat("%#" B_PRIx8,
_GetSIMDValueAtOffset<uint8>(data, i));
break;
case SIMD_RENDER_FORMAT_INT16:
format.SetToFormat("%#" B_PRIx16,
_GetSIMDValueAtOffset<uint16>(data, i));
break;
case SIMD_RENDER_FORMAT_INT32:
format.SetToFormat("%#" B_PRIx32,
_GetSIMDValueAtOffset<uint32>(data, i));
break;
case SIMD_RENDER_FORMAT_INT64:
format.SetToFormat("%#" B_PRIx64,
_GetSIMDValueAtOffset<uint64>(data, i));
break;
case SIMD_RENDER_FORMAT_FLOAT:
format.SetToFormat("%.3g",
(double)_GetSIMDValueAtOffset<float>(data, i));
break;
case SIMD_RENDER_FORMAT_DOUBLE:
format.SetToFormat("%.3g",
_GetSIMDValueAtOffset<double>(data, i));
break;
}
temp += format;
if (i < count - 1)
temp += ", ";
}
temp += "}";
_value.SetTo(temp);
}
template<typename T>
T _GetSIMDValueAtOffset(char* data, int32 index)
{
return ((T*)data)[index];
}
int32 _GetSIMDFormatByteSize() const
{
switch (fSIMDFormat) {
case SIMD_RENDER_FORMAT_INT8:
return sizeof(char);
case SIMD_RENDER_FORMAT_INT16:
return sizeof(int16);
case SIMD_RENDER_FORMAT_INT32:
return sizeof(int32);
case SIMD_RENDER_FORMAT_INT64:
return sizeof(int64);
case SIMD_RENDER_FORMAT_FLOAT:
return sizeof(float);
case SIMD_RENDER_FORMAT_DOUBLE:
return sizeof(double);
}
return 0;
}
private:
Architecture* fArchitecture;
CpuState* fCpuState;

View File

@ -1,6 +1,6 @@
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Copyright 2012-2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -485,3 +485,77 @@ UiUtils::TypeCodeToString(type_code type)
return "unknown";
}
}
template<typename T>
T GetSIMDValueAtOffset(char* data, int32 index)
{
return ((T*)data)[index];
}
static int32 GetSIMDFormatByteSize(uint32 format)
{
switch (format) {
case SIMD_RENDER_FORMAT_INT8:
return sizeof(char);
case SIMD_RENDER_FORMAT_INT16:
return sizeof(int16);
case SIMD_RENDER_FORMAT_INT32:
return sizeof(int32);
case SIMD_RENDER_FORMAT_INT64:
return sizeof(int64);
case SIMD_RENDER_FORMAT_FLOAT:
return sizeof(float);
case SIMD_RENDER_FORMAT_DOUBLE:
return sizeof(double);
}
return 0;
}
/*static*/
const BString&
UiUtils::FormatSIMDValue(const BVariant& value, uint32 bitSize,
uint32 format, BString& _output)
{
_output.SetTo("{");
char* data = (char*)value.ToPointer();
uint32 count = bitSize / (GetSIMDFormatByteSize(format) * 8);
for (uint32 i = 0; i < count; i ++) {
BString temp;
switch (format) {
case SIMD_RENDER_FORMAT_INT8:
temp.SetToFormat("%#" B_PRIx8,
GetSIMDValueAtOffset<uint8>(data, i));
break;
case SIMD_RENDER_FORMAT_INT16:
temp.SetToFormat("%#" B_PRIx16,
GetSIMDValueAtOffset<uint16>(data, i));
break;
case SIMD_RENDER_FORMAT_INT32:
temp.SetToFormat("%#" B_PRIx32,
GetSIMDValueAtOffset<uint32>(data, i));
break;
case SIMD_RENDER_FORMAT_INT64:
temp.SetToFormat("%#" B_PRIx64,
GetSIMDValueAtOffset<uint64>(data, i));
break;
case SIMD_RENDER_FORMAT_FLOAT:
temp.SetToFormat("%.3g",
(double)GetSIMDValueAtOffset<float>(data, i));
break;
case SIMD_RENDER_FORMAT_DOUBLE:
temp.SetToFormat("%.3g",
GetSIMDValueAtOffset<double>(data, i));
break;
}
_output += temp;
if (i < count - 1)
_output += ", ";
}
_output += "}";
return _output;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014, Rene Gollent, rene@gollent.com.
* Copyright 2014-2015, Rene Gollent, rene@gollent.com.
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
@ -22,6 +22,16 @@ class TeamMemoryBlock;
class ValueNodeChild;
enum {
SIMD_RENDER_FORMAT_INT8 = 0,
SIMD_RENDER_FORMAT_INT16,
SIMD_RENDER_FORMAT_INT32,
SIMD_RENDER_FORMAT_INT64,
SIMD_RENDER_FORMAT_FLOAT,
SIMD_RENDER_FORMAT_DOUBLE
};
class UiUtils {
public:
static const char* ThreadStateToString(int state,
@ -60,6 +70,10 @@ public:
RangeList& _output);
static const char* TypeCodeToString(type_code type);
static const BString& FormatSIMDValue(const BVariant& value,
uint32 bitSize, uint32 format,
BString& _output);
};