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

Printing backtrace ip for x86_64-fortanix-unknown-sgx #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#![deny(missing_docs)]
#![no_std]
#![cfg_attr(
all(feature = "std", target_env = "sgx", target_vendor = "fortanix"),
all(target_env = "sgx", target_vendor = "fortanix"),
feature(sgx_platform)
)]
#![allow(bare_trait_objects)] // TODO: remove when updating to 2018 edition
Expand Down
10 changes: 7 additions & 3 deletions src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ impl BacktraceFrameFmt<'_, '_, '_> {
filename: Option<BytesOrWideString>,
lineno: Option<u32>,
) -> fmt::Result {
let mut print_frame_ip = PrintFmt::Full == self.fmt.format;

// No need to print "null" frames, it basically just means that the
// system backtrace was a bit eager to trace back super far.
if let PrintFmt::Short = self.fmt.format {
Expand All @@ -196,30 +198,32 @@ impl BacktraceFrameFmt<'_, '_, '_> {
// To reduce TCB size in Sgx enclave, we do not want to implement symbol
// resolution functionality. Rather, we can print the offset of the
// address here, which could be later mapped to correct function.
#[cfg(all(feature = "std", target_env = "sgx", target_vendor = "fortanix"))]
Copy link
Member

Choose a reason for hiding this comment

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

I think the removal of this feature directive will break this building when included into libstd?

#[cfg(all(target_env = "sgx", target_vendor = "fortanix"))]
{
let image_base = std::os::fortanix_sgx::mem::image_base();
frame_ip = usize::wrapping_sub(frame_ip as usize, image_base as _) as _;
print_frame_ip = true;
}

// Print the index of the frame as well as the optional instruction
// pointer of the frame. If we're beyond the first symbol of this frame
// though we just print appropriate whitespace.
if self.symbol_index == 0 {
write!(self.fmt.fmt, "{:4}: ", self.fmt.frame_index)?;
if let PrintFmt::Full = self.fmt.format {
if print_frame_ip {
write!(self.fmt.fmt, "{:1$?} - ", frame_ip, HEX_WIDTH)?;
}
} else {
write!(self.fmt.fmt, " ")?;
if let PrintFmt::Full = self.fmt.format {
if print_frame_ip {
write!(self.fmt.fmt, "{:1$}", "", HEX_WIDTH + 3)?;
}
}

// Next up write out the symbol name, using the alternate formatting for
// more information if we're a full backtrace. Here we also handle
// symbols which don't have a name,
#[cfg(not(all(target_env = "sgx", target_vendor = "fortanix")))]
Copy link
Member

Choose a reason for hiding this comment

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

Could this use an if instead of using an attribute?

match (symbol_name, &self.fmt.format) {
(Some(name), PrintFmt::Short) => write!(self.fmt.fmt, "{:#}", name)?,
(Some(name), PrintFmt::Full) => write!(self.fmt.fmt, "{}", name)?,
Expand Down