diff --git a/src/MIDebugEngine/Engine.Impl/Variables.cs b/src/MIDebugEngine/Engine.Impl/Variables.cs index 55a24796f..25d5a6cdf 100644 --- a/src/MIDebugEngine/Engine.Impl/Variables.cs +++ b/src/MIDebugEngine/Engine.Impl/Variables.cs @@ -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 + // 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": @@ -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) @@ -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; }