old-cross-binutils/gdb/gdbserver/inferiors.h
Josh Stone 82075af2c1 Implement 'catch syscall' for gdbserver
This adds a new QCatchSyscalls packet to enable 'catch syscall', and new
stop reasons "syscall_entry" and "syscall_return" for those events.  It
is currently only supported on Linux x86 and x86_64.

gdb/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS (Changes since GDB 7.10): Mention QCatchSyscalls and the
	syscall_entry and syscall_return stop reasons.  Mention GDB
	support for remote catch syscall.
	* remote.c (PACKET_QCatchSyscalls): New enum.
	(remote_set_syscall_catchpoint): New function.
	(remote_protocol_features): New element for QCatchSyscalls.
	(remote_parse_stop_reply): Parse syscall_entry/return stops.
	(init_remote_ops): Install remote_set_syscall_catchpoint.
	(_initialize_remote): Config QCatchSyscalls.
	* linux-nat.h (struct lwp_info) <syscall_state>: Comment typo.

gdb/doc/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Remote Configuration): List the QCatchSyscalls packet.
	(Stop Reply Packets): List the syscall entry and return stop reasons.
	(General Query Packets): Describe QCatchSyscalls, and add it to the
	table and the detailed list of stub features.

gdb/gdbserver/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* inferiors.h: Include "gdb_vecs.h".
	(struct process_info): Add syscalls_to_catch.
	* inferiors.c (remove_process): Free syscalls_to_catch.
	* remote-utils.c (prepare_resume_reply): Report syscall_entry and
	syscall_return stops.
	* server.h (UNKNOWN_SYSCALL, ANY_SYSCALL): Define.
	* server.c (handle_general_set): Handle QCatchSyscalls.
	(handle_query): Report support for QCatchSyscalls.
	* target.h (struct target_ops): Add supports_catch_syscall.
	(target_supports_catch_syscall): New macro.
	* linux-low.h (struct linux_target_ops): Add get_syscall_trapinfo.
	(struct lwp_info): Add syscall_state.
	* linux-low.c (handle_extended_wait): Mark syscall_state as an entry.
	Maintain syscall_state and syscalls_to_catch across exec.
	(get_syscall_trapinfo): New function, proxy to the_low_target.
	(linux_low_ptrace_options): Enable PTRACE_O_TRACESYSGOOD.
	(linux_low_filter_event): Toggle syscall_state entry/return for
	syscall traps, and set it ignored for all others.
	(gdb_catching_syscalls_p): New function.
	(gdb_catch_this_syscall_p): New function.
	(linux_wait_1): Handle SYSCALL_SIGTRAP.
	(linux_resume_one_lwp_throw): Add PTRACE_SYSCALL possibility.
	(linux_supports_catch_syscall): New function.
	(linux_target_ops): Install it.
	* linux-x86-low.c (x86_get_syscall_trapinfo): New function.
	(the_low_target): Install it.

gdb/testsuite/ChangeLog:

2016-01-12  Josh Stone  <jistone@redhat.com>
	    Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/catch-syscall.c (do_execve): New variable.
	(main): Conditionally trigger an execve.
	* gdb.base/catch-syscall.exp: Enable testing for remote targets.
	(test_catch_syscall_execve): New, check entry/return across execve.
	(do_syscall_tests): Call test_catch_syscall_execve.
2016-01-12 12:27:27 -08:00

163 lines
5.1 KiB
C

