Valgrind在警告/错误消息中显示的线程ID似乎是自生成的。它与gettid()或pthread_self()的线程ID不匹配。请找到所附的valgrind警告日志。在这种情况下,如何将valgrind警告与我自己的线程匹配,特别是当valgrind错误未显示完整堆栈时?
[debug] [12034:12525] zwp_interfaces_time.c:221 zwp_time_report_handler(): time callback done
[function] [12034:12426] zwp_interfaces.c:220 zwp_interfaces_report_wait(): Function started
[debug] [12034:12426] zwp_interfaces.c:229 zwp_interfaces_report_wait(): 1
[debug] [12034:12525] zwp_interfaces_time.c:245 zwp_time_date_report_handler(): date callback start
[debug] [12034:12426] zwp_interfaces.c:267 zwp_interfaces_report_wait(): 4
==12034== Thread 5:
==12034== Invalid write of size 4
==12034== at 0x4DCB36E: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034== Address 0x77a69d8 is on thread 5's stack
==12034== 16 bytes below stack pointer
==12034==
==12034== Conditional jump or move depends on uninitialised value(s)
==12034== at 0x4DCB518: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034== Uninitialised value was created by a stack allocation
==12034== at 0x4DCB36E: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034==
==12034== Use of uninitialised value of size 4
==12034== at 0x4DCB51A: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034== Uninitialised value was created by a stack allocation
==12034== at 0x4DCB36E: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034==
==12034== Use of uninitialised value of size 4
==12034== at 0x4DCB382: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034== Uninitialised value was created by a stack allocation
==12034== at 0x4DCB36E: ??? (in /home/debian/projecta/install/apr/lib/libapr-1.so.0.5.2)
==12034==
[debug] [12034:12429] zwp_interfaces.c:397 zwp_execute_messages(): 1
Valgrind线程ID为5。我的线程ID(来自syscall(SYS_gettid)
)为12525、12426、12429等。
答案 0 :(得分:0)
Valgrind日志/消息输出不显示OS线程ID。 实施例如一个新的命令行选项:
--show-lwpid=yes|no
(可选)在日志/消息输出中添加lwpid。 因此,我建议在valgrind bugzilla上提交错误/希望, 可能会增加很快出现此功能的可能性 即将发布新版本:)。
同时,如果线程恰好在开始时启动 在执行过程中,您可能会显示线程列表和链接 通过使用gdb监视器命令“ v.info Scheduler”使用操作系统线程ID。
例如从外壳程序,您可以执行以下操作:
vgdb v.info scheduler
您也可以从gdb或代码中执行此操作。
答案 1 :(得分:0)
通过IRC频道与Valgrind开发人员/用户进行了聊天。 Valgrind线程ID是从1开始的自生成编号。它与系统线程ID没有关系。感谢渠道中的Valgrind开发人员/用户之一,建议为线程分配名称。我已经尝试过该方法,并且有效!这是我的代码:
//Start of each thread
char current_thread_name[16] = { 0 };
sprintf(current_thread_name, "tid[%ld]", syscall(SYS_gettid));
if(prctl(PR_SET_NAME, current_thread_name) == -1) goto l_err_set_thread_name;
Debug_print("Current thread name: %s", current_thread_name);
在valgrind选项中具有'-v'选项可以在错误报告和检查期间打印出线程名称!