{"id":7945,"date":"2023-01-09T11:25:15","date_gmt":"2023-01-09T09:25:15","guid":{"rendered":"https:\/\/blue.pri.ee\/ttu\/?page_id=7945"},"modified":"2025-02-14T17:16:05","modified_gmt":"2025-02-14T15:16:05","slug":"using-a-debugger-with-geany","status":"publish","type":"page","link":"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/","title":{"rendered":"Using a debugger with Geany"},"content":{"rendered":"<p>Debugger is a tool that you can use to run your code line-by-line and analyze the contents of your program. This includes the values of all variables, function call stack and so on.<\/p>\n<p>These kinds of tools exist with almost all programming languages and are used regularly during development for analyzing and fixing mistakes. Most code editors already come with a debugger (e.g. CLion, Visual Studio) or they can be &#8220;attached&#8221; to them (e.g. Geany, Visual Studio Code). Quite often the debuggers themselves are actually separate programs (e.g. GDB &#8211; GNU debugger) for which the code editor just provides a front end.<\/p>\n<p>This is exactly how the debugger in Geany works. We will install and enable a plugin that will be a front-end to a command line based debugger called GDB.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 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 Content\"><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:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Setup\" >Setup<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Installing_the_Geany_plugin\" >Installing the Geany plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Activating_the_Geany_plugin\" >Activating the Geany plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Configuring_the_compiler\" >Configuring the compiler<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Setting_up_hotkeys\" >Setting up hotkeys<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#User_interface\" >User interface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Debugging_a_program\" >Debugging a program<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#1_Choose_the_program_you_are_debugging\" >1. Choose the program you are debugging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#2_Choose_your_breakpoints\" >2. Choose your breakpoints<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#3_Start_your_program_in_the_debugger\" >3. Start your program in the debugger<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#4_Stepping_through_the_program\" >4. Stepping through the program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Hovering_over_variables\" >Hovering over variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Watch_list\" >Watch list<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Debugging_command_line_arguments\" >Debugging command line arguments<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/#Windows\" >Windows<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Setup\"><\/span>Setup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before you can use the debugger, you need to perform a few one-time actions to set it up. The setup is only required on your own computer. Lab computers are already preconfigured.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Installing_the_Geany_plugin\"><\/span>Installing the Geany plugin<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><em>If you followed our Geany installation guide you should already have everything installed and you can skip this part (go directly to activating the debugger)<\/em><\/p>\n<p>If not, then install\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">geany-plugin-debugger<\/span>.\u00a0 When using any of the Ubuntu based distributions, you can do it by running the following command:<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">sudo apt install geany-plugin-debugger<\/pre>\n<p>You can also install all the other available plugins. Just replace the name with <span class=\"lang:default highlight:0 decode:true crayon-inline\">geany-plugins<\/span> , which will contain all of them nicely packed together..<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Activating_the_Geany_plugin\"><\/span>Activating the Geany plugin<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><em>Note: this is also preconfigured on the lab computers.<\/em><\/p>\n<p>To activate, inside Geany go to the following menu <strong>Tools -&gt; Plugins.<\/strong><\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_1_tools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7864\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_1_tools.png\" alt=\"\" width=\"241\" height=\"180\" \/><\/a><\/p>\n<p>Find <strong>Debugger<\/strong> in the list and tick the box to enable it.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_2_plugins.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7865\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_2_plugins.png\" alt=\"\" width=\"511\" height=\"488\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_2_plugins.png 511w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_2_plugins-300x286.png 300w\" sizes=\"auto, (max-width: 511px) 100vw, 511px\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configuring_the_compiler\"><\/span>Configuring the compiler<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><em>Note: this is also preconfigured on the lab computers.<\/em><\/p>\n<p>To allow the debugger to work, we need to instruct the compiler to provide it additional assistance by adding a flag\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">-g<\/span> . This flag will add information to the compiled program that is necessary for debugging. Your program will get bigger and slower, but it will allow us to use debuggers and various software analysis tools. You do not want this flag on when shipping to clients!<\/p>\n<p><em>Note: The same can be done by choosing<\/em><em> Build -&gt; Set build commands in the menu, but then you will need to have a .c code file open in Geany or it will not work. The guide below is written in a way that it is not necessary .<\/em><\/p>\n<p>Open the configuration file for C code files:\u00a0 <strong>Tools -&gt; Configuration files -&gt; Filetype Configuration -&gt; Programming Languages -&gt; filetypes.c<\/strong><\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_3_filetypes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7866\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_3_filetypes.png\" alt=\"\" width=\"921\" height=\"324\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_3_filetypes.png 921w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_3_filetypes-300x106.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_3_filetypes-768x270.png 768w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In the configuration file, you need to add the compilation flag\u00a0\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">-g<\/span>\u00a0 to the line FT_01_FM. It is underlined with red in the figure below. Make sure to have spaces before and after. The argument cannot be placed after the argument <span class=\"lang:default highlight:0 decode:true crayon-inline\">-o<\/span> .<\/p>\n<p>This is an example of my configuration file after adding the compile flag (red underline for the added argument).<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_4_add_g.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7867\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_4_add_g.png\" alt=\"\" width=\"723\" height=\"152\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_4_add_g.png 723w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_4_add_g-300x63.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/a><\/p>\n<p>If you want to copy-paste it, you can do it from the box below. Note that I&#8217;m also using flags\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">-Wextra<\/span>\u00a0 and <span class=\"lang:default highlight:0 decode:true crayon-inline\">-Wconversion<\/span>\u00a0 for additional information on potential bugs when compiling (you can remove them if you wish to do so).<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">[build-menu]\r\nFT_01_LB=_Build\r\nFT_01_CM=gcc -g -Wall -Wextra -Wconversion -o \"%e\" \"%f\" -lm\r\nFT_01_WD=\r\n<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Setting_up_hotkeys\"><\/span>Setting up hotkeys<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><em>Unfortunately you likely don&#8217;t have an idea what to do with this paragraph yet. However you should return here after you have tried the debugger out at least a few times to know what you are looking at.<\/em><\/p>\n<p>By default, the debugger has no preset shortcuts (e.g. if you press F5, the program will run without the debugger as it did before). You will likely want to assign some keyboard shortcuts to directly launch and interact with the debugger. To do so, choose\u00a0 <strong>Edit -&gt; Preferences<\/strong> in the menus. Choose the tab <strong>Keybindings<\/strong> and scroll until you see the Debugger partition. Here you can add shortcuts of your choosing.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_5_keybindings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7868\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_5_keybindings.png\" alt=\"\" width=\"798\" height=\"598\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_5_keybindings.png 798w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_5_keybindings-300x225.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_5_keybindings-768x576.png 768w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/a>Some of the ones you might be interested in are Run \/ Continue, Step into, Step over, Step out, Run to cursor etc.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"User_interface\"><\/span>User interface<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>After enabling the plugin, you will get a new tab called <strong>Debug<\/strong>. By opening it, you should be looking at the following:<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_ui-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7890\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_ui-1.png\" alt=\"\" width=\"1078\" height=\"326\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_ui-1.png 1078w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_ui-1-300x91.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_ui-1-1024x310.png 1024w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_ui-1-768x232.png 768w\" sizes=\"auto, (max-width: 1078px) 100vw, 1078px\" \/><\/a><\/p>\n<p><strong>Highlighted areas:\u00a0<\/strong><\/p>\n<p>1 &#8211; The program under debugging should be specified into\u00a0<strong>Target<\/strong>. You need to update this every time you are debugging a new program. You can specify command line arguments below it.<\/p>\n<p>2 &#8211; This contains the controls of the program &#8211; run, stop, stepping through etc.<\/p>\n<p>3. These are the various informational views of the program<\/p>\n<ul>\n<li>Target describes the program, command line arguments and the environment<\/li>\n<li>Breakpoints allows you to see and toggle on which lines in which files your code will stop.<\/li>\n<li>Autos will show you the variables that are currently in scope (e.g. local variables in a function).<\/li>\n<li>Watch allows you to add things you want to always see. You can add a variable from Autos by double-clicking it or write what you want to see manually.<\/li>\n<li>Call stack shows you the function call stack starting from main. It will also show threads in a multithreaded programs.<\/li>\n<li>Debug terminal is your normal terminal window. You can also input through here.<\/li>\n<li>Debugger Messages is the output of GDB.<\/li>\n<\/ul>\n<p>4 -I&#8217;ve highlighted this button because it allows you to split the debugger window into 2 tabs. It is important since it allows you to comfortably observe the output and variable values at the same time. Otherwise they are in different tabs and you need to click through them constantly.<\/p>\n<p>The alternative UI it provides looks the following:<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_2_ui_split.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-7909 size-full\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_2_ui_split.png\" alt=\"\" width=\"948\" height=\"297\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_2_ui_split.png 948w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_2_ui_split-300x94.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_6_2_ui_split-768x241.png 768w\" sizes=\"auto, (max-width: 948px) 100vw, 948px\" \/><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Debugging_a_program\"><\/span>Debugging a program<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before we start debugging, let&#8217;s make sure we are more familiar with the user interface and know where to look for things.<\/p>\n<p>Code used in the sample below: <strong><a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0584\/demokood\/demo_debugger.c\">https:\/\/blue.pri.ee\/ttu\/files\/iax0584\/demokood\/demo_debugger.c<\/a><\/strong><\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Choose_the_program_you_are_debugging\"><\/span>1. Choose the program you are debugging<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>First step for\u00a0<strong>debugging any program<\/strong> is to set the location of the program you are about to debug. The debugger does not automatically try to debug the\u00a0<strong>file<\/strong> that is currently open. Typically a program consists of a lot of code files and the debugger does not know the starting point nor what is the output name of your program.<\/p>\n<p>Go to the <strong>Target<\/strong> tab and click <strong>Browse<\/strong>. Find and select the program you are about to debug. The location of it will appear in the textbox next to the target\u00a0(<strong><span style=\"color: #ff0000;\">.c files are not programs!<\/span>)<\/strong><\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_7_target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7891\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_7_target.png\" alt=\"\" width=\"465\" height=\"310\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_7_target.png 465w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_7_target-300x200.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/a><\/p>\n<p>You can also add environment variables and command line arguments here.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Choose_your_breakpoints\"><\/span>2. Choose your breakpoints<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Secondly, we need to choose our breakpoint or breakpoints where we want to program to stop. You can add multiple breakpoints in one file and you can add them in multiple files at the same time. After you start your program, it will run until it reaches the first breakpoint and then goes over to the debugging mode.<\/p>\n<p>Easiest way to do so is to click next to the line number with your mouse. A red dot will appear to signify a breakpoint. In this program, it is stopped on line 34.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_8_brkpnt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7887\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_8_brkpnt.png\" alt=\"\" width=\"574\" height=\"325\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_8_brkpnt.png 574w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_8_brkpnt-300x170.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/a><\/p>\n<p>You can also specify and toggle breakpoints by hotkeys.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Start_your_program_in_the_debugger\"><\/span>3. Start your program in the debugger<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Look for the debugger controls on the right side of the debugging window. Click\u00a0<strong>Run<\/strong> to start the debugger. To stop it, click the\u00a0<strong>Stop<\/strong> button.<\/p>\n<p>After you start, the debugger will run until the first breakpoint (or where it may need user input). In a two-pane view, you will have the information of the program on the left and the terminal on the right.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_9_started.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7905\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_9_started.png\" alt=\"\" width=\"946\" height=\"299\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_9_started.png 946w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_9_started-300x95.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_9_started-768x243.png 768w\" sizes=\"auto, (max-width: 946px) 100vw, 946px\" \/><\/a><\/p>\n<p>Our demo program stopped at user input. It has not yet reached our breakpoint! It will be reached after completing the\u00a0<span class=\"lang:default highlight:0 decode:true crayon-inline\">scanf<\/span>\u00a0 statement. This means we need to give some input in the terminal.<\/p>\n<p>Once the input is entered, the program stops again. This time it&#8217;s because of reaching a breakpoint. Looking at the <strong>Autos<\/strong> tab on the left pane, you will see the local variables of the function. On the right side, all the debugger controls for stepping through the program also unlocked.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_10_dbg_mode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-7907 size-full\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_10_dbg_mode.png\" alt=\"\" width=\"944\" height=\"294\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_10_dbg_mode.png 944w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_10_dbg_mode-300x93.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_10_dbg_mode-768x239.png 768w\" sizes=\"auto, (max-width: 944px) 100vw, 944px\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Stepping_through_the_program\"><\/span>4. Stepping through the program<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Once the program reaches a breakpoint, you can control the program flow step by step. For this, you have the control buttons on the right:<\/p>\n<ul>\n<li><strong>Continue<\/strong> &#8211; program runs normally until it reaches the next breakpoint. If necessary, it will stop to ask for user input, however debugging mode will only continue when you reach a breakpoint.<\/li>\n<li><strong>Restart<\/strong> &#8211; restart the program<\/li>\n<li><strong>Stop<\/strong> &#8211; stop the program<\/li>\n<li><strong>Step over<\/strong> &#8211; Steps over a function call. The function itself will be executed normally, however the debugger will not enter it so you don&#8217;t have step-by-step controls inside of the function.<\/li>\n<li><strong>Step into<\/strong> &#8211; Steps into the function being called &#8211; this allows you to strep through the entire function that was called, step by step.\u00a0<strong>Do not use this for standard library functions (e.g. printf, scanf).<\/strong><\/li>\n<li><strong>Step out<\/strong> &#8211; Steps out of the current function (to after it returns) and continues the debugging from where the function was called.<\/li>\n<li><strong>Run to cursor<\/strong> -In the code window, you can click on a new location where the program will stop. Until that point, the program will go back to normal mode. This is basically an automatically added temporary breakpoint.<br \/>\nNB! If your program encounters another breakpoint before this, it will stop there.<\/li>\n<\/ul>\n<p><strong>Heads up!<\/strong> Printing in the terminal is a buffered operation. The output of every <span class=\"lang:default highlight:0 decode:true crayon-inline \">printf<\/span>\u00a0 statement will not be immediately visible after it&#8217;s being called, but rather either once the buffer is manually flushed, fills up or the end of the line is reached.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Hovering_over_variables\"><\/span>Hovering over variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>When we are in the debugging mode, we can hover over any variable or function with our mouse that is in scope. This allows us to immediately see the value a certain variable is holding at that time.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_11_hover_inspect.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7898\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_11_hover_inspect.png\" alt=\"\" width=\"472\" height=\"175\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_11_hover_inspect.png 472w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_11_hover_inspect-300x111.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Watch_list\"><\/span>Watch list<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In order to keep track of certain variables all the time, you can add them to the watch list. You can add things there in two different ways:<\/p>\n<ol>\n<li>In the autos tab, you can double-click the variable you wish to add to Watch.<\/li>\n<li>In the Watch tab, you can click on the empty line after the last entry and write the variable or expression you wish to observe.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_12_watch-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-7901 size-full\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_12_watch-1.png\" alt=\"\" width=\"937\" height=\"397\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_12_watch-1.png 937w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_12_watch-1-300x127.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_12_watch-1-768x325.png 768w\" sizes=\"auto, (max-width: 937px) 100vw, 937px\" \/><\/a><\/p>\n<p>In the example above, we have stopped the program in the main() function, after reading the array values. You can see that the parameters min and max for ReadValue() are not readable &#8211;\u00a0<strong>we can only read variables in scope.<\/strong><\/p>\n<p>We can add additional data points not automatically added to Autos. In this example, we have added<\/p>\n<ul>\n<li>The array with all its members<\/li>\n<li>A single member of the array<\/li>\n<li>A memory address to a single member of the array (including which it is pointing at)<\/li>\n<li>Some mathematical operations with the resulting values<\/li>\n<\/ul>\n<p>To see <strong>array contents that has been passed to a function<\/strong>, add it manually to the watch list using the following format: <span class=\"lang:c highlight:0 decode:true crayon-inline\">*arrayName@length<\/span><\/p>\n<p>NB! You cannot add names of macros. Just as a reminder, macros are replaced during compilation with constants, so they are no longer present in the compiled code.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Debugging_command_line_arguments\"><\/span>Debugging command line arguments<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To use command line arguments in the program being debugged, specify them in the <strong>Target<\/strong> tab under <strong>Command Line Arguments<\/strong>.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9833\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args.png\" alt=\"\" width=\"636\" height=\"285\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args.png 636w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args-300x134.png 300w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/a>While the <strong>autos<\/strong> tab is able to easily detect <span class=\"lang:c highlight:0 decode:true crayon-inline \">argc<\/span> , it only shows a pointer to <span class=\"lang:c highlight:0 decode:true crayon-inline \">argv<\/span>\u00a0 and the first argument (<span class=\"lang:c highlight:0 decode:true crayon-inline \">argv[0]<\/span>\u00a0). To have a better overview of the arguments, add them to a <strong>watchlist<\/strong>. To see all of the arguments, we use the previously introduced pattern of <span class=\"lang:c highlight:0 decode:true crayon-inline \">arrayName@arrayLength<\/span>\u00a0.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args_watch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9834\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args_watch.png\" alt=\"\" width=\"629\" height=\"275\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args_watch.png 629w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2025\/02\/cmd_args_watch-300x131.png 300w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Windows\"><\/span>Windows<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The version of the debugger used in this guide is now available for Windows. Still, it is possible for Windows users to a different debugger plugin for Geany, which is relatively similar. This version has a few extra nice features, but also some disadvantages. The differences for our purpose will be minor and rather irrelevant.<\/p>\n<p><em>Note: this debugger can also be used in Linux, however it is not preconfigured in the lab computers.<\/em><\/p>\n<p>The usage of this debugger is relatively similar to the one described before, so I&#8217;ll only highlight the main differences.<\/p>\n<p>The name of the plugin to enable is <strong>Scope Debugger<\/strong><\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w1_plugins.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7870\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w1_plugins.png\" alt=\"\" width=\"468\" height=\"449\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w1_plugins.png 468w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w1_plugins-300x288.png 300w\" sizes=\"auto, (max-width: 468px) 100vw, 468px\" \/><\/a><\/p>\n<p>To set up the program, you need to go to the menu <strong>Debug -&gt; Setup.\u00a0<\/strong>Select the program you are about to debug and press OK.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w2_setup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7872\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w2_setup.png\" alt=\"\" width=\"251\" height=\"323\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w2_setup.png 251w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w2_setup-233x300.png 233w\" sizes=\"auto, (max-width: 251px) 100vw, 251px\" \/><\/a><\/p>\n<p>The stepping through the program is done by using a new set of icons that appeared on the top toolbar. To add \/ remove a breakpoint, you need to click on the blue button on the toolbar. The rest of the buttons are for controlling your program in the debugger and stepping through it.<\/p>\n<p><a href=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w3_run_bkpnt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7873\" src=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w3_run_bkpnt.png\" alt=\"\" width=\"814\" height=\"97\" srcset=\"https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w3_run_bkpnt.png 814w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w3_run_bkpnt-300x36.png 300w, https:\/\/blue.pri.ee\/ttu\/wp-content\/uploads\/2022\/12\/dbg_w3_run_bkpnt-768x92.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Debugger is a tool that you can use to run your code line-by-line and analyze the contents of your program. This includes the values of all variables, function call stack and so on. These kinds of tools exist with almost all programming languages and are used regularly during development for analyzing and fixing mistakes. Most &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/coding-guides\/using-a-debugger-with-geany\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">Using a debugger with Geany<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4802,"menu_order":10,"comment_status":"closed","ping_status":"closed","template":"page-templates\/code-width-wide.php","meta":{"footnotes":""},"class_list":["post-7945","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/7945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=7945"}],"version-history":[{"count":5,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/7945\/revisions"}],"predecessor-version":[{"id":9837,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/7945\/revisions\/9837"}],"up":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/4802"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=7945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}