Commit 7fbbe778 authored by Friedemann Kleint's avatar Friedemann Kleint

Debugger[CDB]: Rework string formatting.

Use watch encoding without quotes for non-ASCII output.
Use formats with quotes for recoded strings.
Extend char-pointer recoding to work for char-arrays as well
and restrict to char types. Split up and re-use when
outputting QByteArrays or std::[w]string.

Task-number: QTCREATORBUG-5667
Change-Id: If9748c2e375ee5ecb05d257410eba4012de1c3cf
Reviewed-on: http://codereview.qt.nokia.com/2747Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent 815d9cb1
......@@ -206,6 +206,31 @@ inline char toHexDigit(unsigned v)
return char(v - 10) + 'a';
}
// Strings from raw data.
std::wstring quotedWStringFromCharData(const unsigned char *data, size_t size)
{
std::wstring rc;
rc.reserve(size + 2);
rc.push_back(L'"');
const unsigned char *end = data + size;
for ( ; data < end; data++)
rc.push_back(wchar_t(*data));
rc.push_back(L'"');
return rc;
}
std::wstring quotedWStringFromWCharData(const unsigned char *dataIn, size_t sizeIn)
{
std::wstring rc;
const wchar_t *data = reinterpret_cast<const wchar_t *>(dataIn);
const size_t size = sizeIn / sizeof(wchar_t);
rc.reserve(size + 2);
rc.push_back(L'"');
rc.append(data, data + size);
rc.push_back(L'"');
return rc;
}
// String from hex "414A" -> "AJ".
std::string stringFromHex(const char *p, const char *end)
{
......
......@@ -178,6 +178,10 @@ std::string wStringToGdbmiString(const std::wstring &w);
std::string wStringToString(const std::wstring &w);
std::wstring stringToWString(const std::string &w);
// Strings from raw data.
std::wstring quotedWStringFromCharData(const unsigned char *data, size_t size);
std::wstring quotedWStringFromWCharData(const unsigned char *data, size_t size);
// String from hex "414A" -> "AJ".
std::string stringFromHex(const char *begin, const char *end);
// Decode hex to a memory area.
......
......@@ -49,6 +49,17 @@ class SymbolGroup;
struct SymbolGroupValueContext;
class SymbolGroupNode;
// Helper struct used for check results when recoding CDB char pointer output.
struct DumpParameterRecodeResult
{
DumpParameterRecodeResult() : buffer(0), size(0), recommendedFormat(0),isWide(false) {}
unsigned char *buffer;
size_t size;
int recommendedFormat;
bool isWide;
};
struct DumpParameters
{
typedef std::map<std::string, int> FormatMap; // type or iname to format
......@@ -63,8 +74,17 @@ struct DumpParameters
// Helper to decode format option arguments.
static FormatMap decodeFormatArgument(const std::string &f);
static DumpParameterRecodeResult
checkRecode(const std::string &type, const std::string &iname,
const std::wstring &value,
const SymbolGroupValueContext &ctx,
ULONG64 address,
const DumpParameters *dp =0);
bool recode(const std::string &type, const std::string &iname,
const SymbolGroupValueContext &ctx,
ULONG64 address,
std::wstring *value, int *encoding) const;
int format(const std::string &type, const std::string &iname) const;
......
......@@ -1394,6 +1394,13 @@ void formatKnownTypeFlags(std::ostream &os, KnownType kt)
os << " simple_dumper";
}
static inline DumpParameterRecodeResult
checkCharArrayRecode(const SymbolGroupValue &v)
{
return DumpParameters::checkRecode(v.type(), std::string(),
v.value(), v.context(), v.address());
}
// Helper struct containing data Address and size/alloc information
// from Qt's QString/QByteArray.
struct QtStringAddressData
......@@ -1554,9 +1561,15 @@ static inline bool dumpQByteArray(const SymbolGroupValue &v, std::wostream &str)
return false;
// Qt 4.
if (qtInfo.version < 5) {
// TODO: More sophisticated dumping of binary data?
if (const SymbolGroupValue data = dV["data"]) {
str << data.value();
const DumpParameterRecodeResult check =
checkCharArrayRecode(data);
if (check.buffer) {
str << quotedWStringFromCharData(check.buffer, check.size);
delete [] check.buffer;
} else {
str << data.value();
}
return true;
}
return false;
......@@ -2039,7 +2052,17 @@ static bool dumpStd_W_String(const SymbolGroupValue &v, int type, std::wostream
const SymbolGroupValue string = bufSize <= reserved ? bx["_Ptr"] : bx["_Buf"];
if (!string)
return false;
str << string.value();
// Potentially re-code char arrays (preferably relying on
// CDB to initially format the string array).
const DumpParameterRecodeResult recode = checkCharArrayRecode(string);
if (recode.buffer) {
str << (type == KT_StdString ?
quotedWStringFromCharData(recode.buffer, recode.size) :
quotedWStringFromWCharData(recode.buffer, recode.size));
delete [] recode.buffer;
} else {
str << string.value();
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment