chDbgAssert discards reason Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
ER-Force
Posts: 1
Joined: Wed May 12, 2021 9:29 pm

chDbgAssert discards reason  Topic is solved

Postby ER-Force » Wed May 12, 2021 9:47 pm

I noticed that the parameter 'r' of chDbgAssert is not actually used.

Code: Select all

#if !defined(chDbgAssert)
#define chDbgAssert(c, r) do {                                              \
  /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/       \
  if (CH_DBG_ENABLE_ASSERTS != FALSE) {                                     \
    if (!(c)) {                                                             \
  /*lint -restore*/                                                         \
      chSysHalt(__func__);                                                  \
    }                                                                       \
  }                                                                         \
} while (false)
#endif /* !defined(chDbgAssert) */


I find a reason displayed in a debugger quite helpful, although the __func__ is of course great information as well.
We have quickly hack-fixed it in our codebase by using sprintf to get both __func__ and the reason. Using the standard library is of course not ideal, but one could just manually concatenate or leave inserting __func__ to the caller.
What I'm wondering is, if there's a special reason for discarding r that I'm unaware of? Or is this just an oversight?

Kind regards
Lukas

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: chDbgAssert discards reason

Postby Giovanni » Thu May 13, 2021 7:51 am

Hi,

The reason it is there for the debugger, you click on the stack trace and you can read the reason in the source code, is there a need to store in memory all those strings? (Same could be said for __func__ frankly, I am tempted to remove it as well). Concatenation would require a RAM buffer as you did, it has no place in that code.

Note that chDbgAssert() is a macro that can be overridden with your own implementation, your implementation could leverage the "reason" parameter. You could add your own variant to chconf.h.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 22 guests