aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-04-25 01:27:39 +0200
committerRon Evans <[email protected]>2023-04-26 18:40:35 +0200
commitae381e74a506b13138e82dc01883f230255f14ff (patch)
treee2ca5cccdeb83c4c0d3b92c154798b3306333995 /main.go
parent3392827c3e6ac2c0849e443242576c1dd24f6677 (diff)
downloadtinygo-ae381e74a506b13138e82dc01883f230255f14ff.tar.gz
tinygo-ae381e74a506b13138e82dc01883f230255f14ff.zip
main: print source location when a panic happens in -monitor
The previous commit started printing the instruction address for runtime panics. This commit starts using this address to print the source location. Here is an example where this feature is very useful. There is a heap allocation in the Bluetooth package, but we don't know where exactly. Printing the instruction address of the panic is already useful, but what is even more useful is looking up this address in the DWARF debug information that's part of the binary: $ tinygo flash -target=circuitplay-bluefruit -monitor ./examples/heartrate Connected to /dev/ttyACM0. Press Ctrl-C to exit. tick 00:00.810 tick 00:01.587 tick 00:02.387 tick 00:03.244 panic: runtime error at 0x00027c4d: alloc in interrupt [tinygo: panic at /home/ayke/src/tinygo/bluetooth/adapter_sd.go:74:4] To be clear, this path isn't stored on the microcontroller. It's stored as part of the build, and `-monitor` just looks up the path from the panic message. Possible enhancements: - Print such an address for regular panics as well. I'm not sure that's so useful, as it's usually a lot easier to look up panics just by their message. - Use runtimePanicAt (instead of runtimePanic) in other locations, if that proves to be beneficial. - Print the TinyGo-generated output in some other color, to distinguish it from the regular console output. - Print more details when panicking (registers, stack values), and print an actual backtrace.
Diffstat (limited to 'main.go')
-rw-r--r--main.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/main.go b/main.go
index 3b3b1a301..a2c5611b7 100644
--- a/main.go
+++ b/main.go
@@ -532,7 +532,7 @@ func Flash(pkgName, port string, options *compileopts.Options) error {
return fmt.Errorf("unknown flash method: %s", flashMethod)
}
if options.Monitor {
- return Monitor("", options)
+ return Monitor(result.Executable, "", options)
}
return nil
}
@@ -1720,7 +1720,7 @@ func main() {
os.Exit(1)
}
case "monitor":
- err := Monitor(*port, options)
+ err := Monitor("", *port, options)
handleCompilerError(err)
case "targets":
dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets")