From patchwork Mon Nov 13 15:04:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 79745 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 918F938E08DD for ; Mon, 13 Nov 2023 15:05:06 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by sourceware.org (Postfix) with ESMTPS id AFD2E3858C2D for ; Mon, 13 Nov 2023 15:04:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFD2E3858C2D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AFD2E3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887890; cv=none; b=j8YaUfRMGgfss/F/5XqodVRiB64JX6gv5cQRdqf+x+veRCAOTn1RmBFMyf86th49QBhYgTAJcOy1js6YLaGwGWIjd1PWdl+NifN0e/dGuUWIUQ4KiPHl79XX+YfPhxIq0Y4vfoxfdgD5/pcT7qh6iRJdK5Do6jtodkcX32RvwPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887890; c=relaxed/simple; bh=qDDBOUp+TM3Gq8pzwNXtwv6PR0gDAGlWZ+wx6qFIlko=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=jGmGp2yFRVOH45jUFHpfULzwgiCwjgJUaMB303kui+2vLlYseyRJEX6XgrO2FykCmwmpkdtrHrBw2pLd9nhAOT+PXeYC+oNO9IoCuZ0mdSZso2EdiuMFOGfhvk5fUgWKCJxHOF6/1U18melL4N5FBwvqbbre2EK50XnQtBjIUfI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2c54c8934abso61701091fa.0 for ; Mon, 13 Nov 2023 07:04:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887886; x=1700492686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EpqSjioQemKq9eQEIJHULy+caCcRhfvmBm5UJNidcc4=; b=WDogSrFEGR/TbjqvF9dTfPsObq8eaZLJlBV+b9xmD/1oH5C9nPUWCZaBmmiL9RPzFL hjS1/66oP4k2Rl/L/TMwhx34CSw+3KhqBgGuRp03I0rrpqL6EneV9Amj9FVpLqFtW6fU s961YzuN7zOsXW4bC+G0lvF1s5SFRlJEr/Fi/sb0ZItzmaFOyejXPvEgZ1nCJ9M9DYMG w3Sjlw4AZJ398LyzjEV40kS8CuvkVNR8f0j8Iu3JUPUUSSrQz2iYU4S2SRhznQqO/+Cc qGyfRSdzkA/fiikCqqwzrCwIsHY98g5DXlLKpDMsUWpuUuEWi7DvBPWM9jp4hDYvI/rn rtVA== X-Gm-Message-State: AOJu0YymXrEmEERM1hu6qZ8Kej8kwRwI9It5V01Xdm/xZKzLBtsGX4Hb ydCQT7qmDftb756NrbV6pSq4e3gaopc= X-Google-Smtp-Source: AGHT+IEHCQd+R0RnMYq7oJ1xWN51bel504UrdYqzYeqinhx2bxq/cBcXGbD3xn1JKX3pvfePkGA+Lg== X-Received: by 2002:a2e:be14:0:b0:2c8:3b99:7f04 with SMTP id z20-20020a2ebe14000000b002c83b997f04mr4501400ljq.0.1699887885750; Mon, 13 Nov 2023 07:04:45 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with UTF8SMTPSA id l10-20020a5d674a000000b003253523d767sm5621189wrw.109.2023.11.13.07.04.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:04:45 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [FYI/pushed v4 01/25] Add "maint info linux-lwps" command Date: Mon, 13 Nov 2023 15:04:03 +0000 Message-Id: <20231113150427.477431-2-pedro@palves.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231113150427.477431-1-pedro@palves.net> References: <20231113150427.477431-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org From: Andrew Burgess This adds a maintenance command that lets you list all the LWPs under control of the linux-nat target. For example: (gdb) maint info linux-lwps LWP Ptid Thread ID 560948.561047.0 None 560948.560948.0 1.1 This shows that "560948.561047.0" LWP doesn't map to any thread_info object, which is bogus. We'll be using this in a testcase in a following patch. Co-Authored-By: Pedro Alves Change-Id: Ic4e9e123385976e5cd054391990124b7a20fb3f5 --- gdb/NEWS | 5 +++++ gdb/doc/gdb.texinfo | 4 ++++ gdb/linux-nat.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 3851114a9f7..d85a13b64fe 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -24,6 +24,11 @@ disassemble ** New read/write attribute gdb.Value.bytes that contains a bytes object holding the contents of this value. +* New commands + +maintenance info linux-lwps + List all LWPs under control of the linux-nat target. + *** Changes in GDB 14 * GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 2cd565ed5b4..4cbaaa6804f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -41189,6 +41189,10 @@ module (@pxref{Disassembly In Python}), and will only be present after that module has been imported. To force the module to be imported do the following: +@kindex maint info linux-lwps +@item maint info linux-lwps +Print information about LWPs under control of the Linux native target. + @smallexample (@value{GDBP}) python import gdb.disassembler @end smallexample diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 1c9756c18bd..f73e52f9617 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4503,6 +4503,49 @@ current_lwp_ptid (void) return inferior_ptid; } +/* Implement 'maintenance info linux-lwps'. Displays some basic + information about all the current lwp_info objects. */ + +static void +maintenance_info_lwps (const char *arg, int from_tty) +{ + if (all_lwps ().size () == 0) + { + gdb_printf ("No Linux LWPs\n"); + return; + } + + /* Start the width at 8 to match the column heading below, then + figure out the widest ptid string. We'll use this to build our + output table below. */ + size_t ptid_width = 8; + for (lwp_info *lp : all_lwps ()) + ptid_width = std::max (ptid_width, lp->ptid.to_string ().size ()); + + /* Setup the table headers. */ + struct ui_out *uiout = current_uiout; + ui_out_emit_table table_emitter (uiout, 2, -1, "linux-lwps"); + uiout->table_header (ptid_width, ui_left, "lwp-ptid", _("LWP Ptid")); + uiout->table_header (9, ui_left, "thread-info", _("Thread ID")); + uiout->table_body (); + + /* Display one table row for each lwp_info. */ + for (lwp_info *lp : all_lwps ()) + { + ui_out_emit_tuple tuple_emitter (uiout, "lwp-entry"); + + thread_info *th = linux_target->find_thread (lp->ptid); + + uiout->field_string ("lwp-ptid", lp->ptid.to_string ().c_str ()); + if (th == nullptr) + uiout->field_string ("thread-info", "None"); + else + uiout->field_string ("thread-info", print_full_thread_id (th)); + + uiout->message ("\n"); + } +} + void _initialize_linux_nat (); void _initialize_linux_nat () @@ -4540,6 +4583,9 @@ Enables printf debugging output."), sigemptyset (&blocked_mask); lwp_lwpid_htab_create (); + + add_cmd ("linux-lwps", class_maintenance, maintenance_info_lwps, + _("List the Linux LWPS."), &maintenanceinfolist); }