BeRTOS
Defines | Functions
debug.h File Reference
#include <cfg/os.h>
#include <cfg/compiler.h>
#include "cfg/cfg_debug.h"
#include <cpu/attr.h>

Go to the source code of this file.

Defines

#define _DEBUG   1
 Preprocessor symbol defined only for debug builds.
#define THIS_FILE   __FILE__
 This macro duplicates the old MSVC trick of redefining THIS_FILE locally to avoid the overhead of many duplicate strings in ASSERT().
#define DB(x)   x
 This macro can be used to conditionally exclude one or more statements conditioned on _DEBUG, avoiding the clutter of ifdef/endif pairs.
#define ASSERT(x)   ((void)(LIKELY(x) ? 0 : __bassert(#x, THIS_FILE, __LINE__)))
 Assert a pre-condition on code.
#define ASSERT2(x, help)   ((void)(LIKELY(x) ? 0 : __bassert(help " (" #x ")", THIS_FILE, __LINE__)))
 Assert a pre-condition and give explanation message when assert fails.
#define ASSERT_VALID_PTR(p)
 Check that the given pointer is either NULL or pointing to valid memory.
#define ASSERT_VALID_PTR_OR_NULL(p)
 Check that the given pointer is not pointing to invalid memory.
#define ASSERT_VALID_OBJ(_t, _o)
 Check that the given pointer actually points to an object of the specified type.
Debug object creation and destruction.

These macros help track some kinds of leaks in C++ programs.

Usage is as follows:

   class Foo
   {
       DECLARE_INSTANCE_TRACKING(Foo)

       Foo()
       {
           NEW_INSTANCE(Foo);
           // ...
       }

       ~Foo()
       {
           DELETE_INSTANCE(Foo);
           // ...
       }
   };

   // Put this in the implementation file of the class
   IMPLEMENT_INSTANCE_TRACKING(Foo)

   // Client code
   int main(void)
   {
        Foo *foo = new Foo;
        cout << GET_INSTANCE_COUNT(Foo) << endl; // prints "1"
        delete foo;
        ASSERT_ZERO_INSTANCES(Foo); // OK
   }
#define NEW_INSTANCE(CLASS)   do { ++CLASS::__instances } while (0)
#define DELETE_INSTANCE(CLASS)   do { --CLASS::__instances } while (0)
#define ASSERT_ZERO_INSTANCES(CLASS)   ASSERT(CLASS::__instances == 0)
#define GET_INSTANCE_COUNT(CLASS)   (CLASS::__instances)
#define DECLARE_INSTANCE_TRACKING(CLASS)   static int __instances
#define IMPLEMENT_INSTANCE_TRACKING(CLASS)   int CLASS::__instances = 0
Walls to detect data corruption
#define WALL_SIZE   8
#define WALL_VALUE   (long)0xABADCAFEL
#define DECLARE_WALL(name, size)   long name[(size) / sizeof(long)];
#define FWD_DECLARE_WALL(name, size)   extern long name[(size) / sizeof(long)];
#define INIT_WALL(name)   __init_wall((name), countof(name))
#define CHECK_WALL(name)   __check_wall((name), countof(name), #name, THIS_FILE, __LINE__)

Functions

int kputnum (int num)
 Cheap function to print small integers without using printf().
void kdump (const void *buf, size_t len)
 Dump binary data in hex.

Detailed Description

Definition in file debug.h.