Skip to content

Commit 2247de6

Browse files
committed
Add kallsyms querying
1 parent b817b66 commit 2247de6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/BPFnative.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import ..API
8282
include("host/syscall.jl")
8383
include("host/maps.jl")
8484
include("host/socket.jl")
85+
include("host/kallsyms.jl")
8586
end
8687

8788
# Compiler

src/host/kallsyms.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function find_ksym(addr::UInt64)
2+
start, stop = UInt64(0), addr
3+
rgx = r"([0-9abcdef]*) ([a-zA-Z]) ([0-9a-zA-Z_\-]*)"
4+
last_addr = start
5+
last_kind = "?"
6+
last_name = ""
7+
for line in readlines(open("/proc/kallsyms", "r"))
8+
m = match(rgx, line)
9+
@assert m !== nothing
10+
start_addr, kind, name = m.captures
11+
start_addr = parse(UInt64, "0x"*start_addr)
12+
if start_addr > stop
13+
return last_addr, last_kind, last_name
14+
elseif start_addr == stop
15+
return addr, kind, name
16+
end
17+
last_addr = addr
18+
last_kind = kind
19+
last_name = name
20+
end
21+
end
22+
function stack_to_string(nt::NTuple{N,UInt64}) where N
23+
iob = IOBuffer()
24+
for i in 1:N
25+
addr = nt[i]
26+
if addr == UInt64(0)
27+
break
28+
end
29+
println(iob, "$(find_ksym(addr)[3])")
30+
end
31+
String(take!(iob))
32+
end

0 commit comments

Comments
 (0)