From a074fa401ba897ed36db977eafa2c6e0b2560f3f Mon Sep 17 00:00:00 2001 From: micio Date: Wed, 12 Feb 2014 00:02:33 +0000 Subject: [PATCH] Ide/Debuggers/Gdb_MI2 : fixed Upp::String pretty printer git-svn-id: svn://ultimatepp.org/upp/trunk@6911 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Debuggers/Gdb_MI2.cpp | 1 + uppsrc/ide/Debuggers/MIValue.cpp | 83 +++++++++++++++++++++------ uppsrc/ide/Debuggers/TypeSimplify.cpp | 45 ++++++++++----- 3 files changed, 95 insertions(+), 34 deletions(-) diff --git a/uppsrc/ide/Debuggers/Gdb_MI2.cpp b/uppsrc/ide/Debuggers/Gdb_MI2.cpp index 057917e3c..6a20a0d0c 100644 --- a/uppsrc/ide/Debuggers/Gdb_MI2.cpp +++ b/uppsrc/ide/Debuggers/Gdb_MI2.cpp @@ -1182,6 +1182,7 @@ void Gdb_MI2::UpdateThis(void) return; MIValue s(tup.ToString()); s.PackNames(); +//RLOG(s.Dump()); TypeSimplify(s); ExploreValueDeep("", s, names, values); } diff --git a/uppsrc/ide/Debuggers/MIValue.cpp b/uppsrc/ide/Debuggers/MIValue.cpp index 3bc630e10..c43422298 100644 --- a/uppsrc/ide/Debuggers/MIValue.cpp +++ b/uppsrc/ide/Debuggers/MIValue.cpp @@ -1,5 +1,7 @@ #include "MIValue.h" +//#define MITUPLE_DUMP_MARKERS + static MIValue &NullMIValue(void) { static MIValue v; @@ -27,6 +29,21 @@ bool MIValue::expect(String const &where, char exp, int i, String const &s) return false; } +static char backslash(String const &s, int &i) +{ + i++; + char c; + if(IsDigit(s[i])) + { + c = (s[i]-'0')*64 + (s[i+1]-'0')*8 + s[i+2]-'0'; + i += 2; + } + else + c = s[i]; + return c; +} + + int MIValue::ParsePair(String &name, MIValue &val, String const &s, int i) { name.Clear(); @@ -41,29 +58,40 @@ int MIValue::ParsePair(String &name, MIValue &val, String const &s, int i) // is starting wirh '[' or '{' take it as a value with empty name if(s[i] == '{' || s[i] == '[') - name = ""; + name = ""; else { int aCount = 0; while(s[i] && ((s[i] != '=' && s[i] != '}' && s[i] != ']') || aCount)) { - name.Cat(s[i]); if(s[i] == '<') aCount++; else if(s[i] == '>') aCount--; + if(s[i] == '\\') + name.Cat(backslash(s, i)); + else + name.Cat(s[i]); i++; // skip blanks if not inside <> +/* if(!aCount) while(s[i] && isspace(s[i])) i++; +*/ } while(s[i] && isspace(s[i])) i++; if(s[i] != '=') + { + // we take the data without = as the value part + // of keyless tuple... + val.Set(name); + name = ""; return i; + } i++; while(s[i] && isspace(s[i])) @@ -165,19 +193,22 @@ int MIValue::ParseString(String const &s, int i) Clear(); type = MIString; - char c; if(!expect("ParseString", '"', i, s)) return s.GetCount(); i++; - while( (c = s[i++]) != 0) + while(s[i]) { // verbatim if escaped - if(c == '\\') - string.Cat(s[i++]); - else if(c == '"') + if(s[i] == '\\') + string.Cat(backslash(s, i)); + else if(s[i] == '"') + { + i++; break; + } else - string.Cat(c); + string.Cat(s[i]); + i++; } if(!expect("ParseString", '"', i-1, s)) return s.GetCount(); @@ -191,23 +222,28 @@ int MIValue::ParseAngle(String const &s, int i) type = MIString; int aCount = 0; - char c; if(!expect("ParseAngle", '<', i, s)) return s.GetCount(); string = "<"; aCount++; i++; - while( (c = s[i++]) != 0) + while(s[i]) { // verbatim if escaped - if(c == '\\') - string.Cat(s[i++]); - else if(c == '>' && !--aCount) + if(s[i] == '\\') + string.Cat(backslash(s, i)); + else if(s[i] == '>' && !--aCount) + { + i++; break; + } else - string.Cat(c); - if(c == '<') - aCount++; + { + string.Cat(s[i]); + if(s[i] == '<') + aCount++; + } + i++; } if(!expect("ParseAngle", '"', i-1, s)) return s.GetCount(); @@ -488,17 +524,26 @@ void MIValue::Set(String const &s) } // data dump +#ifdef MITUPLE_DUMP_MARKERS + #define MARK_STRING "" + #define MARK_ARRAY "" + #define MARK_TUPLE "" +#else + #define MARK_STRING "" + #define MARK_ARRAY "" + #define MARK_TUPLE "" +#endif String MIValue::Dump(int level) const { String spacer(' ', level); switch(type) { case MIString: - return spacer + "" + string; + return spacer + MARK_STRING + string; case MITuple: { - String s = spacer + "" + "{\n"; + String s = spacer + MARK_TUPLE + "{\n"; level += 4; spacer = String(' ', level); for(int i = 0; i < tuple.GetCount(); i++) @@ -525,7 +570,7 @@ String MIValue::Dump(int level) const case MIArray: { - String s = spacer + "" + "[ \n"; + String s = spacer + MARK_ARRAY + "[ \n"; level += 4; for(int i = 0; i < array.GetCount(); i++) { diff --git a/uppsrc/ide/Debuggers/TypeSimplify.cpp b/uppsrc/ide/Debuggers/TypeSimplify.cpp index 95f231957..81f91ea90 100644 --- a/uppsrc/ide/Debuggers/TypeSimplify.cpp +++ b/uppsrc/ide/Debuggers/TypeSimplify.cpp @@ -1,32 +1,47 @@ #include "Debuggers.h" #include -typedef void (*TYPE_SIMPLIFIER_HANDLER)(MIValue &val); +typedef bool (*TYPE_SIMPLIFIER_HANDLER)(MIValue &val); -static void UppStringSimplify(MIValue &val) +static bool UppStringSimplify(MIValue &val) { // strings are "easy", in debug mode 's' and 'len' members are provided // so we shall just look at them in tuple + // see Upp::String code for how it works.... try { MIValue &v = val[0][0][0]; - if(!v.IsTuple()) - return; - if(v.Find("s") < 0) - return; - String s = v["s"]; + MIValue &unn = v[1]; + if(!v.IsTuple() || !unn.IsTuple()) + return false; - // strip address part - int pos = 0; - while(s[pos] && s[pos] != '"') - pos++; - if(!s[pos]) - return; - val.Set(s.Mid(pos)); + if(unn.Find("chr") < 0) + return false; + String chr = unn["chr"]; + bool isSmall = (chr[14] == 0); + String s; + if(isSmall) + s = chr; + else + { + if(unn.Find("ptr") < 0) + return false; + s = unn["ptr"]; + + // strip address... + int i = s.Find('"'); + if(i >= 0) + { + s = s.Mid(i+1); + s = s.Left(s.GetCount()-1); + } + } + val.Set(s); + return true; } catch(...) { - return; + return false; } }