{"id":4215,"date":"2024-04-27T11:52:16","date_gmt":"2024-04-27T06:22:16","guid":{"rendered":"https:\/\/cthecosmos.com\/?p=4215"},"modified":"2024-04-27T11:52:16","modified_gmt":"2024-04-27T06:22:16","slug":"gdb-commands","status":"publish","type":"post","link":"https:\/\/cthecosmos.com\/?p=4215","title":{"rendered":"GDB COMMANDS"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"851\" data-attachment-id=\"4218\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=4218\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/gdb_commands.png?fit=4087%2C3477&amp;ssl=1\" data-orig-size=\"4087,3477\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"gdb_commands\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/gdb_commands.png?fit=1000%2C851&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/gdb_commands.png?resize=1000%2C851&#038;ssl=1\" alt=\"\" class=\"wp-image-4218\" \/><\/figure>\n<\/div>\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-9caab494be60133353ffc44957d546fe wp-block-paragraph\" style=\"font-size:17px;line-height:1.8\">A List of few gdb commands that can help you during debugging using gdb debugger.<br><br><strong>1) \ud835\udc22\ud835\udc27\ud835\udc1f\ud835\udc28 \ud835\udc1f\ud835\udc2e\ud835\udc27\ud835\udc1c\ud835\udc2d\ud835\udc22\ud835\udc28\ud835\udc27\ud835\udc2c:<\/strong><br>List all the functions in the program or those matching a regular expression. Useful to see the functions provided by a library or module.<br><strong><em>Syntax: info functions &lt;regex&gt;<br>Example: info functions _init<br><\/em><\/strong><br><strong>2) \ud835\udc22\ud835\udc27\ud835\udc1f\ud835\udc28 \ud835\udc2b\ud835\udc1e\ud835\udc20\ud835\udc22\ud835\udc2c\ud835\udc2d\ud835\udc1e\ud835\udc2b\ud835\udc2c:<\/strong><br>Display the content of the CPU registers.<br><strong><em>Example: info registers<\/em><\/strong><br><br><strong>3) \ud835\udc2c\ud835\udc1e\ud835\udc2d:<\/strong><br>Modify the value of variables or memory.<br><br><strong><em>Syntax: set var &lt;variable_name&gt;=&lt;value&gt;<br>Example: To set a variable counter to 5: set var counter=5<br><\/em><\/strong><br><strong><em>Syntax for memory: set {&lt;type&gt;}&lt;address&gt; = &lt;value&gt;<br>Example: To set a word of memory at address 0x20000010 to 0xABCD1234: set {int}0x20000010 = 0xABCD1234<br><\/em><\/strong><br><strong>4) \ud835\udc30\ud835\udc1a\ud835\udc2d\ud835\udc1c\ud835\udc21:<\/strong><br>Set a watchpoint for a variable. The program will stop when the variable changes.<br><br><strong><em>Syntax: watch &lt;variable_name&gt;<br>Example: watch myVariable<br><\/em><\/strong><br><strong>5) \ud835\udc2c\ud835\udc2d\ud835\udc1e\ud835\udc29\ud835\udc22 \ud835\udc28\ud835\udc2b \ud835\udc2c\ud835\udc22:<\/strong><br>Execute one machine instruction, stepping into functions.<br><strong><em>Example: stepi<\/em><\/strong><br><br><strong>6) \ud835\udc27\ud835\udc1e\ud835\udc31\ud835\udc2d\ud835\udc22 \ud835\udc28\ud835\udc2b \ud835\udc27\ud835\udc22:<\/strong><br>Execute one machine instruction, stepping over functions.<br><strong><em>Example: nexti<\/em><\/strong><br><br><strong>7) \ud835\udc22\ud835\udc27\ud835\udc1f\ud835\udc28 \ud835\udc29\ud835\udc2b\ud835\udc28\ud835\udc1c:<\/strong><br>Shows detailed information about the process being debugged. This can be helpful to inspect the memory map, which is essential in embedded systems.<br><br><strong><em>Example: info proc<\/em><\/strong><br><br><strong>8) \ud835\udc2c\ud835\udc21\ud835\udc28\ud835\udc30 \ud835\udc29\ud835\udc1a\ud835\udc2d\ud835\udc21\ud835\udc2c:<\/strong><br>Display the list of directories GDB searches for executables and source files. This is essential when you have an embedded system&#8217;s SDK or cross-compilation toolchain with its libraries.<br><br><strong><em>Example: show paths<\/em><\/strong><br><br><strong>9) \ud835\udc1a\ud835\udc1d\ud835\udc1d-\ud835\udc2c\ud835\udc32\ud835\udc26\ud835\udc1b\ud835\udc28\ud835\udc25-\ud835\udc1f\ud835\udc22\ud835\udc25\ud835\udc1e:<\/strong><br>Add symbols from an external file. This is useful when you have a stripped binary running on an embedded device but have a separate file with debugging symbols.<br><br><strong><em>Syntax: add-symbol-file &lt;file&gt; &lt;address&gt;<br>Example: add-symbol-file my_symbols.elf 0x08000000<br><\/em><\/strong><br><strong>10) \ud835\udc1d\ud835\udc22\ud835\udc2c\ud835\udc1a\ud835\udc2c\ud835\udc2c\ud835\udc1e\ud835\udc26\ud835\udc1b\ud835\udc25\ud835\udc1e:<\/strong><br>View the assembly code of a function or a range of addresses.<br>Syntax: disassemble &lt;function\/range&gt;<br><br><strong><em>Example: disassemble main<br>Example: disassemble 0x08000000,+50<br><\/em><\/strong><br><strong>11) \ud835\udc26\ud835\udc1a\ud835\udc22\ud835\udc27\ud835\udc2d\ud835\udc1e\ud835\udc27\ud835\udc1a\ud835\udc27\ud835\udc1c\ud835\udc1e \ud835\udc22\ud835\udc27\ud835\udc1f\ud835\udc28 \ud835\udc2c\ud835\udc1e\ud835\udc1c\ud835\udc2d\ud835\udc22\ud835\udc28\ud835\udc27\ud835\udc2c:<\/strong><br>Display all the sections in the current binary. This is useful to inspect where each section (like .text, .data, .bss) is located in memory.<br><br><strong><em>Example: maintenance info sections..<\/em><\/strong><br><br><strong>12) \ud835\udc2c\ud835\udc1e\ud835\udc2d \ud835\udc29\ud835\udc2b\ud835\udc22\ud835\udc27\ud835\udc2d \ud835\udc29\ud835\udc2b\ud835\udc1e\ud835\udc2d\ud835\udc2d\ud835\udc32 \ud835\udc28\ud835\udc27:<\/strong><br>Print structures in a pretty format, making it easier to read complex data structures.<br><br><strong><em>Example: set print pretty on<\/em><\/strong><br><br><strong>13) \ud835\udc2c\ud835\udc1e\ud835\udc2d \ud835\udc1f\ud835\udc28\ud835\udc25\ud835\udc25\ud835\udc28\ud835\udc30-\ud835\udc1f\ud835\udc28\ud835\udc2b\ud835\udc24-\ud835\udc26\ud835\udc28\ud835\udc1d\ud835\udc1e:<\/strong><br>Decide how GDB should behave when the debugged process forks. It&#8217;s relevant in embedded systems where processes or tasks might spawn child processes.<br><br><strong><em>Syntax: set follow-fork-mode &lt;mode&gt;<br>Example: set follow-fork-mode child (debug the child process after a fork)<\/em><\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-link-color wp-elements-39701e13669fccc736b4996fc9f3df8d wp-block-paragraph\">LinkedIn Post: <a href=\"https:\/\/www.linkedin.com\/posts\/t-yashwanth-naidu_earlycareer-embeddedsystems-learning-activity-7108913094852022272-ntD6\/?utm_source=share&amp;utm_medium=member_desktop\">https:\/\/www.linkedin.com\/posts\/t-yashwanth-naidu_earlycareer-embeddedsystems-learning-activity-7108913094852022272-ntD6\/?utm_source=share&amp;utm_medium=member_desktop<\/a><\/p>\n\n\n\n<p class=\"has-white-color has-text-color has-background has-link-color has-medium-font-size wp-elements-486e7799b35920eece0029316d5e98bd wp-block-paragraph\" style=\"background:linear-gradient(135deg,rgb(35,23,11) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%)\">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><strong>An Article by: <\/strong>Yashwanth Naidu Tikkisetty<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article by Yashwanth Naidu Tikkisetty provides a comprehensive list of gdb commands for debugging. It covers functions like info, set, watch, stepi, disassemble, and more, essential for efficient debugging in embedded systems. The post also emphasizes the importance of inspecting memory maps and displaying directory paths. For more details, visit the LinkedIn post.<\/p>\n<a href=\"https:\/\/cthecosmos.com\/?p=4215\" class=\"more-link\">Read More <span class=\"screen-reader-text\">GDB COMMANDS<\/span><\/a>","protected":false},"author":120055267,"featured_media":4216,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[769112296,36985,28627,30181,35264203,769114260],"tags":[772321195,772321193,320749,306968029,88204,771201861,1354040,34920936],"class_list":["post-4215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-concepts-hub","category-c-programming","category-embedded","category-embedded-systems","category-linux-3","category-linuxlearnings","tag-c-programming","tag-embedded-systems","tag-gdb","tag-gdb-commands","tag-linux-fun","tag-linuxlearning-2","tag-short-article","tag-ubuntu-2","fallback-thumbnail"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2024\/04\/cznmcy1wcml2yxrll3jhd3bpegvsx2ltywdlcy93zwjzaxrlx2nvbnrlbnqvbhivbnmymtuxmi1pbwfnzs1rd3z5owloms5qcgc.webp?fit=1024%2C576&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8CiEf-15Z","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/users\/120055267"}],"replies":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4215"}],"version-history":[{"count":7,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4215\/revisions"}],"predecessor-version":[{"id":4224,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/4215\/revisions\/4224"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/media\/4216"}],"wp:attachment":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}