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
60542d8e
Commit
60542d8e
authored
Apr 27, 2016
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
usdt: Implement `assign_to_local`
parent
4fa98eaa
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1118 additions
and
0 deletions
+1118
-0
src/cc/usdt.h
src/cc/usdt.h
+8
-0
src/cc/usdt_args.cc
src/cc/usdt_args.cc
+70
-0
src/cc/vendor/tinyformat.hpp
src/cc/vendor/tinyformat.hpp
+1039
-0
tests/cc/test_usdt_args.cc
tests/cc/test_usdt_args.cc
+1
-0
No files found.
src/cc/usdt.h
View file @
60542d8e
...
...
@@ -33,11 +33,19 @@ class Argument {
optional
<
std
::
string
>
deref_ident_
;
optional
<
std
::
string
>
register_name_
;
uint64_t
get_global_address
(
int
pid
)
const
;
static
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>
translations_
;
public:
Argument
();
~
Argument
();
void
assign_to_local
(
std
::
ostream
&
stream
,
const
std
::
string
&
local_name
,
optional
<
int
>
pid
=
nullopt
)
const
;
int
arg_size
()
const
{
return
arg_size_
.
value_or
(
sizeof
(
void
*
));
}
std
::
string
ctype
()
const
;
void
normalize_register_name
(
std
::
string
*
normalized
)
const
;
const
optional
<
std
::
string
>
&
deref_ident
()
const
{
return
deref_ident_
;
}
const
optional
<
std
::
string
>
&
register_name
()
const
{
return
register_name_
;
}
...
...
src/cc/usdt_args.cc
View file @
60542d8e
...
...
@@ -15,12 +15,82 @@
*/
#include "usdt.h"
#include <unordered_map>
#include "vendor/tinyformat.hpp"
namespace
USDT
{
Argument
::
Argument
()
{}
Argument
::~
Argument
()
{}
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>
Argument
::
translations_
=
{
{
"rax"
,
"ax"
},
{
"rbx"
,
"bx"
},
{
"rcx"
,
"cx"
},
{
"rdx"
,
"dx"
},
{
"rdi"
,
"di"
},
{
"rsi"
,
"si"
},
{
"rbp"
,
"bp"
},
{
"rsp"
,
"sp"
},
{
"rip"
,
"ip"
},
{
"eax"
,
"ax"
},
{
"ebx"
,
"bx"
},
{
"ecx"
,
"cx"
},
{
"edx"
,
"dx"
},
{
"edi"
,
"di"
},
{
"esi"
,
"si"
},
{
"ebp"
,
"bp"
},
{
"esp"
,
"sp"
},
{
"eip"
,
"ip"
},
{
"al"
,
"ax"
},
{
"bl"
,
"bx"
},
{
"cl"
,
"cx"
},
{
"dl"
,
"dx"
}
};
std
::
string
Argument
::
ctype
()
const
{
const
int
s
=
arg_size
()
*
8
;
return
(
s
<
0
)
?
tfm
::
format
(
"int%d_t"
,
-
s
)
:
tfm
::
format
(
"uint%d_t"
,
s
);
}
void
Argument
::
normalize_register_name
(
std
::
string
*
normalized
)
const
{
if
(
!
register_name_
)
return
;
normalized
->
assign
(
*
register_name_
);
if
((
*
normalized
)[
0
]
==
'%'
)
normalized
->
erase
(
0
,
1
);
auto
it
=
translations_
.
find
(
*
normalized
);
if
(
it
!=
translations_
.
end
())
normalized
->
assign
(
it
->
second
);
}
uint64_t
Argument
::
get_global_address
(
int
pid
)
const
{
return
0x0
;
}
void
Argument
::
assign_to_local
(
std
::
ostream
&
stream
,
const
std
::
string
&
local_name
,
optional
<
int
>
pid
)
const
{
std
::
string
regname
;
normalize_register_name
(
&
regname
);
if
(
constant_
)
{
tfm
::
format
(
stream
,
"%s = %d;"
,
local_name
,
*
constant_
);
return
;
}
if
(
!
deref_offset_
)
{
tfm
::
format
(
stream
,
"%s = (%s)ctx->%s;"
,
local_name
,
ctype
(),
regname
);
return
;
}
if
(
deref_offset_
&&
!
deref_ident_
)
{
tfm
::
format
(
stream
,
"{
\n
"
" u64 __temp = ctx->%s + (%d);
\n
"
" bpf_probe_read(&%s, sizeof(%s), (void *)__temp);
\n
"
"}
\n
"
,
regname
,
*
deref_offset_
,
local_name
,
local_name
);
return
;
}
tfm
::
format
(
stream
,
"{
\n
"
" u64 __temp = 0x%xull + %d;
\n
"
" bpf_probe_read(&%s, sizeof(%s), (void *)__temp);
\n
"
"}
\n
"
,
get_global_address
(
pid
.
value_or
(
-
1
)),
*
deref_offset_
,
local_name
,
local_name
);
}
ssize_t
ArgumentParser
::
parse_number
(
ssize_t
pos
,
optional
<
int
>
*
result
)
{
char
*
endp
;
int
number
=
strtol
(
arg_
+
pos
,
&
endp
,
0
);
...
...
src/cc/vendor/tinyformat.hpp
0 → 100644
View file @
60542d8e
This diff is collapsed.
Click to expand it.
tests/cc/test_usdt_args.cc
View file @
60542d8e
...
...
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <string>
#include <iostream>
#include "catch.hpp"
#include "usdt.h"
...
...
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