mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Introduce MapSymbol to propagate map type info in map_sym_tab
This commit is contained in:
@ -12,11 +12,9 @@ from .helper_utils import (
|
|||||||
get_int_value_from_arg,
|
get_int_value_from_arg,
|
||||||
)
|
)
|
||||||
from .printk_formatter import simple_string_print, handle_fstring_print
|
from .printk_formatter import simple_string_print, handle_fstring_print
|
||||||
|
|
||||||
from logging import Logger
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BPFHelperID(Enum):
|
class BPFHelperID(Enum):
|
||||||
@ -377,6 +375,10 @@ def bpf_perf_event_output_handler(
|
|||||||
struct_sym_tab=None,
|
struct_sym_tab=None,
|
||||||
map_sym_tab=None,
|
map_sym_tab=None,
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Emit LLVM IR for bpf_perf_event_output helper function call.
|
||||||
|
"""
|
||||||
|
|
||||||
if len(call.args) != 1:
|
if len(call.args) != 1:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Perf event output expects exactly one argument, got {len(call.args)}"
|
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:
|
if not map_sym_tab or map_name not in map_sym_tab:
|
||||||
raise ValueError(f"Map '{map_name}' not found in symbol table")
|
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
|
return None
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from .maps import HashMap, PerfEventArray, RingBuffer
|
from .maps import HashMap, PerfEventArray, RingBuffer
|
||||||
from .maps_pass import maps_proc
|
from .maps_pass import maps_proc
|
||||||
|
from .map_types import BPFMapType
|
||||||
|
|
||||||
__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer"]
|
__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer", "BPFMapType"]
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import logging
|
|||||||
from logging import Logger
|
from logging import Logger
|
||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
|
|
||||||
from .maps_utils import MapProcessorRegistry
|
from .maps_utils import MapProcessorRegistry, MapSymbol
|
||||||
from .map_types import BPFMapType
|
from .map_types import BPFMapType
|
||||||
from .map_debug_info import create_map_debug_info, create_ringbuf_debug_info
|
from .map_debug_info import create_map_debug_info, create_ringbuf_debug_info
|
||||||
from pythonbpf.expr.vmlinux_registry import VmlinuxHandlerRegistry
|
from pythonbpf.expr.vmlinux_registry import VmlinuxHandlerRegistry
|
||||||
@ -46,7 +46,7 @@ def create_bpf_map(module, map_name, map_params):
|
|||||||
map_global.align = 8
|
map_global.align = 8
|
||||||
|
|
||||||
logger.info(f"Created BPF map: {map_name} with params {map_params}")
|
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):
|
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}")
|
logger.info(f"Ringbuf map parameters: {map_params}")
|
||||||
|
|
||||||
map_global = create_bpf_map(module, map_name, 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
|
return map_global
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ def process_hash_map(map_name, rval, module):
|
|||||||
logger.info(f"Map parameters: {map_params}")
|
logger.info(f"Map parameters: {map_params}")
|
||||||
map_global = create_bpf_map(module, map_name, map_params)
|
map_global = create_bpf_map(module, map_name, map_params)
|
||||||
# Generate debug info for BTF
|
# 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
|
return map_global
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ def process_perf_event_map(map_name, rval, module):
|
|||||||
logger.info(f"Map parameters: {map_params}")
|
logger.info(f"Map parameters: {map_params}")
|
||||||
map_global = create_bpf_map(module, map_name, map_params)
|
map_global = create_bpf_map(module, map_name, map_params)
|
||||||
# Generate debug info for BTF
|
# 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
|
return map_global
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,16 @@
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from llvmlite import ir
|
||||||
from typing import Any
|
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:
|
class MapProcessorRegistry:
|
||||||
|
|||||||
Reference in New Issue
Block a user