Skip to content

Commit

Permalink
POC typedef resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Trass3r committed Aug 6, 2020
1 parent 6515cec commit 6c35684
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/MIDebugEngine/Engine.Impl/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,31 @@ private VariableInformation(ThreadContext ctx, AD7Engine engine, AD7Thread threa
_debuggedProcess.ActiveVariables.Add(this);
}
}
public static async Task<string> resolveType(DebuggedProcess process, string type)
{
// avoid useless requests
if (string.IsNullOrEmpty(type) || type.Contains("{...}"))
return type;

// support the common case of a single-level */&
char last = type[type.Length - 1];
string orgtype = type;
if (last == '*' || last == '&')
type = type.Substring(0, type.Length - 1);
try
{
// N.B.: whatis only strips 1 typedef level and fails when type is a * or &
type = await process.ConsoleCmdAsync("whatis " + type, false);
}
catch(UnexpectedMIResultException e)
{
process.WriteOutput(e.ToString());
return orgtype;
}
if (last == '*' || last == '&')
type += last;
return Regex.Match(type, "type = (.+)").Groups[1].Value;
}

//this constructor is used to create root nodes (local/params)
internal VariableInformation(string expr, ThreadContext ctx, AD7Engine engine, AD7Thread thread, bool isParameter = false)
Expand Down Expand Up @@ -494,6 +519,7 @@ internal async Task Eval(enum_EVALFLAGS dwFlags = 0, DAPEvalFlags dwDAPFlags = 0
{
_internalName = results.FindString("name");
TypeName = results.TryFindString("type");
TypeName = await VariableInformation.resolveType(_debuggedProcess, TypeName);
if (results.Contains("dynamic"))
{
IsPreformatted = true;
Expand Down Expand Up @@ -632,7 +658,9 @@ private async Task InternalFetchChildren()
Children = new VariableInformation[CountChildren];
foreach (var c in children)
{
Children[i] = new VariableInformation(c, this);
var vi = new VariableInformation(c, this);
vi.TypeName = await resolveType(_debuggedProcess, vi.TypeName);
Children[i] = vi;
i++;
}
}
Expand All @@ -651,7 +679,9 @@ private async Task InternalFetchChildren()
var variable = new VariableInformation("[" + (p / 2).ToString() + "]", this);
variable.CountChildren = 2;
var first = new VariableInformation(children[p], variable, "first");
first.TypeName = await resolveType(_debuggedProcess, first.TypeName);
var second = new VariableInformation(children[p + 1], this, "second");
second.TypeName = await resolveType(_debuggedProcess, second.TypeName);

variable.Children = new VariableInformation[] { first, second };
variable.TypeName = FormattableString.Invariant($"std::pair<{first.TypeName}, {second.TypeName}>");
Expand All @@ -664,6 +694,7 @@ private async Task InternalFetchChildren()
// and the second element (p+1) becoming the value.
string name = children[p].TryFindString("value");
var variable = new VariableInformation(children[p + 1], this, '[' + name + ']');
variable.TypeName = await resolveType(_debuggedProcess, variable.TypeName);
listChildren.Add(variable);
}
}
Expand All @@ -676,6 +707,7 @@ private async Task InternalFetchChildren()
foreach (var c in children)
{
var variable = new VariableInformation(c, this);
variable.TypeName = await resolveType(_debuggedProcess, variable.TypeName);
enum_DBG_ATTRIB_FLAGS access = enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_NONE;
if (variable.Name == "public")
{
Expand Down

0 comments on commit 6c35684

Please sign in to comment.