Skip to content

Commit

Permalink
Fixup objdump calling syntax and add docstrings
Browse files Browse the repository at this point in the history
Use the full path invocation of objdump in both places.

Add a docstring for the variants of attach_retprobe.

Signed-off-by: Brenden Blanco <[email protected]>
  • Loading branch information
Brenden Blanco committed Jan 29, 2016
1 parent 7468195 commit c0c6da7
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,9 @@ def find_load_address(cls, path):
return cls._lib_load_address_cache[path]

# "LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x..."
with os.popen("""/usr/bin/objdump -x %s | awk '$1 == "LOAD" && $3 ~ /^[0x]*$/ { print $5 }'""" % path) as f:
with os.popen("""/usr/bin/objdump -x %s | \
awk '$1 == "LOAD" && $3 ~ /^[0x]*$/ \
{ print $5 }'""" % path) as f:
data = f.read().rstrip()
if not data:
return None
Expand All @@ -741,7 +743,9 @@ def find_symbol(cls, path, sym):
if sym in symbols:
return symbols[sym]

with os.popen("""objdump -tT %s | awk -v sym=%s '$NF == sym && $4 == ".text" { print $1; exit }'""" % (path, sym)) as f:
with os.popen("""/usr/bin/objdump -tT %s | \
awk -v sym=%s '$NF == sym && $4 == ".text" \
{ print $1; exit }'""" % (path, sym)) as f:
data = f.read().rstrip()
if not data:
return None
Expand Down Expand Up @@ -769,6 +773,21 @@ def _check_path_symbol(cls, name, sym, addr):

def attach_uprobe(self, name="", sym="", addr=None,
fn_name="", pid=-1, cpu=0, group_fd=-1):
"""attach_uprobe(name="", sym="", addr=None, fn_name=""
pid=-1, cpu=0, group_fd=-1)
Run the bpf function denoted by fn_name every time the symbol sym in
the library or binary 'name' is encountered. The real address addr may
be supplied in place of sym. Optional parameters pid, cpu, and group_fd
can be used to filter the probe.
Libraries can be given in the name argument without the lib prefix, or
with the full path (/usr/lib/...). Binaries can be given only with the
full path (/bin/sh).
Example: BPF(text).attach_uprobe("c", "malloc")
BPF(text).attach_uprobe("/usr/bin/python", "main")
"""

(path, addr) = BPF._check_path_symbol(name, sym, addr)

Expand All @@ -786,6 +805,12 @@ def attach_uprobe(self, name="", sym="", addr=None,

@classmethod
def detach_uprobe(cls, name="", sym="", addr=None):
"""detach_uprobe(name="", sym="", addr=None)
Stop running a bpf function that is attached to symbol 'sym' in library
or binary 'name'.
"""

(path, addr) = BPF._check_path_symbol(name, sym, addr)
ev_name = "p_%s_0x%x" % (cls._probe_repl.sub("_", path), addr)
if ev_name not in open_uprobes:
Expand All @@ -799,6 +824,13 @@ def detach_uprobe(cls, name="", sym="", addr=None):

def attach_uretprobe(self, name="", sym="", addr=None,
fn_name="", pid=-1, cpu=0, group_fd=-1):
"""attach_uretprobe(name="", sym="", addr=None, fn_name=""
pid=-1, cpu=0, group_fd=-1)
Run the bpf function denoted by fn_name every time the symbol sym in
the library or binary 'name' finishes execution. See attach_uprobe for
meaning of additional parameters.
"""

(path, addr) = BPF._check_path_symbol(name, sym, addr)

Expand All @@ -816,6 +848,12 @@ def attach_uretprobe(self, name="", sym="", addr=None,

@classmethod
def detach_uretprobe(cls, name="", sym="", addr=None):
"""detach_uretprobe(name="", sym="", addr=None)
Stop running a bpf function that is attached to symbol 'sym' in library
or binary 'name'.
"""

(path, addr) = BPF._check_path_symbol(name, sym, addr)
ev_name = "r_%s_0x%x" % (cls._probe_repl.sub("_", path), addr)
if ev_name not in open_uprobes:
Expand Down

0 comments on commit c0c6da7

Please sign in to comment.