mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-02-11 15:40:56 +00:00
add globals todo
This commit is contained in:
@ -1,15 +0,0 @@
|
|||||||
# This is what it is going to look like
|
|
||||||
# pylint: disable-all# type: ignore
|
|
||||||
from pythonbpf.decorators import tracepoint, syscalls, bpfglobal, bpf
|
|
||||||
from ctypes import c_void_p, c_int32
|
|
||||||
|
|
||||||
@bpf
|
|
||||||
@tracepoint(syscalls.sys_clone)
|
|
||||||
def trace_clone(ctx: c_void_p) -> c_int32:
|
|
||||||
print("Hello, World!")
|
|
||||||
return c_int32(0)
|
|
||||||
|
|
||||||
@bpf
|
|
||||||
@bpfglobal
|
|
||||||
def LICENSE() -> str:
|
|
||||||
return "GPL"
|
|
||||||
@ -62,7 +62,9 @@ def compile_to_ir(filename: str, output: str):
|
|||||||
"language": DW_LANG_C11,
|
"language": DW_LANG_C11,
|
||||||
"file": module._file_metadata, # type: ignore
|
"file": module._file_metadata, # type: ignore
|
||||||
"producer": f"PythonBPF {version}",
|
"producer": f"PythonBPF {version}",
|
||||||
"isOptimized": True,
|
"isOptimized": True, #TODO: This is probably not true
|
||||||
|
#TODO: add a global field here that keeps track of all the globals. Works without it, but I think it might
|
||||||
|
# be required for kprobes.
|
||||||
"runtimeVersion": 0,
|
"runtimeVersion": 0,
|
||||||
"emissionKind": 1,
|
"emissionKind": 1,
|
||||||
"splitDebugInlining": False,
|
"splitDebugInlining": False,
|
||||||
@ -80,12 +82,12 @@ def compile_to_ir(filename: str, output: str):
|
|||||||
frame_pointer = module.add_metadata([DwarfBehaviorEnum.OVERRIDE_USE_LARGEST,
|
frame_pointer = module.add_metadata([DwarfBehaviorEnum.OVERRIDE_USE_LARGEST,
|
||||||
"frame-pointer",
|
"frame-pointer",
|
||||||
ir.Constant(ir.IntType(32), 2)])
|
ir.Constant(ir.IntType(32), 2)])
|
||||||
# Add Debug Info Version (3 = DWARF v3, which LLVM expects)
|
# Add Debug Info Version 3
|
||||||
debug_info_version = module.add_metadata([DwarfBehaviorEnum.WARNING_IF_MISMATCH,
|
debug_info_version = module.add_metadata([DwarfBehaviorEnum.WARNING_IF_MISMATCH,
|
||||||
"Debug Info Version",
|
"Debug Info Version",
|
||||||
ir.Constant(ir.IntType(32), 3)])
|
ir.Constant(ir.IntType(32), 3)])
|
||||||
|
|
||||||
# Add explicit DWARF version (4 is common, works with LLVM BPF backend)
|
# Add explicit DWARF version 5
|
||||||
dwarf_version = module.add_metadata([DwarfBehaviorEnum.OVERRIDE_USE_LARGEST,
|
dwarf_version = module.add_metadata([DwarfBehaviorEnum.OVERRIDE_USE_LARGEST,
|
||||||
"Dwarf Version",
|
"Dwarf Version",
|
||||||
ir.Constant(ir.IntType(32), 5)])
|
ir.Constant(ir.IntType(32), 5)])
|
||||||
|
|||||||
Reference in New Issue
Block a user