-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse C++ class and inheritance from Debug Info #3094
base: master
Are you sure you want to change the base?
Conversation
651b120
to
c5fc189
Compare
{ | ||
Parent p{ 1, 2, 3, 4 }; | ||
Child c{ 1, 2, 3, 4, 5, 6 }; | ||
func_1(c, p); |
Check warning
Code scanning / CodeQL
Expression has no effect Warning
func_1
func_1(c, p); | ||
|
||
LittleChild lc{ 1, 2, 3, 4, 5, 6, 7 }; | ||
func_2(lc); |
Check warning
Code scanning / CodeQL
Expression has no effect Warning
func_2
ed523b6
to
a6d232f
Compare
099b9f5
to
e44449c
Compare
d61b5dd
to
4580a6d
Compare
|
||
int x = 42; | ||
Foo foo{ 1, 2, 3, x }; | ||
uprobeFunction1(x, foo); |
Check warning
Code scanning / CodeQL
Expression has no effect Warning
uprobeFunction1
Child c{ 1, 2, 3, 4, 5, 6 }; | ||
|
||
int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | ||
uprobeArray(arr); |
Check warning
Code scanning / CodeQL
Expression has no effect Warning
uprobeArray
dd69afc
to
6316e7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to cause an abort with this script when it's triggered:
uprobe:./tests/testprogs/uprobe_test_cxx:cpp:uprobeFunction1 { print(args.foo) }
This change could do with some semantic analyser unit tests as well, to confirm the AST transformation occurs as expected.
EXPECT Child & c | ||
EXPECT Parent & p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT Child & c | |
EXPECT Parent & p | |
EXPECT uprobe:./testprogs/uprobe_test_cxx:cpp:"uprobeFunction3(Child&, Parent&)" | |
Child & c | |
Parent & p |
The multi-line EXPECT will verify that the order of the arguments is printed correct too
TIMEOUT 5 | ||
|
||
NAME list uprobe args - array reference type | ||
RUN {{BPFTRACE}} -lv 'uprobe:./testprogs/uprobe_test_cxx:_Z11uprobeArrayRA10_i' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the demangled name here?
class Parent { | ||
private: | ||
int a; | ||
|
||
protected: | ||
int b; | ||
|
||
public: | ||
int c; | ||
int d; // Shadowed by Child::d, but should be reachable with a cast | ||
|
||
Parent(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) | ||
{ | ||
} | ||
}; | ||
|
||
class Child : public Parent { | ||
public: | ||
int d; | ||
int e; | ||
int f; | ||
|
||
Child(int a, int b, int c, int d, int e, int f) | ||
: Parent(a, b, c, d), d(d + 1), e(e), f(f) | ||
{ | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like these fields or inheritance hierarchy are being used in the tests - are they needed? Best to keep things as simple as possible if not necessary
{ | ||
const auto &type = expr->type; | ||
if (type.IsRefTy()) { | ||
expr = new Unop(Operator::MUL, expr, expr->loc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we convert the wrapped reference here into a pointer, then I think that will simplify later passes by not having to care about reference types any more. I'm hoping we can get away with zero changes to codegen and field_analyser. With luck, it might help with the crash I found too.
Here's an example to explain what I mean a bit better.
Original AST:
. :: [reference (struct Foo)]
builtin: args :: [struct uprobeFunction1_args]
foo
Current transformation:
dereference :: [struct Foo]
. :: [reference (struct Foo)]
builtin: args :: [struct uprobeFunction1_args]
foo
AST after converting reference into pointer:
dereference :: [struct Foo]
. :: [pointer (struct Foo)]
builtin: args :: [struct uprobeFunction1_args]
foo
Btw, I like how much simpler your method is for generating a DWARF data source - maybe we could switch the C data source across to that way in the future? |
Extend the Dwarf parser to make class members and parents' members accessible.
This patch handles any shape of inheritance hierarchy, but does provide access to parents' shadowed members:
Multiple inheritance suffer from a similar problem: when a parent shadows the member of another parent.
Checklist
man/adoc/bpftrace.adoc
CHANGELOG.md