File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1010class data_t :
1111 pid : c_uint64
1212 ts : c_uint64
13+ comm : str (16 )
1314
1415
1516@bpf
Original file line number Diff line number Diff line change @@ -28,14 +28,25 @@ def process_bpf_struct(cls_node, module):
2828
2929 for item in cls_node .body :
3030 if isinstance (item , ast .AnnAssign ) and isinstance (item .target , ast .Name ):
31+ print (f"Field: { item .target .id } , Type: "
32+ f"{ ast .dump (item .annotation )} " )
3133 field_names .append (item .target .id )
32- field_types .append (ctypes_to_ir (item .annotation .id ))
34+ if isinstance (item .annotation , ast .Call ) and isinstance (item .annotation .func , ast .Name ) and item .annotation .func .id == "str" :
35+ # This is a char array with fixed length
36+ # TODO: For now assuming str is always called with constant
37+ field_types .append (ir .ArrayType (
38+ ir .IntType (8 ), item .annotation .args [0 ].value ))
39+ else :
40+ field_types .append (ctypes_to_ir (item .annotation .id ))
3341
3442 curr_offset = 0
3543 for ftype in field_types :
3644 if isinstance (ftype , ir .IntType ):
3745 fsize = ftype .width // 8
3846 alignment = fsize
47+ elif isinstance (ftype , ir .ArrayType ):
48+ fsize = ftype .count * (ftype .element .width // 8 )
49+ alignment = ftype .element .width // 8
3950 elif isinstance (ftype , ir .PointerType ):
4051 fsize = 8
4152 alignment = 8
You can’t perform that action at this time.
0 commit comments