{"id":5641,"date":"2020-05-24T08:13:52","date_gmt":"2020-05-24T08:13:52","guid":{"rendered":"https:\/\/www.fambach.net\/?p=5641"},"modified":"2020-05-24T08:19:13","modified_gmt":"2020-05-24T08:19:13","slug":"debug-ausgaben-im-quellcode","status":"publish","type":"post","link":"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/","title":{"rendered":"Debug output in source code"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Contents\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Boolische_Variable_IF\" >Boolean variable + IF<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Praprozessor_Bedingung\" >Pr&auml;prozessor Bedingung<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Praprozessor_Ersetzung\" >Pr&auml;prozessor Ersetzung<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Praprozessor_Funktionen\" >Pr&auml;prozessor Funktionen<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Online_Debugger\" >Online Debugger<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Fazit\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/#Quellen\" >Sources<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">Gerade beim neuen Entwicklungen ist es wichtig ein paar Ausgaben &uuml;ber die serielle Schnittstelle oder ein anderes Medium zu schicken. Nat&uuml;rlich k&ouml;nnen diese Ausgaben einfach gel&ouml;scht oder ausdokumentiert werden. Aber sp&auml;testens wenn die Implementierung erweitert wird, werden sie wieder ben&ouml;tigt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Es gibt unterschiedliche Ans&auml;tze welche ich hier kurz vorstellen m&ouml;chte. Welche Variante die Richtige ist muss jeder f&uuml;r sich selbst entscheiden.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Boolische_Variable_IF\"><\/span>Boolean variable + IF<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Verwendung einer globale boolischen Variable und eine IF-Bedinung f&uuml;r jede Ausgabe.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bool debug = true;\n\nvoid funktion1(){\n  \/\/ ....\n  if(debug){\n    Serial.println(\"Debug message\");\n  }\n  \/\/ ....\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Dieser Variante erm&ouml;glicht es, das Debugging auch noch w&auml;hrend des Betriebes ein zu schalten. Dies ist bei den folgenden Varianten nicht m&ouml;glich. Der gr&ouml;&szlig;te Nachteil ist der zus&auml;tliche Code und der Speicher f&uuml;r die Texte. Um Speicher zu sparen k&ouml;nnen die Texte ins EEPROM oder in den Flash Speicher ausgelagert werden.  Hier ein Beispiel f&uuml;r den Flash Speicher:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bool debug = true;\n\nvoid funktion1(){\n  \/\/ ....\n  if(debug){\n    Serial.println(F(\"Debug message\"));\n  }\n  \/\/ ....\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Praprozessor_Bedingung\"><\/span>Pr&auml;prozessor Bedingung<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In folgenden Beispiel wir die Variante von oben mit Pr&auml;prozessoranweisungen realisiert. F&auml;llt das #define oben weg, werden auch die Ausgabe nicht eincompiliert. Dies spart Speicher ein. Ein Nachteil ist der druchbrochene Code, Pr&auml;prozessornaweisungen zerfleddern einwenig das Gesamtbild.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define DEBUG\n\nvoid function1(){\n  \/\/ .... \n#ifdef DEBUG\n   Serial.println(F(&quot;Debug message&quot;));\n#endif\n  \/\/ ....\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Praprozessor_Ersetzung\"><\/span>Pr&auml;prozessor Ersetzung<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">kaufhaus ein Haus von einer Frau gekauft. <a href=\"https:\/\/forum.arduino.cc\/index.php?topic=155268.0\">Arduino Forum<\/a> the following example brought:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &quot;Arduino.h&quot;   \n\n#define DEBUG true \/\/ flag to enable\/disable debugging\n#define Serial if(DEBUG)Serial<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This seems to me to be one of the most elegant variants because the Serial class can be used as usual and then completely switched off. According to some forum participants, however, this does not always seem to work. Thus, we come to the last variant.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Praprozessor_Funktionen\"><\/span>Pr&auml;prozessor Funktionen<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Definition von Pr&auml;prozessor Funktionen. Diese k&ouml;nnen leicht ausgeschaltet werden und belasten den Speicher nicht. Nachteil jede Funktion muss einzeln definiert und im Quellcode verwendet werden. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#ifdef DEBUG\n #define DEBUG_PRINT(x)    Serial.print (x)\n #define DEBUG_PRINTDEC(x) Serial.print (x, DEC)\n #define DEBUG_PRINTLN(x)  Serial.println (x)\n#else\n #define DEBUG_PRINT(x)\n #define DEBUG_PRINTDEC(x)\n #define DEBUG_PRINTLN(x)\n#endif\n\nvoid setup()\n  Serial.begin(115200);\n  DEBUG_PRINT (&quot;Hello, I am a Text2&quot;);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Oder diese im Arduino Forum gefundene Version, hier ist mir nicht ganz klar worf&uuml;r die Schleife gebaucht werden &#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define DEBUG false \/\/ flag to enable\/disable debugging\n#define debug_begin(...) do { if (DEBUG) { Serial.begin(__VA_ARGS__); while(!Serial); }} while (0)\n#define debug_print(...) do { if (DEBUG) Serial.print(__VA_ARGS__); } while (0)\n#define debug_println(...) do { if (DEBUG) Serial.println(__VA_ARGS__); } while (0)\n#define debug_printf(...) do { if (DEBUG) Serial.printf(__VA_ARGS__); } while (0)\n\nvoid setup()\n  debug_begin(115200);\n  debug_begin(&quot;Hello, I am a Text2&quot;);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Online_Debugger\"><\/span>Online Debugger<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Noch besser ist nat&uuml;rlich ein Debugger, der schrittweise &uuml;ber den Code gehen kann. Dies war beim Atmel mit JTAG schon immer m&ouml;glich. Arduino scheint diese M&ouml;glichkeit etwas verschlafen zu haben. Hier die Bem&uuml;hungen der Arduino IDE.<\/p>\n\n\n\n<figure class=\"wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-arduino-blog\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"bSI5HPqVfg\"><a href=\"https:\/\/blog.arduino.cc\/2020\/02\/28\/preview-the-debugger-feature-for-the-arduino-pro-ide\/\">Preview the Debugger feature for the Arduino Pro IDE<\/a><\/blockquote><iframe loading=\"lazy\" title=\"\u201cPreview the Debugger feature for the Arduino Pro IDE\u201d \u2014 Arduino Blog\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"https:\/\/blog.arduino.cc\/2020\/02\/28\/preview-the-debugger-feature-for-the-arduino-pro-ide\/embed\/#?secret=bSI5HPqVfg\" data-secret=\"bSI5HPqVfg\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here are PlatformIO's aspirations<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.platformio.org\/en\/latest\/plus\/debugging.html\">https:\/\/docs.platformio.org\/en\/latest\/plus\/debugging.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.platformio.org\/en\/latest\/tutorials\/espressif32\/arduino_debugging_unit_testing.html\">https:\/\/docs.platformio.org\/en\/latest\/tutorials\/espressif32\/arduino_debugging_unit_testing.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Eclipse kann es Grunds&auml;tzlich, es gibt auch Ans&auml;tze f&uuml;r den Arduino:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.codeproject.com\/Articles\/1037057\/Debugger-for-Arduino\">https:\/\/www.codeproject.com\/Articles\/1037057\/Debugger-for-Arduino<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fazit\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Es gibt zahlreiche M&ouml;glichkeiten Debugging Nachrichten aus dem produktiven Code heraus zu nehmen. Die letzten Varianten sind sicherlich die meist angewandten. Um Variablen inhalte &uuml;ber alles &Auml;nderungen hinweg zu verfolgen ist sicherlich ein &#8222;Richtiger&#8220; Debugger besser geeignet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Quellen\"><\/span>Sources<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/forum.arduino.cc\/index.php?topic=155268.0\">https:\/\/forum.arduino.cc\/index.php?topic=155268.0<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/blog.arduino.cc\/2020\/02\/28\/preview-the-debugger-feature-for-the-arduino-pro-ide\/\">Preview the Debugger feature for the Arduino Pro IDE<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.arduino.cc\/en\/Reference\/EEPROM\">https:\/\/www.arduino.cc\/en\/Reference\/EEPROM<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/playground.arduino.cc\/Learning\/Memory\/\">https:\/\/playground.arduino.cc\/Learning\/Memory\/<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Gerade beim neuen Entwicklungen ist es wichtig ein paar Ausgaben &uuml;ber die serielle Schnittstelle oder ein anderes Medium zu schicken. Nat&uuml;rlich k&ouml;nnen diese Ausgaben einfach gel&ouml;scht oder ausdokumentiert werden. Aber sp&auml;testens wenn die Implementierung erweitert wird, werden sie wieder ben&ouml;tigt. Es gibt unterschiedliche Ans&auml;tze welche ich hier kurz vorstellen m&ouml;chte. Welche Variante die Richtige ist &#8230;<\/p>\n<a href=\"https:\/\/www.fambach.net\/en\/debug-ausgaben-im-quellcode\/\" class=\"read-more-link\">Carry on reading <span class=\"screen-reader-text\">\"Debug Ausgaben im Quellcode\"<\/span> <span class=\"meta-nav\">\u2192<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[157,184,171],"tags":[314,311,312,313],"class_list":["post-5641","post","type-post","status-publish","format-standard","hentry","category-atnrob","category-c-c","category-tools","tag-anweisung","tag-debuggen","tag-debugging","tag-praeprozessor","penguin-post","penguin-post-not-sticky"],"modified_by":"sfambach","_links":{"self":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/5641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/comments?post=5641"}],"version-history":[{"count":7,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/5641\/revisions"}],"predecessor-version":[{"id":5648,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/5641\/revisions\/5648"}],"wp:attachment":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/media?parent=5641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/categories?post=5641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/tags?post=5641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}