mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
e7eee665a1
The darwin-nat.c file doesn't build since the multi-target changes
(5b6d1e4f
, "Multi-target support"). This patch makes it build. I have
access to a macOS vm, so I am able to build it, but I wasn't able to
successfully codesign it and try to actually debug something, so I don't
know if it works. I don't have much more time to put on this to figure
it out, so I thought I'd sent the patch anyway, as it's at least a step
in the right direction.
The bulk of the patch is to change a bunch of functions to be methods of
the darwin_nat_target object, so that this can pass `this` to
find_inferior_ptid and other functions that now require a
process_stratum_target pointer.
The darwin_ptrace_him function (renamed to darwin_nat_target::ptrace_him
in this patch) is passed to fork_inferior as the `init_trace_fun`
parameter. Since the method can't be passed as a plain function pointer
(we need the `this` pointer), I changed the `init_trace_fun` parameter
of fork_inferior to be a gdb::function_view, so we can pass a lambda and
capture `this`.
The changes in darwin-nat.h are only to move definition higher in the
file, so that forward declarations are not needed.
gdb/ChangeLog:
* darwin-nat.h (struct darwin_exception_msg, enum
darwin_msg_state, struct darwin_thread_info, darwin_thread_t):
Move up.
(class darwin_nat_target) <wait_1, check_new_threads,
decode_exception_message, decode_message, stop_inferior,
init_thread_list, ptrace_him, cancel_breakpoint>: Declare.
* darwin-nat.c (darwin_check_new_threads): Rename to...
(darwin_nat_target::check_new_threads): ... this.
(darwin_suspend_inferior_it): Remove.
(darwin_decode_exception_message): Rename to...
(darwin_nat_target::decode_exception_message): ... this.
(darwin_nat_target::resume): Pass target to find_inferior_ptid.
(darwin_decode_message): Rename to...
(darwin_nat_target::decode_message): ... this.
(cancel_breakpoint): Rename to...
(darwin_nat_target::cancel_breakpoint): ... this.
(darwin_wait): Rename to...
(darwin_nat_target::wait_1): ... this. Use range-based for loop
instead of iterate_over_inferiors.
(darwin_nat_target::wait): Call wait_1 instead of darwin_wait.
(darwin_stop_inferior): Rename to...
(darwin_nat_target::stop_inferior): ... this.
(darwin_nat_target::kill): Call wait_1 instead of darwin_wait.
(darwin_init_thread_list): Rename to...
(darwin_nat_target::init_thread_list): ... this.
(darwin_ptrace_him): Rename to...
(darwin_nat_target::ptrace_him): ... this.
(darwin_nat_target::create_inferior): Pass lambda function to
fork_inferior.
(darwin_nat_target::detach): Call stop_inferior instead of
darwin_stop_inferior.
* fork-inferior.h (fork_inferior): Change init_trace_fun
parameter to gdb::function_view.
* fork-inferior.c (fork_inferior): Likewise.
91 lines
3.5 KiB
C++
91 lines
3.5 KiB
C++
/* Functions and data responsible for forking the inferior process.
|
|
|
|
Copyright (C) 1986-2020 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef NAT_FORK_INFERIOR_H
|
|
#define NAT_FORK_INFERIOR_H
|
|
|
|
#include <string>
|
|
#include "gdbsupport/function-view.h"
|
|
|
|
struct process_stratum_target;
|
|
|
|
/* Number of traps that happen between exec'ing the shell to run an
|
|
inferior and when we finally get to the inferior code, not counting
|
|
the exec for the shell. This is 1 on all supported
|
|
implementations. */
|
|
#define START_INFERIOR_TRAPS_EXPECTED 1
|
|
|
|
/* Start an inferior Unix child process and sets inferior_ptid to its
|
|
pid. EXEC_FILE is the file to run. ALLARGS is a string containing
|
|
the arguments to the program. ENV is the environment vector to
|
|
pass. SHELL_FILE is the shell file, or NULL if we should pick
|
|
one. EXEC_FUN is the exec(2) function to use, or NULL for the default
|
|
one. */
|
|
|
|
/* This function is NOT reentrant. Some of the variables have been
|
|
made static to ensure that they survive the vfork call. */
|
|
extern pid_t fork_inferior (const char *exec_file_arg,
|
|
const std::string &allargs,
|
|
char **env, void (*traceme_fun) (),
|
|
gdb::function_view<void (int)> init_trace_fun,
|
|
void (*pre_trace_fun) (),
|
|
const char *shell_file_arg,
|
|
void (*exec_fun) (const char *file,
|
|
char * const *argv,
|
|
char * const *env));
|
|
|
|
/* Accept NTRAPS traps from the inferior.
|
|
|
|
Return the ptid of the inferior being started. */
|
|
extern ptid_t startup_inferior (process_stratum_target *proc_target,
|
|
pid_t pid, int ntraps,
|
|
struct target_waitstatus *mystatus,
|
|
ptid_t *myptid);
|
|
|
|
/* Perform any necessary tasks before a fork/vfork takes place. ARGS
|
|
is a string containing all the arguments received by the inferior.
|
|
This function is mainly used by fork_inferior. */
|
|
extern void prefork_hook (const char *args);
|
|
|
|
/* Perform any necessary tasks after a fork/vfork takes place. This
|
|
function is mainly used by fork_inferior. */
|
|
extern void postfork_hook (pid_t pid);
|
|
|
|
/* Perform any necessary tasks *on the child* after a fork/vfork takes
|
|
place. This function is mainly used by fork_inferior. */
|
|
extern void postfork_child_hook ();
|
|
|
|
/* Flush both stdout and stderr. This function needs to be
|
|
implemented differently on GDB and GDBserver. */
|
|
extern void gdb_flush_out_err ();
|
|
|
|
/* Report an error that happened when starting to trace the inferior
|
|
(i.e., when the "traceme_fun" callback is called on fork_inferior)
|
|
and bail out. This function does not return. */
|
|
extern void trace_start_error (const char *fmt, ...)
|
|
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
|
|
|
|
/* Like "trace_start_error", but the error message is constructed by
|
|
combining STRING with the system error message for errno. This
|
|
function does not return. */
|
|
extern void trace_start_error_with_name (const char *string)
|
|
ATTRIBUTE_NORETURN;
|
|
|
|
#endif /* NAT_FORK_INFERIOR_H */
|