* target.h (struct target_ops): Delete to_async_mask_value and add
	to_async_mask.
	(target_is_async_p, target_async): Formatting.
	(target_async_mask_value): Delete.
	(target_async_mask): Delete function declaration, and add new
	target macro with the same name.

	* target.c (update_current_target): Replace to_async_mask_value by
	to_async_mask.  Default to_async_mask to return_one.
	(target_async_mask): Delete.
	(find_default_can_async_p, find_default_is_async_p): New.
	(init_dummy_target): register find_default_can_async_p and
	find_default_is_async_p on the dummy target.

	* linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h.
	(debug_linux_nat_async): New global.
	(show_debug_linux_nat_async): New function.
	(linux_nat_async_enabled, linux_nat_async_mask_value)
	(linux_nat_event_pipe, linux_nat_num_queued_events)
	(linux_nat_async_events_enabled): New globals.
	(struct waitpid_result): New struct.
	(waitpid_queue): New global.
	(queued_waitpid, push_waitpid, drain_queued_events): New.
	(my_waitpid): Call queued_waitpid.
	(linux_child_follow_fork): Disable async events during the call.
	(blocked_mask): Delete.
	(sync_sigchld_action, async_sigchld_action): New globals.
	(lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD.  In
	async mode, block events during the call.
	(linux_nat_create_inferior): New.
	(linux_nat_attach): In sync mode, restore the mask states.  In
	async mode, wake the event loop immediatelly.
	(detach_callback): Drain all queued events of the lwp we're
	detaching from.
	(linux_nat_detach): Block async mode, and drain events of the main
	process.
	(linux_nat_resume): If in async mode, mask async events during the
	call.  If short circuiting, force event loop to wake up.  If
	resuming, set target_executing, and register target events in the
	event loop.
	(pipe_to_local_event_queue, local_event_queue_to_pipe): New.
	(linux_nat_wait): In async mode, block events during the call.
	Only enable/disable passing SIGINT to the inferior in sync mode.
	Get events from local waitpid queue.  If no interesting events was
	found, return to events loop.  Reregister target events in the
	event loop on exit.  In sync mode, no need to reblock SIGCHLD.
	(linux_nat_kill): Disable events on entry.
	(linux_nat_mourn_inferior): In sync mode, don't restore the masks
	here.  Detach async mode from the event loop if there are no more
	forks available, otherwise leave it on.
	(sigchld_handler): Assure this is called only in sync mode.
	(linux_async_permitted, linux_async_permitted_1): New globals.
	(set_maintenance_linux_async_permitted)
	(show_maintenance_linux_async_permitted): New functions.
	(linux_nat_is_async_p, linux_nat_can_async_p)
	(linux_nat_async_mask): New.
	(linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New.
	(get_pending_events, async_sigchld_handler): New.
	(linux_nat_async_events): New.
	(async_terminal_is_ours): New global.
	(linux_nat_terminal_inferior, linux_nat_terminal_ours): New.
	(async_client_callback, async_client_context): New.
	(linux_nat_async_file_handler, linux_nat_async)
	(linux_nat_disable_async, linux_nat_enable_async): New.
	(linux_nat_add_target): Register linux_nat_create_inferior,
	linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async,
	linux_nat_async_mask, linux_nat_terminal_inferior and
	linux_nat_terminal_ours.
	(_initialize_linux_nat): Remove local action variable, and update
	code that used it to use sync_sigchld_action.  Add new
	"lin-lwp-async" debug set/show command.  Put the "lin-lwp" debug
	set/show command in the maintenance class.  Add new "linux-async"
	maintenance set/show command.  Block SIGCHLD by default.  Setup
	async_sichld_action, and sync_sigchld_action.  Install the default
	async mode.
	(lin_thread_get_thread_signals): Use a local sigset_t for blocking
	the cancel signals.

	* linux-thread-db.c (re_check_for_thread_db): New.
	(clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE.
	(thread_db_can_async_p, thread_db_is_async_p, thread_db_async)
	(thread_db_async_mask): New.
	(init_thread_db_ops): Register thread_db_can_async_p,
	thread_db_is_async_p, thread_db_async and thread_db_async_mask.

	* remote.c (remote_async_mask_value): New.
	(remote_return_zero): New.
	(init_remote_ops): Register remote_return_zero as callbacks of
	to_can_async_p and to_is_async_p.
	(remote_can_async_p, remote_is_async_p, remote_async): Update to
	use remote_async_mask_value.
	(remote_async_mask): New.
	(init_remote_async_ops): Remove to_async_mask_value setting and
	register remote_async_mask as to_async_mask callback in
	remote_async_ops.

	* Makefile.in (linux-nat.o): Update.

gdb/doc/
	* gdb.texinfo (Debugging Output): Document
	"set/show debug lin-lwp-async".
	(Maintenance Commands): Document "maint set/show linux-async".
This commit is contained in:
Pedro Alves 2008-03-21 17:09:35 +00:00
parent 08b55522ea
commit b84876c212
9 changed files with 1029 additions and 81 deletions

View file

@ -1,3 +1,105 @@
2008-03-21 Pedro Alves <pedro@codesourcery.com>
Linux native async support.
* target.h (struct target_ops): Delete to_async_mask_value and add
to_async_mask.
(target_is_async_p, target_async): Formatting.
(target_async_mask_value): Delete.
(target_async_mask): Delete function declaration, and add new
target macro with the same name.
* target.c (update_current_target): Replace to_async_mask_value by
to_async_mask. Default to_async_mask to return_one.
(target_async_mask): Delete.
(find_default_can_async_p, find_default_is_async_p): New.
(init_dummy_target): register find_default_can_async_p and
find_default_is_async_p on the dummy target.
* linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h.
(debug_linux_nat_async): New global.
(show_debug_linux_nat_async): New function.
(linux_nat_async_enabled, linux_nat_async_mask_value)
(linux_nat_event_pipe, linux_nat_num_queued_events)
(linux_nat_async_events_enabled): New globals.
(struct waitpid_result): New struct.
(waitpid_queue): New global.
(queued_waitpid, push_waitpid, drain_queued_events): New.
(my_waitpid): Call queued_waitpid.
(linux_child_follow_fork): Disable async events during the call.
(blocked_mask): Delete.
(sync_sigchld_action, async_sigchld_action): New globals.
(lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In
async mode, block events during the call.
(linux_nat_create_inferior): New.
(linux_nat_attach): In sync mode, restore the mask states. In
async mode, wake the event loop immediatelly.
(detach_callback): Drain all queued events of the lwp we're
detaching from.
(linux_nat_detach): Block async mode, and drain events of the main
process.
(linux_nat_resume): If in async mode, mask async events during the
call. If short circuiting, force event loop to wake up. If
resuming, set target_executing, and register target events in the
event loop.
(pipe_to_local_event_queue, local_event_queue_to_pipe): New.
(linux_nat_wait): In async mode, block events during the call.
Only enable/disable passing SIGINT to the inferior in sync mode.
Get events from local waitpid queue. If no interesting events was
found, return to events loop. Reregister target events in the
event loop on exit. In sync mode, no need to reblock SIGCHLD.
(linux_nat_kill): Disable events on entry.
(linux_nat_mourn_inferior): In sync mode, don't restore the masks
here. Detach async mode from the event loop if there are no more
forks available, otherwise leave it on.
(sigchld_handler): Assure this is called only in sync mode.
(linux_async_permitted, linux_async_permitted_1): New globals.
(set_maintenance_linux_async_permitted)
(show_maintenance_linux_async_permitted): New functions.
(linux_nat_is_async_p, linux_nat_can_async_p)
(linux_nat_async_mask): New.
(linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New.
(get_pending_events, async_sigchld_handler): New.
(linux_nat_async_events): New.
(async_terminal_is_ours): New global.
(linux_nat_terminal_inferior, linux_nat_terminal_ours): New.
(async_client_callback, async_client_context): New.
(linux_nat_async_file_handler, linux_nat_async)
(linux_nat_disable_async, linux_nat_enable_async): New.
(linux_nat_add_target): Register linux_nat_create_inferior,
linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async,
linux_nat_async_mask, linux_nat_terminal_inferior and
linux_nat_terminal_ours.
(_initialize_linux_nat): Remove local action variable, and update
code that used it to use sync_sigchld_action. Add new
"lin-lwp-async" debug set/show command. Put the "lin-lwp" debug
set/show command in the maintenance class. Add new "linux-async"
maintenance set/show command. Block SIGCHLD by default. Setup
async_sichld_action, and sync_sigchld_action. Install the default
async mode.
(lin_thread_get_thread_signals): Use a local sigset_t for blocking
the cancel signals.
* linux-thread-db.c (re_check_for_thread_db): New.
(clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE.
(thread_db_can_async_p, thread_db_is_async_p, thread_db_async)
(thread_db_async_mask): New.
(init_thread_db_ops): Register thread_db_can_async_p,
thread_db_is_async_p, thread_db_async and thread_db_async_mask.
* remote.c (remote_async_mask_value): New.
(remote_return_zero): New.
(init_remote_ops): Register remote_return_zero as callbacks of
to_can_async_p and to_is_async_p.
(remote_can_async_p, remote_is_async_p, remote_async): Update to
use remote_async_mask_value.
(remote_async_mask): New.
(init_remote_async_ops): Remove to_async_mask_value setting and
register remote_async_mask as to_async_mask callback in
remote_async_ops.
* Makefile.in (linux-nat.o): Update.
2008-03-21 Daniel Jacobowitz <dan@codesourcery.com>
* gdbthread.h (add_thread_with_info): New.

View file

@ -2351,7 +2351,7 @@ linux-nat.o: linux-nat.c $(defs_h) $(inferior_h) $(target_h) $(gdb_string_h) \
$(gdb_wait_h) $(gdb_assert_h) $(linux_nat_h) $(gdbthread_h) \
$(gdbcmd_h) $(regcache_h) $(regset_h) $(inf_ptrace_h) $(auxv_h) \
$(elf_bfd_h) $(gregset_h) $(gdbcore_h) $(gdbthread_h) $(gdb_stat_h) \
$(linux_fork_h)
$(linux_fork_h) $(inf_loop_h) $(event_loop_h) $(event_top_h)
linux-thread-db.o: linux-thread-db.c $(defs_h) $(gdb_assert_h) \
$(gdb_proc_service_h) $(gdb_thread_db_h) $(bfd_h) $(exceptions_h) \
$(gdbthread_h) $(inferior_h) $(symfile_h) $(objfiles_h) $(target_h) \

View file

@ -1,3 +1,9 @@
2008-03-21 Pedro Alves <pedro@codesourcery.com>
* gdb.texinfo (Debugging Output): Document
"set/show debug lin-lwp-async".
(Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 Daniel Jacobowitz <dan@codesourcery.com>
* gdb.texinfo (Expressions): Update description of malloced arrays.

View file

@ -16407,6 +16407,12 @@ Displays the current state of @value{GDBN} inferior debugging.
Turns on or off debugging messages from the Linux LWP debug support.
@item show debug lin-lwp
Show the current state of Linux LWP debugging messages.
@item set debug lin-lwp-async
@cindex @sc{gnu}/Linux LWP async debug messages
@cindex Linux lightweight processes
Turns on or off debugging messages from the Linux LWP async debug support.
@item show debug lin-lwp-async
Show the current state of Linux LWP async debugging messages.
@item set debug observer
@cindex observer debugging info
Turns on or off display of @value{GDBN} observer debugging. This
@ -23242,6 +23248,16 @@ data in a @file{gmon.out} file, be sure to move it to a safe location.
Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
compiled with the @samp{-pg} compiler option.
@kindex maint set linux-async
@kindex maint show linux-async
@cindex asynchronous support
@item maint set linux-async
@itemx maint show linux-async
Control the GNU/Linux native asynchronous support of @value{GDBN}.
GNU/Linux native asynchronous support will be disabled until you use
the @samp{maint set linux-async} command to enable it.
@kindex maint show-debug-regs
@cindex x86 hardware debug registers
@item maint show-debug-regs

File diff suppressed because it is too large Load diff

View file

@ -824,6 +824,9 @@ thread_db_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
ptid = target_beneath->to_wait (ptid, ourstatus);
if (ourstatus->kind == TARGET_WAITKIND_IGNORE)
return ptid;
if (ourstatus->kind == TARGET_WAITKIND_EXITED
|| ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
return pid_to_ptid (-1);
@ -884,6 +887,31 @@ thread_db_mourn_inferior (void)
using_thread_db = 0;
}
static int
thread_db_can_async_p (void)
{
return target_beneath->to_can_async_p ();
}
static int
thread_db_is_async_p (void)
{
return target_beneath->to_is_async_p ();
}
static void
thread_db_async (void (*callback) (enum inferior_event_type event_type,
void *context), void *context)
{
return target_beneath->to_async (callback, context);
}
static int
thread_db_async_mask (int mask)
{
return target_beneath->to_async_mask (mask);
}
static int
find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
{
@ -1056,6 +1084,10 @@ init_thread_db_ops (void)
thread_db_ops.to_get_thread_local_address
= thread_db_get_thread_local_address;
thread_db_ops.to_extra_thread_info = thread_db_extra_thread_info;
thread_db_ops.to_can_async_p = thread_db_can_async_p;
thread_db_ops.to_is_async_p = thread_db_is_async_p;
thread_db_ops.to_async = thread_db_async;
thread_db_ops.to_async_mask = thread_db_async_mask;
thread_db_ops.to_magic = OPS_MAGIC;
}

View file

@ -481,6 +481,8 @@ static struct target_ops extended_remote_ops;
extended_remote_ops, but with asynchronous support. */
static struct target_ops remote_async_ops;
static int remote_async_mask_value = 1;
static struct target_ops extended_async_remote_ops;
/* FIXME: cagney/1999-09-23: Even though getpkt was called with
@ -7176,6 +7178,12 @@ remote_command (char *args, int from_tty)
help_list (remote_cmdlist, "remote ", -1, gdb_stdout);
}
static int
remote_return_zero (void)
{
return 0;
}
static void
init_remote_ops (void)
{
@ -7229,6 +7237,8 @@ Specify the serial device it is connected to\n\
remote_ops.to_flash_erase = remote_flash_erase;
remote_ops.to_flash_done = remote_flash_done;
remote_ops.to_read_description = remote_read_description;
remote_ops.to_can_async_p = remote_return_zero;
remote_ops.to_is_async_p = remote_return_zero;
}
/* Set up the extended remote vector by making a copy of the standard
@ -7256,14 +7266,14 @@ static int
remote_can_async_p (void)
{
/* We're async whenever the serial device is. */
return (current_target.to_async_mask_value) && serial_can_async_p (remote_desc);
return remote_async_mask_value && serial_can_async_p (remote_desc);
}
static int
remote_is_async_p (void)
{
/* We're async whenever the serial device is. */
return (current_target.to_async_mask_value) && serial_is_async_p (remote_desc);
return remote_async_mask_value && serial_is_async_p (remote_desc);
}
/* Pass the SERIAL event on and up to the client. One day this code
@ -7287,7 +7297,7 @@ static void
remote_async (void (*callback) (enum inferior_event_type event_type,
void *context), void *context)
{
if (current_target.to_async_mask_value == 0)
if (remote_async_mask_value == 0)
internal_error (__FILE__, __LINE__,
_("Calling remote_async when async is masked"));
@ -7301,6 +7311,14 @@ remote_async (void (*callback) (enum inferior_event_type event_type,
serial_async (remote_desc, NULL, NULL);
}
static int
remote_async_mask (int new_mask)
{
int curr_mask = remote_async_mask_value;
remote_async_mask_value = new_mask;
return curr_mask;
}
/* Target async and target extended-async.
This are temporary targets, until it is all tested. Eventually
@ -7360,7 +7378,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
remote_async_ops.to_can_async_p = remote_can_async_p;
remote_async_ops.to_is_async_p = remote_is_async_p;
remote_async_ops.to_async = remote_async;
remote_async_ops.to_async_mask_value = 1;
remote_async_ops.to_async_mask = remote_async_mask;
remote_async_ops.to_magic = OPS_MAGIC;
remote_async_ops.to_memory_map = remote_memory_map;
remote_async_ops.to_flash_erase = remote_flash_erase;

View file

@ -464,7 +464,7 @@ update_current_target (void)
INHERIT (to_can_async_p, t);
INHERIT (to_is_async_p, t);
INHERIT (to_async, t);
INHERIT (to_async_mask_value, t);
INHERIT (to_async_mask, t);
INHERIT (to_find_memory_regions, t);
INHERIT (to_make_corefile_notes, t);
INHERIT (to_get_thread_local_address, t);
@ -637,6 +637,9 @@ update_current_target (void)
de_fault (to_async,
(void (*) (void (*) (enum inferior_event_type, void*), void*))
tcomplain);
de_fault (to_async_mask,
(int (*) (int))
return_one);
current_target.to_read_description = NULL;
#undef de_fault
@ -1694,14 +1697,6 @@ target_disconnect (char *args, int from_tty)
tcomplain ();
}
int
target_async_mask (int mask)
{
int saved_async_masked_status = target_async_mask_value;
target_async_mask_value = mask;
return saved_async_masked_status;
}
/* Look through the list of possible targets for a target that can
follow forks. */
@ -1835,6 +1830,28 @@ find_default_create_inferior (char *exec_file, char *allargs, char **env,
return;
}
int
find_default_can_async_p (void)
{
struct target_ops *t;
t = find_default_run_target ("async");
if (t->to_can_async_p)
return (t->to_can_async_p) ();
return 0;
}
int
find_default_is_async_p (void)
{
struct target_ops *t;
t = find_default_run_target ("async");
if (t->to_is_async_p)
return (t->to_is_async_p) ();
return 0;
}
static int
default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
{
@ -2099,6 +2116,8 @@ init_dummy_target (void)
dummy_target.to_doc = "";
dummy_target.to_attach = find_default_attach;
dummy_target.to_create_inferior = find_default_create_inferior;
dummy_target.to_can_async_p = find_default_can_async_p;
dummy_target.to_is_async_p = find_default_is_async_p;
dummy_target.to_pid_to_str = normal_pid_to_str;
dummy_target.to_stratum = dummy_stratum;
dummy_target.to_find_memory_regions = dummy_find_memory_regions;

View file

@ -414,9 +414,8 @@ struct target_ops
/* ASYNC target controls */
int (*to_can_async_p) (void);
int (*to_is_async_p) (void);
void (*to_async) (void (*cb) (enum inferior_event_type, void *context),
void *context);
int to_async_mask_value;
void (*to_async) (void (*) (enum inferior_event_type, void *), void *);
int (*to_async_mask) (int);
int (*to_find_memory_regions) (int (*) (CORE_ADDR,
unsigned long,
int, int, int,
@ -938,11 +937,11 @@ int target_follow_fork (int follow_child);
#define target_can_async_p() (current_target.to_can_async_p ())
/* Is the target in asynchronous execution mode? */
#define target_is_async_p() (current_target.to_is_async_p())
#define target_is_async_p() (current_target.to_is_async_p ())
/* Put the target in async mode with the specified callback function. */
#define target_async(CALLBACK,CONTEXT) \
(current_target.to_async((CALLBACK), (CONTEXT)))
(current_target.to_async ((CALLBACK), (CONTEXT)))
/* This is to be used ONLY within call_function_by_hand(). It provides
a workaround, to have inferior function calls done in sychronous
@ -958,10 +957,8 @@ int target_follow_fork (int follow_child);
the turning async on and off to the single execution commands,
from where it is done currently, in remote_resume(). */
#define target_async_mask_value \
(current_target.to_async_mask_value)
extern int target_async_mask (int mask);
#define target_async_mask(MASK) \
(current_target.to_async_mask (MASK))
/* Converts a process id to a string. Usually, the string just contains
`process xyz', but on some systems it may contain