{"id":2375,"date":"2011-11-07T09:48:03","date_gmt":"2011-11-07T08:48:03","guid":{"rendered":"https:\/\/blogs.mentor.com\/colinwalls\/?p=2375"},"modified":"2026-03-26T16:36:13","modified_gmt":"2026-03-26T20:36:13","slug":"who-needs-a-debugger-anyway","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/embedded-software\/2011\/11\/07\/who-needs-a-debugger-anyway\/","title":{"rendered":"Who needs a debugger anyway?"},"content":{"rendered":"<p>If you met someone in a bar, say, and you got talking, they are likely to ask what you do. You will probably reply that you are an embedded software developer. [Actually, in my experience, this can be a bit of a conversation killer. You might be better saying you are an airline pilot or a brain surgeon.] If they carry on talking with you, they might ask you what that job entails and you would probably answer with something about designing software and writing C\/C++ code. Of course, that is not really the case. Most embedded software developers spend the bulk of their time debugging.<\/p>\n<p>This does beg the question: what does debugging actually mean? The answer is less simple than you might expect &#8230;<!--more--><\/p>\n<p>Many years ago, when computers were big and expensive, there were no debugging tools that we would recognize today. Frankly, programmers made less errors. One reason for this was that time on the computer was precious, so the programmer would write the code down on paper first, thinking it through very thoroughly. They would very carefully proof read to avoid syntax errors, as just one slip could waste a computer run. Then they would think through the operation of the code, dry running it on paper to check the logic. Eventually, this carefully scrutinized code would be submitted to the computer. After the run, the results would be studied and, if an error was detected, the code would be modified to include extra <strong>printf()<\/strong> [or equivalent] lines to show how values were changing. By using conditional compilation, &#8220;debug&#8221; and &#8220;production&#8221; versions of code could be compiled.<\/p>\n<p>So, why not take this approach when writing embedded software today? The first part &#8211; writing the code on paper and thinking a lot &#8211; might be a very good practice. However, the ready access to computers that cost almost nothing has moved us away from such an approach. The practice of adding <strong>printf()<\/strong> calls to log values is still amazingly common, despite it being quite problematic for embedded applications. There are five key issues:<\/p>\n<ol>\n<li>Most implementations of <strong>printf()<\/strong> are quite large. The function needs to address a very wide range of formatting situations and that takes a lot of code. This does not matter in a desktop software context, but memory is rarely in abundance in an embedded system.<\/li>\n<li>There is the question of where the output of <strong>printf()<\/strong> actually goes. Many embedded systems have nothing that looks like a &#8220;console&#8221; and directing output back to a host computer can be challenging.<\/li>\n<li>In a multi-threading context &#8211; i.e. when using an RTOS &#8211; reentrancy is a concern. If two threads try to use <strong>printf()<\/strong> at the same time, confusion can result.<\/li>\n<li>Every time you want to change the variables you are looking at, a complete rebuild and download of the code is required.<\/li>\n<li>Lastly, of course, formatting and sending the output [somewhere] takes time. If it is a real time application, this overhead can introduce problems.<\/li>\n<\/ol>\n<p>So, for most systems, using <strong>printf()<\/strong> as a debug tool is not viable. Much better is to attach a <a href=\"http:\/\/www.mentor.com\/embedded-software\/sourcery-tools\/\" target=\"_blank\" rel=\"noopener noreferrer\">debugger<\/a> to the target system using JTAG. This can give ready access to all the target data and addresses the five issues thus:<\/p>\n<ol>\n<li>There is no extra code on the target.<\/li>\n<li>Data is displayed on the host computer without effort.<\/li>\n<li>The debugger needs to be task-aware, but that is well understood.<\/li>\n<li>Code only needs to be rebuilt to fix bugs.<\/li>\n<li>A JTAG connection is not totally non-intrusive in the time domain, but the impact is typically quite small.<\/li>\n<\/ol>\n<p>I am left wondering whether, if developers were rationed in their computer access and, hence, required to write out all code by hand and do some thinking, would better code result and debug time be reduced?<\/p>\n<p>[With thanks to my colleague Rizwan Rasheed, who suggested this topic.]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you met someone in a bar, say, and you got talking, they are likely to ask what you do&#8230;.<\/p>\n","protected":false},"author":71677,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1],"tags":[424,339,300,434],"industry":[],"product":[],"coauthors":[],"class_list":["post-2375","post","type-post","status-publish","format-standard","hentry","category-news","tag-debugging","tag-development-tools","tag-embedded-software","tag-jtag"],"_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/2375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/users\/71677"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/comments?post=2375"}],"version-history":[{"count":1,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/2375\/revisions"}],"predecessor-version":[{"id":10013,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/posts\/2375\/revisions\/10013"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/media?parent=2375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/categories?post=2375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/tags?post=2375"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/industry?post=2375"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/product?post=2375"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/embedded-software\/wp-json\/wp\/v2\/coauthors?post=2375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}