[lldb] Fix term-width setting (#82736)

I noticed that the term-width setting would always report its default
value (80) despite the driver correctly setting the value with
SBDebugger::SetTerminalWidth.

```
(lldb) settings show term-width
term-width (int) = 80
```

The issue is that the setting was defined as a SInt64 instead of a
UInt64 while the getter returned an unsigned value. There's no reason
the terminal width should be a signed value. My best guess it that it
was using SInt64 because UInt64 didn't support min and max values. I
fixed that and correct the type and now lldb reports the correct
terminal width:

```
(lldb) settings show term-width
term-width (unsigned) = 189
```

rdar://123488999
This commit is contained in:
Jonas Devlieghere
2024-02-22 21:48:49 -08:00
committed by GitHub
parent 0d72fe9777
commit afd469023a
7 changed files with 52 additions and 15 deletions

View File

@@ -86,8 +86,8 @@ public:
protected:
int64_t m_current_value = 0;
int64_t m_default_value = 0;
int64_t m_min_value = INT64_MIN;
int64_t m_max_value = INT64_MAX;
int64_t m_min_value = std::numeric_limits<int64_t>::min();
int64_t m_max_value = std::numeric_limits<int64_t>::max();
};
} // namespace lldb_private

View File

@@ -64,13 +64,35 @@ public:
uint64_t GetDefaultValue() const { return m_default_value; }
void SetCurrentValue(uint64_t value) { m_current_value = value; }
bool SetCurrentValue(uint64_t value) {
if (value >= m_min_value && value <= m_max_value) {
m_current_value = value;
return true;
}
return false;
}
void SetDefaultValue(uint64_t value) { m_default_value = value; }
bool SetDefaultValue(uint64_t value) {
if (value >= m_min_value && value <= m_max_value) {
m_default_value = value;
return true;
}
return false;
}
void SetMinimumValue(int64_t v) { m_min_value = v; }
uint64_t GetMinimumValue() const { return m_min_value; }
void SetMaximumValue(int64_t v) { m_max_value = v; }
uint64_t GetMaximumValue() const { return m_max_value; }
protected:
uint64_t m_current_value = 0;
uint64_t m_default_value = 0;
uint64_t m_min_value = std::numeric_limits<uint64_t>::min();
uint64_t m_max_value = std::numeric_limits<uint64_t>::max();
};
} // namespace lldb_private

View File

@@ -132,7 +132,7 @@ let Definition = "debugger" in {
Global,
DefaultStringValue<"${ansi.normal}">,
Desc<"When displaying the line marker in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the line to be marked.">;
def TerminalWidth: Property<"term-width", "SInt64">,
def TerminalWidth: Property<"term-width", "UInt64">,
Global,
DefaultUnsignedValue<80>,
Desc<"The maximum number of columns to use for displaying text.">;

View File

@@ -886,8 +886,8 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
}
assert(m_dummy_target_sp.get() && "Couldn't construct dummy target?");
OptionValueSInt64 *term_width =
m_collection_sp->GetPropertyAtIndexAsOptionValueSInt64(
OptionValueUInt64 *term_width =
m_collection_sp->GetPropertyAtIndexAsOptionValueUInt64(
ePropertyTerminalWidth);
term_width->SetMinimumValue(10);
term_width->SetMaximumValue(1024);

View File

@@ -47,9 +47,16 @@ Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,
llvm::StringRef value_trimmed = value_ref.trim();
uint64_t value;
if (llvm::to_integer(value_trimmed, value)) {
m_value_was_set = true;
m_current_value = value;
NotifyValueChanged();
if (value >= m_min_value && value <= m_max_value) {
m_value_was_set = true;
m_current_value = value;
NotifyValueChanged();
} else {
error.SetErrorStringWithFormat(
"%" PRIu64 " is out of range, valid values must be between %" PRIu64
" and %" PRIu64 ".",
value, m_min_value, m_max_value);
}
} else {
error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
value_ref.str().c_str());

View File

@@ -2,7 +2,6 @@
Test lldb settings command.
"""
import json
import os
import re
@@ -151,14 +150,22 @@ class SettingsCommandTestCase(TestBase):
self.expect(
"settings show term-width",
SETTING_MSG("term-width"),
startstr="term-width (int) = 70",
startstr="term-width (unsigned) = 70",
)
# The overall display should also reflect the new setting.
self.expect(
"settings show",
SETTING_MSG("term-width"),
substrs=["term-width (int) = 70"],
substrs=["term-width (unsigned) = 70"],
)
self.dbg.SetTerminalWidth(60)
self.expect(
"settings show",
SETTING_MSG("term-width"),
substrs=["term-width (unsigned) = 60"],
)
# rdar://problem/10712130
@@ -593,7 +600,7 @@ class SettingsCommandTestCase(TestBase):
self.expect(
"settings show term-width",
SETTING_MSG("term-width"),
startstr="term-width (int) = 60",
startstr="term-width (unsigned) = 60",
)
self.runCmd("settings clear term-width", check=False)
# string

View File

@@ -24,7 +24,8 @@ class TestTrimmedProgressReporting(PExpectTest):
)
self.expect("set set term-width " + str(term_width))
self.expect(
"set show term-width", substrs=["term-width (int) = " + str(term_width)]
"set show term-width",
substrs=["term-width (unsigned) = " + str(term_width)],
)
self.child.send("file " + self.getBuildArtifact("a.out") + "\n")