@@ -91,6 +91,8 @@ The disadvantages are:
9191 * [ Alternate Arduino Core] ( #AlternateArduinoCore )
9292 * [ PlatformIO] ( #PlatformIO )
9393 * [ Command Line Flags and Arguments] ( #CommandLineFlagsAndArguments )
94+ * [ Debugging] ( #Debugging )
95+ * [ Valgrind] ( #Valgrind )
9496* [ Supported Arduino Features] ( #SupportedArduinoFeatures )
9597 * [ Arduino Functions] ( #ArduinoFunctions )
9698 * [ Serial Port Emulation] ( #SerialPortEmulation )
@@ -646,6 +648,52 @@ Usage: ./CommandLine.out [--help|-h] [-s] [--include word] [--] [words ...]
646648A more advanced example can be seen in
647649[ AUnit/TestRunner.cpp] ( https://github.com/bxparks/AUnit/blob/develop/src/aunit/TestRunner.cpp ) .
648650
651+ <a name =" Debugging " ></a >
652+ ### Debugging
653+
654+ A huge benefit of compiling Arduino programs using EpoxyDuino is that all the
655+ debugging tools in a Unix environment become automatically available. For
656+ example:
657+
658+ * External Tools
659+ * [ Valgrind] ( https://valgrind.org/docs/manual/quick-start.html )
660+ * [ GDB Debugger] ( https://www.sourceware.org/gdb/ )
661+ * Compiler Options
662+ * [ Address Sanitizer] ( https://github.com/google/sanitizers/wiki/AddressSanitizer ) (ASan)
663+ * [ Memory Sanitizer] ( https://github.com/google/sanitizers/wiki/MemorySanitizer )
664+ (MSan)
665+ * [ Undefined Behavior Sanitizer] ( https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html ) (UBSan)
666+
667+ I am not an expert on any of these sanitizers, and I have not enabled them by
668+ default in the ` EpoxyDuino.mk ` file. But you have the capability to add them to
669+ your ` Makefile ` through the ` CXXFLAGS ` variable.
670+
671+ Below are some things that I have found useful in my own limited experience.
672+
673+ <a name =" Valgrind " ></a >
674+ #### Valgrind
675+
676+ I have found the [ Valgrind] ( https://valgrind.org/docs/manual/quick-start.html )
677+ quite helpful in tracking down Segmentation Fault crashes. Here is a quick
678+ start:
679+
680+ 1 . Compile your program using the ` -g ` flag.
681+ * This is not strictly necessary but this will allow Valgrind to print line
682+ numbers to the source code in the stack trace.
683+ * Two ways:
684+ * Pass the pass through the command line: ` $ make CXXFLAGS=-g `
685+ * Edit the ` Makefile ` and add a ` CXXFLAGS += -g ` directive
686+ near the top of the file.
687+ 2 . Run the program under the ` valgrind ` program.
688+ * Valgrind has tons of options and flags. Here are the flags that I use
689+ (don't remember where I got them):
690+ * `$ alias val='valgrind --tool=memcheck --leak-check=yes
691+ --show-reachable=yes --num-callers=20 --track-fds=yes'`
692+ * ` $ val ./MyProgram.out `
693+
694+ When the program crashes because of a ` nullptr ` dereference, Valgrind will show
695+ exactly where that happened in the source code.
696+
649697<a name =" SupportedArduinoFeatures " ></a >
650698## Supported Arduino Features
651699
0 commit comments