• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    C++
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ““ A dead-simple tracing library to debug your Arduino programs

A quote from Brian Kernighan

ArduinoTrace

arduino-library-badge Continuous Integration

A dead-simple tracing library to debug your Arduino programs.

Example

All you need to do is call TRACE() or DUMP(variable).

#include <ArduinoTrace.h>

int value = 0;

void setup() {
  Serial.begin(9600);
  TRACE();
}

void loop() {
  value++;
  DUMP(value);
  BREAK();
}

The program above would print:

MyProgram.ino:7: void setup()
MyProgram.ino:12: value = 1
MyProgram.ino:13: BREAK! (press [enter] to continue)
MyProgram.ino:12: value = 2
MyProgram.ino:13: BREAK! (press [enter] to continue)
MyProgram.ino:12: value = 3
MyProgram.ino:13: BREAK! (press [enter] to continue)
...

Features

  • TRACE() prints:
    • filename
    • line number
    • function's name
    • function's parameters
    • template parameters (if any)
  • DUMP(variable) prints:
    • filename
    • line number
    • variable's name
    • variable's value
  • BREAK() pauses the program until you send a line-break to the Serial
  • TRACE() and DUMP(variable) work at global scope, provided that you call ARDUINOTRACE_INIT() to initialize the Serial port.
  • Flushes the Serial port to make sure that each line is complete
  • Uses Flash memory when possible
  • Deduplicates strings a much as reasonable feasible
  • Header-only
  • Roughly 200 lines of code

A simple recipe to find where the code crashes

  1. sprinkle your code with TRACE() and DUMP(variable)
  2. run the program
  3. view all traces in the Serial monitor
  4. repeat the process until you find the line that causes the crash

Configuration

Setting Default Description
ARDUINOTRACE_ENABLE 1 Determines whether the library is active. If set to 1, ArduinoTrace is active, and prints traces to the serial port. Set this value to 0 to disable all the traces at once.
ARDUINOTRACE_ENABLE_PROGMEM 1 Determines whether the strings are stored in Flash or RAM. If defined to 1 (it's the default), ArduinoTrace places the string in the Flash memory to reduce the memory consumption. Only set this value to 0 if you have a compilation issue.
ARDUINOTRACE_ENABLE_FULLPATH 0 Determines how the filename is written. If set to 1, ArduinoTrace prints the full path of the file. If set to 0, ArduinoTrace only prints the filename.
ARDUINOTRACE_SERIAL Serial Define the serial port to use. Change this value to use an alternative serial port, for example, SerialUSB.

To change one of the settings above, you must define the symbol before including the library. For example:

#define ARDUINOTRACE_ENABLE 0  // Disable all traces
#include <ArduinoTrace.h>

FAQ

Is there a performance impact?

Of course, there is! Your program will become fat and slow, so it's essential to use this library only when debugging.

You should never use it in production.

You should never commit a program with traces.

Does this library replace my logging library?

Absolutely not! Tracing and logging are different things.

Logging is recording (possibly in an SD card) the important things that happen in a program so that we can do a post-mortem analysis, in case something goes wrong.

Tracing is recording every little step to narrow down the area of analysis when you're fixing a bug. It's a technique that you use for short periods of time, during a debugging session. Again, you should not commit code that contains traces.

In short: logging is something you do in production, tracing is something you do while debugging.

Why not use a debugger instead?

Sometimes, you cannot use a debugger. In this case, you can always go back to the good-old tracing technique.

And what about EspExceptionDecoder?

EspExceptionDecoder is an awesome tool, but unfortunately, the results are not always accurate; you often see unrelated function names in the stack. I don't know why that happens (I guess it's due to compiler optimizations), but whatever the reason, it's still good to have a fallback option.

Tutorials

Want to see how this library works?

Youtube video: How to debug any Arduino program with tracing

More Repositories

1

ArduinoJson

๐Ÿ“Ÿ JSON library for Arduino and embedded C++. Simple and efficient.
C++
6,718
star
2

pdfium-binaries

๐Ÿ“ฐ Binary distribution of PDFium
Shell
887
star
3

ArduinoStreamUtils

๐Ÿ’ช Power-ups for Arduino streams
C++
258
star
4

django-htmx-modal-form

Django+HTMX modal form
Python
100
star
5

WpfBindingErrors

๐Ÿ’ฅ Turn WPF Binding errors into exception
C#
78
star
6

django-htmx-messages-framework

Django+HTMX: integration with the messages framework
Python
51
star
7

dllhelper

How to GetProcAddress() like a boss ๐Ÿ˜Ž
C++
50
star
8

cpp4arduino

Samples files for cpp4arduino.com
C++
48
star
9

ArduinoContinuousStepper

An Arduino library to spin stepper motors in continuous motions.
C++
39
star
10

disable-windows-keys

A tiny application that disables the Windows keys of your keyboard. Very useful in games!
C
21
star
11

HighSpeedMvvm

โšก๏ธ MVVM : How to deal with fast changing properties ?
C#
19
star
12

ArduinoJsonAssistant

Source code of the ArduinoJson Assistant
JavaScript
13
star
13

SublimeText-HighlightBuildErrors

๐Ÿ‘ป A plugin for Sublime Text 3 that highlights the lines that caused errors in the build
Python
12
star
14

BuckOperator

๐Ÿ’ฒ The C++ "buck" operator (aka the dollar sign operator)
C++
10
star
15

BlogRipper

Get links to all articles of a blog
Python
8
star
16

HpglViewer

An application to view HPGL files
C#
6
star
17

ArduinoJson-vs-Arduino_JSON

ArduinoJson vs Arduino_JSON
C++
3
star
18

CsharpLeetSpeak

Proof of concept: modify literal strings of an assembly at runtime
C#
2
star
19

django-sse-demo

Proof of concept implementation for server sent event with Django 3.1 async views
Python
2
star
20

CodeJam

My attempts to solve the puzzles of Code Jam
C#
2
star
21

UnhandledExceptions

Dealing with unhandled exception in C# projects
C#
2
star
22

ArduinoJsonTroubleshooter

Source code of the ArduinoJson Troubleshooter
Vue
1
star
23

conan-ArduinoJson

Conan.io package for ArduinoJson
Python
1
star
24

RecursiveCleaner

Keep your hard-drive tidy with XML rules
C#
1
star
25

WpfAttachedProperties

WPF: attached properties as an alternative to code behind
C#
1
star
26

PlayWithKodi

A Chrome extension to send videos to Kodi
JavaScript
1
star
27

ArduinoJson-msgpack.org

MessagePack library for Arduino and embedded C++ | msgpack.org[Arduino/C++]
1
star