Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: gdb/jit.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/iq2000-tdep.c ('k') | gdb/jit-reader.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Handle JIT code generation in the inferior for GDB, the GNU Debugger. 1 /* Handle JIT code generation in the inferior for GDB, the GNU Debugger.
2 2
3 Copyright (C) 2009-2012 Free Software Foundation, Inc. 3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 static int 121 static int
122 mem_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb) 122 mem_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
123 { 123 {
124 struct target_buffer *buffer = (struct target_buffer*) stream; 124 struct target_buffer *buffer = (struct target_buffer*) stream;
125 125
126 sb->st_size = buffer->size; 126 sb->st_size = buffer->size;
127 return 0; 127 return 0;
128 } 128 }
129 129
130 /* Open a BFD from the target's memory. */
131
132 static struct bfd *
133 bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size, char *target)
134 {
135 const char *filename = xstrdup ("<in-memory>");
136 struct target_buffer *buffer = xmalloc (sizeof (struct target_buffer));
137
138 buffer->base = addr;
139 buffer->size = size;
140 return bfd_openr_iovec (filename, target,
141 mem_bfd_iovec_open,
142 buffer,
143 mem_bfd_iovec_pread,
144 mem_bfd_iovec_close,
145 mem_bfd_iovec_stat);
146 }
147
130 /* One reader that has been loaded successfully, and can potentially be used to 148 /* One reader that has been loaded successfully, and can potentially be used to
131 parse debug info. */ 149 parse debug info. */
132 150
133 static struct jit_reader 151 static struct jit_reader
134 { 152 {
135 struct gdb_reader_funcs *functions; 153 struct gdb_reader_funcs *functions;
136 void *handle; 154 void *handle;
137 } *loaded_jit_reader = NULL; 155 } *loaded_jit_reader = NULL;
138 156
139 typedef struct gdb_reader_funcs * (reader_init_fn_type) (void); 157 typedef struct gdb_reader_funcs * (reader_init_fn_type) (void);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 discard_cleanups (old_cleanups); 193 discard_cleanups (old_cleanups);
176 return new_reader; 194 return new_reader;
177 } 195 }
178 196
179 /* Provides the jit-reader-load command. */ 197 /* Provides the jit-reader-load command. */
180 198
181 static void 199 static void
182 jit_reader_load_command (char *args, int from_tty) 200 jit_reader_load_command (char *args, int from_tty)
183 { 201 {
184 char *so_name; 202 char *so_name;
185 int len;
186 struct cleanup *prev_cleanup; 203 struct cleanup *prev_cleanup;
187 204
188 if (args == NULL) 205 if (args == NULL)
189 error (_("No reader name provided.")); 206 error (_("No reader name provided."));
190 207
191 if (loaded_jit_reader != NULL) 208 if (loaded_jit_reader != NULL)
192 error (_("JIT reader already loaded. Run jit-reader-unload first.")); 209 error (_("JIT reader already loaded. Run jit-reader-unload first."));
193 210
194 so_name = xstrprintf ("%s/%s", jit_reader_dir, args); 211 so_name = xstrprintf ("%s/%s", jit_reader_dir, args);
195 prev_cleanup = make_cleanup (xfree, so_name); 212 prev_cleanup = make_cleanup (xfree, so_name);
(...skipping 10 matching lines...) Expand all
206 if (!loaded_jit_reader) 223 if (!loaded_jit_reader)
207 error (_("No JIT reader loaded.")); 224 error (_("No JIT reader loaded."));
208 225
209 loaded_jit_reader->functions->destroy (loaded_jit_reader->functions); 226 loaded_jit_reader->functions->destroy (loaded_jit_reader->functions);
210 227
211 gdb_dlclose (loaded_jit_reader->handle); 228 gdb_dlclose (loaded_jit_reader->handle);
212 xfree (loaded_jit_reader); 229 xfree (loaded_jit_reader);
213 loaded_jit_reader = NULL; 230 loaded_jit_reader = NULL;
214 } 231 }
215 232
216 /* Open a BFD from the target's memory. */ 233 /* Per-inferior structure recording which objfile has the JIT
217 234 symbols. */
218 static struct bfd *
219 bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size, char *target)
220 {
221 const char *filename = xstrdup ("<in-memory>");
222 struct target_buffer *buffer = xmalloc (sizeof (struct target_buffer));
223
224 buffer->base = addr;
225 buffer->size = size;
226 return bfd_openr_iovec (filename, target,
227 mem_bfd_iovec_open,
228 buffer,
229 mem_bfd_iovec_pread,
230 mem_bfd_iovec_close,
231 mem_bfd_iovec_stat);
232 }
233
234 /* Per-inferior structure recording the addresses in the inferior. */
235 235
236 struct jit_inferior_data 236 struct jit_inferior_data
237 { 237 {
238 CORE_ADDR breakpoint_addr; /* &__jit_debug_register_code() */ 238 /* The objfile. This is NULL if no objfile holds the JIT
239 CORE_ADDR descriptor_addr; /* &__jit_debug_descriptor */ 239 symbols. */
240
241 struct objfile *objfile;
240 }; 242 };
241 243
244 /* Per-objfile structure recording the addresses in the inferior. */
245
246 struct jit_objfile_data
247 {
248 /* Symbol for __jit_debug_register_code. */
249 struct minimal_symbol *register_code;
250
251 /* Symbol for __jit_debug_descriptor. */
252 struct minimal_symbol *descriptor;
253
254 /* Address of struct jit_code_entry in this objfile. */
255 CORE_ADDR addr;
256 };
257
258 /* Fetch the jit_objfile_data associated with OBJF. If no data exists
259 yet, make a new structure and attach it. */
260
261 static struct jit_objfile_data *
262 get_jit_objfile_data (struct objfile *objf)
263 {
264 struct jit_objfile_data *objf_data;
265
266 objf_data = objfile_data (objf, jit_objfile_data);
267 if (objf_data == NULL)
268 {
269 objf_data = XZALLOC (struct jit_objfile_data);
270 set_objfile_data (objf, jit_objfile_data, objf_data);
271 }
272
273 return objf_data;
274 }
275
242 /* Remember OBJFILE has been created for struct jit_code_entry located 276 /* Remember OBJFILE has been created for struct jit_code_entry located
243 at inferior address ENTRY. */ 277 at inferior address ENTRY. */
244 278
245 static void 279 static void
246 add_objfile_entry (struct objfile *objfile, CORE_ADDR entry) 280 add_objfile_entry (struct objfile *objfile, CORE_ADDR entry)
247 { 281 {
248 CORE_ADDR *entry_addr_ptr; 282 struct jit_objfile_data *objf_data;
249 283
250 entry_addr_ptr = xmalloc (sizeof (CORE_ADDR)); 284 objf_data = get_jit_objfile_data (objfile);
251 *entry_addr_ptr = entry; 285 objf_data->addr = entry;
252 set_objfile_data (objfile, jit_objfile_data, entry_addr_ptr);
253 } 286 }
254 287
255 /* Return jit_inferior_data for current inferior. Allocate if not already 288 /* Return jit_inferior_data for current inferior. Allocate if not already
256 present. */ 289 present. */
257 290
258 static struct jit_inferior_data * 291 static struct jit_inferior_data *
259 get_jit_inferior_data (void) 292 get_jit_inferior_data (void)
260 { 293 {
261 struct inferior *inf; 294 struct inferior *inf;
262 struct jit_inferior_data *inf_data; 295 struct jit_inferior_data *inf_data;
263 296
264 inf = current_inferior (); 297 inf = current_inferior ();
265 inf_data = inferior_data (inf, jit_inferior_data); 298 inf_data = inferior_data (inf, jit_inferior_data);
266 if (inf_data == NULL) 299 if (inf_data == NULL)
267 { 300 {
268 inf_data = XZALLOC (struct jit_inferior_data); 301 inf_data = XZALLOC (struct jit_inferior_data);
269 set_inferior_data (inf, jit_inferior_data, inf_data); 302 set_inferior_data (inf, jit_inferior_data, inf_data);
270 } 303 }
271 304
272 return inf_data; 305 return inf_data;
273 } 306 }
274 307
275 static void 308 static void
276 jit_inferior_data_cleanup (struct inferior *inf, void *arg) 309 jit_inferior_data_cleanup (struct inferior *inf, void *arg)
277 { 310 {
278 xfree (arg); 311 xfree (arg);
279 } 312 }
280 313
281 /* Helper function for reading the global JIT descriptor from remote 314 /* Helper function for reading the global JIT descriptor from remote
282 memory. */ 315 memory. Returns 1 if all went well, 0 otherwise. */
283 316
284 static void 317 static int
285 jit_read_descriptor (struct gdbarch *gdbarch, 318 jit_read_descriptor (struct gdbarch *gdbarch,
286 struct jit_descriptor *descriptor, 319 struct jit_descriptor *descriptor,
287 » » CORE_ADDR descriptor_addr) 320 » » struct jit_inferior_data *inf_data)
288 { 321 {
289 int err; 322 int err;
290 struct type *ptr_type; 323 struct type *ptr_type;
291 int ptr_size; 324 int ptr_size;
292 int desc_size; 325 int desc_size;
293 gdb_byte *desc_buf; 326 gdb_byte *desc_buf;
294 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 327 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
328 struct jit_objfile_data *objf_data;
329
330 if (inf_data->objfile == NULL)
331 return 0;
332 objf_data = get_jit_objfile_data (inf_data->objfile);
333 if (objf_data->descriptor == NULL)
334 return 0;
335
336 if (jit_debug)
337 fprintf_unfiltered (gdb_stdlog,
338 "jit_read_descriptor, descriptor_addr = %s\n",
339 paddress (gdbarch, SYMBOL_VALUE_ADDRESS (objf_data->desc riptor)));
295 340
296 /* Figure out how big the descriptor is on the remote and how to read it. */ 341 /* Figure out how big the descriptor is on the remote and how to read it. */
297 ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 342 ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
298 ptr_size = TYPE_LENGTH (ptr_type); 343 ptr_size = TYPE_LENGTH (ptr_type);
299 desc_size = 8 + 2 * ptr_size; /* Two 32-bit ints and two pointers. */ 344 desc_size = 8 + 2 * ptr_size; /* Two 32-bit ints and two pointers. */
300 desc_buf = alloca (desc_size); 345 desc_buf = alloca (desc_size);
301 346
302 /* Read the descriptor. */ 347 /* Read the descriptor. */
303 err = target_read_memory (descriptor_addr, desc_buf, desc_size); 348 err = target_read_memory (SYMBOL_VALUE_ADDRESS (objf_data->descriptor),
349 » » » desc_buf, desc_size);
304 if (err) 350 if (err)
305 error (_("Unable to read JIT descriptor from remote memory!")); 351 {
352 printf_unfiltered (_("Unable to read JIT descriptor from "
353 » » » "remote memory\n"));
354 return 0;
355 }
306 356
307 /* Fix the endianness to match the host. */ 357 /* Fix the endianness to match the host. */
308 descriptor->version = extract_unsigned_integer (&desc_buf[0], 4, byte_order); 358 descriptor->version = extract_unsigned_integer (&desc_buf[0], 4, byte_order);
309 descriptor->action_flag = 359 descriptor->action_flag =
310 extract_unsigned_integer (&desc_buf[4], 4, byte_order); 360 extract_unsigned_integer (&desc_buf[4], 4, byte_order);
311 descriptor->relevant_entry = extract_typed_address (&desc_buf[8], ptr_type); 361 descriptor->relevant_entry = extract_typed_address (&desc_buf[8], ptr_type);
312 descriptor->first_entry = 362 descriptor->first_entry =
313 extract_typed_address (&desc_buf[8 + ptr_size], ptr_type); 363 extract_typed_address (&desc_buf[8 + ptr_size], ptr_type);
364
365 return 1;
314 } 366 }
315 367
316 /* Helper function for reading a JITed code entry from remote memory. */ 368 /* Helper function for reading a JITed code entry from remote memory. */
317 369
318 static void 370 static void
319 jit_read_code_entry (struct gdbarch *gdbarch, 371 jit_read_code_entry (struct gdbarch *gdbarch,
320 CORE_ADDR code_addr, struct jit_code_entry *code_entry) 372 CORE_ADDR code_addr, struct jit_code_entry *code_entry)
321 { 373 {
322 int err, off; 374 int err, off;
323 struct type *ptr_type; 375 struct type *ptr_type;
324 int ptr_size; 376 int ptr_size;
325 int entry_size; 377 int entry_size;
326 int align_bytes; 378 int align_bytes;
327 gdb_byte *entry_buf; 379 gdb_byte *entry_buf;
328 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 380 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
329 381
330 /* Figure out how big the entry is on the remote and how to read it. */ 382 /* Figure out how big the entry is on the remote and how to read it. */
331 ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 383 ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
332 ptr_size = TYPE_LENGTH (ptr_type); 384 ptr_size = TYPE_LENGTH (ptr_type);
333 entry_size = 3 * ptr_size + 8; /* Three pointers and one 64-bit int. */ 385
386 /* Figure out where the longlong value will be. */
387 align_bytes = gdbarch_long_long_align_bit (gdbarch) / 8;
388 off = 3 * ptr_size;
389 off = (off + (align_bytes - 1)) & ~(align_bytes - 1);
390
391 entry_size = off + 8; /* Three pointers and one 64-bit int. */
334 entry_buf = alloca (entry_size); 392 entry_buf = alloca (entry_size);
335 393
336 /* Read the entry. */ 394 /* Read the entry. */
337 err = target_read_memory (code_addr, entry_buf, entry_size); 395 err = target_read_memory (code_addr, entry_buf, entry_size);
338 if (err) 396 if (err)
339 error (_("Unable to read JIT code entry from remote memory!")); 397 error (_("Unable to read JIT code entry from remote memory!"));
340 398
341 /* Fix the endianness to match the host. */ 399 /* Fix the endianness to match the host. */
342 ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 400 ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
343 code_entry->next_entry = extract_typed_address (&entry_buf[0], ptr_type); 401 code_entry->next_entry = extract_typed_address (&entry_buf[0], ptr_type);
344 code_entry->prev_entry = 402 code_entry->prev_entry =
345 extract_typed_address (&entry_buf[ptr_size], ptr_type); 403 extract_typed_address (&entry_buf[ptr_size], ptr_type);
346 code_entry->symfile_addr = 404 code_entry->symfile_addr =
347 extract_typed_address (&entry_buf[2 * ptr_size], ptr_type); 405 extract_typed_address (&entry_buf[2 * ptr_size], ptr_type);
348
349 align_bytes = gdbarch_long_long_align_bit (gdbarch) / 8;
350 off = 3 * ptr_size;
351 off = (off + (align_bytes - 1)) & ~(align_bytes - 1);
352
353 code_entry->symfile_size = 406 code_entry->symfile_size =
354 extract_unsigned_integer (&entry_buf[off], 8, byte_order); 407 extract_unsigned_integer (&entry_buf[off], 8, byte_order);
355 } 408 }
356 409
357 /* Proxy object for building a block. */ 410 /* Proxy object for building a block. */
358 411
359 struct gdb_block 412 struct gdb_block
360 { 413 {
361 /* gdb_blocks are linked into a tree structure. Next points to the 414 /* gdb_blocks are linked into a tree structure. Next points to the
362 next node at the same depth as this block and parent to the 415 next node at the same depth as this block and parent to the
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 /* First run over all the gdb_block objects, creating a real block 653 /* First run over all the gdb_block objects, creating a real block
601 object for each. Simultaneously, keep setting the real_block 654 object for each. Simultaneously, keep setting the real_block
602 fields. */ 655 fields. */
603 for (i = (actual_nblocks - 1), gdb_block_iter = stab->blocks; 656 for (i = (actual_nblocks - 1), gdb_block_iter = stab->blocks;
604 i >= FIRST_LOCAL_BLOCK; 657 i >= FIRST_LOCAL_BLOCK;
605 i--, gdb_block_iter = gdb_block_iter->next) 658 i--, gdb_block_iter = gdb_block_iter->next)
606 { 659 {
607 struct block *new_block = allocate_block (&objfile->objfile_obstack); 660 struct block *new_block = allocate_block (&objfile->objfile_obstack);
608 struct symbol *block_name = obstack_alloc (&objfile->objfile_obstack, 661 struct symbol *block_name = obstack_alloc (&objfile->objfile_obstack,
609 sizeof (struct symbol)); 662 sizeof (struct symbol));
663 struct type *block_type = arch_type (get_objfile_arch (objfile),
664 TYPE_CODE_VOID,
665 1,
666 "void");
610 667
611 BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack, 668 BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
612 NULL); 669 NULL);
613 /* The address range. */ 670 /* The address range. */
614 BLOCK_START (new_block) = (CORE_ADDR) gdb_block_iter->begin; 671 BLOCK_START (new_block) = (CORE_ADDR) gdb_block_iter->begin;
615 BLOCK_END (new_block) = (CORE_ADDR) gdb_block_iter->end; 672 BLOCK_END (new_block) = (CORE_ADDR) gdb_block_iter->end;
616 673
617 /* The name. */ 674 /* The name. */
618 memset (block_name, 0, sizeof (struct symbol)); 675 memset (block_name, 0, sizeof (struct symbol));
619 SYMBOL_DOMAIN (block_name) = VAR_DOMAIN; 676 SYMBOL_DOMAIN (block_name) = VAR_DOMAIN;
620 SYMBOL_CLASS (block_name) = LOC_BLOCK; 677 SYMBOL_CLASS (block_name) = LOC_BLOCK;
621 SYMBOL_SYMTAB (block_name) = symtab; 678 SYMBOL_SYMTAB (block_name) = symtab;
679 SYMBOL_TYPE (block_name) = lookup_function_type (block_type);
622 SYMBOL_BLOCK_VALUE (block_name) = new_block; 680 SYMBOL_BLOCK_VALUE (block_name) = new_block;
623 681
624 block_name->ginfo.name = obsavestring (gdb_block_iter->name, 682 block_name->ginfo.name = obsavestring (gdb_block_iter->name,
625 strlen (gdb_block_iter->name), 683 strlen (gdb_block_iter->name),
626 &objfile->objfile_obstack); 684 &objfile->objfile_obstack);
627 685
628 BLOCK_FUNCTION (new_block) = block_name; 686 BLOCK_FUNCTION (new_block) = block_name;
629 687
630 BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block; 688 BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
631 if (begin > BLOCK_START (new_block)) 689 if (begin > BLOCK_START (new_block))
632 begin = BLOCK_START (new_block); 690 begin = BLOCK_START (new_block);
633 if (end < BLOCK_END (new_block)) 691 if (end < BLOCK_END (new_block))
634 end = BLOCK_END (new_block); 692 end = BLOCK_END (new_block);
635 693
636 gdb_block_iter->real_block = new_block; 694 gdb_block_iter->real_block = new_block;
637 } 695 }
638 696
639 /* Now add the special blocks. */ 697 /* Now add the special blocks. */
640 block_iter = NULL; 698 block_iter = NULL;
641 for (i = 0; i < FIRST_LOCAL_BLOCK; i++) 699 for (i = 0; i < FIRST_LOCAL_BLOCK; i++)
642 { 700 {
643 struct block *new_block = allocate_block (&objfile->objfile_obstack); 701 struct block *new_block;
702
703 new_block = (i == GLOBAL_BLOCK
704 » » ? allocate_global_block (&objfile->objfile_obstack)
705 » » : allocate_block (&objfile->objfile_obstack));
644 BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack, 706 BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
645 NULL); 707 NULL);
646 BLOCK_SUPERBLOCK (new_block) = block_iter; 708 BLOCK_SUPERBLOCK (new_block) = block_iter;
647 block_iter = new_block; 709 block_iter = new_block;
648 710
649 BLOCK_START (new_block) = (CORE_ADDR) begin; 711 BLOCK_START (new_block) = (CORE_ADDR) begin;
650 BLOCK_END (new_block) = (CORE_ADDR) end; 712 BLOCK_END (new_block) = (CORE_ADDR) end;
651 713
652 BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block; 714 BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
715
716 if (i == GLOBAL_BLOCK)
717 set_block_symtab (new_block, symtab);
653 } 718 }
654 719
655 /* Fill up the superblock fields for the real blocks, using the 720 /* Fill up the superblock fields for the real blocks, using the
656 real_block fields populated earlier. */ 721 real_block fields populated earlier. */
657 for (gdb_block_iter = stab->blocks; 722 for (gdb_block_iter = stab->blocks;
658 gdb_block_iter; 723 gdb_block_iter;
659 gdb_block_iter = gdb_block_iter->next) 724 gdb_block_iter = gdb_block_iter->next)
660 { 725 {
661 if (gdb_block_iter->parent != NULL) 726 if (gdb_block_iter->parent != NULL)
662 BLOCK_SUPERBLOCK (gdb_block_iter->real_block) = 727 BLOCK_SUPERBLOCK (gdb_block_iter->real_block) =
(...skipping 24 matching lines...) Expand all
687 { 752 {
688 struct gdb_symtab *i, *j; 753 struct gdb_symtab *i, *j;
689 struct objfile *objfile; 754 struct objfile *objfile;
690 jit_dbg_reader_data *priv_data; 755 jit_dbg_reader_data *priv_data;
691 756
692 priv_data = cb->priv_data; 757 priv_data = cb->priv_data;
693 758
694 objfile = allocate_objfile (NULL, 0); 759 objfile = allocate_objfile (NULL, 0);
695 objfile->gdbarch = target_gdbarch; 760 objfile->gdbarch = target_gdbarch;
696 761
697 objfile->msymbols = obstack_alloc (&objfile->objfile_obstack, 762 terminate_minimal_symbol_table (objfile);
698 sizeof (struct minimal_symbol));
699 memset (objfile->msymbols, 0, sizeof (struct minimal_symbol));
700 763
701 xfree (objfile->name); 764 xfree (objfile->name);
702 objfile->name = xstrdup ("<< JIT compiled code >>"); 765 objfile->name = xstrdup ("<< JIT compiled code >>");
703 766
704 j = NULL; 767 j = NULL;
705 for (i = obj->symtabs; i; i = j) 768 for (i = obj->symtabs; i; i = j)
706 { 769 {
707 j = i->next; 770 j = i->next;
708 finalize_symtab (i, objfile); 771 finalize_symtab (i, objfile);
709 } 772 }
710 add_objfile_entry (objfile, *priv_data); 773 add_objfile_entry (objfile, *priv_data);
711 xfree (obj); 774 xfree (obj);
712 } 775 }
713 776
714 /* Try to read CODE_ENTRY using the loaded jit reader (if any). 777 /* Try to read CODE_ENTRY using the loaded jit reader (if any).
715 ENTRY_ADDR is the address of the struct jit_code_entry in the 778 ENTRY_ADDR is the address of the struct jit_code_entry in the
716 inferior address space. */ 779 inferior address space. */
717 780
718 static int 781 static int
719 jit_reader_try_read_symtab (struct jit_code_entry *code_entry, 782 jit_reader_try_read_symtab (struct jit_code_entry *code_entry,
720 CORE_ADDR entry_addr) 783 CORE_ADDR entry_addr)
721 { 784 {
722 void *gdb_mem; 785 void *gdb_mem;
723 int status; 786 int status;
724 struct jit_dbg_reader *i;
725 jit_dbg_reader_data priv_data; 787 jit_dbg_reader_data priv_data;
726 struct gdb_reader_funcs *funcs; 788 struct gdb_reader_funcs *funcs;
727 volatile struct gdb_exception e; 789 volatile struct gdb_exception e;
728 struct gdb_symbol_callbacks callbacks = 790 struct gdb_symbol_callbacks callbacks =
729 { 791 {
730 jit_object_open_impl, 792 jit_object_open_impl,
731 jit_symtab_open_impl, 793 jit_symtab_open_impl,
732 jit_block_open_impl, 794 jit_block_open_impl,
733 jit_symtab_close_impl, 795 jit_symtab_close_impl,
734 jit_object_close_impl, 796 jit_object_close_impl,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 { 937 {
876 free_objfile (objfile); 938 free_objfile (objfile);
877 } 939 }
878 940
879 /* Look up the objfile with this code entry address. */ 941 /* Look up the objfile with this code entry address. */
880 942
881 static struct objfile * 943 static struct objfile *
882 jit_find_objf_with_entry_addr (CORE_ADDR entry_addr) 944 jit_find_objf_with_entry_addr (CORE_ADDR entry_addr)
883 { 945 {
884 struct objfile *objf; 946 struct objfile *objf;
885 CORE_ADDR *objf_entry_addr;
886 947
887 ALL_OBJFILES (objf) 948 ALL_OBJFILES (objf)
888 { 949 {
889 objf_entry_addr = (CORE_ADDR *) objfile_data (objf, jit_objfile_data); 950 struct jit_objfile_data *objf_data;
890 if (objf_entry_addr != NULL && *objf_entry_addr == entry_addr) 951
952 objf_data = objfile_data (objf, jit_objfile_data);
953 if (objf_data != NULL && objf_data->addr == entry_addr)
891 return objf; 954 return objf;
892 } 955 }
893 return NULL; 956 return NULL;
894 } 957 }
895 958
896 /* (Re-)Initialize the jit breakpoint if necessary. 959 /* (Re-)Initialize the jit breakpoint if necessary.
897 Return 0 on success. */ 960 Return 0 on success. */
898 961
899 static int 962 static int
900 jit_breakpoint_re_set_internal (struct gdbarch *gdbarch, 963 jit_breakpoint_re_set_internal (struct gdbarch *gdbarch,
901 struct jit_inferior_data *inf_data) 964 struct jit_inferior_data *inf_data)
902 { 965 {
903 if (inf_data->breakpoint_addr == 0) 966 struct minimal_symbol *reg_symbol, *desc_symbol;
904 { 967 struct objfile *objf;
905 struct minimal_symbol *reg_symbol; 968 struct jit_objfile_data *objf_data;
906 969
907 /* Lookup the registration symbol. If it is missing, then we assume 970 if (inf_data->objfile != NULL)
908 » we are not attached to a JIT. */ 971 return 0;
909 reg_symbol = lookup_minimal_symbol (jit_break_name, NULL, NULL);
910 if (reg_symbol == NULL)
911 » return 1;
912 inf_data->breakpoint_addr = SYMBOL_VALUE_ADDRESS (reg_symbol);
913 if (inf_data->breakpoint_addr == 0)
914 » return 2;
915 972
916 /* If we have not read the jit descriptor yet (e.g. because the JITer 973 /* Lookup the registration symbol. If it is missing, then we assume
917 » itself is in a shared library which just got loaded), do so now. */ 974 we are not attached to a JIT. */
918 if (inf_data->descriptor_addr == 0) 975 reg_symbol = lookup_minimal_symbol_and_objfile (jit_break_name, &objf);
919 » jit_inferior_init (gdbarch); 976 if (reg_symbol == NULL || SYMBOL_VALUE_ADDRESS (reg_symbol) == 0)
920 } 977 return 1;
921 else 978
922 return 0; 979 desc_symbol = lookup_minimal_symbol (jit_descriptor_name, NULL, objf);
980 if (desc_symbol == NULL || SYMBOL_VALUE_ADDRESS (desc_symbol) == 0)
981 return 1;
982
983 objf_data = get_jit_objfile_data (objf);
984 objf_data->register_code = reg_symbol;
985 objf_data->descriptor = desc_symbol;
986
987 inf_data->objfile = objf;
988
989 jit_inferior_init (gdbarch);
923 990
924 if (jit_debug) 991 if (jit_debug)
925 fprintf_unfiltered (gdb_stdlog, 992 fprintf_unfiltered (gdb_stdlog,
926 "jit_breakpoint_re_set_internal, " 993 "jit_breakpoint_re_set_internal, "
927 "breakpoint_addr = %s\n", 994 "breakpoint_addr = %s\n",
928 » » » paddress (gdbarch, inf_data->breakpoint_addr)); 995 » » » paddress (gdbarch, SYMBOL_VALUE_ADDRESS (reg_symbol)));
929 996
930 /* Put a breakpoint in the registration symbol. */ 997 /* Put a breakpoint in the registration symbol. */
931 create_jit_event_breakpoint (gdbarch, inf_data->breakpoint_addr); 998 create_jit_event_breakpoint (gdbarch, SYMBOL_VALUE_ADDRESS (reg_symbol));
932 999
933 return 0; 1000 return 0;
934 } 1001 }
935 1002
936 /* The private data passed around in the frame unwind callback 1003 /* The private data passed around in the frame unwind callback
937 functions. */ 1004 functions. */
938 1005
939 struct jit_unwind_private 1006 struct jit_unwind_private
940 { 1007 {
941 /* Cached register values. See jit_frame_sniffer to see how this 1008 /* Cached register values. See jit_frame_sniffer to see how this
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 unwinds the frame and saves the corresponding register values in 1096 unwinds the frame and saves the corresponding register values in
1030 the cache. jit_frame_prev_register simply returns the saved 1097 the cache. jit_frame_prev_register simply returns the saved
1031 register values. */ 1098 register values. */
1032 1099
1033 static int 1100 static int
1034 jit_frame_sniffer (const struct frame_unwind *self, 1101 jit_frame_sniffer (const struct frame_unwind *self,
1035 struct frame_info *this_frame, void **cache) 1102 struct frame_info *this_frame, void **cache)
1036 { 1103 {
1037 struct jit_inferior_data *inf_data; 1104 struct jit_inferior_data *inf_data;
1038 struct jit_unwind_private *priv_data; 1105 struct jit_unwind_private *priv_data;
1039 struct jit_dbg_reader *iter;
1040 struct gdb_unwind_callbacks callbacks; 1106 struct gdb_unwind_callbacks callbacks;
1041 struct gdb_reader_funcs *funcs; 1107 struct gdb_reader_funcs *funcs;
1042 1108
1043 inf_data = get_jit_inferior_data (); 1109 inf_data = get_jit_inferior_data ();
1044 1110
1045 callbacks.reg_get = jit_unwind_reg_get_impl; 1111 callbacks.reg_get = jit_unwind_reg_get_impl;
1046 callbacks.reg_set = jit_unwind_reg_set_impl; 1112 callbacks.reg_set = jit_unwind_reg_set_impl;
1047 callbacks.target_read = jit_target_read_impl; 1113 callbacks.target_read = jit_target_read_impl;
1048 1114
1049 if (loaded_jit_reader == NULL) 1115 if (loaded_jit_reader == NULL)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1247
1182 if (jit_debug) 1248 if (jit_debug)
1183 fprintf_unfiltered (gdb_stdlog, "jit_inferior_init\n"); 1249 fprintf_unfiltered (gdb_stdlog, "jit_inferior_init\n");
1184 1250
1185 jit_prepend_unwinder (gdbarch); 1251 jit_prepend_unwinder (gdbarch);
1186 1252
1187 inf_data = get_jit_inferior_data (); 1253 inf_data = get_jit_inferior_data ();
1188 if (jit_breakpoint_re_set_internal (gdbarch, inf_data) != 0) 1254 if (jit_breakpoint_re_set_internal (gdbarch, inf_data) != 0)
1189 return; 1255 return;
1190 1256
1191 if (inf_data->descriptor_addr == 0)
1192 {
1193 struct minimal_symbol *desc_symbol;
1194
1195 /* Lookup the descriptor symbol and cache the addr. If it is
1196 missing, we assume we are not attached to a JIT and return early. */
1197 desc_symbol = lookup_minimal_symbol (jit_descriptor_name, NULL, NULL);
1198 if (desc_symbol == NULL)
1199 return;
1200
1201 inf_data->descriptor_addr = SYMBOL_VALUE_ADDRESS (desc_symbol);
1202 if (inf_data->descriptor_addr == 0)
1203 return;
1204 }
1205
1206 if (jit_debug)
1207 fprintf_unfiltered (gdb_stdlog,
1208 "jit_inferior_init, descriptor_addr = %s\n",
1209 paddress (gdbarch, inf_data->descriptor_addr));
1210
1211 /* Read the descriptor so we can check the version number and load 1257 /* Read the descriptor so we can check the version number and load
1212 any already JITed functions. */ 1258 any already JITed functions. */
1213 jit_read_descriptor (gdbarch, &descriptor, inf_data->descriptor_addr); 1259 if (!jit_read_descriptor (gdbarch, &descriptor, inf_data))
1260 return;
1214 1261
1215 /* Check that the version number agrees with that we support. */ 1262 /* Check that the version number agrees with that we support. */
1216 if (descriptor.version != 1) 1263 if (descriptor.version != 1)
1217 error (_("Unsupported JIT protocol version in descriptor!")); 1264 {
1265 printf_unfiltered (_("Unsupported JIT protocol version %ld "
1266 » » » "in descriptor (expected 1)\n"),
1267 » » » (long) descriptor.version);
1268 return;
1269 }
1218 1270
1219 /* If we've attached to a running program, we need to check the descriptor 1271 /* If we've attached to a running program, we need to check the descriptor
1220 to register any functions that were already generated. */ 1272 to register any functions that were already generated. */
1221 for (cur_entry_addr = descriptor.first_entry; 1273 for (cur_entry_addr = descriptor.first_entry;
1222 cur_entry_addr != 0; 1274 cur_entry_addr != 0;
1223 cur_entry_addr = cur_entry.next_entry) 1275 cur_entry_addr = cur_entry.next_entry)
1224 { 1276 {
1225 jit_read_code_entry (gdbarch, cur_entry_addr, &cur_entry); 1277 jit_read_code_entry (gdbarch, cur_entry_addr, &cur_entry);
1226 1278
1227 /* This hook may be called many times during setup, so make sure we don't 1279 /* This hook may be called many times during setup, so make sure we don't
(...skipping 16 matching lines...) Expand all
1244 /* Exported routine to call to re-set the jit breakpoints, 1296 /* Exported routine to call to re-set the jit breakpoints,
1245 e.g. when a program is rerun. */ 1297 e.g. when a program is rerun. */
1246 1298
1247 void 1299 void
1248 jit_breakpoint_re_set (void) 1300 jit_breakpoint_re_set (void)
1249 { 1301 {
1250 jit_breakpoint_re_set_internal (target_gdbarch, 1302 jit_breakpoint_re_set_internal (target_gdbarch,
1251 get_jit_inferior_data ()); 1303 get_jit_inferior_data ());
1252 } 1304 }
1253 1305
1254 /* Reset inferior_data, so sybols will be looked up again, and jit_breakpoint
1255 will be reset. */
1256
1257 static void
1258 jit_reset_inferior_data_and_breakpoints (void)
1259 {
1260 struct jit_inferior_data *inf_data;
1261
1262 /* Force jit_inferior_init to re-lookup of jit symbol addresses. */
1263 inf_data = get_jit_inferior_data ();
1264 inf_data->breakpoint_addr = 0;
1265 inf_data->descriptor_addr = 0;
1266
1267 /* Remove any existing JIT breakpoint(s). */
1268 remove_jit_event_breakpoints ();
1269
1270 jit_inferior_init (target_gdbarch);
1271 }
1272
1273 /* Wrapper to match the observer function pointer prototype. */
1274
1275 static void
1276 jit_inferior_created_observer (struct target_ops *objfile, int from_tty)
1277 {
1278 jit_reset_inferior_data_and_breakpoints ();
1279 }
1280
1281 /* This function cleans up any code entries left over when the 1306 /* This function cleans up any code entries left over when the
1282 inferior exits. We get left over code when the inferior exits 1307 inferior exits. We get left over code when the inferior exits
1283 without unregistering its code, for example when it crashes. */ 1308 without unregistering its code, for example when it crashes. */
1284 1309
1285 static void 1310 static void
1286 jit_inferior_exit_hook (struct inferior *inf) 1311 jit_inferior_exit_hook (struct inferior *inf)
1287 { 1312 {
1288 struct objfile *objf; 1313 struct objfile *objf;
1289 struct objfile *temp; 1314 struct objfile *temp;
1290 1315
1291 ALL_OBJFILES_SAFE (objf, temp) 1316 ALL_OBJFILES_SAFE (objf, temp)
1292 if (objfile_data (objf, jit_objfile_data) != NULL) 1317 {
1293 jit_unregister_code (objf); 1318 struct jit_objfile_data *objf_data = objfile_data (objf,
1294 } 1319 » » » » » » » jit_objfile_data);
1295 1320
1296 static void 1321 if (objf_data != NULL && objf_data->addr != 0)
1297 jit_executable_changed_observer (void) 1322 » jit_unregister_code (objf);
1298 { 1323 }
1299 jit_reset_inferior_data_and_breakpoints ();
1300 } 1324 }
1301 1325
1302 void 1326 void
1303 jit_event_handler (struct gdbarch *gdbarch) 1327 jit_event_handler (struct gdbarch *gdbarch)
1304 { 1328 {
1305 struct jit_descriptor descriptor; 1329 struct jit_descriptor descriptor;
1306 struct jit_code_entry code_entry; 1330 struct jit_code_entry code_entry;
1307 CORE_ADDR entry_addr; 1331 CORE_ADDR entry_addr;
1308 struct objfile *objf; 1332 struct objfile *objf;
1309 1333
1310 /* Read the descriptor from remote memory. */ 1334 /* Read the descriptor from remote memory. */
1311 jit_read_descriptor (gdbarch, &descriptor, 1335 if (!jit_read_descriptor (gdbarch, &descriptor, get_jit_inferior_data ()))
1312 » » get_jit_inferior_data ()->descriptor_addr); 1336 return;
1313 entry_addr = descriptor.relevant_entry; 1337 entry_addr = descriptor.relevant_entry;
1314 1338
1315 /* Do the corresponding action. */ 1339 /* Do the corresponding action. */
1316 switch (descriptor.action_flag) 1340 switch (descriptor.action_flag)
1317 { 1341 {
1318 case JIT_NOACTION: 1342 case JIT_NOACTION:
1319 break; 1343 break;
1320 case JIT_REGISTER: 1344 case JIT_REGISTER:
1321 jit_read_code_entry (gdbarch, entry_addr, &code_entry); 1345 jit_read_code_entry (gdbarch, entry_addr, &code_entry);
1322 jit_register_code (gdbarch, entry_addr, &code_entry); 1346 jit_register_code (gdbarch, entry_addr, &code_entry);
(...skipping 12 matching lines...) Expand all
1335 error (_("Unknown action_flag value in JIT descriptor!")); 1359 error (_("Unknown action_flag value in JIT descriptor!"));
1336 break; 1360 break;
1337 } 1361 }
1338 } 1362 }
1339 1363
1340 /* Called to free the data allocated to the jit_inferior_data slot. */ 1364 /* Called to free the data allocated to the jit_inferior_data slot. */
1341 1365
1342 static void 1366 static void
1343 free_objfile_data (struct objfile *objfile, void *data) 1367 free_objfile_data (struct objfile *objfile, void *data)
1344 { 1368 {
1369 struct jit_objfile_data *objf_data = data;
1370
1371 if (objf_data->register_code != NULL)
1372 {
1373 struct jit_inferior_data *inf_data = get_jit_inferior_data ();
1374
1375 if (inf_data->objfile == objfile)
1376 inf_data->objfile = NULL;
1377 }
1378
1345 xfree (data); 1379 xfree (data);
1346 } 1380 }
1347 1381
1348 /* Initialize the jit_gdbarch_data slot with an instance of struct 1382 /* Initialize the jit_gdbarch_data slot with an instance of struct
1349 jit_gdbarch_data_type */ 1383 jit_gdbarch_data_type */
1350 1384
1351 static void * 1385 static void *
1352 jit_gdbarch_data_init (struct obstack *obstack) 1386 jit_gdbarch_data_init (struct obstack *obstack)
1353 { 1387 {
1354 struct jit_gdbarch_data_type *data; 1388 struct jit_gdbarch_data_type *data;
(...skipping 13 matching lines...) Expand all
1368 jit_reader_dir = relocate_gdb_directory (JIT_READER_DIR, 1402 jit_reader_dir = relocate_gdb_directory (JIT_READER_DIR,
1369 JIT_READER_DIR_RELOCATABLE); 1403 JIT_READER_DIR_RELOCATABLE);
1370 add_setshow_zinteger_cmd ("jit", class_maintenance, &jit_debug, 1404 add_setshow_zinteger_cmd ("jit", class_maintenance, &jit_debug,
1371 _("Set JIT debugging."), 1405 _("Set JIT debugging."),
1372 _("Show JIT debugging."), 1406 _("Show JIT debugging."),
1373 _("When non-zero, JIT debugging is enabled."), 1407 _("When non-zero, JIT debugging is enabled."),
1374 NULL, 1408 NULL,
1375 show_jit_debug, 1409 show_jit_debug,
1376 &setdebuglist, &showdebuglist); 1410 &setdebuglist, &showdebuglist);
1377 1411
1378 observer_attach_inferior_created (jit_inferior_created_observer);
1379 observer_attach_inferior_exit (jit_inferior_exit_hook); 1412 observer_attach_inferior_exit (jit_inferior_exit_hook);
1380 observer_attach_executable_changed (jit_executable_changed_observer);
1381 jit_objfile_data = 1413 jit_objfile_data =
1382 register_objfile_data_with_cleanup (NULL, free_objfile_data); 1414 register_objfile_data_with_cleanup (NULL, free_objfile_data);
1383 jit_inferior_data = 1415 jit_inferior_data =
1384 register_inferior_data_with_cleanup (jit_inferior_data_cleanup); 1416 register_inferior_data_with_cleanup (jit_inferior_data_cleanup);
1385 jit_gdbarch_data = gdbarch_data_register_pre_init (jit_gdbarch_data_init); 1417 jit_gdbarch_data = gdbarch_data_register_pre_init (jit_gdbarch_data_init);
1386 if (is_dl_available ()) 1418 if (is_dl_available ())
1387 { 1419 {
1388 add_com ("jit-reader-load", no_class, jit_reader_load_command, _("\ 1420 add_com ("jit-reader-load", no_class, jit_reader_load_command, _("\
1389 Load FILE as debug info reader and unwinder for JIT compiled code.\n\ 1421 Load FILE as debug info reader and unwinder for JIT compiled code.\n\
1390 Usage: jit-reader-load FILE\n\ 1422 Usage: jit-reader-load FILE\n\
1391 Try to load file FILE as a debug info reader (and unwinder) for\n\ 1423 Try to load file FILE as a debug info reader (and unwinder) for\n\
1392 JIT compiled code. The file is loaded from " JIT_READER_DIR ",\n\ 1424 JIT compiled code. The file is loaded from " JIT_READER_DIR ",\n\
1393 relocated relative to the GDB executable if required.")); 1425 relocated relative to the GDB executable if required."));
1394 add_com ("jit-reader-unload", no_class, jit_reader_unload_command, _("\ 1426 add_com ("jit-reader-unload", no_class, jit_reader_unload_command, _("\
1395 Unload the currently loaded JIT debug info reader.\n\ 1427 Unload the currently loaded JIT debug info reader.\n\
1396 Usage: jit-reader-unload FILE\n\n\ 1428 Usage: jit-reader-unload FILE\n\n\
1397 Do \"help jit-reader-load\" for info on loading debug info readers.")); 1429 Do \"help jit-reader-load\" for info on loading debug info readers."));
1398 } 1430 }
1399 } 1431 }
OLDNEW
« no previous file with comments | « gdb/iq2000-tdep.c ('k') | gdb/jit-reader.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698