-
Notifications
You must be signed in to change notification settings - Fork 230
Implement natvis 'na' modifier and $T substitution #1612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SachinM123
wants to merge
7
commits into
microsoft:main
Choose a base branch
from
SachinM123:natvisFormatSpecifierFix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−21
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
507e16f
Implement natvis 'na' modifier and $T substitution
SachinM123 442a1d3
address pr comments
SachinM123 3f38aef
address pr comments
SachinM123 79422c4
fix CleanUtf16StringValue
SachinM123 42fa4c9
pr changes
SachinM123 55881f8
Update Natvis.cs
SachinM123 afe98a8
Update Natvis.cs
SachinM123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1283,12 +1283,16 @@ private string FormatValue(string format, IVariableInformation variable, IDictio | |
| if (m.Success) | ||
| { | ||
| string rawExpr = format.Substring(i + 1, m.Length - 2); | ||
| string spec = ExtractFormatSpecifier(rawExpr); | ||
| string spec = ExtractFormatSpecifier(rawExpr, out bool hasNa); | ||
| string exprValue = GetExpressionValue(rawExpr, variable, scopedNames, intrinsics); | ||
| if (spec == "sub" || spec == "su") | ||
| if (spec == "sub") | ||
| exprValue = CleanUtf16StringValue(exprValue); | ||
| else if (spec == "sb") | ||
| exprValue = CleanAsciiStringValue(exprValue); | ||
|
gregg-miskelly marked this conversation as resolved.
gregg-miskelly marked this conversation as resolved.
gregg-miskelly marked this conversation as resolved.
|
||
| if (hasNa) | ||
| { | ||
| exprValue = VariableInformation.StripLeadingAddress(exprValue); | ||
| } | ||
|
gregg-miskelly marked this conversation as resolved.
|
||
| value.Append(exprValue); | ||
| i += m.Length - 1; | ||
| } | ||
|
|
@@ -1494,30 +1498,40 @@ private static int FindLastTopLevelComma(string expression) | |
| /// <see cref="VariableInformation.ProcessFormatSpecifiers"/>: modifiers "nvo", "na", | ||
| /// "nr", "nd" are stripped before returning. Returns null when no specifier is present. | ||
| /// </summary> | ||
| internal static string ExtractFormatSpecifier(string expression) | ||
| internal static string ExtractFormatSpecifier(string expression, out bool hasNa) | ||
|
SachinM123 marked this conversation as resolved.
|
||
| { | ||
| hasNa = false; | ||
| int commaPos = FindLastTopLevelComma(expression); | ||
| if (commaPos < 0) return null; | ||
|
|
||
| string tail = expression.Substring(commaPos + 1).Trim(); | ||
| hasNa = tail.IndexOf("na", StringComparison.Ordinal) >= 0; | ||
|
|
||
| return expression.Substring(commaPos + 1).Trim() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .Replace("nvo", "").Replace("na", "").Replace("nr", "").Replace("nd", ""); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns true if the NatVis expression's trailing format specifier (the part after the | ||
| /// last top-level comma) contains the "na" modifier. This intentionally inspects the | ||
| /// raw specifier text and does not normalize/remove modifiers so callers can detect | ||
| /// whether the original expression asked for the "na" behavior. | ||
| /// </summary> | ||
| /// <summary> | ||
| /// Cleans up the raw value that GDB/LLDB returns for a <c>const char16_t*</c> | ||
| /// expression (i.e. one evaluated with the <c>,sub</c> / <c>,su</c> format specifier). | ||
| /// GDB and LLDB both prefix the string with the pointer address, e.g. | ||
| /// <c>0x00007fff5fbff6c0 u"Hello"</c> | ||
| /// This method strips the address and the surrounding <c>u"…"</c> quotes so that | ||
| /// the NatVis DisplayString shows just the string content. | ||
| /// This method strips the leading address prefix that GDB/LLDB emits ("0x... "). | ||
| /// It does NOT remove surrounding quotes or the leading character-width prefix (u/U). | ||
| /// </summary> | ||
| internal static string CleanUtf16StringValue(string value) | ||
| { | ||
| if (string.IsNullOrEmpty(value)) return value; | ||
| // Strip leading "0x<hex> " address prefix emitted by GDB/LLDB. | ||
| value = s_addressPrefix.Replace(value, ""); | ||
| value = VariableInformation.StripLeadingAddress(value); | ||
| // Strip surrounding u"..." or U"..." quotes. | ||
| if (value.Length >= 3 && | ||
| (value.StartsWith("u\"", StringComparison.Ordinal) || value.StartsWith("U\"", StringComparison.Ordinal))) | ||
| if (value.Length >= 3 && (value.StartsWith("u\"", StringComparison.Ordinal) || value.StartsWith("U\"", StringComparison.Ordinal))) | ||
| { | ||
| value = value.EndsWith("\"", StringComparison.Ordinal) | ||
| ? value.Substring(2, value.Length - 3) | ||
|
|
@@ -1531,15 +1545,13 @@ internal static string CleanUtf16StringValue(string value) | |
| /// (i.e. one evaluated with the <c>,sb</c> format specifier). | ||
| /// GDB and LLDB prefix the string with the pointer address, e.g. | ||
| /// <c>0x00007fff5fbff6c0 "Hello"</c> | ||
| /// This method strips the address and the surrounding <c>"…"</c> quotes so that | ||
| /// the NatVis DisplayString shows just the string content (matching VS behaviour, | ||
| /// where <c>{ptr,sb}</c> evaluates to bare text without quotes). | ||
| /// This method strips the leading address prefix that GDB/LLDB emits ("0x... "). | ||
| /// </summary> | ||
| internal static string CleanAsciiStringValue(string value) | ||
| { | ||
| if (string.IsNullOrEmpty(value)) return value; | ||
| // Strip leading "0x<hex> " address prefix emitted by GDB/LLDB. | ||
| value = s_addressPrefix.Replace(value, ""); | ||
| value = VariableInformation.StripLeadingAddress(value); | ||
| // Strip surrounding "..." quotes. | ||
| if (value.Length >= 2 && value.StartsWith("\"", StringComparison.Ordinal)) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.