从内存泄漏日志中,我有以下信息:
TestApp.exe! + 2238路
让我们说这意味着偏移为“2238c”(十六进制值)的方法正在泄漏。
如何在源代码中找到相应的方法?我有链接器映射(testapp.map),但不确定如何使用它。
这是在VS2008中编译的C++应用程序。
最佳答案
您的 map 文件将包含许多此类条目:
0001:00000070 0logic_error @ std @@ QAE @ ABV01 @@ Z 00401070 f i scratch.obj
0001:000000e0 _main 004010e0 f scratch.obj
0001:00000310?1?$ list @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@@ std @@@ std @@ QAE @ XZ 00401310 fi scratch.obj
0001:00000330 1?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ QAE @ XZ 00401330 fi scratch.obj
0001:00000360?_Buynode @?$ list @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ std @@@ std @@ IAEPAU_Node @?$ _ List_nod @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @ @V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U? @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ std @@@ 2 @ XZ 00401360 fi爬取。对象
0001:00000380?clear @?$ list @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@@ std @@@ std @@ QAEXXZ 00401380 fi scratch.obj
0001:000003f0?_Buynode @?$ list @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ std @@@ std @@ IAEPAU_Node @?$ _ List_nod @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @ @V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U? @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ std @@@ 2 @ PAU342 @ 0ABV?$ @ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H _NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@@ Z 004013f0 i scratch.obj
0001:00000480?_Incsize @?$ list @ V?$ variant @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@ V?$ allocator @ V?$ variant @ V?$ basic_string @DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ H_NUvoid_ @ 0detail @ boost @@ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @ U3045 @@ boost @@@ std @@@ std @@ IAEXI @ Z 00401480 fi scratch.obj
这准确地显示了您的代码在内存中的布局方式。例如main()在段1中的E0处开始并在30F处结束。
您只需要查看地址列表,即可查看给您地址的住所。要注意的一件事是通常有多个段,但是您通常可以推断出哪个段具有您感兴趣的代码。