Oracle® Solaris Studio 12.4:使用 dbx 调试程序

退出打印视图

更新时间: 2015 年 1 月
 
 

了解线程创建活动

通过使用 thr_create 事件和 thr_exit 事件,您可以了解您的应用程序多久创建并销毁一次线程,如以下示例所示:

(dbx) trace thr_create
(dbx) trace thr_exit
(dbx) run

trace: thread created t@2 on l@2
trace: thread created t@3 on l@3
trace: thread created t@4 on l@4
trace: thr_exit t@4
trace: thr_exit t@3
trace: thr_exit t@2

该应用程序创建了三个线程。请注意线程是如何以相反顺序从其创建中退出来的。这可能表明,如果此应用程序中的线程偏多,就会导致线程累积并消耗资源。

要获得更广泛的信息,可以在不同会话中尝试以下示例:

(dbx) when thr_create { echo "XXX thread $newthread created by $thread"; }
XXX thread t@2 created by t@1
XXX thread t@3 created by t@1
XXX thread t@4 created by t@1

此输出显示三个线程全部是由公用多线程模式的 t@1 线程创建的。

假设您要从开头调试线程 t@3。可以在线程 t@3 创建为如下所示时停止应用程序。

(dbx) stop thr_create t@3
(dbx) run
t@1 (l@1) stopped in tdb_event_create at 0xff38409c
0xff38409c: tdb_event_create       :    retl
Current function is main
216       stat = (int) thr_create(NULL, 0, consumer, q, tflags, &tid_cons2);
(dbx)

如果您的应用程序有时从线程 t@5 而不是从线程 t@1 产生新的线程,则可以按如下所示捕获此事件:

(dbx) stop thr_create -thread t@5