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

Add metadata to instructions returned by program info #1118

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

dylandreimerink
Copy link
Member

@dylandreimerink dylandreimerink commented Aug 16, 2023

The instructions returned by program info gotten from the kernel did
not contain any metadata such as line info or function info. This
makes it harder to read the instructions when comparing the xlated
instruction in the kernel with the spec.

This PR uses the line info and function info that is available via
the program info and adds it to the returned instructions.

@dylandreimerink dylandreimerink force-pushed the feature/program-info-metadata branch 2 times, most recently from a7efb4a to 917fec1 Compare August 16, 2023 12:51
@dylandreimerink dylandreimerink marked this pull request as ready for review August 16, 2023 13:01
Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice idea, when we wrote the current code to pull out instructions metadata wasn't a thing yet. This reminds me that we could also use metadata to tag map load isns we get from the kernel, I should create an issue.

Some high level thoughts: seems like what you really want to do is calling Assign(). All of the other stuff with ExtInfoBuilder is just a side-show. What do you think about the following?

  • Export funcInfo and lineInfo
  • Export constructors for []FuncInfo, []LineInfo. Those should take a byte order, reader and a Spec probably. These are somewhere between parseFuncInfos and parseFuncInfoRecords: they take infos without the header and return a slice instead of a map.
  • Add a function AssignInstructionMetadata(Instructions, []FuncInfo, []LineInfo) and call that from ExtInfos.Assign. The core relocation part we can keep in ExtInfos.Assign for now.

In general I want to avoid public APIs which assume native endian as much as possible. The same goes for the record size.

info.go Outdated Show resolved Hide resolved
btf/ext_info.go Outdated Show resolved Hide resolved
@dylandreimerink
Copy link
Member Author

Some high level thoughts: seems like what you really want to do is calling Assign(). All of the other stuff with ExtInfoBuilder is just a side-show. What do you think about the following?

  • Export funcInfo and lineInfo
  • Export constructors for []FuncInfo, []LineInfo. Those should take a byte order, reader and a Spec probably. These are somewhere between parseFuncInfos and parseFuncInfoRecords: they take infos without the header and return a slice instead of a map.
  • Add a function AssignInstructionMetadata(Instructions, []FuncInfo, []LineInfo) and call that from ExtInfos.Assign. The core relocation part we can keep in ExtInfos.Assign for now.

Yea, that is fair, sounds like a good way to approach this. I will make it so

btf/ext_info.go Outdated Show resolved Hide resolved
btf/ext_info.go Show resolved Hide resolved
info.go Outdated Show resolved Hide resolved
btf/ext_info.go Outdated Show resolved Hide resolved
info.go Show resolved Hide resolved
@dylandreimerink dylandreimerink force-pushed the feature/program-info-metadata branch 2 times, most recently from 428e523 to 2bc0dc6 Compare September 13, 2023 09:40
Added exported types which contain slices of metadata objects so they
can be used by other packages. In particular to in a followup commit.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Added two constructors which allow for parsing of BTF FuncInfos and
LineInfos from their wire format. This will be used in a followup commit
to parse BTF metadata from program info.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
The `ProgInfo.LineInfo` and `ProgInfo.FuncInfo` fields were uint64.
This commit changes their type from uint64 to Pointer so pointers
can be assigned to these fields in a follow up commit.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
info_test.go Outdated

spec, err := LoadCollectionSpec("testdata/raw_tracepoint-el.elf")
if err != nil {
panic(err)
Copy link
Collaborator

@lmb lmb Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these should be t.Fatal

Edit: i'll fix these up.

The instructions returned by program info gotten from the kernel did
not contain any metadata such as line info or function info. This
makes it harder to read the instructions when comparing the xlated
instruction in the kernel with the spec.

This commit uses the line info and function info that is available via
the program info and adds it to the returned instructions.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
@lmb lmb force-pushed the feature/program-info-metadata branch from ea5a274 to 4204efe Compare September 13, 2023 12:13
Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lmb lmb merged commit 19be4f6 into cilium:main Sep 13, 2023
2 checks passed
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

2 participants