COSA
An Object-Oriented Platform for Arduino Programming
Debug Class Reference

#include <Debug.hh>

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

Classes

class  Variable
 

Public Types

enum  Base {
  bcd = 0, bin = 2, oct = 8, dec = 10,
  hex = 16
}
 
enum  Mode { CR_MODE = 0, LF_MODE = 1, CRLF_MODE = 2 }
 
typedef IOStream &(* Manipulator) (IOStream &)
 

Public Member Functions

 Debug ()
 
bool begin (IOStream::Device *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 ()
 
Devicedevice () const
 
Devicedevice (Device *dev)
 
str_P eol () const
 
void eol (str_P s)
 
str_P EOL () const
 
int8_t width (int8_t value)
 
uint8_t precision (uint8_t value)
 
void print (int value, Base base=dec)
 
void print (long int value, Base base=dec)
 
void print (unsigned int value, Base base=dec)
 
void print (unsigned long int value, Base base=dec)
 
void print (unsigned int value, uint8_t digits, Base base)
 
void print (unsigned long int value, uint8_t digits, Base base)
 
void print (double value, int8_t width, uint8_t prec)
 
void print (uint32_t src, const void *ptr, size_t size, Base base=dec, uint8_t max=16)
 
void print (const void *ptr, size_t size, Base base=dec, uint8_t max=16)
 
void print (void *ptr)
 
void print (const void *ptr)
 
void print (char c)
 
void print (const char *s)
 
void print (str_P s)
 
void print (IOStream::Device *buffer)
 
void println ()
 
void vprintf (str_P format, va_list args)
 
void printf (str_P format,...)
 
void flush ()
 
char * scan (char *s, size_t count)
 
char * readline (char *buf, size_t size, bool echo=true)
 
IOStreamoperator<< (Manipulator func)
 
IOStreamoperator<< (int n)
 
IOStreamoperator<< (long int n)
 
IOStreamoperator<< (double n)
 
IOStreamoperator<< (unsigned int n)
 
IOStreamoperator<< (unsigned long int n)
 
IOStreamoperator<< (void *ptr)
 
IOStreamoperator<< (const void *ptr)
 
IOStreamoperator<< (char c)
 
IOStreamoperator<< (char *s)
 
IOStreamoperator<< (const char *s)
 
IOStreamoperator<< (str_P s)
 
IOStreamoperator<< (IOStream &buffer)
 
IOStreamoperator<< (const iovec_t *vec)
 

Static Public Member Functions

static char * ultoa (unsigned long __val, char *__s, int base)
 
static char * ltoa (long __val, char *__s, int base)
 
static char * utoa (unsigned int __val, char *__s, int base)
 
static char * itoa (int __val, char *__s, int base)
 

Static Public Attributes

static const int EOF = -1
 
static const char CR []
 
static const char LF [] = "\r"
 
static const char CRLF [] = "\r\n"
 

Protected Member Functions

void run (const char *file=NULL, int line=0, const char *func=NULL, str_P expr=NULL)
 
void do_backtrace (const char *func)
 
void do_help ()
 
bool do_lookup_variables (const char *name)
 
void do_memory_usage (int marker)
 
void do_print_data ()
 
void do_print_heap ()
 
void do_print_stack (int marker)
 
void do_print_variables ()
 
void do_quit ()
 
void print_prefix (Base base)
 

Protected Attributes

Variablem_var
 Last registered variable. More...
 
char EXITCHARACTER
 Character to emit on exit. More...
 
int DATAEND
 End of data segment. More...
 
int DATASIZE
 Size of data segment. More...
 
Devicem_dev
 Delegated device. More...
 
Base m_base
 Base for next output operator. More...
 
int8_t m_width
 Minimum width of output string. More...
 
uint8_t m_prec
 Number of digits after decimal sign. More...
 
str_P m_eols
 End of line string (program memory). More...
 

Static Protected Attributes

static const size_t BUF_MAX = sizeof(uint32_t) * CHARBITS + 1
 

Friends

class Variable
 

Detailed Description

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

Configuration

Define to remove corresponding command: COSA_DEBUG_NO_BACKTRACE COSA_DEBUG_NO_HELP COSA_DEBUG_NO_LOOKUP_VARIABLES COSA_DEBUG_NO_MEMORY_USAGE COSA_DEBUG_NO_PRINT_DATA COSA_DEBUG_NO_PRINT_HEAP COSA_DEBUG_NO_PRINT_STACK COSA_DEBUG_NO_PRINT_VARIABLES COSA_DEBUG_NO_QUIT COSA_DEBUG_NO_WHERE May be used to reduce memory footprint and allow debugging with limited resources.

Definition at line 48 of file Debug.hh.

Member Typedef Documentation

typedef IOStream&(* IOStream::Manipulator) (IOStream &)
inherited

Stream manipulator function prototype. To allow implementation of base change and end of line.

Parameters
[in]iostream.
Returns
iostream.

Definition at line 538 of file IOStream.hh.

Member Enumeration Documentation

enum IOStream::Base
inherited

Base conversion.

Enumerator
bcd 
bin 
oct 
dec 
hex 

Definition at line 43 of file IOStream.hh.

enum IOStream::Mode
inherited

End of line modes.

Enumerator
CR_MODE 
LF_MODE 
CRLF_MODE 

Definition at line 54 of file IOStream.hh.

Constructor & Destructor Documentation

Debug::Debug ( )
inline

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

Definition at line 53 of file Debug.hh.

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 45 of file Debug.cpp.

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

Start debug handler with given iostream device, 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]deviostream device for debug handler.
[in]filename.
[in]linenumber.
[in]funcfunction name.
Returns
bool.

