diff options
author | Markus Metzger <markus.t.metzger@intel.com> | 2016-01-26 14:58:44 +0100 |
---|---|---|
committer | Markus Metzger <markus.t.metzger@intel.com> | 2016-02-12 09:49:48 +0100 |
commit | 33b4777ca1b7b456af8201b98eda27d1b272cbab (patch) | |
tree | ed42f9fc456aba8951c1abcb4ecf050b434caaab /gdb/testsuite/gdb.btrace/tailcall-only.c | |
parent | a038fa3e14a477d4d72a26c2e139fa47d2774be2 (diff) | |
download | gdb-33b4777ca1b7b456af8201b98eda27d1b272cbab.zip gdb-33b4777ca1b7b456af8201b98eda27d1b272cbab.tar.gz gdb-33b4777ca1b7b456af8201b98eda27d1b272cbab.tar.bz2 |
btrace, frame: fix crash in get_frame_type
In skip_artificial_frames we repeatedly call get_prev_frame_always until we get
a non-inline and non-tailcall frame assuming that there must be such a frame
eventually.
For record targets, however, we may have a frame chain that consists only of
artificial frames. This leads to a crash in get_frame_type when dereferencing a
NULL frame pointer.
Change skip_artificial_frames and skip_tailcall_frames to return NULL in such a
case and modify each caller to cope with a NULL return.
In frame_unwind_caller_pc and frame_unwind_caller_arch, we simply assert that
the returned value is not NULL. Their caller was supposed to check
frame_unwind_caller_id before calling those functions.
In other cases, we thrown an error.
In infcmd further move the skip_tailcall_frames call to the forward-stepping
case since we don't need a frame for reverse execution and we don't want to fail
because of that. Reverse-finish does make sense for a tailcall frame.
gdb/
* frame.h (skip_tailcall_frames): Update comment.
* frame.c (skip_artificial_frames, skip_tailcall_frames): Return NULL
if only artificial frames are found. Update comment.
(frame_unwind_caller_id): Handle NULL return.
(frame_unwind_caller_pc, frame_unwind_caller_arch): Assert that
skip_artificial_frames does not return NULL.
(frame_pop): Add an error if only tailcall frames are found.
* infcmd.c (finish_command): Move skip_tailcall_frames call into forward-
execution case. Add an error if only tailcall frames are found.
testsuite/
* gdb.btrace/tailcall-only.exp: New.
* gdb.btrace/tailcall-only.c: New.
* gdb.btrace/x86_64-tailcall-only.S: New.
* gdb.btrace/i686-tailcall-only.S: New.
Diffstat (limited to 'gdb/testsuite/gdb.btrace/tailcall-only.c')
-rw-r--r-- | gdb/testsuite/gdb.btrace/tailcall-only.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.btrace/tailcall-only.c b/gdb/testsuite/gdb.btrace/tailcall-only.c new file mode 100644 index 0000000..5913ddc --- /dev/null +++ b/gdb/testsuite/gdb.btrace/tailcall-only.c @@ -0,0 +1,53 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 Free Software Foundation, Inc. + + Contributed by Intel Corp. <markus.t.metzger@intel.com> + + 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/>. */ + +static __attribute__ ((noinline)) int +bar_1 (void) +{ + return 42; +} + +static __attribute__ ((noinline)) int +bar (void) +{ + return bar_1 (); +} + +static __attribute__ ((noinline)) int +foo_1 (void) +{ + return bar (); +} + +static __attribute__ ((noinline)) int +foo (void) +{ + return foo_1 (); +} + +int +main (void) +{ + int answer; + + answer = foo (); + answer += 1; + + return answer; +} |