1 /* Load module for 'compile' command.
3 Copyright (C) 2014-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "compile-object-load.h"
22 #include "compile-internal.h"
26 #include "readline/tilde.h"
33 #include "arch-utils.h"
35 /* Helper data for setup_sections. */
37 struct setup_sections_data
39 /* Size of all recent sections with matching LAST_PROT. */
42 /* First section matching LAST_PROT. */
43 asection
*last_section_first
;
45 /* Memory protection like the prot parameter of gdbarch_infcall_mmap. */
48 /* Maximum of alignments of all sections matching LAST_PROT.
49 This value is always at least 1. This value is always a power of 2. */
50 CORE_ADDR last_max_alignment
;
53 /* Place all ABFD sections next to each other obeying all constraints. */
56 setup_sections (bfd
*abfd
, asection
*sect
, void *data_voidp
)
58 struct setup_sections_data
*data
= data_voidp
;
64 /* It is required by later bfd_get_relocated_section_contents. */
65 if (sect
->output_section
== NULL
)
66 sect
->output_section
= sect
;
68 if ((bfd_get_section_flags (abfd
, sect
) & SEC_ALLOC
) == 0)
71 /* Make the memory always readable. */
72 prot
= GDB_MMAP_PROT_READ
;
73 if ((bfd_get_section_flags (abfd
, sect
) & SEC_READONLY
) == 0)
74 prot
|= GDB_MMAP_PROT_WRITE
;
75 if ((bfd_get_section_flags (abfd
, sect
) & SEC_CODE
) != 0)
76 prot
|= GDB_MMAP_PROT_EXEC
;
79 fprintf_unfiltered (gdb_stdout
,
80 "module \"%s\" section \"%s\" size %s prot %u\n",
81 bfd_get_filename (abfd
),
82 bfd_get_section_name (abfd
, sect
),
83 paddress (target_gdbarch (),
84 bfd_get_section_size (sect
)),
91 || (data
->last_prot
!= prot
&& bfd_get_section_size (sect
) != 0))
96 if (data
->last_size
!= 0)
98 addr
= gdbarch_infcall_mmap (target_gdbarch (), data
->last_size
,
101 fprintf_unfiltered (gdb_stdout
,
102 "allocated %s bytes at %s prot %u\n",
103 paddress (target_gdbarch (), data
->last_size
),
104 paddress (target_gdbarch (), addr
),
110 if ((addr
& (data
->last_max_alignment
- 1)) != 0)
111 error (_("Inferior compiled module address %s "
112 "is not aligned to BFD required %s."),
113 paddress (target_gdbarch (), addr
),
114 paddress (target_gdbarch (), data
->last_max_alignment
));
116 for (sect_iter
= data
->last_section_first
; sect_iter
!= sect
;
117 sect_iter
= sect_iter
->next
)
118 if ((bfd_get_section_flags (abfd
, sect_iter
) & SEC_ALLOC
) != 0)
119 bfd_set_section_vma (abfd
, sect_iter
,
120 addr
+ bfd_get_section_vma (abfd
, sect_iter
));
123 data
->last_section_first
= sect
;
124 data
->last_prot
= prot
;
125 data
->last_max_alignment
= 1;
131 alignment
= ((CORE_ADDR
) 1) << bfd_get_section_alignment (abfd
, sect
);
132 data
->last_max_alignment
= max (data
->last_max_alignment
, alignment
);
134 data
->last_size
= (data
->last_size
+ alignment
- 1) & -alignment
;
136 bfd_set_section_vma (abfd
, sect
, data
->last_size
);
138 data
->last_size
+= bfd_get_section_size (sect
);
139 data
->last_size
= (data
->last_size
+ alignment
- 1) & -alignment
;
142 /* Helper for link_callbacks callbacks vector. */
145 link_callbacks_multiple_definition (struct bfd_link_info
*link_info
,
146 struct bfd_link_hash_entry
*h
, bfd
*nbfd
,
147 asection
*nsec
, bfd_vma nval
)
149 bfd
*abfd
= link_info
->input_bfds
;
151 if (link_info
->allow_multiple_definition
)
153 warning (_("Compiled module \"%s\": multiple symbol definitions: %s"),
154 bfd_get_filename (abfd
), h
->root
.string
);
158 /* Helper for link_callbacks callbacks vector. */
161 link_callbacks_warning (struct bfd_link_info
*link_info
, const char *xwarning
,
162 const char *symbol
, bfd
*abfd
, asection
*section
,
165 warning (_("Compiled module \"%s\" section \"%s\": warning: %s"),
166 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
),
168 /* Maybe permit running as a module? */
172 /* Helper for link_callbacks callbacks vector. */
175 link_callbacks_undefined_symbol (struct bfd_link_info
*link_info
,
176 const char *name
, bfd
*abfd
, asection
*section
,
177 bfd_vma address
, bfd_boolean is_fatal
)
179 warning (_("Cannot resolve relocation to \"%s\" "
180 "from compiled module \"%s\" section \"%s\"."),
181 name
, bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
));
185 /* Helper for link_callbacks callbacks vector. */
188 link_callbacks_reloc_overflow (struct bfd_link_info
*link_info
,
189 struct bfd_link_hash_entry
*entry
,
190 const char *name
, const char *reloc_name
,
191 bfd_vma addend
, bfd
*abfd
, asection
*section
,
194 /* TRUE is required for intra-module relocations. */
198 /* Helper for link_callbacks callbacks vector. */
201 link_callbacks_reloc_dangerous (struct bfd_link_info
*link_info
,
202 const char *message
, bfd
*abfd
,
203 asection
*section
, bfd_vma address
)
205 warning (_("Compiled module \"%s\" section \"%s\": dangerous "
207 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
),
212 /* Helper for link_callbacks callbacks vector. */
215 link_callbacks_unattached_reloc (struct bfd_link_info
*link_info
,
216 const char *name
, bfd
*abfd
, asection
*section
,
219 warning (_("Compiled module \"%s\" section \"%s\": unattached "
221 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, section
),
226 /* Helper for link_callbacks callbacks vector. */
228 static void link_callbacks_einfo (const char *fmt
, ...)
229 ATTRIBUTE_PRINTF (1, 2);
232 link_callbacks_einfo (const char *fmt
, ...)
234 struct cleanup
*cleanups
;
239 str
= xstrvprintf (fmt
, ap
);
241 cleanups
= make_cleanup (xfree
, str
);
243 warning (_("Compile module: warning: %s"), str
);
245 do_cleanups (cleanups
);
248 /* Helper for bfd_get_relocated_section_contents.
249 Only these symbols are set by bfd_simple_get_relocated_section_contents
250 but bfd/ seems to use even the NULL ones without checking them first. */
252 static const struct bfd_link_callbacks link_callbacks
=
254 NULL
, /* add_archive_element */
255 link_callbacks_multiple_definition
, /* multiple_definition */
256 NULL
, /* multiple_common */
257 NULL
, /* add_to_set */
258 NULL
, /* constructor */
259 link_callbacks_warning
, /* warning */
260 link_callbacks_undefined_symbol
, /* undefined_symbol */
261 link_callbacks_reloc_overflow
, /* reloc_overflow */
262 link_callbacks_reloc_dangerous
, /* reloc_dangerous */
263 link_callbacks_unattached_reloc
, /* unattached_reloc */
265 link_callbacks_einfo
, /* einfo */
268 NULL
, /* override_segment_assignment */
271 struct link_hash_table_cleanup_data
277 /* Cleanup callback for struct bfd_link_info. */
280 link_hash_table_free (void *d
)
282 struct link_hash_table_cleanup_data
*data
= d
;
284 if (data
->abfd
->is_linker_output
)
285 (*data
->abfd
->link
.hash
->hash_table_free
) (data
->abfd
);
286 data
->abfd
->link
.next
= data
->link_next
;
289 /* Relocate and store into inferior memory each section SECT of ABFD. */
292 copy_sections (bfd
*abfd
, asection
*sect
, void *data
)
294 asymbol
**symbol_table
= data
;
295 bfd_byte
*sect_data
, *sect_data_got
;
296 struct cleanup
*cleanups
;
297 struct bfd_link_info link_info
;
298 struct bfd_link_order link_order
;
299 CORE_ADDR inferior_addr
;
300 struct link_hash_table_cleanup_data cleanup_data
;
302 if ((bfd_get_section_flags (abfd
, sect
) & (SEC_ALLOC
| SEC_LOAD
))
303 != (SEC_ALLOC
| SEC_LOAD
))
306 if (bfd_get_section_size (sect
) == 0)
309 /* Mostly a copy of bfd_simple_get_relocated_section_contents which GDB
310 cannot use as it does not report relocations to undefined symbols. */
311 memset (&link_info
, 0, sizeof (link_info
));
312 link_info
.output_bfd
= abfd
;
313 link_info
.input_bfds
= abfd
;
314 link_info
.input_bfds_tail
= &abfd
->link
.next
;
316 cleanup_data
.abfd
= abfd
;
317 cleanup_data
.link_next
= abfd
->link
.next
;
319 abfd
->link
.next
= NULL
;
320 link_info
.hash
= bfd_link_hash_table_create (abfd
);
322 cleanups
= make_cleanup (link_hash_table_free
, &cleanup_data
);
323 link_info
.callbacks
= &link_callbacks
;
325 memset (&link_order
, 0, sizeof (link_order
));
326 link_order
.next
= NULL
;
327 link_order
.type
= bfd_indirect_link_order
;
328 link_order
.offset
= 0;
329 link_order
.size
= bfd_get_section_size (sect
);
330 link_order
.u
.indirect
.section
= sect
;
332 sect_data
= xmalloc (bfd_get_section_size (sect
));
333 make_cleanup (xfree
, sect_data
);
335 sect_data_got
= bfd_get_relocated_section_contents (abfd
, &link_info
,
336 &link_order
, sect_data
,
337 FALSE
, symbol_table
);
339 if (sect_data_got
== NULL
)
340 error (_("Cannot map compiled module \"%s\" section \"%s\": %s"),
341 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sect
),
342 bfd_errmsg (bfd_get_error ()));
343 gdb_assert (sect_data_got
== sect_data
);
345 inferior_addr
= bfd_get_section_vma (abfd
, sect
);
346 if (0 != target_write_memory (inferior_addr
, sect_data
,
347 bfd_get_section_size (sect
)))
348 error (_("Cannot write compiled module \"%s\" section \"%s\" "
349 "to inferior memory range %s-%s."),
350 bfd_get_filename (abfd
), bfd_get_section_name (abfd
, sect
),
351 paddress (target_gdbarch (), inferior_addr
),
352 paddress (target_gdbarch (),
353 inferior_addr
+ bfd_get_section_size (sect
)));
355 do_cleanups (cleanups
);
358 /* Fetch the type of COMPILE_I_EXPR_PTR_TYPE and COMPILE_I_EXPR_VAL
359 symbols in OBJFILE so we can calculate how much memory to allocate
360 for the out parameter. This avoids needing a malloc in the generated
361 code. Throw an error if anything fails.
362 GDB first tries to compile the code with COMPILE_I_PRINT_ADDRESS_SCOPE.
363 If it finds user tries to print an array type this function returns
364 NULL. Caller will then regenerate the code with
365 COMPILE_I_PRINT_VALUE_SCOPE, recompiles it again and finally runs it.
366 This is because __auto_type array-to-pointer type conversion of
367 COMPILE_I_EXPR_VAL which gets detected by COMPILE_I_EXPR_PTR_TYPE
368 preserving the array type. */
371 get_out_value_type (struct symbol
*func_sym
, struct objfile
*objfile
,
372 enum compile_i_scope_types scope
)
374 struct symbol
*gdb_ptr_type_sym
, *gdb_val_sym
;
375 struct type
*gdb_ptr_type
, *gdb_type_from_ptr
, *gdb_type
;
376 const struct block
*block
;
377 const struct blockvector
*bv
;
381 bv
= SYMTAB_BLOCKVECTOR (func_sym
->owner
.symtab
);
382 nblocks
= BLOCKVECTOR_NBLOCKS (bv
);
384 gdb_ptr_type_sym
= NULL
;
385 for (block_loop
= 0; block_loop
< nblocks
; block_loop
++)
387 struct symbol
*function
;
388 const struct block
*function_block
;
390 block
= BLOCKVECTOR_BLOCK (bv
, block_loop
);
391 if (BLOCK_FUNCTION (block
) != NULL
)
393 gdb_val_sym
= block_lookup_symbol (block
, COMPILE_I_EXPR_VAL
, VAR_DOMAIN
);
394 if (gdb_val_sym
== NULL
)
397 function_block
= block
;
398 while (function_block
!= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)
399 && function_block
!= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
))
401 function_block
= BLOCK_SUPERBLOCK (function_block
);
402 function
= BLOCK_FUNCTION (function_block
);
403 if (function
!= NULL
)
407 && (BLOCK_SUPERBLOCK (function_block
)
408 == BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
409 && (strcmp (SYMBOL_LINKAGE_NAME (function
), GCC_FE_WRAPPER_FUNCTION
)
413 if (block_loop
== nblocks
)
414 error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE
);
416 gdb_type
= SYMBOL_TYPE (gdb_val_sym
);
417 CHECK_TYPEDEF (gdb_type
);
419 gdb_ptr_type_sym
= block_lookup_symbol (block
, COMPILE_I_EXPR_PTR_TYPE
,
421 if (gdb_ptr_type_sym
== NULL
)
422 error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE
);
423 gdb_ptr_type
= SYMBOL_TYPE (gdb_ptr_type_sym
);
424 CHECK_TYPEDEF (gdb_ptr_type
);
425 if (TYPE_CODE (gdb_ptr_type
) != TYPE_CODE_PTR
)
426 error (_("Type of \"%s\" is not a pointer"), COMPILE_I_EXPR_PTR_TYPE
);
427 gdb_type_from_ptr
= TYPE_TARGET_TYPE (gdb_ptr_type
);
429 if (types_deeply_equal (gdb_type
, gdb_type_from_ptr
))
431 if (scope
!= COMPILE_I_PRINT_ADDRESS_SCOPE
)
432 error (_("Expected address scope in compiled module \"%s\"."),
433 objfile_name (objfile
));
437 if (TYPE_CODE (gdb_type
) != TYPE_CODE_PTR
)
438 error (_("Invalid type code %d of symbol \"%s\" "
439 "in compiled module \"%s\"."),
440 TYPE_CODE (gdb_type_from_ptr
), COMPILE_I_EXPR_VAL
,
441 objfile_name (objfile
));
443 switch (TYPE_CODE (gdb_type_from_ptr
))
445 case TYPE_CODE_ARRAY
:
446 gdb_type_from_ptr
= TYPE_TARGET_TYPE (gdb_type_from_ptr
);
451 error (_("Invalid type code %d of symbol \"%s\" "
452 "in compiled module \"%s\"."),
453 TYPE_CODE (gdb_type_from_ptr
), COMPILE_I_EXPR_PTR_TYPE
,
454 objfile_name (objfile
));
456 if (!types_deeply_equal (gdb_type_from_ptr
,
457 TYPE_TARGET_TYPE (gdb_type
)))
458 error (_("Referenced types do not match for symbols \"%s\" and \"%s\" "
459 "in compiled module \"%s\"."),
460 COMPILE_I_EXPR_PTR_TYPE
, COMPILE_I_EXPR_VAL
,
461 objfile_name (objfile
));
462 if (scope
== COMPILE_I_PRINT_ADDRESS_SCOPE
)
464 return gdb_type_from_ptr
;
467 /* Fetch the type of first parameter of FUNC_SYM.
468 Return NULL if FUNC_SYM has no parameters. Throw an error otherwise. */
471 get_regs_type (struct symbol
*func_sym
, struct objfile
*objfile
)
473 struct type
*func_type
= SYMBOL_TYPE (func_sym
);
474 struct type
*regsp_type
, *regs_type
;
476 /* No register parameter present. */
477 if (TYPE_NFIELDS (func_type
) == 0)
480 regsp_type
= check_typedef (TYPE_FIELD_TYPE (func_type
, 0));
481 if (TYPE_CODE (regsp_type
) != TYPE_CODE_PTR
)
482 error (_("Invalid type code %d of first parameter of function \"%s\" "
483 "in compiled module \"%s\"."),
484 TYPE_CODE (regsp_type
), GCC_FE_WRAPPER_FUNCTION
,
485 objfile_name (objfile
));
487 regs_type
= check_typedef (TYPE_TARGET_TYPE (regsp_type
));
488 if (TYPE_CODE (regs_type
) != TYPE_CODE_STRUCT
)
489 error (_("Invalid type code %d of dereferenced first parameter "
490 "of function \"%s\" in compiled module \"%s\"."),
491 TYPE_CODE (regs_type
), GCC_FE_WRAPPER_FUNCTION
,
492 objfile_name (objfile
));
497 /* Store all inferior registers required by REGS_TYPE to inferior memory
498 starting at inferior address REGS_BASE. */
501 store_regs (struct type
*regs_type
, CORE_ADDR regs_base
)
503 struct gdbarch
*gdbarch
= target_gdbarch ();
504 struct regcache
*regcache
= get_thread_regcache (inferior_ptid
);
507 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (regs_type
); fieldno
++)
509 const char *reg_name
= TYPE_FIELD_NAME (regs_type
, fieldno
);
510 ULONGEST reg_bitpos
= TYPE_FIELD_BITPOS (regs_type
, fieldno
);
511 ULONGEST reg_bitsize
= TYPE_FIELD_BITSIZE (regs_type
, fieldno
);
513 struct type
*reg_type
= check_typedef (TYPE_FIELD_TYPE (regs_type
,
515 ULONGEST reg_size
= TYPE_LENGTH (reg_type
);
517 struct value
*regval
;
518 CORE_ADDR inferior_addr
;
520 if (strcmp (reg_name
, COMPILE_I_SIMPLE_REGISTER_DUMMY
) == 0)
523 if ((reg_bitpos
% 8) != 0 || reg_bitsize
!= 0)
524 error (_("Invalid register \"%s\" position %s bits or size %s bits"),
525 reg_name
, pulongest (reg_bitpos
), pulongest (reg_bitsize
));
526 reg_offset
= reg_bitpos
/ 8;
528 if (TYPE_CODE (reg_type
) != TYPE_CODE_INT
529 && TYPE_CODE (reg_type
) != TYPE_CODE_PTR
)
530 error (_("Invalid register \"%s\" type code %d"), reg_name
,
531 TYPE_CODE (reg_type
));
533 regnum
= compile_register_name_demangle (gdbarch
, reg_name
);
535 regval
= value_from_register (reg_type
, regnum
, get_current_frame ());
536 if (value_optimized_out (regval
))
537 error (_("Register \"%s\" is optimized out."), reg_name
);
538 if (!value_entirely_available (regval
))
539 error (_("Register \"%s\" is not available."), reg_name
);
541 inferior_addr
= regs_base
+ reg_offset
;
542 if (0 != target_write_memory (inferior_addr
, value_contents (regval
),
544 error (_("Cannot write register \"%s\" to inferior memory at %s."),
545 reg_name
, paddress (gdbarch
, inferior_addr
));
549 /* Load OBJECT_FILE into inferior memory. Throw an error otherwise.
550 Caller must fully dispose the return value by calling compile_object_run.
551 SOURCE_FILE's copy is stored into the returned object.
552 Caller should free both OBJECT_FILE and SOURCE_FILE immediatelly after this
554 Function returns NULL only for COMPILE_I_PRINT_ADDRESS_SCOPE when
555 COMPILE_I_PRINT_VALUE_SCOPE should have been used instead. */
557 struct compile_module
*
558 compile_object_load (const char *object_file
, const char *source_file
,
559 enum compile_i_scope_types scope
, void *scope_data
)
561 struct cleanup
*cleanups
, *cleanups_free_objfile
;
563 struct setup_sections_data setup_sections_data
;
564 CORE_ADDR addr
, regs_addr
, out_value_addr
= 0;
565 struct symbol
*func_sym
;
566 struct type
*func_type
;
567 struct bound_minimal_symbol bmsym
;
569 asymbol
**symbol_table
, **symp
;
570 long number_of_symbols
, missing_symbols
;
571 struct type
*dptr_type
= builtin_type (target_gdbarch ())->builtin_data_ptr
;
572 unsigned dptr_type_len
= TYPE_LENGTH (dptr_type
);
573 struct compile_module
*retval
;
574 struct type
*regs_type
, *out_value_type
= NULL
;
575 char *filename
, **matching
;
576 struct objfile
*objfile
;
577 int expect_parameters
;
578 struct type
*expect_return_type
;
580 filename
= tilde_expand (object_file
);
581 cleanups
= make_cleanup (xfree
, filename
);
583 abfd
= gdb_bfd_open (filename
, gnutarget
, -1);
585 error (_("\"%s\": could not open as compiled module: %s"),
586 filename
, bfd_errmsg (bfd_get_error ()));
587 make_cleanup_bfd_unref (abfd
);
589 if (!bfd_check_format_matches (abfd
, bfd_object
, &matching
))
590 error (_("\"%s\": not in loadable format: %s"),
591 filename
, gdb_bfd_errmsg (bfd_get_error (), matching
));
593 if ((bfd_get_file_flags (abfd
) & (EXEC_P
| DYNAMIC
)) != 0)
594 error (_("\"%s\": not in object format."), filename
);
596 setup_sections_data
.last_size
= 0;
597 setup_sections_data
.last_section_first
= abfd
->sections
;
598 setup_sections_data
.last_prot
= -1;
599 setup_sections_data
.last_max_alignment
= 1;
600 bfd_map_over_sections (abfd
, setup_sections
, &setup_sections_data
);
601 setup_sections (abfd
, NULL
, &setup_sections_data
);
603 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
604 if (storage_needed
< 0)
605 error (_("Cannot read symbols of compiled module \"%s\": %s"),
606 filename
, bfd_errmsg (bfd_get_error ()));
608 /* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in
609 "Reading symbols from ..." message for automatically generated file. */
610 objfile
= symbol_file_add_from_bfd (abfd
, filename
, 0, NULL
, 0, NULL
);
611 cleanups_free_objfile
= make_cleanup_free_objfile (objfile
);
613 func_sym
= lookup_global_symbol_from_objfile (objfile
,
614 GCC_FE_WRAPPER_FUNCTION
,
616 if (func_sym
== NULL
)
617 error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
618 GCC_FE_WRAPPER_FUNCTION
, objfile_name (objfile
));
619 func_type
= SYMBOL_TYPE (func_sym
);
620 if (TYPE_CODE (func_type
) != TYPE_CODE_FUNC
)
621 error (_("Invalid type code %d of function \"%s\" in compiled "
623 TYPE_CODE (func_type
), GCC_FE_WRAPPER_FUNCTION
,
624 objfile_name (objfile
));
628 case COMPILE_I_SIMPLE_SCOPE
:
629 expect_parameters
= 1;
630 expect_return_type
= builtin_type (target_gdbarch ())->builtin_void
;
632 case COMPILE_I_RAW_SCOPE
:
633 expect_parameters
= 0;
634 expect_return_type
= builtin_type (target_gdbarch ())->builtin_void
;
636 case COMPILE_I_PRINT_ADDRESS_SCOPE
:
637 case COMPILE_I_PRINT_VALUE_SCOPE
:
638 expect_parameters
= 2;
639 expect_return_type
= builtin_type (target_gdbarch ())->builtin_void
;
642 internal_error (__FILE__
, __LINE__
, _("invalid scope %d"), scope
);
644 if (TYPE_NFIELDS (func_type
) != expect_parameters
)
645 error (_("Invalid %d parameters of function \"%s\" in compiled "
647 TYPE_NFIELDS (func_type
), GCC_FE_WRAPPER_FUNCTION
,
648 objfile_name (objfile
));
649 if (!types_deeply_equal (expect_return_type
, TYPE_TARGET_TYPE (func_type
)))
650 error (_("Invalid return type of function \"%s\" in compiled "
652 GCC_FE_WRAPPER_FUNCTION
, objfile_name (objfile
));
654 /* The memory may be later needed
655 by bfd_generic_get_relocated_section_contents
656 called from default_symfile_relocate. */
657 symbol_table
= obstack_alloc (&objfile
->objfile_obstack
, storage_needed
);
658 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
659 if (number_of_symbols
< 0)
660 error (_("Cannot parse symbols of compiled module \"%s\": %s"),
661 filename
, bfd_errmsg (bfd_get_error ()));
664 for (symp
= symbol_table
; symp
< symbol_table
+ number_of_symbols
; symp
++)
666 asymbol
*sym
= *symp
;
671 fprintf_unfiltered (gdb_stdout
,
672 "lookup undefined ELF symbol \"%s\"\n",
674 sym
->flags
= BSF_GLOBAL
;
675 sym
->section
= bfd_abs_section_ptr
;
676 if (strcmp (sym
->name
, "_GLOBAL_OFFSET_TABLE_") == 0)
681 bmsym
= lookup_minimal_symbol (sym
->name
, NULL
, NULL
);
682 switch (bmsym
.minsym
== NULL
683 ? mst_unknown
: MSYMBOL_TYPE (bmsym
.minsym
))
686 sym
->value
= BMSYMBOL_VALUE_ADDRESS (bmsym
);
688 case mst_text_gnu_ifunc
:
689 sym
->value
= gnu_ifunc_resolve_addr (target_gdbarch (),
690 BMSYMBOL_VALUE_ADDRESS (bmsym
));
693 warning (_("Could not find symbol \"%s\" "
694 "for compiled module \"%s\"."),
695 sym
->name
, filename
);
700 error (_("%ld symbols were missing, cannot continue."), missing_symbols
);
702 bfd_map_over_sections (abfd
, copy_sections
, symbol_table
);
704 regs_type
= get_regs_type (func_sym
, objfile
);
705 if (regs_type
== NULL
)
709 /* Use read-only non-executable memory protection. */
710 regs_addr
= gdbarch_infcall_mmap (target_gdbarch (),
711 TYPE_LENGTH (regs_type
),
713 gdb_assert (regs_addr
!= 0);
715 fprintf_unfiltered (gdb_stdout
,
716 "allocated %s bytes at %s for registers\n",
717 paddress (target_gdbarch (),
718 TYPE_LENGTH (regs_type
)),
719 paddress (target_gdbarch (), regs_addr
));
720 store_regs (regs_type
, regs_addr
);
723 if (scope
== COMPILE_I_PRINT_ADDRESS_SCOPE
724 || scope
== COMPILE_I_PRINT_VALUE_SCOPE
)
726 out_value_type
= get_out_value_type (func_sym
, objfile
, scope
);
727 if (out_value_type
== NULL
)
729 do_cleanups (cleanups
);
732 check_typedef (out_value_type
);
733 out_value_addr
= gdbarch_infcall_mmap (target_gdbarch (),
734 TYPE_LENGTH (out_value_type
),
736 | GDB_MMAP_PROT_WRITE
));
737 gdb_assert (out_value_addr
!= 0);
739 fprintf_unfiltered (gdb_stdout
,
740 "allocated %s bytes at %s for printed value\n",
741 paddress (target_gdbarch (),
742 TYPE_LENGTH (out_value_type
)),
743 paddress (target_gdbarch (), out_value_addr
));
746 discard_cleanups (cleanups_free_objfile
);
747 do_cleanups (cleanups
);
749 retval
= xmalloc (sizeof (*retval
));
750 retval
->objfile
= objfile
;
751 retval
->source_file
= xstrdup (source_file
);
752 retval
->func_sym
= func_sym
;
753 retval
->regs_addr
= regs_addr
;
754 retval
->scope
= scope
;
755 retval
->scope_data
= scope_data
;
756 retval
->out_value_type
= out_value_type
;
757 retval
->out_value_addr
= out_value_addr
;