/* Enable shared library breakpoint for the OpenCL runtime running on the SPU. */ static void ocl_enable_break (struct objfile *objfile) { struct bound_minimal_symbol event_sym; struct bound_minimal_symbol addr_sym; /* The OpenCL runtime on the SPU will call __opencl_program_update_event whenever an OpenCL program is loaded. */ event_sym = lookup_minimal_symbol ("__opencl_program_update_event", NULL, objfile); /* The PPU address of the OpenCL program can be found at opencl_elf_image_address. */ addr_sym = lookup_minimal_symbol ("opencl_elf_image_address", NULL, objfile); if (event_sym.minsym && addr_sym.minsym) { /* Place a solib_event breakpoint on the symbol. */ CORE_ADDR event_addr = BMSYMBOL_VALUE_ADDRESS (event_sym); create_solib_event_breakpoint (get_objfile_arch (objfile), event_addr); /* Store the address of the symbol that will point to OpenCL program using the per-objfile private data mechanism. */ if (objfile_data (objfile, ocl_program_data_key) == NULL) { CORE_ADDR *ocl_program_addr_base = OBSTACK_CALLOC ( &objfile->objfile_obstack, objfile->sections_end - objfile->sections, CORE_ADDR); *ocl_program_addr_base = BMSYMBOL_VALUE_ADDRESS (addr_sym); set_objfile_data (objfile, ocl_program_data_key, ocl_program_addr_base); } } }
CORE_ADDR get_pc_function_start (CORE_ADDR pc) { const struct block *bl; struct bound_minimal_symbol msymbol; bl = block_for_pc (pc); if (bl) { struct symbol *symbol = block_linkage_function (bl); if (symbol) { bl = SYMBOL_BLOCK_VALUE (symbol); return BLOCK_START (bl); } } msymbol = lookup_minimal_symbol_by_pc (pc); if (msymbol.minsym) { CORE_ADDR fstart = BMSYMBOL_VALUE_ADDRESS (msymbol); if (find_pc_section (fstart)) return fstart; } return 0; }
/* Hook into inferior_created, solib_loaded, and solib_unloaded observers to track whether we've loaded a version of libspe2 (as static or dynamic library) that provides the __spe_current_active_context variable. */ static void ppc_linux_spe_context_lookup (struct objfile *objfile) { struct bound_minimal_symbol sym; if (!objfile) { spe_context_objfile = NULL; spe_context_lm_addr = 0; spe_context_offset = 0; spe_context_cache_ptid = minus_one_ptid; spe_context_cache_address = 0; return; } sym = lookup_minimal_symbol ("__spe_current_active_context", NULL, objfile); if (sym.minsym) { spe_context_objfile = objfile; spe_context_lm_addr = svr4_fetch_objfile_link_map (objfile); spe_context_offset = BMSYMBOL_VALUE_ADDRESS (sym); spe_context_cache_ptid = minus_one_ptid; spe_context_cache_address = 0; return; } }
CORE_ADDR kgdb_lookup(const char *sym) { struct bound_minimal_symbol msym; msym = lookup_minimal_symbol(sym, NULL, NULL); if (msym.minsym == NULL) return (0); return (BMSYMBOL_VALUE_ADDRESS(msym)); }
CORE_ADDR obsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) { struct bound_minimal_symbol msym; msym = lookup_minimal_symbol("_dl_bind", NULL, NULL); if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc) return frame_unwind_caller_pc (get_current_frame ()); else return find_solib_trampoline_target (get_current_frame (), pc); }
CORE_ADDR sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) { struct bound_minimal_symbol msym; msym = lookup_minimal_symbol("elf_bndr", NULL, NULL); if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc) return frame_unwind_caller_pc (get_current_frame ()); return 0; }
static CORE_ADDR ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc) { struct bound_minimal_symbol fun; int local_entry_offset = 0; fun = lookup_minimal_symbol_by_pc (pc); if (fun.minsym == NULL) return pc; /* See ppc_elfv2_elf_make_msymbol_special for how local entry point offset values are encoded. */ if (MSYMBOL_TARGET_FLAG_1 (fun.minsym)) local_entry_offset = 8; if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset) return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset; return pc; }
int find_minimal_symbol_address (const char *name, CORE_ADDR *addr, struct objfile *objfile) { struct bound_minimal_symbol sym = lookup_minimal_symbol (name, NULL, objfile); if (sym.minsym != NULL) *addr = BMSYMBOL_VALUE_ADDRESS (sym); return sym.minsym == NULL; }
static int nbsd_thread_proc_lookup (void *arg, const char *sym, caddr_t *addr) { struct bound_minimal_symbol bms; bms = lookup_minimal_symbol (sym, NULL, NULL); if (bms.minsym == NULL) return TD_ERR_NOSYM; *addr = (caddr_t)(uintptr_t)BMSYMBOL_VALUE_ADDRESS (bms); return 0; }
static void som_solib_create_inferior_hook (int from_tty) { enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); struct bound_minimal_symbol msymbol; unsigned int dld_flags, status, have_endo; asection *shlib_info; gdb_byte buf[4]; CORE_ADDR anaddr; if (symfile_objfile == NULL) return; /* First see if the objfile was dynamically linked. */ shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$"); if (!shlib_info) return; /* It's got a $SHLIB_INFO$ section, make sure it's not empty. */ if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0) return; /* Read the DL header. */ bfd_get_section_contents (symfile_objfile->obfd, shlib_info, (char *) &dl_header, 0, sizeof (dl_header)); have_endo = 0; /* Slam the pid of the process into __d_pid. We used to warn when this failed, but that warning is only useful on very old HP systems (hpux9 and older). The warnings are an annoyance to users of modern systems and foul up the testsuite as well. As a result, the warnings have been disabled. */ msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile); if (msymbol.minsym == NULL) goto keep_going; anaddr = BMSYMBOL_VALUE_ADDRESS (msymbol); store_unsigned_integer (buf, 4, byte_order, ptid_get_pid (inferior_ptid)); status = target_write_memory (anaddr, buf, 4); if (status != 0) { warning (_("\ Unable to write __d_pid.\n\ Suggest linking with /opt/langtools/lib/end.o.\n\ GDB will be unable to track shl_load/shl_unload calls")); goto keep_going; }
static CORE_ADDR lm_base (void) { enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); struct bound_minimal_symbol got_sym; CORE_ADDR addr; gdb_byte buf[FRV_PTR_SIZE]; /* One of our assumptions is that the main executable has been relocated. Bail out if this has not happened. (Note that post_create_inferior() in infcmd.c will call solib_add prior to solib_create_inferior_hook(). If we allow this to happen, lm_base_cache will be initialized with a bogus value. */ if (main_executable_lm_info == 0) return 0; /* If we already have a cached value, return it. */ if (lm_base_cache) return lm_base_cache; got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", NULL, symfile_objfile); if (got_sym.minsym == 0) { if (solib_frv_debug) fprintf_unfiltered (gdb_stdlog, "lm_base: _GLOBAL_OFFSET_TABLE_ not found.\n"); return 0; } addr = BMSYMBOL_VALUE_ADDRESS (got_sym) + 8; if (solib_frv_debug) fprintf_unfiltered (gdb_stdlog, "lm_base: _GLOBAL_OFFSET_TABLE_ + 8 = %s\n", hex_string_custom (addr, 8)); if (target_read_memory (addr, buf, sizeof buf) != 0) return 0; lm_base_cache = extract_unsigned_integer (buf, sizeof buf, byte_order); if (solib_frv_debug) fprintf_unfiltered (gdb_stdlog, "lm_base: lm_base_cache = %s\n", hex_string_custom (lm_base_cache, 8)); return lm_base_cache; }
ps_err_e ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj, const char *name, psaddr_t *sym_addr) { inferior *inf = ph->thread->inf; scoped_restore_current_program_space restore_pspace; set_current_program_space (inf->pspace); /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */ bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL); if (ms.minsym == NULL) return PS_NOSYM; *sym_addr = core_addr_to_ps_addr (BMSYMBOL_VALUE_ADDRESS (ms)); return PS_OK; }
static CORE_ADDR macho_resolve_oso_sym_with_minsym (struct objfile *main_objfile, asymbol *sym) { /* For common symbol and global symbols, use the min symtab. */ struct bound_minimal_symbol msym; const char *name = sym->name; if (name[0] == bfd_get_symbol_leading_char (main_objfile->obfd)) ++name; msym = lookup_minimal_symbol (name, NULL, main_objfile); if (msym.minsym == NULL) { warning (_("can't find symbol '%s' in minsymtab"), name); return 0; } else return BMSYMBOL_VALUE_ADDRESS (msym); }
/* Enable shared library breakpoint. */ static int spu_enable_break (struct objfile *objfile) { struct bound_minimal_symbol spe_event_sym; /* The libspe library will call __spe_context_update_event whenever any SPE context is allocated or destroyed. */ spe_event_sym = lookup_minimal_symbol ("__spe_context_update_event", NULL, objfile); /* Place a solib_event breakpoint on the symbol. */ if (spe_event_sym.minsym) { CORE_ADDR addr = BMSYMBOL_VALUE_ADDRESS (spe_event_sym); addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (), addr, ¤t_target); create_solib_event_breakpoint (target_gdbarch (), addr); return 1; } return 0; }
void tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) { struct tui_gen_win_info *locator; struct tui_locator_element *element; struct gdbarch *gdbarch = get_current_arch (); CORE_ADDR addr; locator = tui_locator_win_info_ptr (); element = &locator->content[0]->which_element.locator; if (element->addr == 0) { struct bound_minimal_symbol main_symbol; /* Find address of the start of program. Note: this should be language specific. */ main_symbol = lookup_minimal_symbol ("main", NULL, NULL); if (main_symbol.minsym == 0) main_symbol = lookup_minimal_symbol ("MAIN", NULL, NULL); if (main_symbol.minsym == 0) main_symbol = lookup_minimal_symbol ("_start", NULL, NULL); if (main_symbol.minsym) addr = BMSYMBOL_VALUE_ADDRESS (main_symbol); else addr = 0; } else /* The target is executing. */ { gdbarch = element->gdbarch; addr = element->addr; } *gdbarch_p = gdbarch; *addr_p = addr; }
ps_err_e ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, const char *name, psaddr_t *sym_addr) { struct bound_minimal_symbol ms; struct cleanup *old_chain = save_current_program_space (); struct inferior *inf = find_inferior_ptid (ph->ptid); ps_err_e result; set_current_program_space (inf->pspace); /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */ ms = lookup_minimal_symbol (name, NULL, NULL); if (ms.minsym == NULL) result = PS_NOSYM; else { *sym_addr = core_addr_to_ps_addr (BMSYMBOL_VALUE_ADDRESS (ms)); result = PS_OK; } do_cleanups (old_chain); return result; }
void pascal_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value *original_value, const struct value_print_options *options) { struct gdbarch *gdbarch = get_type_arch (type); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); unsigned int i = 0; /* Number of characters printed */ unsigned len; LONGEST low_bound, high_bound; struct type *elttype; unsigned eltlen; int length_pos, length_size, string_pos; struct type *char_type; CORE_ADDR addr; int want_space = 0; type = check_typedef (type); switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: if (get_array_bounds (type, &low_bound, &high_bound)) { len = high_bound - low_bound + 1; elttype = check_typedef (TYPE_TARGET_TYPE (type)); eltlen = TYPE_LENGTH (elttype); if (options->prettyformat_arrays) { print_spaces_filtered (2 + 2 * recurse, stream); } /* If 's' format is used, try to print out as string. If no format is given, print as string if element type is of TYPE_CODE_CHAR and element size is 1,2 or 4. */ if (options->format == 's' || ((eltlen == 1 || eltlen == 2 || eltlen == 4) && TYPE_CODE (elttype) == TYPE_CODE_CHAR && options->format == 0)) { /* If requested, look for the first null char and only print elements up to it. */ if (options->stop_print_at_null) { unsigned int temp_len; /* Look for a NULL char. */ for (temp_len = 0; extract_unsigned_integer (valaddr + embedded_offset + temp_len * eltlen, eltlen, byte_order) && temp_len < len && temp_len < options->print_max; temp_len++); len = temp_len; } LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), valaddr + embedded_offset, len, NULL, 0, options); i = len; } else { fprintf_filtered (stream, "{"); /* If this is a virtual function table, print the 0th entry specially, and the rest of the members normally. */ if (pascal_object_is_vtbl_ptr_type (elttype)) { i = 1; fprintf_filtered (stream, "%d vtable entries", len - 1); } else { i = 0; } val_print_array_elements (type, valaddr, embedded_offset, address, stream, recurse, original_value, options, i); fprintf_filtered (stream, "}"); } break; } /* Array of unspecified length: treat like pointer to first elt. */ addr = address + embedded_offset; goto print_unpacked_pointer; case TYPE_CODE_PTR: if (options->format && options->format != 's') { val_print_scalar_formatted (type, valaddr, embedded_offset, original_value, options, 0, stream); break; } if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if we ARE using -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ /* Extract the address, assume that it is unsigned. */ addr = extract_unsigned_integer (valaddr + embedded_offset, TYPE_LENGTH (type), byte_order); print_address_demangle (options, gdbarch, addr, stream, demangle); break; } check_typedef (TYPE_TARGET_TYPE (type)); addr = unpack_pointer (type, valaddr + embedded_offset); print_unpacked_pointer: elttype = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) { /* Try to print what function it points to. */ print_address_demangle (options, gdbarch, addr, stream, demangle); return; } if (options->addressprint && options->format != 's') { fputs_filtered (paddress (gdbarch, addr), stream); want_space = 1; } /* For a pointer to char or unsigned char, also print the string pointed to, unless pointer is null. */ if (((TYPE_LENGTH (elttype) == 1 && (TYPE_CODE (elttype) == TYPE_CODE_INT || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) && (options->format == 0 || options->format == 's') && addr != 0) { if (want_space) fputs_filtered (" ", stream); /* No wide string yet. */ i = val_print_string (elttype, NULL, addr, -1, stream, options); } /* Also for pointers to pascal strings. */ /* Note: this is Free Pascal specific: as GDB does not recognize stabs pascal strings Pascal strings are mapped to records with lowercase names PM. */ if (is_pascal_string_type (elttype, &length_pos, &length_size, &string_pos, &char_type, NULL) && addr != 0) { ULONGEST string_length; gdb_byte *buffer; if (want_space) fputs_filtered (" ", stream); buffer = (gdb_byte *) xmalloc (length_size); read_memory (addr + length_pos, buffer, length_size); string_length = extract_unsigned_integer (buffer, length_size, byte_order); xfree (buffer); i = val_print_string (char_type, NULL, addr + string_pos, string_length, stream, options); } else if (pascal_object_is_vtbl_member (type)) { /* Print vtbl's nicely. */ CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (vt_address); /* If 'symbol_print' is set, we did the work above. */ if (!options->symbol_print && (msymbol.minsym != NULL) && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol))) { if (want_space) fputs_filtered (" ", stream); fputs_filtered ("<", stream); fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream); fputs_filtered (">", stream); want_space = 1; } if (vt_address && options->vtblprint) { struct value *vt_val; struct symbol *wsym = NULL; struct type *wtype; struct block *block = NULL; struct field_of_this_result is_this_fld; if (want_space) fputs_filtered (" ", stream); if (msymbol.minsym != NULL) wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym), block, VAR_DOMAIN, &is_this_fld).symbol; if (wsym) { wtype = SYMBOL_TYPE (wsym); } else { wtype = TYPE_TARGET_TYPE (type); } vt_val = value_at (wtype, vt_address); common_val_print (vt_val, stream, recurse + 1, options, current_language); if (options->prettyformat) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } } } return; case TYPE_CODE_REF: case TYPE_CODE_ENUM: case TYPE_CODE_FLAGS: case TYPE_CODE_FUNC: case TYPE_CODE_RANGE: case TYPE_CODE_INT: case TYPE_CODE_FLT: case TYPE_CODE_VOID: case TYPE_CODE_ERROR: case TYPE_CODE_UNDEF: case TYPE_CODE_BOOL: case TYPE_CODE_CHAR: generic_val_print (type, valaddr, embedded_offset, address, stream, recurse, original_value, options, &p_decorations); break; case TYPE_CODE_UNION: if (recurse && !options->unionprint) { fprintf_filtered (stream, "{...}"); break; } /* Fall through. */ case TYPE_CODE_STRUCT: if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if NOT using -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ /* Extract the address, assume that it is unsigned. */ print_address_demangle (options, gdbarch, extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8, TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET)), byte_order), stream, demangle); } else { if (is_pascal_string_type (type, &length_pos, &length_size, &string_pos, &char_type, NULL)) { len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size, byte_order); LA_PRINT_STRING (stream, char_type, valaddr + embedded_offset + string_pos, len, NULL, 0, options); } else pascal_object_print_value_fields (type, valaddr, embedded_offset, address, stream, recurse, original_value, options, NULL, 0); } break; case TYPE_CODE_SET: elttype = TYPE_INDEX_TYPE (type); elttype = check_typedef (elttype); if (TYPE_STUB (elttype)) { fprintf_filtered (stream, "<incomplete type>"); gdb_flush (stream); break; } else { struct type *range = elttype; LONGEST low_bound, high_bound; int i; int need_comma = 0; fputs_filtered ("[", stream); i = get_discrete_bounds (range, &low_bound, &high_bound); if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) { /* If we know the size of the set type, we can figure out the maximum value. */ i = 0; high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1; TYPE_HIGH_BOUND (range) = high_bound; } maybe_bad_bstring: if (i < 0) { fputs_filtered ("<error value>", stream); goto done; } for (i = low_bound; i <= high_bound; i++) { int element = value_bit_index (type, valaddr + embedded_offset, i); if (element < 0) { i = element; goto maybe_bad_bstring; } if (element) { if (need_comma) fputs_filtered (", ", stream); print_type_scalar (range, i, stream); need_comma = 1; if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i)) { int j = i; fputs_filtered ("..", stream); while (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i)) j = i; print_type_scalar (range, j, stream); } } } done: fputs_filtered ("]", stream); } break; default: error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type)); } gdb_flush (stream); }
static enum target_xfer_status ld_so_xfer_auxv (gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { struct bound_minimal_symbol msym; CORE_ADDR data_address, pointer_address; struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; size_t ptr_size = TYPE_LENGTH (ptr_type); size_t auxv_pair_size = 2 * ptr_size; gdb_byte *ptr_buf = (gdb_byte *) alloca (ptr_size); LONGEST retval; size_t block; msym = lookup_minimal_symbol ("_dl_auxv", NULL, NULL); if (msym.minsym == NULL) return TARGET_XFER_E_IO; if (MSYMBOL_SIZE (msym.minsym) != ptr_size) return TARGET_XFER_E_IO; /* POINTER_ADDRESS is a location where the `_dl_auxv' variable resides. DATA_ADDRESS is the inferior value present in `_dl_auxv', therefore the real inferior AUXV address. */ pointer_address = BMSYMBOL_VALUE_ADDRESS (msym); /* The location of the _dl_auxv symbol may no longer be correct if ld.so runs at a different address than the one present in the file. This is very common case - for unprelinked ld.so or with a PIE executable. PIE executable forces random address even for libraries already being prelinked to some address. PIE executables themselves are never prelinked even on prelinked systems. Prelinking of a PIE executable would block their purpose of randomizing load of everything including the executable. If the memory read fails, return -1 to fallback on another mechanism for retrieving the AUXV. In most cases of a PIE running under valgrind there is no way to find out the base addresses of any of ld.so, executable or AUXV as everything is randomized and /proc information is not relevant for the virtual executable running under valgrind. We think that we might need a valgrind extension to make it work. This is PR 11440. */ if (target_read_memory (pointer_address, ptr_buf, ptr_size) != 0) return TARGET_XFER_E_IO; data_address = extract_typed_address (ptr_buf, ptr_type); /* Possibly still not initialized such as during an inferior startup. */ if (data_address == 0) return TARGET_XFER_E_IO; data_address += offset; if (writebuf != NULL) { if (target_write_memory (data_address, writebuf, len) == 0) { *xfered_len = (ULONGEST) len; return TARGET_XFER_OK; } else return TARGET_XFER_E_IO; } /* Stop if trying to read past the existing AUXV block. The final AT_NULL was already returned before. */ if (offset >= auxv_pair_size) { if (target_read_memory (data_address - auxv_pair_size, ptr_buf, ptr_size) != 0) return TARGET_XFER_E_IO; if (extract_typed_address (ptr_buf, ptr_type) == AT_NULL) return TARGET_XFER_EOF; } retval = 0; block = 0x400; gdb_assert (block % auxv_pair_size == 0); while (len > 0) { if (block > len) block = len; /* Reading sizes smaller than AUXV_PAIR_SIZE is not supported. Tails unaligned to AUXV_PAIR_SIZE will not be read during a call (they should be completed during next read with new/extended buffer). */ block &= -auxv_pair_size; if (block == 0) break; if (target_read_memory (data_address, readbuf, block) != 0) { if (block <= auxv_pair_size) break; block = auxv_pair_size; continue; } data_address += block; len -= block; /* Check terminal AT_NULL. This function is being called indefinitely being extended its READBUF until it returns EOF (0). */ while (block >= auxv_pair_size) { retval += auxv_pair_size; if (extract_typed_address (readbuf, ptr_type) == AT_NULL) { *xfered_len = (ULONGEST) retval; return TARGET_XFER_OK; } readbuf += auxv_pair_size; block -= auxv_pair_size; } } *xfered_len = (ULONGEST) retval; return TARGET_XFER_OK; }
/* Find the disassembly address that corresponds to FROM lines above or below the PC. Variable sized instructions are taken into account by the algorithm. */ static CORE_ADDR tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from) { CORE_ADDR new_low; int max_lines; int i; struct tui_asm_line *asm_lines; max_lines = (from > 0) ? from : - from; if (max_lines <= 1) return pc; asm_lines = XALLOCAVEC (struct tui_asm_line, max_lines); memset (asm_lines, 0, sizeof (struct tui_asm_line) * max_lines); new_low = pc; if (from > 0) { tui_disassemble (gdbarch, asm_lines, pc, max_lines); new_low = asm_lines[max_lines - 1].addr; } else { CORE_ADDR last_addr; int pos; struct bound_minimal_symbol msymbol; /* Find backward an address which is a symbol and for which disassembling from that address will fill completely the window. */ pos = max_lines - 1; do { new_low -= 1 * max_lines; msymbol = lookup_minimal_symbol_by_pc_section (new_low, 0); if (msymbol.minsym) new_low = BMSYMBOL_VALUE_ADDRESS (msymbol); else new_low += 1 * max_lines; tui_disassemble (gdbarch, asm_lines, new_low, max_lines); last_addr = asm_lines[pos].addr; } while (last_addr > pc && msymbol.minsym); /* Scan forward disassembling one instruction at a time until the last visible instruction of the window matches the pc. We keep the disassembled instructions in the 'lines' window and shift it downward (increasing its addresses). */ if (last_addr < pc) do { CORE_ADDR next_addr; pos++; if (pos >= max_lines) pos = 0; next_addr = tui_disassemble (gdbarch, &asm_lines[pos], last_addr, 1); /* If there are some problems while disassembling exit. */ if (next_addr <= last_addr) break; last_addr = next_addr; } while (last_addr <= pc); pos++; if (pos >= max_lines) pos = 0; new_low = asm_lines[pos].addr; } for (i = 0; i < max_lines; i++) { xfree (asm_lines[i].addr_string); xfree (asm_lines[i].insn); } return new_low; }
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; }
struct compile_module * compile_object_load (const char *object_file, const char *source_file) { struct cleanup *cleanups, *cleanups_free_objfile; bfd *abfd; struct setup_sections_data setup_sections_data; CORE_ADDR addr, func_addr, regs_addr; 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; char *filename, **matching; struct objfile *objfile; 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; 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); bmsym = lookup_minimal_symbol_text (GCC_FE_WRAPPER_FUNCTION, objfile); if (bmsym.minsym == NULL || MSYMBOL_TYPE (bmsym.minsym) == mst_file_text) error (_("Could not find symbol \"%s\" of compiled module \"%s\"."), GCC_FE_WRAPPER_FUNCTION, filename); func_addr = BMSYMBOL_VALUE_ADDRESS (bmsym); /* 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; if (compile_debug) fprintf_unfiltered (gdb_stdout, "lookup undefined ELF symbol \"%s\"\n", sym->name); sym->flags = BSF_GLOBAL; sym->section = bfd_abs_section_ptr; if (strcmp (sym->name, "_GLOBAL_OFFSET_TABLE_") == 0) { 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); 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 (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); store_regs (regs_type, regs_addr); } discard_cleanups (cleanups_free_objfile); do_cleanups (cleanups); retval = xmalloc (sizeof (*retval)); retval->objfile = objfile; retval->source_file = xstrdup (source_file); retval->func_addr = func_addr; retval->regs_addr = regs_addr; return retval; }
int find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, int *is_gnu_ifunc_p) { struct obj_section *section; struct symbol *f; struct bound_minimal_symbol msymbol; struct symtab *symtab = NULL; struct objfile *objfile; int i; CORE_ADDR mapped_pc; /* To ensure that the symbol returned belongs to the correct setion (and that the last [random] symbol from the previous section isn't returned) try to find the section containing PC. First try the overlay code (which by default returns NULL); and second try the normal section code (which almost always succeeds). */ section = find_pc_overlay (pc); if (section == NULL) section = find_pc_section (pc); mapped_pc = overlay_mapped_address (pc, section); if (mapped_pc >= cache_pc_function_low && mapped_pc < cache_pc_function_high && section == cache_pc_function_section) goto return_cached_value; msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section); ALL_OBJFILES (objfile) { if (objfile->sf) symtab = objfile->sf->qf->find_pc_sect_symtab (objfile, msymbol, mapped_pc, section, 0); if (symtab) break; } if (symtab) { /* Checking whether the msymbol has a larger value is for the "pathological" case mentioned in print_frame_info. */ f = find_pc_sect_function (mapped_pc, section); if (f != NULL && (msymbol.minsym == NULL || (BLOCK_START (SYMBOL_BLOCK_VALUE (f)) >= BMSYMBOL_VALUE_ADDRESS (msymbol)))) { cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f)); cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f)); cache_pc_function_name = SYMBOL_LINKAGE_NAME (f); cache_pc_function_section = section; cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f)); goto return_cached_value; } } /* Not in the normal symbol tables, see if the pc is in a known section. If it's not, then give up. This ensures that anything beyond the end of the text seg doesn't appear to be part of the last function in the text segment. */ if (!section) msymbol.minsym = NULL; /* Must be in the minimal symbol table. */ if (msymbol.minsym == NULL) { /* No available symbol. */ if (name != NULL) *name = 0; if (address != NULL) *address = 0; if (endaddr != NULL) *endaddr = 0; if (is_gnu_ifunc_p != NULL) *is_gnu_ifunc_p = 0; return 0; } cache_pc_function_low = BMSYMBOL_VALUE_ADDRESS (msymbol); cache_pc_function_name = MSYMBOL_LINKAGE_NAME (msymbol.minsym); cache_pc_function_section = section; cache_pc_function_is_gnu_ifunc = (MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc); cache_pc_function_high = minimal_symbol_upper_bound (msymbol); return_cached_value: if (address) { if (pc_in_unmapped_range (pc, section)) *address = overlay_unmapped_address (cache_pc_function_low, section); else *address = cache_pc_function_low; } if (name) *name = cache_pc_function_name; if (endaddr) { if (pc_in_unmapped_range (pc, section)) { /* Because the high address is actually beyond the end of the function (and therefore possibly beyond the end of the overlay), we must actually convert (high - 1) and then add one to that. */ *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1, section); } else *endaddr = cache_pc_function_high; } if (is_gnu_ifunc_p) *is_gnu_ifunc_p = cache_pc_function_is_gnu_ifunc; return 1; }
static CORE_ADDR ft32_analyze_prologue (CORE_ADDR start_addr, CORE_ADDR end_addr, struct ft32_frame_cache *cache, struct gdbarch *gdbarch) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); CORE_ADDR next_addr; ULONGEST inst; int regnum, pushreg; struct bound_minimal_symbol msymbol; const int first_saved_reg = 13; /* The first saved register. */ /* PROLOGS are addresses of the subroutine prologs, PROLOGS[n] is the address of __prolog_$rN. __prolog_$rN pushes registers from 13 through n inclusive. So for example CALL __prolog_$r15 is equivalent to: PUSH $r13 PUSH $r14 PUSH $r15 Note that PROLOGS[0] through PROLOGS[12] are unused. */ CORE_ADDR prologs[32]; cache->saved_regs[FT32_PC_REGNUM] = 0; cache->framesize = 0; for (regnum = first_saved_reg; regnum < 32; regnum++) { char prolog_symbol[32]; snprintf (prolog_symbol, sizeof (prolog_symbol), "__prolog_$r%02d", regnum); msymbol = lookup_minimal_symbol (prolog_symbol, NULL, NULL); if (msymbol.minsym) prologs[regnum] = BMSYMBOL_VALUE_ADDRESS (msymbol); else prologs[regnum] = 0; } if (start_addr >= end_addr) return end_addr; cache->established = 0; for (next_addr = start_addr; next_addr < end_addr;) { inst = read_memory_unsigned_integer (next_addr, 4, byte_order); if (FT32_IS_PUSH (inst)) { pushreg = FT32_PUSH_REG (inst); cache->framesize += 4; cache->saved_regs[FT32_R0_REGNUM + pushreg] = cache->framesize; next_addr += 4; } else if (FT32_IS_CALL (inst)) { for (regnum = first_saved_reg; regnum < 32; regnum++) { if ((4 * (inst & 0x3ffff)) == prologs[regnum]) { for (pushreg = first_saved_reg; pushreg <= regnum; pushreg++) { cache->framesize += 4; cache->saved_regs[FT32_R0_REGNUM + pushreg] = cache->framesize; } next_addr += 4; } } break; } else break; } for (regnum = FT32_R0_REGNUM; regnum < FT32_PC_REGNUM; regnum++) { if (cache->saved_regs[regnum] != REG_UNAVAIL) cache->saved_regs[regnum] = cache->framesize - cache->saved_regs[regnum]; } cache->saved_regs[FT32_PC_REGNUM] = cache->framesize; /* It is a LINK? */ if (next_addr < end_addr) { inst = read_memory_unsigned_integer (next_addr, 4, byte_order); if (FT32_IS_LINK (inst)) { cache->established = 1; for (regnum = FT32_R0_REGNUM; regnum < FT32_PC_REGNUM; regnum++) { if (cache->saved_regs[regnum] != REG_UNAVAIL) cache->saved_regs[regnum] += 4; } cache->saved_regs[FT32_PC_REGNUM] = cache->framesize + 4; cache->saved_regs[FT32_FP_REGNUM] = 0; cache->framesize += FT32_LINK_SIZE (inst); next_addr += 4; } } return next_addr; }
static int add_pe_forwarded_sym (minimal_symbol_reader &reader, const char *sym_name, const char *forward_dll_name, const char *forward_func_name, int ordinal, const char *dll_name, struct objfile *objfile) { CORE_ADDR vma, baseaddr; struct bound_minimal_symbol msymbol; enum minimal_symbol_type msymtype; char *qualified_name, *bare_name; int forward_dll_name_len = strlen (forward_dll_name); int forward_func_name_len = strlen (forward_func_name); int forward_len = forward_dll_name_len + forward_func_name_len + 2; char *forward_qualified_name = (char *) alloca (forward_len); short section; xsnprintf (forward_qualified_name, forward_len, "%s!%s", forward_dll_name, forward_func_name); msymbol = lookup_minimal_symbol_and_objfile (forward_qualified_name); if (!msymbol.minsym) { int i; for (i = 0; i < forward_dll_name_len; i++) forward_qualified_name[i] = tolower (forward_qualified_name[i]); msymbol = lookup_minimal_symbol_and_objfile (forward_qualified_name); } if (!msymbol.minsym) { if (debug_coff_pe_read) fprintf_unfiltered (gdb_stdlog, _("Unable to find function \"%s\" in" " dll \"%s\", forward of \"%s\" in dll \"%s\"\n"), forward_func_name, forward_dll_name, sym_name, dll_name); return 0; } if (debug_coff_pe_read > 1) fprintf_unfiltered (gdb_stdlog, _("Adding forwarded exported symbol" " \"%s\" in dll \"%s\", pointing to \"%s\"\n"), sym_name, dll_name, forward_qualified_name); vma = BMSYMBOL_VALUE_ADDRESS (msymbol); msymtype = MSYMBOL_TYPE (msymbol.minsym); section = MSYMBOL_SECTION (msymbol.minsym); /* Generate a (hopefully unique) qualified name using the first part of the dll name, e.g. KERNEL32!AddAtomA. This matches the style used by windbg from the "Microsoft Debugging Tools for Windows". */ if (sym_name == NULL || *sym_name == '\0') bare_name = xstrprintf ("#%d", ordinal); else bare_name = xstrdup (sym_name); qualified_name = xstrprintf ("%s!%s", dll_name, bare_name); /* Note that this code makes a minimal symbol whose value may point outside of any section in this objfile. These symbols can't really be relocated properly, but nevertheless we make a stab at it, choosing an approach consistent with the history of this code. */ baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); reader.record_with_info (qualified_name, vma - baseaddr, msymtype, section); /* Enter the plain name as well, which might not be unique. */ reader.record_with_info (bare_name, vma - baseaddr, msymtype, section); xfree (qualified_name); xfree (bare_name); return 1; }
int find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block) { struct obj_section *section; struct symbol *f; struct bound_minimal_symbol msymbol; struct compunit_symtab *compunit_symtab = NULL; CORE_ADDR mapped_pc; /* To ensure that the symbol returned belongs to the correct setion (and that the last [random] symbol from the previous section isn't returned) try to find the section containing PC. First try the overlay code (which by default returns NULL); and second try the normal section code (which almost always succeeds). */ section = find_pc_overlay (pc); if (section == NULL) section = find_pc_section (pc); mapped_pc = overlay_mapped_address (pc, section); if (mapped_pc >= cache_pc_function_low && mapped_pc < cache_pc_function_high && section == cache_pc_function_section) goto return_cached_value; msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section); for (objfile *objfile : current_program_space->objfiles ()) { if (objfile->sf) { compunit_symtab = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, mapped_pc, section, 0); } if (compunit_symtab != NULL) break; } if (compunit_symtab != NULL) { /* Checking whether the msymbol has a larger value is for the "pathological" case mentioned in stack.c:find_frame_funname. We use BLOCK_ENTRY_PC instead of BLOCK_START_PC for this comparison because the minimal symbol should refer to the function's entry pc which is not necessarily the lowest address of the function. This will happen when the function has more than one range and the entry pc is not within the lowest range of addresses. */ f = find_pc_sect_function (mapped_pc, section); if (f != NULL && (msymbol.minsym == NULL || (BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (f)) >= BMSYMBOL_VALUE_ADDRESS (msymbol)))) { const struct block *b = SYMBOL_BLOCK_VALUE (f); cache_pc_function_name = SYMBOL_LINKAGE_NAME (f); cache_pc_function_section = section; cache_pc_function_block = b; /* For blocks occupying contiguous addresses (i.e. no gaps), the low and high cache addresses are simply the start and end of the block. For blocks with non-contiguous ranges, we have to search for the range containing mapped_pc and then use the start and end of that range. This causes the returned *ADDRESS and *ENDADDR values to be limited to the range in which mapped_pc is found. See comment preceding declaration of find_pc_partial_function in symtab.h for more information. */ if (BLOCK_CONTIGUOUS_P (b)) { cache_pc_function_low = BLOCK_START (b); cache_pc_function_high = BLOCK_END (b); } else { int i; for (i = 0; i < BLOCK_NRANGES (b); i++) { if (BLOCK_RANGE_START (b, i) <= mapped_pc && mapped_pc < BLOCK_RANGE_END (b, i)) { cache_pc_function_low = BLOCK_RANGE_START (b, i); cache_pc_function_high = BLOCK_RANGE_END (b, i); break; } } /* Above loop should exit via the break. */ gdb_assert (i < BLOCK_NRANGES (b)); } goto return_cached_value; } } /* Not in the normal symbol tables, see if the pc is in a known section. If it's not, then give up. This ensures that anything beyond the end of the text seg doesn't appear to be part of the last function in the text segment. */ if (!section) msymbol.minsym = NULL; /* Must be in the minimal symbol table. */ if (msymbol.minsym == NULL) { /* No available symbol. */ if (name != NULL) *name = 0; if (address != NULL) *address = 0; if (endaddr != NULL) *endaddr = 0; return 0; } cache_pc_function_low = BMSYMBOL_VALUE_ADDRESS (msymbol); cache_pc_function_name = MSYMBOL_LINKAGE_NAME (msymbol.minsym); cache_pc_function_section = section; cache_pc_function_high = minimal_symbol_upper_bound (msymbol); cache_pc_function_block = nullptr; return_cached_value: if (address) { if (pc_in_unmapped_range (pc, section)) *address = overlay_unmapped_address (cache_pc_function_low, section); else *address = cache_pc_function_low; } if (name) *name = cache_pc_function_name; if (endaddr) { if (pc_in_unmapped_range (pc, section)) { /* Because the high address is actually beyond the end of the function (and therefore possibly beyond the end of the overlay), we must actually convert (high - 1) and then add one to that. */ *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1, section); } else *endaddr = cache_pc_function_high; } if (block != nullptr) *block = cache_pc_function_block; return 1; }