Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/MIDebugEngine/Engine.Impl/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,16 @@ private string ProcessFormatSpecifiers(string exp, out string formatSpecifier)
if (lastComma <= 0)
return exp;

// Find the format specifier expression
string expFS = exp.Substring(lastComma + 1).Trim();

// Strip off modifiers that may be included together with another format specifier, e.g. 'nvoXb' is a valid format specifier, but we only care about the 'Xb' part
Comment thread
gregg-miskelly marked this conversation as resolved.
// This is not quite the right fix -- really the below switch statement should be a series of if statements. But since none of the supported format specifiers
// contain any of these characters we can fix this the simple way and remove them.
expFS = expFS.Replace("nvo", "").Replace("na", "").Replace("nr", "").Replace("nd", "");

// https://docs.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-cpp
string expFS = exp.Substring(lastComma + 1);
string trimmed = expFS.Trim();
switch (trimmed)
switch (expFS)
{
case "x":
case "X":
Expand Down Expand Up @@ -433,19 +439,17 @@ private string ProcessFormatSpecifiers(string exp, out string formatSpecifier)
return "(char)(" + exp.Substring(0, lastComma) + ")";
// just remove and ignore these
case "en":
case "na":
case "nd":
case "nr":
case "!":
case "":
return exp.Substring(0, lastComma);
}

// array with static size
var m = Regex.Match(trimmed, @"^\[?(\d+)\]?$");
if (m.Success)
// Array with static size
// Note that size specifiers may also include format specifiers (e.g. "ptr,[10]s8") which we should recognize in the regex, but ignore, since neither LLDB nor GDB support them
var matchStatic = Regex.Match(expFS, @"^\[?(\d+)\]?[a-zA-Z\d]*$");
if (matchStatic.Success)
{
string count = m.Groups[1].Value; // (\d+) capture group
string count = matchStatic.Groups[1].Value; // (\d+) capture group
string expr = exp.Substring(0, lastComma);

if (_engine.DebuggedProcess.MICommandFactory.Mode == MIMode.Gdb)
Expand All @@ -472,9 +476,13 @@ private string ProcessFormatSpecifiers(string exp, out string formatSpecifier)
}
}

// array with dynamic size
if (Regex.Match(trimmed, @"^\[([a-zA-Z_][a-zA-Z_\d]*)\]$").Success)
return exp.Substring(0, lastComma);
// Array with dynamic size is not supported, discard the format specifier
var matchDynamic = Regex.Match(expFS, @"^\[.*\][a-zA-Z\d]*$");
if (matchDynamic.Success)
{
string expr = exp.Substring(0, lastComma);
return expr;
}

return exp;
}
Expand Down
Loading