Definition at line 28 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 58 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 68 of file Debug.cpp.

Device* IOStream::device ( ) const
inlineinherited

Get current device.

Returns
device.

Definition at line 265 of file IOStream.hh.

Device* IOStream::device ( Device dev)
inlineinherited

Set io stream device.

Parameters
[in]devstream device.
Returns
previous device.

Definition at line 275 of file IOStream.hh.

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

Print backtrace.

Parameters
[in]funcdebug entry function.

Definition at line 187 of file Debug.cpp.

void Debug::do_help ( )
protected

Print list of commands and short description.

Definition at line 200 of file Debug.cpp.

bool Debug::do_lookup_variables ( const char *  name)
protected

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

Parameters
[in]nameof variable.

Definition at line 238 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 253 of file Debug.cpp.

void Debug::do_print_data ( )
protected

Print contents of data segment in hex format.

Definition at line 266 of file Debug.cpp.

void Debug::do_print_heap ( )
protected

Print contents of heap in hex format.

Definition at line 274 of file Debug.cpp.

void Debug::do_print_stack ( int  marker)
protected

Print contents of stack in hex format.

Definition at line 286 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 296 of file Debug.cpp.

void Debug::do_quit ( )
protected

Stop the sketch.

bool Debug::end ( )

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

Returns
bool.

Definition at line 77 of file Debug.cpp.

str_P IOStream::eol ( ) const
inlineinherited

Get io stream end of line string.

Returns
string for end of line.

Definition at line 286 of file IOStream.hh.

str_P IOStream::EOL ( ) const
inlineinherited

Get io stream end of line string.

Returns
string for end of line.

Definition at line 295 of file IOStream.hh.

void IOStream::eol ( str_P  s)
inlineinherited

Set io stream end of line string.

Parameters
[in]sstring for end of line.

Definition at line 304 of file IOStream.hh.

void IOStream::flush ( )
inlineinherited

Flush contents of iostream to stream.

Definition at line 504 of file IOStream.hh.

char * IOStream::itoa ( int  __val,
char *  __s,
int  base 
)
staticinherited

Definition at line 144 of file IOStream_dtoa.cpp.

char * IOStream::ltoa ( long  __val,
char *  __s,
int  base 
)
staticinherited

Definition at line 129 of file IOStream_dtoa.cpp.

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

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 119 of file Debug.hh.

IOStream& IOStream::operator<< ( Manipulator  func)
inlineinherited

Output operator for stream manipulator. Apply function.

Parameters
[in]funciostream manipulator.
Returns
iostream.

Definition at line 545 of file IOStream.hh.

IOStream& IOStream::operator<< ( int  n)
inlineinherited

Print integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 556 of file IOStream.hh.

IOStream& IOStream::operator<< ( long int  n)
inlineinherited

Print long integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 569 of file IOStream.hh.

IOStream& IOStream::operator<< ( double  n)
inlineinherited

Print double as string with the current field min width and number of decimals. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 583 of file IOStream.hh.

IOStream& IOStream::operator<< ( unsigned int  n)
inlineinherited

Print unsigned integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 596 of file IOStream.hh.

IOStream& IOStream::operator<< ( unsigned long int  n)
inlineinherited

Print unsigned long integer as string in the current base to stream. Reset base to decimal.

Parameters
[in]nvalue to print.
Returns
iostream.

Definition at line 609 of file IOStream.hh.

IOStream& IOStream::operator<< ( void *  ptr)
inlineinherited

Print pointer as a hexadecimal number string to stream.

Parameters
[in]ptrpointer to print.
Returns
iostream.

Definition at line 621 of file IOStream.hh.

IOStream& IOStream::operator<< ( const void *  ptr)
inlineinherited

Print program memory pointer as a hexadecimal number string to stream.

Parameters
[in]ptrprogram memory pointer to print.
Returns
iostream.

Definition at line 634 of file IOStream.hh.

