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
d82e813e
Commit
d82e813e
authored
May 04, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add and unify helper for ELF type
parent
b6b9c6db
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
21 deletions
+23
-21
src/cc/bcc_elf.c
src/cc/bcc_elf.c
+16
-6
src/cc/bcc_elf.h
src/cc/bcc_elf.h
+3
-0
src/cc/bcc_proc.c
src/cc/bcc_proc.c
+2
-13
src/cc/usdt.cc
src/cc/usdt.cc
+1
-1
src/cc/usdt_args.cc
src/cc/usdt_args.cc
+1
-1
No files found.
src/cc/bcc_elf.c
View file @
d82e813e
...
...
@@ -483,21 +483,31 @@ int bcc_elf_loadaddr(const char *path, uint64_t *address) {
return
res
;
}
int
bcc_elf_
is_shared_obj
(
const
char
*
path
)
{
int
bcc_elf_
get_type
(
const
char
*
path
)
{
Elf
*
e
;
GElf_Ehdr
hdr
;
int
fd
,
res
=
-
1
;
int
fd
;
void
*
res
=
NULL
;
if
(
openelf
(
path
,
&
e
,
&
fd
)
<
0
)
return
-
1
;
if
(
gelf_getehdr
(
e
,
&
hdr
))
res
=
(
hdr
.
e_type
==
ET_DYN
);
res
=
(
void
*
)
gelf_getehdr
(
e
,
&
hdr
);
elf_end
(
e
);
close
(
fd
);
return
res
;
if
(
!
res
)
return
-
1
;
else
return
hdr
.
e_type
;
}
int
bcc_elf_is_exe
(
const
char
*
path
)
{
return
(
bcc_elf_get_type
(
path
)
!=
-
1
)
&&
(
access
(
path
,
X_OK
)
==
0
);
}
int
bcc_elf_is_shared_obj
(
const
char
*
path
)
{
return
bcc_elf_get_type
(
path
)
==
ET_DYN
;
}
#if 0
...
...
src/cc/bcc_elf.h
View file @
d82e813e
...
...
@@ -41,7 +41,10 @@ int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback,
int
bcc_elf_loadaddr
(
const
char
*
path
,
uint64_t
*
address
);
int
bcc_elf_foreach_sym
(
const
char
*
path
,
bcc_elf_symcb
callback
,
void
*
payload
);
int
bcc_elf_get_type
(
const
char
*
path
);
int
bcc_elf_is_shared_obj
(
const
char
*
path
);
int
bcc_elf_is_exe
(
const
char
*
path
);
#ifdef __cplusplus
}
...
...
src/cc/bcc_proc.c
View file @
d82e813e
...
...
@@ -35,23 +35,12 @@
#include "bcc_proc.h"
#include "bcc_elf.h"
static
bool
is_exe
(
const
char
*
path
)
{
struct
stat
s
;
if
(
access
(
path
,
X_OK
)
<
0
)
return
false
;
if
(
stat
(
path
,
&
s
)
<
0
)
return
false
;
return
S_ISREG
(
s
.
st_mode
);
}
char
*
bcc_procutils_which
(
const
char
*
binpath
)
{
char
buffer
[
4096
];
const
char
*
PATH
;
if
(
strchr
(
binpath
,
'/'
))
return
is_exe
(
binpath
)
?
strdup
(
binpath
)
:
0
;
return
bcc_elf_
is_exe
(
binpath
)
?
strdup
(
binpath
)
:
0
;
if
(
!
(
PATH
=
getenv
(
"PATH"
)))
return
0
;
...
...
@@ -65,7 +54,7 @@ char *bcc_procutils_which(const char *binpath) {
buffer
[
path_len
]
=
'/'
;
strcpy
(
buffer
+
path_len
+
1
,
binpath
);
if
(
is_exe
(
buffer
))
if
(
bcc_elf_
is_exe
(
buffer
))
return
strdup
(
buffer
);
}
...
...
src/cc/usdt.cc
View file @
d82e813e
...
...
@@ -48,7 +48,7 @@ Probe::Probe(const char *bin_path, const char *provider, const char *name,
bool
Probe
::
in_shared_object
()
{
if
(
!
in_shared_object_
)
in_shared_object_
=
(
bcc_elf_is_shared_obj
(
bin_path_
.
c_str
())
==
1
);
in_shared_object_
=
bcc_elf_is_shared_obj
(
bin_path_
.
c_str
()
);
return
in_shared_object_
.
value
();
}
...
...
src/cc/usdt_args.cc
View file @
d82e813e
...
...
@@ -39,7 +39,7 @@ bool Argument::get_global_address(uint64_t *address, const std::string &binpath,
.
resolve_name
(
binpath
.
c_str
(),
deref_ident_
->
c_str
(),
address
);
}
if
(
bcc_elf_is_shared_obj
(
binpath
.
c_str
())
==
0
)
{
if
(
!
bcc_elf_is_shared_obj
(
binpath
.
c_str
())
)
{
struct
bcc_symbol
sym
=
{
deref_ident_
->
c_str
(),
binpath
.
c_str
(),
0x0
};
if
(
!
bcc_find_symbol_addr
(
&
sym
)
&&
sym
.
offset
)
{
*
address
=
sym
.
offset
;
...
...
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