mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Ide/Debuggers/Gdb_MI2 : fixed Upp::String pretty printer
git-svn-id: svn://ultimatepp.org/upp/trunk@6911 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
fcbd6ec6eb
commit
a074fa401b
3 changed files with 95 additions and 34 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = "<UNNAMED>";
|
||||
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 = "<UNNAMED>";
|
||||
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 "<STRING>"
|
||||
#define MARK_ARRAY "<ARRAY>"
|
||||
#define MARK_TUPLE "<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>" + string;
|
||||
return spacer + MARK_STRING + string;
|
||||
|
||||
case MITuple:
|
||||
{
|
||||
String s = spacer + "<TUPLE>" + "{\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 + "<ARRAY>" + "[ \n";
|
||||
String s = spacer + MARK_ARRAY + "[ \n";
|
||||
level += 4;
|
||||
for(int i = 0; i < array.GetCount(); i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,32 +1,47 @@
|
|||
#include "Debuggers.h"
|
||||
#include <ide/ide.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue