-
Notifications
You must be signed in to change notification settings - Fork 233
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
8
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.
Open
Changes from all commits
Commits
Show all changes
8 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 596849a
add test NatvisFormatStringTest.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 |
|---|---|---|
|
|
@@ -1502,13 +1502,31 @@ internal static string ExtractFormatSpecifier(string expression) | |
| .Replace("nvo", "").Replace("na", "").Replace("nr", "").Replace("nd", ""); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the format specifier from a NatVis expression (the part after the last | ||
| /// top-level comma), normalized the same way as | ||
| /// <see cref="VariableInformation.ProcessFormatSpecifiers"/>: modifiers "nvo", "na", | ||
| /// "nr", "nd" are stripped before returning. Returns null when no specifier is present. | ||
| /// also returns whether modifier 'na' was there via the out parameter | ||
| /// </summary> | ||
| internal static string ExtractFormatSpecifier(string expression, out bool hasNa) | ||
| { | ||
| 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 tail | ||
| .Replace("nvo", "").Replace("na", "").Replace("nr", "").Replace("nd", ""); | ||
| } | ||
|
|
||
|
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. Am I missing something? It looks like nothing is calling your new method |
||
| /// <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. | ||
| /// </summary> | ||
| internal static string CleanUtf16StringValue(string value) | ||
| { | ||
|
|
@@ -1531,9 +1549,6 @@ 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). | ||
| /// </summary> | ||
| internal static string CleanAsciiStringValue(string value) | ||
| { | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using Xunit; | ||
| using Microsoft.MIDebugEngine.Natvis; | ||
| using Microsoft.MIDebugEngine; | ||
|
|
||
| namespace MIDebugEngineUnitTests | ||
| { | ||
| /// <summary> | ||
| /// unit tests for natvis format string processing with format specifiers | ||
| /// tests the handling of format specifiers like, 'na', sub (UTF-16), sb (ASCII). | ||
| /// </summary> | ||
| public class NatvisFormatStringTest | ||
| { | ||
| // -- format specifier with template parameters ($T1, $T2,) -- | ||
| [Fact] | ||
| public void ExtractFormatSpecifier_HasTemplateParameter_TemplateSubstituted() | ||
| { | ||
| string spec = Natvis.ExtractFormatSpecifier("myVector,sub"); | ||
| Assert.Equal("sub", spec); | ||
| } | ||
|
|
||
| // -- Format specifier na -- | ||
|
|
||
| [Fact] | ||
| public void ExtractFormatSpecifier_WithNaModifier_HasNaIsTrue() | ||
| { | ||
| string spec = Natvis.ExtractFormatSpecifier("someExpr,na", out bool hasNa); | ||
| Assert.Equal("", spec); | ||
| Assert.True(hasNa); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ExtractFormatSpecifier_WithNaAndFormat_HasNaIsTrueAndSpecReturned() | ||
| { | ||
| string spec = Natvis.ExtractFormatSpecifier("myString,subna", out bool hasNa); | ||
| Assert.Equal("sub", spec); | ||
| Assert.True(hasNa); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ExtractFormatSpecifier_WithoutNaModifier_HasNaIsFalse() | ||
| { | ||
| string spec = Natvis.ExtractFormatSpecifier("myString,sub", out bool hasNa); | ||
| Assert.Equal("sub", spec); | ||
| Assert.False(hasNa); | ||
| } | ||
|
|
||
| // -- UTF-16 and ASCII string cleanup -- | ||
|
|
||
| [Fact] | ||
| public void CleanUtf16StringValue_WithAddressAndQuotes_AddressAndQuotesStripped() | ||
| { | ||
| string result = Natvis.CleanUtf16StringValue("0x00007fff5fbff6c0 u\"Hello\""); | ||
| Assert.Equal("Hello", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CleanUtf16StringValue_WithCapitalU_QuotesStripped() | ||
| { | ||
| string result = Natvis.CleanUtf16StringValue("U\"Hello\""); | ||
| Assert.Equal("Hello", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CleanUtf16StringValue_JustAddress_AddressStripped() | ||
| { | ||
| string result = Natvis.CleanUtf16StringValue("0x00007fff u"); | ||
| Assert.Equal("u", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CleanAsciiStringValue_WithAddressAndQuotes_AddressAndQuotesStripped() | ||
| { | ||
| string result = Natvis.CleanAsciiStringValue("0x00007fff5fbff6c0 \"Hello\""); | ||
| Assert.Equal("Hello", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CleanAsciiStringValue_TruncatedNoClosingQuote_OpeningQuoteStripped() | ||
| { | ||
| string result = Natvis.CleanAsciiStringValue("0x00007fff \"Hello..."); | ||
| Assert.Equal("Hello...", result); | ||
| } | ||
| } | ||
| } | ||
|
|
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.