Skip to content

[lldb][split-dwarf] implement GetSeparateDebugInfo for SymbolFileOnDemand #71230

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 5 commits into from
Nov 20, 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
5 changes: 5 additions & 0 deletions lldb/include/lldb/Symbol/SymbolFileOnDemand.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile {
return m_sym_file_impl->SetDebugInfoHadFrameVariableErrors();
}

bool GetSeparateDebugInfo(StructuredData::Dictionary &d,
bool errors_only) override {
return m_sym_file_impl->GetSeparateDebugInfo(d, errors_only);
}

lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
std::optional<uint64_t> byte_size,
SymbolContextScope *context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXX_SOURCES := main.cpp foo.cpp
CFLAGS_EXTRAS := -gsplit-dwarf

include Makefile.rules

a.out:
$(CC) -target x86_64-pc-linux-elf -g -gsplit-dwarf -o $@ $(SRCDIR)/main.c $(SRCDIR)/foo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from lldbsuite.test import lldbtest, lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test_event.build_exception import BuildError


class TestDumpDWO(lldbtest.TestBase):
Expand All @@ -23,14 +24,17 @@ def get_dwos_from_json_output(self):
result[symfile_entry["symfile"]] = dwo_dict
return result

@skipIfRemote
@skipIfDarwin
@skipIfWindows
def build_and_skip_if_error(self):
try:
self.build()
except BuildError as e:
self.skipTest(f"Skipping test due to build exception: {e}")

def test_dwos_loaded_json_output(self):
self.build()
self.build_and_skip_if_error()
exe = self.getBuildArtifact("a.out")
main_dwo = self.getBuildArtifact("main.dwo")
foo_dwo = self.getBuildArtifact("foo.dwo")
main_dwo = self.getBuildArtifact("a.out-main.dwo")
foo_dwo = self.getBuildArtifact("a.out-foo.dwo")

# Make sure dwo files exist
self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists')
Expand All @@ -43,17 +47,14 @@ def test_dwos_loaded_json_output(self):

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

@skipIfRemote
@skipIfDarwin
@skipIfWindows
def test_dwos_not_loaded_json_output(self):
self.build()
self.build_and_skip_if_error()
exe = self.getBuildArtifact("a.out")
main_dwo = self.getBuildArtifact("main.dwo")
foo_dwo = self.getBuildArtifact("foo.dwo")
main_dwo = self.getBuildArtifact("a.out-main.dwo")
foo_dwo = self.getBuildArtifact("a.out-foo.dwo")

# REMOVE one of the dwo files
os.unlink(main_dwo)
Expand All @@ -65,26 +66,23 @@ def test_dwos_not_loaded_json_output(self):

# Check the output
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"])
self.assertFalse(output[exe]["a.out-main.dwo"]["loaded"])
self.assertIn("error", output[exe]["a.out-main.dwo"])
self.assertTrue(output[exe]["a.out-foo.dwo"]["loaded"])
self.assertNotIn("error", output[exe]["a.out-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.assertIn("error", output[exe]["main.dwo"])
self.assertNotIn("foo.dwo", output[exe])
self.assertFalse(output[exe]["a.out-main.dwo"]["loaded"])
self.assertIn("error", output[exe]["a.out-main.dwo"])
self.assertNotIn("a.out-foo.dwo", output[exe])

@skipIfRemote
@skipIfDarwin
@skipIfWindows
def test_dwos_loaded_table_output(self):
self.build()
self.build_and_skip_if_error()
exe = self.getBuildArtifact("a.out")
main_dwo = self.getBuildArtifact("main.dwo")
foo_dwo = self.getBuildArtifact("foo.dwo")
main_dwo = self.getBuildArtifact("a.out-main.dwo")
foo_dwo = self.getBuildArtifact("a.out-foo.dwo")

# Make sure dwo files exist
self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists')
Expand All @@ -104,14 +102,11 @@ def test_dwos_loaded_table_output(self):
],
)

@skipIfRemote
@skipIfDarwin
@skipIfWindows
def test_dwos_not_loaded_table_output(self):
self.build()
self.build_and_skip_if_error()
exe = self.getBuildArtifact("a.out")
main_dwo = self.getBuildArtifact("main.dwo")
foo_dwo = self.getBuildArtifact("foo.dwo")
main_dwo = self.getBuildArtifact("a.out-main.dwo")
foo_dwo = self.getBuildArtifact("a.out-foo.dwo")

# REMOVE the dwo files
os.unlink(main_dwo)
Expand All @@ -130,3 +125,26 @@ def test_dwos_not_loaded_table_output(self):
"0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.dwo",
],
)

def test_dwos_loaded_symbols_on_demand(self):
self.build_and_skip_if_error()
exe = self.getBuildArtifact("a.out")
main_dwo = self.getBuildArtifact("a.out-main.dwo")
foo_dwo = self.getBuildArtifact("a.out-foo.dwo")

# Make sure dwo files exist
self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists')
self.assertTrue(os.path.exists(foo_dwo), f'Make sure "{foo_dwo}" file exists')

# Load symbols on-demand
self.runCmd("settings set symbols.load-on-demand true")

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.assertTrue(output[exe]["a.out-main.dwo"]["loaded"])
self.assertTrue(output[exe]["a.out-foo.dwo"]["loaded"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "foo.h"

int main(void) { return foo(); }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,33 @@ def test_shows_oso_not_loaded_table_output(self):
"0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.o",
],
)

@skipIfRemote
@skipUnlessDarwin
def test_osos_loaded_symbols_on_demand(self):
self.build(debug_info="dwarf")
exe = self.getBuildArtifact("a.out")
main_o = self.getBuildArtifact("main.o")
foo_o = self.getBuildArtifact("foo.o")

# Make sure o files exist
self.assertTrue(os.path.exists(main_o), f'Make sure "{main_o}" file exists')
self.assertTrue(os.path.exists(foo_o), f'Make sure "{foo_o}" file exists')

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

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

# Load symbols on-demand
self.runCmd("settings set symbols.load-on-demand true")

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_output()
self.assertTrue(osos[exe][main_o]["loaded"])
self.assertTrue(osos[exe][foo_o]["loaded"])