[Lldb-commits] [lldb] [LLDB] added getName method in SBModule (PR #150331)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 24 10:54:01 PDT 2025
https://github.com/barsolo2000 updated https://github.com/llvm/llvm-project/pull/150331
>From b79edf938d49d03498ec3a9228344a684d0cbf6e Mon Sep 17 00:00:00 2001
From: Bar Soloveychik <barsolo at fb.com>
Date: Wed, 23 Jul 2025 15:17:29 -0700
Subject: [PATCH 1/3] [LLDB] added getName method in SBModule
---
lldb/include/lldb/API/SBModule.h | 3 +++
lldb/source/API/SBModule.cpp | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h
index 85332066ee687..ed90c48849699 100644
--- a/lldb/include/lldb/API/SBModule.h
+++ b/lldb/include/lldb/API/SBModule.h
@@ -296,6 +296,9 @@ class LLDB_API SBModule {
/// Remove any global modules which are no longer needed.
static void GarbageCollectAllocatedModules();
+ /// Return the name of the module.
+ const char *GetName() const;
+
private:
friend class SBAddress;
friend class SBFrame;
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 985107ec68efd..9eb0ae3cb3dba 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -671,3 +671,11 @@ void SBModule::GarbageCollectAllocatedModules() {
const bool mandatory = false;
ModuleList::RemoveOrphanSharedModules(mandatory);
}
+
+const char *SBModule::GetName() const {
+ LLDB_INSTRUMENT_VA(this);
+ if (!m_opaque_sp) {
+ return nullptr;
+ }
+ return m_opaque_sp->GetObjectName().AsCString();
+}
\ No newline at end of file
>From 019261475ee073345aac9faba2e20ac2ef980b79 Mon Sep 17 00:00:00 2001
From: Bar Soloveychik <barsolo at fb.com>
Date: Wed, 23 Jul 2025 16:00:07 -0700
Subject: [PATCH 2/3] added nullptr check
---
lldb/source/API/SBModule.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 9eb0ae3cb3dba..88cff3d6bcbf2 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -677,5 +677,9 @@ const char *SBModule::GetName() const {
if (!m_opaque_sp) {
return nullptr;
}
- return m_opaque_sp->GetObjectName().AsCString();
+ auto mod_name = m_opaque_sp->GetObjectName();
+ if (!mod_name) {
+ return nullptr;
+ }
+ return mod_name.AsCString();
}
\ No newline at end of file
>From 8a03abc421b049c98ca74da21b02bd44feb87c4b Mon Sep 17 00:00:00 2001
From: Bar Soloveychik <barsolo at fb.com>
Date: Thu, 24 Jul 2025 10:53:45 -0700
Subject: [PATCH 3/3] changed format and added a test to run darwin
---
lldb/source/API/SBModule.cpp | 12 ++++--------
lldb/test/API/python_api/sbmodule/TestSBModule.py | 11 +++++++++++
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 88cff3d6bcbf2..31508cb5ff1f4 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -674,12 +674,8 @@ void SBModule::GarbageCollectAllocatedModules() {
const char *SBModule::GetName() const {
LLDB_INSTRUMENT_VA(this);
- if (!m_opaque_sp) {
- return nullptr;
- }
- auto mod_name = m_opaque_sp->GetObjectName();
- if (!mod_name) {
- return nullptr;
- }
- return mod_name.AsCString();
+
+ if (!m_opaque_sp)
+ return nullptr;
+ return m_opaque_sp->GetObjectName().AsCString();
}
\ No newline at end of file
diff --git a/lldb/test/API/python_api/sbmodule/TestSBModule.py b/lldb/test/API/python_api/sbmodule/TestSBModule.py
index c04e2fa55e8cf..cc1019d2e8434 100644
--- a/lldb/test/API/python_api/sbmodule/TestSBModule.py
+++ b/lldb/test/API/python_api/sbmodule/TestSBModule.py
@@ -20,6 +20,17 @@ def tearDown(self):
@skipUnlessDarwin
@skipIfRemote
+ 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)
+ module_names = {target.GetModuleAtIndex(i).GetName() for i in range(target.GetNumModules())}
+ self.assertIn("a.out", module_names)
+
def test_module_is_file_backed(self):
"""Test the SBModule::IsFileBacked() method"""
self.build()
More information about the lldb-commits
mailing list