Index: lldb/trunk/include/lldb/API/SBModule.h =================================================================== --- lldb/trunk/include/lldb/API/SBModule.h +++ lldb/trunk/include/lldb/API/SBModule.h @@ -129,6 +129,21 @@ 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); Index: lldb/trunk/include/lldb/API/SBTarget.h =================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h +++ lldb/trunk/include/lldb/API/SBTarget.h @@ -292,6 +292,21 @@ 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(); Index: lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py +++ lldb/trunk/packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py @@ -141,3 +141,29 @@ 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) Index: lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py +++ lldb/trunk/packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py @@ -46,6 +46,14 @@ 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 @@ 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) Index: lldb/trunk/scripts/interface/SBModule.i =================================================================== --- lldb/trunk/scripts/interface/SBModule.i +++ lldb/trunk/scripts/interface/SBModule.i @@ -179,6 +179,23 @@ 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 (); Index: lldb/trunk/scripts/interface/SBTarget.i =================================================================== --- lldb/trunk/scripts/interface/SBTarget.i +++ lldb/trunk/scripts/interface/SBTarget.i @@ -405,6 +405,23 @@ 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 (); Index: lldb/trunk/source/API/SBModule.cpp =================================================================== --- lldb/trunk/source/API/SBModule.cpp +++ lldb/trunk/source/API/SBModule.cpp @@ -253,6 +253,17 @@ 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(); Index: lldb/trunk/source/API/SBTarget.cpp =================================================================== --- lldb/trunk/source/API/SBTarget.cpp +++ lldb/trunk/source/API/SBTarget.cpp @@ -1544,6 +1544,18 @@ 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)