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

Report more specific errors for unknown constants #714

Merged
merged 2 commits into from
May 23, 2024

Conversation

jameysharp
Copy link
Contributor

In case someone encounters some DWARF containing a constant value not known to gimli, let's ensure that the error has the actual constant available in it.

These values are not visible in Error::description or the various other error-reporting functions which use it, such as the Display implementation. I think it would be good to improve that too, but wanted to keep this PR relatively small.

In case someone encounters some DWARF containing a constant value not
known to gimli, let's ensure that the error has the actual constant
available in it.

These values are not visible in `Error::description` or the various
other error-reporting functions which use it, such as the `Display`
implementation. I think it would be good to improve that too, but wanted
to keep this PR relatively small.
src/read/cfi.rs Outdated Show resolved Hide resolved
src/read/cfi.rs Outdated Show resolved Hide resolved
@@ -1048,7 +1048,7 @@ impl<R: Reader> DwarfPackage<R> {
SectionId::DebugMacro | SectionId::DebugMacinfo => {
// These are valid but we can't parse these yet.
}
_ => return Err(Error::UnknownIndexSection),
_ => return Err(Error::UnknownSection(section.section)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine, I don't think there's a better option, but it feels a bit dirty to add an error variant for a code path that will only occur due to a bug in gimli.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be better to introduce a new enum IndexSectionId which has only the kinds that are allowed in a UnitIndex?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe. It would avoid this possibility, and most consumers won't be directly using this section id so it won't affect them. Something for another PR though. I'd probably call it DwoSectionId.

src/read/loclists.rs Outdated Show resolved Hide resolved
src/read/mod.rs Outdated Show resolved Hide resolved
src/read/rnglists.rs Outdated Show resolved Hide resolved
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!

@philipc philipc merged commit 0fe475c into gimli-rs:master May 23, 2024
20 checks passed
@jameysharp jameysharp deleted the better-errors branch May 23, 2024 16:48
jameysharp added a commit to jameysharp/gimli that referenced this pull request May 24, 2024
Keeping this type distinct from the `SectionId` enum ensures that the
compiler will report an error if someone adds incomplete support for new
separate-debug sections.

As discussed in:
gimli-rs#714 (comment)

The existing `SectionId::dwo_name` method did not match the list of
sections actually supported elsewhere in gimli. I've added the one
section ID that was missing (`.debug_macinfo.dwo`), but I have not
removed the section IDs which are only present there: `.debug_str.dwo`,
`.debug_cu_index`, and `.debug_tu_index`.
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.

2 participants