summaryrefslogtreecommitdiff
path: root/lldb/test/API/functionalities/data-formatter/custom-printf-summary
AgeCommit message (Collapse)Author
2024-05-15[lldb] Support custom LLVM formatting for variables (#91868)Dave Lee
Re-apply https://github.com/llvm/llvm-project/pull/81196, with a fix that handles the absence of llvm formatting: https://github.com/llvm/llvm-project/pull/91868/commits/3ba650e91eded3543764f37921dcce3b b47d425f
2024-04-30Revert "[lldb] Support custom LLVM formatting for variables (#81196)"Dave Lee
This reverts commit 7a8d15e919dde70118dbfa34e927be1705ded67d.
2024-04-30[lldb] Support custom LLVM formatting for variables (#81196)Dave Lee
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.