Search /usr/lib/debug/.build-id for debug files#1415
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1415 +/- ##
=======================================
Coverage 95.78% 95.78%
=======================================
Files 61 61
Lines 11075 11115 +40
=======================================
+ Hits 10608 10647 +39
- Misses 467 468 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for working on this feature. I will take a look tomorrow. |
d-e-s-o
left a comment
There was a problem hiding this comment.
It's a good addition, but I think the way it's written will make testing close to impossible. Please take a look at my comments/suggestions and let me know what you think.
src/dwarf/debug_link.rs
Outdated
| return self.next() | ||
| }; | ||
|
|
||
| let Ok(Some(build_id)) = read_elf_build_id(linker) else { |
There was a problem hiding this comment.
I really don't like that we are just papering over errors here -- it is unclear from the context whether that is or is not acceptable and so the decision shouldn't be forced here. The iterator is also meant to be independent of system state, so it shouldn't be doing any file system operations.
My suggestion would be to move build ID reading into find_debug_file and then pass an optional build ID to DebugFileIter::new, that will also basically be a requirement for testing purposes. It's a bit unfortunate that it means eager build ID reading, but given that we check it first anyway that seems fine and we can revisit that part later.
There was a problem hiding this comment.
I really don't like that we are just papering over errors here -- it unclear from the context whether that is or is not acceptable and so the decision shouldn't be forced here.
How do you think I should deal with errors? Just log them with warn!() or do something else?
My suggestion would be to move build ID reading into find_debug_file and then pass an optional build ID to
DebugFileIter::new, that will also basically be a requirement for testing purposes.
I moved it there.
There was a problem hiding this comment.
that will also basically be a requirement for testing purposes
How do you see testing this? I'm thinking of using DrarfResolver::from_parser() and passing an argument to override the build id directory, but let me know if you have something else in mind.
There was a problem hiding this comment.
I amended DebugFileIter tests. Let me know if that's sufficient (it feels like it is to me).
src/dwarf/debug_link.rs
Outdated
| let first = build_id | ||
| .iter() | ||
| .take(1) | ||
| .map(|byte| format!("{byte:02x}")) | ||
| .collect::<String>(); | ||
| let rest = build_id | ||
| .iter() | ||
| .skip(1) | ||
| .map(|byte| format!("{byte:02x}")) | ||
| .collect::<String>(); |
There was a problem hiding this comment.
Nitpicky, but please dont iterate twice. Just create an iterator, take a first element and format it as a byte as you do, then consume the rest as you also do.
That will also make it more obvious that the logic is actually not handling the case of an empty build ID in a way I'd intend (while that is b/s input, it also is effectively user controlled input, so we should probably deal with it properly instead of potentially opening files in directories we don't intend to). I think it's legitimate to just skip the BuildId state if the build ID is not of the expected format, i.e., missing the first byte (I think it's fine to not assert length of the remainder, but a check that it is not empty may also be in order; for the most part I am concerned about staying in the intended directory, though).
It would also be great if you were to add a test for such a case.
There was a problem hiding this comment.
I moved it to one iterator + length check with a comment.
There was a problem hiding this comment.
I added a test for the length as well.
70bbc6c to
4afb1c6
Compare
Signed-off-by: Ivan Babrou <[email protected]>
d-e-s-o
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
| use crate::BuildId; | ||
| use crate::Result; | ||
|
|
||
|
|
There was a problem hiding this comment.
Please avoid spurious changes like this in the future. Thanks!
Add a CHANGELOG entry for pull request libbpf#1415, which added support for the /usr/lib/debug/.build-id directory for debug link targets. Also extend the DebugFileIter tests marginally, to cover one more case. Signed-off-by: Daniel Müller <[email protected]>
Add a CHANGELOG entry for pull request libbpf#1415, which added support for the /usr/lib/debug/.build-id directory for debug link targets. Also adjust the DebugFileIter logic marginally. Signed-off-by: Daniel Müller <[email protected]>
Add a CHANGELOG entry for pull request #1415, which added support for the /usr/lib/debug/.build-id directory for debug link targets. Also adjust the DebugFileIter logic marginally. Signed-off-by: Daniel Müller <[email protected]>
This takes a stab at #1401. It works on Debian with
libc6-dbginstalled:It does not work without the change:
Let me know if it's the right approach before I go about adding a test.