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
b762569e
Commit
b762569e
authored
Jun 14, 2016
by
4ast
Committed by
GitHub
Jun 14, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #571 from iovisor/fix_568
Check for NULL result from bpf_attach_kprobe
parents
cfac8da4
9964bf2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+7
-7
tests/python/test_probe_count.py
tests/python/test_probe_count.py
+8
-0
No files found.
src/python/bcc/__init__.py
View file @
b762569e
...
...
@@ -171,7 +171,7 @@ class BPF(object):
self
.
module
=
lib
.
bpf_module_create_c
(
src_file
.
encode
(
"ascii"
),
self
.
debug
,
cflags_array
,
len
(
cflags_array
))
if
self
.
module
==
Non
e
:
if
not
self
.
modul
e
:
raise
Exception
(
"Failed to compile BPF module %s"
%
src_file
)
# If any "kprobe__" prefixed functions were defined, they will be
...
...
@@ -195,7 +195,7 @@ class BPF(object):
if
func_name
in
self
.
funcs
:
return
self
.
funcs
[
func_name
]
if
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
))
==
None
:
if
not
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
))
:
raise
Exception
(
"Unknown program %s"
%
func_name
)
log_buf
=
ct
.
create_string_buffer
(
65536
)
if
self
.
debug
else
None
...
...
@@ -227,7 +227,7 @@ class BPF(object):
"""
Return the eBPF bytecodes for the specified function as a string
"""
if
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
))
==
None
:
if
not
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
))
:
raise
Exception
(
"Unknown program %s"
%
func_name
)
start
,
=
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
)),
...
...
@@ -373,7 +373,7 @@ class BPF(object):
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
res
==
None
:
if
not
res
:
raise
Exception
(
"Failed to attach BPF to kprobe"
)
open_kprobes
[
ev_name
]
=
res
return
self
...
...
@@ -421,7 +421,7 @@ class BPF(object):
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
res
==
None
:
if
not
res
:
raise
Exception
(
"Failed to attach BPF to kprobe"
)
open_kprobes
[
ev_name
]
=
res
return
self
...
...
@@ -481,7 +481,7 @@ class BPF(object):
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
res
==
None
:
if
not
res
:
raise
Exception
(
"Failed to attach BPF to uprobe"
)
open_uprobes
[
ev_name
]
=
res
return
self
...
...
@@ -525,7 +525,7 @@ class BPF(object):
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
res
==
None
:
if
not
res
:
raise
Exception
(
"Failed to attach BPF to uprobe"
)
open_uprobes
[
ev_name
]
=
res
return
self
...
...
tests/python/test_probe_count.py
View file @
b762569e
...
...
@@ -34,6 +34,14 @@ class TestProbeQuota(TestCase):
with
self
.
assertRaises
(
Exception
):
self
.
b
.
attach_kprobe
(
event_re
=
".*"
,
fn_name
=
"count"
)
class
TestProbeNotExist
(
TestCase
):
def
setUp
(
self
):
self
.
b
=
BPF
(
text
=
"""int count(void *ctx) { return 0; }"""
)
def
test_not_exist
(
self
):
with
self
.
assertRaises
(
Exception
):
b
.
attach_kprobe
(
event
=
"___doesnotexist"
,
fn_name
=
"count"
)
if
__name__
==
"__main__"
:
main
()
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