gdb break line thread thread-id

来源:互联网 发布:世嘉 倒闭 知乎 编辑:程序博客网 时间:2024/05/21 08:01

#include <stdio.h>#include <pthread.h>#include <sched.h>/*****************************************************************/typedef unsigned char   BYTE_T;typedef int             INT32_T;#define MAX_CHAR_LEN    (10)/****************************************************************/BYTE_T g_pu8Str[MAX_CHAR_LEN] = "abc";pthread_t   g_stPid;/***************************************************************/static void task_fun(void){    int i32Num = 0;        while (1)    {        sleep(1);        printf("%d\n", i32Num);        i32Num++;    }}void init_thread(void){    pthread_attr_t stAttr;    struct sched_param sched_proi;    pthread_attr_init(&stAttr);        /*ÉèÖÃÏß³ÌÓÅÏÈŒ¶*/    pthread_attr_setschedpolicy(&stAttr, SCHED_FIFO);    /*set thread pri*/    pthread_attr_setscope(&stAttr, PTHREAD_SCOPE_SYSTEM);    /**/    pthread_attr_setdetachstate(&stAttr, PTHREAD_CREATE_DETACHED);        /**/    sched_proi.__sched_priority =   66;    pthread_attr_setschedparam(&stAttr, &sched_proi);    pthread_attr_setstacksize(&stAttr, 0x20000);        if (0 != pthread_create(&g_stPid, &stAttr, (void *)task_fun, NULL))    {        /**/        pthread_detach((pthread_t)g_stPid);    }}int main(int argc, char *argv[]){    INT32_T i32Num = 0;    init_thread();    printf("%s\n", g_pu8Str);    printf("%d\n", i32Num);    i32Num = 32;        printf("i32Num = [%d]\n", i32Num);    getchar();    return 0;}

root@ubuntu:/home/commander/project/gdb_test# gdb ./gdb_test.elf -q

Reading symbols from /home/commander/project/gdb_test/gdb_test.elf...done.
(gdb) l task_fun
15    pthread_t   g_stPid;
16    
17    /***************************************************************/
18    
19    static void task_fun(void)
20    {
21        int i32Num = 0;
22        
23        while (1)
24        {
(gdb)
25            sleep(1);
26            printf("%d\n", i32Num);
27            i32Num++;
28        }
29    }
30    
31    void init_thread(void)
32    {
33        pthread_attr_t stAttr;
34        struct sched_param sched_proi;
(gdb) break task_fun
Breakpoint 1 at 0x804873a: file ./gdb_test.c, line 21.
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x0804873a in task_fun at ./gdb_test.c:21
(gdb) r
Starting program: /home/commander/project/gdb_test/gdb_test.elf
[Thread debugging using libthread_db enabled]
[New Thread 0xb7febb70 (LWP 5277)]
abc
0
i32Num = [32]
[Switching to Thread 0xb7febb70 (LWP 5277)]

Breakpoint 1, task_fun () at ./gdb_test.c:21
21        int i32Num = 0;
(gdb) info threads
  Id   Target Id         Frame
* 2    Thread 0xb7febb70 (LWP 5277) "gdb_test.elf" task_fun () at ./gdb_test.c:21                 ------------thread-id = 2
  1    Thread 0xb7fec6c0 (LWP 5274) "gdb_test.elf" 0x00130416 in __kernel_vsyscall ()
(gdb) break gdb_test.c:25 thread 2                                                                                                  ------------filename:line thread thread-id
Breakpoint 2 at 0x8048741: file ./gdb_test.c, line 25.
(gdb) c
Continuing.

Breakpoint 2, task_fun () at ./gdb_test.c:25
25            sleep(1);
(gdb) c
Continuing.
0

Breakpoint 2, task_fun () at ./gdb_test.c:25
25            sleep(1);
(gdb) c
Continuing.
1

Breakpoint 2, task_fun () at ./gdb_test.c:25
25            sleep(1);
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x0804873a in task_fun at ./gdb_test.c:21
    breakpoint already hit 1 time
2       breakpoint     keep y   0x08048741 in task_fun at ./gdb_test.c:25 thread 2
    stop only in thread 2
    breakpoint already hit 3 times
(gdb)

原创粉丝点击