IOStream& IOStream::operator<< ( char  c)
inlineinherited

Print character to stream.

Parameters
[in]ccharacter to print.
Returns
iostream.

Definition at line 646 of file IOStream.hh.

IOStream& IOStream::operator<< ( char *  s)
inlineinherited

Print null terminated string to stream.

Parameters
[in]sstring to print.
Returns
iostream.

Definition at line 657 of file IOStream.hh.

IOStream& IOStream::operator<< ( const char *  s)
inlineinherited

Print null terminated string in program memory to stream.

Parameters
[in]sstring in program memory to print.
Returns
iostream.

Definition at line 668 of file IOStream.hh.

IOStream& IOStream::operator<< ( str_P  s)
inlineinherited

Print null terminated string in program memory to stream.

Parameters
[in]sstring in program memory to print.
Returns
iostream.

Definition at line 679 of file IOStream.hh.

IOStream& IOStream::operator<< ( IOStream buffer)
inlineinherited

Print contents of iobuffer to stream.

Parameters
[in]bufferinput/output buffer.
Returns
iostream.

Definition at line 690 of file IOStream.hh.

IOStream& IOStream::operator<< ( const iovec_t vec)
inlineinherited

Print contents of iovector to stream.

Parameters
[in]veciovector.
Returns
iostream.

Definition at line 701 of file IOStream.hh.

uint8_t IOStream::precision ( uint8_t  value)
inlineinherited

Set number of digits after decimal point for double numbers.

Parameters
[in]valueprecision.
Returns
previous precision.

Definition at line 327 of file IOStream.hh.

void IOStream::print ( int  value,
Base  base = dec 
)
inherited

Print integer as string with given base to stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 46 of file IOStream.cpp.

void IOStream::print ( long int  value,
Base  base = dec 
)
inherited

Print long integer 32-bit value in given base torace stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 65 of file IOStream.cpp.

void IOStream::print ( unsigned int  value,
Base  base = dec 
)
inherited

Print unsigned integer as string with given base to stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 73 of file IOStream.cpp.

void IOStream::print ( unsigned long int  value,
Base  base = dec 
)
inherited

Print unsigned long integer 32-bit value in given base to stream.

Parameters
[in]valueto print.
[in]baseto represent value in (default 10).

Definition at line 81 of file IOStream.cpp.

void IOStream::print ( unsigned int  value,
uint8_t  digits,
Base  base 
)
inherited

Print unsigned integer as string with given base to stream.

Parameters
[in]valueto print.
[in]digitsto print.
[in]baseto represent value in.

Definition at line 89 of file IOStream.cpp.

void IOStream::print ( unsigned long int  value,
uint8_t  digits,
Base  base 
)
inherited

Print unsigned long integer 32-bit value in given base to stream.

Parameters
[in]valueto print.
[in]digitsto print.
[in]baseto represent value in.

Definition at line 99 of file IOStream.cpp.

void IOStream::print ( double  value,
int8_t  width,
uint8_t  prec 
)
inherited

Print double with the minimum field width of the output string (including the '.' and the possible sign for negative values) is given in width, and prec determines the number of digits after the decimal sign. width is signed value, negative for left adjustment.

Parameters
[in]valueto print.
[in]widthminimum field width.
[in]precnumber of digits.

Definition at line 109 of file IOStream.cpp.

void IOStream::print ( uint32_t  src,
const void *  ptr,
size_t  size,
Base  base = dec,
uint8_t  max = 16 
)
inherited

Print buffer contents in given base to stream.

Parameters
[in]srcaddress prefix.
[in]ptrpointer to data memory.
[in]sizenumber of bytes.
[in]baseto represent value in (default 10).
[in]maxnumber of numbers per line (default 16).

Definition at line 136 of file IOStream.cpp.

void IOStream::print ( const void *  ptr,
size_t  size,
Base  base = dec,
uint8_t  max = 16 
)
inlineinherited

Print buffer contents in given base to stream.

Parameters
[in]ptrpointer to data memory.
[in]sizenumber of bytes.
[in]baseto represent value in (default 10).
[in]maxnumber of numbers per line (default 16).

Definition at line 408 of file IOStream.hh.

void IOStream::print ( void *  ptr)
inlineinherited

Print pointer as a hexadecimal number to stream.

Parameters
[in]ptrpointer to data memory.

Definition at line 418 of file IOStream.hh.

void IOStream::print ( const void *  ptr)
inlineinherited

Print pointer to program memory as a hexadecimal number to stream.

Parameters
[in]ptrpointer to program memory.

Definition at line 428 of file IOStream.hh.

void IOStream::print ( char  c)
inlineinherited

Print character to stream.

Parameters
[in]ccharacter to print.

Definition at line 437 of file IOStream.hh.

