{"id":225,"date":"2017-11-19T23:36:49","date_gmt":"2017-11-19T15:36:49","guid":{"rendered":"https:\/\/damogame.cn\/?p=225"},"modified":"2017-11-19T23:36:49","modified_gmt":"2017-11-19T15:36:49","slug":"linux-c-%e5%bc%80%e5%8f%91%e5%b7%a5%e5%85%b7gcc-gdb%e7%9a%84%e4%bd%bf%e7%94%a8%ef%bc%9a","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/225","title":{"rendered":"linux c \u5f00\u53d1\u5de5\u5177gcc gdb\u7684\u4f7f\u7528\uff1a"},"content":{"rendered":"<p class=\"csdn_top\">\u539f\u521b\u00a0<span class=\"time\" style=\"font-size: 16px;\">2013\u5e7411\u670804\u65e5 21:10:06<\/span><\/p>\n<div class=\"article_bar clearfix\">\n<ul class=\"right_bar\">\n<li><button class=\"btn-noborder\"><i class=\"icon iconfont icon-read\"><\/i><span class=\"txt\">523<\/span><\/button><\/li>\n<\/ul>\n<\/div>\n<div id=\"article_content\" class=\"article_content csdn-tracking-statistics\" data-mod=\"popu_519\" data-dsm=\"post\">\n<p>1\u3001GCC\u6700\u57fa\u672c\u7684\u7528\u6cd5\u662f\u2236gcc [options] [filenames]<\/p>\n<p>\u5176\u4e2doptions\u5c31\u662f\u7f16\u8bd1\u5668\u6240\u9700\u8981\u7684\u53c2\u6570\uff0cfilenames\u7ed9\u51fa\u76f8\u5173\u7684\u6587\u4ef6\u540d\u79f0\u3002<\/p>\n<p>-c\uff0c\u53ea\u7f16\u8bd1\uff0c\u4e0d\u94fe\u63a5\u6210\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7f16\u8bd1\u5668\u53ea\u662f\u7531\u8f93\u5165\u7684.c\u7b49\u6e90\u4ee3\u7801\u6587\u4ef6\u751f\u6210.o\u4e3a\u540e\u7f00\u7684\u76ee\u6807\u6587\u4ef6\uff0c\u901a\u5e38\u7528\u4e8e\u7f16\u8bd1\u4e0d\u5305\u542b\u4e3b\u7a0b\u5e8f\u7684\u5b50\u7a0b\u5e8f\u6587\u4ef6\u3002<\/p>\n<p>-o output_filename\uff0c\u786e\u5b9a\u8f93\u51fa\u6587\u4ef6\u7684\u540d\u79f0\u4e3aoutput_filename\uff0c\u540c\u65f6\u8fd9\u4e2a\u540d\u79f0\u4e0d\u80fd\u548c\u6e90\u6587\u4ef6\u540c\u540d\u3002\u5982\u679c\u4e0d\u7ed9\u51fa\u8fd9\u4e2a\u9009\u9879\uff0cgcc\u5c31\u7ed9\u51fa\u9884\u8bbe\u7684\u53ef\u6267\u884c\u6587\u4ef6a.out\u3002<\/p>\n<p>-g\uff0c\u4ea7\u751f\u7b26\u53f7\u8c03\u8bd5\u5de5\u5177(GNU\u7684gdb)\u6240\u5fc5\u8981\u7684\u7b26\u53f7\u8d44\u8baf\uff0c\u8981\u60f3\u5bf9\u6e90\u4ee3\u7801\u8fdb\u884c\u8c03\u8bd5\uff0c\u6211\u4eec\u5c31\u5fc5\u987b\u52a0\u5165\u8fd9\u4e2a\u9009\u9879\u3002<\/p>\n<p>-O\uff0c\u5bf9\u7a0b\u5e8f\u8fdb\u884c\u4f18\u5316\u7f16\u8bd1\u3001\u94fe\u63a5\uff0c\u91c7\u7528\u8fd9\u4e2a\u9009\u9879\uff0c\u6574\u4e2a\u6e90\u4ee3\u7801\u4f1a\u5728\u7f16\u8bd1\u3001\u94fe\u63a5\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u4f18\u5316\u5904\u7406\uff0c\u8fd9\u6837\u4ea7\u751f\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6267\u884c\u6548\u7387\u53ef\u4ee5\u63d0\u9ad8\uff0c\u4f46\u662f\uff0c\u7f16\u8bd1\u3001\u94fe\u63a5\u7684\u901f\u5ea6\u5c31\u76f8\u5e94\u5730\u8981\u6162\u4e00\u4e9b\u3002<\/p>\n<p>-O2\uff0c\u6bd4-O\u66f4\u597d\u7684\u4f18\u5316\u7f16\u8bd1\u3001\u94fe\u63a5\uff0c\u5f53\u7136\u6574\u4e2a\u7f16\u8bd1\u3001\u94fe\u63a5\u8fc7\u7a0b\u4f1a\u66f4\u6162\u3002<\/p>\n<p>-Idirname\uff0c\u5c06dirname\u6240\u6307\u51fa\u7684\u76ee\u5f55\u52a0\u5165\u5230\u7a0b\u5e8f\u5934\u6587\u4ef6\u76ee\u5f55\u5217\u8868\u4e2d\uff0c\u662f\u5728\u9884\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u53c2\u6570\u3002C\u7a0b\u5e8f\u4e2d\u7684\u5934\u6587\u4ef6\u5305\u542b\u4e24\u79cd\u60c5\u51b5\u2236<\/p>\n<p>\u53e6\u5916\u9644\u4e0a\u5176\u4ed6\u7528\u6cd5\uff1a<\/p>\n<p>gcc -pedantic source.c\u00a0 \/\/\u4f7f\u7528\u6269\u5c55\u8bed\u6cd5\u4ea7\u751f\u8b66\u544a\u4fe1\u606f\u3002<\/p>\n<p>gcc -Wall source.c \/\/\u4ea7\u751f\u66f4\u591a\u8b66\u544a\u3002\u63a8\u8350\u4f7f\u7528<\/p>\n<p>gcc -Werror source.c \/\/\u8b66\u544a\u5f53\u6210\u9519\u8bef\u6765\u5904\u7406\u3002<\/p>\n<p>gcc -save-temps source.c<\/p>\n<p>time .\/exe \/\/\u7edf\u8ba1\u8fd0\u884c\u65f6\u95f4<\/p>\n<p>2\u3001gdb<\/p>\n<p>2.1\u3001list line1,line2 \u67e5\u770b\u6e90\u4ee3\u7801<\/p>\n<p>list lineNum \u5728lineNum\u7684\u524d\u540e\u6e90\u4ee3\u7801\u663e\u793a\u51fa\u6765<\/p>\n<p>list + \u5217\u51fa\u5f53\u524d\u884c\u7684\u540e\u9762\u4ee3\u7801\u884c<\/p>\n<p>list &#8211; \u5217\u51fa\u5f53\u524d\u884c\u7684\u524d\u9762\u4ee3\u7801\u884c<\/p>\n<p>list function<\/p>\n<p>set listsize count \u8bbe\u7f6e\u663e\u793a\u4ee3\u7801\u7684\u884c\u6570<\/p>\n<p>show listsize \u663e\u793a\u6253\u5370\u4ee3\u7801\u7684\u884c\u6570<\/p>\n<p>list first,last \u663e\u793a\u4ecefirst\u5230last\u7684\u6e90\u4ee3\u7801\u884c<\/p>\n<p>2.2\u3001\u52a0\u8f7d\u7a0b\u5e8f<br \/>\n(gdb) file a.out \/\/\u52a0\u8f7d\u88ab\u8c03\u8bd5\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u6587\u4ef6\u3002<\/p>\n<p>\uff08gdb\uff09set args \u2013b \u2013x<\/p>\n<p>\uff08gdb) show args<\/p>\n<p>\uff08gdb\uff09r \/\/\u6267\u884c\u7a0b\u5e8frun<\/p>\n<p>backtrace\u547d\u4ee4\u4e3a\u5806\u6808\u63d0\u4f9b\u5411\u540e\u8ddf\u8e2a\u529f\u80fd\u3002<\/p>\n<p>Backtrace \u547d\u4ee4\u4ea7\u751f\u4e00\u5f20\u5217\u8868\uff0c\u5305\u542b\u7740\u4ece\u6700\u8fd1\u7684\u8fc7\u7a0b\u5f00\u59cb\u7684\u6240\u6709\u6709\u6548\u8fc7\u7a0b\u548c\u8c03\u7528\u8fd9\u4e9b\u8fc7\u7a0b\u7684\u53c2\u6570\u3002<\/p>\n<p>2.3\u3001\u663e\u793a\u6570\u636e<br \/>\n\uff08gdb) print p (p\u4e3a\u53d8\u91cf\u540d\uff09<\/p>\n<p>\uff08gdb) print find_entry\uff081,0) \uff08\u51fd\u6570\u540d\uff09<\/p>\n<p>\uff08gdb) print *table_start\u00a0 (\u6253\u5370\u7ed3\u6784\u4f53)<\/p>\n<p>\uff08gdb)print\u00a0<a href=\"mailto:h@10\" target=\"_blank\" rel=\"noopener\">h@10<\/a>\u00a0 =(-1,345,23,-234,0,0,0,98,345,10\uff09<\/p>\n<p>whatis\u547d\u4ee4\u53ef\u4ee5\u663e\u793a\u67d0\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b<\/p>\n<p>\uff08gdb) whatis p<br \/>\ntype = int *<\/p>\n<p>2.4 break<\/p>\n<p>break line-number \u4f7f\u7a0b\u5e8f\u6070\u597d\u5728\u6267\u884c\u7ed9\u5b9a\u884c\u4e4b\u524d\u505c\u6b62\u3002<\/p>\n<p>break function-name \u4f7f\u7a0b\u5e8f\u6070\u597d\u5728\u8fdb\u5165\u6307\u5b9a\u7684\u51fd\u6570\u4e4b\u524d\u505c\u6b62\u3002<\/p>\n<p>break line-or-function if condition \u5982\u679ccondition\uff08\u6761\u4ef6\uff09\u662f\u771f\uff0c\u7a0b\u5e8f\u5230\u8fbe\u6307\u5b9a\u884c\u6216\u51fd\u6570\u65f6\u505c\u6b62\u3002<\/p>\n<p>break routine-name \u5728\u6307\u5b9a\u4f8b\u7a0b\u7684\u5165\u53e3\u5904\u8bbe\u7f6e\u65ad\u70b9<\/p>\n<p>\u5982\u679c\u8be5\u7a0b\u5e8f\u662f\u7531\u5f88\u591a\u539f\u6587\u4ef6\u6784\u6210\u7684\uff0c\u4f60\u53ef\u4ee5\u5728\u5404\u4e2a\u539f\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u800c\u4e0d\u662f\u5728\u5f53\u524d\u7684\u539f\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u5176\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\uff08gdb) break filename:line-number<\/p>\n<p>\uff08gdb) break filename:function-name<\/p>\n<p>\uff08gdb) break line-or-function if expr<\/p>\n<p>\uff08gdb) break 46 if testsize==100<\/p>\n<p>2.5\u3001\u65ad\u70b9\u4fe1\u606f<\/p>\n<p>\uff08gdb) info break<\/p>\n<p>\uff08gdb) delete breakpoint 1 \u8be5\u547d\u4ee4\u5c06\u4f1a\u5220\u9664\u7f16\u53f7\u4e3a1\u7684\u65ad\u70b9\uff0c\u5982\u679c\u4e0d\u5e26\u7f16\u53f7\u53c2\u6570\uff0c\u5c06\u5220\u9664\u6240\u6709\u7684\u65ad\u70b9<\/p>\n<p>\uff08gdb) delete breakpoint<\/p>\n<p>\uff08gdb) disable breakpoint 1<\/p>\n<p>\uff08gdb) enable breakpoint 1<\/p>\n<p>\uff08gdb)clear number\u00a0 \u6ce8\uff1anumber \u4e3a\u6e90\u6587\u4ef6\u7684\u67d0\u4e2a\u4ee3\u7801\u884c\u7684\u884c\u53f7<\/p>\n<p>2.6\u3001\u53d8\u91cf\u68c0\u67e5\u8d4b\u503c<\/p>\n<p>whatis\uff1a\u8bc6\u522b\u6570\u7ec4\u6216\u53d8\u91cf\u7684\u7c7b\u578b<\/p>\n<p>ptype\uff1a\u6bd4whatis\u7684\u529f\u80fd\u66f4\u5f3a\uff0c\u4ed6\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u7ed3\u6784\u7684\u5b9a\u4e49<\/p>\n<p>set variable = value\uff1a\u5c06\u503c\u8d4b\u4e88\u53d8\u91cf<\/p>\n<p>print variable = value or p variable = value : \u9664\u4e86\u663e\u793a\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u5916\uff0c\u8fd8\u53ef\u4ee5\u7528\u6765\u8d4b\u503c<\/p>\n<p>2.7\u3001\u6267\u884c<\/p>\n<p>\uff08gdb) next<\/p>\n<p>\uff08gdb) step<\/p>\n<p>\uff08gdb) call gen_and_sork\uff081234,1,0)<\/p>\n<p>\uff08gdb) call printf\uff08\u201cabcd\u201d\uff09<\/p>\n<p>\uff08gdb) finish\u00a0 \u7ed3\u675f\u6267\u884c\u5f53\u524d\u51fd\u6570\uff0c\u663e\u793a\u5176\u8fd4\u56de\u503c\uff08\u5982\u679c\u6709\u7684\u8bdd\uff09<\/p>\n<p>2.8\u3001\u5176\u4ed6\u7528\u6cd5\uff1a<br \/>\n(gdb) crash<br \/>\n(gdb) run<br \/>\n(gdb) backtrace<br \/>\n(gdb) frame 3<br \/>\n(gdb) quit\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u521b\u00a02013\u5e7411\u670804\u65e5 21:10<\/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-225","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/225","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=225"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}