[Lldb-commits] [lldb] [lldb][split-dwarf] implement GetSeparateDebugInfo for SymbolFileOnDemand (PR #71230)

Tom Yang via lldb-commits lldb-commits at lists.llvm.org
Sun Nov 19 19:56:25 PST 2023


https://github.com/zhyty updated https://github.com/llvm/llvm-project/pull/71230

>From 68c8884696efab8991e71dfd892463b9873b5e46 Mon Sep 17 00:00:00 2001
From: Tom Yang <toyang at fb.com>
Date: Fri, 3 Nov 2023 13:45:37 -0700
Subject: [PATCH 1/5] [lldb][split-dwarf] implement GetSeparateDebugInfo for
 SymbolFileOnDemand

---
 lldb/include/lldb/Symbol/SymbolFileOnDemand.h |  5 ++++
 lldb/source/Commands/CommandObjectTarget.cpp  |  1 +
 .../dwo/TestDumpDwo.py                        | 26 +++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
index adf1017ce73c11b..9cbcef2a111d320 100644
--- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
+++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h
@@ -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,
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 8f052d0a7b837e2..31ad485ac236878 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2691,6 +2691,7 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles
                     "Found unsupported debug info type '%s'.\n",
                     type.str().c_str());
               }
+              strm.EOL();
               return true;
             });
       }
diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
index 163f5a112367693..881ee7b1dc71adf 100644
--- a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
@@ -130,3 +130,29 @@ def test_dwos_not_loaded_table_output(self):
                 "0x[a-zA-Z0-9]{16}\s+E\s+.*foo\.dwo",
             ],
         )
+
+    @skipIfRemote
+    @skipIfDarwin
+    @skipIfWindows
+    def test_dwos_loaded_symbols_on_demand(self):
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+        main_dwo = self.getBuildArtifact("main.dwo")
+        foo_dwo = self.getBuildArtifact("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]["main.dwo"]["loaded"])
+        self.assertTrue(output[exe]["foo.dwo"]["loaded"])

>From f2e2b100144dad2bfeb2d71efd8559a0a003bd27 Mon Sep 17 00:00:00 2001
From: Tom Yang <toyang at fb.com>
Date: Sun, 5 Nov 2023 10:06:12 -0800
Subject: [PATCH 2/5] add symbol on demand Darwin OSO tests

---
 .../oso/TestDumpOso.py                        | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py b/lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py
index b69938454659bda..06dc8234591844b 100644
--- a/lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/oso/TestDumpOso.py
@@ -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"])

>From da7cf854335ac93ce15fe457b3432f268f1cd36f Mon Sep 17 00:00:00 2001
From: Tom Yang <toyang at fb.com>
Date: Sun, 5 Nov 2023 10:22:16 -0800
Subject: [PATCH 3/5] Remove extra EOL

---
 lldb/source/Commands/CommandObjectTarget.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 31ad485ac236878..8f052d0a7b837e2 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2691,7 +2691,6 @@ class CommandObjectTargetModulesDumpSeparateDebugInfoFiles
                     "Found unsupported debug info type '%s'.\n",
                     type.str().c_str());
               }
-              strm.EOL();
               return true;
             });
       }

>From 2efa56974ee171b5f34f19607eefa652ef1b344a Mon Sep 17 00:00:00 2001
From: Tom Yang <toyang at fb.com>
Date: Sun, 19 Nov 2023 15:59:34 -0800
Subject: [PATCH 4/5] change dwo test to include other platforms, skipping if
 build failure

---
 .../dump-separate-debug-info/dwo/Makefile     |  6 +-
 .../dwo/TestDumpDwo.py                        | 74 +++++++++----------
 2 files changed, 36 insertions(+), 44 deletions(-)

diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile
index 3b6d788b2b0130a..ea236b3d975e047 100644
--- a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile
@@ -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.cpp $(SRCDIR)/foo.cpp
diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
index 881ee7b1dc71adf..a8f2dd4e92e8f8c 100644
--- a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
@@ -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):
@@ -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')
@@ -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)
@@ -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')
@@ -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)
@@ -131,14 +126,11 @@ def test_dwos_not_loaded_table_output(self):
             ],
         )
 
-    @skipIfRemote
-    @skipIfDarwin
-    @skipIfWindows
     def test_dwos_loaded_symbols_on_demand(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')
@@ -154,5 +146,5 @@ def test_dwos_loaded_symbols_on_demand(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"])

>From d3e5d26f1638d355f596a02b447fd045a0595dd9 Mon Sep 17 00:00:00 2001
From: Tom Yang <toyang at fb.com>
Date: Sun, 19 Nov 2023 19:55:52 -0800
Subject: [PATCH 5/5] formatting issues, rename the cpp to c since we're using
 $(CC)

---
 .../API/commands/target/dump-separate-debug-info/dwo/Makefile  | 2 +-
 .../target/dump-separate-debug-info/dwo/TestDumpDwo.py         | 2 +-
 .../target/dump-separate-debug-info/dwo/{foo.cpp => foo.c}     | 0
 .../API/commands/target/dump-separate-debug-info/dwo/main.c    | 3 +++
 .../API/commands/target/dump-separate-debug-info/dwo/main.cpp  | 3 ---
 5 files changed, 5 insertions(+), 5 deletions(-)
 rename lldb/test/API/commands/target/dump-separate-debug-info/dwo/{foo.cpp => foo.c} (100%)
 create mode 100644 lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.c
 delete mode 100644 lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.cpp

diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile
index ea236b3d975e047..99b3fb3bd7762f7 100644
--- a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/Makefile
@@ -1,4 +1,4 @@
 include Makefile.rules
 
 a.out:
-	$(CC) -target x86_64-pc-linux-elf -g -gsplit-dwarf -o $@ $(SRCDIR)/main.cpp $(SRCDIR)/foo.cpp
+	$(CC) -target x86_64-pc-linux-elf -g -gsplit-dwarf -o $@ $(SRCDIR)/main.c $(SRCDIR)/foo.c
diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
index a8f2dd4e92e8f8c..05c72945b14390e 100644
--- a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/TestDumpDwo.py
@@ -26,7 +26,7 @@ def get_dwos_from_json_output(self):
 
     def build_and_skip_if_error(self):
         try:
-            self.build() 
+            self.build()
         except BuildError as e:
             self.skipTest(f"Skipping test due to build exception: {e}")
 
diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/foo.cpp b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/foo.c
similarity index 100%
rename from lldb/test/API/commands/target/dump-separate-debug-info/dwo/foo.cpp
rename to lldb/test/API/commands/target/dump-separate-debug-info/dwo/foo.c
diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.c b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.c
new file mode 100644
index 000000000000000..2505586c52e43a9
--- /dev/null
+++ b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.c
@@ -0,0 +1,3 @@
+#include "foo.h"
+
+int main(void) { return foo(); }
diff --git a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.cpp b/lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.cpp
deleted file mode 100644
index 8087e682432798b..000000000000000
--- a/lldb/test/API/commands/target/dump-separate-debug-info/dwo/main.cpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "foo.h"
-
-int main() { return foo(); }



More information about the lldb-commits mailing list