{"id":7568,"date":"2021-11-03T05:06:37","date_gmt":"2021-11-03T12:06:37","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7568"},"modified":"2021-11-03T15:54:29","modified_gmt":"2021-11-03T22:54:29","slug":"using-code-explorer-to-understand-function-call-order","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/intellisense\/codeexplorer\/calls\/","title":{"rendered":"Using Code Explorer to Understand Complex Call Graphs"},"content":{"rendered":"<p>This tutorial shows how to use Code Explorer to quickly understand how multiple functions of interest are related. We will show how to flag multiple functions for review while browsing the code, and then automatically place them on a call tree, showing which of them participate in initialization, what is the top-level entry point, and when some other functions are called.<\/p>\n<p>We will demonstrate it based on the Xilinx UltraScale platform, that includes a relatively complex network driver spread around multiple source files. We will flag initialization-related functions in different sources, and will then will use the common root view in Code Explorer to instantly see how the initialization process looks like (i.e. what function is the top-level one, and how does it call other functions).<\/p>\n<p>Before you begin, install VisualGDB 5.6 or later.<\/p>\n<ol>\n<li>Start Visual Studio and locate the VisualGDB Xilinx Project Wizard in the New Project window:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/01-newprj-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7569\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/01-newprj-1.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a>Note that this tutorial uses the Xilinx environment to demonstrate a project with a complex structure out-of-the-box. The steps shown in this tutorial will work the same way for any other project type using Clang IntelliSense.<\/li>\n<li>Enter the name and location for your project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/02-prjname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7570\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/02-prjname.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Specify the location of your Vitis installation and pick the board you would like to target: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/03-board.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7571\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/03-board.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Select the processor, architecture and OS to use for this project. In this tutorial we will create a FreeRTOS-based project for the ARM64 core: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/04-os.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7572\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/04-os.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Select the example project you would like to use. In this tutorial we will be exploring the Xilinx lwIP port, so choose <strong>FreeRTOS lwIP Echo Server<\/strong>: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/05-echo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7573\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/05-echo.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Finally, you can pick the debug settings that will work with your board. However, in this tutorial we will focus on analyzing the code structure, rather than debugging it, so any debug settings will suffice:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/06-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7574\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/06-debug.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the project. As the Xilinx BSPs generate public header directories during build, you will need to build the project before you can meaningfully explore its source code. Press Ctrl-Shift-B and wait for the build to succeed:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/07-created.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7575\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/07-created.png\" alt=\"\" width=\"1343\" height=\"855\" \/><\/a>Note how VisualGDB displays the sources from all Xilinx libraries in Solution Explorer on the right, and the structure of the current source file in Code Explorer on the left. If you have previously disabled Code Explorer, you can activate it via <strong>View-&gt;Code Explorer<\/strong>.<\/li>\n<li>Now we will begin marking functions for further review. Open the <strong>xemacpsif_dma.c<\/strong> file locate the <strong>init_dma()<\/strong> function. Note how it appears in the Outline view in Code Explorer. Mark it, along with <strong>setup_rx_bds()<\/strong> and <strong>reset_dma()<\/strong> as favorite by clicking in the &#8220;favorite&#8221; column:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/08-fav-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7582\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/08-fav-1.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>Now instead of flagging code in the source files, we will use the global view to locate similarly named functions. Click on the <strong>init_dma()<\/strong> function in the code and then press the &#8220;Go to code explorer&#8221; button in the top right corner of the editor: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/09-goto-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7592\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/09-goto-1.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>This will enable the global view in Code Explorer that shows all of the symbols in the entire project. Flag the <strong>init_emacps()<\/strong> function below <strong>init_dma()<\/strong> as favorite by clicking in the &#8220;favorite&#8221; column:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/10-init2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7584\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/10-init2.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>Open the <strong>xemacpsif_hw.c<\/strong> file and flag the <strong>start_emacps()<\/strong> function as favorite:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/11-start.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7585\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/11-start.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>Switch back to the global view of Code Explorer and enter &#8220;xemacps_&#8221; in the filter. Locate the &#8220;<strong>xemacpsif_init()<\/strong>&#8221; function and mark it as favorite:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/12-init.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7586\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/12-init.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>Now that we have finished marking all relevant functions as favorite, enable the &#8220;Favorites only&#8221; filter in Code Explorer and select all functions by pressing Ctrl-A. VisualGDB will display the details about the selected functions in the Code Explorer Details window: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/13-favs-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7593\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/13-favs-1.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>Normally, the Details window will show all available information: calls, referenced variables, allocated types, etc. While this is useful for understanding what a specific function does, viewing multiple functions in this mode is impractical. Instead, we will limit the view to the call tree by selecting the &#8220;Outgoing calls&#8221; filter. Hold <strong>Shift<\/strong> while clicking it to automatically unchedk other filters:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/14-outgoing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7588\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/14-outgoing.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>Now VisualGDB will automatically discover the common roots (i.e. functions calling other selected functions) and will display them, along with all outgoing calls, in the Details view:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/15-found-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7595\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/15-found-1.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a><\/li>\n<li>To limit the view to just the favorite functions (and not the functions called by them), enable the favorites filter in the Code Explorer details window: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/16-filtered-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7594\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/16-filtered-1.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a>This clearly shows the following observations about the code structure:\n<ul>\n<li>The <strong>reset_dma()<\/strong> function has no known callers (if you search for it by name, you will find an inactive #ifdef block)<\/li>\n<li>The <strong>setup_rx_bds()<\/strong> function is not called during initialization, but is instead invoked by the error handler and the RX handler<\/li>\n<li>The entry point of initialization is the <strong>xemacpsif_init()<\/strong> function, that calls <strong>low_level_init()<\/strong>, in turn, calling other functions<\/li>\n<\/ul>\n<\/li>\n<li>If you would like to review the initialization functions later, you can simply save the current set of favorites to a file: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/17-save.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7591\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/10\/17-save.png\" alt=\"\" width=\"1355\" height=\"822\" \/><\/a>This will only save their names. If the relations between the functions change next time you load the saved set of favorites, Code Explorer will automatically display the up-to-date information.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use Code Explorer to quickly understand how multiple functions of interest are related. We will<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[134],"tags":[236,52],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7568"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=7568"}],"version-history":[{"count":2,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7568\/revisions"}],"predecessor-version":[{"id":7657,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7568\/revisions\/7657"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}