Function call is corrupted when compiled for debug
(rustc 1.82.0-nightly (c1a6199e9 2024-07-24)
)
#589
Replies: 1 comment 1 reply
-
Please always use the following build profiles to ensure even debug code gets optimized: Lines 1 to 11 in 544e50b Beyond that, the only difference between debug and release should be the presence of You can try "optimizing" against them by ensuring panicking code-paths cannot be reached. For example, by doing appropriate bounds checks on values before performing arithmetic, or by using methods like, for example, But in any case, corruption either hints at a compiler bug or the stack growing too far and corrupting the static data. As you do have quite a large amount of static data (2610 bytes debug/1800 bytes release), this is quite possible. You may want to take a look at the contents of all that static data and where it came from - possibly you can get rid of a lot of it. |
Beta Was this translation helpful? Give feedback.
-
I don't have a minimal reproduction, as this issue disappears when I remove one function call from my loop function, specifically, a call to the
dispatch_commands
function in my code, which is linked below.The full code is here.
I suspect the Arduino might be running out of memory in
debug
mode, but I cannot confirm, and I have no idea how to debug it. I am using an Arduino Mega 2560. Below is the output of theavr-size
command for the binary indebug
mode:Below is the output of the
avr-size
command for the binary inrelease
mode:My code essentially moves a car, so there are four movement motors for the four wheels. The main loop runs the four movement motors every loop. Below are the logs for the expected result, in
release
mode, running the loop 4 times:In
debug
mode, however, it seems like the function to run the motors has been corrupted, as shown in the logs below:There are integer overflows for subtracting the
previous step time
from thecurrent time
as well, which should not happen as theprevious step time
is initialised to0
.I think this is most likely memory corruption due to the Arduino running out of memory, but I don't know how to get the memory usage of each function call or even the total memory used by the program, so I'm not sure where to start optimising either.
Does anyone have any idea on how to fix this issue?
Beta Was this translation helpful? Give feedback.
All reactions