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

Nickez/add debug target #1323

Merged
merged 6 commits into from
Dec 3, 2024
Merged

Conversation

NickeZ
Copy link
Collaborator

@NickeZ NickeZ commented Nov 11, 2024

This improves the developer experience. You can now run the following shortcuts in separate terminals.

Let the gdb-server and rtt-client run forever:

make gdb-server  # launches JLinkGDBServer
make rtt-client  # connects to gdb server with telnet to get the RTT output

Whenever you built the firmware, rerun this:

make run-debug  # runs gdb and flashes the firmware over the gdb-server before executing it

To compile the debug firmware, run:

make firmware-debug

@NickeZ NickeZ requested a review from benma November 11, 2024 22:21
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 3 times, most recently from 05be931 to 82668e7 Compare November 12, 2024 09:45
Copy link
Collaborator

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docs for how to use this in BUILD.md.

869864 build-debug/bin/firmware.bin
715956 Build/bin/firmware.bin

This new debug firmware uses 849.48kB of the available 864kB, and adds 150kB on top of the release builds. This is super tight - when we add more code to the firmware, the debug build will be too large to fit. Any ideas what to do about it?

150kB seems generally like way too much for RTT support, any idea what uses so much space? The panic strings, or something else too?

@NickeZ
Copy link
Collaborator Author

NickeZ commented Nov 18, 2024

Please add docs for how to use this in BUILD.md.

869864 build-debug/bin/firmware.bin 715956 Build/bin/firmware.bin

This new debug firmware uses 849.48kB of the available 864kB, and adds 150kB on top of the release builds. This is super tight - when we add more code to the firmware, the debug build will be too large to fit. Any ideas what to do about it?

150kB seems generally like way too much for RTT support, any idea what uses so much space? The panic strings, or something else too?

Debug builds (by default) check for example overflow in arithmetics, so they introduce a lot of new panic places, with that comes of course lots of static strings and probably some formatting.

Setting debug-assertions = false in [profile.dev] gives a binary size of 774264.

Setting codege-units = 1 further reduces it to 750568.

We could add both, but eventually the release build will be equivalent to the debug build. So then we can just go back to only using release build and ignore the debug build.

edit: I guess there still is a point in having a debug build that enables pretty-printing of panics and enables RTT but keeps everything else the same.

@NickeZ NickeZ force-pushed the nickez/add-debug-target branch from 82668e7 to d54830b Compare November 19, 2024 09:11
@NickeZ NickeZ marked this pull request as draft November 20, 2024 12:43
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 10 times, most recently from e53c451 to dd206fb Compare November 26, 2024 20:14
Previously the debug build was to large to flash due to the optimization flag
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch from dd206fb to b19de45 Compare November 27, 2024 07:37
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 2 times, most recently from df31acc to b416c0a Compare November 27, 2024 08:29
Makefile Outdated Show resolved Hide resolved
@benma
Copy link
Collaborator

benma commented Nov 27, 2024

Is there any way to make rust_log in C have a sprintf signature like the screen debug equivalent?

void screen_sprintf_debug(int duration, const char* fmt, ...) __attribute__((format(printf, 2, 0)));

then one can much more conveniently log data, like rust_log("result: %d", result);

I guess you could just add a wrapper around rust_log in C that builds the string that is passed to rust_log.

@NickeZ NickeZ force-pushed the nickez/add-debug-target branch from b416c0a to 7c1bf61 Compare November 27, 2024 11:42
@NickeZ
Copy link
Collaborator Author

NickeZ commented Nov 27, 2024

Is there any way to make rust_log in C have a sprintf signature like the screen debug equivalent?

void screen_sprintf_debug(int duration, const char* fmt, ...) __attribute__((format(printf, 2, 0)));

then one can much more conveniently log data, like rust_log("result: %d", result);

I guess you could just add a wrapper around rust_log in C that builds the string that is passed to rust_log.

Good idea, I called it util_log because it does some stuff in C-land before calling rust_log.

@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 2 times, most recently from 325d016 to 4f49869 Compare November 27, 2024 11:51
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 4 times, most recently from 4d78e11 to 2bc35c3 Compare December 2, 2024 10:19
@NickeZ
Copy link
Collaborator Author

NickeZ commented Dec 2, 2024

i have some bootloader specific changes that I will create separate PRs of.

@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 2 times, most recently from aa9a1c5 to 3d78a39 Compare December 2, 2024 12:41
@benma
Copy link
Collaborator

benma commented Dec 3, 2024

To run the make run command inside the Docker container, the libncurses5 package must be installed. Would be useful to put it into the Dockerfile.

Yeah, I noticed that as well.

In the end the networking didn't work out for me. So I have to investigate why --network=host doesn't work with docker.

Even if you don't find a solution to the networking thing, it would still help me to just install libncurses5 in the docker image so I can use it. Currently I apt-get update && apt-get install libncurses5 every time.

@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 5 times, most recently from 65d24c6 to 91dc575 Compare December 3, 2024 12:31
@NickeZ
Copy link
Collaborator Author

NickeZ commented Dec 3, 2024

To run the make run command inside the Docker container, the libncurses5 package must be installed. Would be useful to put it into the Dockerfile.

Yeah, I noticed that as well.
In the end the networking didn't work out for me. So I have to investigate why --network=host doesn't work with docker.

Even if you don't find a solution to the networking thing, it would still help me to just install libncurses5 in the docker image so I can use it. Currently I apt-get update && apt-get install libncurses5 every time.

I'll add that in a separate PR.

@NickeZ NickeZ marked this pull request as ready for review December 3, 2024 13:00
@NickeZ NickeZ requested a review from benma December 3, 2024 13:00
Copy link
Collaborator

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super mega useful 👏

BUILD.md Outdated Show resolved Hide resolved
BUILD.md Outdated Show resolved Hide resolved
BUILD.md Show resolved Hide resolved
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 2 times, most recently from e435b46 to edf92e5 Compare December 3, 2024 13:41
BUILD.md Show resolved Hide resolved
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch 2 times, most recently from fe1d617 to ee318c2 Compare December 3, 2024 14:09
This commit introduces a new `log` macro that calls `rprintln` in case
the `rtt` feature is enabled. It also creates a new c function called
`util_log` that reuses the rust RTT machinery.

The rust `log` macro is used the same way `println` is used. `util_log`
is used the same way `printf` is used.
Add a section about debugging with GDB and restructure the docs for more
clarity.
@NickeZ NickeZ force-pushed the nickez/add-debug-target branch from ee318c2 to 5921931 Compare December 3, 2024 14:18
@NickeZ NickeZ merged commit fe8ee46 into BitBoxSwiss:master Dec 3, 2024
7 checks passed
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.

2 participants