Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6139839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:02:30+00:00 2026-05-23T18:02:30+00:00

Using gdb, I can type ‘info threads’ or ‘thread apply all backtrace’ to get

  • 0

Using gdb, I can type ‘info threads’ or ‘thread apply all backtrace’ to get a listing of all my threads and what they’re doing.

I would like to write a gdb macro which will instead list all running threads. This macro would retrieve the thread number (i.e. the argument to the gdb ‘thread’ command) and then would get the name of the thread that I have defined and stored in thread-local storage.

In pseudocode, this would look something like:

for each thread in threads
    t thread
    f 1
    set $name = my_name
    f top
    printf "Thread %d has name %s and is currently doing %s\n", thread, $name, curr_frame
next

There may be some small complexity around getting the string for curr_frame, but I’m willing to elide that for right now if I could get a good framework going for the rest of this bit.

I have a list of threads in my program, and for it I can get the pthread_t which corresponds to the thread pointer displayed as part of ‘info thread’ output:

(gdb) info thread
....
30 Thread 0x5221c940 (LWP 25304)  0x00000031c5a0aee9 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
....
(gdb) p *(_thread_t*)my_threads[0].pid
$4 = {
  t_id = 0x5221c940,

As you can see, the t_id member is the same as the thread address in the output, but I can’t really find any way to take programmatic advantage of this fact.

Anybody know a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:02:30+00:00Added an answer on May 23, 2026 at 6:02 pm

    Starting with version 7.0, GDB is scriptable in python, so you could pretty much implement your pseudo-code as is. See the documentation for accessing threads here and for getting the stack frame here.

    I think easiest is to write your program in a source.py file and then run in GDB:

    source source.py
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to list all the loaded modules using gdb, just like
To debug chromium using gdb ( LinuxDebugging ) one can use chromium --renderer-cmd-prefix=gdb --args
Using GDB, I find I get a segmentation fault when I attempt this operation:
I am trying to debug (using gdb) a multi-threaded program, which uses POSIX threads.
Over using gdb, any one can see content of any registers ? ex: x/x
I've tried using GDB and Valgrind, but I can't seem to pinpoint the problem.
In Linux, with C/C++ code, using gdb, how can you add a gdb breakpoint
When using gdb and Vim, often I want to stop on a particular line.
I know about specifying source locations using gdb. But I am wondering if there's
I'm working on a multithreaded application, and I want to debug it using GDB.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.