{"id":52435,"date":"2023-07-18T18:28:13","date_gmt":"2023-07-18T10:28:13","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=52435"},"modified":"2023-07-18T18:28:13","modified_gmt":"2023-07-18T10:28:13","slug":"linux-gdb-c","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-gdb-c.html","title":{"rendered":"\u5728 Linux \u4e2d\u8c03\u8bd5 C \u7a0b\u5e8f\u7684\u798f\u97f3\u2014\u2014gdb"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u65e0\u8bba\u591a\u4e48\u6709\u7ecf\u9a8c\u7684\u7a0b\u5e8f\u5458\uff0c\u5f00\u53d1\u7684\u4efb\u4f55\u8f6f\u4ef6\u90fd\u4e0d\u53ef\u80fd\u5b8c\u5168\u6ca1\u6709 bug\u3002\u56e0\u6b64\uff0c\u6392\u67e5\u53ca\u4fee\u590d bug \u6210\u4e3a\u8f6f\u4ef6\u5f00\u53d1\u5468\u671f\u4e2d\u6700\u91cd\u8981\u7684\u4efb\u52a1\u4e4b\u4e00\u3002\u6709\u8bb8\u591a\u529e\u6cd5\u53ef\u4ee5\u6392\u67e5 bug\uff08\u6d4b\u8bd5\u3001\u4ee3\u7801\u81ea\u5ba1\u7b49\u7b49\uff09\uff0c\u4f46\u662f\u8fd8\u6709\u4e00\u4e9b\u4e13\u7528\u8f6f\u4ef6\uff08\u79f0\u4e3a\u8c03\u8bd5\u5668\uff09\u53ef\u4ee5\u5e2e\u52a9\u51c6\u786e\u5b9a\u4f4d\u95ee\u9898\u7684\u6240\u5728\uff0c\u4ee5\u4fbf\u8fdb\u884c\u4fee\u590d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u5982\u679c\u4f60\u662f C\/C++ \u7a0b\u5e8f\u5458\uff0c\u6216\u8005\u4f7f\u7528 Fortran \u548c Modula-2 \u7f16\u7a0b\u8bed\u8a00\u5f00\u53d1\u8f6f\u4ef6\uff0c\u90a3\u4e48\u4f60\u5c06\u4f1a\u5f88\u4e50\u610f\u77e5\u9053\u6709\u8fd9\u4e48\u4e00\u6b3e\u4f18\u79c0\u7684\u8c03\u8bd5\u5668 - GDB - \u53ef\u4ee5\u5e2e\u4f60\u66f4\u8f7b\u677e\u5730\u8c03\u8bd5\u4ee3\u7801 bug \u4ee5\u53ca\u5176\u5b83\u95ee\u9898\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u4e00\u4e0b GDB \u8c03\u8bd5\u5668\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5305\u62ec\u5b83\u63d0\u4f9b\u7684\u4e00\u4e9b\u6709\u7528\u7684\u529f\u80fd\/\u9009\u9879\u3002<\/p>\n <\/p>\n \u5728\u6211\u4eec\u5f00\u59cb\u4e4b\u524d\uff0c\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u6587\u7ae0\u4e2d\u7684\u6240\u6709\u8bf4\u660e\u548c\u793a\u4f8b\u90fd\u5df2\u7ecf\u5728 Ubuntu 14.04 LTS \u4e2d\u6d4b\u8bd5\u8fc7\u3002\u6559\u7a0b\u4e2d\u7684\u793a\u4f8b\u4ee3\u7801\u90fd\u662f C \u8bed\u8a00\u5199\u7684\uff1b\u4f7f\u7528\u7684 shell \u4e3a bash\uff084.3.11\uff09\uff1bGDB \u7248\u672c\u4e3a 7.7.1\u3002<\/p>\n GDB \u8c03\u8bd5\u5668\u57fa\u7840<\/strong><\/div>\n \u901a\u4fd7\u7684\u8bb2\uff0cGDB \u53ef\u4ee5\u8ba9\u4f60\u770b\u5230\u7a0b\u5e8f\u5728\u6267\u884c\u8fc7\u7a0b\u65f6\u7684\u5185\u90e8\u6d41\u7a0b\uff0c\u5e76\u5e2e\u4f60\u660e\u786e\u95ee\u9898\u7684\u6240\u5728\u3002\u6211\u4eec\u5c06\u5728\u4e0b\u4e00\u8282\u901a\u8fc7\u4e00\u4e2a\u6709\u6548\u7684\u793a\u4f8b\u6765\u8ba8\u8bba GDB \u8c03\u8bd5\u5668\u7684\u7528\u6cd5\uff0c\u4f46\u5728\u6b64\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u63a2\u8ba8\u4e00\u4e9b\u4e4b\u540e\u5bf9\u4f60\u6709\u5e2e\u52a9\u7684\u57fa\u672c\u8981\u70b9\u3002<\/p>\n \u9996\u5148\uff0c\u4e3a\u4e86\u80fd\u591f\u987a\u5229\u4f7f\u7528\u7c7b\u4f3c GDB \u8fd9\u6837\u7684\u8c03\u8bd5\u5668\uff0c\u4f60\u5fc5\u987b\u4ee5\u6307\u5b9a\u7684\u65b9\u5f0f\u7f16\u8bd1\u7a0b\u5e8f\uff0c\u8ba9\u7f16\u8bd1\u5668\u4ea7\u751f\u8c03\u8bd5\u5668\u6240\u9700\u7684\u8c03\u8bd5\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u5728\u4f7f\u7528 gcc \u7f16\u8bd1\u5668\uff08\u6211\u4eec\u5c06\u5728\u672c\u6559\u7a0b\u4e4b\u540e\u7684\u7ae0\u8282\u7528\u5b83\u6765\u7f16\u8bd1 C \u7a0b\u5e8f\u793a\u4f8b\uff09\u7f16\u8bd1\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4f60\u9700\u8981\u4f7f\u7528-g<\/span> \u547d\u4ee4\u884c\u9009\u9879\u3002<\/p>\n \u60f3\u8981\u4e86\u89e3 gcc \u7f16\u8bd1\u5668\u624b\u518c\u9875\u4e2d\u5173\u4e8e -g<\/span> \u547d\u4ee4\u884c\u9009\u9879\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u8bf7\u770b\u8fd9\u91cc\u3002<\/p>\n \u4e0b\u4e00\u6b65\uff0c\u786e\u4fdd\u5728\u4f60\u7684\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5 GDB \u8c03\u8bd5\u5668\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u800c\u4e14\u4f60\u4f7f\u7528\u7684\u662f\u57fa\u4e8e Debian \u7684\u7cfb\u7edf\uff08\u5982 Ubuntu\uff09\uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8f7b\u677e\u5b89\u88c5\u8be5\u5de5\u5177\uff1a<\/p>\n \u5728\u5176\u4ed6\u53d1\u884c\u7248\u4e0a\u7684\u5b89\u88c5\u65b9\u6cd5\uff0c\u8bf7\u770b\u8fd9\u91cc\u3002<\/p>\n \u73b0\u5728\uff0c\u5f53\u4f60\u6309\u7167\u4e0a\u8ff0\u7684\u65b9\u5f0f\u7f16\u8bd1\u5b8c\u7a0b\u5e8f\uff08gcc -g<\/span> \u547d\u4ee4\u884c\u9009\u9879\uff09\uff0c\u540c\u65f6\u4e5f\u5df2\u7ecf\u5b89\u88c5\u597d GDB \u8c03\u8bd5\u5668\uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8ba9\u7a0b\u5e8f\u5728\u8c03\u8bd5\u6a21\u5f0f\u4e2d\u8fd0\u884c\uff1a<\/p>\n \u8fd9\u6837\u505a\u4f1a\u521d\u59cb\u5316 GDB \u8c03\u8bd5\u5668\uff0c\u4f46\u4f60\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u6b64\u65f6\u8fd8\u4e0d\u4f1a\u88ab\u542f\u52a8\u3002\u5728\u8fd9\u4e2a\u65f6\u5019\u4f60\u5c31\u53ef\u4ee5\u5b9a\u4e49\u8c03\u8bd5\u76f8\u5173\u7684\u8bbe\u7f6e\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5728\u7279\u5b9a\u884c\u6216\u51fd\u6570\u4e2d\u8bbe\u7f6e\u4e00\u4e2a\u65ad\u70b9\u8ba9 GDB \u5728\u8be5\u884c\u6682\u505c\u7a0b\u5e8f\u7684\u6267\u884c\u3002<\/p>\n \u63a5\u7740\uff0c\u4e3a\u4e86\u542f\u52a8\u4f60\u7684\u7a0b\u5e8f\uff0c\u4f60\u5fc5\u987b\u8f93\u5165\u6267\u884c\u4ee5\u4e0b gdb \u547d\u4ee4\uff1a<\/p>\n \u5728\u8fd9\u91cc\uff0c\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u9700\u8981\u4e00\u4e9b\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u6307\u5b9a\u8fd9\u4e9b\u53c2\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n GDB \u63d0\u4f9b\u4e86\u5f88\u591a\u6709\u7528\u7684\u547d\u4ee4\uff0c\u5728\u8c03\u8bd5\u7684\u65f6\u5019\u603b\u662f\u80fd\u6d3e\u7684\u4e0a\u7528\u573a\u3002\u6211\u4eec\u5c06\u5728\u4e0b\u4e00\u8282\u8ba8\u8bba\u5176\u4e2d\u4e00\u90e8\u5206\u547d\u4ee4\u3002<\/p>\n \u73b0\u5728\u6211\u4eec\u5bf9 GDB \u53ca\u5176\u7528\u6cd5\u6709\u4e86\u57fa\u672c\u7684\u6982\u5ff5\u3002\u56e0\u6b64\uff0c\u8ba9\u6211\u4eec\u4e3e\u4f8b\u6765\u5e94\u7528\u6240\u5b66\u7684\u77e5\u8bc6\u3002\u8fd9\u662f\u4e00\u6bb5\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n \u7b80\u5355\u8bf4\u660e\u4e00\u4e0b\u8fd9\u6bb5\u4ee3\u7801\u8981\u505a\u4ec0\u4e48\u4e8b\u3002\u83b7\u53d6 val<\/span>\u6570\u7ec4\u4e2d\u6bcf\u4e00\u4e2a\u503c\uff0c\u5c06\u5176\u8d4b\u503c\u7ed9out<\/span> \u53d8\u91cf\uff0c\u7136\u540e\u5c06tot<\/span> \u4e4b\u524d\u7684\u503c\u4e0e0xffffffff\/out<\/span> \u7684\u7ed3\u679c\u503c\u7d2f\u52a0\uff0c\u8d4b\u503c\u7ed9 tot<\/span> \u53d8\u91cf\u3002<\/p>\n \u8fd9\u91cc\u9047\u5230\u7684\u95ee\u9898\u662f\uff0c\u5f53\u6267\u884c\u8fd9\u6bb5\u4ee3\u7801\u7f16\u8bd1\u540e\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u65f6\uff0c\u4ea7\u751f\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n \u56e0\u6b64\uff0c\u8981\u8c03\u8bd5\u8fd9\u6bb5\u4ee3\u7801\uff0c\u7b2c\u4e00\u6b65\u662f\u4f7f\u7528 \u63a5\u7740\uff0c\u8ba9\u6211\u4eec\u8fd0\u884c GDB \u8c03\u8bd5\u5668\u5e76\u6307\u5b9a\u8981\u8c03\u8bd5\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u3002\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n \u73b0\u5728\uff0c\u6211\u521a\u624d\u5f97\u5230\u7684\u9519\u8bef\u662f Floating point exception<\/span>\uff0c\u5927\u90e8\u5206\u4eba\u53ef\u80fd\u5df2\u7ecf\u77e5\u9053\uff0c\u8fd9\u662f\u56e0\u4e3a n % x<\/span>\uff0c\u5f53 x \u4e3a 0 \u65f6\u5bfc\u81f4\u7684\u9519\u8bef\u3002\u6240\u4ee5\uff0c\u8003\u8651\u5230\u8fd9\u4e00\u70b9\uff0c\u6211\u5728 11 \u884c\u4ee3\u7801\u9664\u6cd5\u8fd0\u7b97\u7684\u4f4d\u7f6e\u5904\u6dfb\u52a0\u4e86\u4e00\u4e2a\u65ad\u70b9\u3002\u5982\u4e0b\uff1a<\/p>\n \u6ce8\u610f (gdb)<\/span> \u662f\u8c03\u8bd5\u5668\u7684\u63d0\u793a\u4fe1\u606f\uff0c\u6211\u53ea\u8f93\u5165\u4e86break 11<\/span> \u547d\u4ee4\u3002<\/p>\n \u73b0\u5728\uff0c\u8ba9 GDB \u5f00\u59cb\u8fd0\u884c\u7a0b\u5e8f\uff1a<\/p>\n \u5f53\u65ad\u70b9\u7b2c\u4e00\u6b21\u88ab\u547d\u4e2d\u65f6\uff0cGDB \u663e\u793a\u5982\u4e0b\u8f93\u51fa\uff1a<\/p>\n \u6b63\u5982\u4f60\u6240\u770b\u5230\u7684\u90a3\u6837\uff0c\u8c03\u8bd5\u5668\u4f1a\u663e\u793a\u65ad\u70b9\u6240\u5728\u7684\u884c\u4ee3\u7801\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u6253\u5370\u51fa\u6b64\u65f6out<\/span> \u7684\u503c\u3002\u5982\u4e0b\uff1a<\/p>\n \u5982\u4e0a\u6240\u793a\uff0c\u503c 5<\/span>\u88ab\u6253\u5370\u51fa\u6765\u4e86\u3002\u8fd9\u4e2a\u65f6\u5019\u4e00\u5207\u90fd\u8fd8\u662f\u6b63\u5e38\u7684\u3002\u8ba9\u8c03\u8bd5\u5668\u7ee7\u7eed\u6267\u884c\u7a0b\u5e8f\u76f4\u5230\u547d\u4e2d\u4e0b\u4e00\u4e2a\u65ad\u70b9\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 c<\/span> \u547d\u4ee4\u6765\u5b8c\u6210\uff1a<\/p>\n \u91cd\u590d\u4e0a\u8ff0\u64cd\u4f5c\uff0c\u76f4\u5230 out<\/span>\u503c\u53d8\u4e3a0<\/span> \u65f6\u3002<\/p>\n \u73b0\u5728\uff0c\u4e3a\u4e86\u8fdb\u4e00\u6b65\u786e\u8ba4\u95ee\u9898\uff0c\u6211\u4f7f\u7528 GDB \u7684s<\/span> \uff08\u6216 step<\/span>\uff09 \u547d\u4ee4\u4ee3\u66ff c<\/span> \u547d\u4ee4\u3002\u56e0\u4e3a\uff0c\u6211\u53ea\u60f3\u8ba9\u5f53\u524d\u7a0b\u5e8f\u5728\u7b2c 11 \u884c\u4e4b\u540e\u6682\u505c\uff0c\u518d\u4e00\u6b65\u6b65\u6267\u884c\uff0c\u770b\u770b\u8fd9\u4e2a\u65f6\u5019\u662f\u5426\u4f1a\u53d1\u751f\u5d29\u6e83\u3002<\/p>\n \u4ee5\u4e0b\u662f\u6267\u884c\u4e4b\u540e\u8f93\u51fa\u4fe1\u606f\uff1a<\/p>\n \u662f\u7684\uff0c\u5982\u4e0a\u8f93\u51fa\u7684\u7b2c\u4e00\u884c\u5185\u5bb9\u6240\u793a\uff0c\u8fd9\u5c31\u662f\u629b\u51fa\u5f02\u5e38\u7684\u5730\u65b9\u3002\u5f53\u6211\u518d\u6b21\u5c1d\u8bd5\u8fd0\u884cs<\/span> \u547d\u4ee4\u65f6\uff0c\u95ee\u9898\u6700\u7ec8\u4e5f\u5f97\u5230\u4e86\u786e\u8ba4\uff1a<\/p>\n \u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u5c31\u53ef\u4ee5\u4f7f\u7528 GDB \u8c03\u8bd5\u4f60\u7684\u7a0b\u5e8f\u3002<\/p>\n GDB \u63d0\u4f9b\u4e86\u5f88\u591a\u529f\u80fd\u4f9b\u7528\u6237\u7814\u7a76\u548c\u4f7f\u7528\uff0c\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4ec5\u4ec5\u53ea\u4ecb\u7ecd\u4e86\u5f88\u5c11\u4e00\u90e8\u5206\u5185\u5bb9\u3002\u901a\u8fc7 GDB \u7684\u624b\u518c\u9875\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4e86\u89e3\u8fd9\u4e2a\u5de5\u5177\uff0c\u5f53\u4f60\u5728\u8c03\u8bd5\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u5c1d\u8bd5\u4f7f\u7528\u4e00\u4e0b\u5b83\u3002GDB \u8c03\u8bd5\u5668\u6709\u4e00\u5b9a\u7684\u5b66\u4e60\u96be\u5ea6\uff0c\u4f46\u662f\u5b83\u5f88\u503c\u5f97\u4f60\u4e0b\u529f\u592b\u5b66\u4e60\u3002<\/p>\n via: https:\/\/www.howtoforge.com\/tutorial\/how-to-debug-c-programs-in-linux-using-gdb\/<\/a><\/p>\n \u4f5c\u8005\uff1aAnsh<\/a> \u8bd1\u8005\uff1azhb127<\/a> \u6821\u5bf9\uff1ajasminepeng<\/a><\/p>\n \u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-8174-1.html<\/a><\/p>\n |