Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
84664dc3
Commit
84664dc3
authored
Apr 26, 2018
by
4ast
Committed by
GitHub
Apr 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1708 from iovisor/yhs_dev
using get_syscall_fnname to get kprobe func name for tools
parents
18a2f2f8
64335694
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
24 deletions
+42
-24
tests/python/test_tools_smoke.py
tests/python/test_tools_smoke.py
+2
-2
tools/deadlock_detector.py
tools/deadlock_detector.py
+2
-2
tools/execsnoop.py
tools/execsnoop.py
+5
-2
tools/killsnoop.py
tools/killsnoop.py
+6
-2
tools/mountsnoop.py
tools/mountsnoop.py
+10
-4
tools/statsnoop.py
tools/statsnoop.py
+14
-11
tools/syncsnoop.py
tools/syncsnoop.py
+3
-1
No files found.
tests/python/test_tools_smoke.py
View file @
84664dc3
...
...
@@ -66,7 +66,7 @@ class SmokeTests(TestCase):
pass
def test_argdist(self):
self.run_with_duration("
argdist
.
py
-
C
'p::
SyS
_open()'
-
n
1
-
i
1
")
self.run_with_duration("
argdist
.
py
-
C
'p::
do_sys
_open()'
-
n
1
-
i
1
")
@skipUnless(kernel_version_ge(4,4), "
requires
kernel
>=
4.4
")
def test_bashreadline(self):
...
...
@@ -322,7 +322,7 @@ class SmokeTests(TestCase):
@skipUnless(kernel_version_ge(4,4), "
requires
kernel
>=
4.4
")
def test_trace(self):
self.run_with_int("
trace
.
py
SyS
_open
")
self.run_with_int("
trace
.
py
do_sys
_open
")
@skipUnless(kernel_version_ge(4,4), "
requires
kernel
>=
4.4
")
def test_ttysnoop(self):
...
...
tools/deadlock_detector.py
View file @
84664dc3
...
...
@@ -465,10 +465,10 @@ def main():
print
(
'%s. Is the process (pid=%d) running?'
%
(
str
(
e
),
args
.
pid
))
sys
.
exit
(
1
)
bpf
=
BPF
(
src_file
=
'deadlock_detector.c'
)
bpf
=
BPF
(
src_file
=
b
'deadlock_detector.c'
)
# Trace where threads are created
bpf
.
attach_kretprobe
(
event
=
'sys_clone'
,
fn_name
=
'trace_clone'
)
bpf
.
attach_kretprobe
(
event
=
bpf
.
get_syscall_fnname
(
'clone'
)
,
fn_name
=
'trace_clone'
)
# We must trace unlock first, otherwise in the time we attached the probe
# on lock() and have not yet attached the probe on unlock(), a thread can
...
...
tools/execsnoop.py
View file @
84664dc3
...
...
@@ -98,7 +98,7 @@ static int submit_arg(struct pt_regs *ctx, void *ptr, struct data_t *data)
return 0;
}
int
kprobe_
_sys_execve(struct pt_regs *ctx,
int
do
_sys_execve(struct pt_regs *ctx,
const char __user *filename,
const char __user *const __user *__argv,
const char __user *const __user *__envp)
...
...
@@ -125,7 +125,7 @@ out:
return 0;
}
int
kretprobe_
_sys_execve(struct pt_regs *ctx)
int
do_ret
_sys_execve(struct pt_regs *ctx)
{
struct data_t data = {};
data.pid = bpf_get_current_pid_tgid() >> 32;
...
...
@@ -145,6 +145,9 @@ if args.ebpf:
# initialize BPF
b
=
BPF
(
text
=
bpf_text
)
execve_fnname
=
b
.
get_syscall_fnname
(
"execve"
)
b
.
attach_kprobe
(
event
=
execve_fnname
,
fn_name
=
"do_sys_execve"
)
b
.
attach_kretprobe
(
event
=
execve_fnname
,
fn_name
=
"do_ret_sys_execve"
)
# header
if
args
.
timestamp
:
...
...
tools/killsnoop.py
View file @
84664dc3
...
...
@@ -60,7 +60,7 @@ struct data_t {
BPF_HASH(infotmp, u32, struct val_t);
BPF_PERF_OUTPUT(events);
int
kprobe_
_sys_kill(struct pt_regs *ctx, int tpid, int sig)
int
do
_sys_kill(struct pt_regs *ctx, int tpid, int sig)
{
u32 pid = bpf_get_current_pid_tgid();
FILTER
...
...
@@ -75,7 +75,7 @@ int kprobe__sys_kill(struct pt_regs *ctx, int tpid, int sig)
return 0;
};
int
kretprobe_
_sys_kill(struct pt_regs *ctx)
int
do_ret
_sys_kill(struct pt_regs *ctx)
{
struct data_t data = {};
struct val_t *valp;
...
...
@@ -111,6 +111,10 @@ if debug or args.ebpf:
# initialize BPF
b
=
BPF
(
text
=
bpf_text
)
kill_fnname
=
b
.
get_syscall_fnname
(
"kill"
)
b
.
attach_kprobe
(
event
=
kill_fnname
,
fn_name
=
"do_sys_kill"
)
b
.
attach_kretprobe
(
event
=
kill_fnname
,
fn_name
=
"do_ret_sys_kill"
)
TASK_COMM_LEN
=
16
# linux/sched.h
...
...
tools/mountsnoop.py
View file @
84664dc3
...
...
@@ -86,7 +86,7 @@ struct data_t {
BPF_PERF_OUTPUT(events);
int
kprobe_
_sys_mount(struct pt_regs *ctx, char __user *source,
int
do
_sys_mount(struct pt_regs *ctx, char __user *source,
char __user *target, char __user *type,
unsigned long flags)
{
...
...
@@ -132,7 +132,7 @@ int kprobe__sys_mount(struct pt_regs *ctx, char __user *source,
return 0;
}
int
kretprobe_
_sys_mount(struct pt_regs *ctx)
int
do_ret
_sys_mount(struct pt_regs *ctx)
{
struct data_t event = {};
...
...
@@ -145,7 +145,7 @@ int kretprobe__sys_mount(struct pt_regs *ctx)
return 0;
}
int
kprobe_
_sys_umount(struct pt_regs *ctx, char __user *target, int flags)
int
do
_sys_umount(struct pt_regs *ctx, char __user *target, int flags)
{
struct data_t event = {};
struct task_struct *task;
...
...
@@ -172,7 +172,7 @@ int kprobe__sys_umount(struct pt_regs *ctx, char __user *target, int flags)
return 0;
}
int
kretprobe_
_sys_umount(struct pt_regs *ctx)
int
do_ret
_sys_umount(struct pt_regs *ctx)
{
struct data_t event = {};
...
...
@@ -403,6 +403,12 @@ def main():
print
(
bpf_text
)
exit
()
b
=
bcc
.
BPF
(
text
=
bpf_text
)
mount_fnname
=
b
.
get_syscall_fnname
(
"mount"
)
b
.
attach_kprobe
(
event
=
mount_fnname
,
fn_name
=
"do_sys_mount"
)
b
.
attach_kretprobe
(
event
=
mount_fnname
,
fn_name
=
"do_ret_sys_mount"
)
umount_fnname
=
b
.
get_syscall_fnname
(
"umount"
)
b
.
attach_kprobe
(
event
=
umount_fnname
,
fn_name
=
"do_sys_umount"
)
b
.
attach_kretprobe
(
event
=
umount_fnname
,
fn_name
=
"do_ret_sys_umount"
)
b
[
'events'
].
open_perf_buffer
(
functools
.
partial
(
print_event
,
mounts
,
umounts
))
print
(
'{:16} {:<7} {:<7} {:<11} {}'
.
format
(
...
...
tools/statsnoop.py
View file @
84664dc3
...
...
@@ -114,17 +114,20 @@ b = BPF(text=bpf_text)
# system calls but the name of the actual entry point may
# be different for which we must check if the entry points
# actually exist before attaching the probes
if
BPF
.
ksymname
(
"sys_stat"
)
!=
-
1
:
b
.
attach_kprobe
(
event
=
"sys_stat"
,
fn_name
=
"trace_entry"
)
b
.
attach_kretprobe
(
event
=
"sys_stat"
,
fn_name
=
"trace_return"
)
if
BPF
.
ksymname
(
"sys_statfs"
)
!=
-
1
:
b
.
attach_kprobe
(
event
=
"sys_statfs"
,
fn_name
=
"trace_entry"
)
b
.
attach_kretprobe
(
event
=
"sys_statfs"
,
fn_name
=
"trace_return"
)
if
BPF
.
ksymname
(
"sys_newstat"
)
!=
-
1
:
b
.
attach_kprobe
(
event
=
"sys_newstat"
,
fn_name
=
"trace_entry"
)
b
.
attach_kretprobe
(
event
=
"sys_newstat"
,
fn_name
=
"trace_return"
)
syscall_fnname
=
b
.
get_syscall_fnname
(
"stat"
)
if
BPF
.
ksymname
(
syscall_fnname
)
!=
-
1
:
b
.
attach_kprobe
(
event
=
syscall_fnname
,
fn_name
=
"trace_entry"
)
b
.
attach_kretprobe
(
event
=
syscall_fnname
,
fn_name
=
"trace_return"
)
syscall_fnname
=
b
.
get_syscall_fnname
(
"statfs"
)
if
BPF
.
ksymname
(
syscall_fnname
)
!=
-
1
:
b
.
attach_kprobe
(
event
=
syscall_fnname
,
fn_name
=
"trace_entry"
)
b
.
attach_kretprobe
(
event
=
syscall_fnname
,
fn_name
=
"trace_return"
)
syscall_fnname
=
b
.
get_syscall_fnname
(
"newstat"
)
if
BPF
.
ksymname
(
syscall_fnname
)
!=
-
1
:
b
.
attach_kprobe
(
event
=
syscall_fnname
,
fn_name
=
"trace_entry"
)
b
.
attach_kretprobe
(
event
=
syscall_fnname
,
fn_name
=
"trace_return"
)
TASK_COMM_LEN
=
16
# linux/sched.h
NAME_MAX
=
255
# linux/limits.h
...
...
tools/syncsnoop.py
View file @
84664dc3
...
...
@@ -25,12 +25,14 @@ struct data_t {
BPF_PERF_OUTPUT(events);
void
kprobe_
_sys_sync(void *ctx) {
void
do
_sys_sync(void *ctx) {
struct data_t data = {};
data.ts = bpf_ktime_get_ns() / 1000;
events.perf_submit(ctx, &data, sizeof(data));
};
"""
)
b
.
attach_kprobe
(
event
=
b
.
get_syscall_fnname
(
"sync"
),
fn_name
=
"do_sys_sync"
)
class
Data
(
ct
.
Structure
):
_fields_
=
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment