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
3e7c3d9a
Commit
3e7c3d9a
authored
Apr 17, 2016
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #490 from vmg/vmg/lua64
lua: Properly support high-range 64 addresses
parents
3344dc9e
fbf7193c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
53 additions
and
17 deletions
+53
-17
examples/lua/memleak.lua
examples/lua/memleak.lua
+2
-2
examples/lua/offcputime.lua
examples/lua/offcputime.lua
+1
-1
src/lua/bcc/bpf.lua
src/lua/bcc/bpf.lua
+2
-2
src/lua/bcc/ld.lua
src/lua/bcc/ld.lua
+3
-2
src/lua/bcc/sym.lua
src/lua/bcc/sym.lua
+9
-8
src/lua/bcc/table.lua
src/lua/bcc/table.lua
+1
-1
src/lua/bcc/vendor/helpers.lua
src/lua/bcc/vendor/helpers.lua
+27
-1
src/lua/bcc/vendor/posix.lua
src/lua/bcc/vendor/posix.lua
+8
-0
No files found.
examples/lua/memleak.lua
View file @
3e7c3d9a
...
...
@@ -148,7 +148,7 @@ return function(BPF, utils)
if
args
.
pid
==
nil
then
sym
=
sym
..
" [kernel]"
end
return
string.format
(
"%s (%
x
)"
,
sym
,
addr
)
return
string.format
(
"%s (%
p
)"
,
sym
,
addr
)
end
local
function
print_outstanding
()
...
...
@@ -174,7 +174,7 @@ return function(BPF, utils)
end
if
args
.
show_allocs
then
print
(
"
\t
addr = %
x size = %s"
%
{
tonumber
(
address
)
,
tonumber
(
info
.
size
)})
print
(
"
\t
addr = %
p size = %s"
%
{
address
,
tonumber
(
info
.
size
)})
end
end
end
...
...
examples/lua/offcputime.lua
View file @
3e7c3d9a
...
...
@@ -107,7 +107,7 @@ return function(BPF, utils)
for
k
,
v
in
counts
:
items
()
do
for
addr
in
stack_traces
:
walk
(
tonumber
(
k
.
stack_id
))
do
print
(
" %-16
x
%s"
%
{
addr
,
ksym
:
lookup
(
addr
)})
print
(
" %-16
p
%s"
%
{
addr
,
ksym
:
lookup
(
addr
)})
end
print
(
" %-16s %s"
%
{
"-"
,
ffi
.
string
(
k
.
name
)})
print
(
" %d\n"
%
tonumber
(
v
))
...
...
src/lua/bcc/bpf.lua
View file @
3e7c3d9a
...
...
@@ -188,8 +188,8 @@ function Bpf:attach_uprobe(args)
local
path
,
addr
=
LD
.
check_path_symbol
(
args
.
name
,
args
.
sym
,
args
.
addr
)
local
fn
=
self
:
load_func
(
args
.
fn_name
,
'BPF_PROG_TYPE_KPROBE'
)
local
ptype
=
args
.
retprobe
and
"r"
or
"p"
local
ev_name
=
string.format
(
"%s_%s_0x%
x
"
,
ptype
,
path
:
gsub
(
"
[^
%a%d
]
"
,
"_"
),
addr
)
local
desc
=
string.format
(
"%s:uprobes/%s %s:0x%
x
"
,
ptype
,
ev_name
,
path
,
addr
)
local
ev_name
=
string.format
(
"%s_%s_0x%
p
"
,
ptype
,
path
:
gsub
(
"
[^
%a%d
]
"
,
"_"
),
addr
)
local
desc
=
string.format
(
"%s:uprobes/%s %s:0x%
p
"
,
ptype
,
ev_name
,
path
,
addr
)
log
.
info
(
desc
)
...
...
src/lua/bcc/ld.lua
View file @
3e7c3d9a
...
...
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
]]
local
ffi
=
require
(
"ffi"
)
local
posix
=
require
(
"bcc.vendor.posix"
)
local
_find_library_cache
=
{}
local
function
_find_library
(
name
)
...
...
@@ -60,7 +61,7 @@ local function _find_load_address(path)
path
)
if
addr
then
addr
=
tonumber
(
addr
,
16
)
addr
=
posix
.
tonumber64
(
addr
,
16
)
_find_load_address_cache
[
path
]
=
addr
end
...
...
@@ -85,7 +86,7 @@ local function _find_symbol(path, sym)
path
,
sym
)
if
addr
then
addr
=
tonumber
(
addr
,
16
)
addr
=
posix
.
tonumber64
(
addr
,
16
)
symbols
[
sym
]
=
addr
end
...
...
src/lua/bcc/sym.lua
View file @
3e7c3d9a
...
...
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
local
posix
=
require
(
"bcc.vendor.posix"
)
local
ProcSymbols
=
class
(
"ProcSymbols"
)
function
ProcSymbols
:
initialize
(
pid
)
...
...
@@ -46,7 +47,7 @@ function ProcSymbols:_get_code_ranges()
local
range
=
parts
[
1
]:
split
(
"-"
,
true
)
assert
(
#
range
==
2
)
ranges
[
binary
]
=
{
tonumber
(
range
[
1
],
16
),
tonumber
(
range
[
2
],
16
)}
ranges
[
binary
]
=
{
posix
.
tonumber64
(
range
[
1
],
16
),
posix
.
tonumber64
(
range
[
2
],
16
)}
end
end
...
...
@@ -83,8 +84,8 @@ function ProcSymbols:_get_sym_ranges(binary)
for
line
in
proc
:
lines
()
do
local
parts
=
line
:
split
()
if
is_function_sym
(
parts
)
then
local
sym_start
=
tonumber
(
parts
[
1
],
16
)
local
sym_len
=
tonumber
(
parts
[
5
],
16
)
local
sym_start
=
posix
.
tonumber64
(
parts
[
1
],
16
)
local
sym_len
=
posix
.
tonumber64
(
parts
[
5
],
16
)
local
sym_name
=
parts
[
6
]
sym_ranges
[
sym_name
]
=
{
sym_start
,
sym_len
}
end
...
...
@@ -102,10 +103,10 @@ function ProcSymbols:_decode_sym(binary, offset)
local
start
=
range
[
1
]
local
length
=
range
[
2
]
if
offset
>=
start
and
offset
<=
(
start
+
length
)
then
return
string.format
(
"%s+0x%
x
"
,
name
,
offset
-
start
)
return
string.format
(
"%s+0x%
p
"
,
name
,
offset
-
start
)
end
end
return
string.format
(
"%
x
"
,
offset
)
return
string.format
(
"%
p
"
,
offset
)
end
function
ProcSymbols
:
lookup
(
addr
)
...
...
@@ -121,7 +122,7 @@ function ProcSymbols:lookup(addr)
end
end
return
string.format
(
"%
x
"
,
addr
)
return
string.format
(
"%
p
"
,
addr
)
end
local
KSymbols
=
class
(
"KSymbols"
)
...
...
@@ -142,7 +143,7 @@ function KSymbols:_load()
if
not
first_line
then
local
cols
=
line
:
split
()
local
name
=
cols
[
3
]
local
addr
=
tonumber
(
cols
[
1
],
16
)
local
addr
=
posix
.
tonumber64
(
cols
[
1
],
16
)
table.insert
(
self
.
ksyms
,
{
name
,
addr
})
self
.
ksym_names
[
name
]
=
#
self
.
ksyms
end
...
...
@@ -164,7 +165,7 @@ function KSymbols:lookup(addr, with_offset)
if
with_offset
then
local
offset
=
addr
-
self
.
ksyms
[
idx
][
2
]
return
"%s %
x
"
%
{
self
.
ksyms
[
idx
][
1
],
offset
}
return
"%s %
p
"
%
{
self
.
ksyms
[
idx
][
1
],
offset
}
else
return
self
.
ksyms
[
idx
][
1
]
end
...
...
src/lua/bcc/table.lua
View file @
3e7c3d9a
...
...
@@ -286,7 +286,7 @@ function StackTrace:walk(id)
return
nil
end
local
addr
=
tonumber
(
pstack
[
0
].
ip
[
i
])
local
addr
=
pstack
[
0
].
ip
[
i
]
if
addr
==
0
then
return
nil
end
...
...
src/lua/bcc/vendor/helpers.lua
View file @
3e7c3d9a
do
local
ffi
=
require
(
"ffi"
)
local
ptrtype
=
ffi
.
typeof
(
"uint64_t"
)
local
strformat
=
string.format
function
string
.
format
(
format
,
...
)
local
args
=
{
...
}
local
match_no
=
1
local
newfmt
,
count
=
string.gsub
(
format
,
"()%%(.-)(%a)"
,
function
(
_
,
mods
,
t
)
local
n
=
match_no
match_no
=
match_no
+
1
if
t
==
'p'
and
ffi
.
istype
(
ptrtype
,
args
[
n
])
then
local
lo
=
tonumber
(
args
[
n
]
%
4294967296
ULL
)
local
hi
=
tonumber
(
args
[
n
]
/
4294967296
ULL
)
args
[
n
]
=
(
hi
==
0
)
and
strformat
(
"%x"
,
lo
)
or
strformat
(
"%x%08x"
,
hi
,
lo
)
return
"%"
..
mods
..
"s"
end
end
)
if
count
==
0
then
return
strformat
(
format
,
...
)
else
return
strformat
(
newfmt
,
unpack
(
args
,
1
,
select
(
'#'
,
...
)))
end
end
end
function
string
.
starts
(
s
,
p
)
return
string.sub
(
s
,
1
,
string.len
(
p
))
==
p
end
...
...
@@ -66,7 +92,7 @@ function table.bsearch(list, value, mkval)
return
mid
end
end
return
nil
return
low
-
1
end
function
table
.
join
(
a
,
b
)
...
...
src/lua/bcc/vendor/posix.lua
View file @
3e7c3d9a
...
...
@@ -29,6 +29,8 @@ int clock_nanosleep(clockid_t clock_id, int flags,
const struct timespec *request, struct timespec *remain);
int get_nprocs(void);
uint64_t strtoull(const char *nptr, char **endptr, int base);
]]
local
CLOCK
=
{
...
...
@@ -62,9 +64,15 @@ local function cpu_count()
return
tonumber
(
ffi
.
C
.
get_nprocs
())
end
local
function
tonumber64
(
n
,
base
)
assert
(
type
(
n
)
==
"string"
)
return
ffi
.
C
.
strtoull
(
n
,
nil
,
base
or
10
)
end
return
{
time_ns
=
time_ns
,
sleep
=
sleep
,
CLOCK
=
CLOCK
,
cpu_count
=
cpu_count
,
tonumber64
=
tonumber64
,
}
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