apolyakov updated this revision to Diff 153817.
apolyakov added a comment.

Added documentation and tests.


https://reviews.llvm.org/D48801

Files:
  include/lldb/API/SBModule.h
  include/lldb/API/SBTarget.h
  
packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
  packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
  scripts/interface/SBModule.i
  scripts/interface/SBTarget.i
  source/API/SBModule.cpp
  source/API/SBTarget.cpp

Index: source/API/SBTarget.cpp
===================================================================
--- source/API/SBTarget.cpp
+++ source/API/SBTarget.cpp
@@ -1548,6 +1548,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)
Index: source/API/SBModule.cpp
===================================================================
--- source/API/SBModule.cpp
+++ 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: scripts/interface/SBTarget.i
===================================================================
--- scripts/interface/SBTarget.i
+++ scripts/interface/SBTarget.i
@@ -410,6 +410,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: scripts/interface/SBModule.i
===================================================================
--- scripts/interface/SBModule.i
+++ 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: packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
===================================================================
--- packages/Python/lldbsuite/test/python_api/target/TestTargetAPI.py
+++ 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('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,21 @@
                     value_list.GetValueAtIndex(0).GetValue() == "'X'")
                 break
 
+    def find_compile_units(self, exe_name):
+        """Exercise SBTarget.FindCompileUnits() API."""
+        exe = self.getBuildArtifact(exe_name)
+        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: packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
===================================================================
--- packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
+++ packages/Python/lldbsuite/test/python_api/module_section/TestModuleAndSection.py
@@ -141,3 +141,30 @@
         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('b.out')
+
+    def find_compile_units(self, exe_name):
+        """Exercise SBModule.FindCompileUnits() API."""
+        exe = self.getBuildArtifact(exe_name)
+        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: include/lldb/API/SBTarget.h
===================================================================
--- include/lldb/API/SBTarget.h
+++ include/lldb/API/SBTarget.h
@@ -295,6 +295,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: include/lldb/API/SBModule.h
===================================================================
--- include/lldb/API/SBModule.h
+++ 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);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to