Skip to content

Instantly share code, notes, and snippets.

@HollisTech
Created December 18, 2019 16:12
Show Gist options
  • Save HollisTech/18f7bd2963e9c33fc8b630ff414e13a9 to your computer and use it in GitHub Desktop.
Save HollisTech/18f7bd2963e9c33fc8b630ff414e13a9 to your computer and use it in GitHub Desktop.
espdecode: decode raw esp32 backtrace data from a log file. Requires PlatformIO.
<#
.SYNOPSIS
Decode raw esp32 backtraces in a log file.
Requires PlatformIO build environment.
.DESCRIPTION
Capture a log file with raw 'Backtrace:' data and pass it to this script.
The script filters the file, replacing the raw backtrace entries with decoded entries.
The filtered data is written to stdout.
.PARAMETER firmwarePath
The path to the elf firmware for the device, typically sometyhing like: .pio/build/featheresp32/firmware.elf
Your path will be specific your device type and configureation.
.PARAMETER file
The path to your logfile.
.PARAMETER pioRoot
If you installed PlatformIO in a non standard location, (not $env:USERPROFILE) you need to remedy that here.
.EXAMPLE
espdecode -file ".\espdecodetest.txt" -firmwarePath ".\.pio\build\featheresp32\firmware.elf" > log.txt
#>
param(
[Parameter(Mandatory=$true)]
[string]$firmwarePath,
[Parameter(Mandatory=$true)]
[string]$file,
[string]$pioRoot=$env:USERPROFILE
)
$decode = "$pioRoot/.platformio/packages/toolchain-xtensa32\bin\xtensa-esp32-elf-addr2line.exe"
function decodeStack
{
param(
[string] $stackline
)
$stackline -split ' ' | foreach-object {
& $decode -fp -e $firmwarePath $_
}
}
try {
$content = get-content -LiteralPath $file
foreach ($line in $content) {
if ($line -match '^Backtrace:.*') {
$b = $line -split "Backtrace:"
"Backtrace:"
decodeStack $b[1].trim()
} else {
$line
}
}
}
catch {
Write-Host ($_.Exception.Message -split ' For')[0] -ForegroundColor Red
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment