From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3pdaJXSjH2d0bh0AWB0awg (envelope-from ) for ; Mon, 28 Oct 2024 10:45:08 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=L/bEXSWC; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 701611E56E; Mon, 28 Oct 2024 10:45:08 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,URIBL_BLOCKED,URIBL_DBL_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 85D081E37A for ; Mon, 28 Oct 2024 10:45:07 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 144A23858C98 for ; Mon, 28 Oct 2024 14:45:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 144A23858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1730126707; bh=8CmFCkjmsucXUpPpsRfbaJUYzjrdkb7ZTDtnGX0gCng=; h=To:Cc:Subject:In-Reply-To:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=L/bEXSWCo4Ym5QUTiLNsi6xrpBkw+JCBFvWKoff1jtt+6z+k0yPAEUxSgViR40Zik qNmW+XG1bCJIax4PKlyWTso/6SKLSdgPHnTI6n6KBNg6Wv5QWZ/lKcbr8pHV2LQrgz n5hjS7mmW1myHWQBD1Vnu4/1ercNFwkG9JhPHspo= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 4009B3858D26 for ; Mon, 28 Oct 2024 14:44:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4009B3858D26 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4009B3858D26 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730126664; cv=none; b=ecaje7ugkHrPbOwQ2ngIfFbCB09fJNK970bX12o+gABRwRwbP2nQbRxtoN8WOU+otyOQWIc51goIradFFsSTS9/dJeeMlIfzx0iyn5yJBh1U/WIOJ5si7T2QBZIl18sSu0CYWtPQtvVPkHQwDkA5VWFeDiDUaTgzmj+M8XUM4V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730126664; c=relaxed/simple; bh=wbdbwHhQsPrVegNjQ5lgTNoDxikdYxOxZ3GrCJmd6gE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GO+6sJy47QFL7zqYHlSgoJFyKDwrj+HYAKpRk0U1xBbTqsNLNAaRE989EhHUHvdiOClgJcUCFJSDVj/vmTGB0Wei75k2nkVe33rnwLaG1uLF4GM9k2jm1f/K+qaviytAhOEORPanLeQWm5wQI/3kY9u6NUTNzrJOq7JiuoMPSg0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-p7dTB8UWMW6qoeFJBznGVQ-1; Mon, 28 Oct 2024 10:44:13 -0400 X-MC-Unique: p7dTB8UWMW6qoeFJBznGVQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-37d5606250aso2178596f8f.2 for ; Mon, 28 Oct 2024 07:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730126652; x=1730731452; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8CmFCkjmsucXUpPpsRfbaJUYzjrdkb7ZTDtnGX0gCng=; b=HcICfCKbRGFxXMQjrJm8uDWaDRA+dRG5fTwMwNRgmETD8OZCiuXTJL1C0gqBS8m5VB vEnmdGtw17fwdPRva9DFwhIuXRkdrGVC+F3p2eg4LZYMnKKLu4gZbWP5QxCWS/AncnkW amVxD5+pyX0ETz6eV6Ycck3qTSu5Igoz+sGNnNBgSJeO8s2IIcD45WKikYu+taNjor/x gQk/9Ht/B8vNfkxnEkV3ypN7grsAUQ/NYRgQhkECwQDRa3ojoLpdfPzWouxbvKl854Il /XNd3YNBUQM0y30tS6Sf8Ck0kgt4m7yeE5MkPmeDPB47+rQhNN+EtfsgREM162ZM1ASD qaYg== X-Forwarded-Encrypted: i=1; AJvYcCWd2D4w9Mlj6UjvujuazMQv3bXFsJroL1VsM2NELxvJoitVdVsyN7sCuHhVFSEHb74T/QE=@sourceware.org X-Gm-Message-State: AOJu0YyU00Fm9ux8JcexA3dPHyjsg50PnUsXBobeKxtlL14Ae1ixaeRi 36/T4WyVn6GT8JDHpzsBUTezlMZcNhSHcWObf9d44vTcApTWxOIbRbXaMbIon6BKvQul+4jH+4f L3UoDYDIhbYOLV5NwFsdzEyqdkqj/2MBB1sJQLKtKGwdWO+Jt X-Received: by 2002:a5d:5552:0:b0:37d:238:983 with SMTP id ffacd0b85a97d-3806113d43amr6111818f8f.22.1730126652307; Mon, 28 Oct 2024 07:44:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuxXsOzsirQkSOqhE1Uu2mdDcykxjWtCzXR11P+Zq1zvUoioM1PAQFhJA3/xfZYV7aiBPiZQ== X-Received: by 2002:a5d:5552:0:b0:37d:238:983 with SMTP id ffacd0b85a97d-3806113d43amr6111801f8f.22.1730126651948; Mon, 28 Oct 2024 07:44:11 -0700 (PDT) Received: from localhost (197.209.200.146.dyn.plus.net. [146.200.209.197]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b70bc1sm9722484f8f.70.2024.10.28.07.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 07:44:11 -0700 (PDT) To: "Ijaz, Abdul B" , "gdb@sourceware.org" Cc: "Aktemur, Tankut Baris" , "Schimpe, Christina" , "Metzger, Markus T" Subject: Re: [RFC] New command "thread filter" in GDB In-Reply-To: References: Date: Mon, 28 Oct 2024 14:44:11 +0000 Message-ID: <874j4wwamc.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb Reply-To: Andrew Burgess Errors-To: gdb-bounces~public-inbox=simark.ca@sourceware.org Sender: "Gdb" "Ijaz, Abdul B via Gdb" writes: > Hi All, > > I am writing to collect your feedback for the new command =E2=80=9Cthread= filter=E2=80=9D, we would like to introduce. This new command will proce= ss the input list of threads and then try to filter them if there is any ex= pression in the input. So it print only filtered thread ids from the input = list where the input expression evaluates to true. Here are some examples= for the usage of this command: > > > * thread filter 1-9 > * Outputs the ids of threads with single digit > * thread filter all x > 10 > * Outputs the ids of threads in whose context the variable =E2=80= =9Cx=E2=80=9D is greater than 10. > * thread filter 10-99 $_thread % 2 =3D=3D 0 > * Outputs the ids of threads whose id is a two-digit even number. > * thread filter all predicate() > * Outputs the ids of thread for which the function =E2=80=9Cpredic= ate=E2=80=9D evaluates to true. > * thread filter all workitem =3D=3D 1234 > * Find the thread(s) for which the =E2=80=9Cworkitem=E2=80=9D vari= able has a specific value. > > Output of all these commands will be string type list of thread ids which= may be used later for other commands like thread apply, info thread or fur= ther filtering. For example > > * thread filter all $_thread<5 > > Filtered threads: > > $1 =3D =E2=80=9C1 2 3 4=E2=80=9D > > > Examples of output usage in other command like =E2=80=9Cinfo thread=E2= =80=9D or =E2=80=9Cthread apply=E2=80=9D: > > * info threads 1 2 3 4 > * =E2=80=9Cinfo thread=E2=80=9D command print thread info for thre= ad ids =E2=80=9C1 2 3 4 5=E2=80=9D > > OR > > * thread apply 1 2 3 4 p workitem > * Print a variable with name =E2=80=9Cworkitem=E2=80=9D for all th= e threads matching ids filtered by the thread filter command. > * Thread filter 1 2 3 4 workitem >2 > * Outputs the ids of thread from the input =E2=80=9C1 2 3 4 5=E2= =80=9D list for which a variable =E2=80=9Cworkitem=E2=80=9D value is great= er than 2. > > There is already a =E2=80=9Cthread find=E2=80=9D command in GDB which fil= ters using regex for some fields. It filters the thread(s) using fields lik= e id, thread name etc. The output of this command is thread id, name and = extra information. But this command is not able to filter using thread loc= ation, expression, private or convenience variables like shown above and al= so if there are many threads filtered then its output is not easy to reuse = as an input for other commands. Like if someone want to get =E2=80=9Cinfo = threads=E2=80=9D or =E2=80=9Cthread apply=E2=80=9D for all the filtered thr= eads etc. Mentioning this, to clarify also whether it will be best to upd= ate the existing command or adding a new command would be fine. As extend= ing the existing command will update the output of command. Example of the = input and outputs of existing =E2=80=9Cthread find=E2=80=9D command. > > (gdb) help thread find > Find threads that match a regular expression. > Usage: thread find REGEXP > Will display thread ids whose name, target ID, or extra info matches REGE= XP. > (gdb) info threads > Id Target Id Frame > * 1 Thread 0x2b80 (LWP 70636) "async" main () at async.c:63 > 2 Thread 0x640 (LWP 70639) "async" futex_wait (=E2=80=A6) at ../sy= sdeps/nptl/futex-internal.h:146 > 3 Thread 0x7ffff7580640 (LWP 70640) "async" futex_wait (=E2=80=A6) = at ../sysdeps/nptl/futex-internal.h:146 > (gdb) thread find 7063 > Thread 1 has target id 'Thread 0x7ffff7d82b80 (LWP 70636)' > Thread 2 has target id 'Thread 0x7ffff7d81640 (LWP 70639)' > (gdb) thread find async > Thread 1 has target name 'async' > Thread 2 has target name 'async' > Thread 3 has target name 'async' > (gdb) thread find async.c > No threads match 'async.c' > > So the new =E2=80=9Cthread filter=E2=80=9D command will handle =E2=80=9Cl= ocation=E2=80=9D and =E2=80=9Cexpression=E2=80=9D filtering which is not ha= ndled by =E2=80=9Cthread find=E2=80=9D command. Adding a new command inste= ad of extending =E2=80=9Cthread find=E2=80=9D will avoid changing the outpu= t of the existing command. > > For the new command =E2=80=9Cthread filter=E2=80=9D, here are two options= considered in handling of =E2=80=9Cexpression=E2=80=9D and =E2=80=9Clocati= on=E2=80=9D as in input. Output will be same for both options and only inp= ut expression and locations can be handled differently. The output is a li= st of =E2=80=9Cthread ids=E2=80=9D a string type. Please refer to examples = above for the usage of output from this command as other commands input. Y= our feedback will be greatly appreciated regarding which option would be be= st here: > > OPTION 1: Using "at" and "if" Clauses > > In this case for filtering, =E2=80=9Cat=E2=80=9D and =E2=80=9Cif=E2=80=9D= clauses can be added as an optional arguments to this command which takes = expression as an input for the =E2=80=9Cif=E2=80=9D clause and location via= =E2=80=9Cat=E2=80=9D clause. The =E2=80=9Cif=E2=80=9D clause usage is si= milar to similar clause in the =E2=80=9Cbreak=E2=80=9D command. > > Command: thread filter [thread-id-list/all] [OPTION] [ at filename:linenu= m] [if expression] > > E.g.: > (gdb) thread filter at main.cpp:3 if $_thread >1 && $_thread<5 > Filtered threads: > $1=3D =E2=80=9C2 3 4=E2=80=9D > > OPTION 2: Using Convenience Variables for Location > > Second option is we can avoid =E2=80=9Cif=E2=80=9D and =E2=80=9Cat=E2=80= =9D clauses and add location > also to the convenience variable (e.g. $_location) then user may just > filter everything via the convenience variable in the expression. Having the current location available via convenience variables sounds useful regardless, though I'd be tempted to suggest it should be split into two, file and line. The other possibility, which you don't specifically mention would be using GDB's option system, rather than going with a more natural language syntax (OPTION #1). You could allow something like: (gdb) thread filter [-location LOC] [-thread-id LIST] [expression] with the expression being: everything left on the command line once the arguments have been parsed. I'm not sure if this is better or not, but you hadn't mentioned this possibility, so I thought I'd offer it up. Thanks, Andrew > > Command: thread filter [thread-id-list/all] [OPTION] [expression] > > E.g.: > (gdb) thread filter at main.cpp:3 if ($_thread >1 && $_thread<5 ) && $_st= req($_location,=E2=80=9Dmain.cpp:3=E2=80=9D) > Filtered threads: > $1=3D =E2=80=9C2 3 4=E2=80=9D > =E2=80=9C > > What are your thoughts on this topic? Any feedback and new ideas are welc= ome for: > > 1. Extending "thread find" vs. New Command "thread filter" > 2. =E2=80=9COption1=E2=80=9D vs =E2=80=9COptions2=E2=80=9D for the new= filtering command. > > > Thanks & Best Regards > Abdul Basit > > Intel Deutschland GmbH > Registered Address: Am Campeon 10, 85579 Neubiberg, Germany > Tel: +49 89 99 8853-0, www.intel.de > Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Sil= va > Chairperson of the Supervisory Board: Nicole Lau > Registered Office: Munich > Commercial Register: Amtsgericht Muenchen HRB 186928