How can I use the assert to debug the code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I use the assert to debug the code

2,708 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dino on Thu Jul 05 03:13:57 MST 2012
I am using LPCXpresso v4.2.2 [Build 275] [03/04/2012] and I would like to use the macro assert to debug my code. I included the file assert.h and I added only assert(0); and assert (1); just to test if works. But I have an error if I compile for debug.
[SIZE=1][SIZE=3]Many thanks[/SIZE]

[/SIZE]
0 Kudos
Reply
7 Replies

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Brutte on Fri Jul 06 10:28:01 MST 2012

Quote: Dino
I selected the library semihost.  Now assert(0) stop the program (...) From now on is not possible to go on .. 


Sure, that is what one expects from assert.
With semihosting enabled you should see a message in a console view, something like:
"runtime assertion failed at file: src/foo.c, line 123, because of: 0"


Quote: atomicdog
If you mean assert() and debug give any error that's what it's suppose to do (give a compile time error).


Current LPCXpresso implementation verifies only run-time assertions. Static assertions (compile-time) were introduced in c++0x.
0 Kudos
Reply

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dino on Fri Jul 06 07:41:23 MST 2012
I selected the library semihost.  Now assert(0) stop the program and a new window is opened  _SYS_APPEXIT() with this info :
  No source available for "__sys_appexit() "
(View disassembly)
From now on is not possible to go on .. 


In the disassembly window I see this code :
00001cfd: memset1a+7             bne.n 0x1cf6 <memset1a>
00001cff: memset1_ret+1          mov r0, r12
00001d01: memset1_ret+3          bx lr
00001d03: memset1_ret+5          movs r0, r0
00001d05: __sys_appexit+1        movs r0, #24
00001d07: __sys_appexit+3        ldr r1, [pc, #4]        ; (0x1d0c <__sys_appexit+8>)
00001d09: __sys_appexit+5        bkpt 0x00ab
00001d0b: __sys_appexit+7        bx lr
00001d0d: __sys_appexit+9        movs r6, r4
00001d0f: __sys_appexit+11       movs r2, r0
                               __sys_close:
00001d10: __sys_close+0          push {r0, r1}
00001d12: __sys_close+2          mov r1, sp
00001d14: __sys_close+4          movs r0, #2
00001d16: __sys_close+6          bkpt 0x00ab
00001d18: __sys_close+8          add sp, #8
00001d1a: __sys_close+10         bx lr
0 Kudos
Reply

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Jul 06 06:29:54 MST 2012

Quote: Dino
I selected the library redlib nohost using the  command
Quickstart -> Quick Settings -> Set library typeIn this case I haven't an error but the assert don't stop the program. If I suspended the program I see this error:  No source available for "__sys_appexit() "



Yes, this is expected behaviour - exactly as specified in the FAQ you were previously pointed to which states that, when invoked, the assert macro will cause....


Quote:
the semihosting stub function __sys_appexit()  is now called. If you are linking with Redlib(semihost), then this will  cause your application to terminate execution and return control to the  debugger. If you are linking with Redlib(nohost), then __sys_appexit() will simply enter a while(1) loop



Regards,
CodeRedSupport
0 Kudos
Reply

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dino on Fri Jul 06 01:52:28 MST 2012
I selected the library redlib nohost using the  command
Quickstart -> Quick Settings -> Set library typeIn this case I haven't an error but the assert don't stop the program. If I suspended the program I see this error:  No source available for "__sys_appexit() "
0 Kudos
Reply

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Thu Jul 05 16:33:42 MST 2012

Quote: Dino
I included the file assert.h and I added only assert(0); and assert (1); just to test if works. But I have an error if I compile for debug.
[SIZE=1][SIZE=3]Many thanks[/SIZE]

[/SIZE]

If you mean assert() and debug give any error that's what it's suppose to do (give a runtime error).
0 Kudos
Reply

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jul 05 08:48:01 MST 2012
Using assert.h really only makes sense if you link with the 'semihost' (or 'nohost') variants of Redlib. If you are seeing errors, then I suspect that you are linking with the 'none' variant.

For more information, please see:

http://support.code-red-tech.com/CodeRedWiki/CodeRedFAQ#CLibrary

and specifically...

http://support.code-red-tech.com/CodeRedWiki/redlib_v2_notes

Regards,
CodeRedSupport
0 Kudos
Reply

2,410 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Thu Jul 05 03:28:59 MST 2012
My psychic powers are failing me at the moment, so maybe if you told us what the compile error was, we might be able to help.
0 Kudos
Reply