{"id":3341,"date":"2021-08-05T14:06:56","date_gmt":"2021-08-05T12:06:56","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=3341"},"modified":"2021-12-14T15:14:23","modified_gmt":"2021-12-14T14:14:23","slug":"debugging-segmentation-faults-with-clang","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/","title":{"rendered":"Debugging Segmentation Faults with Clang"},"content":{"rendered":"<p>I wanted to provide an easy to use <a href=\"https:\/\/github.com\/pschatzmann\/arduino-libhelix\">Arduino Audio Decoding Library<\/a> based on libhelix. Unfortunately the ESP32 was crashing <strong>w\/o any stacktrace<\/strong> and on the desktop it was the first time I was running into <strong>Segmentation Faults<\/strong>. I tried to resolve the issue with the help of Google where I found the recommendation<\/p>\n<ul>\n<li>to use <a href=\"https:\/\/valgrind.org\/\">valgrind<\/a><\/li>\n<li>to debug the code<\/li>\n<\/ul>\n<p>So I used my <a href=\"https:\/\/github.com\/pschatzmann\/Arduino-Emulator\">Arduino Emulator<\/a> to debug the code on my <strong>McBook<\/strong> and on my <strong>Raspberry PI<\/strong> (for valgrind).<\/p>\n<p>Unfortunately both of this was just identifying only the <strong>location of the symptom<\/strong> and not the root cause!<\/p>\n<p>The <strong>breakthru<\/strong> finally came when I discovered the <strong>-fsanitize=address<\/strong> compiler option!<br \/>\nI just needed to add the following lines to my CMakeList.txt<\/p>\n<pre><code>set (CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address\")\nset (CMAKE_LINKER_FLAGS_DEBUG \"${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address\")\n\n<\/code><\/pre>\n<p>and built the project in debug mode with<\/p>\n<pre><code>cmake -DCMAKE_BUILD_TYPE=Debug ..\nmake\n<\/code><\/pre>\n<p>After starting the debugger, I added the breakpoint on <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizerAndDebugger\">__asan::ReportGenericError<\/a> to stop the debugger right before the error and to my surprise <strong>I found the issue right way<\/strong>!<\/p>\n<p>The <a href=\"https:\/\/github.com\/pschatzmann\/arduino-libhelix\/tree\/main\/examples\/output_mp3\">example test case can be found on Github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to provide an easy to use Arduino Audio Decoding Library based on libhelix. Unfortunately the ESP32 was crashing w\/o any stacktrace and on the desktop it was the first time I was running into Segmentation Faults. I tried to resolve the issue with the help of Google where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3348,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,1],"tags":[30],"class_list":["post-3341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-generic","tag-back-to-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Debugging Segmentation Faults with Clang - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Debugging Segmentation Faults with Clang - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"I wanted to provide an easy to use Arduino Audio Decoding Library based on libhelix. Unfortunately the ESP32 was crashing w\/o any stacktrace and on the desktop it was the first time I was running into Segmentation Faults. I tried to resolve the issue with the help of Google where [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-05T12:06:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-14T14:14:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/08\/debug.png\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Debugging Segmentation Faults with Clang\",\"datePublished\":\"2021-08-05T12:06:56+00:00\",\"dateModified\":\"2021-12-14T14:14:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/\"},\"wordCount\":175,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/debug.png\",\"keywords\":[\"Back to Basics\"],\"articleSection\":[\"Arduino\",\"Other Topics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/\",\"name\":\"Debugging Segmentation Faults with Clang - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/debug.png\",\"datePublished\":\"2021-08-05T12:06:56+00:00\",\"dateModified\":\"2021-12-14T14:14:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/debug.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/debug.png\",\"width\":200,\"height\":200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/08\\\/05\\\/debugging-segmentation-faults-with-clang\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Debugging Segmentation Faults with Clang\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Debugging Segmentation Faults with Clang - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/","og_locale":"en_US","og_type":"article","og_title":"Debugging Segmentation Faults with Clang - Phil Schatzmann","og_description":"I wanted to provide an easy to use Arduino Audio Decoding Library based on libhelix. Unfortunately the ESP32 was crashing w\/o any stacktrace and on the desktop it was the first time I was running into Segmentation Faults. I tried to resolve the issue with the help of Google where [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-08-05T12:06:56+00:00","article_modified_time":"2021-12-14T14:14:23+00:00","og_image":[{"width":200,"height":200,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/08\/debug.png","type":"image\/png"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Debugging Segmentation Faults with Clang","datePublished":"2021-08-05T12:06:56+00:00","dateModified":"2021-12-14T14:14:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/"},"wordCount":175,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/08\/debug.png","keywords":["Back to Basics"],"articleSection":["Arduino","Other Topics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/","name":"Debugging Segmentation Faults with Clang - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/08\/debug.png","datePublished":"2021-08-05T12:06:56+00:00","dateModified":"2021-12-14T14:14:23+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/08\/debug.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/08\/debug.png","width":200,"height":200},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/08\/05\/debugging-segmentation-faults-with-clang\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Debugging Segmentation Faults with Clang"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=3341"}],"version-history":[{"count":14,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3341\/revisions"}],"predecessor-version":[{"id":3356,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3341\/revisions\/3356"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/3348"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=3341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=3341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=3341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}