This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Some questions and comments related to the linked post.
When assert() is called and you ARE debugging (say a Launchpad, and using the debugger, even when no breakpoints set), I find that assert() ends up pausing the target, and shows a stack trace of:
__TI_writemsg(), HOSTWrite(). fputs(), _abort_msg(), assert()
and the program counter is at this line of __TI_writemsg():
for (i = 0; i < 8; i++) PACKCHAR(*parm++, p, i);
I don't understand how that invokes the debugger, but I don't really care, as long as it breaks into the debugger as if BKPT was invoked.
What I do care about is that these functions don't have any useful effect, but they seem to drag in a lot of code such as write() and _stream from the runtime library. And they drag in many variables in the .data segment which seem to get initialized at C startup. Which very slightly skews memory sizes and power use while using EnergyTrace.
Question: if I don't care to have an abort message, is overriding the definition of _abort_msg() the conventional way? And how would I then invoke the debugger?
For a production build, I substitute an implementation of assert() that typically does a software reset.
I am testing LPM4.5, use C++, and use many assertions. Maybe that case is unusual.
The assert macro is required by the ANSI standard for C. It tests the given expression, and if it is zero, a message is output and the program exits.
The TI implementation of assert calls the standard C I/O functions fputs and fflush to output the message. These functions, in turn, call many other functions in the compiler RTS library. The lowest level of these functions depends on a breakpoint in CCS to work. For further details on this point, please search the MSP430 compiler manual for the sub-chapter titled Device-Driver Level I/O Functions.
lloyd konneker said:if I don't care to have an abort message, is overriding the definition of _abort_msg() the conventional way?
No. The ANSI standard also requires that the implementation of assert refer to the macro NDEBUG. If NDEBUG is defined, then the assert macro is defined to do nothing. Typically, NDEBUG is defined on the compiler command line with --define=NDEBUG.
Thanks and regards,
-George
I will read the material you suggest, thanks.
I already knew about NDEBUG, but I don't want to remove the all the assertions (and I don't want to use exceptions). (I posted a related post about the fact that DriverLib defines NDEBUG improperly.)
I don't want to remove assertions but I also don't want an assert to do any io (because it drags in code which has no effect.) I assume _abort_msg() calls the io functions you refer to. In the context of an embedded system, an abort message to the host might not make sense (there might not be an OS or other processes or a user who cares about the abort or a programmer running a debugger with a console.) I want the assert to break into the debugger or do a software reset. I think that it is more or less conventional for one to redefine _exit() (which exits to the host) which also might not make sense for an embedded application. A quick search doesn't show it is conventional to redefine _abort_msg(), but I suppose I should just try it.
lloyd konneker said:I should just redefine the assert macro to do what I want.
That seems like a reasonable approach.
Thanks and regards,
-George