This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH 57/58] gdbserver: use unique_ptr for 'the_target'
- From: "Aktemur, Tankut Baris" <tankut dot baris dot aktemur at intel dot com>
- To: Christian Biesinger <cbiesinger at google dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Wed, 12 Feb 2020 08:32:10 +0000
- Subject: RE: [PATCH 57/58] gdbserver: use unique_ptr for 'the_target'
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=03qs2xOHLOPSWMipG+MV669rgRPch1EMuOsdVDxbihk=; b=agoJDFisnz/UTTXQu5pz5dCYX3hlYTMzuPJ51uvhE09n0HL9TD6b13w51ByDa3bZwqpt+qm6pgr0m2j64pBEdE5zFvS++/+fopHM1enpGHq1suOPnWCRWl1txYjXQd7v9ETIxSOxGe07SnKrNct5ZaaIWV4VQsDZKYDmVbJeIYmnohKPdlLSS51C+N1xUYfZ9BtDgDs0cBXxupRrvHKPX+LxcUSPgHyYSRnc18nEL+veyrzjONj/69p1CspMtTgfN166Mse2oxaAHjiQXOV6LuxNaZBht0rCYwEaZFkdDrwo1M83DdLmxDtLy335aQqc38iN1f/QU3yOKVgUTSI9xA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gZ3qzFGp8rnaeBnsDmMdE8sIq4BtNu1MrZ1kE49OkHc/OYk84cdLMQJu+FhRZp71eYocWkfvmkW7WV+FgyAymTTOJsRRCq+gGoVpaIWjpTa3jqCwb4ZJEkM/UkEpz37bOeo6eVW/IEhNeHL7EVHcheX2YmoUguShp//eX7nWsyl53PUoX1Pb7JSJ8kJqJATWLitM3VB3bzY/QvAD8lREqKYIF5BoSXqohUSfMkfdCxXKg4A/oSHmlsCTkCU+tgsGL5AqLZh6RzhMRAcjhZhFdxPDfYCoAurUr4ueaVpdFe+lc5XrW/u4kZiATRLKsIpCE8yvNyY11YN8faJ57RW8YQ==
- References: <cover.1581410932.git.tankut.baris.aktemur@intel.com> <a2565d928bd4596e95ed10d9191c85a4a67bb4e1.1581410935.git.tankut.baris.aktemur@intel.com> <CAPTJ0XFY-JTC0hy8hMWR4hD1wDjE2oohvZ1Gwyr2W+nz+JExtQ@mail.gmail.com>
On Tuesday, February 11, 2020 5:43 PM, Christian Biesinger wrote:
> On Tue, Feb 11, 2020 at 3:08 AM Tankut Baris Aktemur
> <tankut.baris.aktemur@intel.com> wrote:
> >
> > The target op vector is about to be replaced with a process_target
> > object. In the current state, the 'set_target_ops' function takes a
> > target op vector and creates a clone of it via XNEW and memcpy. As we
> > are now switching to using classes and polymorphism, this memcpy'ing
> > will no longer be possible. For proper memory managament, switch to
> > using a unique_ptr.
> >
> > gdbserver/ChangeLog:
> > 2020-02-10 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
> >
> > * target.h (set_target_ops): Remove.
> > (<the_target>): Change the type to
> > std::unique_ptr<process_stratum_target>.
> > * target.c (set_target_ops): Remove.
> > (done_accessing_memory): Update the usage of the_target.
> > * fork-child.c (post_fork_inferior): Update the usage of
> > the_target.
> > * remote-utils.c (prepare_resume_reply): Ditto.
> > * linux-low.c (initialize_low): Set the value of the_target.
> > (struct linux_target_ops): Delete.
> > * lynx-low.c (initialize_low): Set the value of the_target.
> > (struct lynx_target_ops): Delete.
> > * nto-low.c (initialize_low): Set the value of the_target.
> > (struct nto_target_ops): Delete.
> > * win32-low.c (initialize_low): Set the value of the_target.
> > (struct win32_target_ops): Delete.
> > ---
> > gdbserver/fork-child.c | 2 +-
> > gdbserver/linux-low.c | 7 ++-----
> > gdbserver/lynx-low.c | 9 ++-------
> > gdbserver/nto-low.c | 8 ++------
> > gdbserver/remote-utils.c | 2 +-
> > gdbserver/target.c | 11 ++---------
> > gdbserver/target.h | 4 +---
> > gdbserver/win32-low.c | 7 ++-----
> > 8 files changed, 13 insertions(+), 37 deletions(-)
> >
> > diff --git a/gdbserver/fork-child.c b/gdbserver/fork-child.c
> > index 7a71ec0b1ca..3702c1a8c2e 100644
> > --- a/gdbserver/fork-child.c
> > +++ b/gdbserver/fork-child.c
> > @@ -107,7 +107,7 @@ post_fork_inferior (int pid, const char *program)
> > atexit (restore_old_foreground_pgrp);
> > #endif
> >
> > - startup_inferior (the_target, pid,
> > + startup_inferior (the_target.get (), pid,
> > START_INFERIOR_TRAPS_EXPECTED,
> > &cs.last_status, &cs.last_ptid);
> > current_thread->last_resume_kind = resume_stop;
> > diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
> > index cd84cef326a..87cf2fd8afb 100644
> > --- a/gdbserver/linux-low.c
> > +++ b/gdbserver/linux-low.c
> > @@ -7512,10 +7512,6 @@ linux_get_hwcap2 (int wordsize)
> >
> > static linux_process_target the_linux_target;
> >
> > -static process_stratum_target linux_target_ops = {
> > - &the_linux_target,
> > -};
> > -
> > #ifdef HAVE_LINUX_REGSETS
> > void
> > initialize_regsets_info (struct regsets_info *info)
> > @@ -7533,7 +7529,8 @@ initialize_low (void)
> > struct sigaction sigchld_action;
> >
> > memset (&sigchld_action, 0, sizeof (sigchld_action));
> > - set_target_ops (&linux_target_ops);
> > + the_target.reset (new process_stratum_target);
> > + the_target->pt = &the_linux_target;
>
> Should this now be a constructor argument?
Yes, this would make it better; however, to be frank, I did not care too
much because the next patch in the series (PATCH 58/58) deletes the
process_target class and the 'pt' field, making the following change:
- the_target.reset (new process_stratum_target);
- the_target->pt = &the_linux_target;
+ the_target.reset (new linux_process_target);
So the code above is temporary -- if I introduce a constructor here, it
would have to be deleted/modified in the next patch. Given this, is it OK
to leave this patch as it is?
An alternative is to squash PATCH 57 and 58, but 58 is already the longest
patch in the series.
-Baris
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928