{"id":4574,"date":"2019-08-24T00:49:59","date_gmt":"2019-08-23T16:49:59","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=4574"},"modified":"2019-08-24T00:50:01","modified_gmt":"2019-08-23T16:50:01","slug":"gdb","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/gdb","title":{"rendered":"gdb\u547d\u4ee4 – GUN\u8c03\u8bd5\u5668"},"content":{"rendered":"\n

gdb\u547d\u4ee4\u5305\u542b\u5728GNU\u7684gcc\u5f00\u53d1\u5957\u4ef6\u4e2d\uff0c\u662f\u529f\u80fd\u5f3a\u5927\u7684\u7a0b\u5e8f\u8c03\u8bd5\u5668\u3002<\/p>\n\n\n\n

gdb\u4e2d\u7684\u547d\u4ee4\u5f88\u591a\uff0c\u4f46\u6211\u4eec\u53ea\u9700\u638c\u63e1\u5176\u4e2d\u5341\u4e2a\u5de6\u53f3\u7684\u547d\u4ee4\uff0c\u5c31\u5927\u81f4\u53ef\u4ee5\u5b8c\u6210\u65e5\u5e38\u7684\u57fa\u672c\u7684\u7a0b\u5e8f\u8c03\u8bd5\u5de5\u4f5c\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>gdb [\u53c2\u6570] [\u6587\u4ef6]<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n
-cd<\/td>\u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55<\/td><\/tr>
-q<\/td>\u5b89\u9759\u6a21\u5f0f\uff0c\u4e0d\u6253\u5370\u4ecb\u7ecd\u4fe1\u606f\u548c\u7248\u672c\u4fe1\u606f<\/td><\/tr>
-d<\/td>\u6dfb\u52a0\u6587\u4ef6\u67e5\u627e\u8def\u5f84<\/td><\/tr>
-x<\/td>\u4ece\u6307\u5b9a\u6587\u4ef6\u4e2d\u6267\u884cGDB\u6307\u4ee4<\/td><\/tr>
-s<\/td>\u8bbe\u7f6e\u8bfb\u53d6\u7684\u7b26\u53f7\u8868\u6587\u4ef6<\/td><\/tr><\/tbody><\/table>\n\n\n\n

\u5e38\u7528\u547d\u4ee4\uff1a<\/strong><\/p>\n\n\n\n
file <\u6587\u4ef6\u540d><\/td>\u52a0\u8f7d\u88ab\u8c03\u8bd5\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u6587\u4ef6<\/td><\/tr>
run<\/td>\u91cd\u65b0\u5f00\u59cb\u8fd0\u884c\u6587\u4ef6<\/td><\/tr>
start<\/td>\u5355\u6b65\u6267\u884c\uff0c\u8fd0\u884c\u7a0b\u5e8f\uff0c\u505c\u5728\u7b2c\u4e00\u6267\u884c\u8bed\u53e5<\/td><\/tr>
list<\/td>\u67e5\u770b\u539f\u4ee3\u7801\uff0c\u7b80\u5199l<\/td><\/tr>
set<\/td>\u8bbe\u7f6e\u53d8\u91cf\u7684\u503c<\/td><\/tr>
next<\/td>\u5355\u6b65\u8c03\u8bd5\uff08\u9010\u8fc7\u7a0b\uff0c\u51fd\u6570\u76f4\u63a5\u6267\u884c\uff09,\u7b80\u5199n<\/td><\/tr>
step<\/td>\u5355\u6b65\u8c03\u8bd5\uff08\u9010\u8bed\u53e5\uff1a\u8df3\u5165\u81ea\u5b9a\u4e49\u51fd\u6570\u5185\u90e8\u6267\u884c\uff09,\u7b80\u5199s<\/td><\/tr>
backtrace<\/td>\u67e5\u770b\u51fd\u6570\u7684\u8c03\u7528\u7684\u6808\u5e27\u548c\u5c42\u7ea7\u5173\u7cfb,\u7b80\u5199bt<\/td><\/tr>
frame<\/td>\u5207\u6362\u51fd\u6570\u7684\u6808\u5e27,\u7b80\u5199f<\/td><\/tr>
info<\/td>\u67e5\u770b\u51fd\u6570\u5185\u90e8\u5c40\u90e8\u53d8\u91cf\u7684\u6570\u503c,\u7b80\u5199i<\/td><\/tr>
finish<\/td>\u7ed3\u675f\u5f53\u524d\u51fd\u6570\uff0c\u8fd4\u56de\u5230\u51fd\u6570\u8c03\u7528\u70b9<\/td><\/tr>
continue<\/td>\u7ee7\u7eed\u8fd0\u884c,\u7b80\u5199c<\/td><\/tr>
print<\/td>\u6253\u5370\u503c\u53ca\u5730\u5740,\u7b80\u5199p<\/td><\/tr>
quit<\/td>\u9000\u51fagdb,\u7b80\u5199q<\/td><\/tr><\/tbody><\/table>\n\n\n\n

gdb\u547d\u4ee4\u62e5\u6709\u8f83\u591a\u5185\u90e8\u547d\u4ee4\u3002\u5728gdb\u547d\u4ee4\u63d0\u793a\u7b26\u201c(gdb)\u201d\u4e0b\u8f93\u5165\u201chelp\u201d\u53ef\u4ee5\u67e5\u770b\u6240\u6709\u5185\u90e8\u547d\u4ee4\u53ca\u4f7f\u7528\u8bf4\u660e\u3002\u8981\u4f7f\u7528gdb\u8c03\u8bd5\u7a0b\u5e8f\uff0c\u5728\u4f7f\u7528gcc\u7f16\u8bd1\u6e90\u4ee3\u7801\u65f6\u5fc5\u987b\u52a0\u4e0a\u201c-g\u201d\u53c2\u6570\u3002<\/p>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u542f\u52a8gdb\u8c03\u8bd5\u5668\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# gdb\n(gdb)<\/pre>\n\n\n\n

\u52a0\u8f7d\u4e8c\u8fdb\u5236\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n\n\n\n

(gdb)file linuxcool.out<\/pre>\n\n\n\n

\u8fd0\u884c\u5e76\u8ddf\u8e2a\u7a0b\u5e8f\uff1a<\/p>\n\n\n\n

(gdb)start<\/pre>\n","protected":false},"excerpt":{"rendered":"

gdb\u547d\u4ee4\u5305\u542b\u5728GNU\u7684gcc\u5f00\u53d1\u5957\u4ef6\u4e2d\uff0c\u662f\u529f\u80fd\u5f3a\u5927\u7684\u7a0b\u5e8f\u8c03\u8bd5\u5668\u3002 gdb\u4e2d\u7684\u547d\u4ee4\u5f88\u591a\uff0c\u4f46\u6211\u4eec\u53ea\u9700\u638c\u63e1\u5176\u4e2d\u5341\u4e2a […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4574"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=4574"}],"version-history":[{"count":5,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4574\/revisions"}],"predecessor-version":[{"id":4774,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4574\/revisions\/4774"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=4574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=4574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=4574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}