Arduino-Debug
On-target sketch debugger for Arduino
Debug Class Reference

#include <Debug.h>

Inheritance diagram for Debug:
Inheritance graph
Collaboration diagram for Debug:
Collaboration graph

Classes

class  Variable
 

Public Member Functions

 Debug ()
 
bool begin (Stream *dev, const char *file, int line, const char *func)
 
void assert (const char *file, int line, const char *func, str_P cond)
 
void break_at (const char *file, int line, const char *func, str_P cond)
 
bool check_stack (int room=128)
 
void observe_at (const char *file, int line, const char *func, str_P expr)
 
bool end ()
 

Protected Member Functions

virtual size_t write (uint8_t c)
 
virtual int available (void)
 
virtual int peek (void)
 
virtual int read (void)
 
virtual void flush (void)
 
void dump (uint16_t src, const void *ptr, size_t size)
 
void run (const char *file=NULL, int line=0, const char *func=NULL, str_P expr=NULL)
 
void do_backtrace (const char *func)
 
bool do_lookup_variables (const char *name, bool is_pointer=false)
 
void do_memory_usage (int marker)
 
void do_print_commands ()
 
void do_print_data ()
 
void do_print_heap ()
 
void do_print_stack (int marker)
 
void do_print_variables ()
 
void do_quit ()
 

Protected Attributes

Stream * m_dev
 Debug stream. More...
 
Variablem_var
 Last registered variable. More...
 
int DATAEND
 End of data segment. More...
 
int DATASIZE
 Size of data segment. More...
 

Friends

class Variable
 

Detailed Description

Arduino Debug class with basic breakpoint, data observation and display, and memory usage.

Configuration

Define to remove corresponding command: DEBUG_NO_BACKTRACE DEBUG_NO_LOOKUP_VARIABLES DEBUG_NO_MEMORY_USAGE DEBUG_NO_PRINT_COMMANDS DEBUG_NO_PRINT_DATA DEBUG_NO_PRINT_HEAP DEBUG_NO_PRINT_STACK DEBUG_NO_PRINT_VARIABLES DEBUG_NO_QUIT DEBUG_NO_WHERE May be used to reduce memory footprint and allow debugging with limited resources.

Definition at line 55 of file Debug.h.

Constructor & Destructor Documentation

Debug::Debug ( )
inline

Create debug print and command handler. Debug is a singleton.

Definition at line 60 of file Debug.h.

Member Function Documentation

void Debug::assert ( const char *  file,
int  line,
const char *  func,
str_P  cond 
)

Assertion failure of given condition in source code (file, line and function). The debug command handler is called. The macro ASSERT(cond) should be used instead.

Parameters
[in]filename.
[in]linenumber.
[in]funcfunction name.
[in]condcondition string.

Definition at line 47 of file Debug.cpp.

virtual int Debug::available ( void  )
inlineprotectedvirtual

Definition at line 184 of file Debug.h.

bool Debug::begin ( Stream *  dev,
const char *  file,
int  line,
const char *  func 
)

Start debug handler with given stream, file name, line number and function name. The macro DEBUG_STREAM(dev) should be used instead. Returns true(1) if successful otherwise false(0).

Parameters
[in]devstream for debug handler.
[in]filename.
[in]linenumber.
[in]funcfunction name.
Returns
bool.

Definition at line 29 of file Debug.cpp.

void Debug::break_at ( const char *  file,
int  line,
const char *  func,
str_P  cond 
)

Break point in given file, on line, and in function. The debug command handler is run. The macro BREAKPOINT() or BREAK_IF(cond) should be used instead.

Parameters
[in]filename.
[in]linenumber.
[in]funcfunction name.
[in]condcondition string.

Definition at line 59 of file Debug.cpp.

bool Debug::check_stack ( int  room = 128)

Check stack status. Return false(0) if the stack has moved into the heap else true(1).

Parameters
[in]roomrequired free bytes.
Returns
bool.

