{"id":273982,"date":"2023-06-02T20:07:53","date_gmt":"2023-06-02T12:07:53","guid":{"rendered":"https:\/\/lrxjmw.cn\/sdtszxcwbjhs.html"},"modified":"2023-06-02T20:07:53","modified_gmt":"2023-06-02T12:07:53","slug":"sdtszxcwbjhs","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sdtszxcwbjhs.html","title":{"rendered":"\u624b\u52a8\u8c03\u8bd5\u8fd9\u4e9b\u9519\u8bef\u4e0d\u4ec5\u8017\u65f6\uff0c\u8fd8\u96be\u53d1\u73b0\u5e76\u7ea0\u6b63\uff01"},"content":{"rendered":"

Credit:Moini[1]<\/p>\n

\u4f5c\u4e3a\u4e00\u4e2a\u7a0b\u5e8f\u5458\uff0c\u6211\u6653\u5f97\u6211\u80af\u5b9a\u4f1a\u72af\u9519\u8bef\u2014\u2014\u600e\u4e48\u53ef\u80fd\u4e0d\u9519\u4e8b\uff01\u7a0b\u5e8f\u5458\u4e5f\u662f\u4eba\u554a\u3002\u6709\u7684\u9519\u8bef\u80fd\u5728\u7f16\u7801\u8fc7\u7a0b\u4e2d\u53ca\u65f6\u53d1\u89c9\uff0c\u800c\u6709\u4e9b\u5374\u5f97\u7b49\u5230\u8f6f\u4ef6\u6d4b\u8bd5\u4e86\u80fd\u591f\u5c55\u73b0\u4e0b\u6765\u3002\u4f46\u662f\uff0c\u8fd8\u6709\u4e00\u7c7b\u9519\u8bef\u5e76\u4e0d\u80fd\u5728\u8fd9\u4e24\u4e2a\u9636\u6bb5\u88ab\u89e3\u51b3\uff0c\u8fd9\u5c31\u9020\u6210\u8f6f\u4ef6\u4e0d\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u751a\u81f3\u662f\u63d0\u65e9\u4e2d\u6b62\u3002<\/p>\n

\u5047\u5982\u4f60\u8fd8\u6ca1\u731c\u51fa\u662f\u90a3\u4e2a\u9519\u8bef\uff0c\u6211\u8bf4\u7684\u5c31\u662f\u548c\u663e\u5b58\u76f8\u5173\u7684\u9519\u8bef\u3002\u81ea\u52a8\u8c03\u8bd5\u8fd9\u79cd\u9519\u8bef\u9664\u4e86\u5386\u65f6\uff0c\u4f46\u662f\u5f88\u96be\u53d1\u89c9\u5e76\u7ea0\u6b63\u3002\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u8fd9\u4e9b\u9519\u8bef\u5f88\u5e38\u89c1\uff0c\u975e\u5e38\u662f\u5728\u7528C\/C++\u8fd9\u7c7b\u5bb9\u8bb8\u81ea\u52a8\u7ba1\u7406\u663e\u5b58[2]\u7684\u8bed\u8a00\u7f16\u64b0\u7684\u8f6f\u4ef6\u91cc\u3002<\/p>\n

\u8f9b\u8fd0\u7684\u662f\uff0c\u73b0\u4eca\u6709\u4e00\u4e9b\u7f16\u7a0b\u5de5\u5177\u5c31\u80fd\u5e2e\u4f60\u5728\u8f6f\u4ef6\u7a0b\u5e8f\u4e2d\u627e\u5230\u90a3\u4e9b\u548c\u663e\u5b58\u76f8\u5173\u7684\u9519\u8bef\u3002\u5728\u8fd9\u79cd\u5de5\u5177\u96c6\u4e2d\uff0c\u6211\u8bc4\u4f30\u4e86\u4e94\u6b3e\u652f\u6301Linux<\/a>\u7684\u3001\u6d41\u884c\u7684\u3001\u81ea\u7531\u5f00\u6e90\u7684\u663e\u5b58\u8c03\u8bd5\u5668\uff1aDmalloc\u3001ElectricFence\u3001Memcheck\u3001Memwatch\u4ee5\u53caMtrace\u3002\u5728\u65e5\u5e38\u7f16\u7801\u4e2d\uff0c\u6211\u65e9\u5df2\u7528\u8fc7\u8fd9\u4e94\u4e2a\u8c03\u8bd5\u5668\u4e86\uff0c\u6240\u4ee5\u8fd9\u79cd\u8bc4\u4f30\u662f\u6784\u5efa\u5728\u6211\u7684\u5b9e\u9645\u4f53\u9a8c\u4e4b\u4e0a\u7684\u3002<\/p>\n

\u5f00\u53d1\u8005\uff1aGrayWatson<\/p>\n

\u8bc4\u4f30\u7248\u672c\uff1a5.5.2<\/p>\n

\u652f\u6301\u7684Linux\u7248\u672c\uff1a\u6240\u6709\u79cd\u7c7b<\/p>\n

\u8bb8\u53ef\uff1aCC3.0<\/p>\n

Dmalloc\u662fGrayWatson\u5f00\u53d1\u7684\u4e00\u6b3e\u663e\u5b58\u8c03\u8bd5\u5de5\u5177\u3002\u5b83\u662f\u4f5c\u4e3a\u5e93\u6765\u5b9e\u73b0\u7684\uff0c\u5c01\u88c5\u4e86\u6807\u51c6\u663e\u5b58\u7ba1\u7406\u51fd\u6570\u5982malloc,calloc,free\u7b49\uff0c\u4f7f\u7a0b\u5e8f\u5458\u5f97\u4ee5\u68c0\u67e5\u51fa\u6709\u95ee\u9898\u7684\u4ee3\u7801\u3002<\/p>\n

Dmalloc<\/p>\n

\u5c31\u50cf\u5de5\u5177\u7684\u7f51\u9875\u6240\u793a\uff0c\u8fd9\u4e2a\u8c03\u8bd5\u5668\u63d0\u4f9b\u7684\u7279\u70b9\u5305\u62ec\u663e\u5b58\u6cc4\u9732\u8ddf\u8e2a\u3001\u91cd\u590d\u91ca\u653e\u663e\u5b58doublefree[4]\u9519\u8bef\u8ddf\u8e2a\u3001\u4ee5\u53ca\u8d8a\u754c\u5199\u5165fence-postwrite[5]\u68c0\u67e5\u3002\u5176\u5b83\u7279\u70b9\u5305\u62ec\u62a5\u544a\u9519\u8bef\u7684\u6587\u4ef6\/\u884c\u53f7\u3001\u901a\u7528\u7684\u6570\u636e\u7edf\u8ba1\u8bb0\u5f55\u3002<\/p>\n

\u66f4\u65b0\u5185\u5bb9<\/p>\n

5.5.2\u7248\u672c\u662f\u4e00\u4e2abug\u4fee\u6b63\u53d1\u884c\u7248[6]\uff0c\u4fee\u8865\u4e86\u51e0\u4e2a\u6709\u5173\u5efa\u7acb\u548c\u5b89\u88c5\u7684\u95ee\u9898\u3002<\/p>\n

\u6709\u4f55\u4f18\u70b9<\/p>\n

Dmalloc\u6700\u5927\u7684\u4f18\u70b9\u5c31\u662f\u9ad8\u5ea6\u53ef\u914d\u7f6e\u6027\u3002\u4f8b\u5982\u8bf4\uff0c\u4f60\u53ef\u4ee5\u914d\u7f6e\u5b83\u4ee5\u652f\u6301C++\u7a0b\u5e8f\u548c\u591a\u7ebf\u7a0b\u5e94\u7528\u3002Dmalloc\u8fd8\u63d0\u4f9b\u4e00\u4e2a\u6709\u7528\u7684\u529f\u80fd\uff1a\u8fd0\u884c\u65f6\u53ef\u914d\u7f6e\uff0c\u8fd9\u8868\u793a\u5728Dmalloc\u6267\u884c\u65f6\uff0c\u53ef\u4ee5\u8f7b\u6613\u5730\u542f\u7528\u6216\u5219\u7981\u7528\u5b83\u63d0\u4f9b\u7684\u4e00\u4e9b\u7279\u70b9\u3002<\/p>\n

\u4f60\u8fd8\u53ef\u4ee5\u914d\u5408GNUProjectDebugger(GDB)[7]\u6765\u4f7f\u7528Dmalloc\uff0c\u53ea\u987b\u8981\u5c06dmalloc.gdb\u6587\u4ef6\uff08\u5750\u843dDmalloc\u6e90\u7801\u5305\u4e2d\u7684contrib\u5b50\u76ee\u5f55\u91cc\uff09\u7684\u5185\u5bb9\u6dfb\u52a0\u5230\u4f60\u7684\u4e3b\u76ee\u5f55\u4e2d\u7684.gdbinit\u6587\u4ef6\u91cc\u5373\u53ef\u3002<\/p>\n

\u53e6\u5916\u4e00\u4e2a\u8ba9\u6211\u5bf9Dmalloc\u7231\u4e0d\u91ca\u624b\u7684\u4f18\u70b9\u662f\u5b83\u6709\u5927\u91cf\u7684\u8d44\u6599\u6587\u732e\u3002\u62b5\u8fbe\u5b98\u7f51\u7684Documentation\u680f\u76ee[8]\uff0c\u53ef\u4ee5\u83b7\u53d6\u6240\u6709\u5173\u4e8e\u600e\u4e48\u4e0b\u8f7d\u3001\u5b89\u88c5\u3001\u8fd0\u884c\u3001\u600e\u6837\u4f7f\u7528\u5e93\uff0c\u548cDmalloc\u6240\u63d0\u4f9b\u7279\u70b9\u7684\u7ec6\u8282\u63cf\u8ff0\uff0c\u53ca\u5176\u751f\u6210\u7684\u8f93\u51fa\u6587\u4ef6\u7684\u89e3\u91ca\u3002\u5176\u4e2d\u8fd8\u6709\u4e00\u4e2a\u7ae0\u8282\u4ecb\u7ecd\u4e86\u901a\u5e38\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u5f0f\u3002<\/p>\n

\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u8ddfMtrace\u4e00\u6837\uff0cDmalloc\u987b\u8981\u7a0b\u5e8f\u5458\u6539\u52a8\u5979\u4eec\u7684\u6e90\u4ee3\u7801\u3002\u4f8b\u5982\u8bf4\u4f60\u53ef\u4ee5\uff08\u4e5f\u662f\u5fc5\u987b\u7684\uff09\u6dfb\u52a0\u5934\u6587\u4ef6dmalloc.h\uff0c\u5de5\u5177\u80fd\u591f\u6c47\u62a5\u5f62\u6210\u95ee\u9898\u7684\u8c03\u7528\u7684\u6587\u4ef6\u6216\u884c\u53f7\u3002\u8fd9\u4e2a\u529f\u80fd\u5341\u5206\u6709\u7528\uff0c\u7531\u4e8e\u5b83\u8282\u7ea6\u4e86\u8c03\u8bd5\u7684\u65f6\u95f4\u3002<\/p>\n

\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u987b\u8981\u5728\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u65f6\uff0c\u628aDmalloc\u5e93\uff08\u7f16\u8bd1Dmalloc\u6e90\u7801\u5305\u65f6\u5f62\u6210\u7684\uff09\u94fe\u63a5\u8fdb\u53bb\u3002<\/p>\n

\u4f46\u662f\uff0c\u8fd8\u6709\u70b9\u66f4\u9ebb\u70e6\u7684\u4e8b\uff0c\u987b\u8981\u8bbe\u7f6e\u4e00\u4e2a\u73af\u5883\u53d8\u91cf<\/a>\uff0c\u547d\u540d\u4e3aDMALLOC_OPTION\uff0c\u4ee5\u4f9b\u5de5\u5177\u5728\u8fd0\u884c\u65f6\u914d\u7f6e\u663e\u5b58\u8c03\u8bd5\u7279\u70b9\uff0c\u4f8b\u5982\u5b9a\u4e49\u8f93\u51fa\u6587\u4ef6\u7684\u8def\u5f84\u3002\u53ef\u4ee5\u81ea\u52a8\u4e3a\u8be5\u73af\u5883\u53d8\u91cf\u5206\u914d\u4e00\u4e2a\u503c\uff0c\u4e0d\u8fc7\u521d\u5b66\u8005\u53ef\u80fd\u4f1a\u8ba4\u4e3a\u8fd9\u4e2a\u8fc7\u7a0b\u6709\u70b9\u56f0\u96be\uff0c\u7531\u4e8e\u8be5\u503c\u7684\u4e00\u90e8\u4efd\u62ff\u6765\u8868\u793a\u8981\u542f\u7528\u7684Dmalloc\u7279\u70b9\u2014\u2014\u4ee5\u5341\u516d\u8865\u7801\u503c\u7684\u7d2f\u52a0\u503c\u8868\u793a\u3002\u8fd9\u513f[9]\u6709\u8be6\u5c3d\u4ecb\u7ecd\u3002<\/p>\n

\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u65b9\u5f0f\u8bbe\u7f6e\u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\u662f\u4f7f\u7528Dmalloc\u5b9e\u7528\u6307\u4ee4[10]\uff0c\u8fd9\u662f\u4e13\u4e3a\u8fd9\u4e2a\u76ee\u7684\u8bbe\u8ba1\u7684\u65b9\u5f0f\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

Dmalloc\u771f\u6b63\u7684\u4f18\u52bf\u5728\u4e8e\u5b83\u7684\u53ef\u914d\u7f6e\u9009\u9879\u3002\u5e76\u4e14\u9ad8\u5ea6\u53ef\u79fb\u690dlinux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf<\/a>\u5d29\u4e86<\/strong>\uff0c\u4ee5\u524d\u6210\u529f\u79fb\u690d\u5230\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\u5982AIX\u3001BSD\/OS\u3001DG\/UX\u3001Free\/Net\/OpenBSD\u3001GNU\/Hurd\u3001HPUX\u3001Irix\u3001Linux\u3001MS-DOG\u3001NeXT\u3001OSF\u3001SCO\u3001Solaris\u3001SunOS\u3001Ultrix\u3001Unixware\u751a\u81f3Unicos\uff08\u8fd0\u884c\u5728CrayT3E\u4e3b\u673a\u4e0a\uff09\u3002\u5373\u4f7f\u4f7f\u7528Dmalloc\u987b\u8981\u5b66\u4e60\u8bb8\u591a\u77e5\u8bc6\uff0c\u800c\u4e14\u5b83\u6240\u63d0\u4f9b\u7684\u7279\u70b9\u503c\u5f97\u4e3a\u4e4b\u4ed8\u51fa\u3002<\/p>\n

\u5f00\u53d1\u8005\uff1aBrucePerens<\/p>\n

\u8bc4\u4f30\u7248\u672c\uff1a2.2.3<\/p>\n

\u652f\u6301\u7684Linux\u7248\u672c\uff1a\u6240\u6709\u79cd\u7c7b<\/p>\n

\u8bb8\u53ef\uff1aGPLv2<\/p>\n

ElectricFence\u662fBrucePerens\u5f00\u53d1\u7684\u4e00\u6b3e\u663e\u5b58\u8c03\u8bd5\u5de5\u5177\uff0c\u5b83\u4ee5\u5e93\u7684\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4f60\u7684\u7a0b\u5e8f\u987b\u8981\u94fe\u63a5\u5b83\u3002ElectricFence\u80fd\u6d4b\u91cf\u51fa\u5806[12]\u663e\u5b58\u6ea2\u51fa\u548c\u8bbf\u95ee\u65e9\u5df2\u91ca\u653e\u7684\u663e\u5b58\u3002<\/p>\n

ElectricFence<\/p>\n

\u987e\u540d\u601d\u4e49\uff0cElectricFence\u5728\u6bcf\u4f4d\u6240\u7533\u8bf7\u7684\u7f13\u5b58\u8fb9\u754c\u6784\u5efa\u4e86\u865a\u62df\u680f\u6746\uff0c\u8fd9\u6837\u4e00\u6765\u4efb\u4f55\u975e\u6cd5\u7684\u663e\u5b58\u8bbf\u95ee\u5c31\u4f1a\u9020\u6210\u6bb5\u9519\u8bef[13]\u3002\u8fd9\u4e2a\u8c03\u8bd5\u5de5\u5177\u540c\u65f6\u652f\u6301C\u548cC++\u7a0b\u5e8f\u3002<\/p>\n

\u66f4\u65b0\u5185\u5bb9<\/p>\n

2.2.3\u7248\u672c\u4fee\u8865\u4e86\u5de5\u5177\u7684\u5efa\u7acb\u7cfb\u7edf\uff0c\u81f4\u4f7f-fno-builtin-malloc\u9009\u9879\u80fd\u771f\u6b63\u4f20\u7ed9GNUCompilerCollection(GCC)[14]\u3002<\/p>\n

\u6709\u4f55\u4f18\u70b9<\/p>\n

\u6211\u559c\u6b22ElectricFence\u7684\u9996\u8981\u4e00\u70b9\u662f\u5b83\u4e0d\u540c\u4e8eMemwatch\u3001Dmalloc\u548cMtrace\uff0c\u4e0d\u987b\u8981\u5bf9\u4f60\u7684\u6e90\u7801\u505a\u4efb\u4f55\u7684\u6539\u52a8linux\u9a71\u52a8\u4e0b\u8f7d\uff0c\u4f60\u53ea\u987b\u8981\u5728\u7f16\u8bd1\u7684\u65f6\u4faf\u628a\u5b83\u7684\u5e93\u94fe\u63a5\u8fdb\u4f60\u7684\u7a0b\u5e8f\u5373\u53ef\u3002<\/p>\n

\u5176\u6b21\uff0cElectricFence\u7684\u5b9e\u73b0\u4fdd\u8bc1\u4e86\u5f62\u6210\u8d8a\u754c\u8bbf\u95ee\u7684\u7b2c\u4e00\u4e2a\u6307\u4ee4\u90fd\u4f1a\u9020\u6210\u6bb5\u9519\u8bef\u3002\u8fd9\u6bd4\u5728\u65c1\u8fb9\u518d\u53d1\u89c9\u95ee\u9898\u8981\u5f88\u591a\u4e86\u3002<\/p>\n

\u4e0d\u7ba1\u662f\u5426\u6709\u68c0\u67e5\u51fa\u9519\u8bef\uff0cElectricFence\u5c31\u4f1a\u5728\u8f93\u51fa\u5f62\u6210\u7248\u6743\u4fe1\u606f\u3002\u8fd9\u4e00\u70b9\u5341\u5206\u6709\u7528\uff0c\u7531\u6b64\u53ef\u4ee5\u786e\u5b9a\u4f60\u6240\u8fd0\u884c\u7684\u7a0b\u5e8f\u65e9\u5df2\u542f\u7528\u4e86ElectricFence\u3002<\/p>\n

\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u53e6\u4e00\u65b9\u9762\uff0c\u6211\u5bf9ElectricFence\u771f\u6b63\u5ff5\u5ff5\u4e0d\u5fd8\u7684\u662f\u5b83\u6d4b\u91cf\u663e\u5b58\u6cc4\u9732\u7684\u80fd\u529b\u3002\u663e\u5b58\u6cc4\u9732\u662fC\/C++\u8f6f\u4ef6\u6700\u5e38\u89c1\u4e5f\u662f\u6700\u4e0d\u5bb9\u6613\u53d1\u89c9\u7684\u95ee\u9898\u4e4b\u4e00\u3002\u4e0d\u8fc7\uff0cElectricFence\u4e0d\u80fd\u6d4b\u91cf\u51fa\u6808\u6ea2\u51fa\uff0c\u5e76\u4e14\u4e5f\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/p>\n

\u56e0\u4e3aElectricFence\u4f1a\u5728\u7528\u6237\u5206\u914d\u663e\u5b58\u533a\u7684\u524d\u540e\u5206\u914d\u4e25\u7981\u8bbf\u95ee\u7684\u865a\u62df\u663e\u5b58\u9875\uff0c\u5047\u5982\u4f60\u8fc7\u591a\u7684\u8fdb\u884c\u52a8\u6001\u663e\u5b58\u5206\u914d\uff0c\u5c06\u4f1a\u9020\u6210\u4f60\u7684\u7a0b\u5e8f\u6d88\u8017\u5927\u91cf\u7684\u989d\u5916\u663e\u5b58\u3002<\/p>\n

ElectricFence\u8fd8\u6709\u4e00\u4e2a\u5c40\u9650\u662f\u4e0d\u80fd\u660e\u6670\u5f3a\u8c03\u9519\u8bef\u4ee3\u7801\u6240\u5728\u7684\u884c\u53f7\u3002\u5b83\u6240\u80fd\u505a\u53ea\u662f\u5728\u6d4b\u91cf\u5230\u663e\u5b58\u76f8\u5173\u9519\u8bef\u65f6\u5f62\u6210\u6bb5\u9519\u8bef\u3002\u60f3\u8981\u5b9a\u4f4d\u9519\u8bef\u7684\u884c\u53f7\uff0c\u987b\u8981\u5229\u7528GDB[15]\u8fd9\u6837\u7684\u8c03\u8bd5\u5de5\u5177\u6765\u8c03\u8bd5\u542f\u7528\u4e86ElectricFence\u7684\u7a0b\u5e8f\u3002<\/p>\n

\u6700\u540e\u4e00\u70b9\uff0c\u867d\u7136ElectricFence\u80fd\u6d4b\u91cf\u51fa\u5927\u90e8\u4efd\u7684\u7f13\u51b2\u533a\u6ea2\u51fa\uff0c\u6709\u4e00\u4e2a\u4f8b\u5916\u662f\uff0c\u5047\u5982\u6240\u7533\u8bf7\u7684\u7f13\u51b2\u533a\u5927\u5c0f\u4e0d\u662f\u7cfb\u7edf\u5b57\u957f\u7684\u500d\u6570\uff0c\u8fd9\u65f6\u4faf\u6ea2\u51fa\uff08\u867d\u7136\u53ea\u6709\u51e0\u4e2a\u5b57\u8282\uff09\u5c31\u4e0d\u80fd\u88ab\u6d4b\u91cf\u4e0b\u6765\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u867d\u7136\u5c40\u9650\u6027\u8f83\u5927\uff0cElectricFence\u7684\u6613\u7528\u6027\u4e00\u76f4\u662f\u52a0\u5206\u9879\u3002\u53ea\u8981\u94fe\u63a5\u4e00\u6b21\u7a0b\u5e8f\uff0cElectricFence\u5c31\u53ef\u4ee5\u5728\u68c0\u6d4b\u51fa\u663e\u5b58\u76f8\u5173\u95ee\u9898\u7684\u65f6\u4faf\u62a5\u6848\u3002\u4e0d\u8fc7\uff0c\u5c31\u50cf\u4e0a\u9762\u6240\u8bf4\uff0cElectricFence\u987b\u8981\u914d\u5408\u50cfGDB\u8fd9\u6837\u7684\u6e90\u7801\u8c03\u8bd5\u5668\u4f7f\u7528\u3002<\/p>\n

\u8bc4\u4f30\u7248\u672c\uff1a3.10.1<\/p>\n

\u652f\u6301\u7684Linux\u53d1\u884c\u7248\uff1a\u6240\u6709\u79cd\u7c7b<\/p>\n

\u8bb8\u53ef\uff1aGPL<\/p>\n

Valgrind[18]\u662f\u4e00\u4e2a\u63d0\u4f9b\u597d\u51e0\u6b3e\u8c03\u8bd5\u548c\u5256\u6790Linux\u7a0b\u5e8f\u6027\u80fd\u7684\u5de5\u5177\u7684\u5957\u4ef6\u3002\u5176\u5b9eValgrind\u80fd\u548c\u4e0d\u540c\u8bed\u8a00\u2014\u2014Java\u3001Perl\u3001Python\u3001Assemblycode\u3001ortran\u3001Ada\u7b49\u2014\u2014\u7f16\u5199\u7684\u7a0b\u5e8f\u4e00\u8d77\u5de5\u4f5c\uff0c\u5e76\u4e14\u5b83\u4e3b\u8981\u8fd8\u662f\u9488\u5bf9\u4f7f\u7528C\/C++\u6240\u7f16\u64b0\u7684\u7a0b\u5e8f\u3002<\/p>\n

Memcheck\uff0c\u4e00\u6b3e\u663e\u5b58\u9519\u8bef\u68c0\u67e5\u5668\uff0c\u662f\u5176\u4e2d\u6700\u53d7\u6b22\u8fce\u7684\u5de5\u5177\u3002\u5b83\u624d\u80fd\u6d4b\u91cf\u51fa\u5982\u663e\u5b58\u6cc4\u9732\u3001\u65e0\u6548\u7684\u663e\u5b58\u8bbf\u95ee\u3001\u672a\u5b9a\u4e49\u53d8\u91cf\u7684\u4f7f\u7528\u4ee5\u53ca\u5806\u663e\u5b58\u5206\u914d\u548c\u91ca\u653e\u76f8\u5173\u7684\u95ee\u9898\u7b49\u4f17\u591a\u95ee\u9898\u3002<\/p>\n

\u66f4\u65b0\u5185\u5bb9<\/p>\n

\u5de5\u5177\u5957\u4ef6(3.10.1)[19]\u4e3b\u8981\u4fee\u8865\u4e863.10.0\u7248\u672c\u53d1\u89c9\u7684bug\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u201c\u4ece\u4e3b\u5e72\u5f00\u53d1\u7248\u672c\u5411\u540e\u79fb\u690d\u7684\u4e00\u4e9b\u8865\u4e01\uff0c\u4fee\u8865\u4e86\u7f3a\u4f4d\u7684AArch64ARMv8\u6307\u4ee4\u548c\u7cfb\u7edf\u8c03\u7528\u201d\u3002<\/p>\n

\u6709\u4f55\u4f18\u70b9<\/p>\n

\u540c\u5176\u5b83\u6240\u6709Valgrind\u5de5\u5177\u4e00\u6837\uff0cMemcheck\u4e5f\u662f\u547d\u4ee4<\/a>\u884c\u7a0b\u5e8f\u3002\u5b83\u7684\u64cd\u4f5c\u5341\u5206\u7b80\u5355\uff1a\u4e00\u822c\u6211\u4eec\u4f1a\u4f7f\u7528\u4f8b\u5982progarg1arg2\u683c\u5f0f\u7684\u547d\u4ee4\u6765\u8fd0\u884c\u7a0b\u5e8f\uff0c\u800cMemcheck\u53ea\u8981\u6c42\u4f60\u591a\u52a0\u51e0\u4e2a\u503c\u5373\u53ef\uff0c\u5982valgrind--leak-check=fullprogarg1arg2\u3002<\/p>\n

Memcheck<\/p>\n

\uff08\u6ce8\u610f\uff1a\u7531\u4e8eMemcheck\u662fValgrind\u7684\u9ed8\u8ba4\u5de5\u5177\uff0c\u6240\u4ee5\u5728\u547d\u4ee4\u884c\u6267\u884c\u547d\u4ee4\u65f6\u65e0\u9700\u63d0\u5230Memcheck\u3002\u5e76\u4e14\uff0c\u987b\u8981\u5728\u7f16\u8bd1\u7a0b\u5e8f\u4e4b\u521d\u5e26\u4e0a-g\u53c2\u6570\u9009\u9879\uff0c\u8fd9\u4e00\u6b65\u4f1a\u6dfb\u52a0\u8c03\u8bd5\u4fe1\u606f\uff0c\u81f4\u4f7fMemcheck\u7684\u9519\u8bef\u4fe1\u606f\u4f1a\u5305\u542b\u6b63\u786e\u7684\u884c\u53f7\u3002\uff09<\/p>\n

\u6211\u771f\u6b63\u503e\u5fc3\u4e8eMemcheck\u7684\u662f\u5b83\u63d0\u4f9b\u4e86\u597d\u591a\u547d\u4ee4\u884c\u9009\u9879\uff08\u5982\u4e0a\u6240\u8ff0\u7684--leak-check\u9009\u9879\uff09\uff0c\u8fd9\u4e48\u9664\u4e86\u80fd\u63a7\u5236\u5de5\u5177\u8fd0\u8f6c\u8fd8\u53ef\u4ee5\u63a7\u5236\u5b83\u7684\u8f93\u51fa\u3002<\/p>\n

\u4e3e\u4e2a\u4e8b\u4f8b\uff0c\u53ef\u4ee5\u5f00\u542f--track-origins\u9009\u9879\uff0c\u4ee5\u67e5\u770b\u7a0b\u5e8f\u6e90\u7801\u4e2d\u672a\u521d\u59cb\u5316\u7684\u6570\u636e\uff1b\u53ef\u4ee5\u5f00\u542f--show-mismatched-frees\u9009\u9879\u8ba9Memcheck\u5339\u914d\u663e\u5b58\u7684\u5206\u914d\u548c\u91ca\u653e\u6280\u672f\u3002\u5bf9\u4e8eC\u8bed\u8a00\u6240\u5199\u7684\u4ee3\u7801\uff0cMemcheck\u4f1a\u786e\u4fdd\u53ea\u80fd\u4f7f\u7528free\u51fd\u6570\u6765\u91ca\u653e\u663e\u5b58\uff0cmalloc\u51fd\u6570\u6765\u7533\u8bf7\u663e\u5b58\u3002\u800c\u5bf9C++\u6240\u5199\u7684\u6e90\u7801\uff0cMemcheck\u4f1a\u68c0\u6d4b\u662f\u5426\u4f7f\u7528\u4e86delete\u6216delete\u64cd\u4f5c\u7b26\u6765\u91ca\u653e\u663e\u5b58\uff0c\u4ee5\u53canew\u6216\u5219new\u6765\u7533\u8bf7\u663e\u5b58\u3002<\/p>\n

Memcheck\u6700\u597d\u7684\u7279\u6027\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0c\u662f\u5b83\u4f1a\u7ed9\u7528\u6237\u5efa\u8bae\u4f7f\u7528\u90a3\u4e2a\u547d\u4ee4\u884c\u9009\u9879\u80fd\u8ba9\u8f93\u51fa\u6108\u52a0\u6709\u610f\u4e49\u3002\u4f8b\u5982\u8bf4\uff0c\u5047\u5982\u4f60\u4e0d\u4f7f\u7528\u57fa\u672c\u7684--leak-check\u9009\u9879\uff0cMemcheck\u4f1a\u5728\u8f93\u51fa\u65f6\u7ed9\u51fa\u5efa\u8bae\uff1a\u201c\u4f7f\u7528--leak-check=full\u91cd\u65b0\u8fd0\u884c\u4ee5\u67e5\u770b\u66f4\u591a\u6cc4\u9732\u663e\u5b58\u7ec6\u8282\u201d\u3002\u5047\u5982\u7a0b\u5e8f\u6709\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\uff0cMemcheck\u4f1a\u5f62\u6210\u4fe1\u606f\uff1a\u201c\u4f7f\u7528--track-origins=yes\u4ee5\u67e5\u770b\u672a\u521d\u59cb\u5316\u53d8\u91cf\u7684\u5b9a\u4f4d\u201d\u3002<\/p>\n

Memcheck\u53e6\u5916\u4e00\u4e2a\u6709\u7528\u7684\u7279\u70b9\u662f\u5b83\u53ef\u4ee5\u521b\u5efa\u6291\u5236\u6587\u4ef6suppressionfiles[20]\uff0c\u7531\u6b64\u53ef\u4ee5\u7565\u8fc7\u7279\u5b9a\u7684\u4e0d\u80fd\u4fee\u6b63\u7684\u9519\u8bef\uff0c\u8fd9\u6837Memcheck\u8fd0\u884c\u65f6\u5c31\u4e0d\u4f1a\u6bcf\u6b21\u90fd\u62a5\u6848\u4e86\u3002\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0cMemcheck\u4f1a\u53bb\u8bfb\u53d6\u9ed8\u8ba4\u6291\u5236\u6587\u4ef6\u6765\u5ffd\u89c6\u7cfb\u7edf\u5e93\uff08\u4f8b\u5982C\u5e93\uff09\u4e2d\u7684\u62a5\u9519\uff0c\u8fd9\u79cd\u9519\u8bef\u5728\u7cfb\u7edf\u521b\u5efa\u4e4b\u524d\u5c31\u65e9\u5df2\u5b58\u5728\u4e86\u3002\u53ef\u4ee5\u9009\u62e9\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6291\u5236\u6587\u4ef6\uff0c\u6216\u662f\u7f16\u8f91\u73b0\u6709\u7684\u6587\u4ef6(\u4e00\u822c\u662f\/usr\/lib\/valgrind\/default.supp)\u3002<\/p>\n

Memcheck\u8fd8\u6709\u4e2d\u7ea7\u529f\u80fd\uff0c\u4f8b\u5982\u53ef\u4ee5\u4f7f\u7528\u8ba2\u5236\u663e\u5b58\u5206\u914d\u5668[21]\u6765\u6d4b\u91cf\u663e\u5b58\u9519\u8bef[22]\u3002\u9664\u6b64\u4e4b\u5916\uff0cMemcheck\u63d0\u4f9b\u76d1\u63a7\u547d\u4ee4[23]\uff0c\u5f53\u7528\u5230Valgrind\u5916\u7f6e\u7684gdbserver\uff0c\u4ee5\u53ca\u987e\u5ba2\u7aef\u6073\u6c42[24]\u673a\u5236\uff08\u9664\u4e86\u80fd\u628a\u7a0b\u5e8f\u7684\u884c\u4e3a\u544a\u77e5Memcheck\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u884c\u67e5\u8be2\uff09\u65f6\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n

\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u6beb\u65e0\u7591\u60d1\uff0cMemcheck\u53ef\u4ee5\u8282\u7ea6\u597d\u591a\u8c03\u8bd5\u65f6\u95f4\u4ee5\u53ca\u7701\u53bb\u597d\u591a\u9ebb\u70e6\u3002\u5e76\u4e14\u5b83\u4f7f\u7528\u4e86\u597d\u591a\u663e\u5b58\uff0c\u9020\u6210\u7a0b\u5e8f\u6267\u884c\u53d8\u6162\uff08\u7531\u6587\u6863\u53ef\u77e5[25]\uff0c\u5927\u7ea6\u4f1a\u8017\u8d3920\u81f330\u500d\u65f6\u95f4\uff09\u3002<\/p>\n

\u9664\u6b64\u4e4b\u5916\uff0cMemcheck\u8fd8\u6709\u5176\u5b83\u5c40\u9650\u3002\u4f9d\u636e\u7528\u6237\u8bc4\u8bba\uff0cMemcheck\u5f88\u663e\u8457\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168[26]\u7684\uff1b\u5b83\u4e0d\u80fd\u6d4b\u91cf\u51fa\u9759\u6001\u7f13\u51b2\u533a\u6ea2\u51fa[27]\uff1b\u8fd8\u6709\u5c31\u662f\uff0c\u4e00\u4e9bLinux\u7a0b\u5e8f\u5982GNUEmacs[28]\u76ee\u524d\u8fd8\u4e0d\u80fd\u914d\u5408Memcheck\u5de5\u4f5c\u3002<\/p>\n

\u5047\u5982\u6709\u5174\u8da3\uff0c\u53ef\u4ee5\u5728\u8fd9\u513f[29]\u67e5\u770bValgrind\u5c40\u9650\u6027\u7684\u8be6\u5c3d\u8bf4\u660e\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u65e0\u8bba\u662f\u5bf9\u4e8e\u521d\u5b66\u8005\u8fd8\u662f\u8fd9\u4e9b\u987b\u8981\u4e2d\u7ea7\u7279\u70b9\u7684\u4eba\u6765\u8bf4\uff0cMemcheck\u90fd\u662f\u4e00\u6b3e\u65b9\u4fbf\u7684\u663e\u5b58\u8c03\u8bd5\u5de5\u5177\u3002\u5047\u5982\u4f60\u4ec5\u987b\u8981\u57fa\u672c\u8c03\u8bd5\u548c\u9519\u8bef\u68c0\u6d4b\uff0cMemcheck\u4f1a\u7279\u522b\u5bb9\u6613\u4e0a\u624b\u3002\u800c\u5f53\u4f60\u60f3\u8981\u4f7f\u7528\u50cf\u6291\u5236\u6587\u4ef6\u6216\u5219\u76d1\u63a7\u6307\u4ee4\u8fd9\u6837\u7684\u7279\u70b9\uff0c\u5c31\u987b\u8981\u82b1\u4e00\u4e9b\u5de5\u592b\u5b66\u4e60\u4e86\u3002<\/p>\n

linux\u7cfb\u7edfweb\u73af\u5883\u914d\u7f6e_linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86_linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86<\/p>\n

\u5c3d\u7ba1\u5217\u4e3e\u4e86\u5927\u91cf\u7684\u5c40\u9650\u6027\uff0c\u800c\u4e14Valgrind\uff08\u5305\u62ecMemcheck\uff09\u5728\u5b83\u7684\u7f51\u7ad9\u4e0a\u5ba3\u79f0\u5168\u7403\u6709\u6210\u5343\u4e0a\u4e07\u7a0b\u5e8f\u5458[30]\u4f7f\u7528\u4e86\u6b64\u5de5\u5177\u3002\u5f00\u53d1\u56e2\u961f\u79f0\u6536\u5230\u6765\u81ea\u8d85\u8fc730\u4e2a\u56fd\u5bb6\u7684\u7528\u6237\u53cd\u9988\uff0c\u800c\u8fd9\u79cd\u7528\u6237\u7684\u5de5\u7a0b\u4ee3\u7801\u6709\u7684\u9ad8\u8fbe\u4e24\u5343\u4e94\u767e\u4e07\u884c\u3002<\/p>\n

\u5f00\u53d1\u8005\uff1aJohanLindh<\/p>\n

\u8bc4\u4f30\u7248\u672c\uff1a2.71<\/p>\n

\u652f\u6301\u7684Linux\u53d1\u884c\u7248\uff1a\u6240\u6709\u79cd\u7c7b<\/p>\n

\u8bb8\u53ef\uff1aGNUGPL<\/p>\n

Memwatch\u662f\u7531JohanLindh\u5f00\u53d1\u7684\u663e\u5b58\u8c03\u8bd5\u5de5\u5177\uff0c\u5373\u4f7f\u5b83\u9970\u6f14\u7684\u4e3b\u8981\u89d2\u8272\u662f\u663e\u5b58\u6cc4\u9732\u68c0\u67e5\u5668\uff0c\u800c\u4e14\uff08\u6309\u7167\u7f51\u9875\u4ecb\u7ecd\uff09\u5b83\u4e5f\u5177\u6709\u6d4b\u91cf\u5176\u5b83\u5982\u663e\u5b58\u91cd\u590d\u91ca\u653e\u548c\u9519\u8bef\u91ca\u653e[32]\u3001\u7f13\u51b2\u533a\u6ea2\u51fa\u548c\u4e0b\u6ea2\u3001\u91ce\u8868\u9488[33]\u5199\u5165\u7b49\u7b49\u663e\u5b58\u76f8\u5173\u95ee\u9898\u7684\u80fd\u529b\u3002<\/p>\n

Memwatch\u652f\u6301\u7528C\u8bed\u8a00\u6240\u7f16\u64b0\u7684\u7a0b\u5e8f\u3002\u4e5f\u53ef\u4ee5\u5728C++\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\uff0c\u800c\u4e14\u8fd9\u4e9b\u505a\u6cd5\u5e76\u4e0d\u5021\u5bfc\uff08\u7531Memwatch\u6e90\u7801\u5305\u968f\u9644\u7684Q&A\u6587\u4ef6\u4e2d\u53ef\u77e5\uff09\u3002<\/p>\n

\u66f4\u65b0\u5185\u5bb9<\/p>\n

\u8fd9\u4e2a\u7248\u672c\u6dfb\u52a0\u4e86ULONG_LONG_MAX\u4ee5\u5206\u8fa832\u4f4d\u548c64\u4f4d\u7a0b\u5e8f\u3002<\/p>\n

\u6709\u4f55\u4f18\u70b9<\/p>\n

\u8ddfDmalloc\u4e00\u6837\uff0cMemwatch\u4e5f\u6709\u4f18\u79c0\u7684\u6587\u6863\u8d44\u6599\u3002\u53c2\u8003USING\u6587\u4ef6\uff0c\u53ef\u4ee5\u5b66\u4e60\u600e\u4e48\u4f7f\u7528Memwatch\uff0c\u53ef\u4ee5\u4e86\u89e3Memwatch\u662f\u600e\u6837\u521d\u59cb\u5316\u3001\u5982\u4f55\u6e05\u9664\u4ee5\u53ca\u600e\u6837\u8fdb\u884cI\/O\u64cd\u4f5c\uff0c\u7b49\u7b49\u3002\u8fd8\u6709\u4e00\u4e2aFAQ\u6587\u4ef6\uff0c\u501f\u4ee5\u5e2e\u52a9\u7528\u6237\u89e3\u51b3\u4f7f\u7528\u8fc7\u7a0b\u78b0\u5230\u7684\u901a\u5e38\u95ee\u9898\u3002\u6700\u540e\u8fd8\u6709\u4e00\u4e2atest.c\u6587\u4ef6\u63d0\u4f9b\u5de5\u4f5c\u6848\u4f8b\u53c2\u8003\u3002<\/p>\n

linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86_linux\u7cfb\u7edfweb\u73af\u5883\u914d\u7f6e_linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86<\/p>\n

Memwatch<\/p>\n

\u4e0d\u540c\u4e8eMtrace\uff0cMemwatch\u5f62\u6210\u7684\u65e5\u5fd7\u6587\u4ef6\uff08\u4e00\u822c\u662fmemwatch.log\uff09\u662f\u4eba\u7c7b\u53ef\u9605\u8bfb\u7684\u683c\u5f0f\u3002\u5e76\u4e14\uff0cMemwatch\u6bcf\u6b21\u8fd0\u884c\u65f6\u603b\u4f1a\u628a\u663e\u5b58\u8c03\u8bd5\u7ed3\u679c\u62fc\u63a5\u5230\u8f93\u51fa\u8be5\u6587\u4ef6\u7684\u672b\u5c3e\u3002\u8fd9\u4e48\u4fbf\u53ef\u5728\u987b\u8981\u4e4b\u65f6\u8f7b\u677e\u67e5\u770b\u4e4b\u524d\u7684\u8f93\u51fa\u4fe1\u606f\u3002<\/p>\n

\u540c\u6837\u503c\u5f97\u4e00\u63d0\u7684\u662f\u5f53\u4f60\u6267\u884c\u4e86\u542f\u7528Memwatch\u7684\u7a0b\u5e8f\uff0cMemwatch\u4f1a\u5728\u6807\u51c6\u8f93\u51fa[34]\u4e2d\u5f62\u6210\u4e00\u4e2a\u5355\u884c\u8f93\u51fa\uff0c\u544a\u77e5\u53d1\u89c9\u4e86\u9519\u8bef\uff0c\u4e4b\u540e\u4f60\u53ef\u4ee5\u5728\u65e5\u5fd7\u6587\u4ef6\u4e2d\u67e5\u770b\u8f93\u51fa\u7ec6\u8282\u3002\u5047\u5982\u6ca1\u6709\u5f62\u6210\u9519\u8bef\u4fe1\u606f\uff0c\u5c31\u53ef\u4ee5\u786e\u4fdd\u65e5\u5fd7\u6587\u4ef6\u4e0d\u4f1a\u5199\u5165\u4efb\u4f55\u9519\u8bef\uff0c\u591a\u6b21\u8fd0\u884c\u7684\u8bdd\u786e\u5b9e\u80fd\u8282\u7ea6\u65f6\u95f4\u3002<\/p>\n

\u53e6\u4e00\u4e2a\u6211\u559c\u6b22\u7684\u4f18\u70b9\u662fMemwatch\u8fd8\u63d0\u4f9b\u4e86\u5728\u6e90\u7801\u4e2d\u83b7\u53d6\u5176\u8f93\u51fa\u4fe1\u606f\u7684\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u83b7\u53d6\u4fe1\u606f\uff0c\u4e4b\u540e\u4efb\u7531\u4f60\u8fdb\u884c\u5904\u7406\uff08\u53c2\u8003Memwatch\u6e90\u7801\u4e2d\u7684mwSetOutFunc()\u51fd\u6570\u83b7\u53d6\u66f4\u591a\u6709\u5173\u7684\u4fe1\u606f\uff09\u3002<\/p>\n

\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u8ddfMtrace\u548cDmalloc\u4e00\u6837\uff0cMemwatch\u4e5f\u987b\u8981\u4f60\u5f80\u4f60\u7684\u6e90\u6587\u4ef6\u91cc\u964d\u4f4e\u4ee3\u7801\uff1a\u4f60\u987b\u8981\u628amemwatch.h\u8fd9\u4e2a\u5934\u6587\u4ef6\u5305\u542b\u8fdb\u4f60\u7684\u4ee3\u7801\u3002\u5e76\u4e14\uff0c\u7f16\u8bd1\u7a0b\u5e8f\u7684\u65f6\u4faf\uff0c\u4f60\u987b\u8981\u8fde\u540cmemwatch.c\u4e00\u5757\u7f16\u8bd1\uff1b\u6216\u5219\u4f60\u53ef\u4ee5\u628a\u65e9\u5df2\u7f16\u8bd1\u597d\u7684\u76ee\u6807\u6a21\u5757\u5305\u542b\u4e0a\u53bb\uff0c\u4e4b\u540e\u5728\u547d\u4ee4\u884c\u5b9a\u4e49MEMWATCH\u548cMW_STDIO\u53d8\u91cf\u3002\u4e0d\u7528\u8bf4\uff0c\u60f3\u8981\u5728\u8f93\u51fa\u4e2d\u5b9a\u4f4d\u884c\u53f7\uff0c-g\u7f16\u8bd1\u5668\u9009\u9879\u4e5f\u5c11\u4e0d\u4e86\u3002<\/p>\n

\u636e\u6089\uff0cMemwatch\u7f3a\u4e4f\u4e00\u4e9b\u7279\u70b9\u3002\u4f8b\u5982Memwatch\u4e0d\u80fd\u6d4b\u91cf\u51fa\u5bf9\u4e00\u5757\u65e9\u5df2\u88ab\u91ca\u653e\u7684\u663e\u5b58\u8fdb\u884c\u5199\u5165\u64cd\u4f5c\uff0c\u6216\u662f\u5728\u5206\u914d\u7684\u663e\u5b58\u5757\u4e4b\u5916\u7684\u8fdb\u884c\u8bfb\u53d6\u64cd\u4f5c\u3002\u5e76\u4e14\uff0cMemwatch\u4e5f\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u8fd8\u6709\u4e00\u70b9\uff0c\u6b63\u5982\u6211\u5728\u5f00\u59cb\u65f6\u5f3a\u8c03\uff0c\u5728C++\u7a0b\u5e8f\u4e0a\u8fd0\u884cMemwatch\u7684\u7ed3\u679c\u662f\u4e0d\u80fd\u9884\u60f3\u7684\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

Memcheck\u53ef\u4ee5\u6d4b\u91cf\u597d\u591a\u663e\u5b58\u76f8\u5173\u7684\u95ee\u9898\uff0c\u5728\u5904\u7406C\u7a0b\u5e8f\u65f6\u662f\u5341\u5206\u65b9\u4fbf\u7684\u8c03\u8bd5\u5de5\u5177\u3002\u7531\u4e8e\u6e90\u7801\u7cbe\u5de7\uff0c\u6240\u4ee5\u53ef\u4ee5\u4ece\u4e2d\u4e86\u89e3Memcheck\u600e\u6837\u8fd0\u8f6c\uff0c\u6709\u987b\u8981\u7684\u8bdd\u53ef\u4ee5\u8c03\u8bd5\u5b83\uff0c\u751a\u81f3\u53ef\u4ee5\u6309\u7167\u81ea\u8eab\u9700\u6c42\u6269\u5145\u5347\u7ea7\u5b83\u7684\u529f\u80fd\u3002<\/p>\n

\u5f00\u53d1\u8005:RolandMcGrath\u548cUlrichDrepper<\/p>\n

\u8bc4\u4f30\u7248\u672c:2.21<\/p>\n

Mtrace\u662fGNUC\u5e93[36]\u4e2d\u7684\u4e00\u6b3e\u663e\u5b58\u8c03\u8bd5\u5de5\u5177\uff0c\u540c\u65f6\u652f\u6301Linux\u4e0a\u7684C\u548cC++\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u6d4b\u91cf\u7531\u51fd\u6570malloc\u548cfree\u4e0d\u5339\u914d\u7684\u8c03\u7528\u6240\u9020\u6210\u7684\u663e\u5b58\u6cc4\u9732\u95ee\u9898\u3002<\/p>\n

linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86_linux\u7cfb\u7edfweb\u73af\u5883\u914d\u7f6e_linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86<\/p>\n

Mtrace<\/p>\n

Mtrace\u5b9e\u9645\u4e0a\u662f\u5b9e\u73b0\u4e86\u4e00\u4e2a\u540d\u4e3amtrace\u7684\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u8ddf\u8e2a\u7a0b\u5e8f\u4e2d\u6240\u6709malloc\/free\u8c03\u7528\uff0c\u5e76\u5728\u7528\u6237\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\u8bb0\u5f55\u76f8\u5173\u4fe1\u606f\u3002\u6587\u4ef6\u4ee5\u4e00\u79cd\u673a\u5668\u53ef\u8bfb\u7684\u683c\u5f0f\u8bb0\u5f55\u6570\u636e\uff0c\u6240\u4ee5\u6709\u4e00\u4e2aPerl\u811a\u672c\u2014\u2014\u540c\u6837\u547d\u540d\u4e3amtrace\u2014\u2014\u7528\u6765\u628a\u6587\u4ef6\u8f6c\u6362\u5e76\u4e3a\u4eba\u7c7b\u53ef\u8bfb\u683c\u5f0f\u3002<\/p>\n

\u66f4\u65b0\u5185\u5bb9<\/p>\n

Mtrace\u6e90\u7801[37]\u548cPerl\u6587\u4ef6[38]\u540cGNUC\u5e93(2.21\u7248\u672c)\u4e00\u8d77\u91ca\u51fa\uff0c\u4e0d\u4ec5\u66f4\u65b0\u7248\u6743\u65e5\u671f\uff0c\u5176\u5b83\u522b\u65e0\u6539\u52a8\u3002<\/p>\n

\u6709\u4f55\u4f18\u70b9<\/p>\n

Mtrace\u6700\u597d\u7684\u5730\u65b9\u662f\u5b83\u5341\u5206\u7b80\u5355\u6613\u5b66\u3002\u4f60\u53ea\u987b\u8981\u4e86\u89e3\u5728\u4f60\u7684\u6e90\u7801\u4e2d\u5982\u4f55\u4ee5\u53ca\u4f55\u5904\u6dfb\u52a0mtrace\u53ca\u5bf9\u5e94\u7684muntrace\u51fd\u6570\uff0c\u8fd8\u6709\u600e\u6837\u4f7f\u7528Mtrace\u7684Perl\u811a\u672c\u3002\u524d\u8005\u7279\u522b\u7b80\u5355\uff0c\u53ea\u987b\u8981\u8fd0\u884c\u6307\u4ee4mtrace<\/p>\n

\uff08\u4e8b\u4f8b\u89c1\u5f00\u5934\u622a\u56fe\u6700\u540e\u4e00\u6761\u6307\u4ee4\uff09\u3002<\/p>\n

Mtrace\u53e6\u5916\u4e00\u4e2a\u4f18\u70b9\u662f\u5b83\u7684\u53ef\u4f38\u7f29\u6027\uff0c\u8fd9\u5f70\u663e\u5728\u9664\u4e86\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u8c03\u8bd5\u5b8c\u6574\u7684\u7a0b\u5e8f\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u68c0\u67e5\u7a0b\u5e8f\u4e2d\u72ec\u7acb\u6a21\u5757\u7684\u663e\u5b58\u6cc4\u9732\u3002\u53ea\u9700\u5728\u6bcf\u4f4d\u6a21\u5757\u91cc\u8c03\u7528mtrace\u548cmuntrace\u5373\u53ef\u3002<\/p>\n

\u6700\u540e\u4e00\u70b9\uff0c\u7531\u4e8eMtrace\u4f1a\u5728mtrace\u2014\u2014\u5728\u6e90\u7801\u4e2d\u6dfb\u52a0\u7684\u51fd\u6570\u2014\u2014\u6267\u884c\u65f6\u88ab\u89e6\u53d1\uff0c\u56e0\u800c\u53ef\u4ee5\u5f88\u7075\u6d3b\u5730\u4f7f\u7528\u8baf\u53f7[39]\u52a8\u6001\u5730\uff08\u5728\u7a0b\u5e8f\u6267\u884c\u65f6\uff09\u4f7f\u80fdMtrace\u3002<\/p>\n

\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u7531\u4e8emtrace\u548cmauntrace\u51fd\u6570\u2014\u2014\u58f0\u660e\u5728mcheck.h\u6587\u4ef6\u4e2d\uff0c\u6240\u4ee5\u5fc5\u987b\u5728\u6e90\u7801\u4e2d\u5305\u542b\u6b64\u5934\u6587\u4ef6\u2014\u2014\u7684\u8c03\u7528\u662fMtrace\u5de5\u4f5c\u7684\u57fa\u7840\uff08mauntrace()\u51fd\u6570\u5e76\u975e\u603b\u662f\u5fc5\u8981[40]\uff09\uff0c\u56e0\u800cMtrace\u8981\u6c42\u7a0b\u5e8f\u5458\u8d77\u7801\u6539\u52a8\u6e90\u7801\u4e00\u6b21\u3002<\/p>\n

\u987b\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u7f16\u8bd1\u7a0b\u5e8f\u7684\u65f6\u4faf\u5e26\u4e0a-g\u9009\u9879\uff08GCC[41]\u548cG++[42]\u7f16\u8bd1\u5668\u5747\u6709\u63d0\u4f9b\uff09\uff0c\u80fd\u591f\u4f7f\u8c03\u8bd5\u5de5\u5177\u5728\u8f93\u51fa\u7ed3\u679c\u65f6\u5c55\u793a\u6b63\u786e\u7684\u884c\u53f7\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u6709\u4e9b\u7a0b\u5e8f\uff08\u53d6\u51b3\u4e8e\u6e90\u7801\u5bb9\u79ef\u6709\u591a\u5927\uff09\u53ef\u80fd\u4f1a\u82b1\u5f88\u957f\u65f6\u95f4\u8fdb\u884c\u7f16\u8bd1\u3002\u6700\u540e\uff0c\u5e26-g\u9009\u9879\u7f16\u8bd1\u4f1a\u964d\u4f4e\u4e86\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5927\u5c0f\uff08\u7531\u4e8e\u63d0\u4f9b\u4e86\u989d\u5916\u7684\u8c03\u8bd5\u4fe1\u606f\uff09linux\u5b66\u4e60\u8bba\u575b\uff0c\u56e0\u800c\u8bb0\u5f97\u7a0b\u5e8f\u987b\u8981\u5728\u6d4b\u8bd5\u7ed3\u675f\u540e\uff0c\u4e0d\u5e26-g\u9009\u9879\u91cd\u65b0\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n

\u4f7f\u7528Mtrace\uff0c\u4f60\u987b\u8981\u628a\u63e1Linux\u73af\u5883\u53d8\u91cf\u7684\u57fa\u672c\u77e5\u8bc6\uff0c\u7531\u4e8e\u5728\u7a0b\u5e8f\u6267\u884c\u4e4b\u524d\uff0c\u987b\u8981\u628a\u7528\u6237\u628a\u73af\u5883\u53d8\u91cfMALLOC_TRACE\u7684\u503c\u8bbe\u4e3a\u6307\u5b9a\u7684\u6587\u4ef6\uff08mtrace()\u51fd\u6570\u5c06\u4f1a\u8bb0\u5f55\u5168\u90e8\u4fe1\u606f\u5230\u5176\u4e2d\uff09\u8def\u5f84\u3002<\/p>\n

Mtrace\u5728\u68c0\u67e5\u663e\u5b58\u6cc4\u9732\u548c\u4f01\u56fe\u91ca\u653e\u672a\u7ecf\u8fc7\u5206\u914d\u7684\u663e\u5b58\u65b9\u9762\u5b58\u5728\u5c40\u9650\u3002\u5b83\u4e0d\u80fd\u6d4b\u91cf\u5176\u5b83\u663e\u5b58\u76f8\u5173\u95ee\u9898\u5982\u975e\u6cd5\u663e\u5b58\u8bbf\u95ee\u3001\u4f7f\u7528\u672a\u521d\u59cb\u5316\u663e\u5b58\u3002\u5e76\u4e14linux\u4fee\u6539\u73af\u5883\u53d8\u91cf \u7cfb\u7edf\u5d29\u4e86<\/strong>\uff0c\u6709\u4eba\u57cb\u6028[43]Mtrace\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168[44]\u7684\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u4e0d\u8a00\u81ea\u660e\uff0c\u6211\u5728\u6b64\u8ba8\u8bba\u7684\u6bcf\u6b3e\u663e\u5b58\u8c03\u8bd5\u5668\u90fd\u6709\u5176\u4f18\u70b9\u548c\u5c40\u9650\u3002\u6240\u4ee5\uff0c\u54ea\u4e00\u6b3e\u9002\u5b9c\u4f60\u53d6\u51b3\u4e8e\u4f60\u6240\u987b\u8981\u7684\u7279\u70b9\uff0c\u5c3d\u7ba1\u6709\u65f6\u4faf\u5bb9\u6613\u5b89\u88c5\u548c\u4f7f\u7528\u4e5f\u662f\u4e00\u4e2a\u51b3\u5b9a\u8bf1\u56e0\u3002<\/p>\n

\u8981\u60f3\u6355\u83b7\u8f6f\u4ef6\u7a0b\u5e8f\u4e2d\u7684\u663e\u5b58\u6cc4\u9732\uff0cMtrace\u6700\u9002\u5b9c\u4e0d\u8fc7\u4e86\u3002\u5b83\u8fd8\u53ef\u4ee5\u8282\u7ea6\u65f6\u95f4\u3002\u56e0\u4e3aLinux\u7cfb\u7edf\u65e9\u5df2\u9884\u88c5\u4e86\u6b64\u5de5\u5177\uff0c\u5bf9\u4e8e\u4e0d\u80fd\u8054\u7f51\u6216\u5219\u4e0d\u53ef\u4ee5\u4e0b\u8f7d\u7b2c\u4e09\u65b9\u8c03\u8bd5\u8c03\u8bd5\u5de5\u5177\u7684\u60c5\u51b5\uff0cMtrace\u4e5f\u662f\u6781\u6709\u88e8\u76ca\u7684\u3002<\/p>\n

\u53e6\u4e00\u65b9\u9762\uff0c\u76f8\u6bd4Mtrace\uff0cDmalloc\u9664\u4e86\u80fd\u68c0\u67e5\u66f4\u591a\u9519\u8bef\u7c7b\u578b\uff0c\u8fd8\u63d0\u4f9b\u66f4\u591a\u7279\u70b9\uff0c\u4f8b\u5982\u8fd0\u884c\u65f6\u53ef\u914d\u7f6e\u3001GDB\u96c6\u6210\u3002\u5e76\u4e14\uff0cDmalloc\u4e0d\u50cf\u8fd9\u513f\u6240\u8bf4\u7684\u5176\u5b83\u5de5\u5177\uff0c\u5b83\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u66f4\u4e0d\u7528\u8bf4\u5b83\u7684\u8be6\u5c3d\u8d44\u6599\u4e86\uff0c\u8fd9\u8ba9Dmalloc\u6210\u4e3a\u521d\u5b66\u8005\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n

\u5c3d\u7ba1Memwatch\u7684\u8d44\u6599\u6bd4Dmalloc\u7684\u6108\u53d1\u4e30\u5bcc\uff0c\u5e76\u4e14\u80fd\u591f\u6d4b\u91cf\u66f4\u591a\u7684\u9519\u8bef\u79cd\u7c7b\uff0c\u5e76\u4e14\u4f60\u53ea\u80fd\u5728C\u8bed\u8a00\u5199\u5c31\u7684\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5b83\u3002\u4e00\u4e2a\u8ba9Memwatch\u8131\u9896\u800c\u51fa\u7684\u7279\u70b9\u662f\u5b83\u5bb9\u8bb8\u5728\u4f60\u7684\u7a0b\u5e8f\u6e90\u7801\u4e2d\u5904\u7406\u5b83\u7684\u8f93\u51fa\uff0c\u8fd9\u5bf9\u4e8e\u60f3\u8981\u8ba2\u5236\u8f93\u51fa\u683c\u5f0f\u6765\u8bf4\u662f\u5341\u5206\u6709\u7528\u7684\u3002<\/p>\n

\u5047\u5982\u6539\u52a8\u7a0b\u5e8f\u6e90\u7801\u975e\u4f60\u6240\u613f\uff0c\u8fd9\u4e48\u4f7f\u7528ElectricFence\u5427\u3002\u4e0d\u8fc7\uff0c\u8bf7\u8bb0\u4f4f\uff0cElectricFence\u53ea\u80fd\u6d4b\u91cf\u4e24\u79cd\u9519\u8bef\u7c7b\u578b\uff0c\u800c\u6b64\u4e24\u8005\u5747\u975e\u663e\u5b58\u6cc4\u9732\u3002\u8fd8\u6709\u5c31\u662f\uff0c\u987b\u8981\u57fa\u672c\u4e86\u89e3GDB\u4ee5\u6700\u5927\u5316\u53d1\u6325\u8fd9\u6b3e\u663e\u5b58\u8c03\u8bd5\u5de5\u5177\u7684\u4f5c\u7528\u3002<\/p>\n

Memcheck\u53ef\u80fd\u662f\u5176\u4e2d\u7efc\u5408\u6027\u6700\u597d\u7684\u4e86\u3002\u76f8\u6bd4\u8fd9\u513f\u63d0\u5230\u7684\u5176\u5b83\u5de5\u5177\uff0c\u5b83\u80fd\u68c0\u67e5\u66f4\u591a\u7684\u9519\u8bef\u7c7b\u578b\uff0c\u63d0\u4f9b\u66f4\u591a\u7684\u7279\u70b9\uff0c\u4f46\u662f\u4e0d\u987b\u8981\u4f60\u7684\u6e90\u7801\u505a\u4efb\u4f55\u6539\u52a8\u3002\u4f46\u8bf7\u6ce8\u610f\uff0c\u57fa\u672c\u529f\u80fd\u5e76\u4e0d\u96be\u4e0a\u624b\uff0c\u800c\u4e14\u60f3\u8981\u4f7f\u7528\u5b83\u7684\u4e2d\u7ea7\u7279\u70b9\uff0c\u5c31\u5fc5\u987b\u5b66\u4e60\u76f8\u5173\u7684\u4e13\u4e1a\u77e5\u8bc6\u4e86\u3002<\/p>\n

\u4f5c\u8005\uff1aHimanshuArora[45]\u8bd1\u8005\uff1asoooogreen[46]\u6821\u5bf9\uff1aPurlingNayuki[47],ezio[48]<\/p>\n

\u672c\u6587\u7531LCTT[49]\u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd[50]\u8363\u8a89\u63a8\u51fa<\/p>\n

[1]:<\/p>\n

[2]:<\/p>\n

[3]:<\/p>\n

[4]:<\/p>\n

[5]:#Fence-Post%20Overruns<\/p>\n

[11]:+source\/electric-fence\/2.2.3<\/p>\n

[12]:#Dynamic_memory_allocation<\/p>\n

[13]:<\/p>\n

[14]:<\/p>\n

[18]:<\/p>\n

[27]:%28v=cs.20%29.aspx<\/p>\n

[34]:#Standard_output_.28stdout.29<\/p>\n

[36]:<\/p>\n

[37]:;a=history;f=malloc\/mtrace.c;h=df10128b872b4adc4086cf74e5d965c1c11d35d2;hb=HEAD<\/p>\n

[38]:;a=history;f=malloc\/mtrace.pl;h=0737890510e9837f26ebee2ba36c9058affb0bf1;hb=HEAD<\/p>\n

[43]:<\/p>\n

[44]:<\/p>\n

[46]:<\/p>\n

[47]:<\/p>\n

[48]:<\/p>\n

[49]:<\/p>\n

[50]:<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8fd9\u7c7b\u5141\u8bb8\u624b\u52a8\u7ba1\u7406\u5185\u5b58[2]\u7684\u8bed\u8a00\u7f16\u5199\u7684\u8f6f\u4ef6\u91cc\u3002\u7136\u800c\uff0c\u8fd8\u6709\u70b9\u66f4\u9ebb\u70e6\u7684\u4e8b\uff0c\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u73af\u5883\u53d8\u91cf\uff0c\u547d\u540d\u4e3aDMALLOC_OPTION\uff0c\u4ee5\u4f9b\u5de5\u5177\u5728\u8fd0\u884c\u65f6\u914d\u7f6e\u5185\u5b58\u8c03\u8bd5\u7279\u6027\uff0c\u6bd4\u5982\u5b9a\u4e49\u8f93\u51fa\u6587\u4ef6\u7684\u8def\u5f84\u3002\u5f00\u53d1\u7684\u4e00\u6b3e\u5185\u5b58\u8c03\u8bd5\u5de5\u5177\uff0c\u5b83\u4ee5\u5e93\u7684\u5f62\u5f0f\u5b9e\u73b0\uff0c\u4f60\u7684\u7a0b\u5e8f\u9700\u8981\u94fe\u63a5\u5b83\u3002\u8fd8\u6709\u9ad8\u7ea7\u529f\u80fd\uff0c\u6bd4\u5982\u53ef\u4ee5\u4f7f\u7528\u5b9a\u5236\u5185\u5b58\u5206\u914d\u5668[21]\u6765\u68c0\u6d4b\u5185\u5b58\u9519\u8bef[22]\u3002\u4e0d\u8a00\u81ea\u660e\uff0c\u6211\u5728\u6b64\u8ba8\u8bba\u7684\u6bcf\u6b3e\u5185\u5b58\u8c03\u8bd5\u5668\u90fd\u6709\u5176\u4f18\u70b9\u548c\u5c40\u9650\u3002<\/p>\n","protected":false},"author":1,"featured_media":273983,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-273982","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/273982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=273982"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/273982\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/273983"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=273982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=273982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=273982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}