Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
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
bpftrace
Commits
6f90769a
Commit
6f90769a
authored
Jan 06, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Struct class
parent
0d465821
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+2
-2
src/bpftrace.h
src/bpftrace.h
+2
-2
src/struct.h
src/struct.h
+21
-0
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+9
-3
No files found.
src/ast/semantic_analyser.cpp
View file @
6f90769a
...
...
@@ -307,13 +307,13 @@ void SemanticAnalyser::visit(FieldAccess &acc)
abort
();
}
auto
fields
=
bpftrace_
.
structs_
[
cast_type
];
auto
fields
=
bpftrace_
.
structs_
[
cast_type
]
.
fields
;
if
(
fields
.
count
(
acc
.
field
)
==
0
)
{
err_
<<
"Struct/union of type '"
<<
cast_type
<<
"' does not contain "
<<
"a field named '"
<<
acc
.
field
<<
"'"
<<
std
::
endl
;
}
else
{
acc
.
type
=
std
::
get
<
0
>
(
fields
[
acc
.
field
])
;
acc
.
type
=
fields
[
acc
.
field
].
type
;
}
}
...
...
src/bpftrace.h
View file @
6f90769a
...
...
@@ -11,6 +11,7 @@
#include "ast.h"
#include "attached_probe.h"
#include "imap.h"
#include "struct.h"
#include "types.h"
namespace
bpftrace
{
...
...
@@ -30,8 +31,7 @@ public:
std
::
map
<
std
::
string
,
std
::
unique_ptr
<
IMap
>>
maps_
;
std
::
map
<
std
::
string
,
std
::
tuple
<
uint8_t
*
,
uintptr_t
>>
sections_
;
// structs_ = { struct_name: { field_name: { sized_type, offset } } }
std
::
map
<
std
::
string
,
std
::
map
<
std
::
string
,
std
::
tuple
<
SizedType
,
int
>>>
structs_
;
std
::
map
<
std
::
string
,
Struct
>
structs_
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
vector
<
SizedType
>>>
printf_args_
;
std
::
unique_ptr
<
IMap
>
stackid_map_
;
std
::
unique_ptr
<
IMap
>
perf_event_map_
;
...
...
src/struct.h
0 → 100644
View file @
6f90769a
#pragma once
#include <map>
#include "types.h"
namespace
bpftrace
{
class
Field
{
public:
SizedType
type
;
int
offset
;
};
class
Struct
{
public:
int
size
;
std
::
map
<
std
::
string
,
Field
>
fields
;
};
}
// namespace bpftrace
tests/semantic_analyser.cpp
View file @
6f90769a
...
...
@@ -40,10 +40,16 @@ void test(Driver &driver, const std::string &input, int expected_result=0)
void
test
(
const
std
::
string
&
input
,
int
expected_result
=
0
)
{
Field
field
=
{
SizedType
(
Type
::
integer
,
8
),
0
};
Field
mystr
=
{
SizedType
(
Type
::
string
,
8
),
8
};
Struct
type1
=
{
16
,
{{
"field"
,
field
},
{
"mystr"
,
mystr
}}
};
Struct
type2
=
{
8
,
{{
"field"
,
field
}}
};
BPFtrace
bpftrace
;
bpftrace
.
structs_
[
"type1"
]
[
"field"
]
=
std
::
make_tuple
(
SizedType
(
Type
::
integer
,
8
),
0
)
;
bpftrace
.
structs_
[
"type
1"
][
"mystr"
]
=
std
::
make_tuple
(
SizedType
(
Type
::
string
,
8
),
8
)
;
bpftrace
.
structs_
[
"type2"
][
"field"
]
=
std
::
make_tuple
(
SizedType
(
Type
::
integer
,
8
),
0
);
bpftrace
.
structs_
[
"type1"
]
=
type1
;
bpftrace
.
structs_
[
"type
2"
]
=
type2
;
Driver
driver
;
test
(
bpftrace
,
driver
,
input
,
expected_result
);
}
...
...
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