-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Support custom LLVM formatting for variables #81196
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
Merged
kastiglione
merged 9 commits into
llvm:main
from
kastiglione:lldb-Support-custom-printf-formatting-for-variables
Apr 30, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81a2034
[lldb] Support custom printf formatting for variables
kastiglione 335ab1d
Factor out DumpValueWithPrintf; Add test
kastiglione 678ab33
Use main line API
kastiglione bb4a278
Mention printf formatting in variable.rst
kastiglione 24a0bb4
Switch from printf to llvm::format
kastiglione 16b8dfa
Use regex to validate llvm formatting
kastiglione a656f79
Validate llvm format
kastiglione f746188
Update test
kastiglione 558e41d
Fix python formatting
kastiglione 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
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
2 changes: 2 additions & 0 deletions
2
lldb/test/API/functionalities/data-formatter/custom-printf-summary/Makefile
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,2 @@ | ||
C_SOURCES := main.c | ||
include Makefile.rules |
20 changes: 20 additions & 0 deletions
20
...t/API/functionalities/data-formatter/custom-printf-summary/TestCustomSummaryLLVMFormat.py
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,20 @@ | ||
import lldb | ||
from lldbsuite.test.lldbtest import * | ||
import lldbsuite.test.lldbutil as lldbutil | ||
|
||
|
||
class TestCase(TestBase): | ||
def test_raw_bytes(self): | ||
self.build() | ||
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c")) | ||
self.runCmd("type summary add -s '${var.ubyte:x-2}${var.sbyte:x-2}!' Bytes") | ||
self.expect("v bytes", substrs=[" = 3001!"]) | ||
|
||
def test_bad_format(self): | ||
self.build() | ||
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c")) | ||
self.expect( | ||
"type summary add -s '${var.ubyte:y}!' Bytes", | ||
error=True, | ||
substrs=["invalid llvm format"], | ||
) |
13 changes: 13 additions & 0 deletions
13
lldb/test/API/functionalities/data-formatter/custom-printf-summary/main.c
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,13 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
struct Bytes { | ||
uint8_t ubyte; | ||
int8_t sbyte; | ||
}; | ||
|
||
int main() { | ||
struct Bytes bytes = {0x30, 0x01}; | ||
(void)bytes; | ||
printf("break here\n"); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way we can make this string static, by switching over the supported options?
Or let me ask another way — what happens if options contained "}{1}" is this well-defined in llvm::formatv because it knows the template arguments and thus will not lead to corruption and crashes?
If the answer is yes, then this is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many supported options, and they vary from type to type (int has different options than say strings). See FormatProviders.h for the builtins.
It would be possible to exhaustively iterate all the options llvm includes, but I'm not sure it would be worth it. Switching over them seems fragile to changes made to the source of truth in llvm.
I will check/test what llvm does for invalid options.