From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oJNrKfV2e2atDQ4AWB0awg (envelope-from ) for ; Tue, 25 Jun 2024 22:03:33 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XVe1f3Sw; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A4DA01E0BB; Tue, 25 Jun 2024 22:03:33 -0400 (EDT) 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 951841E0C1 for ; Tue, 25 Jun 2024 22:03:31 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 484273870C2C for ; Wed, 26 Jun 2024 02:03:31 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1B4EF3870C34 for ; Wed, 26 Jun 2024 02:02:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B4EF3870C34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B4EF3870C34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719367351; cv=none; b=Shz7A71kifIudsNBTbl0ghTHRaaBcrWYXX95fjxycMaJE5LDzs80EjAoFNpElcrJBtAJW+dooS4gSLzLhhIezK8d/xPrYXLcFIzthOVEMcKQD/3fxqi/o0R6KqXaSBzxwPjyim8GugXqa4QPY9SAJyMs6M3Fi3aGH4o8nQEK/48= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719367351; c=relaxed/simple; bh=rpa8kwMcdYgR9rXJw1uKwBEkNzVCSXImSOe6BwEdHNs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=T0W22k9m4lwbovsJQNtn+o7sq2J5F9PZ0Q66hoQeqq4+oAvxv4MFvRLYY2myUEDgoUJzdkBWDXqkrSACKw82xvjHUFMHFDi10WusoOUaV4V3yep+YQ30ObXe8sh0pPO06bsNavsWadlLlPFXdIGUMvkgF1YPHOUhHl6hN3OzROQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719367345; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q1uG8iIFTAwyDgw9bEPTB+TkqaTv/T5ZorUUy3SCVLA=; b=XVe1f3Swla25EHO4BxlHhRJaef72jI7J9S72XiEpYxJ6QPFEEfpOyVX7tXuBUV98vCaguc P+p8Fxuv3p33KA5cWaug9yTJXGlm6C29PtRpavGYMnYekSqx9SizmRR7sUU/4QnzU62ZEq q6pzUJVJzPxCM3OwscSj/sf1xJZKYHU= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-zrUlD-aAPkOeV84f4sUPuw-1; Tue, 25 Jun 2024 22:02:21 -0400 X-MC-Unique: zrUlD-aAPkOeV84f4sUPuw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AD1A719560AE; Wed, 26 Jun 2024 02:02:20 +0000 (UTC) Received: from f40-1.lan (unknown [10.22.16.241]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 561D219560AB; Wed, 26 Jun 2024 02:02:18 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Pedro Alves , Kevin Buettner Subject: [PATCH v4 3/4] Print only process ptids from linux-fork.c Date: Tue, 25 Jun 2024 18:55:54 -0700 Message-ID: <20240626020148.68109-4-kevinb@redhat.com> In-Reply-To: <20240626020148.68109-1-kevinb@redhat.com> References: <20240626020148.68109-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP 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+public-inbox=simark.ca@sourceware.org This commit causes a "process ptid" to be passed to all calls of target_pid_to_str in linux-fork.c. A "process ptid" is one in which only the pid component is set to a non-zero value; both the lwp and tid components are zero. The reason for doing this is that pids associated with checkpoints can never be a thread due to the fact that checkpoints (which are implemented by forking a process) can only (reasonably) work with single-threaded processes. Without this commit, many of the "info checkpoints" commands in gdb.multi/checkpoint-multi.exp will incorrectly show some of the checkpoints as threads. E.g... * 1.0 A Thread 0x7ffff7cd3740 (LWP 128534) at 0x401199, file hello.c, line 51 1.2 process 128546 at 0x401199, file hello.c, line 51 1.3 process 128547 at 0x401199, file hello.c, line 51 2.1 process 128538 at 0x401258, file goodbye.c, line 62 2.2 A Thread 0x7ffff7cd3740 (LWP 128542) at 0x401258, file goodbye.c, line 62 3.0 A Thread 0x7ffff7cd3740 (LWP 128543) at 0x40115c, file hangout.c, line 31 3.2 process 128545 at 0x40115c, file hangout.c, line 31 With this commit in place, the output looks like this instead: * 1.0 A process 129961 at 0x401199, file hello.c, line 51 1.2 process 129974 at 0x401199, file hello.c, line 51 1.3 process 129975 at 0x401199, file hello.c, line 51 2.1 process 129965 at 0x401258, file goodbye.c, line 62 2.2 A process 129969 at 0x401258, file goodbye.c, line 62 3.0 A process 129970 at 0x40115c, file hangout.c, line 31 3.2 process 129972 at 0x40115c, file hangout.c, line 31 (For brevity, I've removed the directory elements in each of the paths above.) I tried fixing this problem in another way, by not initializing the LWP component in the fork_info constructor. This leaves the LWP component as 0, making the ptid in question a process ptid. However, when I tried this, I saw asserts in add_initial_lwp, which is called by add_lwp, which, in turn, is called by linux_nat_switch_fork(), which is clearly needed by the linux-fork code. So... trying to avoid setting the LWP component to a non-zero value doesn't work. The testcase, gdb.multi/checkpoint-multi.exp, has been updated to reflect the fact that only "process" should now appear in output from "info checkpoints". --- gdb/linux-fork.c | 37 ++++++++++++++------ gdb/testsuite/gdb.multi/checkpoint-multi.exp | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 4905d4ffd88..501e8c332cb 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -445,6 +445,17 @@ fork_save_infrun_state (struct fork_info *fp) } } +/* Given a ptid, return a "process ptid" in which only the pid member + is present. This is used in calls to target_pid_to_str() to ensure + that only process ptids are printed by this file. */ + +static inline ptid_t +proc_ptid (ptid_t ptid) +{ + ptid_t process_ptid (ptid.pid ()); + return process_ptid; +} + /* Kill 'em all, let God sort 'em out... */ void @@ -508,7 +519,7 @@ linux_fork_mourn_inferior () last = find_last_fork (inf); fork_load_infrun_state (last); gdb_printf (_("[Switching to %s]\n"), - target_pid_to_str (inferior_ptid).c_str ()); + target_pid_to_str (proc_ptid (inferior_ptid)).c_str ()); /* If there's only one fork, switch back to non-fork mode. */ if (one_fork_p (inf)) @@ -536,7 +547,7 @@ linux_fork_detach (int from_tty, lwp_info *lp, inferior *inf) { if (ptrace (PTRACE_DETACH, inferior_ptid.pid (), 0, 0)) error (_("Unable to detach %s"), - target_pid_to_str (inferior_ptid).c_str ()); + target_pid_to_str (proc_ptid (inferior_ptid)).c_str ()); } delete_fork (inferior_ptid, inf); @@ -551,7 +562,7 @@ linux_fork_detach (int from_tty, lwp_info *lp, inferior *inf) if (from_tty) gdb_printf (_("[Switching to %s]\n"), - target_pid_to_str (inferior_ptid).c_str ()); + target_pid_to_str (proc_ptid (inferior_ptid)).c_str ()); /* If there's only one fork, switch back to non-fork mode. */ if (one_fork_p (inf)) @@ -626,7 +637,7 @@ class scoped_switch_fork_info catch (const gdb_exception &ex) { warning (_("Couldn't restore checkpoint state in %s: %s"), - target_pid_to_str (m_oldfp->ptid).c_str (), + target_pid_to_str (proc_ptid (m_oldfp->ptid)).c_str (), ex.what ()); } } @@ -702,10 +713,12 @@ delete_checkpoint_command (const char *args, int from_tty) error (_("Cannot delete active checkpoint")); if (ptrace (PTRACE_KILL, ptid.pid (), 0, 0)) - error (_("Unable to kill pid %s"), target_pid_to_str (ptid).c_str ()); + error (_("Unable to kill pid %s"), + target_pid_to_str (proc_ptid (ptid)).c_str ()); if (from_tty) - gdb_printf (_("Killed %s\n"), target_pid_to_str (ptid).c_str ()); + gdb_printf (_("Killed %s\n"), + target_pid_to_str (proc_ptid (ptid)).c_str ()); delete_fork (ptid, inf); @@ -730,7 +743,7 @@ delete_checkpoint_command (const char *args, int from_tty) { if (inferior_call_waitpid (pptid, ptid.pid ())) warning (_("Unable to wait pid %s"), - target_pid_to_str (ptid).c_str ()); + target_pid_to_str (proc_ptid (ptid)).c_str ()); } } @@ -750,10 +763,12 @@ detach_checkpoint_command (const char *args, int from_tty) Please switch to another checkpoint before detaching the current one")); if (ptrace (PTRACE_DETACH, ptid.pid (), 0, 0)) - error (_("Unable to detach %s"), target_pid_to_str (ptid).c_str ()); + error (_("Unable to detach %s"), + target_pid_to_str (proc_ptid (ptid)).c_str ()); if (from_tty) - gdb_printf (_("Detached %s\n"), target_pid_to_str (ptid).c_str ()); + gdb_printf (_("Detached %s\n"), + target_pid_to_str (proc_ptid (ptid)).c_str ()); delete_fork (ptid, current_inferior ()); } @@ -816,7 +831,7 @@ info_checkpoints_command (const char *arg, int from_tty) else gdb_printf (" "); - gdb_printf ("%s", target_pid_to_str (fi.ptid).c_str ()); + gdb_printf ("%s", target_pid_to_str (proc_ptid (fi.ptid)).c_str ()); gdb_printf (_(" at ")); ULONGEST pc @@ -983,7 +998,7 @@ linux_fork_context (struct fork_info *newfp, int from_tty, inferior *newinf) insert_breakpoints (); if (!inferior_changed) gdb_printf (_("Switching to %s\n"), - target_pid_to_str (inferior_ptid).c_str ()); + target_pid_to_str (proc_ptid (inferior_ptid)).c_str ()); } notify_user_selected_context_changed diff --git a/gdb/testsuite/gdb.multi/checkpoint-multi.exp b/gdb/testsuite/gdb.multi/checkpoint-multi.exp index a8f0190747b..6d4b70e1adb 100644 --- a/gdb/testsuite/gdb.multi/checkpoint-multi.exp +++ b/gdb/testsuite/gdb.multi/checkpoint-multi.exp @@ -22,7 +22,7 @@ require {istarget "*-*-linux*"} # Checkpoint support is implemented for the (Linux) native target. require gdb_protocol_is_native -set proc_re "(?:process $::decimal|Thread $::hex \\(LWP $::decimal\\))" +set proc_re "(?:process $::decimal)" set ckpt_re "Checkpoint" set main_proc "\\(main process\\)" set hello_c "hello\\.c" -- 2.45.2