[all-commits] [llvm/llvm-project] 7a8d15: [lldb] Support custom LLVM formatting for variable...
Dave Lee via All-commits
all-commits at lists.llvm.org
Tue Apr 30 10:45:31 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7a8d15e919dde70118dbfa34e927be1705ded67d
https://github.com/llvm/llvm-project/commit/7a8d15e919dde70118dbfa34e927be1705ded67d
Author: Dave Lee <davelee.com at gmail.com>
Date: 2024-04-30 (Tue, 30 Apr 2024)
Changed paths:
M lldb/docs/use/variable.rst
M lldb/source/Core/FormatEntity.cpp
A lldb/test/API/functionalities/data-formatter/custom-printf-summary/Makefile
A lldb/test/API/functionalities/data-formatter/custom-printf-summary/TestCustomSummaryLLVMFormat.py
A lldb/test/API/functionalities/data-formatter/custom-printf-summary/main.c
Log Message:
-----------
[lldb] Support custom LLVM formatting for variables (#81196)
Adds support for applying LLVM formatting to variables.
The reason for this is to support cases such as the following.
Let's say you have two separate bytes that you want to print as a
combined hex value. Consider the following summary string:
```
${var.byte1%x}${var.byte2%x}
```
The output of this will be: `0x120x34`. That is, a `0x` prefix is
unconditionally applied to each byte. This is unlike printf formatting
where you must include the `0x` yourself.
Currently, there's no way to do this with summary strings, instead
you'll need a summary provider in python or c++.
This change introduces formatting support using LLVM's formatter system.
This allows users to achieve the desired custom formatting using:
```
${var.byte1:x-}${var.byte2:x-}
```
Here, each variable is suffixed with `:x-`. This is passed to the LLVM
formatter as `{0:x-}`. For integer values, `x` declares the output as
hex, and `-` declares that no `0x` prefix is to be used. Further, one
could write:
```
${var.byte1:x-2}${var.byte2:x-2}
```
Where the added `2` results in these bytes being written with a minimum
of 2 digits.
An alternative considered was to add a new format specifier that would
print hex values without the `0x` prefix. The reason that approach was
not taken is because in addition to forcing a `0x` prefix, hex values
are also forced to use leading zeros. This approach lets the user have
full control over formatting.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list