Definition at line 69 of file Debug.cpp.

void Debug::do_backtrace ( const char *  func)
protected

Print backtrace.

Parameters
[in]funcdebug entry function.

Definition at line 234 of file Debug.cpp.

bool Debug::do_lookup_variables ( const char *  name,
bool  is_pointer = false 
)
protected

Lookup given variable name in register. Return true(1) if found otherwise false(0).

Parameters
[in]nameof variable.
[in]is_pointerflag (default false).

Definition at line 250 of file Debug.cpp.

void Debug::do_memory_usage ( int  marker)
protected

Print memory usage statistics with size of data segment, heap, stack and number of free bytes.

Definition at line 266 of file Debug.cpp.

void Debug::do_print_commands ( )
protected

Print list of commands and short description.

Definition at line 282 of file Debug.cpp.

void Debug::do_print_data ( )
protected

Print contents of data segment in hex format.

Definition at line 321 of file Debug.cpp.

void Debug::do_print_heap ( )
protected

Print contents of heap in hex format.

Definition at line 329 of file Debug.cpp.

void Debug::do_print_stack ( int  marker)
protected

Print contents of stack in hex format.

Definition at line 341 of file Debug.cpp.

void Debug::do_print_variables ( )
protected

Print registered variables in format:

REG:FUNC:VAR@REF=VAL
REG:FUNC:VAR@REF[SIZE]:HEX

where REG is the stack address of register item for the variable VAR. FUNC is the name of the function where registered. REF is the address of the variables value and VAL is the value. If the value is larger than int the value is printed in HEX format.

Definition at line 351 of file Debug.cpp.

void Debug::do_quit ( )
protected

Stop the sketch.

void Debug::dump ( uint16_t  src,
const void *  ptr,
size_t  size 
)
protected

Dump memory in block format (hex with address prefix).

Parameters
[in]srcaddress.
[in]ptrblock pointer.
[in]sizeof block.

Definition at line 397 of file Debug.cpp.

bool Debug::end ( )

Stop debug handler. Returns true(1) if successful otherwise false(0).

Returns
bool.

Definition at line 94 of file Debug.cpp.

virtual void Debug::flush ( void  )
inlineprotectedvirtual

Definition at line 187 of file Debug.h.

void Debug::observe_at ( const char *  file,
int  line,
const char *  func,
str_P  expr 
)

Print variable obervation prefix with given file name, line number and function name to debug stream. The macro OBSERVE(expr) or OBSERVE_IF(cond,expr) should be used instead.

Parameters
[in]filename.
[in]linenumber.
[in]funcfunction name.
[in]exprexpression string.

Definition at line 78 of file Debug.cpp.

virtual int Debug::peek ( void  )
inlineprotectedvirtual

Definition at line 185 of file Debug.h.

virtual int Debug::read ( void  )
inlineprotectedvirtual

Definition at line 186 of file Debug.h.

void Debug::run ( const char *  file = NULL,
int  line = 0,
const char *  func = NULL,
str_P  expr = NULL 
)
protected

Run debug handler.

Parameters
[in]filename (default NULL).
[in]linenumber (default 0).
[in]funcfunction name (default NULL).
[in]exprexpression string (default NULL).

Definition at line 104 of file Debug.cpp.

virtual size_t Debug::write ( uint8_t  c)
inlineprotectedvirtual

Definition at line 183 of file Debug.h.

Friends And Related Function Documentation

friend class Variable
friend

Definition at line 285 of file Debug.h.

Member Data Documentation

int Debug::DATAEND
protected

End of data segment.

Definition at line 288 of file Debug.h.

int Debug::DATASIZE
protected

Size of data segment.

Definition at line 289 of file Debug.h.

Stream* Debug::m_dev
protected

Debug stream.

Definition at line 286 of file Debug.h.

Variable* Debug::m_var
protected

Last registered variable.

Definition at line 287 of file Debug.h.


The documentation for this class was generated from the following files: