[Lldb-commits] [lldb] [LLDB] added getName method in SBModule (PR #150331)

Jacob Lalonde via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 29 10:53:35 PDT 2025


================
@@ -18,6 +18,26 @@ def tearDown(self):
         if self.background_pid:
             os.kill(self.background_pid, signal.SIGKILL)
 
+    def test_getname(self):
+        """Test the SBModule::GetName() method"""
+        self.build()
+        target, _, _, _ = lldbutil.run_to_source_breakpoint(
+            self, "// break here", lldb.SBFileSpec("main.c")
+        )
+
+        self.assertGreater(target.GetNumModules(), 0)
+        for i in range(target.GetNumModules()):
+            module = target.GetModuleAtIndex(i)
+            file_spec = module.GetFileSpec()
+            name = module.GetName()
+            if file_spec.IsValid() and file_spec.exists:
+#If file is valid and file exist, expect GetName() to be None
+                self.assertIsNone(name, f"Expected None for module with valid file {file_spec.GetFilename()}, got {name!r}")
+            else:
+#If no valid file, expect GetName() to be a non - empty string
+                self.assertIsInstance(name, str)
+                self.assertTrue(name, "Expected a non-empty name for module without a valid file")
----------------
Jlalond wrote:

Thanks for the great context on this Pavel

> What do you intend to use this for? Just show it to the user, or use in some sort of a critical capacity?

I'm currently trying to generate some metrics around Modules, and there are some cases where I don't have access to the UUID. I think the identifier would be great, but a generic name field would also be nice for logging.

Should we pivot this change to expose the `m_file` name if `m_object_name` is not present? If I follow correct the precedence of 'uniqueness' is 

- UUID
- The numerical ID you linked
- Object name
- File name

Having a 'helper' accessor exposing the object name or the file name would solve my needs.


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


More information about the lldb-commits mailing list