Debugger[CDB]: Fix setting individual formats by iname.

Do not hex-decode names.

Change-Id: I0b9b6df2524cdf66bc34958bbab5bbc28f8a73db
Reviewed-on: http://codereview.qt.nokia.com/3172
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
Friedemann Kleint
2011-08-18 12:12:07 +02:00
parent 90a812a8a8
commit f63a969c8a
5 changed files with 61 additions and 11 deletions

View File

@@ -386,13 +386,15 @@ DumpCommandParameters::ParseOptionResult DumpCommandParameters::parseOption(Stri
options->pop_front();
if (options->front().empty())
return Error;
dumpParameters.typeFormats = DumpParameters::decodeFormatArgument(options->front());
dumpParameters.typeFormats =
DumpParameters::decodeFormatArgument(options->front(), true);
break;
case 'I': // individual formats: 'hex'ed name = formatnumber,...'
case 'I': // individual formats: iname= formatnumber,...'
if (options->size() < 2)
return Error;
options->pop_front();
dumpParameters.individualFormats = DumpParameters::decodeFormatArgument(options->front());
dumpParameters.individualFormats =
DumpParameters::decodeFormatArgument(options->front(), false);
break;
default:
knownOption = false;

View File

@@ -35,6 +35,7 @@
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
static const char whiteSpace[] = " \t\r\n";
@@ -239,7 +240,7 @@ std::string stringFromHex(const char *p, const char *end)
std::string rc;
rc.reserve((end - p) / 2);
for ( ; p < end; p++) {
for ( ; p < end; ++p) {
unsigned c = 16 * hexDigit(*p);
c += hexDigit(*++p);
rc.push_back(char(c));
@@ -247,9 +248,40 @@ std::string stringFromHex(const char *p, const char *end)
return rc;
}
// Helper for dumping memory
std::string dumpMemory(const unsigned char *p, size_t size,
bool wantQuotes)
{
std::ostringstream str;
str << std::oct << std::setfill('0');
if (wantQuotes)
str << '"';
const unsigned char *end = p + size;
for ( ; p < end; ++p) {
const unsigned char u = *p;
switch (u) {
case '\t':
str << "\\t";
case '\r':
str << "\\r";
case '\n':
str << "\\n";
default:
if (u >= 32 && u < 128) {
str << (char(u));
} else {
str << '\\' << std::setw(3) << unsigned(u);
}
}
}
if (wantQuotes)
str << '"';
return str.str();
}
void decodeHex(const char *p, const char *end, unsigned char *target)
{
for ( ; p < end; p++) {
for ( ; p < end; ++p) {
unsigned c = 16 * hexDigit(*p);
c += hexDigit(*++p);
*target++ = c;
@@ -263,7 +295,7 @@ std::wstring dataToHexW(const unsigned char *p, const unsigned char *end)
std::wstring rc;
rc.reserve(2 * (end - p));
for ( ; p < end ; p++) {
for ( ; p < end ; ++p) {
const unsigned c = *p;
rc.push_back(toHexDigit(c / 16));
rc.push_back(toHexDigit(c &0xF));
@@ -279,7 +311,7 @@ std::wstring dataToReadableHexW(const unsigned char *begin, const unsigned char
std::wstring rc;
rc.reserve(5 * (end - begin));
for (const unsigned char *p = begin; p < end ; p++) {
for (const unsigned char *p = begin; p < end ; ++p) {
rc.append(p == begin ? L"0x" : L" 0x");
const unsigned c = *p;
rc.push_back(toHexDigit(c / 16));

View File

@@ -182,6 +182,9 @@ std::wstring stringToWString(const std::string &w);
std::wstring quotedWStringFromCharData(const unsigned char *data, size_t size);
std::wstring quotedWStringFromWCharData(const unsigned char *data, size_t size);
// Helper for dumping memory
std::string dumpMemory(const unsigned char *data, size_t size, bool wantQuotes = true);
// String from hex "414A" -> "AJ".
std::string stringFromHex(const char *begin, const char *end);
// Decode hex to a memory area.

View File

@@ -294,7 +294,8 @@ DumpParameters::DumpParameters() : dumpFlags(0)
// typeformats: decode hex-encoded name, value pairs:
// '414A=2,...' -> map of "AB:2".
DumpParameters::FormatMap DumpParameters::decodeFormatArgument(const std::string &f)
DumpParameters::FormatMap DumpParameters::decodeFormatArgument(const std::string &f,
bool isHex)
{
FormatMap rc;
const std::string::size_type size = f.size();
@@ -304,7 +305,9 @@ DumpParameters::FormatMap DumpParameters::decodeFormatArgument(const std::string
const std::string::size_type equalsPos = f.find('=', pos);
if (equalsPos == std::string::npos)
return rc;
const std::string name = stringFromHex(f.c_str() + pos, f.c_str() + equalsPos);
const std::string name = isHex ?
stringFromHex(f.c_str() + pos, f.c_str() + equalsPos) :
f.substr(pos, equalsPos - pos);
// Search for number
const std::string::size_type numberPos = equalsPos + 1;
std::string::size_type nextPos = f.find(',', numberPos);
@@ -383,6 +386,12 @@ DumpParameters::checkRecode(const std::string &type,
enum ReformatType { ReformatNone, ReformatPointer, ReformatArray };
DumpParameterRecodeResult result;
if (SymbolGroupValue::verbose > 2) {
DebugPrint debugPrint;
debugPrint << '>' << __FUNCTION__ << ' ' << iname << '/' << iname;
if (dp)
debugPrint << " option format: " << dp->format(type, iname);
}
// We basically handle char formats for 'char *', '0x834478 "hallo.."'
// and 'wchar_t *', '0x834478 "hallo.."'
// Determine address and length from the pointer value output,
@@ -467,6 +476,11 @@ DumpParameters::checkRecode(const std::string &type,
delete [] result.buffer;
result = DumpParameterRecodeResult();
}
if (SymbolGroupValue::verbose > 2)
DebugPrint()
<< '<' << __FUNCTION__ << ' ' << iname << " format="
<< result.recommendedFormat << " size="
<< result.size << " data=" << dumpMemory(result.buffer, result.size);
return result;
}

View File

@@ -72,8 +72,7 @@ struct DumpParameters
DumpParameters();
bool humanReadable() const { return dumpFlags & DumpHumanReadable; }
// Helper to decode format option arguments.
static FormatMap decodeFormatArgument(const std::string &f);
static FormatMap decodeFormatArgument(const std::string &f, bool isHex);
static DumpParameterRecodeResult
checkRecode(const std::string &type, const std::string &iname,