[Lldb-commits] [lldb] 2c0cbc4 - GetModule, GetExeModule methods added

2020-10-29 Thread Ilya Bukonkin via lldb-commits

Author: Ilya Bukonkin
Date: 2020-10-29T23:44:51+03:00
New Revision: 2c0cbc47cae4e69195a883771664ef3d5a54c7d2

URL: 
https://github.com/llvm/llvm-project/commit/2c0cbc47cae4e69195a883771664ef3d5a54c7d2
DIFF: 
https://github.com/llvm/llvm-project/commit/2c0cbc47cae4e69195a883771664ef3d5a54c7d2.diff

LOG: GetModule, GetExeModule methods added

Added: 
lldb/test/API/functionalities/type_get_module/Makefile
lldb/test/API/functionalities/type_get_module/TestTypeGetModule.py
lldb/test/API/functionalities/type_get_module/compile_unit1.c
lldb/test/API/functionalities/type_get_module/compile_unit2.c
lldb/test/API/functionalities/type_get_module/main.c

Modified: 
lldb/bindings/interface/SBType.i
lldb/include/lldb/API/SBModule.h
lldb/include/lldb/API/SBType.h
lldb/include/lldb/Symbol/Type.h
lldb/source/API/SBType.cpp
lldb/source/Symbol/Type.cpp

Removed: 




diff  --git a/lldb/bindings/interface/SBType.i 
b/lldb/bindings/interface/SBType.i
index 3cd82452084b..fd2dda188454 100644
--- a/lldb/bindings/interface/SBType.i
+++ b/lldb/bindings/interface/SBType.i
@@ -277,6 +277,9 @@ public:
 lldb::SBTypeEnumMemberList
 GetEnumMembers();
 
+lldb::SBModule
+GetModule();
+
 const char*
 GetName();
 
@@ -330,6 +333,7 @@ public:
 return template_args
 return None
 
+module = property(GetModule, None, doc='''A read only property that 
returns the module in which type is defined.''') 
 name = property(GetName, None, doc='''A read only property that 
returns the name for this type as a string.''')
 size = property(GetByteSize, None, doc='''A read only property that 
returns size in bytes for this type as an integer.''')
 is_pointer = property(IsPointerType, None, doc='''A read only property 
that returns a boolean value that indicates if this type is a pointer type.''')

