-
Notifications
You must be signed in to change notification settings - Fork 109
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 the ability to dump specific DIEs with --debug-info=0xdeadbeef. #564
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -353,6 +353,7 @@ struct Flags { | |
eh_frame: bool, | ||
goff: bool, | ||
info: bool, | ||
info_offset: Option<gimli::DebugInfoOffset>, | ||
line: bool, | ||
pubnames: bool, | ||
pubtypes: bool, | ||
|
@@ -386,7 +387,12 @@ fn main() { | |
"print .eh-frame exception handling frame information", | ||
); | ||
opts.optflag("G", "", "show global die offsets"); | ||
opts.optflag("i", "", "print .debug_info and .debug_types sections"); | ||
opts.optflagopt( | ||
"i", | ||
"debug-info", | ||
"print .debug_info and .debug_types sections", | ||
"offset", | ||
); | ||
opts.optflag("l", "", "print .debug_line section"); | ||
opts.optflag("p", "", "print .debug_pubnames section"); | ||
opts.optflag("r", "", "print .debug_aranges section"); | ||
|
@@ -427,6 +433,24 @@ fn main() { | |
} | ||
if matches.opt_present("i") { | ||
flags.info = true; | ||
if let Some(offset) = matches.opt_str("i") { | ||
let offset = match offset | ||
.get(2..) | ||
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. Would be nice if the 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. My primary concern was that we were skipping the first two characters without checking what they were. |
||
.and_then(|o| usize::from_str_radix(o, 16).ok()) | ||
{ | ||
Some(offset) => offset, | ||
None => { | ||
writeln!( | ||
&mut io::stderr(), | ||
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. Use |
||
"Could not parse offset argument '{}'", | ||
offset | ||
) | ||
.ok(); | ||
print_usage(&opts); | ||
} | ||
}; | ||
flags.info_offset = Some(gimli::DebugInfoOffset(offset)); | ||
} | ||
all = false; | ||
} | ||
if matches.opt_present("l") { | ||
|
@@ -970,30 +994,37 @@ where | |
} | ||
}; | ||
let process_unit = |header: UnitHeader<R>, buf: &mut Vec<u8>| -> Result<()> { | ||
writeln!( | ||
buf, | ||
"\nUNIT<header overall offset = 0x{:08x}>:", | ||
header.offset().as_debug_info_offset().unwrap().0, | ||
)?; | ||
let header_offset = header.offset().as_debug_info_offset().unwrap(); | ||
if flags | ||
.info_offset | ||
.map(|o| o == header_offset) | ||
.unwrap_or(true) | ||
{ | ||
writeln!( | ||
buf, | ||
"\nUNIT<header overall offset = 0x{:08x}>:", | ||
header_offset.0, | ||
)?; | ||
|
||
match header.type_() { | ||
UnitType::Compilation | UnitType::Partial => (), | ||
UnitType::Type { | ||
type_signature, | ||
type_offset, | ||
} | ||
| UnitType::SplitType { | ||
type_signature, | ||
type_offset, | ||
} => { | ||
write!(buf, " signature = ")?; | ||
dump_type_signature(buf, type_signature)?; | ||
writeln!(buf)?; | ||
writeln!(buf, " typeoffset = 0x{:08x}", type_offset.0,)?; | ||
} | ||
UnitType::Skeleton(dwo_id) | UnitType::SplitCompilation(dwo_id) => { | ||
write!(buf, " dwo_id = ")?; | ||
writeln!(buf, "0x{:016x}", dwo_id.0)?; | ||
match header.type_() { | ||
UnitType::Compilation | UnitType::Partial => (), | ||
UnitType::Type { | ||
type_signature, | ||
type_offset, | ||
} | ||
| UnitType::SplitType { | ||
type_signature, | ||
type_offset, | ||
} => { | ||
write!(buf, " signature = ")?; | ||
dump_type_signature(buf, type_signature)?; | ||
writeln!(buf)?; | ||
writeln!(buf, " typeoffset = 0x{:08x}", type_offset.0,)?; | ||
} | ||
UnitType::Skeleton(dwo_id) | UnitType::SplitCompilation(dwo_id) => { | ||
write!(buf, " dwo_id = ")?; | ||
writeln!(buf, "0x{:016x}", dwo_id.0)?; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1102,9 +1133,22 @@ fn dump_entries<R: Reader, W: Write>( | |
let mut spaces_buf = String::new(); | ||
|
||
let mut depth = 0; | ||
let mut processing_subtree = false; | ||
let mut entries = unit.entries(); | ||
while let Some((delta_depth, entry)) = entries.next_dfs()? { | ||
depth += delta_depth; | ||
if let Some(o) = flags.info_offset { | ||
if o == entry.offset().to_debug_info_offset(&unit.header).unwrap() { | ||
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. This will panic if there is a |
||
processing_subtree = true; | ||
depth = 0; | ||
} else if processing_subtree == true { | ||
if depth <= 0 { | ||
break; | ||
} | ||
} else { | ||
continue; | ||
} | ||
} | ||
assert!(depth >= 0); | ||
let mut indent = depth as usize * 2 + 2; | ||
write!(w, "<{}{}>", if depth < 10 { " " } else { "" }, depth)?; | ||
|
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 don't think
optflagopt
is a good choice. Previously you could dodwarfdump -i filename
but now that doesn't work.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.
So what should we do instead?
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.
dwarfdump -i -- filename
works but yeah that's not ideal.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.
How about
-o
/--offset
?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 guess we could do that, though the reason I chose this was to match
llvm-dwarfdump
.Maybe we should switch to
structopt
instead. I think it can be made to do the right thing here.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.
Ah okay, yeah matching
llvm-dwarfdump
would be good (llvm-dwarfdump --help
didn't show that option). If you want, can leave this how it is and switch later.