This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] Using bt command in async mode
- From: Nick Roberts <nickrob at snap dot net dot nz>
- To: gdb-patches at sourceware dot org
- Date: Tue, 1 Apr 2008 13:59:42 +1200
- Subject: [RFC] Using bt command in async mode
This patch allows the bt to be executed in async mode while the inferior is
executing. The idea being that the frontend can get a snapshot of what the
inferior is doing and update the UI. It's just a proof of concept, so I've
used linux_nat_async_events and my_waitpid directly but eventually these could
be made into target methods, of course.
If the general idea is agreeable, I would like to extend it to other commands
like "info locals", "info threads" etc.
An example session looks like this:
(gdb) maintenance set linux-async on
(gdb) r&
Starting program: /home/nickrob/donowt
(gdb) bt
#0 0x080483c9 in mysub1 () at donowt.c:12
#1 0x080483f7 in mysub () at donowt.c:22
#2 0x0804840f in main () at donowt.c:28
(gdb) interrupt
(gdb)
Program received signal SIGINT, Interrupt.
0x080483c9 in mysub1 () at donowt.c:12
12 if (i == 5)
(gdb) quit
The program is running. Quit anyway (and kill it)? (y or n) y
nickrob@kahikatea:~$
--
Nick http://www.inet.net.nz/~nickrob
2008-04-01 Nick Roberts <nickrob@snap.net.nz>
* stack.c (backtrace_command): Make it work in async mode when
the target is executing.
* top.c (execute_command): Enable bt command in async mode.
* inferior.h: New externs
* linux-nat.c (linux_nat_async_events, my_waitpid): Make
non-static.
*** stack.c 18 Mar 2008 08:32:24 +1200 1.164
--- stack.c 01 Apr 2008 12:58:57 +1200
*************** static void
*** 1285,1293 ****
backtrace_command (char *arg, int from_tty)
{
struct cleanup *old_chain = NULL;
! int fulltrace_arg = -1, arglen = 0, argc = 0;
struct backtrace_command_args btargs;
if (arg)
{
char **argv;
--- 1285,1306 ----
backtrace_command (char *arg, int from_tty)
{
struct cleanup *old_chain = NULL;
! int fulltrace_arg = -1, arglen = 0, argc = 0, restart = 0;
struct backtrace_command_args btargs;
+ if (target_executing)
+ {
+ int status, options, async_events_were_enabled;
+
+ /* Must be async to get here. */
+ async_events_were_enabled = linux_nat_async_events (0);
+ target_stop ();
+ my_waitpid (PIDGET (inferior_ptid), &status, 0);
+ if (async_events_were_enabled)
+ linux_nat_async_events (1);
+ restart = 1;
+ }
+
if (arg)
{
char **argv;
*************** backtrace_command (char *arg, int from_t
*** 1342,1347 ****
--- 1355,1363 ----
if (old_chain)
do_cleanups (old_chain);
+
+ if (restart)
+ continue_command ("&", 0);
}
static void
*** top.c 01 Apr 2008 13:47:11 +1200 1.137
--- top.c 01 Apr 2008 13:35:00 +1200
*************** execute_command (char *p, int from_tty)
*** 463,469 ****
&& strcmp (c->name, "pwd") != 0
&& strcmp (c->name, "show") != 0
&& strcmp (c->name, "info") != 0
! && strcmp (c->name, "interrupt") != 0)
error (_("Cannot execute this command while the target is running."));
/* Pass null arg rather than an empty one. */
--- 463,470 ----
&& strcmp (c->name, "pwd") != 0
&& strcmp (c->name, "show") != 0
&& strcmp (c->name, "info") != 0
! && strcmp (c->name, "interrupt") != 0
! && strcmp (c->name, "bt") != 0)
error (_("Cannot execute this command while the target is running."));
/* Pass null arg rather than an empty one. */
*** inferior.h 30 Jan 2008 11:18:32 +1300 1.87
--- inferior.h 01 Apr 2008 09:24:04 +1200
*************** struct regcache;
*** 49,54 ****
--- 49,57 ----
struct inferior_status;
+ extern int my_waitpid (int pid, int *status, int flags);
+ extern int linux_nat_async_events (int enable);
+
extern struct inferior_status *save_inferior_status (int);
extern void restore_inferior_status (struct inferior_status *);
*** linux-nat.c 26 Mar 2008 08:51:33 +1200 1.80
--- linux-nat.c 01 Apr 2008 13:10:00 +1200
*************** static volatile int linux_nat_num_queued
*** 176,182 ****
target events are blocked. */
static int linux_nat_async_events_enabled;
- static int linux_nat_async_events (int enable);
static void pipe_to_local_event_queue (void);
static void local_event_queue_to_pipe (void);
static void linux_nat_event_pipe_push (int pid, int status, int options);
--- 176,181 ----
*************** linux_tracefork_child (void)
*** 350,356 ****
/* Wrapper function for waitpid which handles EINTR, and checks for
locally queued events. */
! static int
my_waitpid (int pid, int *status, int flags)
{
int ret;
--- 349,355 ----
/* Wrapper function for waitpid which handles EINTR, and checks for
locally queued events. */
! int
my_waitpid (int pid, int *status, int flags)
{
int ret;
*************** async_sigchld_handler (int signo)
*** 3820,3826 ****
/* Enable or disable async SIGCHLD handling. */
! static int
linux_nat_async_events (int enable)
{
int current_state = linux_nat_async_events_enabled;
--- 3819,3825 ----
/* Enable or disable async SIGCHLD handling. */
! int
linux_nat_async_events (int enable)
{
int current_state = linux_nat_async_events_enabled;