diff --git a/pythonbpf/helper/bpf_helper_handler.py b/pythonbpf/helper/bpf_helper_handler.py index 116d1a0..294985e 100644 --- a/pythonbpf/helper/bpf_helper_handler.py +++ b/pythonbpf/helper/bpf_helper_handler.py @@ -12,11 +12,9 @@ from .helper_utils import ( get_int_value_from_arg, ) from .printk_formatter import simple_string_print, handle_fstring_print - -from logging import Logger import logging -logger: Logger = logging.getLogger(__name__) +logger = logging.getLogger(__name__) class BPFHelperID(Enum): @@ -377,6 +375,10 @@ def bpf_perf_event_output_handler( struct_sym_tab=None, map_sym_tab=None, ): + """ + Emit LLVM IR for bpf_perf_event_output helper function call. + """ + if len(call.args) != 1: raise ValueError( f"Perf event output expects exactly one argument, got {len(call.args)}" @@ -904,6 +906,6 @@ def handle_helper_call( if not map_sym_tab or map_name not in map_sym_tab: raise ValueError(f"Map '{map_name}' not found in symbol table") - return invoke_helper(method_name, map_sym_tab[map_name]) + return invoke_helper(method_name, map_sym_tab[map_name].sym) return None diff --git a/pythonbpf/maps/__init__.py b/pythonbpf/maps/__init__.py index e0b2ada..eb2007d 100644 --- a/pythonbpf/maps/__init__.py +++ b/pythonbpf/maps/__init__.py @@ -1,4 +1,5 @@ from .maps import HashMap, PerfEventArray, RingBuffer from .maps_pass import maps_proc +from .map_types import BPFMapType -__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer"] +__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer", "BPFMapType"] diff --git a/pythonbpf/maps/maps_pass.py b/pythonbpf/maps/maps_pass.py index 42d7a14..87b9c03 100644 --- a/pythonbpf/maps/maps_pass.py +++ b/pythonbpf/maps/maps_pass.py @@ -3,7 +3,7 @@ import logging from logging import Logger from llvmlite import ir -from .maps_utils import MapProcessorRegistry +from .maps_utils import MapProcessorRegistry, MapSymbol from .map_types import BPFMapType from .map_debug_info import create_map_debug_info, create_ringbuf_debug_info from pythonbpf.expr.vmlinux_registry import VmlinuxHandlerRegistry @@ -46,7 +46,7 @@ def create_bpf_map(module, map_name, map_params): map_global.align = 8 logger.info(f"Created BPF map: {map_name} with params {map_params}") - return map_global + return MapSymbol(type=map_params["type"], sym=map_global) def _parse_map_params(rval, expected_args=None): @@ -100,7 +100,7 @@ def process_ringbuf_map(map_name, rval, module): logger.info(f"Ringbuf map parameters: {map_params}") map_global = create_bpf_map(module, map_name, map_params) - create_ringbuf_debug_info(module, map_global, map_name, map_params) + create_ringbuf_debug_info(module, map_global.sym, map_name, map_params) return map_global @@ -114,7 +114,7 @@ def process_hash_map(map_name, rval, module): logger.info(f"Map parameters: {map_params}") map_global = create_bpf_map(module, map_name, map_params) # Generate debug info for BTF - create_map_debug_info(module, map_global, map_name, map_params) + create_map_debug_info(module, map_global.sym, map_name, map_params) return map_global @@ -128,7 +128,7 @@ def process_perf_event_map(map_name, rval, module): logger.info(f"Map parameters: {map_params}") map_global = create_bpf_map(module, map_name, map_params) # Generate debug info for BTF - create_map_debug_info(module, map_global, map_name, map_params) + create_map_debug_info(module, map_global.sym, map_name, map_params) return map_global diff --git a/pythonbpf/maps/maps_utils.py b/pythonbpf/maps/maps_utils.py index ee3ad08..eaa43b2 100644 --- a/pythonbpf/maps/maps_utils.py +++ b/pythonbpf/maps/maps_utils.py @@ -1,5 +1,16 @@ from collections.abc import Callable +from dataclasses import dataclass +from llvmlite import ir from typing import Any +from .map_types import BPFMapType + + +@dataclass +class MapSymbol: + """Class representing a symbol on the map""" + + type: BPFMapType + sym: ir.GlobalVariable class MapProcessorRegistry: