From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 82129 invoked by alias); 6 Mar 2017 23:05:46 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 82118 invoked by uid 89); 6 Mar 2017 23:05:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=HX-PHP-Originating-Script:rcube.php, Examining, H*f:sk:1488663, H*i:sk:1488663 X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Mar 2017 23:05:43 +0000 Received: by simark.ca (Postfix, from userid 33) id E88DA1E7F5; Mon, 6 Mar 2017 18:05:41 -0500 (EST) To: psmith@gnu.org Subject: Re: Examining threads with Python extensions X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 06 Mar 2017 23:05:00 -0000 From: Simon Marchi Cc: gdb@sourceware.org In-Reply-To: <1488663824.3228.154.camel@gnu.org> References: <1488663824.3228.154.camel@gnu.org> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.3 X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00003.txt.bz2 On 2017-03-04 16:43, Paul Smith wrote: > Hi all. > > I'm trying to write some useful commands for my debugging using the > Python API in GDB. > > What I want to do is write a Python command that will visit each of the > threads in my process (or coredump) and examine the stacktrace, etc. > for > interesting content and display that. I have a lot of threads, and > there are certain ones that are always present, plus thread pools, etc. > I'd like to be able to generate a summary of the thread numbers (GDB > thread IDs), what that thread is for in my process, and what its status > is, etc. > > I can see https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html and > I can walk all stack frames in the currently selected thread, using the > gdb.newest() / Frame.older() etc. methods, which I can use to figure > out > what the current thread is doing. > > However, I can't seem to find any way to operate on all the threads. > In > https://sourceware.org/gdb/onlinedocs/gdb/Threads-In-Python.html the > only thread function available to me, from what I can see, is > gdb.selected_thread() which gives me an InferiorThread object for the > selected thread. > > But I can't find any methods that would switch to the "next" thread or > whatever. There's InferiorThread.switch() but that makes the current > InferiorThread object be the current thread... but how do I get the > InferiorThread objects for all the threads so I can use it?! > > Help? Thanks! The Inferior object has a .threads() method that returns its threads. I think that's what you are looking for. So you can do something like (pseudo python): for inf in gdb.inferiors(): for th in inf.threads(): print(th)