public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 2/3] gdb: remove push_target free functions
Date: Mon, 22 Mar 2021 16:30:50 +0000	[thread overview]
Message-ID: <SN6PR11MB28933E672FAEECAC7D2006FBC4659@SN6PR11MB2893.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20210322032027.3397705-2-simon.marchi@polymtl.ca>

On Monday, March 22, 2021 4:20 AM, Simon Marchi wrote:
> Same as the previous patch, but for the push_target functions.
> 
> The implementation of the move variant is moved to a new overload of
> inferior::push_target.
> 
> gdb/ChangeLog:
> 
> 	* target.h (push_target): Remove, update callers to use
> 	inferior::push_target.
> 	* target.c (push_target): Remove.
> 	* inferior.h (class inferior) <push_target>: New overload.
> 
> Change-Id: I5a95496666278b8f3965e5e8aecb76f54a97c185
> ---
>  gdb/aix-thread.c          |  2 +-
>  gdb/bsd-kvm.c             |  2 +-
>  gdb/bsd-uthread.c         |  2 +-
>  gdb/corelow.c             |  2 +-
>  gdb/darwin-nat.c          |  2 +-
>  gdb/exec.c                |  4 ++--
>  gdb/gnu-nat.c             |  6 +++---
>  gdb/go32-nat.c            |  2 +-
>  gdb/inf-child.c           |  2 +-
>  gdb/inf-ptrace.c          |  7 ++++---
>  gdb/inferior.c            |  2 +-
>  gdb/inferior.h            |  7 +++++++
>  gdb/infrun.c              |  6 +++---
>  gdb/linux-thread-db.c     |  2 +-
>  gdb/nto-procfs.c          |  4 ++--
>  gdb/procfs.c              |  4 ++--
>  gdb/ravenscar-thread.c    |  2 +-
>  gdb/record-btrace.c       |  2 +-
>  gdb/record-full.c         |  4 ++--
>  gdb/regcache.c            |  2 +-
>  gdb/remote-sim.c          |  2 +-
>  gdb/remote.c              |  4 ++--
>  gdb/scoped-mock-context.h |  2 +-
>  gdb/sol-thread.c          |  2 +-
>  gdb/target.c              | 19 +------------------
>  gdb/target.h              |  5 -----
>  gdb/tracectf.c            |  2 +-
>  gdb/tracefile-tfile.c     |  2 +-
>  gdb/windows-nat.c         |  4 ++--
>  29 files changed, 47 insertions(+), 61 deletions(-)
> 
> diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
> index a479d0150bc2..fc34210cf9e2 100644
> --- a/gdb/aix-thread.c
> +++ b/gdb/aix-thread.c
> @@ -974,7 +974,7 @@ pd_enable (void)
>      return;
> 
>    /* Prepare for thread debugging.  */
> -  push_target (&aix_thread_ops);
> +  current_inferior ()->push_target (&aix_thread_ops);
>    pd_able = 1;
> 
>    /* If we're debugging a core file or an attached inferior, the
> diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c
> index 17db2fe1cd60..89da40afcb78 100644
> --- a/gdb/bsd-kvm.c
> +++ b/gdb/bsd-kvm.c
> @@ -134,7 +134,7 @@ bsd_kvm_target_open (const char *arg, int from_tty)
>    bsd_kvm_corefile = filename;
>    current_inferior ()->unpush_target (&bsd_kvm_ops);
>    core_kd = temp_kd;
> -  push_target (&bsd_kvm_ops);
> +  current_inferior ()->push_target (&bsd_kvm_ops);
> 
>    thread_info *thr = add_thread_silent (&bsd_kvm_ops, bsd_kvm_ptid);
>    switch_to_thread (thr);
> diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
> index 2ee47bfb5c47..3cb8f64c89a7 100644
> --- a/gdb/bsd-uthread.c
> +++ b/gdb/bsd-uthread.c
> @@ -231,7 +231,7 @@ bsd_uthread_activate (struct objfile *objfile)
>    bsd_uthread_thread_ctx_offset =
>      bsd_uthread_lookup_offset ("_thread_ctx_offset", objfile);
> 
> -  push_target (&bsd_uthread_ops);
> +  current_inferior ()->push_target (&bsd_uthread_ops);
>    bsd_uthread_active = 1;
>    return 1;
>  }
> diff --git a/gdb/corelow.c b/gdb/corelow.c
> index a4c1f6354c6e..a1943ab2ea6d 100644
> --- a/gdb/corelow.c
> +++ b/gdb/corelow.c
> @@ -458,7 +458,7 @@ core_target_open (const char *arg, int from_tty)
>    if (!current_program_space->exec_bfd ())
>      set_gdbarch_from_file (core_bfd);
> 
> -  push_target (std::move (target_holder));
> +  current_inferior ()->push_target (std::move (target_holder));
> 
>    switch_to_no_thread ();
> 
> diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
> index ca95d7b6d385..f8e4443ff408 100644
> --- a/gdb/darwin-nat.c
> +++ b/gdb/darwin-nat.c
> @@ -1659,7 +1659,7 @@ darwin_attach_pid (struct inferior *inf)
> 
>    target_ops *darwin_ops = get_native_target ();
>    if (!target_is_pushed (darwin_ops))
> -    push_target (darwin_ops);
> +    inf->push_target (darwin_ops);
>  }
> 
>  /* Get the thread_info object corresponding to this darwin_thread_info.  */
> diff --git a/gdb/exec.c b/gdb/exec.c
> index bcc54bd966fe..b737bcf6e0f3 100644
> --- a/gdb/exec.c
> +++ b/gdb/exec.c
> @@ -616,7 +616,7 @@ program_space::add_target_sections (void *owner,
>  	    continue;
> 
>  	  switch_to_inferior_no_thread (inf);
> -	  push_target (&exec_ops);
> +	  inf->push_target (&exec_ops);

Similar to the previous patch, it should be OK to also remove the 
switch_to_inferior_no_thread here.

>  	}
>      }
>  }
> @@ -682,7 +682,7 @@ void
>  exec_on_vfork ()
>  {
>    if (!current_program_space->target_sections ().empty ())
> -    push_target (&exec_ops);
> +    current_inferior ()->push_target (&exec_ops);
>  }
> 
> 
> 
> 
> diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
> index 409d141909b3..9ea4c4089340 100644
> --- a/gdb/gnu-nat.c
> +++ b/gdb/gnu-nat.c
> @@ -2114,7 +2114,7 @@ gnu_nat_target::create_inferior (const char *exec_file,
>    inf_debug (inf, "creating inferior");
> 
>    if (!target_is_pushed (this))
> -    push_target (this);
> +    current_inferior ()->push_target (this);
> 
>    pid = fork_inferior (exec_file, allargs, env, gnu_ptrace_me,
>  		       NULL, NULL, NULL, NULL);
> @@ -2190,9 +2190,9 @@ gnu_nat_target::attach (const char *args, int from_tty)
> 
>    inf_attach (inf, pid);
> 
> -  push_target (this);
> -
>    inferior = current_inferior ();
> +  inferior->push_target (this);
> +
>    inferior_appeared (inferior, pid);
>    inferior->attach_flag = 1;
> 
> diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c
> index b18a62e9490d..79c31fcd9877 100644
> --- a/gdb/go32-nat.c
> +++ b/gdb/go32-nat.c
> @@ -757,7 +757,7 @@ go32_nat_target::create_inferior (const char *exec_file,
>    inferior_appeared (inf, SOME_PID);
> 
>    if (!target_is_pushed (this))
> -    push_target (this);
> +    inf->push_target (this);
> 
>    thread_info *thr = add_thread_silent (ptid_t (SOME_PID));
>    switch_to_thread (thr);
> diff --git a/gdb/inf-child.c b/gdb/inf-child.c
> index b8bc2e2598e6..0e68a40d7c04 100644
> --- a/gdb/inf-child.c
> +++ b/gdb/inf-child.c
> @@ -166,7 +166,7 @@ inf_child_open_target (const char *arg, int from_tty)
>    gdb_assert (dynamic_cast<inf_child_target *> (target) != NULL);
> 
>    target_preopen (from_tty);
> -  push_target (target);
> +  current_inferior ()->push_target (target);
>    inf_child_explicitly_opened = 1;
>    if (from_tty)
>      printf_filtered ("Done.  Use the \"run\" command to start a process.\n");
> diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
> index 7ca02dfd8764..e630ba447f40 100644
> --- a/gdb/inf-ptrace.c
> +++ b/gdb/inf-ptrace.c
> @@ -82,7 +82,7 @@ inf_ptrace_target::create_inferior (const char *exec_file,
>    if (! ops_already_pushed)
>      {
>        /* Clear possible core file with its process_stratum.  */
> -      push_target (this);
> +      current_inferior ()->push_target (this);
>        unpusher.reset (this);
>      }
> 
> @@ -139,12 +139,14 @@ inf_ptrace_target::attach (const char *args, int from_tty)
>    if (pid == getpid ())		/* Trying to masturbate?  */
>      error (_("I refuse to debug myself!"));
> 
> +  inf = current_inferior ();
> +
>    target_unpush_up unpusher;
>    if (! ops_already_pushed)
>      {
>        /* target_pid_to_str already uses the target.  Also clear possible core
>  	 file with its process_stratum.  */
> -      push_target (this);
> +      inf->push_target (this);
>        unpusher.reset (this);
>      }
> 
> @@ -169,7 +171,6 @@ inf_ptrace_target::attach (const char *args, int from_tty)
>    error (_("This system does not support attaching to a process"));
>  #endif
> 
> -  inf = current_inferior ();
>    inferior_appeared (inf, pid);
>    inf->attach_flag = 1;
> 
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index 49f869a4c783..69baee34ce9d 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -771,7 +771,7 @@ switch_to_inferior_and_push_target (inferior *new_inf,
>    /* Reuse the target for new inferior.  */
>    if (!no_connection && proc_target != NULL)
>      {
> -      push_target (proc_target);
> +      new_inf->push_target (proc_target);
>        if (proc_target->connection_string () != NULL)
>  	printf_filtered (_("Added inferior %d on connection %d (%s %s)\n"),
>  			 new_inf->num,
> diff --git a/gdb/inferior.h b/gdb/inferior.h
> index b8d5ff94fc56..66fc180ce530 100644
> --- a/gdb/inferior.h
> +++ b/gdb/inferior.h
> @@ -352,6 +352,13 @@ class inferior : public refcounted_object
>    void push_target (struct target_ops *t)
>    { m_target_stack.push (t); }
> 
> +  /* An overload that deletes the target on failure.  */
> +  void push_target (target_ops_up &&t)
> +  {
> +    m_target_stack.push (t.get ());
> +    t.release ();
> +  }
> +
>    /* Unpush T from this inferior's target stack.  */
>    int unpush_target (struct target_ops *t)
>    { return m_target_stack.unpush (t); }
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 3b65a6de9fe2..50340e6edad4 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -477,7 +477,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
>  	  set_current_inferior (child_inf);
>  	  switch_to_no_thread ();
>  	  child_inf->symfile_flags = SYMFILE_NO_READ;
> -	  push_target (parent_inf->process_target ());
> +	  child_inf->push_target (parent_inf->process_target ());
>  	  thread_info *child_thr
>  	    = add_thread_silent (child_inf->process_target (), child_ptid);
> 
> @@ -627,7 +627,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
>  	   informing the solib layer about this new process.  */
> 
>  	set_current_inferior (child_inf);
> -	push_target (target);
> +	child_inf->push_target (target);
>        }
> 
>        thread_info *child_thr = add_thread_silent (target, child_ptid);
> @@ -1183,7 +1183,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
> 
>        inferior *org_inferior = current_inferior ();
>        switch_to_inferior_no_thread (inf);

And here.

Thanks.
-Baris



Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  reply	other threads:[~2021-03-22 16:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22  3:20 [PATCH 1/3] gdb: remove unpush_target free function Simon Marchi
2021-03-22  3:20 ` [PATCH 2/3] gdb: remove push_target free functions Simon Marchi
2021-03-22 16:30   ` Aktemur, Tankut Baris [this message]
2021-03-22 17:31     ` Simon Marchi
2021-03-22 18:21       ` Simon Marchi
2021-03-23 10:25         ` Aktemur, Tankut Baris
2021-03-23 13:50         ` Simon Marchi
2021-03-22  3:20 ` [PATCH 3/3] gdb: remove target_is_pushed free function Simon Marchi
2021-03-22 16:22 ` [PATCH 1/3] gdb: remove unpush_target " Aktemur, Tankut Baris
2021-03-22 17:25   ` Simon Marchi
2021-03-22 18:11     ` Simon Marchi

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=SN6PR11MB28933E672FAEECAC7D2006FBC4659@SN6PR11MB2893.namprd11.prod.outlook.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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).