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

Attempt to capture panics with GDB #690

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 18 additions & 3 deletions bittide-instances/data/gdb/smoltcp-hitl-prog.gdb
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# SPDX-FileCopyrightText: 2024 Google LLC
#
# SPDX-License-Identifier: Apache-2.0
set logging file ./_build/hitl/gdb-out.log
set logging overwrite on
set logging enabled on
file "./_build/cargo/firmware-binaries/riscv32imc-unknown-none-elf/release/smoltcp_client"
target extended-remote :3333

# Load binary on CPU and start execution
break core::panicking::panic
break ExceptionHandler
break rust_begin_unwind
break smoltcp_client::gdb_panic

target extended-remote :3333
load
start

define hook-stop
printf "!!! program stopped executing !!!"
i r
bt
quit 1
end

continue
7 changes: 6 additions & 1 deletion firmware-binaries/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

[build]
target = "riscv32imc-unknown-none-elf"
rustflags = ["-C", "target-feature=+f"]
rustflags = [
"-C", "target-feature=+f",
# XXX: These two seem to be ignored
"-C", "force-frame-pointers=yes",
"-C", "force-unwind-tables=yes"
]
target-dir = "../_build/cargo/firmware-binaries"

[unstable]
Expand Down
56 changes: 53 additions & 3 deletions firmware-binaries/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions firmware-binaries/examples/smoltcp_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ authors = ["Google LLC"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
riscv-rt = "0.11.0"
riscv = "^0.10"
heapless = { version = "0.8", default-features = false}
smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp.git", rev = "dc08e0b42e668c331bb2b6f8d80016301d0efe03", default-features = false, features = ["medium-ethernet", "proto-ipv4", "socket-tcp", "socket-dhcpv4"] }
riscv-rt = "0.11.0"
ufmt = "0.2.0"
log = {version = "0.4.21", features = ["max_level_off", "release_max_level_info"]}

[dependencies.bittide-sys]
path = "../../../firmware-support/bittide-sys"

[dependencies.gdb-trace]
path = "../../../firmware-support/gdb-trace"

[dependencies.heapless]
version = "0.8"
default-features = false

[dependencies.log]
version = "0.4.21"
features = ["max_level_off", "release_max_level_info"]

[dependencies.smoltcp]
git = "https://github.com/smoltcp-rs/smoltcp.git"
rev = "dc08e0b42e668c331bb2b6f8d80016301d0efe03"
default-features = false
features = ["medium-ethernet", "proto-ipv4", "socket-tcp", "socket-dhcpv4"]
16 changes: 4 additions & 12 deletions firmware-binaries/examples/smoltcp_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const CHUNK_SIZE: usize = 4096;
const SERVER_IP: IpAddress = IpAddress::v4(10, 0, 0, 1);
const SERVER_PORT: u16 = 1234;

gdb_trace::gdb_panic! {
unsafe { Uart::new(UART_ADDR) }
}

// See https://github.com/bittide/bittide-hardware/issues/681
#[allow(static_mut_refs)]
#[cfg_attr(not(test), entry)]
Expand Down Expand Up @@ -178,18 +182,6 @@ fn exception_handler(_trap_frame: &riscv_rt::TrapFrame) -> ! {
}
}

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
let mut uart = unsafe { Uart::new(UART_ADDR) };

uwriteln!(uart, "Panicked!").unwrap();
info!("error: {}\n", info);
uwriteln!(uart, "Looping forever now").unwrap();
loop {
continue;
}
}

fn update_dhcp(iface: &mut Interface, socket: &mut dhcpv4::Socket) {
let event = socket.poll();
match event {
Expand Down
55 changes: 55 additions & 0 deletions firmware-support/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firmware-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

[workspace]
members = [
"bittide-sys",
"bittide-sys", "gdb-trace",
]
resolver = "2"
13 changes: 13 additions & 0 deletions firmware-support/gdb-trace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2022 Google LLC
#
# SPDX-License-Identifier: CC0-1.0

[package]
name = "gdb-trace"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
riscv = "0.12.1"
29 changes: 29 additions & 0 deletions firmware-support/gdb-trace/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2022 Google LLC
//
// SPDX-License-Identifier: Apache-2.0

#![no_std]

use core::{fmt::Write, panic::PanicInfo};

/// Internal function for a GDB panic handler. It disables interrupts and attemps to write
/// the panic info to the provided write-able interface. It's expected that the user will
/// be running a GDB process and set a breakpoint to the panic handler so that the output
/// can be read.
#[allow(clippy::empty_loop)]
pub fn gdb_panic_internal<W: Write>(writer: &mut W, info: &PanicInfo) -> ! {
riscv::interrupt::machine::disable();
writeln!(writer, "{:?}", info).unwrap();
loop {}
}

#[macro_export]
macro_rules! gdb_panic {
($writer:expr) => {
#[panic_handler]
fn gdb_panic(info: &::core::panic::PanicInfo) -> ! {
let mut writer = $writer;
$crate::gdb_panic_internal(&mut writer, info);
}
};
}
Loading