@@ -61,6 +61,7 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
6161 return True
6262 else :
6363 new_dep_node = DependencyNode (name = current_symbol_name )
64+ handler .add_node (new_dep_node )
6465 for elem_name , elem_type in field_table .items ():
6566 module_name = getattr (elem_type , "__module__" , None )
6667 if module_name == ctypes .__name__ :
@@ -69,36 +70,48 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
6970 new_dep_node .add_field (elem_name , elem_type , ready = False )
7071 print ("elem_name:" , elem_name , "elem_type:" , elem_type )
7172 # currently fails when a non-normal type appears which is basically everytime
72- identify_ctypes_type (elem_type )
73+ identify_ctypes_type (elem_name , elem_type , new_dep_node )
7374 symbol_name = (
7475 elem_type .__name__
7576 if hasattr (elem_type , "__name__" )
7677 else str (elem_type )
7778 )
78- vmlinux_symbol = getattr (imported_module , symbol_name )
79+ vmlinux_symbol = None
80+ if hasattr (elem_type , "_type_" ):
81+ containing_module_name = getattr (
82+ (elem_type ._type_ ), "__module__" , None
83+ )
84+ if containing_module_name == ctypes .__name__ :
85+ new_dep_node .set_field_ready (elem_name , True )
86+ continue
87+ elif containing_module_name == "vmlinux" :
88+ symbol_name = (
89+ (elem_type ._type_ ).__name__
90+ if hasattr ((elem_type ._type_ ), "__name__" )
91+ else str (elem_type ._type_ )
92+ )
93+ vmlinux_symbol = getattr (imported_module , symbol_name )
94+ else :
95+ vmlinux_symbol = getattr (imported_module , symbol_name )
7996 if process_vmlinux_class (vmlinux_symbol , llvm_module , handler ):
8097 new_dep_node .set_field_ready (elem_name , True )
8198 else :
8299 raise ValueError (
83100 f"{ elem_name } with type { elem_type } not supported in recursive resolver"
84101 )
85- handler .add_node (new_dep_node )
86102 logger .info (f"added node: { current_symbol_name } " )
87103
88104 return True
89105
90106
91- def identify_ctypes_type (t ):
92- if isinstance (t , type ): # t is a type/class
93- if issubclass (t , ctypes .Array ):
94- print ("Array type" )
95- print ("Element type:" , t ._type_ )
96- print ("Length:" , t ._length_ )
97- elif issubclass (t , ctypes ._Pointer ):
98- print ("Pointer type" )
99- print ("Points to:" , t ._type_ )
100- elif issubclass (t , ctypes ._SimpleCData ):
101- print ("Scalar type" )
102- print ("Base type:" , t )
107+ def identify_ctypes_type (elem_name , elem_type , new_dep_node : DependencyNode ):
108+ if isinstance (elem_type , type ):
109+ if issubclass (elem_type , ctypes .Array ):
110+ new_dep_node .set_field_type (elem_name , ctypes .Array )
111+ new_dep_node .set_field_containing_type (elem_name , elem_type ._type_ )
112+ new_dep_node .set_field_type_size (elem_name , elem_type ._length_ )
113+ elif issubclass (elem_type , ctypes ._Pointer ):
114+ new_dep_node .set_field_type (elem_name , ctypes ._Pointer )
115+ new_dep_node .set_field_containing_type (elem_name , elem_type ._type_ )
103116 else :
104117 raise TypeError ("Instance sent instead of Class" )
0 commit comments