Skip to content

Commit

Permalink
Merge pull request iovisor#1055 from goldshtn/syms-encode
Browse files Browse the repository at this point in the history
python: Allow module=None when resolving kernel symbols
  • Loading branch information
drzaeus77 committed Mar 21, 2017
2 parents f78af26 + 3a23760 commit 5f3751b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def resolve(self, addr):
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
Expand Down Expand Up @@ -1018,7 +1018,7 @@ def ksym(addr, show_module=False, show_offset=False):
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:
Expand Down
21 changes: 20 additions & 1 deletion tests/python/test_debuginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5f3751b

Please sign in to comment.