gpt4 book ai didi

c - 如何阅读此 valgrind 信息

转载 作者:行者123 更新时间:2023-11-30 15:18:37 26 4
gpt4 key购买 nike

我正在运行一个多线程程序,每次都会遇到类似的错误

malloc(): memory corruption

或段错误。

我决定使用 valgrind 来调查我的程序显示了哪些类型的问题。首先我得到了以下输出。有人可以帮助我了解如何读取输出消息吗?

 ==17413== Conditional jump or move depends on uninitialised value(s)
==17413== at 0x47A2349: ns_name_ntop (ns_name.c:147)
==17413== by 0x47A3271: ns_name_uncompress (ns_name.c:585)
==17413== by 0x479B3EF: dn_expand (res_comp.c:93)
==17413== by 0x479FD2B: __res_queriesmatch (res_send.c:327)
==17413== by 0x47A0D19: __libc_res_nsend (res_send.c:1327)
==17413== by 0x479DDC7: __libc_res_nquery (res_query.c:226)
==17413== by 0x479E417: __libc_res_nquerydomain (res_query.c:582)
==17413== by 0x479E8FB: __libc_res_nsearch (res_query.c:416)
==17413== by 0x404B1D9: _nss_dns_gethostbyname3_r (dns-host.c:192)
==17413== by 0x404B540: _nss_dns_gethostbyname_r (dns-host.c:273)
==17413== by 0x42C53FA: gethostbyname_r@@GLIBC_2.1.2 (getXXbyYY_r.c:266)
==17413== by 0x42C4B7B: gethostbyname (getXXbyYY.c:116)
==17413== Uninitialised value was created by a stack allocation
==17413== at 0x804ADA3: UDP_Server_Open(int&, unsigned short) (UDP_Server.cpp:16)
==17413==
==17413== Use of uninitialised value of size 4
==17413== at 0x47A2382: ns_name_ntop (ns_name.c:153)
==17413== by 0x47A3271: ns_name_uncompress (ns_name.c:585)
==17413== by 0x479B3EF: dn_expand (res_comp.c:93)
==17413== by 0x479FD2B: __res_queriesmatch (res_send.c:327)
==17413== by 0x47A0D19: __libc_res_nsend (res_send.c:1327)
==17413== by 0x479DDC7: __libc_res_nquery (res_query.c:226)
==17413== by 0x479E417: __libc_res_nquerydomain (res_query.c:582)
==17413== by 0x479E8FB: __libc_res_nsearch (res_query.c:416)
==17413== by 0x404B1D9: _nss_dns_gethostbyname3_r (dns-host.c:192)
==17413== by 0x404B540: _nss_dns_gethostbyname_r (dns-host.c:273)
==17413== by 0x42C53FA: gethostbyname_r@@GLIBC_2.1.2 (getXXbyYY_r.c:266)
==17413== by 0x42C4B7B: gethostbyname (getXXbyYY.c:116)
==17413== Uninitialised value was created by a stack allocation
==17413== at 0x804ADA3: UDP_Server_Open(int&, unsigned short) (UDP_Server.cpp:16)

最佳答案

对于最简单的方法,获取有关错误的信息是读取类似的输出

 ==17413==    at 0x47A2349: ns_name_ntop (ns_name.c:147)

看看

  • 文件名 (ns_name.c)
  • 行号 (147)
  • 函数名称 (ns_name_ntop)

以及错误消息

Conditional jump or move depends on uninitialised value(s)

它基本上是说,您正在使用条件语句,例如 ifelse if 以及包含可能具有未初始化值的变量的表达式。未初始化数据的来源往往是:

  1. 程序中尚未初始化的局部变量。
  2. 在写入内容之前堆 block 的内容(使用 malloc() 或类似函数分配)。

这样,您就可以开始检查所有报告的消息。

更多相关信息,您可以查看on-line manual用于 Valgrind 中的 memcheck 工具。

关于c - 如何阅读此 valgrind 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31269906/

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