Skip to content

Conversation

@jaguilar
Copy link
Contributor

It's helpful when you crash to see what happens right before you crash. For example, if you add a log message "about to dereference sketchy pointer" and then you get a segfault, you'd love to know whether that message occurred. This change makes it so that at least on EV3, we will.

This also adds "pb_log" as an alias for pbdrv_uart_debug_printf. Usually, platforms make it easy to log debug messages, and we should be no different. C.f. ESP_LOGI, Zephyr's LOG_ERR, glog's LOG(WARNING) etc.

Tested by adding the following code to pbdrv_init.

    pb_log("test\n");

    lwrb_t* rb = (lwrb_t*)0x1281441490;
    pb_log("%p\n", lwrb_get_free(rb));

Before this, the "test" would not appear before the panic. After, it does. If a panic occurs while some messages are pending in the uart send state, some bytes may be duplicated on the log.

This only makes this change for EV3. I will separately look into whether it might be useful on other platforms.

@coveralls
Copy link

coveralls commented Dec 12, 2025

Coverage Status

coverage: 56.239%. remained the same
when pulling 9f46367 on jaguilar:dump_log_on_panic
into 350db6e on pybricks:master.

It's helpful when you crash to see what happens right before you
crash. For example, if you add a log message "about to dereference
sketchy pointer" and then you get a segfault, you'd love to know
whether that message occurred. This change makes it so that at least
on EV3, we will.

This also adds "pb_log" as an alias for pbdrv_uart_debug_printf.
Usually, platforms make it easy to log debug messages, and we should
be no different. C.f. `ESP_LOGI`, Zephyr's `LOG_ERR`, glog's
`LOG(WARNING)` etc.

Tested by adding the following code to pbdrv_init.

```
    pb_log("test\n");

    lwrb_t* rb = (lwrb_t*)0x1281441490;
    pb_log("%p\n", lwrb_get_free(rb));
```

Before this, the "test" would not appear before the panic.
After, it does. If a panic occurs while some messages are pending
in the uart send state, some bytes may be duplicated on the log.
@laurensvalk
Copy link
Member

Thanks!

I think this fine. Maybe the alias could still keep the word UART in it?

I'll be adding USB debugging in an upcoming commit. This will be helpful for platforms without uart (like NXT) and for most people without custom cables.

Output will go into the existing stdout ring buffer, so it simply shows up in Pybricks Code without custom terminal tools. Since the EV3 reconnect itself on reboot, this should even be convenient for our own everyday use cases.

They can be complementary - we'll still want the UART version for sketchy pointers and other reasons for panic 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants