target_pass_signals/target_program_signals: Use gdb::array_view

This replaces the pointer and length parameters of target_pass_signals
and target_program_signals with a gdb::array_view parameter, and fixes
the fallout.

In infrun.c, the signal_stop, signal_print, signal_program,
signal_catch, signal_pass globals are currently pointers to
heap-allocated memory.  I see no point in that, so I converted them to
arrays.  This allows simplifying the calls to
target_pass_signals/target_program_signals, since we can pass the
array directly, which can implicitly convert to gdb::array_view.

gdb/ChangeLog:
2019-01-24  Pedro Alves  <palves@redhat.com>

	* infrun.c (signal_stop, signal_print, signal_program)
	(signal_catch, signal_pass): Now arrays instead of pointers.
	(update_signals_program_target, do_target_resume)
	(signal_catch_update, handle_command, _initialize_infrun): Adjust.
	* linux-nat.c (linux_nat_target::pass_signals)
	(linux_nat_target::create_inferior, linux_nat_target::attach):
	Adjust.
	* linux-nat.h (linux_nat_target::pass_signals): Adjust.
	* nto-procfs.c (nto_procfs_target::pass_signals): Adjust.
	* procfs.c (procfs_target::pass_signals): Adjust.
	* record-full.c (record_full_target::resume): Adjust.
	* remote.c (remote_target::pass_signals)
	(remote_target::program_signals): Adjust.
	* target-debug.h (target_debug_print_signals): Now takes a
	gdb::array_view as parameter.  Adjust.
	* target.h (target_ops) <pass_signals, program_signals>: Replace
	pointer and length parameters with gdb::array_view.
	(target_pass_signals, target_program_signals): Likewise.
	* target-delegates.c: Regenerate.
This commit is contained in:
Pedro Alves 2019-01-24 18:25:06 +00:00
parent 3046d67a0e
commit adc6a863a9
12 changed files with 99 additions and 97 deletions

View File

@ -1,3 +1,25 @@
2019-01-24 Pedro Alves <palves@redhat.com>
* infrun.c (signal_stop, signal_print, signal_program)
(signal_catch, signal_pass): Now arrays instead of pointers.
(update_signals_program_target, do_target_resume)
(signal_catch_update, handle_command, _initialize_infrun): Adjust.
* linux-nat.c (linux_nat_target::pass_signals)
(linux_nat_target::create_inferior, linux_nat_target::attach):
Adjust.
* linux-nat.h (linux_nat_target::pass_signals): Adjust.
* nto-procfs.c (nto_procfs_target::pass_signals): Adjust.
* procfs.c (procfs_target::pass_signals): Adjust.
* record-full.c (record_full_target::resume): Adjust.
* remote.c (remote_target::pass_signals)
(remote_target::program_signals): Adjust.
* target-debug.h (target_debug_print_signals): Now takes a
gdb::array_view as parameter. Adjust.
* target.h (target_ops) <pass_signals, program_signals>: Replace
pointer and length parameters with gdb::array_view.
(target_pass_signals, target_program_signals): Likewise.
* target-delegates.c: Regenerate.
2019-01-24 Pedro Alves <palves@redhat.com>
* common/forward-scope-exit.h

View File

