[En-Nut-Discussion] New debugging capabilities of Nut/OS 4.8

Harald Kipp harald.kipp at egnite.de
Tue Apr 7 20:17:43 CEST 2009


Hi all,

it doesn't look like I'll have enough time in the near future to create
a basic document about these new features. The following short version
may help experienced Nut/OS users:

When adding this line to UserConf.mk (both, build and app tree)

HWDEF+=-DNUTDEBUG_CHECK_STACK

the stacks will be filled with 0xDEADBEEF. An application may then call

NutThreadStackAvailable("nameOfTheThread");

to query the number of stack bytes that never had been used. The
following routines spits out all unused bytes in the stacks of all threads:

void ListStacks(void)
{
#ifdef NUTDEBUG_CHECK_STACK
    NUTTHREADINFO *tdp;

    for (tdp = nutThreadList; tdp; tdp = tdp->td_next) {
        printf("%s: %lu bytes stack available\n", tdp->td_name,
(unsigned long)NutThreadStackAvailable(tdp->td_name));
    }
    NutSleep(100);
#endif
}

When adding this line to UserConf.mk (build tree):

HWDEF+=-DNUTDEBUG_USE_ASSERT

then Nut/OS will do additional checks on API parameters. This is not
fully implemented, but may already be helpful to find specific bugs in
application code.

If something goes wrong, Nut/OS will call

void NUTPANIC(CONST char *fmt, ...)

An application may define something like

void NUTPANIC(CONST char *fmt, ...)
{
    va_list ap;

    NutEnterCritical();
    va_start(ap, fmt);
    vfprintf(stdout, fmt, ap);
#ifdef NUTDEBUG_HEAP
    NutHeapDump(stdout);
#endif
    ListStacks();
    for(;;);
}

When adding this line to UserConf.mk (build and app tree):

HWDEF+=-DNUTDEBUG_HEAP

then the application can call

rc = NutHeapCheck()

to verify heap consistency and

NutHeapDump(stdout)

to list all heap fragments.

When adding this line to UserConf.mk (build tree):

HWDEF+=-DNUTMEM_GUARD

then the heap routines will add additional guard bytes to each heap
block. On release (or NutHeapCheck) this will enable to system to detect
overwrites.

All the above is available for AVR and ARM.

The following is for ARM only.

When adding

 $(LIBDIR)/arm-da.o

in front of the

LIBS =

entry in your Makefile, e.g.

LIBS =  $(LIBDIR)/arm-da.o $(LIBDIR)/nutinit.o -lnutos -lnutdev
-lnutarch -lnutcrt

then a data abort will print out a backtrace on stdout.

There is also

arm-pfa.o for prefetch abort
arm-swi.o for software interrupt
arm-udf.o for undefined instructions

Note, that the backtrace requires, that arm-gccdbg is selected.

Hope this helps a bit to try it out,

Harald




More information about the En-Nut-Discussion mailing list