Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
40 changes: 39 additions & 1 deletion library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ enum RawFrame {
Fake,
}

struct BacktraceSymbol {
/// A single symbol associated with a backtrace frame, which may include a
/// function name, filename, line number, and column number.
#[unstable(feature = "backtrace_internals_accessors", issue = "122899")]
pub struct BacktraceSymbol {
name: Option<Vec<u8>>,
filename: Option<BytesOrWide>,
lineno: Option<u32>,
Expand Down Expand Up @@ -207,6 +210,41 @@ impl fmt::Debug for BacktraceFrame {
}
}

///NOTE: This is never intended to become stable. It doesn't have an ACP
/// Its meant to help us port the tests mentioned in issue #122899
#[unstable(feature = "backtrace_internals_accessors", issue = "122899")]
impl BacktraceFrame {
/// Returns the instruction pointer associated with this frame.
pub fn ip(&self) -> *mut c_void {
self.frame.ip()
}

/// Returns the symbols associated with this frame, if any.
pub fn symbols(&self) -> &[BacktraceSymbol] {
&self.symbols
}

/// Returns the base address of the module this frame belongs to, if available.
pub fn module_base_address(&self) -> Option<*mut c_void> {
match &self.frame {
RawFrame::Actual(frame) => frame.module_base_address(),
#[cfg(test)]
RawFrame::Fake => None,
}
}
}

///NOTE: This is never intended to become stable. It doesn't have an ACP
/// Its meant to help us port the tests mentioned in issue #122899
impl BacktraceSymbol {
/// Returns the name of this symbol, if available.
#[unstable(feature = "backtrace_internals_accessors", issue = "122899")]
pub fn name(&self) -> Option<&[u8]> {
self.name.as_deref()
}
}

#[unstable(feature = "backtrace_internals_accessors", issue = "122899")]
impl fmt::Debug for BacktraceSymbol {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
// FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280
Expand Down
18 changes: 11 additions & 7 deletions tests/ui/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# UI Test Suite Categories

This is a high-level summary of the organization of the UI test suite (`tests/ui/`). It is not intended to be *prescriptive*, but instead provide a quick survey of existing groupings.
This is a high-level summary of the organization of the UI test suite (`tests/ui/`). It is not intended to be _prescriptive_, but instead provide a quick survey of existing groupings.

For now, only immediate subdirectories under `tests/ui/` are described, but these subdirectories can themselves include a `SUMMARY.md` to further describe their own organization and intent, should that be helpful.

## `tests/ui/abi`

These tests deal with *Application Binary Interfaces* (ABI), mostly relating to function name mangling (and the `#[no_mangle]` attribute), calling conventions, or compiler flags which affect ABI.
These tests deal with _Application Binary Interfaces_ (ABI), mostly relating to function name mangling (and the `#[no_mangle]` attribute), calling conventions, or compiler flags which affect ABI.

Tests for unsupported ABIs can be made cross-platform by using the `extern "rust-invalid"` ABI, which is considered unsupported on every platform.

Expand Down Expand Up @@ -198,13 +198,13 @@ See [Conditional compilation | Reference](https://doc.rust-lang.org/reference/co

## `tests/ui/check-cfg/`: Configuration Checks

Tests for the `--check-cfg` compiler mechanism for checking cfg configurations, for `#[cfg(..)]` and `cfg!(..)`.
Tests for the `--check-cfg` compiler mechanism for checking cfg configurations, for `#[cfg(..)]` and `cfg!(..)`.
Comment thread
JayanAXHF marked this conversation as resolved.
Outdated

See [Checking conditional configurations | The rustc book](https://doc.rust-lang.org/rustc/check-cfg.html).

## `tests/ui/closure-expected-type/`: Closure type inference

Tests targeted at how we deduce the types of closure arguments. This process is a result of some heuristics which take into account the *expected type* we have alongside the *actual types* that we get from inputs.
Tests targeted at how we deduce the types of closure arguments. This process is a result of some heuristics which take into account the _expected type_ we have alongside the _actual types_ that we get from inputs.

**FIXME**: Appears to have significant overlap with `tests/ui/closure_context` and `tests/ui/functions-closures/closure-expected-type`. Needs further investigation.

Expand Down Expand Up @@ -272,7 +272,7 @@ This directory is actually for the standard library [`std::process::Command`](ht

Some traits' implementation must be compared with their definition, checking for problems such as the implementation having stricter requirements (such as needing to implement `Copy`).

This subdirectory is *not* intended comparison traits (`PartialEq`, `Eq`, `PartialOrd`, `Ord`).
This subdirectory is _not_ intended comparison traits (`PartialEq`, `Eq`, `PartialOrd`, `Ord`).

## `tests/ui/compile-flags/`

Expand Down Expand Up @@ -885,7 +885,7 @@ Tests on [AST lowering](https://rustc-dev-guide.rust-lang.org/ast-lowering.html)

## `tests/ui/lto/`

Exercise *Link-Time Optimization* (LTO), involving the flags `-C lto` or `-Z thinlto`.
Exercise _Link-Time Optimization_ (LTO), involving the flags `-C lto` or `-Z thinlto`.

## `tests/ui/lub-glb/`: LUB/GLB algorithm update

Expand Down Expand Up @@ -973,6 +973,10 @@ See [RFC 3550 New Range](https://github.com/rust-lang/rfcs/blob/master/text/3550

Tests for Non-lexical lifetimes. See [RFC 2094 NLL](https://rust-lang.github.io/rfcs/2094-nll.html).

## `tests/ui/no_debuginfo`: without_debuginfo test ported from backtrace-rs

Tests for behavior when debug information is not available, ported from `backtrace-rs`'s `without_debuginfo` crate's test.

## `tests/ui/no_std/`

Tests for where the standard library is disabled through `#![no_std]`.
Expand Down Expand Up @@ -1368,7 +1372,7 @@ Generic collection of tests for suggestions, when no more specific directories a

## `tests/ui/svh/`: Strict Version Hash

Tests on the *Strict Version Hash* (SVH, also known as the "crate hash").
Tests on the _Strict Version Hash_ (SVH, also known as the "crate hash").

See [Strict Version Hash](https://rustc-dev-guide.rust-lang.org/backend/libs-and-metadata.html#strict-version-hash).

Expand Down
20 changes: 20 additions & 0 deletions tests/ui/no_debuginfo/all_frames_have_module_base_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ compile-flags: -Cstrip=none -Cdebuginfo=none
//@ run-pass
#![feature(backtrace_frames)]
#![feature(backtrace_internals_accessors)]
use std::backtrace;

fn main() {
let mut missing_base_addresses = 0;
let btrace = backtrace::Backtrace::force_capture();
let frames = btrace.frames();
for frame in frames {
if frame.module_base_address().is_none() {
missing_base_addresses += 1;
}
}

if cfg!(windows) {
assert_eq!(missing_base_addresses, 0);
}
}
33 changes: 33 additions & 0 deletions tests/ui/no_debuginfo/all_frames_have_symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@ compile-flags: -Cstrip=none -Cdebuginfo=none
//@ run-pass
#![feature(backtrace_frames)]
#![feature(backtrace_internals_accessors)]
use std::backtrace;
fn main() {
let mut missing_symbols = 0;
let mut has_symbols = 0;
let btrace = backtrace::Backtrace::force_capture();
let frames = btrace.frames();
for frame in frames {
let mut any = false;
for sym in frame.symbols() {
if sym.name().is_some() {
any = true;
break;
}
}
if any {
has_symbols += 1;
} else if !frame.ip().is_null() {
missing_symbols += 1;
}
}

// FIXME(#346) currently on MinGW we can't symbolize kernel32.dll and other
// system libraries, which means we miss the last few symbols.
if cfg!(windows) && cfg!(target_env = "gnu") {
assert!(missing_symbols < has_symbols && has_symbols > 4);
} else {
assert_eq!(missing_symbols, 0);
}
Comment on lines +6 to +43

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't a known problem, so we may need to determine how many frames are missing symbols and it may be aarch64-unknown-linux-gnu specific.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well it doesn't occur on my arm m2 mac so maybe it's specific? Might wanna check windows too to determine if it's x86

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Huuuh.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oops I misread the target. Do you mind if I rerun the CI for x86 Linux to try to repro the problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@workingjubilee I added some debug info to try to find the frame with the missing info. Also could #152870 be relevant to this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's unclear in the current state to which "known problem" this discussion is referring to. Is it about __libc_start_main one?

I don't see how #152870 would be relevant in that context.

}
Loading