From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kLaIMCuiV2en9wkAWB0awg (envelope-from ) for ; Mon, 09 Dec 2024 21:06:35 -0500 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=P1slS4m6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C29F61E097; Mon, 9 Dec 2024 21:06:35 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable 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 482EF1E05C for ; Mon, 9 Dec 2024 21:06:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DBD423858031 for ; Tue, 10 Dec 2024 02:06:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBD423858031 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=P1slS4m6 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 19AA2385841C for ; Tue, 10 Dec 2024 02:04:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19AA2385841C 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 19AA2385841C 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=1733796242; cv=none; b=Oo0zjYdSvVQUpOokBRFjqblc8wfAx6SWPJucLR/LYqLjW0LBQ38ZazKAFgyfVtBW0O4l6juEGzRidMainghRG2bEJydvcJADf84tswnmF/A4QhIFGe6IR1friM4jhvnUiSIkEcBWzuVXNPq8k+dwMyirslD4wJbDrnTwcdkMEjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733796242; c=relaxed/simple; bh=fi8YTFR6/7lS7VIWOYij7kXA1aVESgMrLKz8V8HZq24=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tpmSGvBiEkZDElaO+r2VTajOViT4XOJDNePdvYCeKUdH13QiIXQn9v32SnNbHybhXmKsbb/ywpCWiJ3WTS2QqChAWIpjxjlJdu1T6Y8+12ZEkOx5MiAsJKST3glPuyTucY4E+PYqlDZBf6zg/6qz9oYWj6kyeFHhAyDYApfwib0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19AA2385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733796240; 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=4+c2/gtS6bSwWvwW526VDMKUjS/D6VaUKgMAAE8xAGw=; b=P1slS4m6jA2q0AuTPvYcq6tods36SUd8ba7w7msSd2cF/I/370fcljvsbx2VlS5ElzrLZn etOmGMKRqjalgIr38noJ29Uu8ome+eRJvahenzNl/fZXXXoOKmhmLPBP9dmWBe4lYlZhJy cnckFr/iBwxBnLhxKBoG6UGLtnrShJY= Received: from mx-prod-mc-05.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-197-E4on3XqYNjeRc4AxrmJMxw-1; Mon, 09 Dec 2024 21:03:57 -0500 X-MC-Unique: E4on3XqYNjeRc4AxrmJMxw-1 X-Mimecast-MFC-AGG-ID: E4on3XqYNjeRc4AxrmJMxw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8F78A1954AF5; Tue, 10 Dec 2024 02:03:56 +0000 (UTC) Received: from f41-1.lan (unknown [10.22.80.92]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 819601956089; Tue, 10 Dec 2024 02:03:55 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: pedro@palves.net, Kevin Buettner Subject: [PATCH v5 3/4] Print only process ptids from linux-fork.c Date: Mon, 9 Dec 2024 18:54:06 -0700 Message-ID: <20241210020313.584564-4-kevinb@redhat.com> In-Reply-To: <20241210020313.584564-1-kevinb@redhat.com> References: <20241210020313.584564-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: tA9v7fEBny3WLFOPTQofYSKsKte8Z7SzPVra722e5uc_1733796236 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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... Id Active Target Id Frame * 1.0 y Thread 0x7ffff7cb5740 (LWP 581704) at 0x401199, file hello.c, line 51 1.2 n process 581716 at 0x401199, file hello.c, line 51 1.3 n process 581717 at 0x401199, file hello.c, line 51 2.1 n process 581708 at 0x401258, file goodbye.c, line 62 2.2 y Thread 0x7ffff7cb5740 (LWP 581712) at 0x401258, file goodbye.c, line 62 3.0 y Thread 0x7ffff7cb5740 (LWP 581713) at 0x40115c, file hangout.c, line 31 3.2 n process 581715 at 0x40115c, file hangout.c, line 31 (gdb With this commit in place, the output looks like this instead: Id Active Target Id Frame * 1.0 y process 535276 at 0x401199, file hello.c, line 51 1.2 n process 535288 at 0x401199, file hello.c, line 51 1.3 n process 535289 at 0x401199, file hello.c, line 51 2.1 n process 535280 at 0x401258, file goodbye.c, line 62 2.2 y process 535284 at 0x401258, file goodbye.c, line 62 3.0 y process 535285 at 0x40115c, file hangout.c, line 31 3.2 n process 535287 at 0x40115c, file hangout.c, line 31 (For brevity, I've removed the directory elements in each of the paths above.) 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 | 39 ++++++++++++++------ gdb/testsuite/gdb.multi/checkpoint-multi.exp | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index af7d4b60819..f93e14bcac7 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -429,6 +429,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 @@ -492,7 +503,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)) @@ -520,7 +531,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); @@ -535,7 +546,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)) @@ -610,7 +621,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 ()); } } @@ -688,10 +699,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); @@ -716,7 +729,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 ()); } } @@ -736,10 +749,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 ()); } @@ -790,7 +805,7 @@ info_checkpoints_command (const char *arg, int from_tty) + (print_inf ? 1 : 0)); targid_width = std::max (targid_width, - target_pid_to_str (fi.ptid).size ()); + target_pid_to_str (proc_ptid (fi.ptid)).size ()); } } @@ -847,7 +862,7 @@ info_checkpoints_command (const char *arg, int from_tty) /* Print target id. */ gdb_printf ("%-*s", (int) targid_width, - target_pid_to_str (fi.ptid).c_str ()); + target_pid_to_str (proc_ptid (fi.ptid)).c_str ()); if (t->state == THREAD_RUNNING && is_current) gdb_printf (_(" (running)")); @@ -1013,7 +1028,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 4860608e704..e401e5e9555 100644 --- a/gdb/testsuite/gdb.multi/checkpoint-multi.exp +++ b/gdb/testsuite/gdb.multi/checkpoint-multi.exp @@ -23,7 +23,7 @@ require {istarget "*-*-linux*"} require gdb_protocol_is_native set checkpoints_header_re " +Id +Active Target Id +Frame.*?" -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.46.2