1 /* This test program is part of GDB, the GNU debugger.
3 Copyright 2011-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 /* Simulate loading of JIT code. */
32 #include "jit-protocol.h"
33 #include "jit-elf-util.h"
38 fprintf (stderr
, "Usage: jit-elf-main libraries...\n");
42 /* Defined by the .exp file if testing attach. */
51 /* Must be defined by .exp file when compiling to know
52 what address to map the ELF binary to. */
54 #error "Must define LOAD_ADDRESS"
56 #ifndef LOAD_INCREMENT
57 #error "Must define LOAD_INCREMENT"
60 /* Used to spin waiting for GDB. */
61 volatile int wait_for_gdb
= ATTACH
;
62 #define WAIT_FOR_GDB do {} while (wait_for_gdb)
64 /* The current process's PID. GDB retrieves this. */
68 MAIN (int argc
, char *argv
[])
72 /* Used as backing storage for GDB to populate argv. */
76 /* gdb break here 0 */
84 for (i
= 1; i
< argc
; ++i
)
87 void *load_addr
= (void *) (size_t) (LOAD_ADDRESS
+ (i
- 1) * LOAD_INCREMENT
);
88 printf ("Loading %s as JIT at %p\n", argv
[i
], load_addr
);
89 void *addr
= load_elf (argv
[i
], &obj_size
, load_addr
);
92 sprintf (name
, "jit_function_%04d", i
);
93 int (*jit_function
) (void) = (int (*) (void)) load_symbol (addr
, name
);
95 /* Link entry at the end of the list. */
96 struct jit_code_entry
*const entry
= calloc (1, sizeof (*entry
));
97 entry
->symfile_addr
= (const char *)addr
;
98 entry
->symfile_size
= obj_size
;
99 entry
->prev_entry
= __jit_debug_descriptor
.relevant_entry
;
100 __jit_debug_descriptor
.relevant_entry
= entry
;
102 if (entry
->prev_entry
!= NULL
)
103 entry
->prev_entry
->next_entry
= entry
;
105 __jit_debug_descriptor
.first_entry
= entry
;
108 __jit_debug_descriptor
.action_flag
= JIT_REGISTER
;
109 __jit_debug_register_code ();
111 if (jit_function () != 42)
113 fprintf (stderr
, "unexpected return value\n");
118 WAIT_FOR_GDB
; i
= 0; /* gdb break here 1 */
120 /* Now unregister them all in reverse order. */
121 while (__jit_debug_descriptor
.relevant_entry
!= NULL
)
123 struct jit_code_entry
*const entry
=
124 __jit_debug_descriptor
.relevant_entry
;
125 struct jit_code_entry
*const prev_entry
= entry
->prev_entry
;
127 if (prev_entry
!= NULL
)
129 prev_entry
->next_entry
= NULL
;
130 entry
->prev_entry
= NULL
;
133 __jit_debug_descriptor
.first_entry
= NULL
;
136 __jit_debug_descriptor
.action_flag
= JIT_UNREGISTER
;
137 __jit_debug_register_code ();
139 __jit_debug_descriptor
.relevant_entry
= prev_entry
;
143 WAIT_FOR_GDB
; return 0; /* gdb break here 2 */
This page took 0.033684 seconds and 4 git commands to generate.