public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/27435] Attach on solaris segfaults GDB
Date: Mon, 22 Feb 2021 16:43:28 +0000	[thread overview]
Message-ID: <bug-27435-4717-zRNELaL4NY@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27435-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=27435

--- Comment #1 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Simon Marchi <simark@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=de146e1946ee45f2552c6b56714793a2eba9b823

commit de146e1946ee45f2552c6b56714793a2eba9b823
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Mon Feb 22 11:41:32 2021 -0500

    gdb: push target earlier in procfs_target::attach (PR 27435)

    Since this is a GDB 9 -> 10 regression, I would like to push it to
    gdb-10-branch.

    This is a follow-up to:

      https://sourceware.org/pipermail/gdb-patches/2021-February/176202.html

    This patch fixes a segfault seen when attaching to a process on Solaris.
    The steps leading to the segfault are:

     - procfs_target::attach calls do_attach, at this point the inferior's
       process slot in the target stack is empty.
     - do_attach adds a thread with `add_thread (&the_procfs_target, ptid)`
     - in add_thread_silent, the passed target (&the_procfs_target) is
       passed to find_inferior_ptid
     - find_inferior_ptid returns nullptr, as there is no inferior with this
       ptid that has &the_procfs_target as its process target
     - the nullptr `inf` is passed to find_thread_ptid, which dereferences
       it, causing a segfault
     - back in procfs_target::attach, after do_attach, we push the
       the_procfs_target on the inferior's target stack, although we never
       reach this because the segfault happens before.

    To fix this, I think we need to do the same as is done in
    inf_ptrace_target::attach: push the target early and unpush it in case
    the attach fails (and keep it if the attach succeeds).

    Implement it by moving target_unpush_up to target.h, so it can be
    re-used here.  Make procfs_target::attach use it.  Note that just like
    is mentioned in inf_ptrace_target::attach, we should push the target
    before calling target_pid_to_str, so that calling target_pid_to_str ends
    up in procfs_target::pid_to_str.

    Tested by trying to attach on a process on gcc211 on the gcc compile
    farm.

    gdb/ChangeLog:

            PR gdb/27435
            * inf-ptrace.c (struct target_unpusher): Move to target.h.
            (target_unpush_up): Likewise.
            * procfs.c (procfs_target::attach): Push target early.  Use
            target_unpush_up to unpush target in case of error.
            * target.h (struct target_unpusher): Move here.
            (target_unpush_up): Likewise.

    Change-Id: I88aff8b20204e1ca1d792e27ac6bc34fc1aa0d52

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  reply	other threads:[~2021-02-22 16:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18 16:12 [Bug gdb/27435] New: " simark at simark dot ca
2021-02-22 16:43 ` cvs-commit at gcc dot gnu.org [this message]
2021-02-22 16:47 ` [Bug gdb/27435] " cvs-commit at gcc dot gnu.org
2021-02-22 16:48 ` simark at simark dot ca
2021-06-27 18:01 ` ahmedsayeed1982 at yahoo dot com
2021-07-14  4:39 ` sherrixotyv29 at gmail dot com
2021-08-09  6:18 ` richardsfowle18 at gmail dot com
2021-08-09  9:36 ` phillipsaeverett84 at gmail dot com
2021-08-09  9:48 ` bemovod383 at hyprhost dot com
2021-09-02 11:06 ` donipah907 at mtlcz dot com
2021-09-02 11:13 ` mark at klomp dot org
2021-09-05  7:35 ` kimolsun2020 at yahoo dot com
2021-09-06  9:08 ` focixujo at livinginsurance dot co.uk
2021-09-06  9:13 ` focixujo at livinginsurance dot co.uk
2021-09-10 19:37 ` mehmetgelisin at aol dot com
2021-09-22 10:20 ` diheto5497 at secbuf dot com
2021-09-26 13:31 ` tes.vik1986 at gmail dot com
2021-10-09 11:00 ` gulsenenginar at aol dot com
2021-10-09 17:52 ` svitvitraga at gmail dot com
2021-10-18 12:53 ` ahkitchenremodel at gmail dot com
2021-10-18 19:58 ` ahmedsayeed1982 at hotmail dot com
2021-10-19  7:13 ` progonsaytu at gmail dot com
2021-10-24 10:01 ` glassmtech at ukr dot net
2021-11-15 20:15 ` treeremovalcl1 at gmail dot com
2021-11-22  6:47 ` gexed96894 at keagenan dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-27435-4717-zRNELaL4NY@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).