From 0d6431e2551df9cc004817a09f19a752b959ec66 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Sat, 16 Aug 2008 23:51:14 +0000 Subject: [PATCH] * gdbthread.h: Add comments. * stack.c (get_selected_block): Return 0 on an exited thread. * top.c (execute_command): Check for is_stopped, not !is_running. * event-top.c (command_handler): Likewise. --- gdb/ChangeLog | 7 +++++++ gdb/event-top.c | 2 +- gdb/gdbthread.h | 33 ++++++++++++++++++++++++++------- gdb/stack.c | 3 +++ gdb/top.c | 2 +- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3d590003893..8dd19606082 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2008-08-17 Pedro Alves + + * gdbthread.h: Add comments. + * stack.c (get_selected_block): Return 0 on an exited thread. + * top.c (execute_command): Check for is_stopped, not !is_running. + * event-top.c (command_handler): Likewise. + 2008-08-16 Pedro Alves * mi/mi-main.c (mi_cmd_exec_next, mi_cmd_exec_next_instruction) diff --git a/gdb/event-top.c b/gdb/event-top.c index 722c28e1792..61c431dabf2 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -518,7 +518,7 @@ command_handler (char *command) /* Do any commands attached to breakpoint we stopped at. Only if we are always running synchronously. Or if we have just executed a command that doesn't start the target. */ - if (!target_can_async_p () || !is_running (inferior_ptid)) + if (!target_can_async_p () || is_stopped (inferior_ptid)) { bpstat_do_actions (&stop_bpstat); do_cleanups (old_chain); diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index f283865ccc5..780ec251c76 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -210,21 +210,40 @@ extern void switch_to_thread (ptid_t ptid); If PIDGET (PTID) is -1, marks all threads. */ extern void set_running (ptid_t ptid, int running); -/* Reports if thread PTID is known to be running right now. */ -extern int is_running (ptid_t ptid); +/* NOTE: Since the thread state is not a boolean, most times, you do + not want to check it with negation. If you really want to check if + the thread is stopped, -/* Reports if any thread is known to be running right now. */ -extern int any_running (void); + use (good): + + if (is_stopped (ptid)) + + instead of (bad): + + if (!is_running (ptid)) + + The latter also returns true on exited threads, most likelly not + what you want. */ + +/* Reports if in the frontend's perpective, thread PTID is running. */ +extern int is_running (ptid_t ptid); /* Is this thread listed, but known to have exited? We keep it listed (but not visible) until it's safe to delete. */ extern int is_exited (ptid_t ptid); -/* Is this thread stopped? */ +/* In the frontend's perpective, is this thread stopped? */ extern int is_stopped (ptid_t ptid); -/* Marks thread PTID as executing, or as stopped. - If PIDGET (PTID) is -1, marks all threads. */ +/* In the frontend's perpective is there any thread running? */ +extern int any_running (void); + +/* Marks thread PTID as executing, or not. If PIDGET (PTID) is -1, + marks all threads. + + Note that this is different from the running state. See the + description of state_ and executing_ fields of struct + thread_info. */ extern void set_executing (ptid_t ptid, int executing); /* Reports if thread PTID is executing. */ diff --git a/gdb/stack.c b/gdb/stack.c index 18c4298ed7f..ca39d48a289 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1644,6 +1644,9 @@ get_selected_block (CORE_ADDR *addr_in_block) if (!target_has_stack) return 0; + if (is_exited (inferior_ptid)) + return 0; + if (is_executing (inferior_ptid)) return 0; diff --git a/gdb/top.c b/gdb/top.c index 0ae7ea020ff..52d1a0ef523 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -477,7 +477,7 @@ Cannot execute this command without a live selected thread. See `help thread'." /* FIXME: This should be cacheing the frame and only running when the frame changes. */ - if (target_has_stack && !is_running (inferior_ptid)) + if (target_has_stack && is_stopped (inferior_ptid)) { flang = get_frame_language (); if (!warned -- 2.30.2