Skip to content

Commit 2c56b23

Browse files
* revert: Pin [email protected] * test: Add backtrace tests
1 parent 5c0c6f4 commit 2c56b23

File tree

6 files changed

+87
-33
lines changed

6 files changed

+87
-33
lines changed

Cargo.lock

Lines changed: 40 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

espflash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ path = "./src/bin/espflash.rs"
2525
required-features = ["cli", "serialport"]
2626

2727
[dependencies]
28-
addr2line = { version = "0.24.2", optional = true }
28+
addr2line = { version = "=0.22.0", optional = true }
2929
base64 = "0.22.1"
3030
bitflags = "2.9.0"
3131
bytemuck = { version = "1.21.0", features = ["derive"] }

espflash/src/cli/monitor/symbols.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,22 @@ use std::error::Error;
33
use addr2line::{
44
Context,
55
LookupResult,
6-
gimli::{self, Dwarf, EndianSlice, LittleEndian, SectionId},
6+
gimli::{EndianRcSlice, RunTimeEndian},
7+
object::{Object, ObjectSegment, ObjectSymbol, read::File},
78
};
8-
use object::{Object, ObjectSection, ObjectSegment, ObjectSymbol, read::File};
99

1010
// Wrapper around addr2line that allows to look up function names and
1111
// locations from a given address.
1212
pub(crate) struct Symbols<'sym> {
1313
object: File<'sym, &'sym [u8]>,
14-
ctx: Context<EndianSlice<'sym, LittleEndian>>,
14+
ctx: Context<EndianRcSlice<RunTimeEndian>>,
1515
}
1616

1717
impl<'sym> Symbols<'sym> {
1818
/// Tries to create a new `Symbols` instance from the given ELF file bytes.
1919
pub fn try_from(bytes: &'sym [u8]) -> Result<Self, Box<dyn Error>> {
2020
let object = File::parse(bytes)?;
21-
let dwarf = Dwarf::load(
22-
|id: SectionId| -> Result<EndianSlice<'sym, LittleEndian>, gimli::Error> {
23-
let data = object
24-
.section_by_name(id.name())
25-
.and_then(|section| section.data().ok())
26-
.unwrap_or(&[][..]);
27-
Ok(EndianSlice::new(data, LittleEndian))
28-
},
29-
)?;
30-
31-
let ctx = Context::from_dwarf(dwarf)?;
21+
let ctx = Context::new(&object)?;
3222

3323
Ok(Self { object, ctx })
3424
}

espflash/tests/data/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,22 @@ esp-generate --chip=esp32c6 -o defmt --headless esp32c6_defmt
1515
cd esp32c6_defmt
1616
DEFMT_LOG=info cargo build --release
1717
```
18+
19+
20+
The `esp32c6_backtrace` elf file under this folder has been generated using `esp-generate@f4213a9`:
21+
```
22+
esp-generate --chip=esp32c6 --headless -o esp-backtrace esp32c6_backtrace
23+
cd esp32c6_backtrace
24+
```
25+
Modified the main.rs to panic:
26+
```diff
27+
let _peripherals = esp_hal::init(config);
28+
29+
+ panic!("test");
30+
+
31+
loop {
32+
```
33+
And then build the elf file:
34+
```
35+
cargo build --release
36+
```

espflash/tests/data/esp32c6_backtrace

756 KB
Binary file not shown.

espflash/tests/scripts/flash.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ if [[ "$1" == "esp32c6" ]]; then
4141
echo "Monitoring failed!"
4242
exit 1
4343
fi
44+
45+
# Backtrace test
46+
app_backtrace="${app}_backtrace"
47+
48+
result=$(timeout 10s espflash flash --no-skip --monitor --non-interactive $app_backtrace 2>&1)
49+
echo "$result"
50+
if [[ ! $result =~ "Flashing has completed!" ]]; then
51+
echo "Flashing failed!"
52+
exit 1
53+
fi
54+
expected_strings=(
55+
"0x420012c8"
56+
"main"
57+
"esp32c6_backtrace/src/bin/main.rs:"
58+
"0x42001280"
59+
"hal_main"
60+
)
61+
for expected in "${expected_strings[@]}"; do
62+
if ! echo "$result" | grep -q "$expected"; then
63+
echo "Monitoring failed! Expected '$expected' not found in output."
64+
exit 1
65+
fi
66+
done
4467
fi
4568

4669
result=$(timeout 15s espflash flash --no-skip --monitor --non-interactive $app 2>&1)

0 commit comments

Comments
 (0)