/* Inferior process information for the remote server for GDB.
Copyright (C) 1993-2016 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 INFERIORS_H
#define INFERIORS_H
#include "gdb_vecs.h"
/* Generic information for tracking a list of ``inferiors'' - threads,
processes, etc. */
struct inferior_list
{
struct inferior_list_entry *head;
struct inferior_list_entry *tail;
};
struct inferior_list_entry
{
ptid_t id;
struct inferior_list_entry *next;
};
struct thread_info;
struct regcache;
struct target_desc;
struct sym_cache;
struct breakpoint;
struct raw_breakpoint;
struct fast_tracepoint_jump;
struct process_info_private;
struct process_info
{
/* This must appear first.
The list iterator functions assume it. */
struct inferior_list_entry entry;
/* Nonzero if this child process was attached rather than
spawned. */
int attached;
/* True if GDB asked us to detach from this process, but we remained
attached anyway. */
int gdb_detached;
/* The symbol cache. */
struct sym_cache *symbol_cache;
/* The list of memory breakpoints. */
struct breakpoint *breakpoints;
/* The list of raw memory breakpoints. */
struct raw_breakpoint *raw_breakpoints;
/* The list of installed fast tracepoints. */
struct fast_tracepoint_jump *fast_tracepoint_jumps;
/* The list of syscalls to report, or just a single element, ANY_SYSCALL,
for unfiltered syscall reporting. */
VEC (int) *syscalls_to_catch;
const struct target_desc *tdesc;
/* Private target data. */
struct process_info_private *priv;
};
#define ptid_of(inf) ((inf)->entry.id)
#define pid_of(inf) ptid_get_pid ((inf)->entry.id)
#define lwpid_of(inf) ptid_get_lwp ((inf)->entry.id)
/* Return a pointer to the process that corresponds to the current
thread (current_thread). It is an error to call this if there is
no current thread selected. */
struct process_info *current_process (void);
struct process_info *get_thread_process (struct thread_info *);
extern struct inferior_list all_processes;
void add_inferior_to_list (struct inferior_list *list,
struct inferior_list_entry *new_inferior);
void for_each_inferior (struct inferior_list *list,
void (*action) (struct inferior_list_entry *));
void for_each_inferior_with_data
(struct inferior_list *list,
void (*action) (struct inferior_list_entry *, void *),
void *data);
void clear_inferior_list (struct inferior_list *list);
int one_inferior_p (struct inferior_list *list);
/* Helper for ALL_INFERIORS_TYPE. Gets the next element starting at
CUR, if CUR is not NULL. */
#define A_I_NEXT(type, list, cur) \
((cur) != NULL \
? (type *) ((struct inferior_list_entry *) cur)->next \
: NULL)
/* Iterate over all inferiors of type TYPE in LIST, open loop
style. */
#define ALL_INFERIORS_TYPE(type, list, cur, tmp) \
for ((cur) = (type *) (list)->head, (tmp) = A_I_NEXT (type, list, cur); \
(cur) != NULL; \
(cur) = (tmp), (tmp) = A_I_NEXT (type, list, cur))
/* Iterate over all inferiors in LIST, open loop style. */
#define ALL_INFERIORS(list, cur, tmp) \
ALL_INFERIORS_TYPE (struct inferior_list_entry, list, cur, tmp)
/* Iterate over all processes, open loop style. */
#define ALL_PROCESSES(cur, tmp) \
ALL_INFERIORS_TYPE (struct process_info, &all_processes, cur, tmp)
extern struct thread_info *current_thread;
void remove_inferior (struct inferior_list *list,
struct inferior_list_entry *entry);
struct inferior_list_entry *get_first_inferior (struct inferior_list *list);
/* Return the first process in the processes list. */
struct process_info *get_first_process (void);
struct process_info *add_process (int pid, int attached);
void remove_process (struct process_info *process);
struct process_info *find_process_pid (int pid);
int have_started_inferiors_p (void);
int have_attached_inferiors_p (void);
ptid_t thread_to_gdb_id (struct thread_info *);
ptid_t gdb_id_to_thread_id (ptid_t);
void clear_inferiors (void);
struct inferior_list_entry *find_inferior
(struct inferior_list *,
int (*func) (struct inferior_list_entry *,
void *),
void *arg);
struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
ptid_t id);
void *inferior_target_data (struct thread_info *);
void set_inferior_target_data (struct thread_info *, void *);
struct regcache *inferior_regcache_data (struct thread_info *);
void set_inferior_regcache_data (struct thread_info *, struct regcache *);
#endif /* INFERIORS_H */