mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 19:17:43 +00:00
Auto merge of #79002 - est31:backtrace_colno, r=dtolnay
Add column number support to Backtrace Backtrace frames might include column numbers. Print them if they are included.
This commit is contained in:
commit
bf469eb6c2
@ -161,6 +161,7 @@ struct BacktraceSymbol {
|
|||||||
name: Option<Vec<u8>>,
|
name: Option<Vec<u8>>,
|
||||||
filename: Option<BytesOrWide>,
|
filename: Option<BytesOrWide>,
|
||||||
lineno: Option<u32>,
|
lineno: Option<u32>,
|
||||||
|
colno: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BytesOrWide {
|
enum BytesOrWide {
|
||||||
@ -197,6 +198,10 @@ impl fmt::Debug for Backtrace {
|
|||||||
|
|
||||||
impl fmt::Debug for BacktraceSymbol {
|
impl fmt::Debug for BacktraceSymbol {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
// FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280
|
||||||
|
// FIXME: Also, include column numbers into the debug format as Display already has them.
|
||||||
|
// Until there are stable per-frame accessors, the format shouldn't be changed:
|
||||||
|
// https://github.com/rust-lang/rust/issues/65280#issuecomment-638966585
|
||||||
write!(fmt, "{{ ")?;
|
write!(fmt, "{{ ")?;
|
||||||
|
|
||||||
if let Some(fn_name) = self.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)) {
|
if let Some(fn_name) = self.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)) {
|
||||||
@ -209,7 +214,7 @@ impl fmt::Debug for BacktraceSymbol {
|
|||||||
write!(fmt, ", file: \"{:?}\"", fname)?;
|
write!(fmt, ", file: \"{:?}\"", fname)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(line) = self.lineno.as_ref() {
|
if let Some(line) = self.lineno {
|
||||||
write!(fmt, ", line: {:?}", line)?;
|
write!(fmt, ", line: {:?}", line)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +386,7 @@ impl fmt::Display for Backtrace {
|
|||||||
f.print_raw(frame.frame.ip(), None, None, None)?;
|
f.print_raw(frame.frame.ip(), None, None, None)?;
|
||||||
} else {
|
} else {
|
||||||
for symbol in frame.symbols.iter() {
|
for symbol in frame.symbols.iter() {
|
||||||
f.print_raw(
|
f.print_raw_with_column(
|
||||||
frame.frame.ip(),
|
frame.frame.ip(),
|
||||||
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
|
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
|
||||||
symbol.filename.as_ref().map(|b| match b {
|
symbol.filename.as_ref().map(|b| match b {
|
||||||
@ -389,6 +394,7 @@ impl fmt::Display for Backtrace {
|
|||||||
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
|
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
|
||||||
}),
|
}),
|
||||||
symbol.lineno,
|
symbol.lineno,
|
||||||
|
symbol.colno,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,6 +433,7 @@ impl Capture {
|
|||||||
BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()),
|
BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()),
|
||||||
}),
|
}),
|
||||||
lineno: symbol.lineno(),
|
lineno: symbol.lineno(),
|
||||||
|
colno: symbol.colno(),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ fn test_debug() {
|
|||||||
name: Some(b"std::backtrace::Backtrace::create".to_vec()),
|
name: Some(b"std::backtrace::Backtrace::create".to_vec()),
|
||||||
filename: Some(BytesOrWide::Bytes(b"rust/backtrace.rs".to_vec())),
|
filename: Some(BytesOrWide::Bytes(b"rust/backtrace.rs".to_vec())),
|
||||||
lineno: Some(100),
|
lineno: Some(100),
|
||||||
|
colno: None,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
BacktraceFrame {
|
BacktraceFrame {
|
||||||
@ -21,6 +22,7 @@ fn test_debug() {
|
|||||||
name: Some(b"__rust_maybe_catch_panic".to_vec()),
|
name: Some(b"__rust_maybe_catch_panic".to_vec()),
|
||||||
filename: None,
|
filename: None,
|
||||||
lineno: None,
|
lineno: None,
|
||||||
|
colno: None,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
BacktraceFrame {
|
BacktraceFrame {
|
||||||
@ -30,11 +32,13 @@ fn test_debug() {
|
|||||||
name: Some(b"std::rt::lang_start_internal".to_vec()),
|
name: Some(b"std::rt::lang_start_internal".to_vec()),
|
||||||
filename: Some(BytesOrWide::Bytes(b"rust/rt.rs".to_vec())),
|
filename: Some(BytesOrWide::Bytes(b"rust/rt.rs".to_vec())),
|
||||||
lineno: Some(300),
|
lineno: Some(300),
|
||||||
|
colno: Some(5),
|
||||||
},
|
},
|
||||||
BacktraceSymbol {
|
BacktraceSymbol {
|
||||||
name: Some(b"std::rt::lang_start".to_vec()),
|
name: Some(b"std::rt::lang_start".to_vec()),
|
||||||
filename: Some(BytesOrWide::Bytes(b"rust/rt.rs".to_vec())),
|
filename: Some(BytesOrWide::Bytes(b"rust/rt.rs".to_vec())),
|
||||||
lineno: Some(400),
|
lineno: Some(400),
|
||||||
|
colno: None,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user