static struct type * get_regs_type (struct symbol *func_sym, struct objfile *objfile) { struct type *func_type = SYMBOL_TYPE (func_sym); struct type *regsp_type, *regs_type; /* No register parameter present. */ if (TYPE_NFIELDS (func_type) == 0) return NULL; regsp_type = check_typedef (TYPE_FIELD_TYPE (func_type, 0)); if (TYPE_CODE (regsp_type) != TYPE_CODE_PTR) error (_("Invalid type code %d of first parameter of function \"%s\" " "in compiled module \"%s\"."), TYPE_CODE (regsp_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); regs_type = check_typedef (TYPE_TARGET_TYPE (regsp_type)); if (TYPE_CODE (regs_type) != TYPE_CODE_STRUCT) error (_("Invalid type code %d of dereferenced first parameter " "of function \"%s\" in compiled module \"%s\"."), TYPE_CODE (regs_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); return regs_type; }
char * find_separate_debug_file_by_buildid (struct objfile *objfile) { const struct bfd_build_id *build_id; build_id = build_id_bfd_get (objfile->obfd); if (build_id != NULL) { if (separate_debug_file_debug) printf_unfiltered (_("\nLooking for separate debug info (build-id) for " "%s\n"), objfile_name (objfile)); gdb_bfd_ref_ptr abfd (build_id_to_debug_bfd (build_id->size, build_id->data)); /* Prevent looping on a stripped .debug file. */ if (abfd != NULL && filename_cmp (bfd_get_filename (abfd.get ()), objfile_name (objfile)) == 0) warning (_("\"%s\": separate debug info file has no debug info"), bfd_get_filename (abfd.get ())); else if (abfd != NULL) return xstrdup (bfd_get_filename (abfd.get ())); } return NULL; }
/* An Objfile method which returns the objfile's file name, or None. */ static PyObject * objfpy_get_filename (PyObject *self, void *closure) { objfile_object *obj = (objfile_object *) self; if (obj->objfile) return PyString_Decode (objfile_name (obj->objfile), strlen (objfile_name (obj->objfile)), host_charset (), NULL); Py_RETURN_NONE; }
static gdb_bfd_ref_ptr macho_check_dsym (struct objfile *objfile, std::string *filenamep) { size_t name_len = strlen (objfile_name (objfile)); size_t dsym_len = strlen (DSYM_SUFFIX); const char *base_name = lbasename (objfile_name (objfile)); size_t base_len = strlen (base_name); char *dsym_filename = (char *) alloca (name_len + dsym_len + base_len + 1); bfd_mach_o_load_command *main_uuid; bfd_mach_o_load_command *dsym_uuid; strcpy (dsym_filename, objfile_name (objfile)); strcpy (dsym_filename + name_len, DSYM_SUFFIX); strcpy (dsym_filename + name_len + dsym_len, base_name); if (access (dsym_filename, R_OK) != 0) return NULL; if (bfd_mach_o_lookup_command (objfile->obfd, BFD_MACH_O_LC_UUID, &main_uuid) == 0) { warning (_("can't find UUID in %s"), objfile_name (objfile)); return NULL; } gdb_bfd_ref_ptr dsym_bfd (gdb_bfd_openr (dsym_filename, gnutarget)); if (dsym_bfd == NULL) { warning (_("can't open dsym file %s"), dsym_filename); return NULL; } if (!bfd_check_format (dsym_bfd.get (), bfd_object)) { warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ())); return NULL; } if (bfd_mach_o_lookup_command (dsym_bfd.get (), BFD_MACH_O_LC_UUID, &dsym_uuid) == 0) { warning (_("can't find UUID in %s"), dsym_filename); return NULL; } if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid, sizeof (main_uuid->command.uuid.uuid))) { warning (_("dsym file UUID doesn't match the one in %s"), objfile_name (objfile)); return NULL; } *filenamep = std::string (dsym_filename); return dsym_bfd; }
bfd * find_separate_debug_file_in_section (struct objfile *objfile) { asection *section; bfd *abfd; if (objfile->obfd == NULL) return NULL; section = bfd_get_section_by_name (objfile->obfd, ".gnu_debugdata"); if (section == NULL) return NULL; #ifdef HAVE_LIBLZMA abfd = gdb_bfd_openr_iovec (objfile_name (objfile), gnutarget, lzma_open, section, lzma_pread, lzma_close, lzma_stat); if (abfd == NULL) return NULL; if (!bfd_check_format (abfd, bfd_object)) { warning (_("Cannot parse .gnu_debugdata section; not a BFD object")); gdb_bfd_unref (abfd); return NULL; } #else warning (_("Cannot parse .gnu_debugdata section; LZMA support was " "disabled at compile time")); abfd = NULL; #endif /* !HAVE_LIBLZMA */ return abfd; }
char * find_separate_debug_file_by_buildid (struct objfile *objfile) { const struct elf_build_id *build_id; build_id = build_id_bfd_get (objfile->obfd); if (build_id != NULL) { bfd *abfd; abfd = build_id_to_debug_bfd (build_id->size, build_id->data); /* Prevent looping on a stripped .debug file. */ if (abfd != NULL && filename_cmp (bfd_get_filename (abfd), objfile_name (objfile)) == 0) { warning (_("\"%s\": separate debug info file has no debug info"), bfd_get_filename (abfd)); gdb_bfd_unref (abfd); } else if (abfd != NULL) { char *result = xstrdup (bfd_get_filename (abfd)); gdb_bfd_unref (abfd); return result; } } return NULL; }
static PyObject * pspy_get_filename (PyObject *self, void *closure) { pspace_object *obj = (pspace_object *) self; if (obj->pspace) { struct objfile *objfile = obj->pspace->symfile_object_file; if (objfile) return PyString_Decode (objfile_name (objfile), strlen (objfile_name (objfile)), host_charset (), NULL); } Py_RETURN_NONE; }
static struct type * get_regs_type (struct objfile *objfile) { struct symbol *func_sym; struct type *func_type, *regsp_type, *regs_type; func_sym = lookup_global_symbol_from_objfile (objfile, GCC_FE_WRAPPER_FUNCTION, VAR_DOMAIN); if (func_sym == NULL) error (_("Cannot find function \"%s\" in compiled module \"%s\"."), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); func_type = SYMBOL_TYPE (func_sym); if (TYPE_CODE (func_type) != TYPE_CODE_FUNC) error (_("Invalid type code %d of function \"%s\" in compiled " "module \"%s\"."), TYPE_CODE (func_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); /* No register parameter present. */ if (TYPE_NFIELDS (func_type) == 0) return NULL; if (TYPE_NFIELDS (func_type) != 1) error (_("Invalid %d parameters of function \"%s\" in compiled " "module \"%s\"."), TYPE_NFIELDS (func_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); regsp_type = check_typedef (TYPE_FIELD_TYPE (func_type, 0)); if (TYPE_CODE (regsp_type) != TYPE_CODE_PTR) error (_("Invalid type code %d of first parameter of function \"%s\" " "in compiled module \"%s\"."), TYPE_CODE (regsp_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); regs_type = check_typedef (TYPE_TARGET_TYPE (regsp_type)); if (TYPE_CODE (regs_type) != TYPE_CODE_STRUCT) error (_("Invalid type code %d of dereferenced first parameter " "of function \"%s\" in compiled module \"%s\"."), TYPE_CODE (regs_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); return regs_type; }
static PyObject * objfpy_get_filename (PyObject *self, void *closure) { objfile_object *obj = (objfile_object *) self; if (obj->objfile) return host_string_to_python_string (objfile_name (obj->objfile)); Py_RETURN_NONE; }
static PyObject * pspy_get_filename (PyObject *self, void *closure) { pspace_object *obj = (pspace_object *) self; if (obj->pspace) { struct objfile *objfile = obj->pspace->symfile_object_file; if (objfile) return host_string_to_python_string (objfile_name (objfile)); } Py_RETURN_NONE; }
static bfd_byte * macho_symfile_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf) { bfd *abfd = objfile->obfd; /* We're only interested in sections with relocation information. */ if ((sectp->flags & SEC_RELOC) == 0) return NULL; if (mach_o_debug_level > 0) printf_unfiltered (_("Relocate section '%s' of %s\n"), sectp->name, objfile_name (objfile)); return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL); }
int dump_subexp_body_standard (struct expression *exp, struct ui_file *stream, int elt) { int opcode = exp->elts[elt++].opcode; switch (opcode) { case TERNOP_COND: case TERNOP_SLICE: elt = dump_subexp (exp, stream, elt); /* FALL THROUGH */ case BINOP_ADD: case BINOP_SUB: case BINOP_MUL: case BINOP_DIV: case BINOP_REM: case BINOP_MOD: case BINOP_LSH: case BINOP_RSH: case BINOP_LOGICAL_AND: case BINOP_LOGICAL_OR: case BINOP_BITWISE_AND: case BINOP_BITWISE_IOR: case BINOP_BITWISE_XOR: case BINOP_EQUAL: case BINOP_NOTEQUAL: case BINOP_LESS: case BINOP_GTR: case BINOP_LEQ: case BINOP_GEQ: case BINOP_REPEAT: case BINOP_ASSIGN: case BINOP_COMMA: case BINOP_SUBSCRIPT: case BINOP_EXP: case BINOP_MIN: case BINOP_MAX: case BINOP_INTDIV: case BINOP_ASSIGN_MODIFY: case BINOP_VAL: case BINOP_CONCAT: case BINOP_IN: case BINOP_RANGE: case BINOP_END: case STRUCTOP_MEMBER: case STRUCTOP_MPTR: elt = dump_subexp (exp, stream, elt); /* FALL THROUGH */ case UNOP_NEG: case UNOP_LOGICAL_NOT: case UNOP_COMPLEMENT: case UNOP_IND: case UNOP_ADDR: case UNOP_PREINCREMENT: case UNOP_POSTINCREMENT: case UNOP_PREDECREMENT: case UNOP_POSTDECREMENT: case UNOP_SIZEOF: case UNOP_PLUS: case UNOP_CAP: case UNOP_CHR: case UNOP_ORD: case UNOP_ABS: case UNOP_FLOAT: case UNOP_HIGH: case UNOP_MAX: case UNOP_MIN: case UNOP_ODD: case UNOP_TRUNC: elt = dump_subexp (exp, stream, elt); break; case OP_LONG: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, "), value %ld (0x%lx)", (long) exp->elts[elt + 1].longconst, (long) exp->elts[elt + 1].longconst); elt += 3; break; case OP_DOUBLE: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, "), value %g", (double) exp->elts[elt + 1].doubleconst); elt += 3; break; case OP_VAR_VALUE: fprintf_filtered (stream, "Block @"); gdb_print_host_address (exp->elts[elt].block, stream); fprintf_filtered (stream, ", symbol @"); gdb_print_host_address (exp->elts[elt + 1].symbol, stream); fprintf_filtered (stream, " (%s)", SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol)); elt += 3; break; case OP_VAR_ENTRY_VALUE: fprintf_filtered (stream, "Entry value of symbol @"); gdb_print_host_address (exp->elts[elt].symbol, stream); fprintf_filtered (stream, " (%s)", SYMBOL_PRINT_NAME (exp->elts[elt].symbol)); elt += 2; break; case OP_LAST: fprintf_filtered (stream, "History element %ld", (long) exp->elts[elt].longconst); elt += 2; break; case OP_REGISTER: fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string); elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1); break; case OP_INTERNALVAR: fprintf_filtered (stream, "Internal var @"); gdb_print_host_address (exp->elts[elt].internalvar, stream); fprintf_filtered (stream, " (%s)", internalvar_name (exp->elts[elt].internalvar)); elt += 2; break; case OP_FUNCALL: { int i, nargs; nargs = longest_to_int (exp->elts[elt].longconst); fprintf_filtered (stream, "Number of args: %d", nargs); elt += 2; for (i = 1; i <= nargs + 1; i++) elt = dump_subexp (exp, stream, elt); } break; case OP_ARRAY: { int lower, upper; int i; lower = longest_to_int (exp->elts[elt].longconst); upper = longest_to_int (exp->elts[elt + 1].longconst); fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); elt += 3; for (i = 1; i <= upper - lower + 1; i++) elt = dump_subexp (exp, stream, elt); } break; case UNOP_DYNAMIC_CAST: case UNOP_REINTERPRET_CAST: case UNOP_CAST_TYPE: case UNOP_MEMVAL_TYPE: fprintf_filtered (stream, " ("); elt = dump_subexp (exp, stream, elt); fprintf_filtered (stream, ")"); elt = dump_subexp (exp, stream, elt); break; case UNOP_MEMVAL: case UNOP_CAST: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt = dump_subexp (exp, stream, elt + 2); break; case UNOP_MEMVAL_TLS: fprintf_filtered (stream, "TLS type @"); gdb_print_host_address (exp->elts[elt + 1].type, stream); fprintf_filtered (stream, " (__thread /* \"%s\" */ ", (exp->elts[elt].objfile == NULL ? "(null)" : objfile_name (exp->elts[elt].objfile))); type_print (exp->elts[elt + 1].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt = dump_subexp (exp, stream, elt + 3); break; case OP_TYPE: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt += 2; break; case OP_TYPEOF: case OP_DECLTYPE: fprintf_filtered (stream, "Typeof ("); elt = dump_subexp (exp, stream, elt); fprintf_filtered (stream, ")"); break; case OP_TYPEID: fprintf_filtered (stream, "typeid ("); elt = dump_subexp (exp, stream, elt); fprintf_filtered (stream, ")"); break; case STRUCTOP_STRUCT: case STRUCTOP_PTR: { char *elem_name; int len; len = longest_to_int (exp->elts[elt].longconst); elem_name = &exp->elts[elt + 1].string; fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); } break; case OP_SCOPE: { char *elem_name; int len; fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ") "); len = longest_to_int (exp->elts[elt + 1].longconst); elem_name = &exp->elts[elt + 2].string; fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); elt += 4 + BYTES_TO_EXP_ELEM (len + 1); } break; case TYPE_INSTANCE: { LONGEST len; len = exp->elts[elt++].longconst; fprintf_filtered (stream, "%s TypeInstance: ", plongest (len)); while (len-- > 0) { fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt++; if (len > 0) fputs_filtered (", ", stream); } /* Ending LEN and ending TYPE_INSTANCE. */ elt += 2; elt = dump_subexp (exp, stream, elt); } break; default: case OP_NULL: case MULTI_SUBSCRIPT: case OP_F77_UNDETERMINED_ARGLIST: case OP_COMPLEX: case OP_STRING: case OP_BOOL: case OP_M2_STRING: case OP_THIS: case OP_NAME: fprintf_filtered (stream, "Unknown format"); } return elt; }
struct compile_module * compile_object_load (const char *object_file, const char *source_file, enum compile_i_scope_types scope, void *scope_data) { struct cleanup *cleanups, *cleanups_free_objfile; bfd *abfd; struct setup_sections_data setup_sections_data; CORE_ADDR addr, regs_addr, out_value_addr = 0; struct symbol *func_sym; struct type *func_type; struct bound_minimal_symbol bmsym; long storage_needed; asymbol **symbol_table, **symp; long number_of_symbols, missing_symbols; struct type *dptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; unsigned dptr_type_len = TYPE_LENGTH (dptr_type); struct compile_module *retval; struct type *regs_type, *out_value_type = NULL; char *filename, **matching; struct objfile *objfile; int expect_parameters; struct type *expect_return_type; struct munmap_list *munmap_list_head = NULL; filename = tilde_expand (object_file); cleanups = make_cleanup (xfree, filename); abfd = gdb_bfd_open (filename, gnutarget, -1); if (abfd == NULL) error (_("\"%s\": could not open as compiled module: %s"), filename, bfd_errmsg (bfd_get_error ())); make_cleanup_bfd_unref (abfd); if (!bfd_check_format_matches (abfd, bfd_object, &matching)) error (_("\"%s\": not in loadable format: %s"), filename, gdb_bfd_errmsg (bfd_get_error (), matching)); if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) != 0) error (_("\"%s\": not in object format."), filename); setup_sections_data.last_size = 0; setup_sections_data.last_section_first = abfd->sections; setup_sections_data.last_prot = -1; setup_sections_data.last_max_alignment = 1; setup_sections_data.munmap_list_headp = &munmap_list_head; make_cleanup (munmap_listp_free_cleanup, &munmap_list_head); bfd_map_over_sections (abfd, setup_sections, &setup_sections_data); setup_sections (abfd, NULL, &setup_sections_data); storage_needed = bfd_get_symtab_upper_bound (abfd); if (storage_needed < 0) error (_("Cannot read symbols of compiled module \"%s\": %s"), filename, bfd_errmsg (bfd_get_error ())); /* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in "Reading symbols from ..." message for automatically generated file. */ objfile = symbol_file_add_from_bfd (abfd, filename, 0, NULL, 0, NULL); cleanups_free_objfile = make_cleanup_free_objfile (objfile); func_sym = lookup_global_symbol_from_objfile (objfile, GCC_FE_WRAPPER_FUNCTION, VAR_DOMAIN).symbol; if (func_sym == NULL) error (_("Cannot find function \"%s\" in compiled module \"%s\"."), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); func_type = SYMBOL_TYPE (func_sym); if (TYPE_CODE (func_type) != TYPE_CODE_FUNC) error (_("Invalid type code %d of function \"%s\" in compiled " "module \"%s\"."), TYPE_CODE (func_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); switch (scope) { case COMPILE_I_SIMPLE_SCOPE: expect_parameters = 1; expect_return_type = builtin_type (target_gdbarch ())->builtin_void; break; case COMPILE_I_RAW_SCOPE: expect_parameters = 0; expect_return_type = builtin_type (target_gdbarch ())->builtin_void; break; case COMPILE_I_PRINT_ADDRESS_SCOPE: case COMPILE_I_PRINT_VALUE_SCOPE: expect_parameters = 2; expect_return_type = builtin_type (target_gdbarch ())->builtin_void; break; default: internal_error (__FILE__, __LINE__, _("invalid scope %d"), scope); } if (TYPE_NFIELDS (func_type) != expect_parameters) error (_("Invalid %d parameters of function \"%s\" in compiled " "module \"%s\"."), TYPE_NFIELDS (func_type), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); if (!types_deeply_equal (expect_return_type, TYPE_TARGET_TYPE (func_type))) error (_("Invalid return type of function \"%s\" in compiled " "module \"%s\"."), GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile)); /* The memory may be later needed by bfd_generic_get_relocated_section_contents called from default_symfile_relocate. */ symbol_table = obstack_alloc (&objfile->objfile_obstack, storage_needed); number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); if (number_of_symbols < 0) error (_("Cannot parse symbols of compiled module \"%s\": %s"), filename, bfd_errmsg (bfd_get_error ())); missing_symbols = 0; for (symp = symbol_table; symp < symbol_table + number_of_symbols; symp++) { asymbol *sym = *symp; if (sym->flags != 0) continue; sym->flags = BSF_GLOBAL; sym->section = bfd_abs_section_ptr; if (strcmp (sym->name, "_GLOBAL_OFFSET_TABLE_") == 0) { if (compile_debug) fprintf_unfiltered (gdb_stdlog, "ELF symbol \"%s\" relocated to zero\n", sym->name); /* It seems to be a GCC bug, with -mcmodel=large there should be no need for _GLOBAL_OFFSET_TABLE_. Together with -fPIE the data remain PC-relative even with _GLOBAL_OFFSET_TABLE_ as zero. */ sym->value = 0; continue; } bmsym = lookup_minimal_symbol (sym->name, NULL, NULL); switch (bmsym.minsym == NULL ? mst_unknown : MSYMBOL_TYPE (bmsym.minsym)) { case mst_text: sym->value = BMSYMBOL_VALUE_ADDRESS (bmsym); if (compile_debug) fprintf_unfiltered (gdb_stdlog, "ELF mst_text symbol \"%s\" relocated to %s\n", sym->name, paddress (target_gdbarch (), sym->value)); break; case mst_text_gnu_ifunc: sym->value = gnu_ifunc_resolve_addr (target_gdbarch (), BMSYMBOL_VALUE_ADDRESS (bmsym)); if (compile_debug) fprintf_unfiltered (gdb_stdlog, "ELF mst_text_gnu_ifunc symbol \"%s\" " "relocated to %s\n", sym->name, paddress (target_gdbarch (), sym->value)); break; default: warning (_("Could not find symbol \"%s\" " "for compiled module \"%s\"."), sym->name, filename); missing_symbols++; } } if (missing_symbols) error (_("%ld symbols were missing, cannot continue."), missing_symbols); bfd_map_over_sections (abfd, copy_sections, symbol_table); regs_type = get_regs_type (func_sym, objfile); if (regs_type == NULL) regs_addr = 0; else { /* Use read-only non-executable memory protection. */ regs_addr = gdbarch_infcall_mmap (target_gdbarch (), TYPE_LENGTH (regs_type), GDB_MMAP_PROT_READ); gdb_assert (regs_addr != 0); munmap_list_add (&munmap_list_head, regs_addr, TYPE_LENGTH (regs_type)); if (compile_debug) fprintf_unfiltered (gdb_stdlog, "allocated %s bytes at %s for registers\n", paddress (target_gdbarch (), TYPE_LENGTH (regs_type)), paddress (target_gdbarch (), regs_addr)); store_regs (regs_type, regs_addr); } if (scope == COMPILE_I_PRINT_ADDRESS_SCOPE || scope == COMPILE_I_PRINT_VALUE_SCOPE) { out_value_type = get_out_value_type (func_sym, objfile, scope); if (out_value_type == NULL) { do_cleanups (cleanups); return NULL; } check_typedef (out_value_type); out_value_addr = gdbarch_infcall_mmap (target_gdbarch (), TYPE_LENGTH (out_value_type), (GDB_MMAP_PROT_READ | GDB_MMAP_PROT_WRITE)); gdb_assert (out_value_addr != 0); munmap_list_add (&munmap_list_head, out_value_addr, TYPE_LENGTH (out_value_type)); if (compile_debug) fprintf_unfiltered (gdb_stdlog, "allocated %s bytes at %s for printed value\n", paddress (target_gdbarch (), TYPE_LENGTH (out_value_type)), paddress (target_gdbarch (), out_value_addr)); } discard_cleanups (cleanups_free_objfile); retval = xmalloc (sizeof (*retval)); retval->objfile = objfile; retval->source_file = xstrdup (source_file); retval->func_sym = func_sym; retval->regs_addr = regs_addr; retval->scope = scope; retval->scope_data = scope_data; retval->out_value_type = out_value_type; retval->out_value_addr = out_value_addr; /* CLEANUPS will free MUNMAP_LIST_HEAD. */ retval->munmap_list_head = munmap_list_head; munmap_list_head = NULL; do_cleanups (cleanups); return retval; }
static struct type * get_out_value_type (struct symbol *func_sym, struct objfile *objfile, enum compile_i_scope_types scope) { struct symbol *gdb_ptr_type_sym; /* Initialize it just to avoid a GCC false warning. */ struct symbol *gdb_val_sym = NULL; struct type *gdb_ptr_type, *gdb_type_from_ptr, *gdb_type, *retval; /* Initialize it just to avoid a GCC false warning. */ const struct block *block = NULL; const struct blockvector *bv; int nblocks = 0; int block_loop = 0; bv = SYMTAB_BLOCKVECTOR (func_sym->owner.symtab); nblocks = BLOCKVECTOR_NBLOCKS (bv); gdb_ptr_type_sym = NULL; for (block_loop = 0; block_loop < nblocks; block_loop++) { struct symbol *function = NULL; const struct block *function_block; block = BLOCKVECTOR_BLOCK (bv, block_loop); if (BLOCK_FUNCTION (block) != NULL) continue; gdb_val_sym = block_lookup_symbol (block, COMPILE_I_EXPR_VAL, VAR_DOMAIN); if (gdb_val_sym == NULL) continue; function_block = block; while (function_block != BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) && function_block != BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) { function_block = BLOCK_SUPERBLOCK (function_block); function = BLOCK_FUNCTION (function_block); if (function != NULL) break; } if (function != NULL && (BLOCK_SUPERBLOCK (function_block) == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) && (strcmp (SYMBOL_LINKAGE_NAME (function), GCC_FE_WRAPPER_FUNCTION) == 0)) break; } if (block_loop == nblocks) error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE); gdb_type = SYMBOL_TYPE (gdb_val_sym); gdb_type = check_typedef (gdb_type); gdb_ptr_type_sym = block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE, VAR_DOMAIN); if (gdb_ptr_type_sym == NULL) error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE); gdb_ptr_type = SYMBOL_TYPE (gdb_ptr_type_sym); gdb_ptr_type = check_typedef (gdb_ptr_type); if (TYPE_CODE (gdb_ptr_type) != TYPE_CODE_PTR) error (_("Type of \"%s\" is not a pointer"), COMPILE_I_EXPR_PTR_TYPE); gdb_type_from_ptr = TYPE_TARGET_TYPE (gdb_ptr_type); if (types_deeply_equal (gdb_type, gdb_type_from_ptr)) { if (scope != COMPILE_I_PRINT_ADDRESS_SCOPE) error (_("Expected address scope in compiled module \"%s\"."), objfile_name (objfile)); return gdb_type; } if (TYPE_CODE (gdb_type) != TYPE_CODE_PTR) error (_("Invalid type code %d of symbol \"%s\" " "in compiled module \"%s\"."), TYPE_CODE (gdb_type_from_ptr), COMPILE_I_EXPR_VAL, objfile_name (objfile)); retval = gdb_type_from_ptr; switch (TYPE_CODE (gdb_type_from_ptr)) { case TYPE_CODE_ARRAY: gdb_type_from_ptr = TYPE_TARGET_TYPE (gdb_type_from_ptr); break; case TYPE_CODE_FUNC: break; default: error (_("Invalid type code %d of symbol \"%s\" " "in compiled module \"%s\"."), TYPE_CODE (gdb_type_from_ptr), COMPILE_I_EXPR_PTR_TYPE, objfile_name (objfile)); } if (!types_deeply_equal (gdb_type_from_ptr, TYPE_TARGET_TYPE (gdb_type))) error (_("Referenced types do not match for symbols \"%s\" and \"%s\" " "in compiled module \"%s\"."), COMPILE_I_EXPR_PTR_TYPE, COMPILE_I_EXPR_VAL, objfile_name (objfile)); if (scope == COMPILE_I_PRINT_ADDRESS_SCOPE) return NULL; return retval; }
static void macho_symtab_read (minimal_symbol_reader &reader, struct objfile *objfile, long number_of_symbols, asymbol **symbol_table, std::vector<oso_el> *oso_vector_ptr) { long i; const asymbol *file_so = NULL; asymbol **oso_file = NULL; unsigned int nbr_syms = 0; /* Current state while reading stabs. */ enum { /* Not within an SO part. Only non-debugging symbols should be present, and will be added to the minimal symbols table. */ S_NO_SO, /* First SO read. Introduce an SO section, and may be followed by a second SO. The SO section should contain onl debugging symbols. */ S_FIRST_SO, /* Second non-null SO found, just after the first one. Means that the first is in fact a directory name. */ S_SECOND_SO, /* Non-null OSO found. Debugging info are DWARF in this OSO file. */ S_DWARF_FILE, S_STAB_FILE } state = S_NO_SO; for (i = 0; i < number_of_symbols; i++) { const asymbol *sym = symbol_table[i]; bfd_mach_o_asymbol *mach_o_sym = (bfd_mach_o_asymbol *)sym; switch (state) { case S_NO_SO: if (mach_o_sym->n_type == N_SO) { /* Start of object stab. */ if (sym->name == NULL || sym->name[0] == 0) { /* Unexpected empty N_SO. */ complaint (_("Unexpected empty N_SO stab")); } else { file_so = sym; state = S_FIRST_SO; } } else if (sym->flags & BSF_DEBUGGING) { if (mach_o_sym->n_type == N_OPT) { /* No complaint for OPT. */ break; } /* Debugging symbols are not expected here. */ complaint (_("%s: Unexpected debug stab outside SO markers"), objfile_name (objfile)); } else { /* Non-debugging symbols go to the minimal symbol table. */ macho_symtab_add_minsym (reader, objfile, sym); } break; case S_FIRST_SO: case S_SECOND_SO: if (mach_o_sym->n_type == N_SO) { if (sym->name == NULL || sym->name[0] == 0) { /* Unexpected empty N_SO. */ complaint (_("Empty SO section")); state = S_NO_SO; } else if (state == S_FIRST_SO) { /* Second SO stab for the file name. */ file_so = sym; state = S_SECOND_SO; } else complaint (_("Three SO in a raw")); } else if (mach_o_sym->n_type == N_OSO) { if (sym->name == NULL || sym->name[0] == 0) { /* Empty OSO. Means that this file was compiled with stabs. */ state = S_STAB_FILE; warning (_("stabs debugging not supported for %s"), file_so->name); } else { /* Non-empty OSO for a Dwarf file. */ oso_file = symbol_table + i; nbr_syms = 0; state = S_DWARF_FILE; } } else complaint (_("Unexpected stab after SO")); break; case S_STAB_FILE: case S_DWARF_FILE: if (mach_o_sym->n_type == N_SO) { if (sym->name == NULL || sym->name[0] == 0) { /* End of file. */ if (state == S_DWARF_FILE) oso_vector_ptr->emplace_back (oso_file, symbol_table + i, nbr_syms); state = S_NO_SO; } else { complaint (_("Missing nul SO")); file_so = sym; state = S_FIRST_SO; } } else if (sym->flags & BSF_DEBUGGING) { if (state == S_STAB_FILE) { /* FIXME: to be implemented. */ } else { switch (mach_o_sym->n_type) { case N_FUN: if (sym->name == NULL || sym->name[0] == 0) break; /* Fall through. */ case N_STSYM: /* Interesting symbol. */ nbr_syms++; break; case N_ENSYM: case N_BNSYM: case N_GSYM: break; default: complaint (_("unhandled stab for dwarf OSO file")); break; } } } else complaint (_("non-debugging symbol within SO")); break; } } if (state != S_NO_SO) complaint (_("missing nul SO")); }