{"id":845,"date":"2017-12-22T00:27:46","date_gmt":"2017-12-21T16:27:46","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=845"},"modified":"2017-12-22T00:27:46","modified_gmt":"2017-12-21T16:27:46","slug":"gdb%e8%b0%83%e8%af%95%e5%b8%a6%e5%8f%82%e6%95%b0%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/845","title":{"rendered":"gdb\u8c03\u8bd5\u5e26\u53c2\u6570\u7a0b\u5e8f"},"content":{"rendered":"<div id=\"header\">\n<div id=\"HeaderTitle\">\n<div id=\"Title\"><a id=\"Header1_HeaderTitle\" class=\"headermaintitle\" href=\"http:\/\/www.cnblogs.com\/rosesmall\/\">\u7b11\u7b11\u5c0f\u767d<\/a><\/div>\n<div id=\"subTitle\">\u5f52\u7c7b\u81ea\u5df1\u9700\u8981\u7684\u8d44\u6599\uff0c\u6162\u6162\u722c\u884c<\/div>\n<\/div>\n<\/div>\n<div id=\"main\">\n<div id=\"post_detail\">\n<div class=\"post\">\n<h2><a id=\"cb_post_title_url\" href=\"http:\/\/www.cnblogs.com\/rosesmall\/archive\/2012\/04\/10\/2440514.html\">gdb\u8c03\u8bd5\u5e26\u53c2\u6570\u7a0b\u5e8f<\/a><\/h2>\n<div id=\"cnblogs_post_body\" class=\"blogpost-body\">\n<p>\u4e00\u822c\u6765\u8bf4GDB\u4e3b\u8981\u8c03\u8bd5\u7684\u662fC\/C++\u7684\u7a0b\u5e8f\u3002\u8981\u8c03\u8bd5C\/C++\u7684\u7a0b\u5e8f\uff0c\u9996\u5148\u5728\u7f16\u8bd1\u65f6\uff0c\u6211\u4eec\u5fc5\u987b\u8981<br \/>\n\u628a\u8c03\u8bd5\u4fe1\u606f\u52a0\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u4f7f\u7528\u7f16\u8bd1 \u5668\uff08cc\/gcc\/g++\uff09\u7684 -g \u53c2\u6570\u53ef\u4ee5\u505a\u5230\u8fd9\u4e00\u70b9\u3002\u5982\uff1a<\/p>\n<p>&gt; cc -g hello.c -o hello<br \/>\n&gt; g++ -g hello.cpp -o hello<\/p>\n<p>\u5982\u679c\u6ca1\u6709-g\uff0c\u4f60\u5c06\u770b\u4e0d\u89c1\u7a0b\u5e8f\u7684\u51fd\u6570\u540d\u3001\u53d8\u91cf\u540d\uff0c\u6240\u4ee3\u66ff\u7684\u5168\u662f \u8fd0\u884c\u65f6\u7684\u5185\u5b58\u5730\u5740\u3002\u5f53\u4f60\u7528<br \/>\n-g\u628a\u8c03\u8bd5\u4fe1\u606f\u52a0\u5165\u4e4b\u540e\uff0c\u5e76\u6210\u529f\u7f16\u8bd1\u76ee\u6807\u4ee3\u7801\u4ee5\u540e\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u7528gdb\u6765\u8c03\u8bd5\u4ed6\u3002<\/p>\n<p>\u542f\u52a8 GDB\u7684\u65b9\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/p>\n<p>1\u3001gdb &lt;program&gt;<br \/>\nprogram\u4e5f\u5c31\u662f\u4f60\u7684\u6267\u884c\u6587\u4ef6\uff0c\u4e00\u822c\u5728\u5f53\u7136\u76ee\u5f55\u4e0b\u3002<\/p>\n<p>2\u3001gdb &lt;program&gt; core<br \/>\n\u7528gdb\u540c\u65f6\u8c03\u8bd5\u4e00\u4e2a\u8fd0\u884c\u7a0b\u5e8f\u548ccore\u6587\u4ef6\uff0ccore\u662f\u7a0b\u5e8f\u975e\u6cd5\u6267\u884c\u540ecore dump\u540e\u4ea7\u751f<br \/>\n\u7684\u6587\u4ef6\u3002<\/p>\n<p>3\u3001gdb &lt;program&gt; &lt;PID&gt;<br \/>\n\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u662f\u4e00\u4e2a\u670d\u52a1\u7a0b\u5e8f\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u6307\u5b9a\u8fd9\u4e2a\u670d\u52a1\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u8fdb\u7a0bID\u3002gd<br \/>\nb\u4f1a\u81ea\u52a8attach\u4e0a\u53bb\uff0c\u5e76\u8c03\u8bd5\u4ed6\u3002program\u5e94\u8be5\u5728 PATH\u73af\u5883\u53d8\u91cf\u4e2d\u641c\u7d22\u5f97\u5230\u3002<\/p>\n<p>GDB\u542f\u52a8\u65f6\uff0c\u53ef\u4ee5\u52a0\u4e0a\u4e00\u4e9bGDB\u7684\u542f\u52a8\u5f00\u5173\uff0c\u8be6\u7ec6\u7684\u5f00\u5173\u53ef\u4ee5\u7528gdb -help\u67e5\u770b\u3002\u6211\u5728\u4e0b\u9762\u53ea<br \/>\n\u4f8b\u4e3e\u4e00\u4e9b\u6bd4\u8f83\u5e38\u7528\u7684\u53c2\u6570\uff1a<\/p>\n<p>-symbols &lt;file&gt;<br \/>\n-s &lt;file&gt;<br \/>\n\u4ece\u6307\u5b9a\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7b26\u53f7\u8868\u3002<\/p>\n<p>-se file<br \/>\n\u4ece\u6307\u5b9a\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7b26\u53f7\u8868\u4fe1\u606f\uff0c\u5e76\u628a\u4ed6\u7528\u5728\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>-core &lt;file&gt;<br \/>\n-c &lt;file&gt;<br \/>\n\u8c03\u8bd5\u65f6core dump\u7684core\u6587\u4ef6\u3002<\/p>\n<p>-directory &lt;directory&gt;<br \/>\n-d &lt;directory&gt;<br \/>\n\u52a0\u5165\u4e00\u4e2a\u6e90\u6587\u4ef6\u7684\u641c\u7d22\u8def\u5f84\u3002\u9ed8\u8ba4\u641c\u7d22\u8def\u5f84\u662f\u73af\u5883\u53d8\u91cf\u4e2dPATH\u6240\u5b9a\u4e49\u7684\u8def\u5f84\u3002<\/p>\n<p>\u5f53\u4ee5gdb &lt;program&gt;\u65b9\u5f0f\u542f\u52a8gdb\u540e\uff0cgdb\u4f1a\u5728PATH\u8def\u5f84\u548c\u5f53\u524d\u76ee\u5f55\u4e2d\u641c\u7d22&lt;program&gt;\u7684\u6e90\u6587\u4ef6<br \/>\n\u3002 \u5982\u8981\u786e\u8ba4gdb\u662f\u5426\u8bfb\u5230\u6e90\u6587\u4ef6\uff0c\u53ef\u4f7f\u7528l\u6216list\u547d\u4ee4\uff0c\u770b\u770bgdb\u662f\u5426\u80fd\u5217\u51fa\u6e90\u4ee3\u7801\u3002<\/p>\n<p>\u5728gdb\u4e2d\uff0c\u8fd0\u884c\u7a0b\u5e8f\u4f7f\u7528r\u6216\u662frun\u547d\u4ee4\u3002 \u7a0b\u5e8f\u7684\u8fd0\u884c\uff0c\u4f60\u6709\u53ef\u80fd\u9700\u8981\u8bbe\u7f6e\u4e0b\u9762\u56db\u65b9\u9762\u7684\u4e8b\u3002<\/p>\n<p>1\u3001\u7a0b\u5e8f\u8fd0\u884c\u53c2\u6570\u3002<br \/>\nset args \u53ef\u6307\u5b9a\u8fd0\u884c\u65f6\u53c2\u6570\u3002\uff08\u5982\uff1aset args 10 20 30 40 50\uff09<br \/>\nshow args \u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u8bbe\u7f6e\u597d\u7684\u8fd0\u884c\u53c2\u6570\u3002<\/p>\n<p>2\u3001 \u8fd0\u884c\u73af\u5883\u3002<br \/>\npath &lt;dir&gt; \u53ef\u8bbe\u5b9a\u7a0b\u5e8f\u7684\u8fd0\u884c\u8def\u5f84\u3002<br \/>\nshow paths \u67e5\u770b\u7a0b\u5e8f\u7684\u8fd0\u884c\u8def\u5f84\u3002<br \/>\nset environment varname [=value] \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u5982\uff1aset env USER=hchen<br \/>\nshow environment [varname] \u67e5\u770b\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>3\u3001\u5de5\u4f5c\u76ee\u5f55\u3002<br \/>\ncd &lt;dir&gt; \u76f8\u5f53\u4e8eshell\u7684cd\u547d\u4ee4\u3002<br \/>\npwd \u663e\u793a\u5f53\u524d\u7684\u6240\u5728\u76ee\u5f55\u3002<\/p>\n<p>4\u3001\u7a0b\u5e8f\u7684\u8f93\u5165\u8f93\u51fa\u3002<br \/>\ninfo terminal \u663e\u793a\u4f60\u7a0b\u5e8f\u7528\u5230\u7684\u7ec8\u7aef\u7684\u6a21\u5f0f\u3002<br \/>\n\u4f7f\u7528\u91cd\u5b9a\u5411\u63a7\u5236\u7a0b\u5e8f\u8f93\u51fa\u3002\u5982\uff1arun &gt; outfile<br \/>\ntty\u547d\u4ee4\u53ef\u4ee5\u6307\u5199\u8f93\u5165\u8f93\u51fa\u7684\u7ec8\u7aef\u8bbe\u5907\u3002\u5982\uff1atty \/dev\/ttyb<\/p>\n<p><strong>\u5177\u4f53\u6765\u8bf4\u5c31\u662f<\/strong><\/p>\n<div><strong>\u4f8b\u5982\u4e00\u4e2a\u7a0b\u5e8f\u540d\u4e3aprog \u53c2\u6570\u4e3a\u00a0-l a -C abc<br \/>\n\u5219\uff0c\u8fd0\u884cgcc\/g++ -g\u00a0 prog.c\/cpp -o prog<\/strong><\/div>\n<div><strong>\u5c31\u53ef\u4ee5\u7528gdb\u8c03\u8bd5\u7a0b\u5e8fprog<br \/>\n#gdb prog<\/strong><\/div>\n<div><strong>\u8fdb\u5165gdb\u8c03\u8bd5\u754c\u9762<\/strong><\/div>\n<div><strong>\u8f93\u5165\u53c2\u6570\u547d\u4ee4set args \u540e\u9762\u52a0\u4e0a\u7a0b\u5e8f\u6240\u8981\u7528\u7684\u53c2\u6570\uff0c\u6ce8\u610f\uff0c\u4e0d\u518d\u5e26\u6709\u7a0b\u5e8f\u540d\uff0c\u76f4\u63a5\u52a0\u53c2\u6570\uff0c\u5982\uff1a<br \/>\nset args -l a -C abc<\/strong><\/div>\n<div><strong>\u56de\u8f66\u540e\u8f93\u5165<\/strong><\/div>\n<div><strong>r<\/strong><\/div>\n<div><strong>\u5373\u53ef\u5f00\u59cb\u8fd0\u884c<\/strong><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7b11\u7b11\u5c0f\u767d \u5f52\u7c7b\u81ea\u5df1\u9700\u8981\u7684\u8d44\u6599\uff0c\u6162\u6162\u722c\u884c <\/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-845","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/845","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=845"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/845\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}