pretty print CStringPtr/PStringPts

This commit is contained in:
Kelvin Sherlock 2014-12-30 15:27:34 -05:00
parent f6cc3925a7
commit f946dc1884
3 changed files with 58 additions and 1 deletions

View File

@ -480,6 +480,34 @@ namespace {
namespace Debug {
std::string ReadPString(uint32_t address)
{
std::string tmp;
unsigned size = ReadByte(address++);
tmp.reserve(size);
for (unsigned i = 0; i < size; ++i)
tmp.push_back(ReadByte(address++));
return tmp;
}
std::string ReadCString(uint32_t address)
{
std::string tmp;
for (;;)
{
char c = ReadByte(address++);
if (!c) break;
tmp.push_back(c);
}
return tmp;
}
uint32_t ReadLong(uint32_t address)
{
uint32_t tmp = 0;

View File

@ -110,6 +110,9 @@ uint32_t ReadLong(uint32_t);
uint16_t ReadWord(uint32_t);
uint8_t ReadByte(uint32_t);
std::string ReadPString(uint32_t);
std::string ReadCString(uint32_t);
void Print(uint32_t value);
void PrintRegisters();

View File

@ -119,7 +119,18 @@ namespace Debug {
Templates.emplace(std::make_pair(*name, firstField));
}
void CleanupString(std::string &s)
{
// replace non-printables.
std::transform(s.begin(), s.end(), s.begin(), [](char c){
return isprint(c) ? c : '.';
});
if (s.size() > 40) {
s.resize(37);
s.append("...");
}
}
void PrettyPrint(uint32_t value, unsigned type)
{
@ -134,7 +145,7 @@ namespace Debug {
case kOSErr:
// print value + short name
{
printf(" %6d", (int16_t)value);
printf(" %-6d", (int16_t)value);
auto iter = ErrorTableInvert.find(value);
if (iter != ErrorTableInvert.end()) printf(" %s", iter->second.c_str());
}
@ -142,10 +153,25 @@ namespace Debug {
case kPStringPtr:
// read the string...
if (!value) return;
// need function to check if it's a valid pointer?
{
std::string tmp = ReadPString(value);
CleanupString(tmp);
printf(" '%s'", tmp.c_str());
}
return;
case kCStringPtr:
// read the string...
if (!value) return;
// need function to check if it's a valid pointer?
{
std::string tmp = ReadCString(value);
CleanupString(tmp);
printf(" '%s'", tmp.c_str());
}
return;
return;
case kBoolean: