Skip to content

[lldb][split-dwarf] Add --errors-only argument separate-debug-info list #71000

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 3 commits into from
Nov 2, 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
7 changes: 6 additions & 1 deletion lldb/include/lldb/Symbol/SymbolFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,12 @@ class SymbolFile : public PluginInterface {
/// contains the keys "type", "symfile", and "separate-debug-info-files".
/// "type" can be used to assume the structure of each object in
/// "separate-debug-info-files".
virtual bool GetSeparateDebugInfo(StructuredData::Dictionary &d) {
/// \param errors_only
/// If true, then only return separate debug info files that encountered
/// errors during loading. If false, then return all expected separate
/// debug info files, regardless of whether they were successfully loaded.
virtual bool GetSeparateDebugInfo(StructuredData::Dictionary &d,
bool errors_only) {
return false;
};

Expand Down
20 changes: 14 additions & 6 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,11 +1452,11 @@ static bool DumpModuleSymbolFile(Stream &strm, Module *module) {
}

static bool GetSeparateDebugInfoList(StructuredData::Array &list,
Module *module) {
Module *module, bool errors_only) {
if (module) {
if (SymbolFile *symbol_file = module->GetSymbolFile(/*can_create=*/true)) {
StructuredData::Dictionary d;
if (symbol_file->GetSeparateDebugInfo(d)) {
if (symbol_file->GetSeparateDebugInfo(d, errors_only)) {
list.AddItem(
std::make_shared<StructuredData::Dictionary>(std::move(d)));
return true;
Expand Down Expand Up @@ -2561,7 +2561,10 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles
m_json.SetCurrentValue(true);
m_json.SetOptionWasSet();
break;

case 'e':
m_errors_only.SetCurrentValue(true);
m_errors_only.SetOptionWasSet();
break;
default:
llvm_unreachable("Unimplemented option");
}
Expand All @@ -2570,13 +2573,15 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles

void OptionParsingStarting(ExecutionContext *execution_context) override {
m_json.Clear();
m_errors_only.Clear();
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_target_modules_dump_separate_debug_info_options);
}

OptionValueBoolean m_json = false;
OptionValueBoolean m_errors_only = false;
};

protected:
Expand Down Expand Up @@ -2607,7 +2612,8 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles
break;

if (GetSeparateDebugInfoList(separate_debug_info_lists_by_module,
module_sp.get()))
module_sp.get(),
bool(m_options.m_errors_only)))
num_dumped++;
}
} else {
Expand All @@ -2628,7 +2634,7 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles
break;
Module *module = module_list.GetModulePointerAtIndex(i);
if (GetSeparateDebugInfoList(separate_debug_info_lists_by_module,
module))
module, bool(m_options.m_errors_only)))
num_dumped++;
}
} else
Expand All @@ -2639,11 +2645,13 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles

