├── .clang-format ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ └── lock.yml ├── .gitignore ├── ArduinoTrace.h ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── examples ├── BasicTracing │ └── BasicTracing.ino └── TraceFromGlobalScope │ └── TraceFromGlobalScope.ino ├── extras ├── img │ ├── banner.png │ └── video-thumbnail.png └── test │ ├── Arduino.h │ ├── CMakeLists.txt │ ├── myassert.h │ ├── test_alternative_serial.cpp │ ├── test_defaults.cpp │ ├── test_disabled.cpp │ └── test_full_path.cpp ├── keywords.txt ├── library.json └── library.properties /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: bblanchon 2 | custom: 3 | - https://arduinojson.org/book/ 4 | - https://paypal.me/benoitblanchon -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | name: Test 8 | runs-on: ubuntu-20.04 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | - name: Configure 13 | run: cmake -DCMAKE_BUILD_TYPE=Debug . 14 | - name: Build 15 | run: cmake --build . 16 | - name: Test 17 | run: ctest --output-on-failure -C Debug . 18 | -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | name: Lock Threads 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | 7 | jobs: 8 | lock: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: dessant/lock-threads@v2 12 | with: 13 | github-token: ${{ github.token }} 14 | issue-lock-inactive-days: 30 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ArduinoTrace.h: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018-2021 3 | // MIT License 4 | // 5 | // A simple tracing macro to debug you program. 6 | // 7 | // Recipe to find where the code crashes: 8 | // 1. sprinkle your code with TRACE() 9 | // 2. run the program 10 | // 3. view all traces in the Serial monitor 11 | // 12 | // Each trace includes the: 13 | // * the filename 14 | // * the line number 15 | // * the current function 16 | // * the template parameters (if any) 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #ifndef ARDUINOTRACE_ENABLE 23 | #define ARDUINOTRACE_ENABLE 1 24 | #endif 25 | 26 | #if ARDUINOTRACE_ENABLE == 1 27 | 28 | #ifndef ARDUINOTRACE_SERIAL 29 | #define ARDUINOTRACE_SERIAL Serial 30 | #endif 31 | 32 | #ifndef ARDUINOTRACE_ENABLE_PROGMEM 33 | #ifdef PROGMEM 34 | #define ARDUINOTRACE_ENABLE_PROGMEM 1 35 | #else 36 | #define ARDUINOTRACE_ENABLE_PROGMEM 0 37 | #endif 38 | #endif 39 | 40 | #ifndef ARDUINOTRACE_ENABLE_FULLPATH 41 | #define ARDUINOTRACE_ENABLE_FULLPATH 0 42 | #endif 43 | 44 | #ifndef ARDUINOTRACE_FUNCTION_NAME_IN_FLASH 45 | #if defined(ESP8266) 46 | #define ARDUINOTRACE_FUNCTION_NAME_IN_FLASH 1 47 | #else 48 | #define ARDUINOTRACE_FUNCTION_NAME_IN_FLASH 0 49 | #endif 50 | #endif 51 | 52 | namespace ArduinoTrace { 53 | constexpr size_t strlen(const char *str) { 54 | return str[0] ? strlen(str + 1) + 1 : 0; 55 | } 56 | 57 | template 58 | struct string { 59 | #if ARDUINOTRACE_ENABLE_PROGMEM 60 | const __FlashStringHelper *data() { 61 | static const char buffer[] PROGMEM = {chars...}; 62 | return reinterpret_cast(buffer); 63 | } 64 | #else 65 | const char *data() { 66 | static const char buffer[] = {chars...}; 67 | return buffer; 68 | } 69 | #endif 70 | }; 71 | 72 | template 74 | struct string_maker { 75 | using result = 76 | typename string_maker::result; 79 | }; 80 | 81 | #if ARDUINOTRACE_ENABLE_FULLPATH == 0 82 | template 84 | struct string_maker { 85 | using result = string; 86 | }; 87 | 88 | template 90 | struct string_maker { 91 | using result = string; 92 | }; 93 | #endif 94 | 95 | template 96 | struct string_maker { 97 | using result = string; 98 | }; 99 | 100 | template 101 | using make_string = 102 | typename string_maker::result; 103 | 104 | struct Initializer { 105 | template 106 | Initializer(TSerial &serial, int bauds) { 107 | serial.begin(bauds); 108 | while (!serial) continue; 109 | } 110 | }; 111 | 112 | template 113 | struct Printer { 114 | template 115 | Printer(TSerial &serial, const TValue &content) { 116 | serial.print(make_string{}.data()); 117 | serial.print(make_string{}.data()); 118 | serial.println(content); 119 | serial.flush(); 120 | } 121 | }; 122 | 123 | template 124 | inline void pause(TSerial &serial) { 125 | while (serial.read() != '\n') delay(10); 126 | } 127 | } // namespace ArduinoTrace 128 | 129 | #define ARDUINOTRACE_STRINGIFY(X) #X 130 | #define ARDUINOTRACE_CONCAT(X, Y) X##Y 131 | 132 | #if ARDUINOTRACE_ENABLE_PROGMEM 133 | #define ARDUINOTRACE_FLASHIFY(X) F(X) 134 | #else 135 | #define ARDUINOTRACE_FLASHIFY(X) X 136 | #endif 137 | 138 | #if ARDUINOTRACE_FUNCTION_NAME_IN_FLASH 139 | #define ARDUINOTRACE_FUNCTION_NAME \ 140 | reinterpret_cast(__PRETTY_FUNCTION__) 141 | #else 142 | #define ARDUINOTRACE_FUNCTION_NAME __PRETTY_FUNCTION__ 143 | #endif 144 | 145 | #define ARDUINOTRACE_PRINT(id, file, prefix, content) \ 146 | { \ 147 | struct __filename { \ 148 | constexpr static char const *data() { return file; } \ 149 | }; \ 150 | struct __prefix { \ 151 | constexpr static char const *data() { return prefix; } \ 152 | }; \ 153 | ArduinoTrace::Printer<__filename, __prefix> __tracer(ARDUINOTRACE_SERIAL, \ 154 | content); \ 155 | } 156 | 157 | #define ARDUINOTRACE_INITIALIZE(id, bauds) \ 158 | ArduinoTrace::Initializer ARDUINOTRACE_CONCAT(__initializer, id)( \ 159 | ARDUINOTRACE_SERIAL, bauds); 160 | 161 | #define ARDUINOTRACE_TRACE_PREFIX(line) ":" ARDUINOTRACE_STRINGIFY(line) ": " 162 | 163 | #define ARDUINOTRACE_DUMP_PREFIX(line, variable) \ 164 | ":" ARDUINOTRACE_STRINGIFY(line) ": " #variable " = " 165 | 166 | // Initializes the Serial port 167 | // 168 | // Use this macro only if you want to call TRACE() at global scope, 169 | // in other cases, call Serial.begin() in your setup() function, as usual. 170 | #define ARDUINOTRACE_INIT(bauds) ARDUINOTRACE_INITIALIZE(__COUNTER__, bauds); 171 | 172 | // Adds a trace in the Serial port 173 | // 174 | // Call this macro anywhere, including at global scope. 175 | // However, if you use it at global scope, you need to call ARDUINOTRACE_INIT() 176 | // first, otherwise, the Serial port will not be ready. 177 | #define TRACE() \ 178 | ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, \ 179 | ARDUINOTRACE_TRACE_PREFIX(__LINE__), \ 180 | ARDUINOTRACE_FUNCTION_NAME) 181 | 182 | // Prints the value of a variable. 183 | // 184 | // This function will print the name and the value of the variable to the 185 | // Serial. If you use it at global scope, you need to call ARDUINOTRACE_INIT() 186 | // first, otherwise, the Serial port will not be ready. 187 | #define DUMP(variable) \ 188 | ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, \ 189 | ARDUINOTRACE_DUMP_PREFIX(__LINE__, variable), variable) 190 | 191 | #define BREAK() \ 192 | do { \ 193 | ARDUINOTRACE_PRINT(__COUNTER__, __FILE__, \ 194 | ARDUINOTRACE_TRACE_PREFIX(__LINE__), \ 195 | "BREAK! (press [enter] to continue)"); \ 196 | ArduinoTrace::pause(ARDUINOTRACE_SERIAL); \ 197 | } while (false) 198 | 199 | #else // ie ARDUINOTRACE_ENABLE == 0 200 | 201 | #define ARDUINOTRACE_INIT(bauds) 202 | #define TRACE() 203 | #define DUMP(variable) 204 | #define BREAK() 205 | 206 | #endif -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ArduinoTrace: changelog 2 | ======================= 3 | 4 | 1.2.0 (2021/02/07) 5 | ------------------ 6 | 7 | * Added `BREAK()` macro (issue #8) 8 | * Fixed `ARDUINOTRACE_ENABLE_FULLPATH` being overwritten 9 | 10 | 1.1.2 (2020/03/20) 11 | ------------------ 12 | 13 | * Move auxiliary content to `extras/` to comply with new library layout 14 | * Fixed TRACE() crashing ESP8266 with PlatformIO 15 | 16 | 1.1.1 (2019/04/15) 17 | ------------------ 18 | 19 | * Fixed warning: "ARDUINOTRACE_ENABLE" redefined 20 | 21 | 1.1.0 (2019/03/30) 22 | ------------------ 23 | 24 | * Added `ARDUINOTRACE_SERIAL` to allow changing the serial port (issue #1) 25 | * Reduced the program size by storing each file name only once 26 | * Enabled Flash string on ESP8266 27 | * Print only the filename instead of the full path 28 | (You can set `ARDUINOTRACE_ENABLE_FULLPATH` to `1` to restore the original behavior) 29 | * Added `ARDUINOTRACE_ENABLE` to enable/disable all traces at once (issue #2) 30 | 31 | 1.0.0 (2018/07/19) 32 | ------------------ 33 | 34 | Initial release. 35 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(ArduinoTrace) 3 | enable_testing() 4 | 5 | include_directories(.) 6 | 7 | add_subdirectory(extras/test) -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | --------------------- 3 | 4 | Copyright © 2018-2021 Benoit BLANCHON 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![A quote from Brian Kernighan](extras/img/banner.png) 2 | 3 | ArduinoTrace 4 | ============ 5 | 6 | [![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoTrace.svg?version=1.2.0)](https://www.ardu-badge.com/ArduinoTrace/1.2.0) 7 | ![Continuous Integration](https://github.com/bblanchon/ArduinoTrace/workflows/Continuous%20Integration/badge.svg) 8 | 9 | A dead-simple tracing library to debug your Arduino programs. 10 | 11 | ## Example 12 | 13 | All you need to do is call `TRACE()` or `DUMP(variable)`. 14 | 15 | ```c++ 16 | #include 17 | 18 | int value = 0; 19 | 20 | void setup() { 21 | Serial.begin(9600); 22 | TRACE(); 23 | } 24 | 25 | void loop() { 26 | value++; 27 | DUMP(value); 28 | BREAK(); 29 | } 30 | ``` 31 | 32 | The program above would print: 33 | 34 | ```text 35 | MyProgram.ino:7: void setup() 36 | MyProgram.ino:12: value = 1 37 | MyProgram.ino:13: BREAK! (press [enter] to continue) 38 | MyProgram.ino:12: value = 2 39 | MyProgram.ino:13: BREAK! (press [enter] to continue) 40 | MyProgram.ino:12: value = 3 41 | MyProgram.ino:13: BREAK! (press [enter] to continue) 42 | ... 43 | ``` 44 | 45 | ## Features 46 | 47 | * `TRACE()` prints: 48 | - filename 49 | - line number 50 | - function's name 51 | - function's parameters 52 | - template parameters (if any) 53 | * `DUMP(variable)` prints: 54 | - filename 55 | - line number 56 | - variable's name 57 | - variable's value 58 | * `BREAK()` pauses the program until you send a line-break to the Serial 59 | * `TRACE()` and `DUMP(variable)` work at global scope, provided that you call `ARDUINOTRACE_INIT()` to initialize the Serial port. 60 | * Flushes the Serial port to make sure that each line is complete 61 | * Uses Flash memory when possible 62 | * Deduplicates strings a much as reasonable feasible 63 | * Header-only 64 | * Roughly 200 lines of code 65 | 66 | ## A simple recipe to find where the code crashes 67 | 68 | 1. sprinkle your code with `TRACE()` and `DUMP(variable)` 69 | 2. run the program 70 | 3. view all traces in the Serial monitor 71 | 4. repeat the process until you find the line that causes the crash 72 | 73 | ## Configuration 74 | 75 | | Setting | Default | Description | 76 | |:-------------------------------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 77 | | `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. | 78 | | `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. | 79 | | `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. | 80 | | `ARDUINOTRACE_SERIAL` | `Serial` | Define the serial port to use. Change this value to use an alternative serial port, for example, `SerialUSB`. | 81 | 82 | To change one of the settings above, you must define the symbol before including the library. For example: 83 | 84 | ```c++ 85 | #define ARDUINOTRACE_ENABLE 0 // Disable all traces 86 | #include 87 | ``` 88 | 89 | ## FAQ 90 | 91 | #### Is there a performance impact? 92 | 93 | Of course, there is! Your program will become fat and slow, so it's essential to use this 94 | library only when debugging. 95 | 96 | You should never use it in production. 97 | 98 | You should never commit a program with traces. 99 | 100 | #### Does this library replace my logging library? 101 | 102 | Absolutely not! Tracing and logging are different things. 103 | 104 | 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. 105 | 106 | Tracing is recording every little step to narrow down the area of analysis when you're 107 | fixing a bug. It's a technique that you use for short periods of time, during a debugging session. 108 | Again, you should not commit code that contains traces. 109 | 110 | In short: logging is something you do in production, tracing is something you do while debugging. 111 | 112 | #### Why not use a debugger instead? 113 | 114 | Sometimes, you cannot use a debugger. 115 | In this case, you can always go back to the good-old tracing technique. 116 | 117 | #### And what about EspExceptionDecoder? 118 | 119 | EspExceptionDecoder is an awesome tool, but unfortunately, the results are not always accurate; you 120 | often see unrelated function names in the stack. 121 | 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. 122 | 123 | ## Tutorials 124 | 125 | * [ESP32 / ESP8266 Arduino: Debugging with the ArduinoTrace library](https://techtutorialsx.com/2018/10/11/esp32-esp8266-arduino-debugging-with-the-arduinotrace-library/) (`techtutorialsx.com`) 126 | * [ESP32 / ESP8266 ArduinoTrace: using the TRACE macro](https://techtutorialsx.com/2018/10/12/esp32-esp8266-arduinotrace-using-the-trace-macro/) (`techtutorialsx.com`) 127 | 128 | ## Want to see how this library works? 129 | 130 | [![Youtube video: How to debug any Arduino program with tracing](extras/img/video-thumbnail.png)](https://youtu.be/JHMpszgzWSg) 131 | -------------------------------------------------------------------------------- /examples/BasicTracing/BasicTracing.ino: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018 3 | // MIT License 4 | 5 | #include 6 | 7 | int value = 0; 8 | 9 | void setup() { 10 | Serial.begin(9600); 11 | TRACE(); 12 | } 13 | 14 | void loop() { 15 | value++; 16 | DUMP(value); 17 | BREAK(); 18 | } 19 | -------------------------------------------------------------------------------- /examples/TraceFromGlobalScope/TraceFromGlobalScope.ino: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018 3 | // MIT License 4 | 5 | #include 6 | 7 | // Call Serial.begin(9600) 8 | ARDUINOTRACE_INIT(9600); 9 | 10 | TRACE(); 11 | 12 | int someValue = 42; 13 | 14 | DUMP(42); 15 | 16 | void setup() {} 17 | void loop() {} 18 | -------------------------------------------------------------------------------- /extras/img/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bblanchon/ArduinoTrace/0cb3ce8c4e8c83506fc1671dd3f139ef4a3f44ab/extras/img/banner.png -------------------------------------------------------------------------------- /extras/img/video-thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bblanchon/ArduinoTrace/0cb3ce8c4e8c83506fc1671dd3f139ef4a3f44ab/extras/img/video-thumbnail.png -------------------------------------------------------------------------------- /extras/test/Arduino.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Flash Strings 4 | typedef char __FlashStringHelper; 5 | #define F(X) (X) 6 | 7 | inline void delay(long) {} 8 | 9 | class SpyingSerial { 10 | public: 11 | operator bool() const { return true; } 12 | 13 | void begin(int baud) { log_ << "begin(" << baud << ")\r\n"; } 14 | void flush() { log_ << "flush()\r\n"; } 15 | int read() { 16 | log_ << "read()\r\n"; 17 | return '\n'; 18 | } 19 | 20 | template 21 | void print(const T &value) { 22 | log_ << value; 23 | } 24 | 25 | template 26 | void println(const T &value) { 27 | log_ << value << "\r\n"; 28 | } 29 | 30 | void clear() { log_.str(""); } 31 | std::string log() const { return log_.str(); } 32 | 33 | private: 34 | std::stringstream log_; 35 | }; 36 | 37 | static SpyingSerial Serial; -------------------------------------------------------------------------------- /extras/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | add_executable(test_defaults test_defaults.cpp) 4 | target_compile_features(test_defaults PRIVATE cxx_std_11) 5 | add_test(defaults test_defaults) 6 | 7 | add_executable(test_alternative_serial test_alternative_serial.cpp) 8 | target_compile_features(test_alternative_serial PRIVATE cxx_std_11) 9 | add_test(alternative_serial test_alternative_serial) 10 | 11 | add_executable(test_full_path test_full_path.cpp) 12 | target_compile_features(test_full_path PRIVATE cxx_std_11) 13 | add_test(full_path test_full_path) 14 | 15 | add_executable(test_disabled test_disabled.cpp) 16 | target_compile_features(test_disabled PRIVATE cxx_std_11) 17 | add_test(disabled test_disabled) -------------------------------------------------------------------------------- /extras/test/myassert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void ASSERT_RE(std::string actual, std::string expected) { 8 | std::regex re(expected); 9 | if (regex_match(actual, re)) 10 | return; 11 | std::cerr << "Assertion failed:\n" 12 | "Expected:\n" 13 | << expected << "\n" 14 | << "but got:\n" 15 | << actual << std::endl; 16 | std::exit(1); 17 | } 18 | -------------------------------------------------------------------------------- /extras/test/test_alternative_serial.cpp: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018-2021 3 | // MIT License 4 | // 5 | 6 | #define ARDUINOTRACE_SERIAL Serial2 7 | #include 8 | 9 | static SpyingSerial Serial2; 10 | 11 | #include "myassert.h" 12 | 13 | void test_trace() { 14 | Serial2.clear(); 15 | TRACE(); 16 | ASSERT_RE(Serial2.log(), 17 | "test_alternative_serial.cpp:\\d+: void test_trace\\(\\)\r\n" 18 | "flush\\(\\)\r\n"); 19 | } 20 | 21 | void test_dump() { 22 | Serial2.clear(); 23 | int answer = 42; 24 | DUMP(answer); 25 | ASSERT_RE(Serial2.log(), 26 | "test_alternative_serial.cpp:\\d+: answer = 42\r\n" 27 | "flush\\(\\)\r\n"); 28 | } 29 | 30 | void test_break() { 31 | Serial2.clear(); 32 | BREAK(); 33 | ASSERT_RE(Serial2.log(), 34 | "test_alternative_serial.cpp:\\d+: BREAK.+\r\n" 35 | "flush\\(\\)\r\n" 36 | "read\\(\\)\r\n"); 37 | } 38 | 39 | void test_init() { 40 | Serial2.clear(); 41 | ARDUINOTRACE_INIT(9600); 42 | ASSERT_RE(Serial2.log(), "begin\\(9600\\)\r\n"); 43 | } 44 | 45 | int main() { 46 | test_trace(); 47 | test_dump(); 48 | test_break(); 49 | test_init(); 50 | } 51 | -------------------------------------------------------------------------------- /extras/test/test_defaults.cpp: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018-2021 3 | // MIT License 4 | // 5 | #include 6 | 7 | #include "myassert.h" 8 | 9 | void test_trace() { 10 | Serial.clear(); 11 | TRACE(); 12 | ASSERT_RE(Serial.log(), 13 | "test_defaults.cpp:\\d+: void test_trace\\(\\)\r\n" 14 | "flush\\(\\)\r\n"); 15 | } 16 | 17 | void test_dump() { 18 | Serial.clear(); 19 | int answer = 42; 20 | DUMP(answer); 21 | ASSERT_RE(Serial.log(), 22 | "test_defaults.cpp:\\d+: answer = 42\r\n" 23 | "flush\\(\\)\r\n"); 24 | } 25 | 26 | void test_break() { 27 | Serial.clear(); 28 | BREAK(); 29 | ASSERT_RE(Serial.log(), 30 | "test_defaults.cpp:\\d+: BREAK.+\r\n" 31 | "flush\\(\\)\r\n" 32 | "read\\(\\)\r\n"); 33 | } 34 | 35 | void test_init() { 36 | Serial.clear(); 37 | ARDUINOTRACE_INIT(9600); 38 | ASSERT_RE(Serial.log(), "begin\\(9600\\)\r\n"); 39 | } 40 | 41 | int main() { 42 | test_trace(); 43 | test_dump(); 44 | test_break(); 45 | test_init(); 46 | } 47 | -------------------------------------------------------------------------------- /extras/test/test_disabled.cpp: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018-2021 3 | // MIT License 4 | // 5 | #define ARDUINOTRACE_ENABLE 0 6 | #include 7 | 8 | #include "myassert.h" 9 | 10 | void test_trace() { 11 | Serial.clear(); 12 | TRACE(); 13 | ASSERT_RE(Serial.log(), ""); 14 | } 15 | 16 | void test_dump() { 17 | Serial.clear(); 18 | int answer = 42; 19 | DUMP(answer); 20 | ASSERT_RE(Serial.log(), ""); 21 | } 22 | 23 | void test_break() { 24 | Serial.clear(); 25 | BREAK(); 26 | ASSERT_RE(Serial.log(), ""); 27 | } 28 | 29 | void test_init() { 30 | Serial.clear(); 31 | ARDUINOTRACE_INIT(9600); 32 | ASSERT_RE(Serial.log(), ""); 33 | } 34 | 35 | int main() { 36 | test_trace(); 37 | test_dump(); 38 | test_break(); 39 | test_init(); 40 | } 41 | -------------------------------------------------------------------------------- /extras/test/test_full_path.cpp: -------------------------------------------------------------------------------- 1 | // ArduinoTrace - github.com/bblanchon/ArduinoTrace 2 | // Copyright Benoit Blanchon 2018-2021 3 | // MIT License 4 | // 5 | #define ARDUINOTRACE_ENABLE_FULLPATH 1 6 | #include 7 | 8 | #include "myassert.h" 9 | 10 | void test_trace() { 11 | Serial.clear(); 12 | TRACE(); 13 | ASSERT_RE(Serial.log(), 14 | ".+test_full_path.cpp:\\d+: void test_trace\\(\\)\r\n" 15 | "flush\\(\\)\r\n"); 16 | } 17 | 18 | void test_dump() { 19 | Serial.clear(); 20 | int answer = 42; 21 | DUMP(answer); 22 | ASSERT_RE(Serial.log(), 23 | ".+test_full_path.cpp:\\d+: answer = 42\r\n" 24 | "flush\\(\\)\r\n"); 25 | } 26 | 27 | void test_break() { 28 | Serial.clear(); 29 | BREAK(); 30 | ASSERT_RE(Serial.log(), 31 | ".+test_full_path.cpp:\\d+: BREAK.+\r\n" 32 | "flush\\(\\)\r\n" 33 | "read\\(\\)\r\n"); 34 | } 35 | 36 | void test_init() { 37 | Serial.clear(); 38 | ARDUINOTRACE_INIT(9600); 39 | ASSERT_RE(Serial.log(), "begin\\(9600\\)\r\n"); 40 | } 41 | 42 | int main() { 43 | test_trace(); 44 | test_dump(); 45 | test_break(); 46 | test_init(); 47 | } 48 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | TRACE KEYWORD2 2 | DUMP KEYWORD2 3 | BREAK KEYWORD2 4 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ArduinoTrace", 3 | "keywords": "trace, debug, log, serial", 4 | "description": "A dead-simple tracing library to debug your programs", 5 | "homepage": "https://github.com/bblanchon/ArduinoTrace", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/bblanchon/ArduinoTrace.git" 9 | }, 10 | "version": "1.2.0", 11 | "authors": { 12 | "name": "Benoit Blanchon", 13 | "url": "https://blog.benoitblanchon.fr" 14 | }, 15 | "exclude": [".github", "extras"], 16 | "frameworks": "arduino", 17 | "platforms": "*" 18 | } 19 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ArduinoTrace 2 | version=1.2.0 3 | author=Benoit Blanchon 4 | maintainer=Benoit Blanchon 5 | sentence=A dead-simple tracing library to debug your programs 6 | paragraph=You'll never find a simpler tracing library! Just call TRACE() or DUMP(variable) and watch the result in the Serial... 7 | category=Other 8 | url=https://github.com/bblanchon/ArduinoTrace 9 | architectures=* 10 | repository=https://github.com/bblanchon/ArduinoTrace.git 11 | license=MIT 12 | --------------------------------------------------------------------------------