Skip to content
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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ttreyer
Copy link
Contributor

@ttreyer ttreyer commented Mar 28, 2024

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:

struct Parent { int abc, xyz; };
struct Child : Parent { int abc; };
...
child->abc          // Access the child's member
child->xyz          // Access the parent's member
child->Parent::abc  // Not implemented: access the parent's shadowed member

Multiple inheritance suffer from a similar problem: when a parent shadows the member of another parent.

struct GrandChild : Parent, Child {};
g_child->xyz // Access Parent's member
g_child->abc // Ambiguous! Will access Parent::abc, but it should reject and require a qualified name instead
Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

tests/testprogs/uprobe_test_cxx.cpp Fixed Show fixed Hide fixed
tests/data/data_source_cxx.cpp Fixed Show fixed Hide fixed
tests/data/data_source_cxx.cpp Fixed Show fixed Hide fixed
},
5 // Bottom's w
};
func_3(m, b);

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect (because
func_3
has no external side effects).
{
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

This expression has no effect (because
func_1
has no external side effects).
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

This expression has no effect (because
func_2
has no external side effects).
@ttreyer ttreyer marked this pull request as draft April 9, 2024 13:44
@ttreyer ttreyer force-pushed the cxx-inheritance branch 3 times, most recently from ed523b6 to a6d232f Compare April 30, 2024 16:01
@ttreyer ttreyer force-pushed the cxx-inheritance branch 3 times, most recently from 099b9f5 to e44449c Compare May 23, 2024 16:27
@ttreyer ttreyer force-pushed the cxx-inheritance branch 3 times, most recently from d61b5dd to 4580a6d Compare May 23, 2024 19:15

int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
{
// usleep(1000000);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

int x = 42;
Foo foo{ 1, 2, 3, x };
uprobeFunction1(x, foo);

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect (because
uprobeFunction1
has no external side effects).
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

This expression has no effect (because
uprobeArray
has no external side effects).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant