public static bool evaluateExpression(string name, ref string result, string GDBName)
{
if (name[name.Length - 1] == '.')
name = name.Remove(name.Length - 1);
// Waits for the parsed response for the GDB/MI command that evaluates "name" as an expression.
// (http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Data-Manipulation.html)
result = GDBParser.parseCommand("-data-evaluate-expression \"" + name + "\"", 2);
if (result.Substring(0, 2) == "61") // If result starts with 61, it means that there is an error.
{
if (GDBName != null) // Maybe that error was caused because GDB didn't accept the VS name. Use the GDBName if there is one.
{
// Gets the parsed response for the GDB/MI command that evaluates "GDBName" as an expression.
// (http://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Data-Manipulation.html)
string result2 = GDBParser.parseCommand("-data-evaluate-expression \"" + GDBName + "\"", 2);
if (result2.Substring(0, 2) == "60")
result = result2;
}
}
bool valid = true;
if (result.Substring(0, 2) == "61") // If result starts with 61, it means that there is an error. So, expression is not valid.
valid = false;
result = result.Substring(3);
result = result.Substring(1, result.Length - 2); // remove the quotes located in the beginning and at the end
result = result.Replace("\\\"", "\"");
if (valid)
{
int endString = result.IndexOf("\\\\000");
int ini, end = 0;
while (endString != -1) // remove garbage from strings
{
ini = result.IndexOf("\"", end);
while ((ini > 0) && (result[ini - 1] == '\\'))
ini = result.IndexOf("\"", ini + 1);
if (ini == -1)
break;
end = result.IndexOf("\"", ini + 1);
while ((end > 0) && (result[end - 1] == '\\'))
end = result.IndexOf("\"", end + 1);
if (end == -1)
break;
while ((endString != -1) && (endString < ini))
endString = result.IndexOf("\\\\000", endString + 1);
if ((endString > ini) && (endString < end))
{
result = result.Substring(0, endString) + result.Substring(end, (result.Length - end));
end = endString;
endString = result.IndexOf("\\\\000", end);
}
end++;
};
}
return valid;
}