diff options
author | Doug Evans <dje@google.com> | 2009-01-19 19:05:01 +0000 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2009-01-19 19:05:01 +0000 |
commit | b89667ebd42a3a59b8f17ec9153d07dd2fc7e5e1 (patch) | |
tree | 8789d7e1d5edcf4019b51d276a77fc5fe649d699 | |
parent | 63f2573fe476336550cf141d09a62bc1a349eba2 (diff) | |
download | gdb-b89667ebd42a3a59b8f17ec9153d07dd2fc7e5e1.zip gdb-b89667ebd42a3a59b8f17ec9153d07dd2fc7e5e1.tar.gz gdb-b89667ebd42a3a59b8f17ec9153d07dd2fc7e5e1.tar.bz2 |
* dummy-frame.c (dummy_frame): Replace regcache member with
caller_state.
(dummy_frame_push): Replace caller_regcache arg with caller_state.
All callers updated.
(remove_dummy_frame,pop_dummy_frame,lookup_dummy_frame): New fns.
(dummy_frame_pop): Rewrite. Verify requested frame is in the
dummy frame stack. Restore program state.
(cleanup_dummy_frames): Rewrite.
(dummy_frame_sniffer): Update. Make static.
* dummy-frame.h (regcache,frame_info): Delete forward decls.
(inferior_thread_state): New forward decl.
(dummy_frame_push): Update prototype.
* frame.c (frame_pop): dummy_frame_pop now does all the work for
DUMMY_FRAMEs.
* infcall.c (breakpoint_auto_delete_contents): Delete.
(get_function_name,run_inferior_call): New fns.
(call_function_by_hand): Simplify by moving some code to
get_function_name, run_inferior_call. Inferior function call wrapped
in TRY_CATCH so there's less need for cleanups and all exits from
proceed are handled similarily. Detect program exit.
Detect program stopping in a different thread.
Make error messages more consistent.
* inferior.h (inferior_thread_state): Declare (opaque type).
(save_inferior_thread_state,restore_inferior_thread_state,
make_cleanup_restore_inferior_thread_state,
discard_inferior_thread_state, get_inferior_thread_state_regcache):
Declare.
(save_inferior_status): Update prototype.
* infrun.c: (normal_stop): When stopped for the completion of an
inferior function call, verify the expected stack frame kind.
(inferior_thread_state): New struct.
(save_inferior_thread_state,restore_inferior_thread_state,
do_restore_inferior_thread_state_cleanup,
make_cleanup_restore_inferior_thread_state,
discard_inferior_thread_state,
get_inferior_thread_state_regcache): New functions.
(inferior_status): Move stop_signal, stop_pc, registers to
inferior_thread_state. Remove restore_stack_info.
(save_inferior_status): Remove arg restore_stack_info.
All callers updated. Remove saving of state now saved by
save_inferior_thread_state.
(restore_inferior_status): Remove restoration of state now done by
restore_inferior_thread_state.
(discard_inferior_status): Remove freeing of registers, now done by
discard_inferior_thread_state.
* gdb.base/break.exp: Update expected gdb output.
* gdb.base/sepdebug.exp: Ditto.
* gdb.mi/mi-syn-frame.exp: Ditto.
* gdb.mi/mi2-syn-frame.exp: Ditto.
* gdb.base/call-signal-resume.exp: New file.
* gdb.base/call-signals.c: New file.
* gdb.base/unwindonsignal.exp: New file.
* gdb.base/unwindonsignal.c: New file.
* gdb.threads/interrupted-hand-call.exp: New file.
* gdb.threads/interrupted-hand-call.c: New file.
* gdb.threads/thread-unwindonsignal.exp: New file.
-rw-r--r-- | gdb/ChangeLog | 48 | ||||
-rw-r--r-- | gdb/dummy-frame.c | 112 | ||||
-rw-r--r-- | gdb/dummy-frame.h | 16 | ||||
-rw-r--r-- | gdb/frame.c | 13 | ||||
-rw-r--r-- | gdb/infcall.c | 375 | ||||
-rw-r--r-- | gdb/inferior.h | 28 | ||||
-rw-r--r-- | gdb/infrun.c | 144 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 14 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/break.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/call-signal-resume.exp | 159 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/call-signals.c | 89 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/sepdebug.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/unwindonsignal.c | 65 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/unwindonsignal.exp | 98 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-syn-frame.exp | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi2-syn-frame.exp | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/interrupted-hand-call.c | 149 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/interrupted-hand-call.exp | 92 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/thread-unwindonsignal.exp | 117 |
19 files changed, 1301 insertions, 236 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cbd3dad..03c1159 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,51 @@ +2009-01-19 Doug Evans <dje@google.com> + + * dummy-frame.c (dummy_frame): Replace regcache member with + caller_state. + (dummy_frame_push): Replace caller_regcache arg with caller_state. + All callers updated. + (remove_dummy_frame,pop_dummy_frame,lookup_dummy_frame): New fns. + (dummy_frame_pop): Rewrite. Verify requested frame is in the + dummy frame stack. Restore program state. + (cleanup_dummy_frames): Rewrite. + (dummy_frame_sniffer): Update. Make static. + * dummy-frame.h (regcache,frame_info): Delete forward decls. + (inferior_thread_state): New forward decl. + (dummy_frame_push): Update prototype. + * frame.c (frame_pop): dummy_frame_pop now does all the work for + DUMMY_FRAMEs. + * infcall.c (breakpoint_auto_delete_contents): Delete. + (get_function_name,run_inferior_call): New fns. + (call_function_by_hand): Simplify by moving some code to + get_function_name, run_inferior_call. Inferior function call wrapped + in TRY_CATCH so there's less need for cleanups and all exits from + proceed are handled similarily. Detect program exit. + Detect program stopping in a different thread. + Make error messages more consistent. + * inferior.h (inferior_thread_state): Declare (opaque type). + (save_inferior_thread_state,restore_inferior_thread_state, + make_cleanup_restore_inferior_thread_state, + discard_inferior_thread_state, get_inferior_thread_state_regcache): + Declare. + (save_inferior_status): Update prototype. + * infrun.c: (normal_stop): When stopped for the completion of an + inferior function call, verify the expected stack frame kind. + (inferior_thread_state): New struct. + (save_inferior_thread_state,restore_inferior_thread_state, + do_restore_inferior_thread_state_cleanup, + make_cleanup_restore_inferior_thread_state, + discard_inferior_thread_state, + get_inferior_thread_state_regcache): New functions. + (inferior_status): Move stop_signal, stop_pc, registers to + inferior_thread_state. Remove restore_stack_info. + (save_inferior_status): Remove arg restore_stack_info. + All callers updated. Remove saving of state now saved by + save_inferior_thread_state. + (restore_inferior_status): Remove restoration of state now done by + restore_inferior_thread_state. + (discard_inferior_status): Remove freeing of registers, now done by + discard_inferior_thread_state. + 2009-01-18 Pedro Alves <pedro@codesourcery.com> * tui/tui-disasm.c (tui_vertical_disassem_scroll): Scroll one line diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c index 8e3708d..6e63686 100644 --- a/gdb/dummy-frame.c +++ b/gdb/dummy-frame.c @@ -42,8 +42,8 @@ struct dummy_frame /* This frame's ID. Must match the value returned by gdbarch_dummy_id. */ struct frame_id id; - /* The caller's regcache. */ - struct regcache *regcache; + /* The caller's state prior to the call. */ + struct inferior_thread_state *caller_state; }; static struct dummy_frame *dummy_frame_stack = NULL; @@ -81,61 +81,101 @@ deprecated_pc_in_call_dummy (CORE_ADDR pc) return 0; } -/* Push the caller's state, along with the dummy frame info, onto a +/* Push the caller's state, along with the dummy frame info, onto the dummy-frame stack. */ void -dummy_frame_push (struct regcache *caller_regcache, +dummy_frame_push (struct inferior_thread_state *caller_state, const struct frame_id *dummy_id) { struct dummy_frame *dummy_frame; dummy_frame = XZALLOC (struct dummy_frame); - dummy_frame->regcache = caller_regcache; + dummy_frame->caller_state = caller_state; dummy_frame->id = (*dummy_id); dummy_frame->next = dummy_frame_stack; dummy_frame_stack = dummy_frame; } -/* Pop the dummy frame with ID dummy_id from the dummy-frame stack. */ +/* Remove *DUMMY_PTR from the dummy frame stack. */ -void -dummy_frame_pop (struct frame_id dummy_id) +static void +remove_dummy_frame (struct dummy_frame **dummy_ptr) { - struct dummy_frame **dummy_ptr; + struct dummy_frame *dummy = *dummy_ptr; - for (dummy_ptr = &dummy_frame_stack; - (*dummy_ptr) != NULL; - dummy_ptr = &(*dummy_ptr)->next) - { - struct dummy_frame *dummy = *dummy_ptr; - if (frame_id_eq (dummy->id, dummy_id)) - { - *dummy_ptr = dummy->next; - regcache_xfree (dummy->regcache); - xfree (dummy); - break; - } - } + *dummy_ptr = dummy->next; + discard_inferior_thread_state (dummy->caller_state); + xfree (dummy); } -/* There may be stale dummy frames, perhaps left over from when a longjump took us - out of a function that was called by the debugger. Clean them up at least once - whenever we start a new inferior. */ +/* Pop *DUMMY_PTR, restoring program state to that before the + frame was created. */ static void -cleanup_dummy_frames (struct target_ops *target, int from_tty) +pop_dummy_frame (struct dummy_frame **dummy_ptr) { - struct dummy_frame *dummy, *next; + struct dummy_frame *dummy; - for (dummy = dummy_frame_stack; dummy; dummy = next) + restore_inferior_thread_state ((*dummy_ptr)->caller_state); + + /* restore_inferior_status frees inf_state, + all that remains is to pop *dummy_ptr */ + dummy = *dummy_ptr; + *dummy_ptr = dummy->next; + xfree (dummy); + + /* We've made right mess of GDB's local state, just discard + everything. */ + reinit_frame_cache (); +} + +/* Look up DUMMY_ID. + Return NULL if not found. */ + +static struct dummy_frame ** +lookup_dummy_frame (struct frame_id dummy_id) +{ + struct dummy_frame **dp; + + for (dp = &dummy_frame_stack; *dp != NULL; dp = &(*dp)->next) { - next = dummy->next; - regcache_xfree (dummy->regcache); - xfree (dummy); + if (frame_id_eq ((*dp)->id, dummy_id)) + return dp; } - dummy_frame_stack = NULL; + return NULL; +} + +/* Pop the dummy frame DUMMY_ID, restoring program state to that before the + frame was created. + On return reinit_frame_cache has been called. + If the frame isn't found, flag an internal error. + + NOTE: This can only pop the one frame, even if it is in the middle of the + stack, because the other frames may be for different threads, and there's + currently no way to tell which stack frame is for which thread. */ + +void +dummy_frame_pop (struct frame_id dummy_id) +{ + struct dummy_frame **dp; + + dp = lookup_dummy_frame (dummy_id); + gdb_assert (dp != NULL); + + pop_dummy_frame (dp); +} + +/* There may be stale dummy frames, perhaps left over from when a longjump took + us out of a function that was called by the debugger. Clean them up at + least once whenever we start a new inferior. */ + +static void +cleanup_dummy_frames (struct target_ops *target, int from_tty) +{ + while (dummy_frame_stack != NULL) + remove_dummy_frame (&dummy_frame_stack); } /* Return the dummy frame cache, it contains both the ID, and a @@ -146,7 +186,7 @@ struct dummy_frame_cache struct regcache *prev_regcache; }; -int +static int dummy_frame_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache) @@ -162,7 +202,7 @@ dummy_frame_sniffer (const struct frame_unwind *self, that PC to apply standard frame ID unwind techniques is just asking for trouble. */ - /* Don't bother unles there is at least one dummy frame. */ + /* Don't bother unless there is at least one dummy frame. */ if (dummy_frame_stack != NULL) { /* Use an architecture specific method to extract this frame's @@ -178,7 +218,7 @@ dummy_frame_sniffer (const struct frame_unwind *self, { struct dummy_frame_cache *cache; cache = FRAME_OBSTACK_ZALLOC (struct dummy_frame_cache); - cache->prev_regcache = dummyframe->regcache; + cache->prev_regcache = get_inferior_thread_state_regcache (dummyframe->caller_state); cache->this_id = this_id; (*this_prologue_cache) = cache; return 1; @@ -215,7 +255,7 @@ dummy_frame_prev_register (struct frame_info *this_frame, return reg_val; } -/* Assuming that THIS frame is a dummy, return the ID of THIS frame. That ID is +/* Assuming that THIS_FRAME is a dummy, return its ID. That ID is determined by examining the NEXT frame's unwound registers using the method dummy_id(). As a side effect, THIS dummy frame's dummy cache is located and and saved in THIS_PROLOGUE_CACHE. */ diff --git a/gdb/dummy-frame.h b/gdb/dummy-frame.h index ea4da66..5262ddf 100644 --- a/gdb/dummy-frame.h +++ b/gdb/dummy-frame.h @@ -22,8 +22,7 @@ #include "frame.h" -struct frame_info; -struct regcache; +struct inferior_thread_state; struct frame_unwind; /* Push the information needed to identify, and unwind from, a dummy @@ -39,8 +38,17 @@ struct frame_unwind; be expanded so that it knowns the lower/upper extent of the dummy frame's code. */ -extern void dummy_frame_push (struct regcache *regcache, - const struct frame_id *dummy_id); +extern void dummy_frame_push (struct inferior_thread_state *caller_state, + const struct frame_id *dummy_id); + +/* Pop the dummy frame DUMMY_ID, restoring program state to that before the + frame was created. + On return reinit_frame_cache has been called. + If the frame isn't found, flag an internal error. + + NOTE: This can only pop the one frame, even if it is in the middle of the + stack, because the other frames may be for different threads, and there's + currently no way to tell which stack frame is for which thread. */ extern void dummy_frame_pop (struct frame_id dummy_id); diff --git a/gdb/frame.c b/gdb/frame.c index a46b626..f138133 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -536,6 +536,14 @@ frame_pop (struct frame_info *this_frame) struct regcache *scratch; struct cleanup *cleanups; + if (get_frame_type (this_frame) == DUMMY_FRAME) + { + /* Popping a dummy frame involves restoring more than just registers. + dummy_frame_pop does all the work. */ + dummy_frame_pop (get_frame_id (this_frame)); + return; + } + /* Ensure that we have a frame to pop to. */ prev_frame = get_prev_frame_1 (this_frame); @@ -549,11 +557,6 @@ frame_pop (struct frame_info *this_frame) scratch = frame_save_as_regcache (prev_frame); cleanups = make_cleanup_regcache_xfree (scratch); - /* If we are popping a dummy frame, clean up the associated - data as well. */ - if (get_frame_type (this_frame) == DUMMY_FRAME) - dummy_frame_pop (get_frame_id (this_frame)); - /* FIXME: cagney/2003-03-16: It should be possible to tell the target's register cache that it is about to be hit with a burst register transfer and that the sequence of register writes should diff --git a/gdb/infcall.c b/gdb/infcall.c index 6b42774..d6da8b2 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -36,6 +36,13 @@ #include "dummy-frame.h" #include "ada-lang.h" #include "gdbthread.h" +#include "exceptions.h" + +/* If we can't find a function's name from its address, + we print this instead. */ +#define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s" +#define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \ + + 2 * sizeof (CORE_ADDR)) /* NOTE: cagney/2003-04-16: What's the future of this code? @@ -260,16 +267,6 @@ find_function_addr (struct value *function, struct type **retval_type) return funaddr + gdbarch_deprecated_function_start_offset (current_gdbarch); } -/* Call breakpoint_auto_delete on the current contents of the bpstat - of the current thread. */ - -static void -breakpoint_auto_delete_contents (void *arg) -{ - if (!ptid_equal (inferior_ptid, null_ptid)) - breakpoint_auto_delete (inferior_thread ()->stop_bpstat); -} - /* For CALL_DUMMY_ON_STACK, push a breakpoint sequence that the called function returns to. */ @@ -288,6 +285,103 @@ push_dummy_code (struct gdbarch *gdbarch, regcache); } +/* Fetch the name of the function at FUNADDR. + This is used in printing an error message for call_function_by_hand. + BUF is used to print FUNADDR in hex if the function name cannot be + determined. It must be large enough to hold formatted result of + RAW_FUNCTION_ADDRESS_FORMAT. */ + +static const char * +get_function_name (CORE_ADDR funaddr, char *buf, int buf_size) +{ + { + struct symbol *symbol = find_pc_function (funaddr); + if (symbol) + return SYMBOL_PRINT_NAME (symbol); + } + + { + /* Try the minimal symbols. */ + struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr); + if (msymbol) + return SYMBOL_PRINT_NAME (msymbol); + } + + { + char *tmp = xstrprintf (_(RAW_FUNCTION_ADDRESS_FORMAT), + hex_string (funaddr)); + gdb_assert (strlen (tmp) + 1 <= buf_size); + strcpy (buf, tmp); + xfree (tmp); + return buf; + } +} + +/* Subroutine of call_function_by_hand to simplify it. + Start up the inferior and wait for it to stop. + Return the exception if there's an error, or an exception with + reason >= 0 if there's no error. + + This is done inside a TRY_CATCH so the caller needn't worry about + thrown errors. The caller should rethrow if there's an error. */ + +static struct gdb_exception +run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc) +{ + volatile struct gdb_exception e; + int saved_async = 0; + int saved_suppress_resume_observer = suppress_resume_observer; + int saved_suppress_stop_observer = suppress_stop_observer; + ptid_t call_thread_ptid = call_thread->ptid; + char *saved_target_shortname = xstrdup (target_shortname); + + clear_proceed_status (); + + disable_watchpoints_before_interactive_call_start (); + call_thread->proceed_to_finish = 1; /* We want stop_registers, please... */ + + if (target_can_async_p ()) + saved_async = target_async_mask (0); + + suppress_resume_observer = 1; + suppress_stop_observer = 1; + + TRY_CATCH (e, RETURN_MASK_ALL) + proceed (real_pc, TARGET_SIGNAL_0, 0); + + /* At this point the current thread may have changed. + CALL_THREAD is no longer usable as its thread may have exited. + Set it to NULL to prevent its further use. */ + call_thread = NULL; + + suppress_resume_observer = saved_suppress_resume_observer; + suppress_stop_observer = saved_suppress_stop_observer; + + /* Don't restore the async mask if the target has changed, + saved_async is for the original target. */ + if (saved_async + && strcmp (saved_target_shortname, target_shortname) == 0) + target_async_mask (saved_async); + + enable_watchpoints_after_interactive_call_stop (); + + /* Call breakpoint_auto_delete on the current contents of the bpstat + of inferior call thread. + If all error()s out of proceed ended up calling normal_stop + (and perhaps they should; it already does in the special case + of error out of resume()), then we wouldn't need this. */ + if (e.reason < 0) + { + struct thread_info *tp = find_thread_pid (call_thread_ptid); + if (tp != NULL) + breakpoint_auto_delete (tp->stop_bpstat); + } + + xfree (saved_target_shortname); + + return e; +} + /* All this stuff with a dummy frame may seem unnecessarily complicated (why not just save registers in GDB?). The purpose of pushing a dummy frame which looks just like a real frame is so that if you call a @@ -313,20 +407,22 @@ call_function_by_hand (struct value *function, int nargs, struct value **args) struct type *values_type, *target_values_type; unsigned char struct_return = 0, lang_struct_return = 0; CORE_ADDR struct_addr = 0; - struct regcache *retbuf; - struct cleanup *retbuf_cleanup; struct inferior_status *inf_status; struct cleanup *inf_status_cleanup; + struct inferior_thread_state *caller_state; + struct cleanup *caller_state_cleanup; CORE_ADDR funaddr; CORE_ADDR real_pc; struct type *ftype = check_typedef (value_type (function)); CORE_ADDR bp_addr; - struct regcache *caller_regcache; - struct cleanup *caller_regcache_cleanup; struct frame_id dummy_id; struct cleanup *args_cleanup; struct frame_info *frame; struct gdbarch *gdbarch; + ptid_t call_thread_ptid; + struct gdb_exception e; + const char *name; + char name_buf[RAW_FUNCTION_ADDRESS_SIZE]; if (TYPE_CODE (ftype) == TYPE_CODE_PTR) ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); @@ -340,25 +436,18 @@ call_function_by_hand (struct value *function, int nargs, struct value **args) if (!gdbarch_push_dummy_call_p (gdbarch)) error (_("This target does not support function calls.")); - /* Create a cleanup chain that contains the retbuf (buffer - containing the register values). This chain is create BEFORE the - inf_status chain so that the inferior status can cleaned up - (restored or discarded) without having the retbuf freed. */ - retbuf = regcache_xmalloc (gdbarch); - retbuf_cleanup = make_cleanup_regcache_xfree (retbuf); - - /* A cleanup for the inferior status. Create this AFTER the retbuf - so that this can be discarded or applied without interfering with - the regbuf. */ - inf_status = save_inferior_status (1); + /* A cleanup for the inferior status. + This is only needed while we're preparing the inferior function call. */ + inf_status = save_inferior_status (); inf_status_cleanup = make_cleanup_restore_inferior_status (inf_status); - /* Save the caller's registers so that they can be restored once the + /* Save the caller's registers and other state associated with the + inferior itself so that they can be restored once the callee returns. To allow nested calls the registers are (further down) pushed onto a dummy frame stack. Include a cleanup (which is tossed once the regcache has been pushed). */ - caller_regcache = frame_save_as_regcache (frame); - caller_regcache_cleanup = make_cleanup_regcache_xfree (caller_regcache); + caller_state = save_inferior_thread_state (); + caller_state_cleanup = make_cleanup_restore_inferior_thread_state (caller_state); /* Ensure that the initial SP is correctly aligned. */ { @@ -633,99 +722,117 @@ call_function_by_hand (struct value *function, int nargs, struct value **args) /* Everything's ready, push all the info needed to restore the caller (and identify the dummy-frame) onto the dummy-frame stack. */ - dummy_frame_push (caller_regcache, &dummy_id); - discard_cleanups (caller_regcache_cleanup); + dummy_frame_push (caller_state, &dummy_id); + + /* Discard both inf_status and caller_state cleanups. + From this point on we explicitly restore the associated state + or discard it. */ + discard_cleanups (inf_status_cleanup); /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - If you're looking to implement asynchronous dummy-frames, then just below is the place to chop this function in two.. */ - /* Now proceed, having reached the desired place. */ - clear_proceed_status (); - - /* Execute a "stack dummy", a piece of code stored in the stack by - the debugger to be executed in the inferior. - - The dummy's frame is automatically popped whenever that break is - hit. If that is the first time the program stops, - call_function_by_hand returns to its caller with that frame - already gone and sets RC to 0. - - Otherwise, set RC to a non-zero value. If the called function - receives a random signal, we do not allow the user to continue - executing it as this may not work. The dummy frame is poped and - we return 1. If we hit a breakpoint, we leave the frame in place - and return 2 (the frame will eventually be popped when we do hit - the dummy end breakpoint). */ - + /* TP is invalid after run_inferior_call returns, so enclose this + in a block so that it's only in scope during the time it's valid. */ { - struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0); - struct cleanup *old_cleanups2; - int saved_async = 0; struct thread_info *tp = inferior_thread (); - /* If all error()s out of proceed ended up calling normal_stop - (and perhaps they should; it already does in the special case - of error out of resume()), then we wouldn't need this. */ - make_cleanup (breakpoint_auto_delete_contents, NULL); - - disable_watchpoints_before_interactive_call_start (); - tp->proceed_to_finish = 1; /* We want stop_registers, please... */ + /* Save this thread's ptid, we need it later but the thread + may have exited. */ + call_thread_ptid = tp->ptid; - if (target_can_async_p ()) - saved_async = target_async_mask (0); + /* Run the inferior until it stops. */ - old_cleanups2 = make_cleanup_restore_integer (&suppress_resume_observer); - suppress_resume_observer = 1; - make_cleanup_restore_integer (&suppress_stop_observer); - suppress_stop_observer = 1; - proceed (real_pc, TARGET_SIGNAL_0, 0); - do_cleanups (old_cleanups2); - - if (saved_async) - target_async_mask (saved_async); - - enable_watchpoints_after_interactive_call_stop (); - - discard_cleanups (old_cleanups); + e = run_inferior_call (tp, real_pc); } + /* Rethrow an error if we got one trying to run the inferior. */ + + if (e.reason < 0) + { + const char *name = get_function_name (funaddr, + name_buf, sizeof (name_buf)); + + discard_inferior_status (inf_status); + + /* We could discard the dummy frame here if the program exited, + but it will get garbage collected the next time the program is + run anyway. */ + + switch (e.reason) + { + case RETURN_ERROR: + throw_error (e.error, _("\ +%s\n\ +An error occurred while in a function called from GDB.\n\ +Evaluation of the expression containing the function\n\ +(%s) will be abandoned.\n\ +When the function is done executing, GDB will silently stop."), + e.message, name); + case RETURN_QUIT: + default: + throw_exception (e); + } + } + + /* If the program has exited, or we stopped at a different thread, + exit and inform the user. */ + if (! target_has_execution) { - /* If we try to restore the inferior status (via the cleanup), + const char *name = get_function_name (funaddr, + name_buf, sizeof (name_buf)); + + /* If we try to restore the inferior status, we'll crash as the inferior is no longer running. */ - discard_cleanups (inf_status_cleanup); discard_inferior_status (inf_status); + + /* We could discard the dummy frame here given that the program exited, + but it will get garbage collected the next time the program is + run anyway. */ + error (_("\ -The program being debugged exited while in a function called from GDB.")); +The program being debugged exited while in a function called from GDB.\n\ +Evaluation of the expression containing the function\n\ +(%s) will be abandoned."), + name); + } + + if (! ptid_equal (call_thread_ptid, inferior_ptid)) + { + const char *name = get_function_name (funaddr, + name_buf, sizeof (name_buf)); + + /* We've switched threads. This can happen if another thread gets a + signal or breakpoint while our thread was running. + There's no point in restoring the inferior status, + we're in a different thread. */ + discard_inferior_status (inf_status); + /* Keep the dummy frame record, if the user switches back to the + thread with the hand-call, we'll need it. */ + if (stopped_by_random_signal) + error (_("\ +The program received a signal in another thread while\n\ +making a function call from GDB.\n\ +Evaluation of the expression containing the function\n\ +(%s) will be abandoned.\n\ +When the function is done executing, GDB will silently stop."), + name); + else + error (_("\ +The program stopped in another thread while making a function call from GDB.\n\ +Evaluation of the expression containing the function\n\ +(%s) will be abandoned.\n\ +When the function is done executing, GDB will silently stop."), + name); } if (stopped_by_random_signal || !stop_stack_dummy) { - /* Find the name of the function we're about to complain about. */ - const char *name = NULL; - { - struct symbol *symbol = find_pc_function (funaddr); - if (symbol) - name = SYMBOL_PRINT_NAME (symbol); - else - { - /* Try the minimal symbols. */ - struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr); - if (msymbol) - name = SYMBOL_PRINT_NAME (msymbol); - } - if (name == NULL) - { - /* Can't use a cleanup here. It is discarded, instead use - an alloca. */ - char *tmp = xstrprintf ("at %s", hex_string (funaddr)); - char *a = alloca (strlen (tmp) + 1); - strcpy (a, tmp); - xfree (tmp); - name = a; - } - } + const char *name = get_function_name (funaddr, + name_buf, sizeof (name_buf)); + if (stopped_by_random_signal) { /* We stopped inside the FUNCTION because of a random @@ -737,8 +844,12 @@ The program being debugged exited while in a function called from GDB.")); /* The user wants the context restored. */ /* We must get back to the frame we were before the - dummy call. */ - frame_pop (get_current_frame ()); + dummy call. */ + dummy_frame_pop (dummy_id); + + /* We also need to restore inferior status to that before the + dummy call. */ + restore_inferior_status (inf_status); /* FIXME: Insert a bunch of wrap_here; name can be very long if it's a C++ name with arguments and stuff. */ @@ -746,41 +857,39 @@ The program being debugged exited while in a function called from GDB.")); The program being debugged was signaled while in a function called from GDB.\n\ GDB has restored the context to what it was before the call.\n\ To change this behavior use \"set unwindonsignal off\".\n\ -Evaluation of the expression containing the function (%s) will be abandoned."), +Evaluation of the expression containing the function\n\ +(%s) will be abandoned."), name); } else { /* The user wants to stay in the frame where we stopped - (default).*/ - /* If we restored the inferior status (via the cleanup), - we would print a spurious error message (Unable to - restore previously selected frame), would write the - registers from the inf_status (which is wrong), and - would do other wrong things. */ - discard_cleanups (inf_status_cleanup); + (default). + Discard inferior status, we're not at the same point + we started at. */ discard_inferior_status (inf_status); + /* FIXME: Insert a bunch of wrap_here; name can be very long if it's a C++ name with arguments and stuff. */ error (_("\ The program being debugged was signaled while in a function called from GDB.\n\ GDB remains in the frame where the signal was received.\n\ To change this behavior use \"set unwindonsignal on\".\n\ -Evaluation of the expression containing the function (%s) will be abandoned."), +Evaluation of the expression containing the function\n\ +(%s) will be abandoned.\n\ +When the function is done executing, GDB will silently stop."), name); } } if (!stop_stack_dummy) { - /* We hit a breakpoint inside the FUNCTION. */ - /* If we restored the inferior status (via the cleanup), we - would print a spurious error message (Unable to restore - previously selected frame), would write the registers - from the inf_status (which is wrong), and would do other - wrong things. */ - discard_cleanups (inf_status_cleanup); + /* We hit a breakpoint inside the FUNCTION. + Keep the dummy frame, the user may want to examine its state. + Discard inferior status, we're not at the same point + we started at. */ discard_inferior_status (inf_status); + /* The following error message used to say "The expression which contained the function call has been discarded." It is a hard concept to explain in a few words. Ideally, @@ -791,28 +900,32 @@ Evaluation of the expression containing the function (%s) will be abandoned."), a C++ name with arguments and stuff. */ error (_("\ The program being debugged stopped while in a function called from GDB.\n\ -When the function (%s) is done executing, GDB will silently\n\ -stop (instead of continuing to evaluate the expression containing\n\ -the function call)."), name); +Evaluation of the expression containing the function\n\ +(%s) will be abandoned.\n\ +When the function is done executing, GDB will silently stop."), + name); } /* The above code errors out, so ... */ internal_error (__FILE__, __LINE__, _("... should not be here")); } - /* If we get here the called FUNCTION run to completion. */ + /* If we get here the called FUNCTION ran to completion, + and the dummy frame has already been popped. */ - /* On normal return, the stack dummy has been popped already. */ - regcache_cpy_no_passthrough (retbuf, stop_registers); - - /* Restore the inferior status, via its cleanup. At this stage, - leave the RETBUF alone. */ - do_cleanups (inf_status_cleanup); - - /* Figure out the value returned by the function. */ { + struct regcache *retbuf = regcache_xmalloc (gdbarch); + struct cleanup *retbuf_cleanup = make_cleanup_regcache_xfree (retbuf); struct value *retval = NULL; + regcache_cpy_no_passthrough (retbuf, stop_registers); + + /* Inferior call is successful. Restore the inferior status. + At this stage, leave the RETBUF alone. */ + restore_inferior_status (inf_status); + + /* Figure out the value returned by the function. */ + if (lang_struct_return) retval = value_at (values_type, struct_addr); else if (TYPE_CODE (target_values_type) == TYPE_CODE_VOID) @@ -841,7 +954,7 @@ the function call)."), name); do_cleanups (retbuf_cleanup); - gdb_assert(retval); + gdb_assert (retval); return retval; } } diff --git a/gdb/inferior.h b/gdb/inferior.h index 9dc5ca3..5427677 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -40,24 +40,38 @@ struct ui_out; /* For struct frame_id. */ #include "frame.h" -/* Structure in which to save the status of the inferior. Create/Save - through "save_inferior_status", restore through - "restore_inferior_status". +/* Two structures are used to record inferior state. - This pair of routines should be called around any transfer of - control to the inferior which you don't want showing up in your - control variables. */ + inferior_thread_state contains state about the program itself like its + registers and any signal it received when it last stopped. + This state must be restored regardless of how the inferior function call + ends (either successfully, or after it hits a breakpoint or signal) + if the program is to properly continue where it left off. + inferior_status contains state regarding gdb's control of the inferior + itself like stepping control. It also contains session state like the + user's currently selected frame. + + Call these routines around hand called functions, including function calls + in conditional breakpoints for example. */ + +struct inferior_thread_state; struct inferior_status; -extern struct inferior_status *save_inferior_status (int); +extern struct inferior_thread_state *save_inferior_thread_state (void); +extern struct inferior_status *save_inferior_status (void); +extern void restore_inferior_thread_state (struct inferior_thread_state *); extern void restore_inferior_status (struct inferior_status *); +extern struct cleanup *make_cleanup_restore_inferior_thread_state (struct inferior_thread_state *); extern struct cleanup *make_cleanup_restore_inferior_status (struct inferior_status *); +extern void discard_inferior_thread_state (struct inferior_thread_state *); extern void discard_inferior_status (struct inferior_status *); +extern struct regcache *get_inferior_thread_state_regcache (struct inferior_thread_state *); + /* The -1 ptid, often used to indicate either an error condition or a "don't care" condition, i.e, "run all threads." */ extern ptid_t minus_one_ptid; diff --git a/gdb/infrun.c b/gdb/infrun.c index 228e743..92092ab 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -45,7 +45,6 @@ #include "language.h" #include "solib.h" #include "main.h" - #include "gdb_assert.h" #include "mi/mi-common.h" #include "event-top.h" @@ -4387,14 +4386,20 @@ Further execution is probably impossible.\n")); if (stop_stack_dummy) { - /* Pop the empty frame that contains the stack dummy. POP_FRAME - ends with a setting of the current frame, so we can use that - next. */ - frame_pop (get_current_frame ()); - /* Set stop_pc to what it was before we called the function. - Can't rely on restore_inferior_status because that only gets - called if we don't stop in the called function. */ - stop_pc = read_pc (); + /* Pop the empty frame that contains the stack dummy. + This also restores inferior state prior to the call + (struct inferior_thread_state). */ + struct frame_info *frame = get_current_frame (); + gdb_assert (get_frame_type (frame) == DUMMY_FRAME); + frame_pop (frame); + /* frame_pop() calls reinit_frame_cache as the last thing it does + which means there's currently no selected frame. We don't need + to re-establish a selected frame if the dummy call returns normally, + that will be done by restore_inferior_status. However, we do have + to handle the case where the dummy call is returning after being + stopped (e.g. the dummy call previously hit a breakpoint). We + can't know which case we have so just always re-establish a + selected frame here. */ select_frame (get_current_frame ()); } @@ -4792,10 +4797,85 @@ signals_info (char *signum_exp, int from_tty) printf_filtered (_("\nUse the \"handle\" command to change these tables.\n")); } -struct inferior_status +/* Inferior thread state. + These are details related to the inferior itself, and don't include + things like what frame the user had selected or what gdb was doing + with the target at the time. + For inferior function calls these are things we want to restore + regardless of whether the function call successfully completes + or the dummy frame has to be manually popped. */ + +struct inferior_thread_state { enum target_signal stop_signal; CORE_ADDR stop_pc; + struct regcache *registers; +}; + +struct inferior_thread_state * +save_inferior_thread_state (void) +{ + struct inferior_thread_state *inf_state = XMALLOC (struct inferior_thread_state); + struct thread_info *tp = inferior_thread (); + + inf_state->stop_signal = tp->stop_signal; + inf_state->stop_pc = stop_pc; + + inf_state->registers = regcache_dup (get_current_regcache ()); + + return inf_state; +} + +/* Restore inferior session state to INF_STATE. */ + +void +restore_inferior_thread_state (struct inferior_thread_state *inf_state) +{ + struct thread_info *tp = inferior_thread (); + + tp->stop_signal = inf_state->stop_signal; + stop_pc = inf_state->stop_pc; + + /* The inferior can be gone if the user types "print exit(0)" + (and perhaps other times). */ + if (target_has_execution) + /* NB: The register write goes through to the target. */ + regcache_cpy (get_current_regcache (), inf_state->registers); + regcache_xfree (inf_state->registers); + xfree (inf_state); +} + +static void +do_restore_inferior_thread_state_cleanup (void *state) +{ + restore_inferior_thread_state (state); +} + +struct cleanup * +make_cleanup_restore_inferior_thread_state (struct inferior_thread_state *inf_state) +{ + return make_cleanup (do_restore_inferior_thread_state_cleanup, inf_state); +} + +void +discard_inferior_thread_state (struct inferior_thread_state *inf_state) +{ + regcache_xfree (inf_state->registers); + xfree (inf_state); +} + +struct regcache * +get_inferior_thread_state_regcache (struct inferior_thread_state *inf_state) +{ + return inf_state->registers; +} + +/* Session related state for inferior function calls. + These are the additional bits of state that need to be restored + when an inferior function call successfully completes. */ + +struct inferior_status +{ bpstat stop_bpstat; int stop_step; int stop_stack_dummy; @@ -4809,32 +4889,23 @@ struct inferior_status int stop_after_trap; int stop_soon; - /* These are here because if call_function_by_hand has written some - registers and then decides to call error(), we better not have changed - any registers. */ - struct regcache *registers; - - /* A frame unique identifier. */ + /* ID if the selected frame when the inferior function call was made. */ struct frame_id selected_frame_id; int breakpoint_proceeded; - int restore_stack_info; int proceed_to_finish; }; /* Save all of the information associated with the inferior<==>gdb - connection. INF_STATUS is a pointer to a "struct inferior_status" - (defined in inferior.h). */ + connection. */ struct inferior_status * -save_inferior_status (int restore_stack_info) +save_inferior_status (void) { struct inferior_status *inf_status = XMALLOC (struct inferior_status); struct thread_info *tp = inferior_thread (); struct inferior *inf = current_inferior (); - inf_status->stop_signal = tp->stop_signal; - inf_status->stop_pc = stop_pc; inf_status->stop_step = tp->stop_step; inf_status->stop_stack_dummy = stop_stack_dummy; inf_status->stopped_by_random_signal = stopped_by_random_signal; @@ -4852,12 +4923,10 @@ save_inferior_status (int restore_stack_info) inf_status->stop_bpstat = tp->stop_bpstat; tp->stop_bpstat = bpstat_copy (tp->stop_bpstat); inf_status->breakpoint_proceeded = breakpoint_proceeded; - inf_status->restore_stack_info = restore_stack_info; inf_status->proceed_to_finish = tp->proceed_to_finish; - inf_status->registers = regcache_dup (get_current_regcache ()); - inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); + return inf_status; } @@ -4882,14 +4951,14 @@ restore_selected_frame (void *args) return (1); } +/* Restore inferior session state to INF_STATUS. */ + void restore_inferior_status (struct inferior_status *inf_status) { struct thread_info *tp = inferior_thread (); struct inferior *inf = current_inferior (); - tp->stop_signal = inf_status->stop_signal; - stop_pc = inf_status->stop_pc; tp->stop_step = inf_status->stop_step; stop_stack_dummy = inf_status->stop_stack_dummy; stopped_by_random_signal = inf_status->stopped_by_random_signal; @@ -4902,24 +4971,11 @@ restore_inferior_status (struct inferior_status *inf_status) inf->stop_soon = inf_status->stop_soon; bpstat_clear (&tp->stop_bpstat); tp->stop_bpstat = inf_status->stop_bpstat; + inf_status->stop_bpstat = NULL; breakpoint_proceeded = inf_status->breakpoint_proceeded; tp->proceed_to_finish = inf_status->proceed_to_finish; - /* The inferior can be gone if the user types "print exit(0)" - (and perhaps other times). */ - if (target_has_execution) - /* NB: The register write goes through to the target. */ - regcache_cpy (get_current_regcache (), inf_status->registers); - regcache_xfree (inf_status->registers); - - /* FIXME: If we are being called after stopping in a function which - is called from gdb, we should not be trying to restore the - selected frame; it just prints a spurious error message (The - message is useful, however, in detecting bugs in gdb (like if gdb - clobbers the stack)). In fact, should we be restoring the - inferior status at all in that case? . */ - - if (target_has_stack && inf_status->restore_stack_info) + if (target_has_stack) { /* The point of catch_errors is that if the stack is clobbered, walking the stack might encounter a garbage pointer and @@ -4931,7 +4987,6 @@ restore_inferior_status (struct inferior_status *inf_status) /* Error in restoring the selected frame. Select the innermost frame. */ select_frame (get_current_frame ()); - } xfree (inf_status); @@ -4954,10 +5009,9 @@ discard_inferior_status (struct inferior_status *inf_status) { /* See save_inferior_status for info on stop_bpstat. */ bpstat_clear (&inf_status->stop_bpstat); - regcache_xfree (inf_status->registers); xfree (inf_status); } - + int inferior_has_forked (ptid_t pid, ptid_t *child_pid) { diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0795f58..052c500 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2009-01-19 Doug Evans <dje@google.com> + + * gdb.base/break.exp: Update expected gdb output. + * gdb.base/sepdebug.exp: Ditto. + * gdb.mi/mi-syn-frame.exp: Ditto. + * gdb.mi/mi2-syn-frame.exp: Ditto. + * gdb.base/call-signal-resume.exp: New file. + * gdb.base/call-signals.c: New file. + * gdb.base/unwindonsignal.exp: New file. + * gdb.base/unwindonsignal.c: New file. + * gdb.threads/interrupted-hand-call.exp: New file. + * gdb.threads/interrupted-hand-call.c: New file. + * gdb.threads/thread-unwindonsignal.exp: New file. + 2009-01-14 Daniel Jacobowitz <dan@codesourcery.com> * gdb.base/define.exp: Test defining and hooking prefix commands. diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp index f4c24a0..7067dc3 100644 --- a/gdb/testsuite/gdb.base/break.exp +++ b/gdb/testsuite/gdb.base/break.exp @@ -584,7 +584,7 @@ gdb_expect { } send_gdb "print marker2(99)\n" gdb_expect { - -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2$proto. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\ + -re "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2$proto. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop..*$gdb_prompt $"\ {pass "hit breakpoint on called function"} -re "$gdb_prompt $"\ {fail "hit breakpoint on called function"} diff --git a/gdb/testsuite/gdb.base/call-signal-resume.exp b/gdb/testsuite/gdb.base/call-signal-resume.exp new file mode 100644 index 0000000..ed0903e --- /dev/null +++ b/gdb/testsuite/gdb.base/call-signal-resume.exp @@ -0,0 +1,159 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# 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/>. + +# Test inferior resumption after discarding a hand-called function. +# There are two things to test. +# 1) Inferior stops normally. Upon resumption it should continue normally, +# regardless of whatever signal the hand-called function got. +# 2) Inferior is stopped at a signal. Upon resumption it should continue +# with that signal, regardless of whatever the hand-called function did. + +if $tracelevel then { + strace $tracelevel +} + +if [target_info exists gdb,noinferiorio] { + verbose "Skipping call-signal-resume.exp because of no fileio capabilities." + continue +} + +set prms_id 0 +set bug_id 0 + +set testfile "call-signals" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested call-signal-resume.exp + return -1 +} + +# Some targets can't do function calls, so don't even bother with this +# test. +if [target_info exists gdb,cannot_call_functions] { + setup_xfail "*-*-*" 2416 + fail "This target can not call functions" + continue +} + +proc get_dummy_frame_number { } { + global gdb_prompt + + send_gdb "bt\n" + gdb_expect { + -re "#(\[0-9\]*) *<function called from gdb>.*$gdb_prompt $" + { + return $expect_out(1,string) + } + -re "$gdb_prompt $" + { + return "" + } + timeout + { + return "" + } + } + return "" +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if { ![runto_main] } { + fail "Can't run to main" + return 0 +} + +gdb_test "break stop_one" "Breakpoint \[0-9\]* at .*" +gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_one.*" \ + "continue to breakpoint at stop_one" + +# Call function (causing the program to get a signal), and see if gdb handles +# it properly. +gdb_test_multiple "call gen_signal ()" \ + "inferior function call signaled" { + -re "\[\r\n\]*no signal\[\r\n\]+$gdb_prompt $" { + unsupported "inferior function call signaled" + return 0 + } + -re "\[\r\n\]*The program being debugged was signaled.*\[\r\n\]+$gdb_prompt $" { + pass "inferior function call signaled" + } +} + +set frame_number [get_dummy_frame_number] +if { "$frame_number" == "" } { + fail "dummy stack frame number" + setup_xfail "*-*-*" +} else { + pass "dummy stack frame number" +} + +# Pop the dummy frame. +gdb_test "frame $frame_number" "" +gdb_test "set confirm off" "" +gdb_test "return" "" + +# Resume execution, the program should continue without any signal. + +gdb_test "break stop_two" "Breakpoint \[0-9\]* at .*" +gdb_test "continue" "Breakpoint \[0-9\]*, stop_two.*" \ + "continue to breakpoint at stop_two" + +# Continue again, we should get a signal. + +gdb_test "continue" "Program received signal .*" \ + "continue to receipt of signal" + +# Hand call another function that prematurely stops, +# then manually pop the dummy stack frame. + +gdb_test "break null_hand_call" "Breakpoint \[0-9\]* at .*" +gdb_test "call null_hand_call ()" "Breakpoint \[0-9\]*, null_hand_call.*" \ + "null_hand_call" + +set frame_number [get_dummy_frame_number] +if { "$frame_number" == "" } { + fail "dummy stack frame number" + setup_xfail "*-*-*" + # Need something. + set frame_number 0 +} else { + pass "dummy stack frame number" +} + +# Pop the dummy frame. +gdb_test "frame $frame_number" "" +gdb_test "set confirm off" "" +gdb_test "return" "" + +# Continue again, this time we should get to the signal handler. + +gdb_test "break handle_signal" "Breakpoint \[0-9\]* at .*" +gdb_test "continue" "Breakpoint \[0-9\]*, handle_signal.*" \ + "continue to breakpoint at handle_signal" + +# Continue one last time, the program should exit normally. + +gdb_test "continue" "Program exited normally." \ + "continue to program exit" + +return 0 diff --git a/gdb/testsuite/gdb.base/call-signals.c b/gdb/testsuite/gdb.base/call-signals.c new file mode 100644 index 0000000..223c589 --- /dev/null +++ b/gdb/testsuite/gdb.base/call-signals.c @@ -0,0 +1,89 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 Free Software Foundation, Inc. + + 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/>. */ + +/* Support program for testing handling of inferior function calls + in the presence of signals. */ + +#include <stdio.h> +#include <signal.h> +#include <unistd.h> + +void +handle_signal (int sig) +{ +} + +void +gen_signal () +{ + /* According to sigall.exp, SIGABRT is always supported. */ +#ifdef SIGABRT + kill (getpid (), SIGABRT); +#endif + /* If we get here we couldn't generate a signal, tell dejagnu. */ + printf ("no signal\n"); +} + +/* Easy place to set a breakpoint. */ + +void +stop_one () +{ +} + +void +stop_two () +{ +} + +void +null_hand_call () +{ +} + +int +main () +{ +#ifdef usestubs + set_debug_traps (); + breakpoint (); +#endif + +#ifdef SIG_SETMASK + /* Ensure all the signals aren't blocked. + The environment in which the testsuite is run may have blocked some + for whatever reason. */ + { + sigset_t newset; + sigemptyset (&newset); + sigprocmask (SIG_SETMASK, &newset, NULL); + } +#endif + + signal (SIGABRT, handle_signal); + + /* Stop here so we can hand-call gen_signal. */ + stop_one (); + + /* When we're resumed stop here. */ + stop_two (); + + /* When we're resumed we generate a signal ourselves. */ + gen_signal (); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/sepdebug.exp b/gdb/testsuite/gdb.base/sepdebug.exp index 7c722c7..10eb49d 100644 --- a/gdb/testsuite/gdb.base/sepdebug.exp +++ b/gdb/testsuite/gdb.base/sepdebug.exp @@ -599,7 +599,7 @@ gdb_expect { } send_gdb "print marker2(99)\n" gdb_expect { - -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\ + -re "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop..*$gdb_prompt $"\ {pass "hit breakpoint on called function"} -re "$gdb_prompt $"\ {fail "hit breakpoint on called function"} diff --git a/gdb/testsuite/gdb.base/unwindonsignal.c b/gdb/testsuite/gdb.base/unwindonsignal.c new file mode 100644 index 0000000..2d4fdf5 --- /dev/null +++ b/gdb/testsuite/gdb.base/unwindonsignal.c @@ -0,0 +1,65 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 Free Software Foundation, Inc. + + 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/>. */ + +/* Support program for testing unwindonsignal. */ + +#include <stdio.h> +#include <signal.h> +#include <unistd.h> + +void +gen_signal () +{ + /* According to sigall.exp, SIGABRT is always supported. */ +#ifdef SIGABRT + kill (getpid (), SIGABRT); +#endif + /* If we get here we couldn't generate a signal, tell dejagnu. */ + printf ("no signal\n"); +} + +/* Easy place to set a breakpoint. */ + +void +stop_here () +{ +} + +int +main () +{ +#ifdef usestubs + set_debug_traps (); + breakpoint (); +#endif + +#ifdef SIG_SETMASK + /* Ensure all the signals aren't blocked. + The environment in which the testsuite is run may have blocked some + for whatever reason. */ + { + sigset_t newset; + sigemptyset (&newset); + sigprocmask (SIG_SETMASK, &newset, NULL); + } +#endif + + /* Stop here so we can hand-call gen_signal. */ + stop_here (); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/unwindonsignal.exp b/gdb/testsuite/gdb.base/unwindonsignal.exp new file mode 100644 index 0000000..e435a60 --- /dev/null +++ b/gdb/testsuite/gdb.base/unwindonsignal.exp @@ -0,0 +1,98 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# 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/>. + +if $tracelevel then { + strace $tracelevel +} + +if [target_info exists gdb,noinferiorio] { + verbose "Skipping unwindonsignal.exp because of no fileio capabilities." + continue +} + +set prms_id 0 +set bug_id 0 + +set testfile "unwindonsignal" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested unwindonsignal.exp + return -1 +} + +# Some targets can't do function calls, so don't even bother with this +# test. +if [target_info exists gdb,cannot_call_functions] { + setup_xfail "*-*-*" 2416 + fail "This target can not call functions" + continue +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if { ![runto_main] } { + fail "Can't run to main" + return 0 +} + +gdb_test "break stop_here" "Breakpoint \[0-9\]* at .*" +gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, stop_here.*" \ + "continue to breakpoint at stop_here" + +# Turn on unwindonsignal. +gdb_test "set unwindonsignal on" \ + "" \ + "setting unwindonsignal" +gdb_test "show unwindonsignal" \ + "Unwinding of stack .* is on." \ + "showing unwindonsignal" + +# Call function (causing the program to get a signal), and see if gdb handles +# it properly. +gdb_test_multiple "call gen_signal ()" \ + "unwindonsignal, inferior function call signaled" { + -re "\[\r\n\]*no signal\[\r\n\]+$gdb_prompt $" { + unsupported "unwindonsignal, inferior function call signaled" + return 0 + } + -re "\[\r\n\]*The program being debugged was signaled.*\[\r\n\]+$gdb_prompt $" { + pass "unwindonsignal, inferior function call signaled" + } +} + +# Verify the stack got unwound. +gdb_test "bt" \ + "#0 *\[x0-9a-f in\]*stop_here \\(.*\\) at .*#1 *\[x0-9a-f in\]*main \\(.*\\) at .*" \ + "unwindonsignal, stack unwound" + +# Verify the dummy frame got removed from dummy_frame_stack. +gdb_test_multiple "maint print dummy-frames" \ + "unwindonsignal, dummy frame removed" { + -re "\[\r\n\]*.*stack=.*code=.*\[\r\n\]+$gdb_prompt $" { + fail "unwindonsignal, dummy frame removed" + } + -re "\[\r\n\]+$gdb_prompt $" { + pass "unwindonsignal, dummy frame removed" + } +} + +return 0 diff --git a/gdb/testsuite/gdb.mi/mi-syn-frame.exp b/gdb/testsuite/gdb.mi/mi-syn-frame.exp index 2dafed7..b952b49 100644 --- a/gdb/testsuite/gdb.mi/mi-syn-frame.exp +++ b/gdb/testsuite/gdb.mi/mi-syn-frame.exp @@ -43,7 +43,8 @@ mi_create_breakpoint "foo" 2 keep foo ".*mi-syn-frame.c" $decimal $hex \ # Call foo() by hand, where we'll hit a breakpoint. # -mi_gdb_test "401-data-evaluate-expression foo()" ".*401\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(foo\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" "call inferior's function with a breakpoint set in it" +mi_gdb_test "401-data-evaluate-expression foo()" ".*401\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nEvaluation of the expression containing the function\\\\n\\(foo\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ + "call inferior's function with a breakpoint set in it" mi_gdb_test "402-stack-list-frames" "402\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"foo\",file=\".*mi-syn-frame.c\",line=\"$decimal\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"<function called from gdb>\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",line=\"$decimal\"\}.*\\\]" "backtrace from inferior function stopped at bp, showing gdb dummy frame" @@ -68,7 +69,7 @@ mi_create_breakpoint "subroutine" 3 keep subroutine ".*mi-syn-frame.c" $decimal "insert breakpoint subroutine" mi_gdb_test "406-data-evaluate-expression have_a_very_merry_interrupt()" \ - ".*406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" \ + ".*406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nEvaluation of the expression containing the function\\\\n\\(have_a_very_merry_interrupt\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ "data evaluate expression" # We should have both a signal handler and a call dummy frame @@ -92,7 +93,7 @@ mi_gdb_test "409-stack-list-frames 0 0" \ # mi_gdb_test "410-data-evaluate-expression bar()" \ - ".*410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\".\\\\nEvaluation of the expression containing the function \\(bar\\) will be abandoned.\"" \ + ".*410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\".\\\\nEvaluation of the expression containing the function\\\\n\\(bar\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ "call inferior function which raises exception" mi_gdb_test "411-stack-list-frames" "411\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"bar\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"},frame=\{level=\"1\",addr=\"$hex\",func=\"<function called from gdb>\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"}.*\\\]" "backtrace from inferior function at exception" diff --git a/gdb/testsuite/gdb.mi/mi2-syn-frame.exp b/gdb/testsuite/gdb.mi/mi2-syn-frame.exp index 5ee8abd..fff2a37 100644 --- a/gdb/testsuite/gdb.mi/mi2-syn-frame.exp +++ b/gdb/testsuite/gdb.mi/mi2-syn-frame.exp @@ -45,7 +45,8 @@ mi_create_breakpoint "foo" 2 keep foo ".*mi-syn-frame.c" $decimal $hex \ # Call foo() by hand, where we'll hit a breakpoint. # -mi_gdb_test "401-data-evaluate-expression foo()" ".*401\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(foo\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" "call inferior's function with a breakpoint set in it" +mi_gdb_test "401-data-evaluate-expression foo()" ".*401\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nEvaluation of the expression containing the function\\\\n\\(foo\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ + "call inferior's function with a breakpoint set in it" mi_gdb_test "402-stack-list-frames" "402\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"foo\",file=\".*mi-syn-frame.c\",line=\"$decimal\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"<function called from gdb>\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",line=\"$decimal\"\}.*\\\]" "backtrace from inferior function stopped at bp, showing gdb dummy frame" @@ -70,7 +71,7 @@ mi_create_breakpoint "subroutine" 3 keep subroutine ".*mi-syn-frame.c" $decimal "insert breakpoint subroutine" mi_gdb_test "406-data-evaluate-expression have_a_very_merry_interrupt()" \ - ".*406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nWhen the function \\(have_a_very_merry_interrupt\\) is done executing, GDB will silently\\\\nstop \\(instead of continuing to evaluate the expression containing\\\\nthe function call\\).\"" \ + ".*406\\^error,msg=\"The program being debugged stopped while in a function called from GDB.\\\\nEvaluation of the expression containing the function\\\\n\\(have_a_very_merry_interrupt\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" \ "evaluate expression have_a_very_merry_interrupt" # We should have both a signal handler and a call dummy frame @@ -92,7 +93,7 @@ mi_gdb_test "409-stack-list-frames 0 0" \ # Call bar() by hand, which should get an exception while running. # -mi_gdb_test "410-data-evaluate-expression bar()" ".*410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\".\\\\nEvaluation of the expression containing the function \\(bar\\) will be abandoned.\"" "call inferior function which raises exception" +mi_gdb_test "410-data-evaluate-expression bar()" ".*410\\^error,msg=\"The program being debugged was signaled while in a function called from GDB.\\\\nGDB remains in the frame where the signal was received.\\\\nTo change this behavior use \\\\\"set unwindonsignal on\\\\\".\\\\nEvaluation of the expression containing the function\\\\n\\(bar\\) will be abandoned.\\\\nWhen the function is done executing, GDB will silently stop.\"" "call inferior function which raises exception" mi_gdb_test "411-stack-list-frames" "411\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"bar\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"},frame=\{level=\"1\",addr=\"$hex\",func=\"<function called from gdb>\"\},frame=\{level=\"2\",addr=\"$hex\",func=\"main\",file=\".*mi-syn-frame.c\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$decimal\"}.*\\\]" "backtrace from inferior function at exception" diff --git a/gdb/testsuite/gdb.threads/interrupted-hand-call.c b/gdb/testsuite/gdb.threads/interrupted-hand-call.c new file mode 100644 index 0000000..2b9506b --- /dev/null +++ b/gdb/testsuite/gdb.threads/interrupted-hand-call.c @@ -0,0 +1,149 @@ +/* Test case for hand function calls interrupted by a signal in another thread. + + Copyright 2008 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/>. */ + +#include <pthread.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + +#ifndef NR_THREADS +#define NR_THREADS 4 +#endif + +pthread_t threads[NR_THREADS]; + +/* Number of threads currently running. */ +int thread_count; + +pthread_mutex_t thread_count_mutex; + +pthread_cond_t thread_count_condvar; + +sig_atomic_t sigabrt_received; + +void +incr_thread_count (void) +{ + pthread_mutex_lock (&thread_count_mutex); + ++thread_count; + if (thread_count == NR_THREADS) + pthread_cond_signal (&thread_count_condvar); + pthread_mutex_unlock (&thread_count_mutex); +} + +void +cond_wait (pthread_cond_t *cond, pthread_mutex_t *mut) +{ + pthread_mutex_lock (mut); + pthread_cond_wait (cond, mut); + pthread_mutex_unlock (mut); +} + +void +noreturn (void) +{ + pthread_mutex_t mut; + pthread_cond_t cond; + + pthread_mutex_init (&mut, NULL); + pthread_cond_init (&cond, NULL); + + /* Wait for a condition that will never be signaled, so we effectively + block the thread here. */ + cond_wait (&cond, &mut); +} + +void * +thread_entry (void *unused) +{ + incr_thread_count (); + noreturn (); +} + +void +sigabrt_handler (int signo) +{ + sigabrt_received = 1; +} + +/* Helper to test a hand-call being "interrupted" by a signal on another + thread. */ + +void +hand_call_with_signal (void) +{ + const struct timespec ts = { 0, 10000000 }; /* 0.01 sec */ + + sigabrt_received = 0; + pthread_kill (threads[0], SIGABRT); + while (! sigabrt_received) + nanosleep (&ts, NULL); +} + +/* Wait until all threads are running. */ + +void +wait_all_threads_running (void) +{ + pthread_mutex_lock (&thread_count_mutex); + if (thread_count == NR_THREADS) + { + pthread_mutex_unlock (&thread_count_mutex); + return; + } + pthread_cond_wait (&thread_count_condvar, &thread_count_mutex); + if (thread_count == NR_THREADS) + { + pthread_mutex_unlock (&thread_count_mutex); + return; + } + pthread_mutex_unlock (&thread_count_mutex); + printf ("failed waiting for all threads to start\n"); + abort (); +} + +/* Called when all threads are running. + Easy place for a breakpoint. */ + +void +all_threads_running (void) +{ +} + +int +main (void) +{ + int i; + + signal (SIGABRT, sigabrt_handler); + + pthread_mutex_init (&thread_count_mutex, NULL); + pthread_cond_init (&thread_count_condvar, NULL); + + for (i = 0; i < NR_THREADS; ++i) + pthread_create (&threads[i], NULL, thread_entry, NULL); + + wait_all_threads_running (); + all_threads_running (); + + return 0; +} + diff --git a/gdb/testsuite/gdb.threads/interrupted-hand-call.exp b/gdb/testsuite/gdb.threads/interrupted-hand-call.exp new file mode 100644 index 0000000..375d623 --- /dev/null +++ b/gdb/testsuite/gdb.threads/interrupted-hand-call.exp @@ -0,0 +1,92 @@ +# Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc. + +# 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/>. + +# Test recovering from a hand function call that gets interrupted +# by a signal in another thread. + +set NR_THREADS 4 + +if $tracelevel then { + strace $tracelevel +} + +set testfile "interrupted-hand-call" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}" "additional_flags=-DNR_THREADS=$NR_THREADS"]] != "" } { + return -1 +} + +# Some targets can't do function calls, so don't even bother with this +# test. +if [target_info exists gdb,cannot_call_functions] { + setup_xfail "*-*-*" 2416 + fail "This target can not call functions" + continue +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if { ![runto_main] } { + fail "Can't run to main" + return 0 +} + +gdb_test "break all_threads_running" \ + "Breakpoint 2 at .*: file .*${srcfile}, line .*" \ + "breakpoint on all_threads_running" + +# Run the program and make sure GDB reports that we stopped after +# hitting breakpoint 2 in all_threads_running(). + +gdb_test "continue" \ + ".*Breakpoint 2, all_threads_running ().*" \ + "run to all_threads_running" + +# NOTE: Don't turn on scheduler-locking here. +# We want the main thread (hand_call_with_signal) and +# thread 1 (sigabrt_handler) to both run. + +gdb_test "call hand_call_with_signal()" \ + ".*in another thread.*" \ + "hand-call interrupted by signal in another thread" + +# Verify dummy stack frame is still present. + +gdb_test "maint print dummy-frames" ".*stack=.*" "dummy stack frame present" + +# Continuing now should exit the hand-call and pop the dummy frame. + +gdb_test "continue" "" "finish hand-call" + +gdb_test_multiple "maint print dummy-frames" "dummy frame popped" { + -re ".*stack=.*$gdb_prompt $" { + fail "dummy frame popped" + } + -re ".*$gdb_prompt $" { + pass "dummy frame popped" + } +} + +# Continue one last time, the program should exit normally. + +gdb_test "continue" "Program exited normally." \ + "continue to program exit" + +return 0 diff --git a/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp b/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp new file mode 100644 index 0000000..8d68534 --- /dev/null +++ b/gdb/testsuite/gdb.threads/thread-unwindonsignal.exp @@ -0,0 +1,117 @@ +# Copyright (C) 2008 Free Software Foundation, Inc. + +# 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/>. + +# Test use of unwindonsignal when a hand function call that gets interrupted +# by a signal in another thread. + +set NR_THREADS 4 + +if $tracelevel then { + strace $tracelevel +} + +set testfile "interrupted-hand-call" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}" "additional_flags=-DNR_THREADS=$NR_THREADS"]] != "" } { + return -1 +} + +# Some targets can't do function calls, so don't even bother with this +# test. +if [target_info exists gdb,cannot_call_functions] { + setup_xfail "*-*-*" 2416 + fail "This target can not call functions" + continue +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if { ![runto_main] } { + fail "Can't run to main" + return 0 +} + +gdb_test "break all_threads_running" \ + "Breakpoint 2 at .*: file .*${srcfile}, line .*" \ + "breakpoint on all_threads_running" + +# Run the program and make sure GDB reports that we stopped after +# hitting breakpoint 2 in all_threads_running(). + +gdb_test "continue" \ + ".*Breakpoint 2, all_threads_running ().*" \ + "run to all_threads_running" + +# NOTE: Don't turn on scheduler-locking here. +# We want the main thread (hand_call_with_signal) and +# thread 1 (sigabrt_handler) to both run. + +# Do turn on unwindonsignal. +# We want to test gdb handling of the current thread changing when +# unwindonsignal is in effect. +gdb_test "set unwindonsignal on" \ + "" \ + "setting unwindonsignal" +gdb_test "show unwindonsignal" \ + "Unwinding of stack .* is on." \ + "showing unwindonsignal" + +gdb_test "call hand_call_with_signal()" \ + "The program received a signal.*" \ + "hand-call interrupted by signal in another thread" + +# Verify dummy stack frame is still present. +# ??? Should unwindonsignal still apply even if the program stops +# because of a signal in another thread? + +gdb_test "maint print dummy-frames" ".*stack=.*" "dummy stack frame present" + +# GDB 6.8 would perform the unwindonsignal, but on the thread that stopped, +# not the thread with the hand-called function. +# This is tested by verifying only one thread has main in its backtrace. + +gdb_test_multiple "thread apply all bt" "wrong thread not unwound" { + -re ".* in main .* in main .*$gdb_prompt $" { + fail "wrong thread not unwound" + } + -re ".* in main .*$gdb_prompt $" { + pass "wrong thread not unwound" + } +} + +# Continuing now should exit the hand-call and pop the dummy frame. + +gdb_test "continue" "" "finish hand-call" + +gdb_test_multiple "maint print dummy-frames" "dummy frame popped" { + -re ".*stack=.*$gdb_prompt $" { + fail "dummy frame popped" + } + -re ".*$gdb_prompt $" { + pass "dummy frame popped" + } +} + +# Continue one last time, the program should exit normally. + +gdb_test "continue" "Program exited normally." \ + "continue to program exit" + +return 0 |