gpt4 book ai didi

shared-libraries - 如何使用 Valgrind 跟踪动态加载的库?

转载 作者:行者123 更新时间:2023-12-04 03:21:14 26 4
gpt4 key购买 nike

我有一个使用 dlopendlclose 加载/卸载库的进程。该库有一些内存泄漏,我想用 Valgrind 进行跟踪。我尝试了以下方法:

LD_PRELOAD=libmylibrary.so valgrind --leak-check=full myprogram

这是行不通的。我得到一个 undefined symbol 错误,因为库依赖于主程序中的一些符号。有没有其他方法可以使库在程序结束时保持加载状态?

最佳答案

这是一个老问题,但我相信如果他/她偶然发现了这个问题,这对将来的人会有帮助。

你可以传递--keep-debuginfo=yes参数给valgrind:

--keep-debuginfo=<yes|no> [default: no]

When enabled, keep ("archive") symbols and all other debuginfo for unloaded code. Thisallows saved stack traces to include file/line info for code that has been dlclose'd (orsimilar). Be careful with this, since it can lead to unbounded memory use for programs whichrepeatedly load and unload shared objects.

Some tools and some functionalities have only limited support for archived debug info.Memcheck fully supports it. Generally, tools that report errors can use archived debug info toshow the error stack traces. The known limitations are: Helgrind's past access stack trace of arace condition is does not use archived debug info. Massif (and more generally the xtree Massifoutput format) does not make use of archived debug info. Only Memcheck has been (somewhat) testedwith --keep-debuginfo=yes, so other tools may have unknown limitations.

关于shared-libraries - 如何使用 Valgrind 跟踪动态加载的库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38218487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com