Commit 5f3751bf authored by Brenden Blanco's avatar Brenden Blanco Committed by GitHub

Merge pull request #1055 from goldshtn/syms-encode

python: Allow module=None when resolving kernel symbols
parents f78af269 3a237609
......@@ -71,7 +71,7 @@ class SymbolCache(object):
def resolve_name(self, module, name):
addr = ct.c_ulonglong()
if lib.bcc_symcache_resolve_name(
self.cache, module.encode("ascii"),
self.cache, module.encode("ascii") if module else None,
name.encode("ascii"), ct.pointer(addr)) < 0:
return -1
return addr.value
......@@ -1018,7 +1018,7 @@ class BPF(object):
Translate a kernel memory address into a kernel function name, which is
returned. When show_module is True, the module name ("kernel") is also
included. When show_offset is true, the instruction offset as a
included. When show_offset is true, the instruction offset as a
hexadecimal number is also included in the string.
Example output when both show_module and show_offset are True:
......
......@@ -4,9 +4,28 @@
import os
import subprocess
from bcc import SymbolCache
from bcc import SymbolCache, BPF
from unittest import main, TestCase
class TestKSyms(TestCase):
def grab_sym(self):
# Grab the first symbol in kallsyms that has type 't'.
with open("/proc/kallsyms") as f:
for line in f:
(addr, t, name) = line.strip().split()
if t == "t":
return (addr, name)
def test_ksymname(self):
sym = BPF.ksymname("__kmalloc")
self.assertIsNotNone(sym)
self.assertNotEqual(sym, 0)
def test_ksym(self):
(addr, name) = self.grab_sym()
sym = BPF.ksym(int(addr, 16))
self.assertEqual(sym, name)
class Harness(TestCase):
def setUp(self):
self.build_command()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment