[lldb] [llvm] LLDB Debuginfod usage tests (with fixes) (PR #79181)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 17:14:41 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r 777ac46ddbc318b5d5820d278a2e4dc2213699d8...2c6afa88cf3a095bd404d28d43e4aae5d164177f lldb/test/API/debuginfod/Normal/TestDebuginfod.py lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py lldb/packages/Python/lldbsuite/test/decorators.py lldb/packages/Python/lldbsuite/test/lldbplatformutil.py lldb/test/API/sanity/TestSettingSkipping.py lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py lldb/test/Shell/helper/build.py lldb/test/Shell/lit.cfg.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- test/API/debuginfod/Normal/TestDebuginfod.py	2024-03-07 01:11:44.000000 +0000
+++ test/API/debuginfod/Normal/TestDebuginfod.py	2024-03-07 01:14:26.293177 +0000
@@ -4,27 +4,30 @@
 
 import lldb
 import lldbsuite.test.lldbutil as lldbutil
 from lldbsuite.test.lldbtest import *
 
+
 def getUUID(aoutuuid):
     """
     Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
     to a file already, as part of the build.
     """
     import struct
+
     with open(aoutuuid, "rb") as f:
         data = f.read(36)
         if len(data) != 36:
             return None
         header = struct.unpack_from("<4I", data)
         if len(header) != 4:
             return None
         # 4 element 'prefix', 20 bytes of uuid, 3 byte long string, 'GNU':
-        if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554e47:
+        if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554E47:
             return None
         return data[16:].hex()
+
 
 def config_fake_debuginfod_server(uuid, debuginfo, executable):
     """
     Create a file-system 'hosted' debuginfod server for the given UUID.
     Make the filesystem look like:
@@ -35,32 +38,34 @@
     Returns the /tmp/<tmpdir> path
     """
     import os
     import shutil
     import tempfile
+
     tmpdir = tempfile.mkdtemp()
     uuiddir = os.path.join(tmpdir, "buildid", uuid)
     os.makedirs(uuiddir)
     os.makedirs(os.path.join(tmpdir, "cache"))
     # Move the files to the correct location for debuginfod to find
     if debuginfo:
         pass
-        #shutil.move(debuginfo, os.path.join(uuiddir, "debuginfo"))
+        # shutil.move(debuginfo, os.path.join(uuiddir, "debuginfo"))
 
     if executable:
         pass
-        #shutil.move(executable, os.path.join(uuiddir, "executable"))
+        # shutil.move(executable, os.path.join(uuiddir, "executable"))
 
     return tmpdir
 
 
 # Need to test 5 different scenarios:
 # 1 - A stripped binary with it's corresponding unstripped binary:
 # 2 - A stripped binary with a corresponding --only-keep-debug symbols file
 # 3 - A split binary with it's corresponding DWP file
 # 4 - A stripped, split binary with an unstripped binary and a DWP file
 # 5 - A stripped, split binary with an --only-keep-debug symbols file and a DWP file
+
 
 class DebugInfodTests(TestBase):
     # No need to try every flavor of debug inf.
     NO_DEBUG_INFO_TESTCASE = True
 
@@ -76,13 +81,19 @@
         # Setup the fake DebugInfoD server.
         server_root = config_fake_debuginfod_server(self.uuid, self.dwp, self.debugbin)
 
         # Configure LLDB properly
         self.runCmd("settings set symbols.enable-external-lookup true")
-        self.runCmd("settings set plugin.symbol-locator.debuginfod.cache-path %s/cache" % server_root)
+        self.runCmd(
+            "settings set plugin.symbol-locator.debuginfod.cache-path %s/cache"
+            % server_root
+        )
         self.runCmd("settings clear plugin.symbol-locator.debuginfod.server-urls")
-        cmd = "settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s" % server_root
+        cmd = (
+            "settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s"
+            % server_root
+        )
         self.runCmd(cmd)
         print(cmd)
         # Check to see if the symbol file is properly loaded
         self.main_source_file = lldb.SBFileSpec("main.c")
         self.sample_test()
@@ -105,11 +116,14 @@
         addr = loc.GetAddress()
         self.assertTrue(addr and addr.IsValid(), "Loc address is valid")
         line_entry = addr.GetLineEntry()
         self.assertTrue(line_entry and line_entry.IsValid(), "Loc line entry is valid")
         self.assertEqual(line_entry.GetLine(), 18)
-        self.assertEqual(loc.GetLineEntry().GetFileSpec().GetFilename(), self.main_source_file.GetFilename())
+        self.assertEqual(
+            loc.GetLineEntry().GetFileSpec().GetFilename(),
+            self.main_source_file.GetFilename(),
+        )
 
     def sample_test_no_launch(self):
         """Same as above but doesn't launch a process."""
 
         target = self.createTestTarget()
--- test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py	2024-03-07 01:11:44.000000 +0000
+++ test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py	2024-03-07 01:14:26.328542 +0000
@@ -4,27 +4,30 @@
 
 import lldb
 import lldbsuite.test.lldbutil as lldbutil
 from lldbsuite.test.lldbtest import *
 
+
 def getUUID(aoutuuid):
     """
     Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
     to a file already, as part of the build.
     """
     import struct
+
     with open(aoutuuid, "rb") as f:
         data = f.read(36)
         if len(data) != 36:
             return None
         header = struct.unpack_from("<4I", data)
         if len(header) != 4:
             return None
         # 4 element 'prefix', 20 bytes of uuid, 3 byte long string, 'GNU':
-        if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554e47:
+        if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554E47:
             return None
         return data[16:].hex()
+
 
 def config_fake_debuginfod_server(uuid, debuginfo, executable):
     """
     Create a file-system 'hosted' debuginfod server for the given UUID.
     Make the filesystem look like:
@@ -35,32 +38,34 @@
     Returns the /tmp/<tmpdir> path
     """
     import os
     import shutil
     import tempfile
+
     tmpdir = tempfile.mkdtemp()
     uuiddir = os.path.join(tmpdir, "buildid", uuid)
     os.makedirs(uuiddir)
     os.makedirs(os.path.join(tmpdir, "cache"))
     # Move the files to the correct location for debuginfod to find
     if debuginfo:
         pass
-        #shutil.move(debuginfo, os.path.join(uuiddir, "debuginfo"))
+        # shutil.move(debuginfo, os.path.join(uuiddir, "debuginfo"))
 
     if executable:
         pass
-        #shutil.move(executable, os.path.join(uuiddir, "executable"))
+        # shutil.move(executable, os.path.join(uuiddir, "executable"))
 
     return tmpdir
 
 
 # Need to test 5 different scenarios:
 # 1 - A stripped binary with it's corresponding unstripped binary:
 # 2 - A stripped binary with a corresponding --only-keep-debug symbols file
 # 3 - A split binary with it's corresponding DWP file
 # 4 - A stripped, split binary with an unstripped binary and a DWP file
 # 5 - A stripped, split binary with an --only-keep-debug symbols file and a DWP file
+
 
 class DebugInfodTests(TestBase):
     # No need to try every flavor of debug inf.
     NO_DEBUG_INFO_TESTCASE = True
 
@@ -76,13 +81,19 @@
         # Setup the fake DebugInfoD server.
         server_root = config_fake_debuginfod_server(self.uuid, self.dwp, self.debugbin)
 
         # Configure LLDB properly
         self.runCmd("settings set symbols.enable-external-lookup true")
-        self.runCmd("settings set plugin.symbol-locator.debuginfod.cache-path %s/cache" % server_root)
+        self.runCmd(
+            "settings set plugin.symbol-locator.debuginfod.cache-path %s/cache"
+            % server_root
+        )
         self.runCmd("settings clear plugin.symbol-locator.debuginfod.server-urls")
-        cmd = "settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s" % server_root
+        cmd = (
+            "settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s"
+            % server_root
+        )
         self.runCmd(cmd)
         print(cmd)
         # Check to see if the symbol file is properly loaded
         self.main_source_file = lldb.SBFileSpec("main.c")
         self.sample_test()
@@ -105,11 +116,14 @@
         addr = loc.GetAddress()
         self.assertTrue(addr and addr.IsValid(), "Loc address is valid")
         line_entry = addr.GetLineEntry()
         self.assertTrue(line_entry and line_entry.IsValid(), "Loc line entry is valid")
         self.assertEqual(line_entry.GetLine(), 18)
-        self.assertEqual(loc.GetLineEntry().GetFileSpec().GetFilename(), self.main_source_file.GetFilename())
+        self.assertEqual(
+            loc.GetLineEntry().GetFileSpec().GetFilename(),
+            self.main_source_file.GetFilename(),
+        )
 
     def sample_test_no_launch(self):
         """Same as above but doesn't launch a process."""
 
         target = self.createTestTarget()

``````````

</details>


https://github.com/llvm/llvm-project/pull/79181


More information about the llvm-commits mailing list