Skip to content

[LLDB] Add a setting for printing ValueObject hex values without leading zeroes #66548

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
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class TargetProperties : public Properties {

bool GetEnableSyntheticValue() const;

bool ShowHexVariableValuesWithLeadingZeroes() const;

uint32_t GetMaxZeroPaddingInFloatFormat() const;

uint32_t GetMaximumNumberOfChildrenToDisplay() const;
Expand Down
15 changes: 11 additions & 4 deletions lldb/source/Core/DumpDataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,17 @@ lldb::offset_t lldb_private::DumpDataExtractor(
case 2:
case 4:
case 8:
s->Printf(wantsuppercase ? "0x%*.*" PRIX64 : "0x%*.*" PRIx64,
(int)(2 * item_byte_size), (int)(2 * item_byte_size),
DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
item_bit_offset));
if (Target::GetGlobalProperties()
.ShowHexVariableValuesWithLeadingZeroes()) {
s->Printf(wantsuppercase ? "0x%*.*" PRIX64 : "0x%*.*" PRIx64,
(int)(2 * item_byte_size), (int)(2 * item_byte_size),
DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
item_bit_offset));
} else {
s->Printf(wantsuppercase ? "0x%" PRIX64 : "0x%" PRIx64,
DE.GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size,
item_bit_offset));
}
break;
default: {
assert(item_bit_size == 0 && item_bit_offset == 0);
Expand Down
10 changes: 8 additions & 2 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4236,8 +4236,8 @@ bool TargetProperties::SetPreferDynamicValue(lldb::DynamicValueType d) {
}

bool TargetProperties::GetPreloadSymbols() const {
if (INTERRUPT_REQUESTED(m_target->GetDebugger(),
"Interrupted checking preload symbols")) {
if (INTERRUPT_REQUESTED(m_target->GetDebugger(),
"Interrupted checking preload symbols")) {
return false;
}
const uint32_t idx = ePropertyPreloadSymbols;
Expand Down Expand Up @@ -4539,6 +4539,12 @@ bool TargetProperties::GetEnableSyntheticValue() const {
idx, g_target_properties[idx].default_uint_value != 0);
}

bool TargetProperties::ShowHexVariableValuesWithLeadingZeroes() const {
const uint32_t idx = ePropertyShowHexVariableValuesWithLeadingZeroes;
return GetPropertyAtIndexAs<bool>(
idx, g_target_properties[idx].default_uint_value != 0);
}

uint32_t TargetProperties::GetMaxZeroPaddingInFloatFormat() const {
const uint32_t idx = ePropertyMaxZeroPaddingInFloatFormat;
return GetPropertyAtIndexAs<uint64_t>(
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Target/TargetProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ let Definition = "target" in {
def SaveObjectsDir: Property<"save-jit-objects-dir", "FileSpec">,
DefaultStringValue<"">,
Desc<"If specified, the directory to save intermediate object files generated by the LLVM JIT">;
def ShowHexVariableValuesWithLeadingZeroes: Property<"show-hex-variable-values-with-leading-zeroes", "Boolean">,
Global,
DefaultTrue,
Desc<"Whether to display leading zeroes when printing variable values in hex format.">;
def MaxZeroPaddingInFloatFormat: Property<"max-zero-padding-in-float-format", "UInt64">,
DefaultUnsignedValue<6>,
Desc<"The maximum number of zeroes to insert when displaying a very small float before falling back to scientific notation.">;
Expand Down
17 changes: 16 additions & 1 deletion lldb/test/API/python_api/value/TestValueAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""

import lldb
from lldbsuite.test import lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class ValueAPITestCase(TestBase):
Expand Down Expand Up @@ -206,3 +206,18 @@ def test(self):
-526164208,
"signed sinthex == -526164208",
)

# Check that hex value printing works as expected.
self.assertEqual(
frame0.FindVariable("fixed_int_ptr").GetValue(),
"0x00000000000000aa",
)
self.runCmd("settings set target.show-hex-values-with-leading-zeroes false")
self.assertEqual(
frame0.FindVariable("another_fixed_int_ptr").GetValue(),
"0xaa",
)
self.assertEqual(
frame0.FindVariable("a_null_int_ptr").GetValue(),
"0x0",
)
7 changes: 5 additions & 2 deletions lldb/test/API/python_api/value/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ int main (int argc, char const *argv[])
int i;
MyInt a = 12345;
struct MyStruct s = { 11, 22 };
struct MyBiggerStruct f = { 33, 44, 55 };
struct MyBiggerStruct f = { 33, 44, 55 };
int *my_int_ptr = &g_my_int;
printf("my_int_ptr points to location %p\n", my_int_ptr);
int *fixed_int_ptr = (int*)(void*)0xAA;
int *another_fixed_int_ptr = (int*)(void*)0xAA;
int *a_null_int_ptr = NULL;
const char **str_ptr = days_of_week;
for (i = 0; i < 7; ++i)
printf("%s\n", str_ptr[i]); // Break at this line
// and do str_ptr_val.GetChildAtIndex(5, lldb.eNoDynamicValues, True).

return 0;
}