Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » the debugger
Re: the debugger [message #18716 is a reply to message #17358] |
Sat, 18 October 2008 12:40 |
cocob
Messages: 156 Registered: January 2008
|
Experienced Member |
|
|
Here a little code to solve my problem of printing values in STL vectors. I think it would be great to improve this to print values for other types.
String Gdb::GetVarType(const String& var)
{
String type = FastCmd("ptype " + var);
StringStream ss(type);
String ln = ss.GetLine();
const char *s = strchr(ln, '=');
if(s) {
s++;
while(*s == ' ')
s++;
return String(s);
}
else
return "";
}
String Gdb::TransformExp(const String& exp)
{
String newExp;
int b = exp.Find('[');
if(b>0) {
int e = exp.Find(']', b+1);
if(b>0) {
// we have a *[*] expression so evaluate the index
String index = exp.Mid(b+1, e-b-1);
index = Print(index);
String tab = exp.Mid(0, b);
String tabType = GetVarType(tab);
if(tabType.GetLength()==0) return exp;
if(tabType.Left(17)=="class std::vector") {
newExp << "*(" << tab << "._M_impl._M_start+" << index << ")";
return newExp;
} else {
newExp << tab << "[" << index << "]";
return newExp;
}
}
}
return exp;
}
String Gdb::Print(const String& exp)
{
String newExp = TransformExp(exp);
String q = FastCmd("print " + newExp);
StringStream ss(q);
String ln = ss.GetLine();
const char *s = strchr(ln, '=');
if(s) {
s++;
while(*s == ' ')
s++;
return DataClean(s);
}
else
return DataClean(ln);
}
[Updated on: Sat, 18 October 2008 19:05] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Apr 26 13:55:43 CEST 2024
Total time taken to generate the page: 0.02399 seconds
|