Debug policy
Overwiev
BeRTOS provide a configurabile debug system. This allow the user to debug its application.
To use the debug system you should define the _DEGUB macro inside the your makefile.
If this macro is set, the BeRTOS makefile system compile and link all debug function that
compiler find, but the output binary is more big and consume more device resource because the device
must execute also the debug function code. Otherwise, if you disable the debug system the compiler
remove all debug function from code, so the binary is more light.
Generaly is to better leave the debug system enable and reduce the footprint of the debug in your
application. To do this BeRTOS implement a log module that provide a collection of library
that log your application, with the configurable log level.
Further you can configure differnt level of log for each module or application. In this
way the compiler link only the needed debug funtion, reducing the debug footprint.
Using a debug module
The debug module is common for all BeRTOS application and provide the basic debug function.
To enable it, you should define a _DEBUG in your makefile, like this:
#
# $Id: myprj.mk 18234 2007-10-08 13:39:48Z asterix $
# Copyright 2008 Develer S.r.l. (http://www.develer.com/)
# All rights reserved.
#
# Makefile fragment for DevLib at91sam7s application.
#
# Author: Bernardo Innocenti <bernie@develer.com>
#
#
# Set to 1 for debug builds
myprj_DEBUG = 1
# Our target application
TRG += myprj
myprj_CSRC = \
myprj/main.c \
# .. other src..
#
myprj_CPPASRC = \
bertos/cpu/arm/hw/crtat91sam7_rom.S \
bertos/kern/switch_arm.S \
#
myprj_CROSS = arm-elf-
myprj_CPPAFLAGS = -O2 -g -gdwarf-2 -g -gen-debug
myprj_CPPFLAGS = -O2 -D'ARCH=0' -D__ARM_AT91SAM7X256__ -g3 -gdwarf-2 -fverbose-asm -fno-omit-frame-pointer -fno-strict-aliasing -Imyprj -Ib
ertos -Ibertos/cpu/arm
myprj_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_rom.ld -Wl,--no-warn-mismatch
myprj_CPU = arm7tdmi
# Debug stuff
ifeq ($(myprj_DEBUG),1)
myprj_CFLAGS += -D_DEBUG
myprj_CSRC += bertos/drv/kdebug.c
endif
Otherwise you set _DEBUG to zero you disable all debug, and compiler not compile and link the debug functions.
Generally to enable and use a debug you should:
- define _DEBUG and set to 1 in your makefile
- init the debug module in your main() function using kdbg_init() function
- include the header <cfg/debug.h> in all module that you want to debug.
- use the debug functions (kprintf, kputs, assert, trace, ecc..) where you want.
Example to use debug module.
/**
* \file
* <!--
* This file is part of BeRTOS.
*
* Bertos is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2008 Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \brief My project main.
*
* \version $Id: myprj.c 21673 2008-06-06 14:00:01Z asterix $
*
* \author Daniele Basile <asterix@develer.com>
*
*/
/*
* my app header..
*/
#include <cfg/debug.h>
int main(void)
{
//Init the debug module.
kdbg_init();
//Use a debug function library
kprintf("This a debug message for my app.\n");
// Main loop
for(;;)
{
}
return 0;
}