diff  --git a/lldb/include/lldb/API/SBModule.h 
b/lldb/include/lldb/API/SBModule.h
index ec6e7c21b058..dd783fe4107d 100644
--- a/lldb/include/lldb/API/SBModule.h
+++ b/lldb/include/lldb/API/SBModule.h
@@ -300,6 +300,7 @@ class LLDB_API SBModule {
   friend class SBSection;
   friend class SBSymbolContext;
   friend class SBTarget;
+  friend class SBType;
 
   explicit SBModule(const lldb::ModuleSP &module_sp);
 

diff  --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h
index b0af43351192..5f487aa5d258 100644
--- a/lldb/include/lldb/API/SBType.h
+++ b/lldb/include/lldb/API/SBType.h
@@ -185,6 +185,8 @@ class SBType {
 
   lldb::SBTypeMemberFunction GetMemberFunctionAtIndex(uint32_t idx);
 
+  lldb::SBModule GetModule();
+
   const char *GetName();
 
   const char *GetDisplayTypeName();

diff  --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index 06fc1d5da0aa..dd917cfb7ca8 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -109,12 +109,18 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 
   void DumpTypeName(Stream *s);
 
-  // Since Type instances only keep a "SymbolFile *" internally, other classes
-  // like TypeImpl need make sure the module is still around before playing
-  // with
-  // Type instances. They can store a weak pointer to the Module;
+  /// Since Type instances only keep a "SymbolFile *" internally, other classes
+  /// like TypeImpl need make sure the module is still around before playing
+  /// with
+  /// Type instances. They can store a weak pointer to the Module;
   lldb::ModuleSP GetModule();
 
+  /// GetModule may return module for compile unit's object file.
+  /// GetExeModule returns module for executable object file that contains
+  /// compile unit where type was actualy defined.
+  /// GetModule and GetExeModule may return the same value.
+  lldb::ModuleSP GetExeModule();
+
   void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name,
   ExecutionContextScope *exe_scope);
 
@@ -261,6 +267,8 @@ class TypeImpl {
 
   void Clear();
 
+  lldb::ModuleSP GetModule() const;
+
   ConstString GetName() const;
 
   ConstString GetDisplayTypeName() const;
@@ -288,8 +296,12 @@ class TypeImpl {
 
 private:
   bool CheckModule(lldb::ModuleSP &module_sp) const;
+  bool CheckExeModule(lldb::ModuleSP &module_sp) const;
+  bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp,
+ lldb::ModuleSP &module_sp) const;
 
   lldb::ModuleWP m_module_wp;
+  lldb::ModuleWP m_exe_module_wp;
   CompilerType m_static_type;
   CompilerType m_dynamic_type;
 };

diff  --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp
index 1c1d4e3a3ed9..772ac87145bb 100644
--- a/lldb/source/API/SBType.cpp
+++ b/lldb/source/API/SBType.cpp
@@ -9,6 +9,7 @@
 #include "lldb/API/SBType.h"
 #include "SBReproducerPrivate.h"
 #include "lldb/API/SBDefines.h"
+#include "lldb/API/SBModule.h"
 #include "lldb

[Lldb-commits] [lldb] 1267bb2 - [lldb] TestTypeGetModule.py review improvements

2020-11-01 Thread Ilya Bukonkin via lldb-commits

Author: Ilya Bukonkin
Date: 2020-11-01T13:55:57+03:00
New Revision: 1267bb2e416e42f9c3bbfa7b6cbf4975fa7aa546

URL: 
https://github.com/llvm/llvm-project/commit/1267bb2e416e42f9c3bbfa7b6cbf4975fa7aa546
DIFF: 
https://github.com/llvm/llvm-project/commit/1267bb2e416e42f9c3bbfa7b6cbf4975fa7aa546.diff

LOG: [lldb] TestTypeGetModule.py review improvements

Added: 


Modified: 
lldb/test/API/functionalities/type_get_module/TestTypeGetModule.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/type_get_module/TestTypeGetModule.py 
b/lldb/test/API/functionalities/type_get_module/TestTypeGetModule.py
index 14edc0a14675..5a166e3b38aa 100644
--- a/lldb/test/API/functionalities/type_get_module/TestTypeGetModule.py
+++ b/lldb/test/API/functionalities/type_get_module/TestTypeGetModule.py
@@ -26,6 +26,7 @@ def find_module(self, target, name):
 
 index += 1
 
+self.assertTrue(result.IsValid())
 return result
 
 def find_comp_unit(self, exe_module, name):
@@ -41,6 +42,7 @@ def find_comp_unit(self, exe_module, name):
 
 index += 1
 
+self.assertTrue(result.IsValid())
 return result
 
 def find_type(self, type_list, name):
@@ -56,39 +58,21 @@ def find_type(self, type_list, name):
 
 index += 1
 
+self.assertTrue(result.IsValid())
 return result
 
 def test(self):
 self.build()
 target  = lldbutil.run_to_breakpoint_make_target(self)
 exe_module = self.find_module(target, 'a.out')
-self.assertTrue(exe_module.IsValid())
-
-type1_name = 'compile_unit1_type'
-type2_name = 'compile_unit2_type'
 
 num_comp_units = exe_module.GetNumCompileUnits()
 self.assertEqual(num_comp_units, 3)
 
 comp_unit = self.find_comp_unit(exe_module, 'compile_unit1.c')
-self.assertTrue(comp_unit.IsValid())
-
-cu_type = self.find_type(comp_unit.GetTypes(), type1_name)
-self.assertTrue(cu_type.IsValid())
-self.assertEqual(cu_type.GetName(), type1_name)
-
+cu_type = self.find_type(comp_unit.GetTypes(), 'compile_unit1_type')
+self.assertTrue(exe_module == cu_type.GetModule())
+
 comp_unit = self.find_comp_unit(exe_module, 'compile_unit2.c')
-self.assertTrue(comp_unit.IsValid())
-
-cu_type = self.find_type(comp_unit.GetTypes(), type2_name)
-self.assertTrue(cu_type.IsValid())
-self.assertEqual(cu_type.GetName(), type2_name)
-
-type1 = target.FindFirstType(type1_name)
-self.assertTrue(type1.IsValid())
-
-type2 = target.FindFirstType(type2_name)
-self.assertTrue(type2.IsValid())
-
-self.assertTrue(exe_module == type1.GetModule() and
-exe_module == type2.GetModule())
+cu_type = self.find_type(comp_unit.GetTypes(), 'compile_unit2_type')
+self.assertTrue(exe_module == cu_type.GetModule())



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits