Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,

bool GetAutoOneLineSummaries() const;

bool GetPrintBraces() const;

bool GetAutoIndent() const;

bool SetAutoIndent(bool b);
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class DumpValueObjectOptions {

DumpValueObjectOptions &SetRevealEmptyAggregates(bool reveal = true);

DumpValueObjectOptions &SetPrintBraces(bool print = true);

DumpValueObjectOptions &SetExpandPointerTypeFlags(unsigned flags);

DumpValueObjectOptions &SetElementCount(uint32_t element_count = 0);
Expand Down Expand Up @@ -162,6 +164,7 @@ class DumpValueObjectOptions {
bool m_allow_oneliner_mode : 1;
bool m_hide_pointer_value : 1;
bool m_reveal_empty_aggregates : 1;
bool m_print_braces : 1;
};

} // namespace lldb_private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class OptionGroupValueObjectDisplay : public OptionGroup {

bool show_types : 1, show_location : 1, flat_output : 1, use_object_desc : 1,
use_synth : 1, be_raw : 1, ignore_cap : 1, run_validator : 1,
max_depth_is_default : 1;
max_depth_is_default : 1, print_braces : 1;

uint32_t no_summary_depth;
uint32_t max_depth;
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ let Definition = "debugger", Path = "" in {
Global,
DefaultTrue,
Desc<"If true, LLDB will automatically display small structs in one-liner format (default: true).">;
def PrintBraces: Property<"print-braces", "Boolean">,
Global,
DefaultTrue,
Desc<"Print curly braces around structures when displaying variable values.">;
def AutoIndent: Property<"auto-indent", "Boolean">,
Global,
DefaultTrue,
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,12 @@ bool Debugger::GetAutoOneLineSummaries() const {
idx, g_debugger_properties[idx].default_uint_value != 0);
}

bool Debugger::GetPrintBraces() const {
const uint32_t idx = ePropertyPrintBraces;
return GetPropertyAtIndexAs<bool>(
idx, g_debugger_properties[idx].default_uint_value != 0);
}

bool Debugger::GetEscapeNonPrintables() const {
const uint32_t idx = ePropertyEscapeNonPrintables;
return GetPropertyAtIndexAs<bool>(
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/DataFormatters/DumpValueObjectOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ DumpValueObjectOptions::DumpValueObjectOptions()
m_hide_root_type(false), m_hide_root_name(false), m_hide_name(false),
m_hide_value(false), m_run_validator(false),
m_use_type_display_name(true), m_allow_oneliner_mode(true),
m_hide_pointer_value(false), m_reveal_empty_aggregates(true) {}
m_hide_pointer_value(false), m_reveal_empty_aggregates(true),
m_print_braces(true) {}

DumpValueObjectOptions::DumpValueObjectOptions(ValueObject &valobj)
: DumpValueObjectOptions() {
Expand Down Expand Up @@ -210,6 +211,11 @@ DumpValueObjectOptions::SetRevealEmptyAggregates(bool reveal) {
return *this;
}

DumpValueObjectOptions &DumpValueObjectOptions::SetPrintBraces(bool print) {
m_print_braces = print;
return *this;
}

DumpValueObjectOptions &
DumpValueObjectOptions::SetExpandPointerTypeFlags(unsigned flags) {
m_expand_ptr_type_flags = flags;
Expand Down
17 changes: 11 additions & 6 deletions lldb/source/DataFormatters/ValueObjectPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,16 @@ void ValueObjectPrinter::PrintChildrenPreamble(bool value_printed,
m_stream->EOL();
} else {
if (ShouldPrintValueObject()) {
if (IsRef()) {
m_stream->PutCString(": ");
} else if (value_printed || summary_printed || ShouldShowName()) {
m_stream->PutChar(' ');
if (m_options.m_print_braces) {
if (IsRef()) {
m_stream->PutCString(": ");
} else if (value_printed || summary_printed || ShouldShowName()) {
m_stream->PutChar(' ');
}

m_stream->PutChar('{');
}
m_stream->PutCString("{\n");
m_stream->EOL();
}
m_stream->IndentMore();
}
Expand Down Expand Up @@ -667,7 +671,8 @@ void ValueObjectPrinter::PrintChildrenPostamble(bool print_dotdotdot) {
m_stream->Indent("...\n");
}
m_stream->IndentLess();
m_stream->Indent("}\n");
if (m_options.m_print_braces)
m_stream->Indent("}\n");
}
}

Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void OptionGroupValueObjectDisplay::OptionParsingStarting(
be_raw = false;
ignore_cap = false;
run_validator = false;
print_braces = true;

TargetSP target_sp =
execution_context ? execution_context->GetTargetSP() : TargetSP();
Expand All @@ -180,6 +181,7 @@ void OptionGroupValueObjectDisplay::OptionParsingStarting(
auto max_depth_config = target_sp->GetMaximumDepthOfChildrenToDisplay();
max_depth = std::get<uint32_t>(max_depth_config);
max_depth_is_default = std::get<bool>(max_depth_config);
print_braces = target_sp->GetDebugger().GetPrintBraces();
} else {
// If we don't have any targets, then dynamic values won't do us much good.
use_dynamic = lldb::eNoDynamicValues;
Expand All @@ -203,6 +205,7 @@ DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
.SetUseSyntheticValue(use_synth)
.SetFlatOutput(flat_output)
.SetIgnoreCap(ignore_cap)
.SetPrintBraces(print_braces)
.SetFormat(format)
.SetSummary(summary_sp);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C_SOURCES := main.c
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestPrintBraces(TestBase):
def test_default_has_braces(self):
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
self.expect("frame variable s", substrs=["{", "}"])

def test_no_braces(self):
self.build()
self.runCmd("settings set print-braces false")
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
self.expect("frame variable s", matching=False, substrs=["{", "}"])
self.expect("frame variable s", substrs=["x = 1", "y = 2", "z = 3"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct Inner {
int x;
int y;
};

struct Outer {
struct Inner inner;
int z;
};

int main(void) {
struct Outer s = {{1, 2}, 3};
return s.z; // break here
}