summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/API/SBModule.h15
-rw-r--r--lldb/include/lldb/API/SBTarget.h15
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py26
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py22
-rw-r--r--lldb/scripts/interface/SBModule.i17
-rw-r--r--lldb/scripts/interface/SBTarget.i17
-rw-r--r--lldb/source/API/SBModule.cpp11
-rw-r--r--lldb/source/API/SBTarget.cpp12
8 files changed, 135 insertions, 0 deletions
diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h
index bcc3997a275..d73267f8af5 100644
--- a/lldb/include/lldb/API/SBModule.h
+++ b/lldb/include/lldb/API/SBModule.h
@@ -129,6 +129,21 @@ public:
lldb::SBCompileUnit GetCompileUnitAtIndex(uint32_t);
+ //------------------------------------------------------------------
+ /// Find compile units related to *this module and passed source
+ /// file.
+ ///
+ /// @param[in] sb_file_spec
+ /// A lldb::SBFileSpec object that contains source file
+ /// specification.
+ ///
+ /// @return
+ /// A lldb::SBSymbolContextList that gets filled in with all of
+ /// the symbol contexts for all the matches.
+ //------------------------------------------------------------------
+ lldb::SBSymbolContextList
+ FindCompileUnits(const lldb::SBFileSpec &sb_file_spec);
+
size_t GetNumSymbols();
lldb::SBSymbol GetSymbolAtIndex(size_t idx);
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index a53c5273688..8d99545902f 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -292,6 +292,21 @@ public:
lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec);
+ //------------------------------------------------------------------
+ /// Find compile units related to *this target and passed source
+ /// file.
+ ///
+ /// @param[in] sb_file_spec
+ /// A lldb::SBFileSpec object that contains source file
+ /// specification.
+ ///
+ /// @return
+ /// A lldb::SBSymbolContextList that gets filled in with all of
+ /// the symbol contexts for all the matches.
+ //------------------------------------------------------------------
+ lldb::SBSymbolContextList
+ FindCompileUnits(const lldb::SBFileSpec &sb_file_spec);
+
lldb::ByteOrder GetByteOrder();
uint32_t GetAddressByteSize();
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py b/lldb/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
index 654387fdf87..65b159974c0 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
@@ -141,3 +141,29 @@ class ModuleAndSectionAPIsTestCase(TestBase):
INDENT2 = INDENT * 2
for cu in exe_module.compile_unit_iter():
print(cu)
+
+ @add_test_categories(['pyapi'])
+ def test_find_compile_units(self):
+ """Exercise SBModule.FindCompileUnits() API."""
+ d = {'EXE': 'b.out'}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.find_compile_units(self.getBuildArtifact('b.out'))
+
+ def find_compile_units(self, exe):
+ """Exercise SBModule.FindCompileUnits() API."""
+ source_name_list = ["main.cpp", "b.cpp", "c.cpp"]
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ num_modules = target.GetNumModules()
+ for i in range(num_modules):
+ module = target.GetModuleAtIndex(i)
+ for source_name in source_name_list:
+ list = module.FindCompileUnits(lldb.SBFileSpec(source_name, False))
+ for sc in list:
+ self.assertTrue(
+ sc.GetCompileUnit().GetFileSpec().GetFilename() ==
+ source_name)
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py b/lldb/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
index 3787f55f233..224dca77daa 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
@@ -46,6 +46,14 @@ class TargetAPITestCase(TestBase):
self.find_global_variables('b.out')
@add_test_categories(['pyapi'])
+ def test_find_compile_units(self):
+ """Exercise SBTarget.FindCompileUnits() API."""
+ d = {'EXE': 'b.out'}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.find_compile_units(self.getBuildArtifact('b.out'))
+
+ @add_test_categories(['pyapi'])
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778")
def test_find_functions(self):
"""Exercise SBTarget.FindFunctions() API."""
@@ -219,6 +227,20 @@ class TargetAPITestCase(TestBase):
value_list.GetValueAtIndex(0).GetValue() == "'X'")
break
+ def find_compile_units(self, exe):
+ """Exercise SBTarget.FindCompileUnits() API."""
+ source_name = "main.c"
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ list = target.FindCompileUnits(lldb.SBFileSpec(source_name, False))
+ # Executable has been built just from one source file 'main.c',
+ # so we may check only the first element of list.
+ self.assertTrue(
+ list[0].GetCompileUnit().GetFileSpec().GetFilename() == source_name)
+
def find_functions(self, exe_name):
"""Exercise SBTaget.FindFunctions() API."""
exe = self.getBuildArtifact(exe_name)
diff --git a/lldb/scripts/interface/SBModule.i b/lldb/scripts/interface/SBModule.i
index 71a2198609d..adda954e5bf 100644
--- a/lldb/scripts/interface/SBModule.i
+++ b/lldb/scripts/interface/SBModule.i
@@ -179,6 +179,23 @@ public:
lldb::SBCompileUnit
GetCompileUnitAtIndex (uint32_t);
+ %feature("docstring", "
+ //------------------------------------------------------------------
+ /// Find compile units related to *this module and passed source
+ /// file.
+ ///
+ /// @param[in] sb_file_spec
+ /// A lldb::SBFileSpec object that contains source file
+ /// specification.
+ ///
+ /// @return
+ /// A lldb::SBSymbolContextList that gets filled in with all of
+ /// the symbol contexts for all the matches.
+ //------------------------------------------------------------------
+ ") FindCompileUnits;
+ lldb::SBSymbolContextList
+ FindCompileUnits (const lldb::SBFileSpec &sb_file_spec);
+
size_t
GetNumSymbols ();
diff --git a/lldb/scripts/interface/SBTarget.i b/lldb/scripts/interface/SBTarget.i
index 191f5225769..08fb268c08b 100644
--- a/lldb/scripts/interface/SBTarget.i
+++ b/lldb/scripts/interface/SBTarget.i
@@ -405,6 +405,23 @@ public:
lldb::SBModule
FindModule (const lldb::SBFileSpec &file_spec);
+ %feature("docstring", "
+ //------------------------------------------------------------------
+ /// Find compile units related to *this target and passed source
+ /// file.
+ ///
+ /// @param[in] sb_file_spec
+ /// A lldb::SBFileSpec object that contains source file
+ /// specification.
+ ///
+ /// @return
+ /// A lldb::SBSymbolContextList that gets filled in with all of
+ /// the symbol contexts for all the matches.
+ //------------------------------------------------------------------
+ ") FindCompileUnits;
+ lldb::SBSymbolContextList
+ FindCompileUnits (const lldb::SBFileSpec &sb_file_spec);
+
lldb::ByteOrder
GetByteOrder ();
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index ed0c75c5c3e..3dd99d5321b 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -253,6 +253,17 @@ SBCompileUnit SBModule::GetCompileUnitAtIndex(uint32_t index) {
return sb_cu;
}
+SBSymbolContextList
+SBModule::FindCompileUnits(const SBFileSpec &sb_file_spec) {
+ SBSymbolContextList sb_sc_list;
+ const ModuleSP module_sp(GetSP());
+ if (sb_file_spec.IsValid() && module_sp) {
+ const bool append = true;
+ module_sp->FindCompileUnits(*sb_file_spec, append, *sb_sc_list);
+ }
+ return sb_sc_list;
+}
+
static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) {
if (module_sp) {
SymbolVendor *symbols = module_sp->GetSymbolVendor();
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 7af3e55dce9..550d336906d 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1544,6 +1544,18 @@ SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
return sb_module;
}
+SBSymbolContextList
+SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
+ SBSymbolContextList sb_sc_list;
+ const TargetSP target_sp(GetSP());
+ if (target_sp && sb_file_spec.IsValid()) {
+ const bool append = true;
+ target_sp->GetImages().FindCompileUnits(*sb_file_spec,
+ append, *sb_sc_list);
+ }
+ return sb_sc_list;
+}
+
lldb::ByteOrder SBTarget::GetByteOrder() {
TargetSP target_sp(GetSP());
if (target_sp)
OpenPOWER on IntegriCloud