Open yh-sb opened 1 year ago
I did some digging, and I found the problem is present in visual studio too https://developercommunity.visualstudio.com/t/How-to-avoid-recursion-in-natvis-Display/404898.
I think the best way to solve this is to cast this
to (void*)
as it's explained here.
I guess it could be possible to break the recursion by adding something like this:
--- a/src/MIDebugEngine/Natvis.Impl/Natvis.cs
+++ b/src/MIDebugEngine/Natvis.Impl/Natvis.cs
@@ -1216,7 +1216,13 @@ namespace Microsoft.MIDebugEngine.Natvis
Match m = s_expression.Match(format.Substring(i));
if (m.Success)
{
- string exprValue = GetExpressionValue(format.Substring(i + 1, m.Length - 2), variable, scopedNames);
+ string exprValue;
+ string expression = format.Substring(i + 1, m.Length - 2);
+ IVariableInformation expressionVariable = GetExpression(format.Substring(i + 1, m.Length - 2), variable, scopedNames);
+ if(expression == "this") // or maybe expressionVariable.TypeName == variable.TypeName
+ exprValue = expressionVariable.Value;
+ else
+ exprValue = FormatDisplayString(expressionVariable).value;
value.Append(exprValue);
But it's tricky to get the exit condition right, and it may still not cover some corner cases.
Environment
Bug Summary and Steps to Reproduce
Bug Summary: Value visualization for
this
pointer variables displays messy with the following natvis configuration. The issue is reproduced not only for int* type, but anytime ifthis
pointer is present in DisplayString natvis value.Source code:
Natvis file:
See
ptr
value with lot of redundant{}
:Expected result:
{ 0x2ee11ff6c4=5 }
Debugger Configurations
Debugger Logs
DEBUG CONSOLE
```shell --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (50) LaunchOptions{\"name\":\"g++ active file\",\"type\":\"cppdbg\",\"request\":\"launch\",\"program\":\"D:\\\\dev\\\\c++\\\\cpp-examples\\\\examples/vscode-natvis-int-ptr-bug\",\"cwd\":\"D:\\\\dev\\\\c++\\\\cpp-examples\\\\examples\",\"miDebuggerPath\":\"gdb\",\"internalConsoleOptions\":\"neverOpen\",\"preLaunchTask\":\"g++ active file\",\"showDisplayString\":true,\"visualizerFile\":\"D:\\\\dev\\\\c++\\\\cpp-examples/.vscode/test.natvis\",\"logging\":{\"engineLogging\":true,\"trace\":true,\"traceResponse\":true},\"__configurationTarget\":6,\"configSource\":\"workspaceFolder\",\"debugType\":\"debug\",\"__sessionId\":\"f071e615-5d4d-41d5-a12f-41ad7399372b\",\"MIMode\":\"gdb\"}\r\n"},"seq":2} 1: (50) LaunchOptions{"name":"g++ active file","type":"cppdbg","request":"launch","program":"D:\\dev\\c++\\cpp-examples\\examples/vscode-natvis-int-ptr-bug","cwd":"D:\\dev\\c++\\cpp-examples\\examples","miDebuggerPath":"gdb","internalConsoleOptions":"neverOpen","preLaunchTask":"g++ active file","showDisplayString":true,"visualizerFile":"D:\\dev\\c++\\cpp-examples/.vscode/test.natvis","logging":{"engineLogging":true,"trace":true,"traceResponse":true},"__configurationTarget":6,"configSource":"workspaceFolder","debugType":"debug","__sessionId":"f071e615-5d4d-41d5-a12f-41ad7399372b","MIMode":"gdb"} --> C (runInTerminal-4): {"type":"request","command":"runInTerminal","arguments":{"kind":"integrated","title":"cppdbg: vscode-natvis-int-ptr-bug","cwd":"","args":["c:\\Users\\admin\\.vscode\\extensions\\ms-vscode.cpptools-1.14.4-win32-x64\\debugAdapters\\bin\\WindowsDebugLauncher.exe","--stdin=Microsoft-MIEngine-In-jqx3taox.zhm","--stdout=Microsoft-MIEngine-Out-g0vazuaa.eeg","--stderr=Microsoft-MIEngine-Error-rpaedkk4.ze2","--pid=Microsoft-MIEngine-Pid-lu0kzola.53x","--dbgExe=C:\\Program Files\\mydevtools\\MinGW-w64\\bin\\gdb.exe","--interpreter=mi"],"env":{}},"seq":4} --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (94) Wait for connection completion.\r\n"},"seq":6} 1: (94) Wait for connection completion. --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (1497) ->=thread-group-added,id=\"i1\"\r\n"},"seq":8} 1: (1497) ->=thread-group-added,id="i1" --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (1498) ->~\"GNU gdb (GDB for MinGW-W64 x86_64, built by Brecht Sanders) 12.1\\n\"\r\n"},"seq":10} 1: (1498) ->~"GNU gdb (GDB for MinGW-W64 x86_64, built by Brecht Sanders) 12.1\n" --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (1499) ->~\"Copyright (C) 2022 Free Software Foundation, Inc.\\n\"\r\n"},"seq":12} 1: (1499) ->~"Copyright (C) 2022 Free Software Foundation, Inc.\n" --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (1499) ->~\"License GPLv3+: GNU GPL version 3 or laterOther Extensions
Issue persists when other extensions disabled
Additional Information
No response