@ -306,20 +306,19 @@ update_observer_mode (void)
/* Tables of how to react to signals; the user sets them. */
static unsigned char *signal_stop;
static unsigned char *signal_print;
static unsigned char *signal_program;
static unsigned char signal_stop[GDB_SIGNAL_LAST];
static unsigned char signal_print[GDB_SIGNAL_LAST];
static unsigned char signal_program[GDB_SIGNAL_LAST];
/* Table of signals that are registered with "catch signal". A
non-zero entry indicates that the signal is caught by some "catch
signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
signals. */
static unsigned char *signal_catch;
signal" command. */
static unsigned char signal_catch[GDB_SIGNAL_LAST];
/* Table of signals that the target may silently handle.
This is automatically determined from the flags above,
and simply cached here. */
static unsigned char *signal_pass;
static unsigned char signal_pass[GDB_SIGNAL_LAST];
#define SET_SIGS(nsigs,sigs,flags) \
do { \
@ -343,7 +342,7 @@ static unsigned char *signal_pass;
void
update_signals_program_target (void)
{
target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
target_program_signals (signal_program);
}
/* Value to pass to target_resume() to cause all threads to resume. */
@ -2219,9 +2218,9 @@ do_target_resume (ptid_t resume_ptid, int step, enum gdb_signal sig)
valid. */
if (step_over_info_valid_p ()
|| displaced_step_in_progress (tp->inf))
target_pass_signals (0, NULL);
target_pass_signals ({});
else
target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
target_pass_signals (signal_pass);
target_resume (resume_ptid, step, sig);
@ -8251,7 +8250,7 @@ signal_catch_update (const unsigned int *info)
for (i = 0; i < GDB_SIGNAL_LAST; ++i)
signal_catch[i] = info[i] > 0;
signal_cache_update (-1);
target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
target_pass_signals (signal_pass);
}
static void
@ -8287,8 +8286,6 @@ handle_command (const char *args, int from_tty)
int sigfirst, siglast;
enum gdb_signal oursig;
int allsigs;
int nsigs;
unsigned char *sigs;
if (args == NULL)
{
@ -8297,9 +8294,8 @@ handle_command (const char *args, int from_tty)
/* Allocate and zero an array of flags for which signals to handle. */
nsigs = (int) GDB_SIGNAL_LAST;
sigs = (unsigned char *) alloca (nsigs);
memset (sigs, 0, nsigs);
const size_t nsigs = GDB_SIGNAL_LAST;
unsigned char sigs[nsigs] {};
/* Break the command line up into args. */
@ -8436,8 +8432,8 @@ Are you sure you want to change it? "),
if (sigs[signum])
{
signal_cache_update (-1);
target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
target_pass_signals (signal_pass);
target_program_signals (signal_program);
if (from_tty)
{
@ -8963,8 +8959,6 @@ infrun_async_inferior_event_handler (gdb_client_data data)
void
_initialize_infrun (void)
{
int i;
int numsigs;
struct cmd_list_element *c;
/* Register extra event sources in the event loop. */
@ -9046,13 +9040,7 @@ leave it stopped or free to run as needed."),
&setlist,
&showlist);
numsigs = (int) GDB_SIGNAL_LAST;
signal_stop = XNEWVEC (unsigned char, numsigs);
signal_print = XNEWVEC (unsigned char, numsigs);
signal_program = XNEWVEC (unsigned char, numsigs);
signal_catch = XNEWVEC (unsigned char, numsigs);
signal_pass = XNEWVEC (unsigned char, numsigs);
for (i = 0; i < numsigs; i++)
for (size_t i = 0; i < GDB_SIGNAL_LAST; i++)
{
signal_stop[i] = 1;
signal_print[i] = 1;

View File

@ -789,7 +789,8 @@ static sigset_t pass_mask;
/* Update signals to pass to the inferior. */
void
linux_nat_target::pass_signals (int numsigs, const unsigned char *pass_signals)
linux_nat_target::pass_signals
(gdb::array_view<const unsigned char> pass_signals)
{
int signo;
@ -798,7 +799,7 @@ linux_nat_target::pass_signals (int numsigs, const unsigned char *pass_signals)
for (signo = 1; signo < NSIG; signo++)
{
int target_signo = gdb_signal_from_host (signo);
if (target_signo < numsigs && pass_signals[target_signo])
if (target_signo < pass_signals.size () && pass_signals[target_signo])
sigaddset (&pass_mask, signo);
}
}
@ -1096,7 +1097,7 @@ linux_nat_target::create_inferior (const char *exec_file,
we have to mask the async mode. */
/* Make sure we report all signals during startup. */
pass_signals (0, NULL);
pass_signals ({});
inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
}
@ -1186,7 +1187,7 @@ linux_nat_target::attach (const char *args, int from_tty)
ptid_t ptid;
/* Make sure we report all signals during attach. */
pass_signals (0, NULL);
pass_signals ({});
TRY
{

View File

@ -45,7 +45,7 @@ public:
ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
void pass_signals (int, const unsigned char *) override;
void pass_signals (gdb::array_view<const unsigned char>) override;
enum target_xfer_status xfer_partial (enum target_object object,
const char *annex,

View File

@ -109,7 +109,7 @@ struct nto_procfs_target : public inf_child_target
void mourn_inferior () override;
void pass_signals (int, const unsigned char *) override;
void pass_signals (gdb::array_view<const unsigned char>) override;
bool thread_alive (ptid_t ptid) override;
@ -1442,8 +1442,8 @@ nto_procfs_target::store_registers (struct regcache *regcache, int regno)
/* Set list of signals to be handled in the target. */
void
nto_procfs_target::pass_signals (int numsigs,
const unsigned char *pass_signals)
nto_procfs_target::pass_signals
(gdb::array_view<const unsigned char> pass_signals)
{
int signo;
@ -1452,7 +1452,7 @@ nto_procfs_target::pass_signals (int numsigs,
for (signo = 1; signo < NSIG; signo++)
{
int target_signo = gdb_signal_from_host (signo);
if (target_signo < numsigs && pass_signals[target_signo])
if (target_signo < pass_signals.size () && pass_signals[target_signo])
sigdelset (&run.trace, signo);
}
}

View File

@ -119,7 +119,7 @@ public:
ULONGEST offset, ULONGEST len,
ULONGEST *xfered_len) override;
void pass_signals (int, const unsigned char *) override;
void pass_signals (gdb::array_view<const unsigned char>) override;
void files_info () override;
@ -2772,7 +2772,7 @@ procfs_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
/* Set up to trace signals in the child process. */
void
procfs_target::pass_signals (int numsigs, const unsigned char *pass_signals)
procfs_target::pass_signals (gdb::array_view<const unsigned char> pass_signals)
{
sigset_t signals;
procinfo *pi = find_procinfo_or_die (inferior_ptid.pid (), 0);
@ -2783,7 +2783,7 @@ procfs_target::pass_signals (int numsigs, const unsigned char *pass_signals)
for (signo = 0; signo < NSIG; signo++)
{
int target_signo = gdb_signal_from_host (signo);
if (target_signo < numsigs && pass_signals[target_signo])
if (target_signo < pass_signals.size () && pass_signals[target_signo])
prdelset (&signals, signo);
}

View File

@ -1098,7 +1098,7 @@ record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
}
/* Make sure the target beneath reports all signals. */
target_pass_signals (0, NULL);
target_pass_signals ({});
this->beneath ()->resume (ptid, step, signal);
}

View File

@ -472,12 +472,12 @@ public:
void mourn_inferior () override;
void pass_signals (int, const unsigned char *) override;
void pass_signals (gdb::array_view<const unsigned char>) override;
int set_syscall_catchpoint (int, bool, int,
gdb::array_view<const int>) override;
void program_signals (int, const unsigned char *) override;
void program_signals (gdb::array_view<const unsigned char>) override;
bool thread_alive (ptid_t ptid) override;
@ -2560,16 +2560,16 @@ record_currthread (struct remote_state *rs, ptid_t currthread)
it can simply pass through to the inferior without reporting. */
void
remote_target::pass_signals (int numsigs, const unsigned char *pass_signals)
remote_target::pass_signals (gdb::array_view<const unsigned char> pass_signals)
{
if (packet_support (PACKET_QPassSignals) != PACKET_DISABLE)
{
char *pass_packet, *p;
int count = 0, i;
int count = 0;
struct remote_state *rs = get_remote_state ();
gdb_assert (numsigs < 256);
for (i = 0; i < numsigs; i++)
gdb_assert (pass_signals.size () < 256);
for (size_t i = 0; i < pass_signals.size (); i++)
{
if (pass_signals[i])
count++;
@ -2577,7 +2577,7 @@ remote_target::pass_signals (int numsigs, const unsigned char *pass_signals)
pass_packet = (char *) xmalloc (count * 3 + strlen ("QPassSignals:") + 1);
strcpy (pass_packet, "QPassSignals:");
p = pass_packet + strlen (pass_packet);
for (i = 0; i < numsigs; i++)
for (size_t i = 0; i < pass_signals.size (); i++)
{
if (pass_signals[i])
{
@ -2686,16 +2686,16 @@ remote_target::set_syscall_catchpoint (int pid, bool needed, int any_count,
signals it should pass through to the inferior when detaching. */
void
remote_target::program_signals (int numsigs, const unsigned char *signals)
remote_target::program_signals (gdb::array_view<const unsigned char> signals)
{
if (packet_support (PACKET_QProgramSignals) != PACKET_DISABLE)
{
char *packet, *p;
int count = 0, i;
int count = 0;
struct remote_state *rs = get_remote_state ();
gdb_assert (numsigs < 256);
for (i = 0; i < numsigs; i++)
gdb_assert (signals.size () < 256);
for (size_t i = 0; i < signals.size (); i++)
{
if (signals[i])
count++;
@ -2703,7 +2703,7 @@ remote_target::program_signals (int numsigs, const unsigned char *signals)
packet = (char *) xmalloc (count * 3 + strlen ("QProgramSignals:") + 1);
strcpy (packet, "QProgramSignals:");
p = packet + strlen (packet);
for (i = 0; i < numsigs; i++)
for (size_t i = 0; i < signals.size (); i++)
{
if (signal_pass_state (i))
{
@ -4796,7 +4796,7 @@ remote_target::start_remote (int from_tty, int extended_p)
gdb_assert (wait_status == NULL);
/* Report all signals during attach/startup. */
pass_signals (0, NULL);
pass_signals ({});
/* If there are already stopped threads, mark them stopped and
report their stops before giving the prompt to the user. */

View File

@ -209,20 +209,16 @@ target_debug_print_options (int options)
}
static void
target_debug_print_signals (const unsigned char *sigs)
target_debug_print_signals (gdb::array_view<const unsigned char> sigs)
{
fputs_unfiltered ("{", gdb_stdlog);
if (sigs != NULL)
{
int i;
for (i = 0; i < GDB_SIGNAL_LAST; i++)
if (sigs[i])
{
fprintf_unfiltered (gdb_stdlog, " %s",
gdb_signal_to_name ((enum gdb_signal) i));
}
}
for (size_t i = 0; i < sigs.size (); i++)
if (sigs[i] != 0)
{
fprintf_unfiltered (gdb_stdlog, " %s",
gdb_signal_to_name ((enum gdb_signal) i));
}
fputs_unfiltered (" }", gdb_stdlog);
}

View File

@ -62,8 +62,8 @@ struct dummy_target : public target_ops
void follow_exec (struct inferior *arg0, char *arg1) override;
int set_syscall_catchpoint (int arg0, bool arg1, int arg2, gdb::array_view<const int> arg3) override;
void mourn_inferior () override;
void pass_signals (int arg0, const unsigned char * arg1) override;
void program_signals (int arg0, const unsigned char * arg1) override;
void pass_signals (gdb::array_view<const unsigned char> arg0) override;
void program_signals (gdb::array_view<const unsigned char> arg0) override;
bool thread_alive (ptid_t arg0) override;
void update_thread_list () override;
const char *pid_to_str (ptid_t arg0) override;
@ -229,8 +229,8 @@ struct debug_target : public target_ops
void follow_exec (struct inferior *arg0, char *arg1) override;
int set_syscall_catchpoint (int arg0, bool arg1, int arg2, gdb::array_view<const int> arg3) override;
void mourn_inferior () override;
void pass_signals (int arg0, const unsigned char * arg1) override;
void program_signals (int arg0, const unsigned char * arg1) override;
void pass_signals (gdb::array_view<const unsigned char> arg0) override;
void program_signals (gdb::array_view<const unsigned char> arg0) override;
bool thread_alive (ptid_t arg0) override;
void update_thread_list () override;
const char *pid_to_str (ptid_t arg0) override;
@ -1659,48 +1659,44 @@ debug_target::mourn_inferior ()
}
void
target_ops::pass_signals (int arg0, const unsigned char * arg1)
target_ops::pass_signals (gdb::array_view<const unsigned char> arg0)
{
this->beneath ()->pass_signals (arg0, arg1);
this->beneath ()->pass_signals (arg0);
}
void
dummy_target::pass_signals (int arg0, const unsigned char * arg1)
dummy_target::pass_signals (gdb::array_view<const unsigned char> arg0)
{
}
void
debug_target::pass_signals (int arg0, const unsigned char * arg1)
debug_target::pass_signals (gdb::array_view<const unsigned char> arg0)
{
fprintf_unfiltered (gdb_stdlog, "-> %s->pass_signals (...)\n", this->beneath ()->shortname ());
this->beneath ()->pass_signals (arg0, arg1);
this->beneath ()->pass_signals (arg0);
fprintf_unfiltered (gdb_stdlog, "<- %s->pass_signals (", this->beneath ()->shortname ());
target_debug_print_int (arg0);
fputs_unfiltered (", ", gdb_stdlog);
target_debug_print_signals (arg1);
target_debug_print_signals (arg0);
fputs_unfiltered (")\n", gdb_stdlog);
}
void
target_ops::program_signals (int arg0, const unsigned char * arg1)
target_ops::program_signals (gdb::array_view<const unsigned char> arg0)
{
this->beneath ()->program_signals (arg0, arg1);
this->beneath ()->program_signals (arg0);
}
void
dummy_target::program_signals (int arg0, const unsigned char * arg1)
dummy_target::program_signals (gdb::array_view<const unsigned char> arg0)
{
}
void
debug_target::program_signals (int arg0, const unsigned char * arg1)
debug_target::program_signals (gdb::array_view<const unsigned char> arg0)
{
fprintf_unfiltered (gdb_stdlog, "-> %s->program_signals (...)\n", this->beneath ()->shortname ());
this->beneath ()->program_signals (arg0, arg1);
this->beneath ()->program_signals (arg0);
fprintf_unfiltered (gdb_stdlog, "<- %s->program_signals (", this->beneath ()->shortname ());
target_debug_print_int (arg0);
fputs_unfiltered (", ", gdb_stdlog);
target_debug_print_signals (arg1);
target_debug_print_signals (arg0);
fputs_unfiltered (")\n", gdb_stdlog);
}

View File

@ -2111,15 +2111,15 @@ make_scoped_defer_target_commit_resume ()
}
void
target_pass_signals (int numsigs, const unsigned char *pass_signals)
target_pass_signals (gdb::array_view<const unsigned char> pass_signals)
{
current_top_target ()->pass_signals (numsigs, pass_signals);
current_top_target ()->pass_signals (pass_signals);
}
void
target_program_signals (int numsigs, const unsigned char *program_signals)
target_program_signals (gdb::array_view<const unsigned char> program_signals)
{
current_top_target ()->program_signals (numsigs, program_signals);
current_top_target ()->program_signals (program_signals);
}
static int

View File

@ -637,14 +637,12 @@ struct target_ops
/* Documentation of this routine is provided with the corresponding
target_* macro. */
virtual void pass_signals (int,
const unsigned char * TARGET_DEBUG_PRINTER (target_debug_print_signals))
virtual void pass_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
TARGET_DEFAULT_IGNORE ();
/* Documentation of this routine is provided with the
corresponding target_* function. */
virtual void program_signals (int,
const unsigned char * TARGET_DEBUG_PRINTER (target_debug_print_signals))
virtual void program_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
TARGET_DEFAULT_IGNORE ();
virtual bool thread_alive (ptid_t ptid)
@ -1682,7 +1680,7 @@ extern int target_can_run ();
/* Set list of signals to be handled in the target.
PASS_SIGNALS is an array of size NSIG, indexed by target signal number
PASS_SIGNALS is an array indexed by target signal number
(enum gdb_signal). For every signal whose entry in this array is
non-zero, the target is allowed -but not required- to skip reporting
arrival of the signal to the GDB core by returning from target_wait,
@ -1692,12 +1690,13 @@ extern int target_can_run ();
about to receive a signal, it needs to be reported in any case, even
if mentioned in a previous target_pass_signals call. */
extern void target_pass_signals (int nsig, const unsigned char *pass_signals);
extern void target_pass_signals
(gdb::array_view<const unsigned char> pass_signals);
/* Set list of signals the target may pass to the inferior. This
directly maps to the "handle SIGNAL pass/nopass" setting.
PROGRAM_SIGNALS is an array of size NSIG, indexed by target signal
PROGRAM_SIGNALS is an array indexed by target signal
number (enum gdb_signal). For every signal whose entry in this
array is non-zero, the target is allowed to pass the signal to the
inferior. Signals not present in the array shall be silently
@ -1708,8 +1707,8 @@ extern void target_pass_signals (int nsig, const unsigned char *pass_signals);
example, when detaching (as threads may have been suspended with
pending signals not reported to GDB). */
extern void target_program_signals (int nsig,
const unsigned char *program_signals);
extern void target_program_signals
(gdb::array_view<const unsigned char> program_signals);
/* Check to see if a thread is still alive. */