if (num_dumped > 0) {
Stream &strm = result.GetOutputStream();
// Display the debug info files in some format.
if (m_options.m_json) {
// JSON format
separate_debug_info_lists_by_module.Dump(strm,
/*pretty_print=*/true);
} else {
// List the debug info files in human readable form.
// Human-readable table format
separate_debug_info_lists_by_module.ForEach(
[&result, &strm](StructuredData::Object *obj) {
if (!obj) {
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let Command = "target modules dump symtab" in {

let Command = "target modules dump separate debug info" in {
def tm_json : Option<"json", "j">, Group<1>,
Desc<"Output the details in JSON format.">;
Desc<"Output the details in JSON format.">;
def tm_errors_only : Option<"errors-only", "e">, Group<1>,
Desc<"Filter to show only debug info files with errors.">;
}

let Command = "help" in {
Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4243,7 +4243,8 @@ void SymbolFileDWARF::DumpClangAST(Stream &s) {
clang->Dump(s.AsRawOstream());
}

bool SymbolFileDWARF::GetSeparateDebugInfo(StructuredData::Dictionary &d) {
bool SymbolFileDWARF::GetSeparateDebugInfo(StructuredData::Dictionary &d,
bool errors_only) {
StructuredData::Array separate_debug_info_files;
DWARFDebugInfo &info = DebugInfo();
const size_t num_cus = info.GetNumUnits();
Expand Down Expand Up @@ -4296,7 +4297,8 @@ bool SymbolFileDWARF::GetSeparateDebugInfo(StructuredData::Dictionary &d) {
dwarf_cu->GetDwoError().AsCString("unknown"));
}
dwo_data->AddBooleanItem("loaded", dwo_symfile != nullptr);
separate_debug_info_files.AddItem(dwo_data);
if (!errors_only || dwo_data->HasKey("error"))
separate_debug_info_files.AddItem(dwo_data);
}

d.AddStringItem("type", "dwo");
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class SymbolFileDWARF : public SymbolFileCommon {
void DumpClangAST(Stream &s) override;

/// List separate dwo files.
bool GetSeparateDebugInfo(StructuredData::Dictionary &d) override;
bool GetSeparateDebugInfo(StructuredData::Dictionary &d,
bool errors_only) override;

DWARFContext &GetDWARFContext() { return m_context; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s) {
}

bool SymbolFileDWARFDebugMap::GetSeparateDebugInfo(
lldb_private::StructuredData::Dictionary &d) {
lldb_private::StructuredData::Dictionary &d, bool errors_only) {
StructuredData::Array separate_debug_info_files;
const uint32_t cu_count = GetNumCompileUnits();
for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
Expand All @@ -1302,7 +1302,8 @@ bool SymbolFileDWARFDebugMap::GetSeparateDebugInfo(
oso_data->AddStringItem("error", info.oso_load_error.AsCString());
}
oso_data->AddBooleanItem("loaded", loaded_successfully);
separate_debug_info_files.AddItem(oso_data);
if (!errors_only || oso_data->HasKey("error"))
separate_debug_info_files.AddItem(oso_data);
}

d.AddStringItem("type", "oso");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
void DumpClangAST(Stream &s) override;

/// List separate oso files.
bool GetSeparateDebugInfo(StructuredData::Dictionary &d) override;
bool GetSeparateDebugInfo(StructuredData::Dictionary &d,
bool errors_only) override;

// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class TestDumpDWO(lldbtest.TestBase):
NO_DEBUG_INFO_TESTCASE = True

def get_dwos_from_json(self):
def get_dwos_from_json_output(self):
"""Returns a dictionary of `symfile` -> {`dwo_name` -> dwo_info object}."""
result = {}
output = json.loads(self.res.GetOutput())
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_dwos_loaded_json_output(self):
self.runCmd("target modules dump separate-debug-info --json")

# Check the output
output = self.get_dwos_from_json()
output = self.get_dwos_from_json_output()
self.assertTrue(output[exe]["main.dwo"]["loaded"])
self.assertTrue(output[exe]["foo.dwo"]["loaded"])

Expand All @@ -55,21 +55,27 @@ def test_dwos_not_loaded_json_output(self):
main_dwo = self.getBuildArtifact("main.dwo")
foo_dwo = self.getBuildArtifact("foo.dwo")

# REMOVE the dwo files
# REMOVE one of the dwo files
os.unlink(main_dwo)
os.unlink(foo_dwo)

target = self.dbg.CreateTarget(exe)
self.assertTrue(target, lldbtest.VALID_TARGET)

self.runCmd("target modules dump separate-debug-info --json")

# Check the output
output = self.get_dwos_from_json()
output = self.get_dwos_from_json_output()
self.assertFalse(output[exe]["main.dwo"]["loaded"])
self.assertIn("error", output[exe]["main.dwo"])
self.assertTrue(output[exe]["foo.dwo"]["loaded"])
self.assertNotIn("error", output[exe]["foo.dwo"])

# Check with --errors-only
self.runCmd("target modules dump separate-debug-info --json --errors-only")
output = self.get_dwos_from_json_output()
self.assertFalse(output[exe]["main.dwo"]["loaded"])
self.assertFalse(output[exe]["foo.dwo"]["loaded"])
self.assertIn("error", output[exe]["main.dwo"])
self.assertIn("error", output[exe]["foo.dwo"])
self.assertNotIn("foo.dwo", output[exe])

@skipIfRemote
@skipIfDarwin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class TestDumpOso(lldbtest.TestBase):
NO_DEBUG_INFO_TESTCASE = True

def get_osos_from_json(self):
def get_osos_from_json_output(self):
"""Returns a dictionary of `symfile` -> {`OSO_PATH` -> oso_info object}."""
result = {}
output = json.loads(self.res.GetOutput())
Expand Down Expand Up @@ -41,7 +41,7 @@ def test_shows_oso_loaded_json_output(self):
self.runCmd("target modules dump separate-debug-info --json")

# Check the output
osos = self.get_osos_from_json()
osos = self.get_osos_from_json_output()
self.assertTrue(osos[exe][main_o]["loaded"])
self.assertTrue(osos[exe][foo_o]["loaded"])

Expand All @@ -55,17 +55,25 @@ def test_shows_oso_not_loaded_json_output(self):

# REMOVE the o files
os.unlink(main_o)
os.unlink(foo_o)

target = self.dbg.CreateTarget(exe)
self.assertTrue(target, lldbtest.VALID_TARGET)

self.runCmd("target modules dump separate-debug-info --json")

# Check the output
osos = self.get_osos_from_json()
osos = self.get_osos_from_json_output()
self.assertFalse(osos[exe][main_o]["loaded"])
self.assertFalse(osos[exe][foo_o]["loaded"])
self.assertIn("error", osos[exe][main_o])
self.assertTrue(osos[exe][foo_o]["loaded"])
self.assertNotIn("error", osos[exe][foo_o])

# Check with --errors-only
self.runCmd("target modules dump separate-debug-info --json --errors-only")
output = self.get_osos_from_json_output()
self.assertFalse(output[exe][main_o]["loaded"])
self.assertIn("error", output[exe][main_o])
self.assertNotIn(foo_o, output[exe])

@skipIfRemote
@skipUnlessDarwin
Expand Down