void IOStream::print ( const char *  s)
inlineinherited

Print string in data memory to stream.

Parameters
[in]spointer to data memory string.

Definition at line 447 of file IOStream.hh.

void IOStream::print ( str_P  s)
inlineinherited

Print string in program memory to stream. Use macro PSTR() to generate a string constants in program memory.

Parameters
[in]spointer to program memory string.

Definition at line 458 of file IOStream.hh.

void IOStream::print ( IOStream::Device buffer)
inherited

Print contents of iostream to stream.

Parameters
[in]bufferinput/output buffer.

Definition at line 117 of file IOStream.cpp.

void IOStream::print_prefix ( Base  base)
protectedinherited

Print number prefix for non decimal base.

Parameters
[in]baserepresentation.

Definition at line 125 of file IOStream.cpp.

void IOStream::printf ( str_P  format,
  ... 
)
inlineinherited

Formated print with variable argument list. The format string should be in program memory. Use the macro PSTR().

Parameters
[in]formatstring in program memory.
[in]...variable argument list.

Definition at line 487 of file IOStream.hh.

void IOStream::println ( )
inlineinherited

Print end of line to stream.

Definition at line 467 of file IOStream.hh.

char * IOStream::readline ( char *  buf,
size_t  size,
bool  echo = true 
)
inherited

Read line into the given buffer. Characters received from the device is appended to the end of the string until end of line is received. The buffer pointer is returned with a complete line has been received otherwise NULL. The function will append until the given size of reached.

Parameters
[in]bufbuffer for received line.
[in]sizeof buffer.
[in]echocharacter mode (Default true).
Returns
NULL or pointer to buffer when line received.

Definition at line 262 of file IOStream.cpp.

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 85 of file Debug.cpp.

char * IOStream::scan ( char *  s,
size_t  count 
)
inherited

Scan next token from the input stream. Returns pointer to string or NULL if not stream is empty.

Parameters
[in]sstring buffer to read into.
[in]countmax number of bytes to read.
Returns
string pointer or NULL.

Definition at line 224 of file IOStream.cpp.

char * IOStream::ultoa ( unsigned long  __val,
char *  __s,
int  base 
)
staticinherited

Definition at line 51 of file IOStream_dtoa.cpp.

char * IOStream::utoa ( unsigned int  __val,
char *  __s,
int  base 
)
staticinherited

Definition at line 138 of file IOStream_dtoa.cpp.

void IOStream::vprintf ( str_P  format,
va_list  args 
)
inherited

Format print with variable argument list. The format string should be in program memory. Use the macro PSTR().

Parameters
[in]formatstring in program memory.
[in]argsvariable argument list.

Definition at line 163 of file IOStream.cpp.

int8_t IOStream::width ( int8_t  value)
inlineinherited

Set minimum width for double numbers. The width is signed value, negative for left adjustment.

Parameters
[in]valuewidth.
Returns
previous width.

Definition at line 315 of file IOStream.hh.

Friends And Related Function Documentation

friend class Variable
friend

Definition at line 266 of file Debug.hh.

Member Data Documentation

const size_t IOStream::BUF_MAX = sizeof(uint32_t) * CHARBITS + 1
staticprotectedinherited

Maximum size of required buffer for string conversion.

Definition at line 730 of file IOStream.hh.

const char IOStream::CR[]
staticinherited

End Of Line character sequences

Definition at line 36 of file IOStream.hh.

const char IOStream::CRLF = "\r\n"
staticinherited

Definition at line 38 of file IOStream.hh.

int Debug::DATAEND
protected

End of data segment.

Definition at line 269 of file Debug.hh.

int Debug::DATASIZE
protected

Size of data segment.

Definition at line 270 of file Debug.hh.

const int IOStream::EOF = -1
staticinherited

End Of File, returned when device operations fails (empty or full).

Definition at line 33 of file IOStream.hh.

char Debug::EXITCHARACTER
protected

Character to emit on exit.

Definition at line 268 of file Debug.hh.

const char IOStream::LF = "\r"
staticinherited

Definition at line 37 of file IOStream.hh.

Base IOStream::m_base
protectedinherited

Base for next output operator.

Definition at line 724 of file IOStream.hh.

Device* IOStream::m_dev
protectedinherited

Delegated device.

Definition at line 723 of file IOStream.hh.

str_P IOStream::m_eols
protectedinherited

End of line string (program memory).

Definition at line 727 of file IOStream.hh.

uint8_t IOStream::m_prec
protectedinherited

Number of digits after decimal sign.

Definition at line 726 of file IOStream.hh.

Variable* Debug::m_var
protected

Last registered variable.

Definition at line 267 of file Debug.hh.

int8_t IOStream::m_width
protectedinherited

Minimum width of output string.

Definition at line 725 of file IOStream.hh.


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