[Lldb-commits] [lldb] r336200 - Add new API to SBTarget and SBModule classes.
Alexander Polyakov via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 3 07:22:45 PDT 2018
Author: apolyakov
Date: Tue Jul 3 07:22:44 2018
New Revision: 336200
URL: http://llvm.org/viewvc/llvm-project?rev=336200&view=rev
Log:
Add new API to SBTarget and SBModule classes.
Summary: The new API allows to find a list of compile units related to target/module.
Reviewers: aprantl, clayborg
Reviewed By: aprantl
Subscribers: jingham, lldb-commits
Differential Revision: https://reviews.llvm.org/D48801
Modified:
lldb/trunk/include/lldb/API/SBModule.h
lldb/trunk/include/lldb/API/SBTarget.h
lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
lldb/trunk/scripts/interface/SBModule.i
lldb/trunk/scripts/interface/SBTarget.i
lldb/trunk/source/API/SBModule.cpp
lldb/trunk/source/API/SBTarget.cpp
Modified: lldb/trunk/include/lldb/API/SBModule.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBModule.h?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBModule.h (original)
+++ lldb/trunk/include/lldb/API/SBModule.h Tue Jul 3 07:22:44 2018
@@ -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);
Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Tue Jul 3 07:22:44 2018
@@ -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();
Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py Tue Jul 3 07:22:44 2018
@@ -141,3 +141,29 @@ class ModuleAndSectionAPIsTestCase(TestB
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)
Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py Tue Jul 3 07:22:44 2018
@@ -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)
Modified: lldb/trunk/scripts/interface/SBModule.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBModule.i?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBModule.i (original)
+++ lldb/trunk/scripts/interface/SBModule.i Tue Jul 3 07:22:44 2018
@@ -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 ();
Modified: lldb/trunk/scripts/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBTarget.i?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/interface/SBTarget.i Tue Jul 3 07:22:44 2018
@@ -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 ();
Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Tue Jul 3 07:22:44 2018
@@ -253,6 +253,17 @@ SBCompileUnit SBModule::GetCompileUnitAt
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();
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=336200&r1=336199&r2=336200&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Jul 3 07:22:44 2018
@@ -1544,6 +1544,18 @@ SBModule SBTarget::FindModule(const SBFi
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)
More information about the lldb-commits
mailing list