Skip to content

Commit cbddc0a

Browse files
committed
Introduce MapSymbol to propagate map type info in map_sym_tab
1 parent 209df33 commit cbddc0a

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
get_int_value_from_arg,
1313
)
1414
from .printk_formatter import simple_string_print, handle_fstring_print
15-
16-
from logging import Logger
1715
import logging
1816

19-
logger: Logger = logging.getLogger(__name__)
17+
logger = logging.getLogger(__name__)
2018

2119

2220
class BPFHelperID(Enum):
@@ -377,6 +375,10 @@ def bpf_perf_event_output_handler(
377375
struct_sym_tab=None,
378376
map_sym_tab=None,
379377
):
378+
"""
379+
Emit LLVM IR for bpf_perf_event_output helper function call.
380+
"""
381+
380382
if len(call.args) != 1:
381383
raise ValueError(
382384
f"Perf event output expects exactly one argument, got {len(call.args)}"
@@ -904,6 +906,6 @@ def invoke_helper(method_name, map_ptr=None):
904906
if not map_sym_tab or map_name not in map_sym_tab:
905907
raise ValueError(f"Map '{map_name}' not found in symbol table")
906908

907-
return invoke_helper(method_name, map_sym_tab[map_name])
909+
return invoke_helper(method_name, map_sym_tab[map_name].sym)
908910

909911
return None

pythonbpf/maps/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .maps import HashMap, PerfEventArray, RingBuffer
22
from .maps_pass import maps_proc
3+
from .map_types import BPFMapType
34

4-
__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer"]
5+
__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer", "BPFMapType"]

pythonbpf/maps/maps_pass.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from logging import Logger
44
from llvmlite import ir
55

6-
from .maps_utils import MapProcessorRegistry
6+
from .maps_utils import MapProcessorRegistry, MapSymbol
77
from .map_types import BPFMapType
88
from .map_debug_info import create_map_debug_info, create_ringbuf_debug_info
99
from pythonbpf.expr.vmlinux_registry import VmlinuxHandlerRegistry
@@ -46,7 +46,7 @@ def create_bpf_map(module, map_name, map_params):
4646
map_global.align = 8
4747

4848
logger.info(f"Created BPF map: {map_name} with params {map_params}")
49-
return map_global
49+
return MapSymbol(type=map_params["type"], sym=map_global)
5050

5151

5252
def _parse_map_params(rval, expected_args=None):
@@ -100,7 +100,7 @@ def process_ringbuf_map(map_name, rval, module):
100100
logger.info(f"Ringbuf map parameters: {map_params}")
101101

102102
map_global = create_bpf_map(module, map_name, map_params)
103-
create_ringbuf_debug_info(module, map_global, map_name, map_params)
103+
create_ringbuf_debug_info(module, map_global.sym, map_name, map_params)
104104
return map_global
105105

106106

@@ -114,7 +114,7 @@ def process_hash_map(map_name, rval, module):
114114
logger.info(f"Map parameters: {map_params}")
115115
map_global = create_bpf_map(module, map_name, map_params)
116116
# Generate debug info for BTF
117-
create_map_debug_info(module, map_global, map_name, map_params)
117+
create_map_debug_info(module, map_global.sym, map_name, map_params)
118118
return map_global
119119

120120

@@ -128,7 +128,7 @@ def process_perf_event_map(map_name, rval, module):
128128
logger.info(f"Map parameters: {map_params}")
129129
map_global = create_bpf_map(module, map_name, map_params)
130130
# Generate debug info for BTF
131-
create_map_debug_info(module, map_global, map_name, map_params)
131+
create_map_debug_info(module, map_global.sym, map_name, map_params)
132132
return map_global
133133

134134

pythonbpf/maps/maps_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
from collections.abc import Callable
2+
from dataclasses import dataclass
3+
from llvmlite import ir
24
from typing import Any
5+
from .map_types import BPFMapType
6+
7+
8+
@dataclass
9+
class MapSymbol:
10+
"""Class representing a symbol on the map"""
11+
12+
type: BPFMapType
13+
sym: ir.GlobalVariable
314

415

516
class MapProcessorRegistry:

0 commit comments

Comments
 (0)