{"id":8598,"date":"2016-07-28T18:28:56","date_gmt":"2016-07-28T17:28:56","guid":{"rendered":"https:\/\/sysprogs.com\/w\/?p=8598"},"modified":"2016-07-28T18:28:56","modified_gmt":"2016-07-28T17:28:56","slug":"the-new-dependency-view-in-embedded-memory-explorer","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/w\/the-new-dependency-view-in-embedded-memory-explorer\/","title":{"rendered":"The New Dependency View in Embedded Memory Explorer"},"content":{"rendered":"<p>Embedded Memory Explorer is one of\u00a0the most loved Embedded features of VisualGDB. It\u00a0helps you keep track of the FLASH and RAM used by your embedded project\u00a0so you can\u00a0be sure that your program fits into your device memory:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/memexp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8599\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/memexp.png\" alt=\"memexp\" width=\"651\" height=\"243\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/memexp.png 651w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/memexp-300x112.png 300w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><\/a>The new VisualGDB 5.2\u00a0comes with a feature that makes this window even more efficient at finding out why is your program bigger than you\u00a0wanted it to be.<!--more--><\/p>\n<p>While being precise and clear about <strong>where<\/strong>\u00a0your memory went, the Embedded Memory Explorer of VisualGDB 5.1 and earlier did not answer the more important question <strong>why<\/strong>. Let&#8217;s look at a basic example: turn off the &#8220;Reduce size of C++ binaries&#8221; feature and add a basic\u00a0C++ class with a virtual method to your embedded program:<\/p>\n<pre class=\"\">class Base\r\n{\r\npublic:\r\n    virtual void test() = 0;\r\n};\r\n\r\nclass Some : public Base\r\n{\r\npublic:\r\n    virtual void test() override\r\n    {\r\n    }\r\n};\r\n\r\nint main(void)\r\n{\r\n    Some thing;\r\n}\r\n<\/pre>\n<p>If you compile this, you\u00a0may make a shocking\u00a0discovery that adding nothing more than one empty\u00a0method\u00a0suddenly bumped up your FLASH\u00a0usage by 75 KB:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/bigcode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8600\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/bigcode.png\" alt=\"bigcode\" width=\"969\" height=\"733\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/bigcode.png 969w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/bigcode-300x227.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/bigcode-768x581.png 768w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/><\/a><\/p>\n<p>While being unnoticeable on Linux or Android, this could be a killer if\u00a0you are\u00a0targeting an embedded\u00a0device\u00a0with the FLASH size measured in tens of kilobytes. The normal Embedded Memory Explorer will quickly\u00a0reveal that\u00a0most of the\u00a0memory is now used\u00a0by some library\u00a0code that you\u00a0never called explicitly:<\/p>\n<p><a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8601\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout1.png\" alt=\"layout1\" width=\"653\" height=\"337\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout1.png 653w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout1-300x155.png 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/a><\/p>\n<p>Before VisualGDB 5.2 that\u00a0would mean an annoying search through the disassembly output to figure out who calls <strong>d_print_comp_inner()<\/strong>, then who calls its caller and so on. Thankfully\u00a0there is a simpler way.\u00a0The GCC compiler used by VisualGDB can be instructed to generate the so-called relocation records used by your\u00a0operating system when it decides\u00a0move your program to a different location in memory and needs to update references to all the functions. \u00a0While\u00a0normally\u00a0useless for the barebone embedded applications, they provide an (almost) complete\u00a0list of places where each function is referenced (except some internal library functions).\u00a0VisualGDB now\u00a0utilizes this to show\u00a0all functions referencing\u00a0a given symbol and explain why it was included into your program.<\/p>\n<p>You can enable this mode by\u00a0clicking the corresponding button on the Embedded Memory Explorer toolbar. If you are doing this for the first time, VisualGDB will enable the relocation record generation and will ask you to rebuild the project. Then you will\u00a0quickly see why each of the\u00a0strange functions\u00a0was included. In our example the roots of the d_print_comp_inner() trace to the default implementation of <strong>std::terminate()<\/strong>\u00a0called by the\u00a0default implementation of the pure virtual method that can be accidentally invoked\u00a0from the abstract class\u00a0constructor before the child class was fully initialized:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8602\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout2.png\" alt=\"layout2\" width=\"993\" height=\"568\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout2.png 993w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout2-300x172.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout2-768x439.png 768w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/a><\/p>\n<p>While producing a neat stack trace in that case could be meaningful on Linux, it\u00a0is not\u00a0worth the\u00a0extra memory on small Embedded targets. The solution in this case would be to replace\u00a0<strong>__cxa_pure_virtual()<\/strong> with something\u00a0more compact that will for example\u00a0just\u00a0trigger a breakpoint.\u00a0The &#8220;Reduce size of C++ binaries&#8221; option does exactly that as you can quickly check with the new Memory Explorer:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8603\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout3.png\" alt=\"layout3\" width=\"996\" height=\"311\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout3.png 996w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout3-300x94.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2016\/07\/layout3-768x240.png 768w\" sizes=\"(max-width: 996px) 100vw, 996px\" \/><\/a>You can download the latest VisualGDB supporting this feature on the <a href=\"http:\/\/visualgdb.com\/download\/\">download page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Embedded Memory Explorer is one of\u00a0the most loved Embedded features of VisualGDB. It\u00a0helps you keep track of the FLASH and RAM used by your embedded project\u00a0so you can\u00a0be sure that your program fits into your device memory:The new VisualGDB 5.2\u00a0comes with a feature that makes this window even more efficient at finding out why is &hellip; <a href=\"https:\/\/sysprogs.com\/w\/the-new-dependency-view-in-embedded-memory-explorer\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The New Dependency View in Embedded Memory Explorer<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[216],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/8598"}],"collection":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/comments?post=8598"}],"version-history":[{"count":1,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/8598\/revisions"}],"predecessor-version":[{"id":8604,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/8598\/revisions\/8604"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/media?parent=8598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/categories?post=8598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/tags?post=8598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}