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
53c7f4c3
Commit
53c7f4c3
authored
Dec 08, 2016
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure programs get cleaned up correctly
parent
1b10c068
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
src/cc/BPF.cc
src/cc/BPF.cc
+21
-15
No files found.
src/cc/BPF.cc
View file @
53c7f4c3
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include <linux/bpf.h>
#include <linux/bpf.h>
#include <unistd.h>
#include <unistd.h>
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <exception>
#include <exception>
#include <iostream>
#include <iostream>
#include <memory>
#include <memory>
...
@@ -106,6 +107,15 @@ StatusTuple BPF::detach_all() {
...
@@ -106,6 +107,15 @@ StatusTuple BPF::detach_all() {
delete
it
.
second
;
delete
it
.
second
;
}
}
for
(
auto
it
:
funcs_
)
{
int
res
=
close
(
it
.
second
);
if
(
res
!=
0
)
{
error_msg
+=
"Failed to unload BPF program for "
+
it
.
first
+
": "
;
error_msg
+=
std
::
string
(
std
::
strerror
(
res
))
+
"
\n
"
;
has_error
=
true
;
}
}
if
(
has_error
)
if
(
has_error
)
return
StatusTuple
(
-
1
,
error_msg
);
return
StatusTuple
(
-
1
,
error_msg
);
else
else
...
@@ -117,14 +127,12 @@ StatusTuple BPF::attach_kprobe(const std::string& kernel_func,
...
@@ -117,14 +127,12 @@ StatusTuple BPF::attach_kprobe(const std::string& kernel_func,
bpf_attach_type
attach_type
,
bpf_attach_type
attach_type
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_KPROBE
,
probe_fd
));
std
::
string
probe_event
=
get_kprobe_event
(
kernel_func
,
attach_type
);
std
::
string
probe_event
=
get_kprobe_event
(
kernel_func
,
attach_type
);
if
(
kprobes_
.
find
(
probe_event
)
!=
kprobes_
.
end
())
{
if
(
kprobes_
.
find
(
probe_event
)
!=
kprobes_
.
end
())
TRY2
(
unload_func
(
probe_func
));
return
StatusTuple
(
-
1
,
"kprobe %s already attached"
,
probe_event
.
c_str
());
return
StatusTuple
(
-
1
,
"kprobe %s already attached"
,
probe_event
.
c_str
());
}
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_KPROBE
,
probe_fd
));
std
::
string
probe_event_desc
=
attach_type_prefix
(
attach_type
);
std
::
string
probe_event_desc
=
attach_type_prefix
(
attach_type
);
probe_event_desc
+=
":kprobes/"
+
probe_event
+
" "
+
kernel_func
;
probe_event_desc
+=
":kprobes/"
+
probe_event
+
" "
+
kernel_func
;
...
@@ -154,18 +162,16 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
...
@@ -154,18 +162,16 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
bpf_attach_type
attach_type
,
bpf_attach_type
attach_type
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_KPROBE
,
probe_fd
));
bcc_symbol
sym
=
bcc_symbol
();
bcc_symbol
sym
=
bcc_symbol
();
TRY2
(
check_binary_symbol
(
binary_path
,
symbol
,
symbol_addr
,
&
sym
));
TRY2
(
check_binary_symbol
(
binary_path
,
symbol
,
symbol_addr
,
&
sym
));
std
::
string
probe_event
=
std
::
string
probe_event
=
get_uprobe_event
(
sym
.
module
,
sym
.
offset
,
attach_type
);
get_uprobe_event
(
sym
.
module
,
sym
.
offset
,
attach_type
);
if
(
uprobes_
.
find
(
probe_event
)
!=
uprobes_
.
end
())
{
if
(
uprobes_
.
find
(
probe_event
)
!=
uprobes_
.
end
())
TRY2
(
unload_func
(
probe_func
));
return
StatusTuple
(
-
1
,
"uprobe %s already attached"
,
probe_event
.
c_str
());
return
StatusTuple
(
-
1
,
"uprobe %s already attached"
,
probe_event
.
c_str
());
}
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_KPROBE
,
probe_fd
));
std
::
string
probe_event_desc
=
attach_type_prefix
(
attach_type
);
std
::
string
probe_event_desc
=
attach_type_prefix
(
attach_type
);
probe_event_desc
+=
":uprobes/"
+
probe_event
+
" "
;
probe_event_desc
+=
":uprobes/"
+
probe_event
+
" "
;
...
@@ -195,9 +201,6 @@ StatusTuple BPF::attach_tracepoint(const std::string& tracepoint,
...
@@ -195,9 +201,6 @@ StatusTuple BPF::attach_tracepoint(const std::string& tracepoint,
const
std
::
string
&
probe_func
,
const
std
::
string
&
probe_func
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_TRACEPOINT
,
probe_fd
));
if
(
tracepoints_
.
find
(
tracepoint
)
!=
tracepoints_
.
end
())
if
(
tracepoints_
.
find
(
tracepoint
)
!=
tracepoints_
.
end
())
return
StatusTuple
(
-
1
,
"Tracepoint %s already attached"
,
return
StatusTuple
(
-
1
,
"Tracepoint %s already attached"
,
tracepoint
.
c_str
());
tracepoint
.
c_str
());
...
@@ -208,6 +211,9 @@ StatusTuple BPF::attach_tracepoint(const std::string& tracepoint,
...
@@ -208,6 +211,9 @@ StatusTuple BPF::attach_tracepoint(const std::string& tracepoint,
std
::
string
tp_category
=
tracepoint
.
substr
(
0
,
pos
);
std
::
string
tp_category
=
tracepoint
.
substr
(
0
,
pos
);
std
::
string
tp_name
=
tracepoint
.
substr
(
pos
+
1
);
std
::
string
tp_name
=
tracepoint
.
substr
(
pos
+
1
);
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_TRACEPOINT
,
probe_fd
));
void
*
res
=
void
*
res
=
bpf_attach_tracepoint
(
probe_fd
,
tp_category
.
c_str
(),
tp_name
.
c_str
(),
pid
,
bpf_attach_tracepoint
(
probe_fd
,
tp_category
.
c_str
(),
tp_name
.
c_str
(),
pid
,
cpu
,
group_fd
,
cb
,
cb_cookie
);
cpu
,
group_fd
,
cb
,
cb_cookie
);
...
...
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