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
4afb3f87
Commit
4afb3f87
authored
Sep 15, 2015
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #210 from rlane/ebpf-method
add ebpf method to retrieve bytecode
parents
3daeee7d
1ec985d0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
0 deletions
+48
-0
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+11
-0
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/python/CMakeLists.txt
tests/python/CMakeLists.txt
+5
-0
tests/python/test_dump_func.py
tests/python/test_dump_func.py
+24
-0
tests/wrapper.sh.in
tests/wrapper.sh.in
+7
-0
No files found.
src/python/bcc/__init__.py
View file @
4afb3f87
...
...
@@ -392,6 +392,17 @@ class BPF(object):
return
fn
def
dump_func
(
self
,
func_name
):
"""
Return the eBPF bytecodes for the specified function as a string
"""
if
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
))
==
None
:
raise
Exception
(
"Unknown program %s"
%
func_name
)
start
,
=
lib
.
bpf_function_start
(
self
.
module
,
func_name
.
encode
(
"ascii"
)),
size
,
=
lib
.
bpf_function_size
(
self
.
module
,
func_name
.
encode
(
"ascii"
)),
return
ct
.
string_at
(
start
,
size
)
str2ctype
=
{
u"_Bool"
:
ct
.
c_bool
,
u"char"
:
ct
.
c_char
,
...
...
tests/CMakeLists.txt
View file @
4afb3f87
...
...
@@ -5,3 +5,4 @@ configure_file(wrapper.sh.in "${CMAKE_CURRENT_BINARY_DIR}/wrapper.sh" @ONLY)
set
(
TEST_WRAPPER
${
CMAKE_CURRENT_BINARY_DIR
}
/wrapper.sh
)
add_subdirectory
(
cc
)
add_subdirectory
(
python
)
tests/python/CMakeLists.txt
0 → 100644
View file @
4afb3f87
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
add_test
(
NAME py_test_dump_func WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
COMMAND
${
TEST_WRAPPER
}
py_dump_func simple
${
CMAKE_CURRENT_SOURCE_DIR
}
/test_dump_func.py
)
tests/python/test_dump_func.py
0 → 100755
View file @
4afb3f87
#!/usr/bin/env python
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
# test program for the 'dump_func' method
from
bcc
import
BPF
from
unittest
import
main
,
TestCase
class
TestDumpFunc
(
TestCase
):
def
test_return
(
self
):
b
=
BPF
(
text
=
"""
int entry(void)
{
return 1;
}"""
)
self
.
assertEquals
(
"
\
xb7
\
x00
\
x00
\
x00
\
x01
\
x00
\
x00
\
x00
"
+
"
\
x95
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
"
,
b
.
dump_func
(
"entry"
))
if
__name__
==
"__main__"
:
main
()
tests/wrapper.sh.in
View file @
4afb3f87
...
...
@@ -39,6 +39,10 @@ function sudo_run() {
sudo
bash
-c
"PYTHONPATH=
$PYTHONPATH
LD_LIBRARY_PATH=
$LD_LIBRARY_PATH
$cmd
$1
$2
"
return
$?
}
function
simple_run
()
{
PYTHONPATH
=
$PYTHONPATH
LD_LIBRARY_PATH
=
$LD_LIBRARY_PATH
$cmd
$1
$2
return
$?
}
case
$kind
in
namespace
)
...
...
@@ -47,6 +51,9 @@ case $kind in
sudo
)
sudo_run
$@
;;
simple
)
simple_run
$@
;;
*
)
echo
"Invalid kind
$kind
"
exit
1
...
...
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