【发布时间】:2021-09-26 01:13:49
【问题描述】:
考虑以下故意导致双重恐慌的代码:
use scopeguard::defer; // 1.1.0
fn main() {
defer!{ panic!() };
defer!{ panic!() };
}
我知道这通常发生在 Drop 实现在从先前的恐慌中展开时发生恐慌,但为什么它会导致程序发出非法指令?听起来代码已损坏或意外跳转到某个地方。我认为这可能与系统或代码生成有关,但我在各种平台上进行了测试,它们都以相同的原因发出类似的错误:
-
Linux:
thread panicked while panicking. aborting. Illegal instruction (core dumped) -
Windows(带有
cargo run):thread panicked while panicking. aborting. error: process didn't exit successfully: `target\debug\tests.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION) -
铁锈游乐场:
thread panicked while panicking. aborting. timeout: the monitored command dumped core /playground/tools/entrypoint.sh: line 11: 8 Illegal instruction timeout --signal=KILL ${timeout} "$@"
发生了什么事?这是什么原因造成的?
【问题讨论】:
-
这是因为你惊慌但抓住它什么的然后惊慌了两次,因为第一次恐慌没有奏效,我猜 rust 做了一个"OK I WILL DO IT MYSELF"
标签: rust panic illegal-instruction