Skip to content

Commit 016146d

Browse files
committed
Add column number support to Backtrace
Backtrace frames might include column numbers. Print them if they are included.
1 parent f7801d6 commit 016146d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

library/std/src/backtrace.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ struct BacktraceSymbol {
161161
name: Option<Vec<u8>>,
162162
filename: Option<BytesOrWide>,
163163
lineno: Option<u32>,
164+
colno: Option<u32>,
164165
}
165166

166167
enum BytesOrWide {
@@ -209,7 +210,7 @@ impl fmt::Debug for BacktraceSymbol {
209210
write!(fmt, ", file: \"{:?}\"", fname)?;
210211
}
211212

212-
if let Some(line) = self.lineno.as_ref() {
213+
if let Some(line) = self.lineno {
213214
write!(fmt, ", line: {:?}", line)?;
214215
}
215216

@@ -381,14 +382,15 @@ impl fmt::Display for Backtrace {
381382
f.print_raw(frame.frame.ip(), None, None, None)?;
382383
} else {
383384
for symbol in frame.symbols.iter() {
384-
f.print_raw(
385+
f.print_raw_with_column(
385386
frame.frame.ip(),
386387
symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)),
387388
symbol.filename.as_ref().map(|b| match b {
388389
BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
389390
BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
390391
}),
391392
symbol.lineno,
393+
symbol.colno,
392394
)?;
393395
}
394396
}
@@ -427,6 +429,7 @@ impl Capture {
427429
BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()),
428430
}),
429431
lineno: symbol.lineno(),
432+
colno: symbol.colno(),
430433
});
431434
});
432435
}

library/std/src/backtrace/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn test_debug() {
1313
name: Some(b"std::backtrace::Backtrace::create".to_vec()),
1414
filename: Some(BytesOrWide::Bytes(b"rust/backtrace.rs".to_vec())),
1515
lineno: Some(100),
16+
colno: None,
1617
}],
1718
},
1819
BacktraceFrame {
@@ -21,6 +22,7 @@ fn test_debug() {
2122
name: Some(b"__rust_maybe_catch_panic".to_vec()),
2223
filename: None,
2324
lineno: None,
25+
colno: None,
2426
}],
2527
},
2628
BacktraceFrame {
@@ -30,11 +32,13 @@ fn test_debug() {
3032
name: Some(b"std::rt::lang_start_internal".to_vec()),
3133
filename: Some(BytesOrWide::Bytes(b"rust/rt.rs".to_vec())),
3234
lineno: Some(300),
35+
colno: Some(5),
3336
},
3437
BacktraceSymbol {
3538
name: Some(b"std::rt::lang_start".to_vec()),
3639
filename: Some(BytesOrWide::Bytes(b"rust/rt.rs".to_vec())),
3740
lineno: Some(400),
41+
colno: None,
3842
},
3943
],
4044
},

0 commit comments

Comments
 (0)