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

Support DW_FORM_addrx* in low_pc and high_pc #541

Merged
merged 1 commit into from
Jan 2, 2021

Conversation

RReverser
Copy link
Contributor

Fixes #540.

@@ -629,6 +633,11 @@ impl<R: Reader> Unit<R> {
)?),
None => None,
};
if let Some(low_pc_attr) = low_pc_attr {
if let Some(addr) = dwarf.attr_address(&unit, low_pc_attr)? {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: to be consistent, I followed example of unit.{name,comp_dir,line_program} above where invalid attribute form is silently ignored, but I'm not sure why it's done that way...

Wouldn't it be better to return explicit UnsupportedAttributeForm error in all those cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This code originated from the dwarfdump example (a5c7ac0) and the strategy there was to be able to dump as much as we can, even if it is potentially invalid.

I agree that ideally we would return an error, and this would help expose bugs more quickly. On the other hand not all consumers need everything that this function parses. For example, #515 was fine with ignoring errors instead of fixing the real problem (missing supplementary object file).

I don't know the best way to handle this. Do you have any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, not sure either. I guess personally I would turn those fields into private OnceCells, and expose fallible getters as functions for them instead - that way, user could both handle an error, and not sacrifice any performance because variable would be cached once retrieved.

However, this would be a breaking API change, so probably not acceptable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I properly understand what you mean. Using OnceCell, retrieving the variable would need to iterate the attributes again in order to initialize the OnceCell?

Breaking changes are fine if we are sure it is the correct thing to do (but for this case I'm not sure). We still don't support all of DWARF 5, and that is likely to require more breaking changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

retrieving the variable would need to iterate the attributes again in order to initialize the OnceCell

Yeah, API-wise it would be equivalent of DebuggingInformationEntry::attr(name) which already does that, but here it would do it with caching. As you said yourself, many consumers are already fine with ignoring some fields or errors in them.

I think most consumers don't actually need to access all of the Unit properties, and emitters usually don't emit many properties on Unit node, so iteration won't have any noticeable performance impact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As another alternative, you could keep current iteration, but store Results in private fields, and clone them in such getters. But I really think that making field accessors lazy makes more sense for common scenarios, as it will reduce costs for parsing things user doesn't care about.

@RReverser RReverser marked this pull request as draft January 1, 2021 20:21
@RReverser
Copy link
Contributor Author

Other than the comment above, checked and this works as expected on my original DWARF example.

@RReverser RReverser marked this pull request as ready for review January 1, 2021 20:34
Copy link
Collaborator

@philipc philipc left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -629,6 +633,11 @@ impl<R: Reader> Unit<R> {
)?),
None => None,
};
if let Some(low_pc_attr) = low_pc_attr {
if let Some(addr) = dwarf.attr_address(&unit, low_pc_attr)? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code originated from the dwarfdump example (a5c7ac0) and the strategy there was to be able to dump as much as we can, even if it is potentially invalid.

I agree that ideally we would return an error, and this would help expose bugs more quickly. On the other hand not all consumers need everything that this function parses. For example, #515 was fine with ignoring errors instead of fixing the real problem (missing supplementary object file).

I don't know the best way to handle this. Do you have any ideas?

@philipc philipc merged commit 8c5a7ab into gimli-rs:master Jan 2, 2021
@RReverser
Copy link
Contributor Author

Could you please publish a patch release for this fix? For now I'm pointing to my Github fork with [patch.crates-io], but I'd like to change that.

@philipc
Copy link
Collaborator

philipc commented Jan 3, 2021

I can't because there's already breaking changes on master, and in any case I'd prefer to wait a bit to be sure you don't need more fixes.

@RReverser
Copy link
Contributor Author

Ah okay. So far this is the only thing I ran into, I don't think I'll need anything else on Gimli side in the nearest future, but I guess makes sense to wait.

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.

Dwarf::{unit_ranges, die_ranges} doesn't handle DW_FORM_addrx
2 participants