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
e7893607
Commit
e7893607
authored
Mar 30, 2016
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpf.lua: Add support for CFLAGS and LLVM debug flags
parent
a978401e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
7 deletions
+34
-7
examples/lua/bashreadline.lua
examples/lua/bashreadline.lua
+1
-1
examples/lua/memleak.lua
examples/lua/memleak.lua
+1
-1
examples/lua/strlen_count.lua
examples/lua/strlen_count.lua
+1
-1
examples/lua/task_switch.lua
examples/lua/task_switch.lua
+1
-1
src/lua/bcc/bpf.lua
src/lua/bcc/bpf.lua
+14
-3
src/lua/bcc/vendor/helpers.lua
src/lua/bcc/vendor/helpers.lua
+16
-0
No files found.
examples/lua/bashreadline.lua
View file @
e7893607
...
@@ -16,7 +16,7 @@ limitations under the License.
...
@@ -16,7 +16,7 @@ limitations under the License.
local
ffi
=
require
(
"ffi"
)
local
ffi
=
require
(
"ffi"
)
return
function
(
BPF
)
return
function
(
BPF
)
local
b
=
BPF
:
new
{
src_file
=
"bashreadline.c"
,
debug
=
true
}
local
b
=
BPF
:
new
{
src_file
=
"bashreadline.c"
,
debug
=
0
}
b
:
attach_uprobe
{
name
=
"/bin/bash"
,
sym
=
"readline"
,
fn_name
=
"printret"
,
retprobe
=
true
}
b
:
attach_uprobe
{
name
=
"/bin/bash"
,
sym
=
"readline"
,
fn_name
=
"printret"
,
retprobe
=
true
}
local
function
print_readline
(
cpu
,
event
)
local
function
print_readline
(
cpu
,
event
)
...
...
examples/lua/memleak.lua
View file @
e7893607
...
@@ -123,7 +123,7 @@ return function(BPF, utils)
...
@@ -123,7 +123,7 @@ return function(BPF, utils)
text
=
text
:
gsub
(
"SHOULD_PRINT"
,
args.trace
and
"1"
or
"0"
)
text
=
text
:
gsub
(
"SHOULD_PRINT"
,
args.trace
and
"1"
or
"0"
)
text
=
text
:
gsub
(
"SAMPLE_EVERY_N"
,
tostring
(
args.sample_rate
))
text
=
text
:
gsub
(
"SAMPLE_EVERY_N"
,
tostring
(
args.sample_rate
))
local
bpf
=
BPF
:
new
{
text
=
text
,
debug
=
true
}
local
bpf
=
BPF
:
new
{
text
=
text
,
debug
=
0
}
local
syms
=
nil
local
syms
=
nil
local
min_age_ns
=
args
.
older
*
1e6
local
min_age_ns
=
args
.
older
*
1e6
...
...
examples/lua/strlen_count.lua
View file @
e7893607
...
@@ -32,7 +32,7 @@ int printarg(struct pt_regs *ctx) {
...
@@ -32,7 +32,7 @@ int printarg(struct pt_regs *ctx) {
]]
,
"PID"
,
arg
[
1
])
]]
,
"PID"
,
arg
[
1
])
return
function
(
BPF
)
return
function
(
BPF
)
local
b
=
BPF
:
new
{
text
=
program
,
debug
=
true
}
local
b
=
BPF
:
new
{
text
=
program
,
debug
=
0
}
b
:
attach_uprobe
{
name
=
"c"
,
sym
=
"strlen"
,
fn_name
=
"printarg"
}
b
:
attach_uprobe
{
name
=
"c"
,
sym
=
"strlen"
,
fn_name
=
"printarg"
}
local
pipe
=
b
:
pipe
()
local
pipe
=
b
:
pipe
()
...
...
examples/lua/task_switch.lua
View file @
e7893607
...
@@ -38,7 +38,7 @@ int count_sched(struct pt_regs *ctx, struct task_struct *prev) {
...
@@ -38,7 +38,7 @@ int count_sched(struct pt_regs *ctx, struct task_struct *prev) {
]]
]]
return
function
(
BPF
)
return
function
(
BPF
)
local
b
=
BPF
:
new
{
text
=
program
,
debug
=
true
}
local
b
=
BPF
:
new
{
text
=
program
,
debug
=
0
}
b
:
attach_kprobe
{
event
=
"finish_task_switch"
,
fn_name
=
"count_sched"
}
b
:
attach_kprobe
{
event
=
"finish_task_switch"
,
fn_name
=
"count_sched"
}
print
(
"Press any key..."
)
print
(
"Press any key..."
)
...
...
src/lua/bcc/bpf.lua
View file @
e7893607
...
@@ -27,6 +27,11 @@ Bpf.static.open_uprobes = {}
...
@@ -27,6 +27,11 @@ Bpf.static.open_uprobes = {}
Bpf
.
static
.
process_symbols
=
{}
Bpf
.
static
.
process_symbols
=
{}
Bpf
.
static
.
KPROBE_LIMIT
=
1000
Bpf
.
static
.
KPROBE_LIMIT
=
1000
Bpf
.
static
.
tracer_pipe
=
nil
Bpf
.
static
.
tracer_pipe
=
nil
Bpf
.
static
.
DEFAULT_CFLAGS
=
{
'-D__HAVE_BUILTIN_BSWAP16__'
,
'-D__HAVE_BUILTIN_BSWAP32__'
,
'-D__HAVE_BUILTIN_BSWAP64__'
,
}
function
Bpf
.
static
.
check_probe_quota
(
n
)
function
Bpf
.
static
.
check_probe_quota
(
n
)
local
cur
=
table
.
count
(
Bpf
.
static
.
open_kprobes
)
+
table
.
count
(
Bpf
.
static
.
open_uprobes
)
local
cur
=
table
.
count
(
Bpf
.
static
.
open_kprobes
)
+
table
.
count
(
Bpf
.
static
.
open_uprobes
)
...
@@ -101,17 +106,23 @@ function Bpf:initialize(args)
...
@@ -101,17 +106,23 @@ function Bpf:initialize(args)
self
.
funcs
=
{}
self
.
funcs
=
{}
self
.
tables
=
{}
self
.
tables
=
{}
local
cflags
=
table
.
join
(
Bpf
.
DEFAULT_CFLAGS
,
args
.
cflags
)
local
cflags_ary
=
ffi
.
new
(
"const char *[?]"
,
#
cflags
,
cflags
)
local
llvm_debug
=
args
.
debug
or
0
assert
(
type
(
llvm_debug
)
==
"number"
)
if
args
.
text
then
if
args
.
text
then
log
.
info
(
"
\n
%s\n"
,
args
.
text
)
log
.
info
(
"
\n
%s\n"
,
args
.
text
)
self
.
module
=
libbcc
.
bpf_module_create_c_from_string
(
args
.
text
,
args
.
llvm_debug
or
0
,
nil
,
0
)
self
.
module
=
libbcc
.
bpf_module_create_c_from_string
(
args
.
text
,
llvm_debug
,
cflags_ary
,
#
cflags
)
elseif
args
.
src_file
then
elseif
args
.
src_file
then
local
src
=
_find_file
(
Bpf
.
SCRIPT_ROOT
,
args
.
src_file
)
local
src
=
_find_file
(
Bpf
.
SCRIPT_ROOT
,
args
.
src_file
)
if
src
:
ends
(
".b"
)
then
if
src
:
ends
(
".b"
)
then
local
hdr
=
_find_file
(
Bpf
.
SCRIPT_ROOT
,
args
.
hdr_file
)
local
hdr
=
_find_file
(
Bpf
.
SCRIPT_ROOT
,
args
.
hdr_file
)
self
.
module
=
libbcc
.
bpf_module_create_b
(
src
,
hdr
,
args
.
llvm_debug
or
0
)
self
.
module
=
libbcc
.
bpf_module_create_b
(
src
,
hdr
,
llvm_debug
)
else
else
self
.
module
=
libbcc
.
bpf_module_create_c
(
src
,
args
.
llvm_debug
or
0
,
nil
,
0
)
self
.
module
=
libbcc
.
bpf_module_create_c
(
src
,
llvm_debug
,
cflags_ary
,
#
cflags
)
end
end
end
end
...
...
src/lua/bcc/vendor/helpers.lua
View file @
e7893607
...
@@ -65,6 +65,22 @@ function table.bsearch(list, value, mkval)
...
@@ -65,6 +65,22 @@ function table.bsearch(list, value, mkval)
return
nil
return
nil
end
end
function
table
.
join
(
a
,
b
)
assert
(
a
)
if
b
==
nil
or
#
b
==
0
then
return
a
end
local
res
=
{}
for
_
,
v
in
ipairs
(
a
)
do
table.insert
(
res
,
v
)
end
for
_
,
v
in
ipairs
(
b
)
do
table.insert
(
res
,
v
)
end
return
res
end
function
table
.
build
(
iterator_fn
,
build_fn
)
function
table
.
build
(
iterator_fn
,
build_fn
)
build_fn
=
(
build_fn
or
function
(
arg
)
return
arg
end
)
build_fn
=
(
build_fn
or
function
(
arg
)
return
arg
end
)
local
res
=
{}
local
res
=
{}
...
...
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