From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id BFBD73890417 for ; Thu, 18 Jun 2020 15:52:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BFBD73890417 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-77-IxQIfBMCPQSHQifdVJbulQ-1; Thu, 18 Jun 2020 11:51:58 -0400 X-MC-Unique: IxQIfBMCPQSHQifdVJbulQ-1 Received: by mail-wr1-f69.google.com with SMTP id d6so2968803wrn.1 for ; Thu, 18 Jun 2020 08:51:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=EfJWba0lF2o/pCwTyHH6g+83PsDBBC1JLPZmp5pmjVQ=; b=Q0ghq8ls5EzRYpQen+NPwIGiBiapp0bIFrG5EW3gN58W95FgDWhTglg8e684oC/7KM XHLqU7klDJ4xFKsNyKl7f/e21obCOwux/3XP+7GTaK3JcIp9orIyd/EkDotANb1F/d2Q stOkC+S59s6FCMo0jLZC4rIs7xfNIorSTgZhAZ6wFzd1s2mYm+i5ORKD3YuL5r72O2q7 13duSqsKe4vQMrrqxVRKdVW0R9dHjcE3GbMtUB8wpKcA6eVWq8e3DAfSSx18BZl3ukl6 oKRy+tg4fkZBm5ARiBQSi2AwCHxgQjwP5CfHXFAOPmWueoSAldfTfRoBcTiCc0XGAqC7 B0fg== X-Gm-Message-State: AOAM531CkuFcA0JazwLw08A6Pc0XdLqr3pMPjcVY5av8YVwUCQk+RDrt vv2HCspQZXO+mX0QV+2mrJGq/3vSLh/WLPSIbo8cCBfKN48HmVA4wja1TeLcLAa+BzF5HHx33sV njtFP/jhtg6ucFpibguSHGA== X-Received: by 2002:a5d:4941:: with SMTP id r1mr4145765wrs.72.1592495511395; Thu, 18 Jun 2020 08:51:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5HrGtiqi2+CeQuE4whELWGpXbInrunfPtw3Imc8kbDOVd1H//xP4CoRxr52BKAzEbBa0OZg== X-Received: by 2002:a5d:4941:: with SMTP id r1mr4145757wrs.72.1592495511172; Thu, 18 Jun 2020 08:51:51 -0700 (PDT) Received: from ?IPv6:2001:8a0:f922:c400:56ee:75ff:fe8d:232b? ([2001:8a0:f922:c400:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id s2sm3820023wmh.15.2020.06.18.08.51.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Jun 2020 08:51:50 -0700 (PDT) Subject: Re: Unbreaking gdb on Solaris post-multitarget [PR 25939] To: Rainer Orth References: <7fb790ae-61a9-a6a3-3b87-74fcac400664@redhat.com> <0e3e81a9-a5de-42bc-7d58-094f2adca164@redhat.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Thu, 18 Jun 2020 16:51:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <0e3e81a9-a5de-42bc-7d58-094f2adca164@redhat.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="------------5908642A3D37F82D87E00AB2" X-Spam-Status: No, score=-8.8 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, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jun 2020 15:52:09 -0000 This is a multi-part message in MIME format. --------------5908642A3D37F82D87E00AB2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 6/18/20 3:55 PM, Pedro Alves via Gdb-patches wrote: > On 6/17/20 3:45 PM, Rainer Orth wrote: >> [Thread debugging using libthread_db enabled] >> [New Thread 1 (LWP 1)] >> Breakpoint 1 at 0x401036: file hello.c, line 6. >> bottom-gdb.gdb:3: Error in sourced command file: >> procfs: couldn't find pid 0 in procinfo list. > > I see what this is. This is procfs_target::wait relying on > inferior_ptid. Since the multi-target series, inferior_ptid > is null_ptid before we call target_wait: > > static ptid_t > do_target_wait_1 (inferior *inf, ptid_t ptid, > target_waitstatus *status, int options) > { > ptid_t event_ptid; > struct thread_info *tp; > > /* We know that we are looking for an event in the target of inferior > INF, but we don't know which thread the event might come from. As > such we want to make sure that INFERIOR_PTID is reset so that none of > the wait code relies on it - doing so is always a mistake. */ > switch_to_inferior_no_thread (inf); > > > I'm working on a patch. Here it is. This works for me on a Solaris 11.3 (virtual and slow...) machine. Debugging GDB itself works for me, and I've checked that the gdb.base/break.exp testcase passes cleanly, at least. Your push_target fix is still necessary, FAOD. Could you give it a try? Thanks, Pedro Alves --------------5908642A3D37F82D87E00AB2 Content-Type: text/x-patch; name="0001-Solaris-target_wait-don-t-rely-on-inferior_ptid.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Solaris-target_wait-don-t-rely-on-inferior_ptid.patch" >From d31cd9842ab489d1adfd8d904572db28ef3fcd23 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 18 Jun 2020 14:54:08 +0100 Subject: [PATCH] Solaris, target_wait(), don't rely on inferior_ptid Debugging on Solaris is broken, with the procfs target backend failing with: procfs: couldn't find pid 0 in procinfo list. as soon as you start a program. The problem is procfs_target::wait assuming that inferior_ptid is meaningful on entry, but, since the multi-target series, inferior_ptid is null_ptid before we call target_wait, in infrun.c: static ptid_t do_target_wait_1 (inferior *inf, ptid_t ptid, target_waitstatus *status, int options) { ... /* We know that we are looking for an event in the target of inferior INF, but we don't know which thread the event might come from. As such we want to make sure that INFERIOR_PTID is reset so that none of the wait code relies on it - doing so is always a mistake. */ switch_to_inferior_no_thread (inf); This patch tweaks the backend to remove the assumption that inferior_ptid points at something. sol-thread.c (the thread_stratum that sits on top of procfs.c) also has the same issue. Some spots in procfs_target::wait were returning TARGET_WAITKIND_SPURIOUS+inferior_ptid. This commit replaces those with waiting again without returning to the core. This fixes the relying on inferior_ptid, and also should fix the issue discussed here: https://sourceware.org/pipermail/gdb/2020-May/048616.html https://sourceware.org/pipermail/gdb/2020-June/048660.html gdb/ChangeLog: yyyy-mm-dd Pedro Alves * procfs.c (procfs_target::wait): Don't reference inferior_ptid. Use the current inferior instead. Don't return TARGET_WAITKIND_SPURIOUS/inferior_ptid -- instead continue and wait again. * sol-thread.c (sol_thread_target::wait): Don't reference inferior_ptid. (ps_lgetregs, ps_lsetregs, ps_lgetfpregs, ps_lsetfpregs) (sol_update_thread_list_callback): Use the current inferior's pid instead of inferior_ptid. --- gdb/procfs.c | 45 +++++++++++++++++---------------------------- gdb/sol-thread.c | 30 ++++++++++-------------------- 2 files changed, 27 insertions(+), 48 deletions(-) diff --git a/gdb/procfs.c b/gdb/procfs.c index f5cb5a9320b..c2e3af71c24 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -2126,7 +2126,11 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, retval = ptid_t (-1); /* Find procinfo for main process. */ - pi = find_procinfo_or_die (inferior_ptid.pid (), 0); + + /* procfs_target currently only supports one inferior. */ + inferior *inf = current_inferior (); + + pi = find_procinfo_or_die (inf->pid, 0); if (pi) { /* We must assume that the status is stale now... */ @@ -2153,10 +2157,10 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, wait_retval = ::wait (&wstat); /* "wait" for the child's exit. */ /* Wrong child? */ - if (wait_retval != inferior_ptid.pid ()) + if (wait_retval != inf->pid) error (_("procfs: couldn't stop " "process %d: wait returned %d."), - inferior_ptid.pid (), wait_retval); + inf->pid, wait_retval); /* FIXME: might I not just use waitpid? Or try find_procinfo to see if I know about this child? */ retval = ptid_t (wait_retval); @@ -2211,13 +2215,11 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, printf_unfiltered (_("[%s exited]\n"), target_pid_to_str (retval).c_str ()); delete_thread (find_thread_ptid (this, retval)); - status->kind = TARGET_WAITKIND_SPURIOUS; - return retval; + target_continue_no_signal (ptid); + goto wait_again; } else if (syscall_is_exit (pi, what)) { - struct inferior *inf; - /* Handle SYS_exit call only. */ /* Stopped at entry to SYS_exit. Make it runnable, resume it, then use @@ -2232,14 +2234,13 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, if (!proc_run_process (pi, 0, 0)) proc_error (pi, "target_wait, run_process", __LINE__); - inf = find_inferior_pid (this, pi->pid); if (inf->attach_flag) { /* Don't call wait: simulate waiting for exit, return a "success" exit code. Bogus: what if it returns something else? */ wstat = 0; - retval = inferior_ptid; /* ? ? ? */ + retval = ptid_t (inf->pid); /* ? ? ? */ } else { @@ -2278,19 +2279,9 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, i, sysargs[i]); } - if (status) - { - /* How to exit gracefully, returning "unknown - event". */ - status->kind = TARGET_WAITKIND_SPURIOUS; - return inferior_ptid; - } - else - { - /* How to keep going without returning to wfi: */ - target_continue_no_signal (ptid); - goto wait_again; - } + /* How to keep going without returning to wfi: */ + target_continue_no_signal (ptid); + goto wait_again; } break; case PR_SYSEXIT: @@ -2322,9 +2313,8 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, if (!in_thread_list (this, temp_ptid)) add_thread (this, temp_ptid); - /* Return to WFI, but tell it to immediately resume. */ - status->kind = TARGET_WAITKIND_SPURIOUS; - return inferior_ptid; + target_continue_no_signal (ptid); + goto wait_again; } else if (syscall_is_lwp_exit (pi, what)) { @@ -2364,8 +2354,8 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, i, sysargs[i]); } - status->kind = TARGET_WAITKIND_SPURIOUS; - return inferior_ptid; + target_continue_no_signal (ptid); + goto wait_again; } break; case PR_REQUESTED: @@ -2416,7 +2406,6 @@ procfs_target::wait (ptid_t ptid, struct target_waitstatus *status, /* Got this far without error: If retval isn't in the threads database, add it. */ if (retval.pid () > 0 - && retval != inferior_ptid && !in_thread_list (this, retval)) { /* We have a new thread. We need to add it both to diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index 9addf8de3ab..a24d51d1db2 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -427,16 +427,6 @@ ptid_t sol_thread_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options) { - ptid_t rtnval; - ptid_t save_ptid; - - save_ptid = inferior_ptid; - scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - - inferior_ptid = thread_to_lwp (inferior_ptid, main_ph.ptid.pid ()); - if (inferior_ptid.pid () == -1) - inferior_ptid = procfs_first_available (); - if (ptid.pid () != -1) { ptid_t ptid_for_warning = ptid; @@ -449,17 +439,17 @@ sol_thread_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, ptid_for_warning.tid ()); } - rtnval = beneath ()->wait (ptid, ourstatus, options); + ptid_t rtnval = beneath ()->wait (ptid, ourstatus, options); if (ourstatus->kind != TARGET_WAITKIND_EXITED) { /* Map the LWP of interest back to the appropriate thread ID. */ - rtnval = lwp_to_thread (rtnval); - if (rtnval.pid () == -1) - rtnval = save_ptid; + ptid_t thr_ptid = lwp_to_thread (rtnval); + if (thr_ptid.pid () != -1) + rtnval = thr_ptid; /* See if we have a new thread. */ - if (rtnval.tid_p () && rtnval != save_ptid) + if (rtnval.tid_p ()) { thread_info *thr = find_thread_ptid (current_inferior (), rtnval); if (thr == NULL || thr->state == THREAD_EXITED) @@ -855,7 +845,7 @@ ps_ptwrite (struct ps_prochandle *ph, psaddr_t addr, ps_err_e ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -872,7 +862,7 @@ ps_err_e ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -925,7 +915,7 @@ ps_err_e ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, prfpregset_t *fpregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -942,7 +932,7 @@ ps_err_e ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, const prfpregset_t * fpregset) { - ptid_t ptid = ptid_t (inferior_ptid.pid (), lwpid, 0); + ptid_t ptid = ptid_t (current_inferior ()->pid, lwpid, 0); struct regcache *regcache = get_thread_arch_regcache (current_inferior ()->process_target (), ptid, target_gdbarch ()); @@ -1012,7 +1002,7 @@ sol_update_thread_list_callback (const td_thrhandle_t *th, void *ignored) if (retval != TD_OK) return -1; - ptid_t ptid = ptid_t (inferior_ptid.pid (), 0, ti.ti_tid); + ptid_t ptid = ptid_t (current_inferior ()->pid, 0, ti.ti_tid); thread_info *thr = find_thread_ptid (current_inferior (), ptid); if (thr == NULL || thr->state == THREAD_EXITED) { base-commit: a8a566853a0fc7f57159e55436ff6f395e499568 prerequisite-patch-id: 5d757f55a3e4e55e9b9e70684280f64ea4176356 -- 2.14.5 --------------5908642A3D37F82D87E00AB2--