{"id":3897,"date":"2019-10-07T19:41:17","date_gmt":"2019-10-07T11:41:17","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=3897"},"modified":"2019-10-07T19:41:17","modified_gmt":"2019-10-07T11:41:17","slug":"linux-c-gdb%e5%a6%82%e4%bd%95debug%e5%ae%8f%e5%ae%9a%e4%b9%89","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/3897","title":{"rendered":"[linux c] gdb\u5982\u4f55debug\u5b8f\u5b9a\u4e49"},"content":{"rendered":"<div class=\"article-header-box\">\n<div class=\"article-header\">\n<div class=\"article-title-box\"><\/div>\n<\/div>\n<\/div>\n<div class=\"article-source-link2222\"><a href=\"https:\/\/blog.csdn.net\/jibing57\/article\/details\/7439631\">\u539f\u6587\u5730\u5740<\/a><\/div>\n<div><\/div>\n<article class=\"baidu_pl\">\n<div id=\"article_content\" class=\"article_content clearfix\">\n<div id=\"content_views\" class=\"htmledit_views\">\n<p>\u672c\u6587\u5927\u6982\u9610\u8ff0\u5982\u4f55\u8ba9gdb\u80fd\u591f\u663e\u793a\u5b8f\u5b9a\u4e49\u7684\u503c\u4ee5\u53ca\u5bf9\u5e94\u7684\u539f\u7406<\/p>\n<p>gcc\u9ed8\u8ba4\u7f16\u8bd1\u7684\u65f6\u5019\uff0cgdb\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u662f\u4e0d\u80fd\u770b\u5230\u5b8f\u5b9a\u4e49\u7684\uff0c&#8221;p \u5b8f\u540d&#8221; \u4f1a\u663e\u793a\u9519\u8bef,\u5982\u4e0b\uff1a<\/p>\n<p>(gdb) p CLIENT6_BEGIN_FLG<br \/>\nNo symbol &#8220;CLIENT6_BEGIN_FLG&#8221; in current context.<br \/>\n(gdb)<\/p>\n<p>\u5176\u4e2d\u00a0#define CLIENT6_BEGIN_FLG &#8220;&lt;Client6&gt;&#8221;<\/p>\n<p>\u8fd9\u6837gdb\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u5c31\u5f88\u4e0d\u76f4\u89c2\uff0c\u5c24\u5176\u662f\u5f88\u591a\u5927\u578b\u7a0b\u5e8f\u4e2d\uff0c\u5b8f\u5b9a\u4e49\u6bd4\u8f83\u590d\u6742\u7684\u65f6\u5019\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u5728gdb\u4e2d\u80fd\u67e5\u770b\u5b8f\u5b9a\u4e49\uff0cgcc\u7f16\u8bd1\u7684\u65f6\u5019\u9700\u8981\u52a0\u4e0a -gdwarf-2\u548c-g3\u7684\u53c2\u6570\u3002<\/p>\n<p>\u4e0b\u9762\u770b\u4e00\u4e0b-gdward-2 \u548c-g3\u53c2\u6570\u7684\u610f\u601d\u3002<\/p>\n<p>-g3 \u53c2\u6570\u7684\u610f\u601d\uff1a<\/p>\n<p>man gcc\uff0c\u53ef\u4ee5\u5f97\u51fa\u5982\u4e0b\u7684\u89e3\u91ca\uff1a<\/p>\n<p>-glevel<br \/>\n-ggdblevel<br \/>\n-gstabslevel<br \/>\n-gcofflevel<br \/>\n-gxcofflevel<br \/>\n-gvmslevel<br \/>\nRequest debugging information and also use level to specify how much information. \u00a0The default level is 2.<\/p>\n<p>Level 1 produces minimal information, enough for making backtraces in parts of the program that you don\u2019t plan to debug.<br \/>\nThis includes descriptions of functions and external variables, but no information about local variables and no line numbers.<\/p>\n<p>Level 3 includes extra information, such as all the macro definitions present in the program. \u00a0Some debuggers support macro<br \/>\nexpansion when you use -g3.<\/p>\n<p>\u52a0\u4e86-g3\u7684\u53c2\u6570\u540e\uff0cgcc\u7f16\u8bd1\u7684\u65f6\u5019\uff0c\u4f1a\u5c06\u6269\u5c55\u7684debug \u4fe1\u606f\u7f16\u8bd1\u8fdb\u4e8c\u8fdb\u5236\u6587\u4ef6\u91cc\u9762\uff0c\u5305\u62ec\u5b8f\u5b9a\u4e49\u4fe1\u606f\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5982\u679c\u8981\u4f7f\u7528gdb\u8c03\u8bd5\u4e8c\u8fdb\u5236\u6587\u4ef6\u91cc\u9762\u7684\u5b8f\u5b9a\u4e49\u4fe1\u606f\uff0c\u8fd9\u4e2a\u9009\u9879\u5fc5\u987b\u5f00\u542f\u3002<\/p>\n<p>-gdwarf-2 \u53c2\u6570\u7684\u610f\u601d:<\/p>\n<p>man gcc, \u53ef\u4ee5\u5f97\u51fa\u5982\u4e0b\u76f8\u5173\u7684\u89e3\u91ca\uff1a<\/p>\n<p>-gdwarf-2 does not accept a concatenated debug level, because GCC used to support an option -gdwarf that meant to generate<br \/>\ndebug information in version 1 of the DWARF format (which is very different from version 2), and it would have been too con-<br \/>\nfusing. \u00a0That debug format is long obsolete, but the option cannot be changed now. \u00a0Instead use an additional -glevel option<br \/>\nto change the debug level for DWARF2.<\/p>\n<p>DWARF\u662f\u4e00\u79cd\u5e94\u7528\u7684\u6bd4\u8f83\u5e7f\u6cdb\u7684elf(\u53ef\u6267\u884c\u548c\u94fe\u63a5\u683c\u5f0f)\uff0c \u76ee\u524d\u6709dwarf1, dwarf2,dwarf3 3\u79cd\u7248\u672c\uff0c<\/p>\n<p>\u5176\u4e2d\u7248\u672c1\u5df2\u7ecf\u662f\u6bd4\u8f83\u8001\u65e7\u7684\uff0c\u57fa\u672c\u5e9f\u5f03\u4e0d\u7528\u4e86\u3002<\/p>\n<p>\u8fd9\u8fb9\u7684-gdwarf-2\u610f\u601d\u662f\u4f7f\u7528\u7248\u672c2\u7684\u683c\u5f0f\uff0c<\/p>\n<p>\u5bf9dwarf\u683c\u5f0f\u611f\u5174\u8da3\u7684\uff0c\u53ef\u4ee5\u770b\u4e00\u4e0bibm\u7684\u5f00\u53d1\u8005\u6587\u6863\uff1a<\/p>\n<p>http:\/\/www.ibm.com\/developerworks\/cn\/opensource\/os-debugging\/<\/p>\n<p>\u91cc\u9762\u4f1a\u6709\u4e00\u4e9b\u89e3\u91ca\u3002<\/p>\n<p>\u52a0\u4e0a\u76f8\u5173\u53c2\u6570\u540e\uff0c\u7f16\u8bd1:<\/p>\n<p>gcc -gdwarf-2 -g3 test.c<\/p>\n<p>gdb a.out\u540e\u5c31\u80fd\u591f\u4f7f\u7528 &#8220;p \u5b8f\u540d&#8221; \u8f93\u51fa\u5b8f\u7684\u5185\u5bb9\u4e86<\/p>\n<p>(gdb) p CLIENT6_BEGIN_FLG<br \/>\n$1 = &#8220;&lt;Client6&gt;&#8221;<br \/>\n(gdb)<\/p>\n<p>\u9700\u8981\u67e5\u770b\u5b8f\u5b9a\u4e49\u662f\u5982\u4f55\u88ab\u5c55\u5f00\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u7684\u547d\u4ee4:<\/p>\n<p>macro expand\u00a0<em>macro_name<\/em><\/p>\n<p><strong>\u5b98\u65b9\u53c2\u8003\uff1a<\/strong><\/p>\n<p>\u5177\u4f53\u8be6\u7ec6\u7684\u89e3\u91ca\u548c\u5176\u4ed6\u8bf4\u660e\uff0c\u53ef\u4ee5\u53c2\u8003GDB\u5b98\u65b9\u7f51\u7ad9,\u5185\u5bb9\u8fd8\u662f\u5f88\u597d\u61c2\u7684\u3002<\/p>\n<p>http:\/\/sourceware.org\/gdb\/current\/onlinedocs\/gdb\/Macros.html#Macros<\/p>\n<p>\u6709\u4e2a\u4e2d\u6587\u7ffb\u8bd1\u7684\u7f51\u5740\uff0c\u4e0d\u8fc7\u5e94\u8be5\u4e0d\u662f\u6700\u65b0\u7684\u4e86\u3002<\/p>\n<p>http:\/\/www.eifr.com\/article.php?id=1298&#038;act=print<\/p>\n<p>GDB\u7f51\u5740:\u00a0http:\/\/www.gnu.org\/software\/gdb\/<\/p>\n<\/div>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 \u672c\u6587\u5927\u6982\u9610\u8ff0\u5982\u4f55\u8ba9gdb\u80fd\u591f\u663e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[118],"class_list":["post-3897","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/3897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=3897"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/3897\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=3897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=3897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=3897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}