-
Notifications
You must be signed in to change notification settings - Fork 150
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 some methods useful for locating debug symbols #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#![deny(missing_debug_implementations)] | ||
|
||
extern crate goblin; | ||
extern crate uuid; | ||
|
||
use std::fmt; | ||
use std::io::Cursor; | ||
|
@@ -25,6 +26,8 @@ pub use pe::*; | |
mod traits; | ||
pub use traits::*; | ||
|
||
pub use uuid::Uuid; | ||
|
||
/// An object file. | ||
#[derive(Debug)] | ||
pub struct File<'data> { | ||
|
@@ -54,6 +57,13 @@ pub enum Machine { | |
X86_64, | ||
} | ||
|
||
/// Information from an object file that can be used to locate separate debug info. | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum DebugFileInfo { | ||
/// The UUID from a Mach-O `LC_UUID` load command. | ||
MachOUuid(Uuid), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it makes sense to have this be an associated type of the trait, something like: impl Object for MachOFile {
type DebugFileInfo = Uuid;
fn get_debug_file_info(&self) -> Option<Uuid> { ... }
} And then when we add support for For object files that don't have separate debug info, or we haven't implemented it yet, then we can use Thoughts on this approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that returning an associated type is enough. The goal of the Maybe the API should instead be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets a little twisty, certainly. I wasn't sure which way the dependency ought to go, just that I wanted a straightforward API for users. Having the APIs in The other way we can go with this is to provide a method on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that exposing We do want to keep object dependencies simple. Even if we added |
||
} | ||
|
||
/// An iterator over the segments of a `File`. | ||
#[derive(Debug)] | ||
pub struct SegmentIterator<'data, 'file> | ||
|
@@ -318,6 +328,14 @@ where | |
fn is_little_endian(&self) -> bool { | ||
with_inner!(self.inner, FileInternal, |x| x.is_little_endian()) | ||
} | ||
|
||
fn has_debug_symbols(&self) -> bool { | ||
with_inner!(self.inner, FileInternal, |x| x.has_debug_symbols()) | ||
} | ||
|
||
fn debug_file_info(&self) -> Option<DebugFileInfo> { | ||
with_inner!(self.inner, FileInternal, |x| x.debug_file_info()) | ||
} | ||
} | ||
|
||
impl<'data, 'file> Iterator for SegmentIterator<'data, 'file> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ use std::borrow; | |
|
||
use goblin::pe; | ||
|
||
use {Machine, Object, ObjectSection, ObjectSegment, SectionKind, Symbol, SymbolKind, SymbolMap}; | ||
use {DebugFileInfo, Machine, Object, ObjectSection, ObjectSegment, SectionKind, Symbol, SymbolKind, | ||
SymbolMap}; | ||
|
||
/// A PE object file. | ||
#[derive(Debug)] | ||
|
@@ -152,6 +153,15 @@ where | |
// characteristics flags, but these are obsolete. | ||
true | ||
} | ||
|
||
#[inline] | ||
fn has_debug_symbols(&self) -> bool { | ||
// TODO: look at what the mingw toolchain does with DWARF-in-PE, and also | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File a follow-up investigation issue and link it here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed #40 |
||
// whether CodeView-in-PE still works? | ||
false | ||
} | ||
|
||
fn debug_file_info(&self) -> Option<DebugFileInfo> { None } | ||
} | ||
|
||
impl<'data, 'file> Iterator for PeSegmentIterator<'data, 'file> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not confident that this is correct. What if the file was generated with
.debug_line
only? What's the intended use for this? Should calllers only look for.gnu_debuglink
if this returns false? I think it might be better to always use.gnu_debuglink
if it exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually,
.debug_info
exists even with-C debuginfo=1
. Still might be better to always check for.gnu_debuglink
though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure, honestly, except that
.debug_info
is a pretty strong signal. Callingstrip
on a binary will definitely remove.debug_info
by default. This is mostly intended as a check for "can I load debug info from this binary, or do I need to look for an external symbol file?"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also gdb "mini debug info" to consider: https://sourceware.org/gdb/onlinedocs/gdb/MiniDebugInfo.html#MiniDebugInfo
With this an executable might contain some minimal info (line table) but more data might be available elsewhere. gdb looks for direct debug info first; then tries separate debuginfo; then falls back to minidebug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following whatever gdb does here is probably the best bet for compatibility's sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine then.