1 /* This test program is part of GDB, the GNU debugger.
3 Copyright 2015-2020 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* This is the test program loaded into GDB by the py-unwind test. */
25 swap_value (void **location
, void *new_value
)
27 void *old_value
= *location
;
28 *location
= new_value
;
33 bad_layout(void **variable_ptr
, void *fp
)
35 fprintf (stderr
, "First variable should be allocated one word below "
36 "the frame. Got variable's address %p, frame at %p instead.\n",
41 #define MY_FRAME (__builtin_frame_address (0))
44 corrupt_frame_inner (void)
46 /* Save outer frame address, then corrupt the unwind chain by
47 setting the outer frame address in it to self. This is
48 ABI-specific: the first word of the frame contains previous frame
50 void *previous_fp
= swap_value ((void **) MY_FRAME
, MY_FRAME
);
52 /* Verify the compiler allocates the first local variable one word
53 below frame. This is where the test unwinder expects to find the
54 correct outer frame address. */
55 if (&previous_fp
+ 1 != (void **) MY_FRAME
)
56 bad_layout (&previous_fp
+ 1, MY_FRAME
);
58 /* Now restore it so that we can return. The test sets the
59 breakpoint just before this happens, and GDB will not be able to
60 show the backtrace without JIT reader. */
61 swap_value ((void **) MY_FRAME
, previous_fp
); /* break backtrace-broken */
65 corrupt_frame_outer (void)
67 /* See above for the explanation of the code here. This function
68 corrupts its frame, too, and then calls the inner one. */
69 void *previous_fp
= swap_value ((void **) MY_FRAME
, MY_FRAME
);
70 if (&previous_fp
+ 1 != (void **) MY_FRAME
)
71 bad_layout (&previous_fp
, MY_FRAME
);
72 corrupt_frame_inner ();
73 swap_value ((void **) MY_FRAME
, previous_fp
);
79 corrupt_frame_outer ();
This page took 0.033005 seconds and 4 git commands to generate.