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

feat(gstd): get panic message without panic_info_message #3527

Merged
merged 46 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
409e33b
feat(gstd): get panic message without `panic_info_message`
StackOverflowExcept1on Nov 27, 2023
bab3417
keep feature
StackOverflowExcept1on Nov 27, 2023
90dd7b8
[ci-skip] inline var
StackOverflowExcept1on Nov 27, 2023
b00d583
re-implement panic handler with arrayvec
StackOverflowExcept1on Nov 29, 2023
388492c
add common-handlers feature and document panic_handler
StackOverflowExcept1on Dec 1, 2023
76ba81b
fix fmt
StackOverflowExcept1on Dec 1, 2023
bdd77ae
add some notes
StackOverflowExcept1on Dec 1, 2023
89dbf0f
[skip-ci] use try_push_str bcz it doesn't encodes char as utf8
StackOverflowExcept1on Dec 1, 2023
4aa5f52
make binary x2.2 smaller on nightly
StackOverflowExcept1on Dec 8, 2023
61cb641
[skip-ci] remove core::
StackOverflowExcept1on Dec 8, 2023
e09cc5f
[skip-ci] use array syntax for MaybeUninit
StackOverflowExcept1on Dec 12, 2023
ee01ee3
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Dec 13, 2023
b23ab7b
apply suggestion
StackOverflowExcept1on Dec 13, 2023
9b2b9ad
add safety comments
StackOverflowExcept1on Dec 13, 2023
66be25d
simulate write! macro with for loop
StackOverflowExcept1on Dec 13, 2023
14ab4d5
add extra space for single quotes
StackOverflowExcept1on Dec 13, 2023
8e354c4
trying to fix ci
StackOverflowExcept1on Dec 13, 2023
f7e459b
fix some clippy lint and use other approach for rust >=1.73
StackOverflowExcept1on Dec 15, 2023
9420d8f
remove most unsafe code
StackOverflowExcept1on Dec 26, 2023
c1608f0
completely get rid of unsafe code
StackOverflowExcept1on Dec 26, 2023
b960e3f
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Dec 26, 2023
3297392
match result of get
StackOverflowExcept1on Dec 26, 2023
461b196
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Jan 10, 2024
eab5a5d
split debug and panic handler
StackOverflowExcept1on Jan 11, 2024
d1bd563
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Jan 11, 2024
6a4f82b
keep old msg format
StackOverflowExcept1on Jan 11, 2024
f14edfe
gr_debug is still needed for gtest
StackOverflowExcept1on Jan 12, 2024
e236195
[skip-ci] fix doc
StackOverflowExcept1on Jan 12, 2024
e703d8e
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Jan 12, 2024
9d99503
simplify location/not location
StackOverflowExcept1on Jan 12, 2024
63a341b
nightly -> panic-info-message
StackOverflowExcept1on Jan 12, 2024
2036f5b
move cfg(feature = panic-handler) near the it's module
StackOverflowExcept1on Jan 12, 2024
fbeaefc
no info -> <unknown>
StackOverflowExcept1on Jan 13, 2024
4320ac0
[skip-ci] add dot
StackOverflowExcept1on Jan 13, 2024
ed77410
[skip-ci] move doc comment below
StackOverflowExcept1on Jan 13, 2024
c4a42f9
doc test -> #[test]
StackOverflowExcept1on Jan 14, 2024
2df8095
rework panic handler
StackOverflowExcept1on Jan 15, 2024
d093863
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Jan 15, 2024
63a178b
fix ci
StackOverflowExcept1on Jan 15, 2024
9bb3525
fix assert_panicked
StackOverflowExcept1on Jan 15, 2024
f2759d1
[skip-ci] replace .starts_with with .contains in gtest::tests
StackOverflowExcept1on Jan 15, 2024
7049548
just use TRIMMED_MAX_LEN
StackOverflowExcept1on Jan 15, 2024
a9d9c3f
better docs
StackOverflowExcept1on Jan 15, 2024
ced5651
resolve some conversations
StackOverflowExcept1on Jan 15, 2024
20521e7
[skip-ci] add doc about `panic-location`
StackOverflowExcept1on Jan 16, 2024
d318147
Merge remote-tracking branch 'origin/master' into av/gstd-panic-msg
StackOverflowExcept1on Jan 16, 2024
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ gcore = { path = "gcore" }
gcli = { path = "gcli" }
gclient = { path = "gclient" }
gsdk = { path = "gsdk" }
gstd = { path = "gstd", features = [ "nightly" ] }
gstd = { path = "gstd", features = ["nightly"] }
gsys = { path = "gsys" }
gtest = { path = "gtest" }
gmeta = { path = "gmeta" }
Expand Down
61 changes: 47 additions & 14 deletions gstd/src/common/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,18 @@ mod panic_handler {
ext::panic("no info")
}

