26#include "readline/tilde.h"
44 items.push_back (item);
51 for (
auto &item :
items)
57 catch (
const gdb_exception_error &ex)
115 if (sect->output_section == NULL)
116 sect->output_section = sect;
118 if ((bfd_section_flags (sect) & SEC_ALLOC) == 0)
123 if ((bfd_section_flags (sect) & SEC_READONLY) == 0)
125 if ((bfd_section_flags (sect) & SEC_CODE) != 0)
130 "module \"%s\" section \"%s\" size %s prot %u\n",
131 bfd_get_filename (
m_bfd),
132 bfd_section_name (sect),
134 bfd_section_size (sect)),
141 || (
m_last_prot != prot && bfd_section_size (sect) != 0))
153 "allocated %s bytes at %s prot %u\n",
162 error (_(
"Inferior compiled module address %s "
163 "is not aligned to BFD required %s."),
168 sect_iter = sect_iter->next)
169 if ((bfd_section_flags (sect_iter) & SEC_ALLOC) != 0)
170 bfd_set_section_vma (sect_iter, addr + bfd_section_vma (sect_iter));
181 alignment = ((CORE_ADDR) 1) << bfd_section_alignment (sect);
196 struct bfd_link_hash_entry *h, bfd *nbfd,
197 asection *nsec, bfd_vma nval)
199 bfd *abfd = link_info->input_bfds;
201 if (link_info->allow_multiple_definition)
203 warning (_(
"Compiled module \"%s\": multiple symbol definitions: %s"),
204 bfd_get_filename (abfd), h->root.string);
211 const char *
symbol, bfd *abfd, asection *section,
214 warning (_(
"Compiled module \"%s\" section \"%s\": warning: %s"),
215 bfd_get_filename (abfd), bfd_section_name (section),
223 const char *
name, bfd *abfd, asection *section,
224 bfd_vma address, bfd_boolean is_fatal)
226 warning (_(
"Cannot resolve relocation to \"%s\" "
227 "from compiled module \"%s\" section \"%s\"."),
228 name, bfd_get_filename (abfd), bfd_section_name (section));
235 struct bfd_link_hash_entry *entry,
236 const char *
name,
const char *reloc_name,
237 bfd_vma addend, bfd *abfd, asection *section,
246 const char *message, bfd *abfd,
247 asection *section, bfd_vma address)
249 warning (_(
"Compiled module \"%s\" section \"%s\": dangerous "
251 bfd_get_filename (abfd), bfd_section_name (section),
259 const char *
name, bfd *abfd, asection *section,
262 warning (_(
"Compiled module \"%s\" section \"%s\": unattached "
264 bfd_get_filename (abfd), bfd_section_name (section),
279 std::string str = string_vprintf (fmt, ap);
282 warning (_(
"Compile module: warning: %s"), str.c_str ());
318 if (
abfd->is_linker_output)
319 (*
abfd->link.hash->hash_table_free) (
abfd);
336 asymbol **symbol_table = (asymbol **) data;
337 bfd_byte *sect_data_got;
338 struct bfd_link_info link_info;
339 struct bfd_link_order link_order;
340 CORE_ADDR inferior_addr;
342 if ((bfd_section_flags (sect) & (SEC_ALLOC | SEC_LOAD))
343 != (SEC_ALLOC | SEC_LOAD))
346 if (bfd_section_size (sect) == 0)
351 memset (&link_info, 0,
sizeof (link_info));
352 link_info.output_bfd = abfd;
353 link_info.input_bfds = abfd;
354 link_info.input_bfds_tail = &abfd->link.next;
358 abfd->link.next = NULL;
359 link_info.hash = bfd_link_hash_table_create (
abfd);
363 memset (&link_order, 0,
sizeof (link_order));
364 link_order.next = NULL;
365 link_order.type = bfd_indirect_link_order;
366 link_order.offset = 0;
367 link_order.size = bfd_section_size (sect);
368 link_order.u.indirect.section = sect;
370 gdb::unique_xmalloc_ptr<gdb_byte> sect_data
371 ((bfd_byte *)
xmalloc (bfd_section_size (sect)));
373 sect_data_got = bfd_get_relocated_section_contents (
abfd, &link_info,
376 FALSE, symbol_table);
378 if (sect_data_got == NULL)
379 error (_(
"Cannot map compiled module \"%s\" section \"%s\": %s"),
380 bfd_get_filename (
abfd), bfd_section_name (sect),
381 bfd_errmsg (bfd_get_error ()));
382 gdb_assert (sect_data_got == sect_data.get ());
384 inferior_addr = bfd_section_vma (sect);
386 bfd_section_size (sect)))
387 error (_(
"Cannot write compiled module \"%s\" section \"%s\" "
388 "to inferior memory range %s-%s."),
389 bfd_get_filename (
abfd), bfd_section_name (sect),
392 inferior_addr + bfd_section_size (sect)));
411 struct symbol *gdb_ptr_type_sym;
413 struct symbol *gdb_val_sym = NULL;
414 struct type *gdb_ptr_type, *gdb_type_from_ptr, *gdb_type, *retval;
427 gdb_ptr_type_sym = NULL;
428 for (block_loop = 0; block_loop < nblocks; block_loop++)
430 struct symbol *function = NULL;
440 if (gdb_val_sym == NULL)
457 if (block_loop == nblocks)
460 gdb_type = gdb_val_sym->
type ();
466 if (gdb_ptr_type_sym == NULL)
468 gdb_ptr_type = gdb_ptr_type_sym->
type ();
470 if (gdb_ptr_type->
code () != TYPE_CODE_PTR)
477 error (_(
"Expected address scope in compiled module \"%s\"."),
482 if (gdb_type->
code () != TYPE_CODE_PTR)
483 error (_(
"Invalid type code %d of symbol \"%s\" "
484 "in compiled module \"%s\"."),
488 retval = gdb_type_from_ptr;
489 switch (gdb_type_from_ptr->
code ())
491 case TYPE_CODE_ARRAY:
492 gdb_type_from_ptr = gdb_type_from_ptr->
target_type ();
497 error (_(
"Invalid type code %d of symbol \"%s\" "
498 "in compiled module \"%s\"."),
504 error (_(
"Referenced types do not match for symbols \"%s\" and \"%s\" "
505 "in compiled module \"%s\"."),
520 struct type *regsp_type, *regs_type;
527 if (regsp_type->
code () != TYPE_CODE_PTR)
528 error (_(
"Invalid type code %d of first parameter of function \"%s\" "
529 "in compiled module \"%s\"."),
530 regsp_type->
code (), GCC_FE_WRAPPER_FUNCTION,
534 if (regs_type->
code () != TYPE_CODE_STRUCT)
535 error (_(
"Invalid type code %d of dereferenced first parameter "
536 "of function \"%s\" in compiled module \"%s\"."),
537 regs_type->
code (), GCC_FE_WRAPPER_FUNCTION,
552 for (fieldno = 0; fieldno < regs_type->
num_fields (); fieldno++)
554 const char *reg_name = regs_type->
field (fieldno).
name ();
556 ULONGEST reg_bitsize = regs_type->
field (fieldno).
bitsize ();
558 struct type *reg_type
560 ULONGEST reg_size = reg_type->
length ();
562 struct value *regval;
563 CORE_ADDR inferior_addr;
568 if ((reg_bitpos % 8) != 0 || reg_bitsize != 0)
569 error (_(
"Invalid register \"%s\" position %s bits or size %s bits"),
570 reg_name, pulongest (reg_bitpos), pulongest (reg_bitsize));
573 if (reg_type->
code () != TYPE_CODE_INT
574 && reg_type->
code () != TYPE_CODE_PTR)
575 error (_(
"Invalid register \"%s\" type code %d"), reg_name,
582 error (_(
"Register \"%s\" is optimized out."), reg_name);
584 error (_(
"Register \"%s\" is not available."), reg_name);
590 error (_(
"Cannot write register \"%s\" to inferior memory at %s."),
605 CORE_ADDR regs_addr, out_value_addr = 0;
610 asymbol **symbol_table, **symp;
611 long number_of_symbols, missing_symbols;
612 struct type *regs_type, *out_value_type = NULL;
615 int expect_parameters;
616 struct type *expect_return_type;
618 gdb::unique_xmalloc_ptr<char> filename
623 error (_(
"\"%s\": could not open as compiled module: %s"),
624 filename.get (), bfd_errmsg (bfd_get_error ()));
626 if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching))
627 error (_(
"\"%s\": not in loadable format: %s"),
631 if ((bfd_get_file_flags (abfd.get ()) & (EXEC_P | DYNAMIC)) != 0)
632 error (_(
"\"%s\": not in object format."), filename.get ());
635 for (asection *sect = abfd->sections; sect !=
nullptr; sect = sect->next)
639 storage_needed = bfd_get_symtab_upper_bound (abfd.get ());
640 if (storage_needed < 0)
641 error (_(
"Cannot read symbols of compiled module \"%s\": %s"),
642 filename.get (), bfd_errmsg (bfd_get_error ()));
649 objfile = objfile_holder.get ();
653 GCC_FE_WRAPPER_FUNCTION,
655 if (func_sym == NULL)
656 error (_(
"Cannot find function \"%s\" in compiled module \"%s\"."),
659 if (
func_type->code () != TYPE_CODE_FUNC)
660 error (_(
"Invalid type code %d of function \"%s\" in compiled "
662 func_type->code (), GCC_FE_WRAPPER_FUNCTION,
668 expect_parameters = 1;
672 expect_parameters = 0;
677 expect_parameters = 2;
681 internal_error (_(
"invalid scope %d"), scope);
683 if (
func_type->num_fields () != expect_parameters)
684 error (_(
"Invalid %d parameters of function \"%s\" in compiled "
686 func_type->num_fields (), GCC_FE_WRAPPER_FUNCTION,
689 error (_(
"Invalid return type of function \"%s\" in compiled "
698 number_of_symbols = bfd_canonicalize_symtab (abfd.get (), symbol_table);
699 if (number_of_symbols < 0)
700 error (_(
"Cannot parse symbols of compiled module \"%s\": %s"),
701 filename.get (), bfd_errmsg (bfd_get_error ()));
704 for (symp = symbol_table; symp < symbol_table + number_of_symbols; symp++)
706 asymbol *sym = *symp;
710 sym->flags = BSF_GLOBAL;
711 sym->section = bfd_abs_section_ptr;
712 if (strcmp (sym->name,
"_GLOBAL_OFFSET_TABLE_") == 0)
716 "ELF symbol \"%s\" relocated to zero\n",
725 if (strcmp (sym->name,
".TOC.") == 0)
735 asection *toc_fallback = bfd_get_section_by_name(abfd.get(),
".toc");
736 if (toc_fallback == NULL)
738 for (asection *tsect = abfd->sections; tsect !=
nullptr;
741 if (bfd_section_flags (tsect) & SEC_ALLOC)
743 toc_fallback = tsect;
749 if (toc_fallback == NULL)
753 toc_fallback = bfd_abs_section_ptr;
755 sym->section = toc_fallback;
757 bfd_set_gp_value(abfd.get(), toc_fallback->vma);
760 "Connecting ELF symbol \"%s\" to the .toc section (%s)\n",
767 switch (bmsym.
minsym == NULL
776 "ELF mst_text symbol \"%s\" relocated to %s\n",
785 "ELF mst_text_gnu_ifunc symbol \"%s\" "
791 warning (_(
"Could not find symbol \"%s\" "
792 "for compiled module \"%s\"."),
793 sym->name, filename.get ());
798 error (_(
"%ld symbols were missing, cannot continue."), missing_symbols);
800 bfd_map_over_sections (abfd.get (),
copy_sections, symbol_table);
803 if (regs_type == NULL)
811 gdb_assert (regs_addr != 0);
815 "allocated %s bytes at %s for registers\n",
826 if (out_value_type == NULL)
830 out_value_type->
length (),
833 gdb_assert (out_value_addr != 0);
835 out_value_type->
length ());
838 "allocated %s bytes at %s for printed value\n",
840 out_value_type->
length ()),
845 retval->objfile = objfile_holder.release ();
847 retval->func_sym = func_sym;
848 retval->regs_addr = regs_addr;
849 retval->scope = scope;
850 retval->scope_data = scope_data;
851 retval->out_value_type = out_value_type;
852 retval->out_value_addr = out_value_addr;
constexpr string_view get()
struct gdbarch * target_gdbarch(void)
#define GDB_MMAP_PROT_WRITE
#define GDB_MMAP_PROT_EXEC
#define GDB_MMAP_PROT_READ
struct symbol * block_lookup_symbol(const struct block *block, const char *name, symbol_name_match_type match_type, const domain_enum domain)
const char * source_file() const
const char * object_file() const
#define COMPILE_I_SIMPLE_REGISTER_DUMMY
int compile_register_name_demangle(struct gdbarch *gdbarch, const char *reg_name)
#define COMPILE_I_EXPR_VAL
#define COMPILE_I_EXPR_PTR_TYPE
static void copy_sections(bfd *abfd, asection *sect, void *data)
static void store_regs(struct type *regs_type, CORE_ADDR regs_base)
static void link_callbacks_multiple_definition(struct bfd_link_info *link_info, struct bfd_link_hash_entry *h, bfd *nbfd, asection *nsec, bfd_vma nval)
static void link_callbacks_einfo(const char *fmt,...) ATTRIBUTE_PRINTF(1
static const struct bfd_link_callbacks link_callbacks
static void link_callbacks_reloc_dangerous(struct bfd_link_info *link_info, const char *message, bfd *abfd, asection *section, bfd_vma address)
compile_module_up compile_object_load(const compile_file_names &file_names, enum compile_i_scope_types scope, void *scope_data)
static void link_callbacks_warning(struct bfd_link_info *link_info, const char *xwarning, const char *symbol, bfd *abfd, asection *section, bfd_vma address)
static struct type * get_out_value_type(struct symbol *func_sym, struct objfile *objfile, enum compile_i_scope_types scope)
static void link_callbacks_unattached_reloc(struct bfd_link_info *link_info, const char *name, bfd *abfd, asection *section, bfd_vma address)
static struct type * get_regs_type(struct symbol *func_sym, struct objfile *objfile)
static void link_callbacks_reloc_overflow(struct bfd_link_info *link_info, struct bfd_link_hash_entry *entry, const char *name, const char *reloc_name, bfd_vma addend, bfd *abfd, asection *section, bfd_vma address)
static void link_callbacks_undefined_symbol(struct bfd_link_info *link_info, const char *name, bfd *abfd, asection *section, bfd_vma address, bfd_boolean is_fatal)
std::unique_ptr< compile_module > compile_module_up
@ COMPILE_I_PRINT_ADDRESS_SCOPE
@ COMPILE_I_PRINT_VALUE_SCOPE
struct value * value_from_register(struct type *type, int regnum, frame_info_ptr frame)
frame_info_ptr get_current_frame(void)
static void ATTRIBUTE_PRINTF(1, 0)
std::string gdb_bfd_errmsg(bfd_error_type error_tag, char **matching)
gdb_bfd_ref_ptr gdb_bfd_open(const char *name, const char *target, int fd, bool warn_if_slow)
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
CORE_ADDR gdbarch_infcall_mmap(struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot)
void gdbarch_infcall_munmap(struct gdbarch *gdbarch, CORE_ADDR addr, CORE_ADDR size)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
bool types_deeply_equal(struct type *type1, struct type *type2)
struct type * check_typedef(struct type *type)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
const char * objfile_name(const struct objfile *objfile)
std::unique_ptr< objfile, objfile_deleter > objfile_up
const block * superblock() const
const struct block * function_block() const
symbol * function() const
const char * scope() const
struct block * block(size_t i)
struct block * static_block()
struct block * global_block()
CORE_ADDR value_address() const
struct minimal_symbol * minsym
struct type * builtin_void
struct blockvector * blockvector()
LONGEST loc_bitpos() const
const char * name() const
unsigned int bitsize() const
struct type * type() const
DISABLE_COPY_AND_ASSIGN(link_hash_table_cleanup_data)
link_hash_table_cleanup_data(bfd *abfd_)
~link_hash_table_cleanup_data()
minimal_symbol_type type() const
void add(CORE_ADDR addr, CORE_ADDR size)
std::vector< munmap_item > items
objfile(gdb_bfd_ref_ptr, const char *, objfile_flags)
auto_obstack objfile_obstack
asection * m_last_section_first
struct munmap_list munmap_list
CORE_ADDR m_last_max_alignment
setup_sections_data(bfd *abfd)
void setup_one_section(asection *sect)
struct type * type() const
struct compunit_symtab * compunit() const
struct type * target_type() const
struct field & field(int idx) const
unsigned int num_fields() const
gdb::array_view< const gdb_byte > contents()
bool entirely_available()
struct objfile * symbol_file_add_from_bfd(const gdb_bfd_ref_ptr &abfd, const char *name, symfile_add_flags add_flags, section_addr_info *addrs, objfile_flags flags, struct objfile *parent)
bool symbol_matches_search_name(const struct general_symbol_info *gsymbol, const lookup_name_info &name)
struct block_symbol lookup_global_symbol_from_objfile(struct objfile *main_objfile, enum block_enum block_index, const char *name, const domain_enum domain)
#define gnu_ifunc_resolve_addr
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
void gdb_printf(struct ui_file *stream, const char *format,...)