From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 04/40] target_ops/C++: core target
Date: Sat, 14 Apr 2018 19:18:00 -0000 [thread overview]
Message-ID: <20180414190953.24481-5-palves@redhat.com> (raw)
In-Reply-To: <20180414190953.24481-1-palves@redhat.com>
Straighforward conversion.
The core_target global is renamed to avoid conflict with the
"core_target" class.
---
gdb/corefile.c | 12 ++--
gdb/corelow.c | 202 ++++++++++++++++++++++++++++-----------------------------
gdb/gdbcore.h | 4 +-
3 files changed, 105 insertions(+), 113 deletions(-)
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 5a735264ef..c849a10646 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -53,9 +53,6 @@ static int exec_file_hook_count = 0; /* Size of array. */
bfd *core_bfd = NULL;
-/* corelow.c target. It is never NULL after GDB initialization. */
-
-struct target_ops *core_target;
\f
/* Backward compatability with old way of specifying core files. */
@@ -65,12 +62,12 @@ core_file_command (const char *filename, int from_tty)
{
dont_repeat (); /* Either way, seems bogus. */
- gdb_assert (core_target != NULL);
+ gdb_assert (the_core_target != NULL);
if (!filename)
- (core_target->to_detach) (core_target, current_inferior (), from_tty);
+ the_core_target->detach (current_inferior (), from_tty);
else
- (core_target->to_open) (filename, from_tty);
+ the_core_target->open (filename, from_tty);
}
\f
@@ -237,8 +234,7 @@ read_memory_object (enum target_object object, CORE_ADDR memaddr,
enum target_xfer_status status;
ULONGEST xfered_len;
- status = target_xfer_partial (current_target.beneath,
- object, NULL,
+ status = target_xfer_partial (target_stack, object, NULL,
myaddr + xfered, NULL,
memaddr + xfered, len - xfered,
&xfered_len);
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 190f0162d9..f7202f75e3 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -50,6 +50,55 @@
#define O_LARGEFILE 0
#endif
+/* The core file target. */
+
+class core_target final : public target_ops
+{
+public:
+ core_target ()
+ { to_stratum = process_stratum; }
+
+ const char *shortname () override
+ { return "core"; }
+
+ const char *longname () override
+ { return _("Local core dump file"); }
+
+ const char *doc () override
+ {
+ return _("\
+Use a core file as a target. Specify the filename of the core file.");
+ }
+
+ void open (const char *, int) override;
+ void close () override;
+ void detach (inferior *, int) override;
+ void fetch_registers (struct regcache *, int) override;
+
+ enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+ void files_info () override;
+
+ int thread_alive (ptid_t ptid) override;
+ const struct target_desc *read_description () override;
+
+ const char *pid_to_str (ptid_t) override;
+
+ const char *thread_name (struct thread_info *) override;
+
+ int has_memory () override;
+ int has_stack () override;
+ int has_registers () override;
+ bool info_proc (const char *, enum info_proc_what) override;
+};
+
+/* See gdbcore.h. */
+struct target_ops *the_core_target;
+
/* List of all available core_fns. On gdb startup, each core file
register reader calls deprecated_add_core_fns() to register
information on each core format it is prepared to read. */
@@ -74,21 +123,15 @@ static struct gdbarch *core_gdbarch = NULL;
unix child targets. */
static struct target_section_table *core_data;
-static void core_files_info (struct target_ops *);
-
static struct core_fns *sniff_core_bfd (bfd *);
static int gdb_check_format (bfd *);
-static void core_close (struct target_ops *self);
-
static void core_close_cleanup (void *ignore);
static void add_to_thread_list (bfd *, asection *, void *);
-static void init_core_ops (void);
-
-static struct target_ops core_ops;
+static core_target core_ops;
/* An arbitrary identifier for the core inferior. */
#define CORELOW_PID 1
@@ -185,7 +228,7 @@ gdb_check_format (bfd *abfd)
stack spaces as empty. */
static void
-core_close (struct target_ops *self)
+core_close ()
{
if (core_bfd)
{
@@ -216,7 +259,13 @@ core_close (struct target_ops *self)
static void
core_close_cleanup (void *ignore)
{
- core_close (NULL);
+ core_close ();
+}
+
+void
+core_target::close ()
+{
+ core_close ();
}
/* Look for sections whose names start with `.reg/' so that we can
@@ -266,8 +315,8 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
/* This routine opens and sets up the core file bfd. */
-static void
-core_open (const char *arg, int from_tty)
+void
+core_target::open (const char *arg, int from_tty)
{
const char *p;
int siggy;
@@ -463,10 +512,10 @@ core_open (const char *arg, int from_tty)
}
}
-static void
-core_detach (struct target_ops *ops, inferior *inf, int from_tty)
+void
+core_target::detach (inferior *inf, int from_tty)
{
- unpush_target (ops);
+ unpush_target (this);
reinit_frame_cache ();
if (from_tty)
printf_filtered (_("No core file now.\n"));
@@ -585,9 +634,8 @@ get_core_registers_cb (const char *sect_name, int size,
/* We just get all the registers, so we don't use regno. */
-static void
-get_core_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+void
+core_target::fetch_registers (struct regcache *regcache, int regno)
{
int i;
struct gdbarch *gdbarch;
@@ -619,8 +667,8 @@ get_core_registers (struct target_ops *ops,
regcache_raw_supply (regcache, i, NULL);
}
-static void
-core_files_info (struct target_ops *t)
+void
+core_target::files_info ()
{
print_section_info (core_data, core_bfd);
}
@@ -655,11 +703,10 @@ add_to_spuid_list (bfd *abfd, asection *asect, void *list_p)
list->pos += 4;
}
-static enum target_xfer_status
-core_xfer_partial (struct target_ops *ops, enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset,
- ULONGEST len, ULONGEST *xfered_len)
+enum target_xfer_status
+core_target::xfer_partial (enum target_object object, const char *annex,
+ gdb_byte *readbuf, const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
switch (object)
{
@@ -861,35 +908,13 @@ core_xfer_partial (struct target_ops *ops, enum target_object object,
return TARGET_XFER_E_IO;
default:
- return ops->beneath->to_xfer_partial (ops->beneath, object,
- annex, readbuf,
- writebuf, offset, len,
- xfered_len);
+ return this->beneath->xfer_partial (object, annex, readbuf,
+ writebuf, offset, len,
+ xfered_len);
}
}
\f
-/* If mourn is being called in all the right places, this could be say
- `gdb internal error' (since generic_mourn calls
- breakpoint_init_inferior). */
-
-static int
-ignore (struct target_ops *ops, struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt)
-{
- return 0;
-}
-
-/* Implement the to_remove_breakpoint method. */
-
-static int
-core_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
- struct bp_target_info *bp_tgt,
- enum remove_bp_reason reason)
-{
- return 0;
-}
-
/* Okay, let's be honest: threads gleaned from a core file aren't
exactly lively, are they? On the other hand, if we don't claim
@@ -897,8 +922,8 @@ core_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
to appear in an "info thread" command, which is quite a useful
behaviour.
*/
-static int
-core_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+core_target::thread_alive (ptid_t ptid)
{
return 1;
}
@@ -908,24 +933,23 @@ core_thread_alive (struct target_ops *ops, ptid_t ptid)
wrapper could be avoided if targets got a chance to specialize
core_ops. */
-static const struct target_desc *
-core_read_description (struct target_ops *target)
+const struct target_desc *
+core_target::read_description ()
{
if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch))
{
const struct target_desc *result;
- result = gdbarch_core_read_description (core_gdbarch,
- target, core_bfd);
+ result = gdbarch_core_read_description (core_gdbarch, this, core_bfd);
if (result != NULL)
return result;
}
- return target->beneath->to_read_description (target->beneath);
+ return this->beneath->read_description ();
}
-static const char *
-core_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+core_target::pid_to_str (ptid_t ptid)
{
static char buf[64];
struct inferior *inf;
@@ -956,8 +980,8 @@ core_pid_to_str (struct target_ops *ops, ptid_t ptid)
return buf;
}
-static const char *
-core_thread_name (struct target_ops *self, struct thread_info *thr)
+const char *
+core_target::thread_name (struct thread_info *thr)
{
if (core_gdbarch
&& gdbarch_core_thread_name_p (core_gdbarch))
@@ -965,29 +989,28 @@ core_thread_name (struct target_ops *self, struct thread_info *thr)
return NULL;
}
-static int
-core_has_memory (struct target_ops *ops)
+int
+core_target::has_memory ()
{
return (core_bfd != NULL);
}
-static int
-core_has_stack (struct target_ops *ops)
+int
+core_target::has_stack ()
{
return (core_bfd != NULL);
}
-static int
-core_has_registers (struct target_ops *ops)
+int
+core_target::has_registers ()
{
return (core_bfd != NULL);
}
/* Implement the to_info_proc method. */
-static void
-core_info_proc (struct target_ops *ops, const char *args,
- enum info_proc_what request)
+bool
+core_target::info_proc (const char *args, enum info_proc_what request)
{
struct gdbarch *gdbarch = get_current_arch ();
@@ -995,47 +1018,18 @@ core_info_proc (struct target_ops *ops, const char *args,
method on gdbarch, not 'info_proc'. */
if (gdbarch_core_info_proc_p (gdbarch))
gdbarch_core_info_proc (gdbarch, args, request);
-}
-
-/* Fill in core_ops with its defined operations and properties. */
-static void
-init_core_ops (void)
-{
- core_ops.to_shortname = "core";
- core_ops.to_longname = "Local core dump file";
- core_ops.to_doc =
- "Use a core file as a target. Specify the filename of the core file.";
- core_ops.to_open = core_open;
- core_ops.to_close = core_close;
- core_ops.to_detach = core_detach;
- core_ops.to_fetch_registers = get_core_registers;
- core_ops.to_xfer_partial = core_xfer_partial;
- core_ops.to_files_info = core_files_info;
- core_ops.to_insert_breakpoint = ignore;
- core_ops.to_remove_breakpoint = core_remove_breakpoint;
- core_ops.to_thread_alive = core_thread_alive;
- core_ops.to_read_description = core_read_description;
- core_ops.to_pid_to_str = core_pid_to_str;
- core_ops.to_thread_name = core_thread_name;
- core_ops.to_stratum = process_stratum;
- core_ops.to_has_memory = core_has_memory;
- core_ops.to_has_stack = core_has_stack;
- core_ops.to_has_registers = core_has_registers;
- core_ops.to_info_proc = core_info_proc;
- core_ops.to_magic = OPS_MAGIC;
-
- if (core_target)
- internal_error (__FILE__, __LINE__,
- _("init_core_ops: core target already exists (\"%s\")."),
- core_target->to_longname);
- core_target = &core_ops;
+ return true;
}
void
_initialize_corelow (void)
{
- init_core_ops ();
+ if (the_core_target != NULL)
+ internal_error (__FILE__, __LINE__,
+ _("core target already exists (\"%s\")."),
+ the_core_target->longname ());
+ the_core_target = &core_ops;
add_target_with_completer (&core_ops, filename_completer);
}
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 5264eef4ee..04a235dd90 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -135,7 +135,9 @@ extern void specify_exec_file_hook (void (*hook) (const char *filename));
extern bfd *core_bfd;
-extern struct target_ops *core_target;
+/* corelow.c target. It is never NULL after GDB initialization. */
+
+extern struct target_ops *the_core_target;
/* Whether to open exec and core files read-only or read-write. */
--
2.14.3
next prev parent reply other threads:[~2018-04-14 19:18 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-14 19:09 [PATCH 00/40] C++ify target_ops, toward multi-target Pedro Alves
2018-04-14 19:10 ` [PATCH 09/40] target_ops/C++: bfd-target Pedro Alves
2018-04-14 19:10 ` [PATCH 23/40] target_ops/C++: IA-64 GNU/Linux Pedro Alves
2018-04-14 19:10 ` [PATCH 34/40] target_ops/C++: bsd_kvm_add_target, BSD libkvm target Pedro Alves
2018-04-14 19:10 ` [PATCH 20/40] target_ops/C++: ARM GNU/Linux Pedro Alves
2018-04-14 19:10 ` [PATCH 39/40] linux_nat_target: More low methods Pedro Alves
2018-04-18 0:40 ` John Baldwin
2018-04-14 19:10 ` [PATCH 37/40] target_ops/C++: The Hurd Pedro Alves
2018-04-14 19:10 ` [PATCH 40/40] target factories, target open and multiple instances of targets Pedro Alves
2018-04-14 19:10 ` [PATCH 19/40] target_ops/C++: AIX target Pedro Alves
2018-04-14 19:10 ` [PATCH 08/40] target_ops/C++: bsd-uthread Pedro Alves
2018-04-14 19:10 ` [PATCH 27/40] target_ops/C++: SPARC GNU/Linux Pedro Alves
2018-04-14 19:10 ` [PATCH 32/40] target_ops/C++: Generic i386/AMD64 BSD targets Pedro Alves
2018-04-14 19:10 ` [PATCH 29/40] target_ops/C++: Tile-Gx GNU/Linux Pedro Alves
2018-04-14 19:10 ` [PATCH 38/40] target_ops: Use bool throughout Pedro Alves
2018-04-14 19:10 ` [PATCH 07/40] target_ops/C++: ravenscar-thread Pedro Alves
2018-04-14 19:10 ` [PATCH 03/40] target_ops/C++: exec target Pedro Alves
2018-04-14 19:10 ` [PATCH 02/40] make-target-delegates: line break between return type and function name Pedro Alves
2018-04-14 19:10 ` [PATCH 17/40] target_ops/C++: macOS/Darwin target Pedro Alves
2018-04-14 19:15 ` [PATCH 22/40] target_ops/C++: HP-PA GNU/Linux Pedro Alves
2018-04-14 19:15 ` [PATCH 12/40] target_ops/C++: target remote-sim Pedro Alves
2018-04-14 19:15 ` [PATCH 14/40] target_ops/C++: PPC/PPC64 GNU/Linux Pedro Alves
2018-04-14 19:18 ` [PATCH 24/40] target_ops/C++: m32r GNU/Linux Pedro Alves
2018-04-14 19:18 ` [PATCH 25/40] target_ops/C++: m68k GNU/Linux Pedro Alves
2018-04-14 19:18 ` Pedro Alves [this message]
2018-04-14 19:18 ` [PATCH 36/40] target_ops/C++: go32/DJGPP Pedro Alves
2018-04-14 19:19 ` [PATCH 16/40] target_ops/C++: Windows targets Pedro Alves
2018-04-14 19:19 ` [PATCH 35/40] target_ops/C++: NTO/QNX, nto-procfs.c Pedro Alves
2018-04-14 19:19 ` [PATCH 30/40] target_ops/C++: Xtensa GNU/Linux Pedro Alves
2018-04-14 19:19 ` [PATCH 26/40] target_ops/C++: s390 GNU/Linux Pedro Alves
2018-04-14 19:19 ` [PATCH 15/40] target_ops/C++: Solaris/procfs Pedro Alves
2018-04-14 19:19 ` [PATCH 31/40] target_ops/C++: Base FreeBSD target Pedro Alves
2018-04-17 16:12 ` John Baldwin
2018-04-17 17:07 ` Pedro Alves
2018-04-17 17:28 ` Kamil Rytarowski
2018-04-17 18:13 ` Pedro Alves
2018-04-17 18:50 ` Kamil Rytarowski
2018-04-18 0:40 ` John Baldwin
2018-04-18 1:51 ` Kamil Rytarowski
2018-04-18 11:23 ` Pedro Alves
2018-04-18 11:21 ` Pedro Alves
2018-04-18 14:20 ` Pedro Alves
2018-04-18 20:55 ` John Baldwin
2018-04-14 19:19 ` [PATCH 05/40] target_ops/C++: ctf/tfile targets Pedro Alves
2018-04-14 19:20 ` [PATCH 06/40] target_ops/C++: spu-multiarch Pedro Alves
2018-04-14 19:20 ` [PATCH 33/40] target_ops/C++: The rest of the BSD targets Pedro Alves
2018-04-14 19:20 ` [PATCH 10/40] target_ops/C++: record targets Pedro Alves
2018-04-14 19:20 ` [PATCH 11/40] target_ops/C++: remote/extended-remote targets Pedro Alves
2018-04-14 19:28 ` [PATCH 21/40] target_ops/C++: Aarch64 GNU/Linux Pedro Alves
2018-04-14 19:28 ` [PATCH 28/40] target_ops/C++: SPU/Linux Pedro Alves
2018-05-04 17:09 ` Ulrich Weigand
2018-05-04 17:15 ` Pedro Alves
2018-05-04 17:22 ` Ulrich Weigand
2018-05-04 17:27 ` Pedro Alves
2018-04-14 19:29 ` [PATCH 13/40] target_ops/C++: GNU/Linux + x86/AMD64 Pedro Alves
2018-04-14 19:30 ` [PATCH 18/40] target_ops/C++: linux_trad_target, MIPS and Alpha GNU/Linux Pedro Alves
2018-04-16 15:15 ` [RESEND][PATCH 01/40] Convert struct target_ops to C++ Pedro Alves
2018-05-03 0:06 ` Pedro Alves
2018-10-27 21:58 ` 8.2 regression for invalid -data-directory [Re: [RESEND][PATCH 01/40] Convert struct target_ops to C++] Jan Kratochvil
2018-10-30 20:24 ` Tom Tromey
2019-02-14 15:30 ` [RESEND][PATCH 01/40] Convert struct target_ops to C++ Thomas Schwinge
2018-04-27 15:47 ` [PATCH 00/40] C++ify target_ops, toward multi-target Tom Tromey
2018-05-02 22:55 ` Pedro Alves
2018-04-29 15:22 ` Simon Marchi
2018-05-02 22:51 ` Pedro Alves
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=20180414190953.24481-5-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@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).