/// Panic handler for nightly Rust.
#[cfg(feature = "debug")]
#[cfg(feature = "panic-messages")]
#[panic_handler]
pub fn panic(panic_info: &PanicInfo) -> ! {
use crate::prelude::format;
#[cfg(not(feature = "panic-messages"))]
let message = None::<&core::fmt::Arguments<'_>>;
#[cfg(feature = "panic-messages")]
let message = panic_info.message();

let msg = match (message, panic_info.location()) {
(Some(msg), Some(loc)) => format!(
"'{:?}', {}:{}:{}",
msg,
loc.file(),
loc.line(),
loc.column()
),
(Some(msg), None) => format!("'{msg:?}'"),

let msg = match (panic_info.message(), panic_info.location()) {
(Some(msg), Some(loc)) => {
format!("'{msg}', {}:{}:{}", loc.file(), loc.line(), loc.column())
}
(Some(msg), None) => format!("'{msg}'"),
(None, Some(loc)) => {
format!("{}:{}:{}", loc.file(), loc.line(), loc.column())
}
Expand All @@ -69,6 +63,45 @@ mod panic_handler {
crate::debug!("panic occurred: {msg}");
ext::panic(&msg)
}

/// Panic handler for stable Rust.
#[cfg(feature = "debug")]
#[cfg(not(feature = "panic-messages"))]
#[panic_handler]
pub fn panic(panic_info: &PanicInfo) -> ! {
use crate::prelude::{borrow::Cow, format, ToString};
StackOverflowExcept1on marked this conversation as resolved.
Show resolved Hide resolved

// Default panic handler message format:
// Rust <1.73: `panicked at '{message}', {location}`
// Rust >=1.73: `panicked at {location}:\n{message}`
// source: https://github.com/rust-lang/rust/pull/112849

const PANICKED_AT_LEN: usize = "panicked at ".len();

let default_panic_msg = panic_info.to_string();
let is_old_panic_format = default_panic_msg.as_bytes().get(PANICKED_AT_LEN) == Some(&b'\'');
StackOverflowExcept1on marked this conversation as resolved.
Show resolved Hide resolved

let maybe_panic_msg = if is_old_panic_format {
default_panic_msg.get(PANICKED_AT_LEN..).map(Cow::Borrowed)
} else {
let mut iter = default_panic_msg.splitn(2, ":\n");
iter.next().zip(iter.next()).and_then(|(line1, line2)| {
let msg = line2;
line1
.get(PANICKED_AT_LEN..line1.len())
StackOverflowExcept1on marked this conversation as resolved.
Show resolved Hide resolved
.map(|location| Cow::Owned(format!("'{msg}', {location}")))
StackOverflowExcept1on marked this conversation as resolved.
Show resolved Hide resolved
})
};

if let Some(ref panic_msg) = maybe_panic_msg {
let msg = panic_msg.as_ref();

crate::debug!("panic occurred: {msg}");
ext::panic(msg)
} else {
ext::panic("no info")
}
}
}
#[cfg(feature = "panic-handler")]
pub use panic_handler::*;
2 changes: 1 addition & 1 deletion gstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#![no_std]
#![warn(missing_docs)]
#![cfg_attr(
all(target_arch = "wasm32", feature = "panic-messages",),
all(target_arch = "wasm32", feature = "panic-messages"),
feature(panic_info_message)
)]
#![cfg_attr(
Expand Down