From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 17/40] target_ops/C++: macOS/Darwin target
Date: Sat, 14 Apr 2018 19:10:00 -0000 [thread overview]
Message-ID: <20180414190953.24481-18-palves@redhat.com> (raw)
In-Reply-To: <20180414190953.24481-1-palves@redhat.com>
Straighforward conversion. I'd checked that this builds with a cross
compiler.
---
gdb/darwin-nat.c | 142 +++++++++++++++-----------------------------------
gdb/darwin-nat.h | 46 ++++++++++++++--
gdb/i386-darwin-nat.c | 28 ++++++----
3 files changed, 99 insertions(+), 117 deletions(-)
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index e98ac6c548..919643145a 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -83,36 +83,12 @@
#define PTRACE(CMD, PID, ADDR, SIG) \
darwin_ptrace(#CMD, CMD, (PID), (ADDR), (SIG))
-static void darwin_interrupt (struct target_ops *self);
-
-static void darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step,
- enum gdb_signal signal);
-static void darwin_resume (ptid_t ptid, int step,
- enum gdb_signal signal);
-
-static ptid_t darwin_wait_to (struct target_ops *ops, ptid_t ptid,
- struct target_waitstatus *status, int options);
static ptid_t darwin_wait (ptid_t ptid, struct target_waitstatus *status);
-static void darwin_mourn_inferior (struct target_ops *ops);
-
-static void darwin_kill_inferior (struct target_ops *ops);
-
static void darwin_ptrace_me (void);
static void darwin_ptrace_him (int pid);
-static void darwin_create_inferior (struct target_ops *ops,
- const char *exec_file,
- const std::string &allargs,
- char **env, int from_tty);
-
-static void darwin_files_info (struct target_ops *ops);
-
-static const char *darwin_pid_to_str (struct target_ops *ops, ptid_t tpid);
-
-static int darwin_thread_alive (struct target_ops *ops, ptid_t tpid);
-
static void darwin_encode_reply (mig_reply_error_t *reply,
mach_msg_header_t *hdr, integer_t code);
@@ -942,8 +918,8 @@ darwin_suspend_inferior_threads (struct inferior *inf)
}
}
-static void
-darwin_resume (ptid_t ptid, int step, enum gdb_signal signal)
+void
+darwin_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
{
struct target_waitstatus status;
int pid;
@@ -1007,13 +983,6 @@ darwin_resume (ptid_t ptid, int step, enum gdb_signal signal)
}
}
-static void
-darwin_resume_to (struct target_ops *ops, ptid_t ptid, int step,
- enum gdb_signal signal)
-{
- return darwin_resume (ptid, step, signal);
-}
-
static ptid_t
darwin_decode_message (mach_msg_header_t *hdr,
darwin_thread_t **pthread,
@@ -1334,22 +1303,22 @@ darwin_wait (ptid_t ptid, struct target_waitstatus *status)
return res;
}
-static ptid_t
-darwin_wait_to (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status, int options)
+ptid_t
+darwin_nat_target::wait (ptid_t ptid, struct target_waitstatus *status,
+ int options)
{
return darwin_wait (ptid, status);
}
-static void
-darwin_interrupt (struct target_ops *self)
+void
+darwin_nat_target::interrupt ()
{
struct inferior *inf = current_inferior ();
darwin_inferior *priv = get_darwin_inferior (inf);
/* FIXME: handle in no_ptrace mode. */
gdb_assert (!priv->no_ptrace);
- kill (inf->pid, SIGINT);
+ ::kill (inf->pid, SIGINT);
}
/* Deallocate threads port and vector. */
@@ -1368,8 +1337,8 @@ darwin_deallocate_threads (struct inferior *inf)
priv->threads.clear ();
}
-static void
-darwin_mourn_inferior (struct target_ops *ops)
+void
+darwin_nat_target::mourn_inferior ()
{
struct inferior *inf = current_inferior ();
darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1414,7 +1383,7 @@ darwin_mourn_inferior (struct target_ops *ops)
inf->priv = NULL;
- inf_child_mourn_inferior (ops);
+ inf_child_target::mourn_inferior ();
}
static void
@@ -1538,8 +1507,8 @@ darwin_setup_exceptions (struct inferior *inf)
kret);
}
-static void
-darwin_kill_inferior (struct target_ops *ops)
+void
+darwin_nat_target::kill ()
{
struct inferior *inf = current_inferior ();
darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1559,7 +1528,7 @@ darwin_kill_inferior (struct target_ops *ops)
darwin_reply_to_all_pending_messages (inf);
- res = kill (inf->pid, 9);
+ res = ::kill (inf->pid, 9);
if (res == 0)
{
@@ -1835,11 +1804,10 @@ darwin_execvp (const char *file, char * const argv[], char * const env[])
posix_spawnp (NULL, argv[0], NULL, &attr, argv, env);
}
-static void
-darwin_create_inferior (struct target_ops *ops,
- const char *exec_file,
- const std::string &allargs,
- char **env, int from_tty)
+void
+darwin_nat_target::create_inferior (const char *exec_file,
+ const std::string &allargs,
+ char **env, int from_tty)
{
/* Do the hard work. */
fork_inferior (exec_file, allargs, env, darwin_ptrace_me,
@@ -1877,8 +1845,8 @@ darwin_setup_fake_stop_event (struct inferior *inf)
/* Attach to process PID, then initialize for debugging it
and wait for the trace-trap that results from attaching. */
-static void
-darwin_attach (struct target_ops *ops, const char *args, int from_tty)
+void
+darwin_nat_target::attach (const char *args, int from_tty)
{
pid_t pid;
pid_t pid2;
@@ -1906,7 +1874,7 @@ darwin_attach (struct target_ops *ops, const char *args, int from_tty)
gdb_flush (gdb_stdout);
}
- if (pid == 0 || kill (pid, 0) < 0)
+ if (pid == 0 || ::kill (pid, 0) < 0)
error (_("Can't attach to process %d: %s (%d)"),
pid, safe_strerror (errno), errno);
@@ -1937,8 +1905,9 @@ darwin_attach (struct target_ops *ops, const char *args, int from_tty)
to work, it may be necessary for the process to have been
previously attached. It *might* work if the program was
started via fork. */
-static void
-darwin_detach (struct target_ops *ops, inferior *inf, int from_tty)
+
+void
+darwin_nat_target::detach (inferior *inf, int from_tty)
{
pid_t pid = ptid_get_pid (inferior_ptid);
darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1971,16 +1940,11 @@ darwin_detach (struct target_ops *ops, inferior *inf, int from_tty)
if (priv->no_ptrace)
darwin_resume_inferior (inf);
- darwin_mourn_inferior (ops);
+ mourn_inferior ();
}
-static void
-darwin_files_info (struct target_ops *ops)
-{
-}
-
-static const char *
-darwin_pid_to_str (struct target_ops *ops, ptid_t ptid)
+const char *
+darwin_nat_target::pid_to_str (ptid_t ptid)
{
static char buf[80];
long tid = ptid_get_tid (ptid);
@@ -1995,8 +1959,8 @@ darwin_pid_to_str (struct target_ops *ops, ptid_t ptid)
return normal_pid_to_str (ptid);
}
-static int
-darwin_thread_alive (struct target_ops *ops, ptid_t ptid)
+int
+darwin_nat_target::thread_alive (ptid_t ptid)
{
return 1;
}
@@ -2193,11 +2157,11 @@ darwin_read_dyld_info (task_t task, CORE_ADDR addr, gdb_byte *rdaddr,
\f
-static enum target_xfer_status
-darwin_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
+darwin_nat_target::xfer_partial (enum target_object object, const char *annex,
+ gdb_byte *readbuf, const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
{
struct inferior *inf = current_inferior ();
darwin_inferior *priv = get_darwin_inferior (inf);
@@ -2264,8 +2228,8 @@ set_enable_mach_exceptions (const char *args, int from_tty,
}
}
-static char *
-darwin_pid_to_exec_file (struct target_ops *self, int pid)
+char *
+darwin_nat_target::pid_to_exec_file (int pid)
{
static char path[PATH_MAX];
int res;
@@ -2277,8 +2241,8 @@ darwin_pid_to_exec_file (struct target_ops *self, int pid)
return NULL;
}
-static ptid_t
-darwin_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
+ptid_t
+darwin_nat_target::get_ada_task_ptid (long lwp, long thread)
{
struct inferior *inf = current_inferior ();
darwin_inferior *priv = get_darwin_inferior (inf);
@@ -2342,14 +2306,14 @@ darwin_get_ada_task_ptid (struct target_ops *self, long lwp, long thread)
return null_ptid;
}
-static int
-darwin_supports_multi_process (struct target_ops *self)
+int
+darwin_nat_target::supports_multi_process ()
{
return 1;
}
void
-_initialize_darwin_inferior (void)
+_initialize_darwin_nat (void)
{
kern_return_t kret;
@@ -2364,30 +2328,6 @@ _initialize_darwin_inferior (void)
MACH_CHECK_ERROR (kret);
}
- darwin_ops = inf_child_target ();
-
- darwin_ops->to_create_inferior = darwin_create_inferior;
- darwin_ops->to_attach = darwin_attach;
- darwin_ops->to_attach_no_wait = 0;
- darwin_ops->to_detach = darwin_detach;
- darwin_ops->to_files_info = darwin_files_info;
- darwin_ops->to_wait = darwin_wait_to;
- darwin_ops->to_mourn_inferior = darwin_mourn_inferior;
- darwin_ops->to_kill = darwin_kill_inferior;
- darwin_ops->to_interrupt = darwin_interrupt;
- darwin_ops->to_resume = darwin_resume_to;
- darwin_ops->to_thread_alive = darwin_thread_alive;
- darwin_ops->to_pid_to_str = darwin_pid_to_str;
- darwin_ops->to_pid_to_exec_file = darwin_pid_to_exec_file;
- darwin_ops->to_load = NULL;
- darwin_ops->to_xfer_partial = darwin_xfer_partial;
- darwin_ops->to_supports_multi_process = darwin_supports_multi_process;
- darwin_ops->to_get_ada_task_ptid = darwin_get_ada_task_ptid;
-
- darwin_complete_target (darwin_ops);
-
- add_target (darwin_ops);
-
inferior_debug (2, _("GDB task: 0x%lx, pid: %d\n"),
(unsigned long) mach_task_self (), getpid ());
diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h
index 0eacb5530d..d4a06d9c27 100644
--- a/gdb/darwin-nat.h
+++ b/gdb/darwin-nat.h
@@ -17,9 +17,50 @@
#ifndef __DARWIN_NAT_H__
#define __DARWIN_NAT_H__
+#include "inf-child.h"
#include <mach/mach.h>
#include "gdbthread.h"
+/* This needs to be overridden by the platform specific nat code. */
+
+class darwin_nat_target : public inf_child_target
+{
+ void create_inferior (const char *exec_file,
+ const std::string &allargs,
+ char **env, int from_tty);
+
+ void attach (const char *, int) override;
+
+ void detach (inferior *, int) override;
+
+ ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+
+ void mourn_inferior () override;
+
+ void kill () override;
+
+ void interrupt () override;
+
+ void resume (ptid_t, int , enum gdb_signal) override;
+
+ int thread_alive (ptid_t ptid) override;
+
+ const char *pid_to_str (ptid_t) override;
+
+ char *pid_to_exec_file (int pid) 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;
+
+ int supports_multi_process () override;
+
+ ptid_t get_ada_task_ptid (long lwp, long thread) override;
+};
+
/* Describe the mach exception handling state for a task. This state is saved
before being changed and restored when a process is detached.
For more information on these fields see task_get_exception_ports manual
@@ -158,11 +199,6 @@ extern void mach_check_error (kern_return_t ret, const char *file,
void darwin_set_sstep (thread_t thread, int enable);
-/* This one is called in darwin-nat.c, but needs to be provided by the
- platform specific nat code. It allows each platform to add platform specific
- stuff to the darwin_ops. */
-extern void darwin_complete_target (struct target_ops *target);
-
void darwin_check_osabi (darwin_inferior *inf, thread_t thread);
#endif /* __DARWIN_NAT_H__ */
diff --git a/gdb/i386-darwin-nat.c b/gdb/i386-darwin-nat.c
index 023643fa56..48f1a7921d 100644
--- a/gdb/i386-darwin-nat.c
+++ b/gdb/i386-darwin-nat.c
@@ -43,12 +43,21 @@
#include "amd64-darwin-tdep.h"
#endif
+struct i386_darwin_nat_target final : public x86_nat_target<darwin_nat_target>
+{
+ /* Add our register access methods. */
+ void fetch_registers (struct regcache *, int) override;
+ void store_registers (struct regcache *, int) override;
+};
+
+static struct i386_darwin_nat_target darwin_target;
+
/* Read register values from the inferior process.
If REGNO is -1, do this for all registers.
Otherwise, REGNO specifies which register (so we can save time). */
-static void
-i386_darwin_fetch_inferior_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+
+void
+i386_darwin_nat_target::fetch_registers (struct regcache *regcache, int regno)
{
thread_t current_thread = ptid_get_tid (regcache_get_ptid (regcache));
int fetched = 0;
@@ -163,9 +172,9 @@ i386_darwin_fetch_inferior_registers (struct target_ops *ops,
If REGNO is -1, do this for all registers.
Otherwise, REGNO specifies which register (so we can save time). */
-static void
-i386_darwin_store_inferior_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+void
+i386_darwin_nat_target::store_registers (struct regcache *regcache,
+ int regno)
{
thread_t current_thread = ptid_get_tid (regcache_get_ptid (regcache));
struct gdbarch *gdbarch = regcache->arch ();
@@ -628,7 +637,7 @@ darwin_set_sstep (thread_t thread, int enable)
}
void
-darwin_complete_target (struct target_ops *target)
+_initialize_i386_darwin_nat (void)
{
#ifdef BFD64
amd64_native_gregset64_reg_offset = amd64_darwin_thread_state_reg_offset;
@@ -637,8 +646,6 @@ darwin_complete_target (struct target_ops *target)
amd64_native_gregset32_num_regs = i386_darwin_thread_state_num_regs;
#endif
- x86_use_watchpoints (target);
-
x86_dr_low.set_control = i386_darwin_dr_set_control;
x86_dr_low.set_addr = i386_darwin_dr_set_addr;
x86_dr_low.get_addr = i386_darwin_dr_get_addr;
@@ -652,6 +659,5 @@ darwin_complete_target (struct target_ops *target)
x86_set_debug_register_length (4);
#endif
- target->to_fetch_registers = i386_darwin_fetch_inferior_registers;
- target->to_store_registers = i386_darwin_store_inferior_registers;
+ add_target (&darwin_target);
}
--
2.14.3
next prev parent reply other threads:[~2018-04-14 19:10 UTC|newest]
Thread overview: 64+ 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 02/40] make-target-delegates: line break between return type and function name Pedro Alves
2018-04-14 19:10 ` [PATCH 19/40] target_ops/C++: AIX target Pedro Alves
2018-04-14 19:10 ` Pedro Alves [this message]
2018-04-14 19:10 ` [PATCH 23/40] target_ops/C++: IA-64 GNU/Linux Pedro Alves
2018-04-14 19:10 ` [PATCH 07/40] target_ops/C++: ravenscar-thread Pedro Alves
2018-04-14 19:10 ` [PATCH 08/40] target_ops/C++: bsd-uthread Pedro Alves
2018-04-14 19:10 ` [PATCH 03/40] target_ops/C++: exec target Pedro Alves
2018-04-14 19:10 ` [PATCH 27/40] target_ops/C++: SPARC GNU/Linux Pedro Alves
2018-04-14 19:10 ` [PATCH 37/40] target_ops/C++: The Hurd 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 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 32/40] target_ops/C++: Generic i386/AMD64 BSD targets 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 20/40] target_ops/C++: ARM 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:15 ` [PATCH 14/40] target_ops/C++: PPC/PPC64 GNU/Linux 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:18 ` [PATCH 04/40] target_ops/C++: core target Pedro Alves
2018-04-14 19:18 ` [PATCH 24/40] target_ops/C++: m32r GNU/Linux Pedro Alves
2018-04-14 19:18 ` [PATCH 36/40] target_ops/C++: go32/DJGPP Pedro Alves
2018-04-14 19:18 ` [PATCH 25/40] target_ops/C++: m68k GNU/Linux Pedro Alves
2018-04-14 19:19 ` [PATCH 05/40] target_ops/C++: ctf/tfile targets 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
[not found] ` <0b900391-f06d-278c-cbed-b89b207bd12e@redhat.com>
2018-04-18 14:20 ` Pedro Alves
2018-04-18 20:55 ` John Baldwin
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 35/40] target_ops/C++: NTO/QNX, nto-procfs.c Pedro Alves
2018-04-14 19:19 ` [PATCH 16/40] target_ops/C++: Windows targets Pedro Alves
2018-04-14 19:19 ` [PATCH 15/40] target_ops/C++: Solaris/procfs 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-18-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