gdb how to get thread name displayed

前端 未结 3 1105
深忆病人
深忆病人 2021-01-04 19:34

There are many threads created in my application. some of the threads name are visible in the gdb while i execute the command \'info threads\', others are not displayed. How

相关标签:
3条回答
  • 2021-01-04 20:12

    You can set the thread name via non-standard POSIX api calls. GDB (and other debuggers) will display these names.

    On Linux

    // watch out, 16 char limit on the name
    pthread_setname_np(pthread_self(), "My thread name");
    

    On Mac

    pthread_setname_np("My thread name");
    
    0 讨论(0)
  • 2021-01-04 20:17

    Threads don't have names by default - the JKMainT string there is the name of the current function.

    Try selecting one of the threads and viewing the backtrace - that might give you a good idea which thread it is. Otherwise, you could try prctl with PR_SET_NAME if it's available.

    0 讨论(0)
  • 2021-01-04 20:30

    If you upgrade to gdb 7.3 or later, "info thread" will show thread names; at least on native (not remote) Linux.

    0 讨论(0)
提交回复
热议问题