22 #define VERSION "1.0a3" 34 if (
m_dev != NULL)
return (
false);
39 ", Copyright (C) 2015-2016, Mikael Patel\n" 40 "For help, type \"help\".\n" 42 run(file, line, func);
52 print(F(
"Debug::assert"));
53 run(file, line, func, cond);
64 print(F(
"Debug::break_at"));
65 run(file, line, func, cond);
71 uint16_t marker = 0xA5A5;
72 int HEAPEND = (__brkval == 0 ? (int) &__heap_start : (
int)
__brkval);
73 int STACKSTART = (int) ▮
74 return (STACKSTART > HEAPEND + room);
84 print(F(
"Debug::observe_at:"));
96 if (
m_dev == NULL)
return (
false);
97 println(F(
"Debug::end"));
116 if (func != NULL) println();
118 uint16_t marker = 0xA5A5;
119 str_P prompt = F(
"(debug) ");
129 if (c ==
'\r' || c ==
'\n')
break;
140 size_t len = bp -
buf;
141 if (len == 0)
continue;
143 if (!strncmp_P(buf, PSTR(
"go"), len))
return;
145 #if !defined(DEBUG_NO_BACKTRACE) 146 if (!strncmp_P(buf, PSTR(
"backtrace"), len)) {
148 print((
int) &marker, HEX);
156 #if !defined(DEBUG_NO_PRINT_DATA) 157 if (!strncmp_P(buf, PSTR(
"data"), len)) {
163 #if !defined(DEBUG_NO_PRINT_HEAP) 164 if (!strncmp_P(buf, PSTR(
"heap"), len)) {
170 #if !defined(DEBUG_NO_MEMORY_USAGE) 171 if (!strncmp_P(buf, PSTR(
"memory"), len)) {
177 #if !defined(DEBUG_NO_PRINT_COMMANDS) 178 if (!strncmp_P(buf, PSTR(
"commands"), len)
179 || !strncmp_P(buf, PSTR(
"help"), len)) {
185 #if !defined(DEBUG_NO_PRINT_STACK) 186 if (!strncmp_P(buf, PSTR(
"stack"), len)) {
192 #if !defined(DEBUG_NO_PRINT_VARIABLES) 193 if (!strncmp_P(buf, PSTR(
"variables"), len)) {
199 #if !defined(DEBUG_NO_QUIT) 200 if (!strncmp_P(buf, PSTR(
"quit"), len)) {
206 #if !defined(DEBUG_NO_WHERE) 207 if (!strncmp_P(buf, PSTR(
"where"), len)) {
217 #if !defined(DEBUG_NO_LOOKUP_VARIABLES) 218 if (*buf ==
'?' || *buf ==
'@' ) {
219 const char* name = buf + 1;
222 println(F(
": unknown variable"));
228 println(F(
": unknown command"));
232 #if !defined(DEBUG_NO_BACKTRACE) 237 if (func != vp->m_func) {
240 print((
int) vp, HEX);
248 #if !defined(DEBUG_NO_LOOKUP_VARIABLES) 254 if (strcmp_P(name, (
const char*) vp->m_name) == 0) {
255 if (!is_pointer || (vp->m_size ==
sizeof(
void*)))
256 vp->print(is_pointer);
264 #if !defined(DEBUG_NO_MEMORY_USAGE) 268 int HEAPEND = (__brkval == 0 ? (int) &__heap_start : (
int)
__brkval);
272 print(HEAPEND - (
int) &__heap_start);
274 print(RAMEND - marker + 1);
276 println(marker - HEAPEND);
280 #if !defined(DEBUG_NO_PRINT_COMMANDS) 284 static const char help[] PROGMEM =
285 #if !defined(DEBUG_NO_LOOKUP_VARIABLES) 286 "?VARIABLE -- Print variable(s)\n" 287 "@VARIABLE -- Print pointer variable(s)\n" 289 #if !defined(DEBUG_NO_BACKTRACE) 290 "backtrace -- Print call stack\n" 292 #if !defined(DEBUG_NO_PRINT_DATA) 293 "data -- Print data\n" 295 "go -- Return to sketch\n" 296 #if !defined(DEBUG_NO_PRINT_HEAP) 297 "heap -- Print heap\n" 299 #if !defined(DEBUG_NO_MEMORY_USAGE) 300 "memory -- Print memory usage\n" 302 #if !defined(DEBUG_NO_QUIT) 303 "quit -- Exit sketch\n" 305 #if !defined(DEBUG_NO_PRINT_STACK) 306 "stack -- Print stack\n" 308 #if !defined(DEBUG_NO_PRINT_REGISTER) 309 "variables -- Print variables\n" 311 #if !defined(DEBUG_NO_WHERE) 312 "where -- Location in source code\n" 319 #if !defined(DEBUG_NO_PRINT_DATA) 327 #if !defined(DEBUG_NO_PRINT_HEAP) 331 int HEAPSTART = (int) &__heap_start;
332 int HEAPEND = (__brkval == 0 ? (int) &__heap_start : (
int)
__brkval);
333 int size = HEAPEND - HEAPSTART;
334 if (size == 0)
return;
335 dump((uint16_t) HEAPSTART, (
void*) HEAPSTART, size);
339 #if !defined(DEBUG_NO_PRINT_STACK) 343 int size = RAMEND - marker + 1;
344 if (size == 0)
return;
345 dump((uint16_t) marker, (
void*) marker, size);
349 #if !defined(DEBUG_NO_PRINT_VARIABLES) 364 debug.print(F(
"0x"));
365 debug.print((
int) m_ref, HEX);
366 if (m_size ==
sizeof(
void*) && is_pointer) {
367 int* ptr = *((
int**) m_ref);
368 debug.print(F(
"=>"));
374 debug.print(*((uint8_t*) m_ref));
375 debug.print(F(
" (0x"));
376 debug.print(*((uint8_t*) m_ref), HEX);
379 else if (m_size == 2) {
381 debug.print(*((
int*) m_ref));
382 debug.print(F(
" (0x"));
383 debug.print(*((uint16_t*) m_ref), HEX);
389 debug.print(F(
"]:"));
390 if (m_size > 16)
debug.println();
391 debug.
dump((uint16_t) m_ref, m_ref, m_size);
399 uint8_t* p = (uint8_t*) ptr;
407 print(d & 0x0F, HEX);
422 if (n != 0) println();
const class __FlashStringHelper * str_P
void run(const char *file=NULL, int line=0, const char *func=NULL, str_P expr=NULL)
void do_print_stack(int marker)
bool check_stack(int room=128)
void observe_at(const char *file, int line, const char *func, str_P expr)
void do_print_variables()
bool begin(Stream *dev, const char *file, int line, const char *func)
void do_backtrace(const char *func)
void assert(const char *file, int line, const char *func, str_P cond)
Variable * m_var
Last registered variable.
void print(bool is_pointer=false)
void dump(uint16_t src, const void *ptr, size_t size)
Stream * m_dev
Debug stream.
void do_memory_usage(int marker)
int DATAEND
End of data segment.
void break_at(const char *file, int line, const char *func, str_P cond)
int DATASIZE
Size of data segment.
bool do_lookup_variables(const char *name, bool is_pointer=false)
class Variable * m_next
Next variable.