static void hpux_thread_new_objfile (struct objfile *objfile) { struct minimal_symbol *ms; if (!objfile) { hpux_thread_active = 0; return; } ms = lookup_minimal_symbol ("cma__g_known_threads", NULL, objfile); if (!ms) return; P_cma__g_known_threads = SYMBOL_VALUE_ADDRESS (ms); ms = lookup_minimal_symbol ("cma__g_current_thread", NULL, objfile); if (!ms) return; P_cma__g_current_thread = SYMBOL_VALUE_ADDRESS (ms); hpux_thread_active = 1; }
CORE_ADDR tui_get_begin_asm_address (void) { struct tui_gen_win_info * locator; struct tui_locator_element * element; CORE_ADDR addr; locator = tui_locator_win_info_ptr (); element = &((struct tui_win_element *) locator->content[0])->which_element.locator; if (element->addr == 0) { struct 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 == 0) main_symbol = lookup_minimal_symbol ("MAIN", NULL, NULL); if (main_symbol == 0) main_symbol = lookup_minimal_symbol ("_start", NULL, NULL); if (main_symbol) addr = SYMBOL_VALUE_ADDRESS (main_symbol); else addr = 0; } else /* the target is executing */ addr = element->addr; return addr; }
CORE_ADDR lookup_child_selector (struct gdbarch *gdbarch, char *selname) { struct type *char_type = builtin_type (gdbarch)->builtin_char; struct value * function, *selstring; if (! target_has_execution) { /* Can't call into inferior to lookup selector. */ return 0; } if (lookup_minimal_symbol("sel_getUid", 0, 0).minsym) function = find_function_in_inferior("sel_getUid", NULL); else if (lookup_minimal_symbol ("sel_get_any_uid", 0, 0).minsym) function = find_function_in_inferior("sel_get_any_uid", NULL); else { complaint (&symfile_complaints, _("no way to lookup Objective-C selectors")); return 0; } selstring = value_coerce_array (value_string (selname, strlen (selname) + 1, char_type)); return value_as_long (call_function_by_hand (function, 1, &selstring)); }
/* 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 lookup_objc_class (struct gdbarch *gdbarch, char *classname) { struct type *char_type = builtin_type (gdbarch)->builtin_char; struct value * function, *classval; if (! target_has_execution) { /* Can't call into inferior to lookup class. */ return 0; } if (lookup_minimal_symbol("objc_lookUpClass", 0, 0).minsym) function = find_function_in_inferior("objc_lookUpClass", NULL); else if (lookup_minimal_symbol ("objc_lookup_class", 0, 0).minsym) function = find_function_in_inferior("objc_lookup_class", NULL); else { complaint (&symfile_complaints, _("no way to lookup Objective-C classes")); return 0; } classval = value_string (classname, strlen (classname) + 1, char_type); classval = value_coerce_array (classval); return (CORE_ADDR) value_as_long (call_function_by_hand (function, 1, &classval)); }
const char * pascal_main_name (void) { struct bound_minimal_symbol msym; msym = lookup_minimal_symbol (GPC_P_INITIALIZE, NULL, NULL); /* If '_p_initialize' was not found, the main program is likely not written in Pascal. */ if (msym.minsym == NULL) return NULL; msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_1, NULL, NULL); if (msym.minsym != NULL) { return GPC_MAIN_PROGRAM_NAME_1; } msym = lookup_minimal_symbol (GPC_MAIN_PROGRAM_NAME_2, NULL, NULL); if (msym.minsym != NULL) { return GPC_MAIN_PROGRAM_NAME_2; } /* No known entry procedure found, the main program is probably not compiled with GPC. */ return NULL; }
struct value * value_nsstring (struct gdbarch *gdbarch, char *ptr, int len) { struct type *char_type = builtin_type (gdbarch)->builtin_char; struct value *stringValue[3]; struct value *function, *nsstringValue; struct symbol *sym; struct type *type; if (!target_has_execution) return 0; /* Can't call into inferior to create NSString. */ stringValue[2] = value_string(ptr, len, char_type); stringValue[2] = value_coerce_array(stringValue[2]); /* _NSNewStringFromCString replaces "istr" after Lantern2A. */ if (lookup_minimal_symbol("_NSNewStringFromCString", 0, 0).minsym) { function = find_function_in_inferior("_NSNewStringFromCString", NULL); nsstringValue = call_function_by_hand(function, 1, &stringValue[2]); } else if (lookup_minimal_symbol("istr", 0, 0).minsym) { function = find_function_in_inferior("istr", NULL); nsstringValue = call_function_by_hand(function, 1, &stringValue[2]); } else if (lookup_minimal_symbol("+[NSString stringWithCString:]", 0, 0).minsym) { function = find_function_in_inferior("+[NSString stringWithCString:]", NULL); type = builtin_type (gdbarch)->builtin_long; stringValue[0] = value_from_longest (type, lookup_objc_class (gdbarch, "NSString")); stringValue[1] = value_from_longest (type, lookup_child_selector (gdbarch, "stringWithCString:")); nsstringValue = call_function_by_hand(function, 3, &stringValue[0]); } else error (_("NSString: internal error -- no way to create new NSString")); sym = lookup_struct_typedef("NSString", 0, 1); if (sym == NULL) sym = lookup_struct_typedef("NXString", 0, 1); if (sym == NULL) type = builtin_type (gdbarch)->builtin_data_ptr; else type = lookup_pointer_type(SYMBOL_TYPE (sym)); deprecated_set_value_type (nsstringValue, type); return nsstringValue; }
int agent_look_up_symbols (void *arg) { int i; all_agent_symbols_looked_up = 0; for (i = 0; i < sizeof (symbol_list) / sizeof (symbol_list[0]); i++) { CORE_ADDR *addrp = (CORE_ADDR *) ((char *) &ipa_sym_addrs + symbol_list[i].offset); #ifdef GDBSERVER if (look_up_one_symbol (symbol_list[i].name, addrp, 1) == 0) #else struct minimal_symbol *sym = lookup_minimal_symbol (symbol_list[i].name, NULL, (struct objfile *) arg); if (sym != NULL) *addrp = SYMBOL_VALUE_ADDRESS (sym); else #endif { DEBUG_AGENT ("symbol `%s' not found\n", symbol_list[i].name); return -1; } } all_agent_symbols_looked_up = 1; return 0; }
CORE_ADDR glibc_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) { /* The GNU dynamic linker is part of the GNU C library, and is used by all GNU systems (GNU/Hurd, GNU/Linux). An unresolved PLT entry points to "_dl_runtime_resolve", which calls "fixup" to patch the PLT, and then passes control to the function. We look for the symbol `_dl_runtime_resolve', and find `fixup' in the same objfile. If we are at the entry point of `fixup', then we set a breakpoint at the return address (at the top of the stack), and continue. It's kind of gross to do all these checks every time we're called, since they don't change once the executable has gotten started. But this is only a temporary hack --- upcoming versions of GNU/Linux will provide a portable, efficient interface for debugging programs that use shared libraries. */ struct objfile *objfile; struct minimal_symbol *resolver = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile); if (resolver) { struct minimal_symbol *fixup = lookup_minimal_symbol ("fixup", NULL, objfile); if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc) return frame_pc_unwind (get_current_frame ()); } return 0; }
static int convert_code_addr_to_desc_addr (CORE_ADDR code_addr, CORE_ADDR *desc_addr) { struct obj_section *dot_fn_section; struct minimal_symbol *dot_fn; struct minimal_symbol *fn; CORE_ADDR toc; /* Find the minimal symbol that corresponds to CODE_ADDR (should have a name of the form ".FN"). */ dot_fn = lookup_minimal_symbol_by_pc (code_addr); if (dot_fn == NULL || SYMBOL_LINKAGE_NAME (dot_fn)[0] != '.') return 0; /* Get the section that contains CODE_ADDR. Need this for the "objfile" that it contains. */ dot_fn_section = find_pc_section (code_addr); if (dot_fn_section == NULL || dot_fn_section->objfile == NULL) return 0; /* Now find the corresponding "FN" (dropping ".") minimal symbol's address. Only look for the minimal symbol in ".FN"'s object file - avoids problems when two object files (i.e., shared libraries) contain a minimal symbol with the same name. */ fn = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL, dot_fn_section->objfile); if (fn == NULL) return 0; /* Found a descriptor. */ (*desc_addr) = SYMBOL_VALUE_ADDRESS (fn); return 1; }
static CORE_ADDR skip_hurd_resolver (CORE_ADDR pc) { /* The HURD dynamic linker is part of the GNU C library, so many GNU/Linux distributions use it. (All ELF versions, as far as I know.) An unresolved PLT entry points to "_dl_runtime_resolve", which calls "fixup" to patch the PLT, and then passes control to the function. We look for the symbol `_dl_runtime_resolve', and find `fixup' in the same objfile. If we are at the entry point of `fixup', then we set a breakpoint at the return address (at the top of the stack), and continue. It's kind of gross to do all these checks every time we're called, since they don't change once the executable has gotten started. But this is only a temporary hack --- upcoming versions of GNU/Linux will provide a portable, efficient interface for debugging programs that use shared libraries. */ struct objfile *objfile; struct minimal_symbol *resolver = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile); if (resolver) { struct minimal_symbol *fixup = lookup_minimal_symbol ("fixup", NULL, objfile); if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc) return (SAVED_PC_AFTER_CALL (get_current_frame ())); } return 0; }
static void enable_dec_thread (void) { struct minimal_symbol *msym; void* caller_context; int status; /* If already active, nothing more to do. */ if (dec_thread_active) return; msym = lookup_minimal_symbol ("__pthread_dbg_symtable", NULL, NULL); if (msym == NULL) { debug ("enable_dec_thread: No __pthread_dbg_symtable"); return; } status = pthreadDebugContextInit (&caller_context, &debug_callbacks, (void *) SYMBOL_VALUE_ADDRESS (msym), &debug_context); if (status != ESUCCESS) { debug ("enable_dec_thread: pthreadDebugContextInit -> %d", status); return; } push_target (&dec_thread_ops); dec_thread_active = 1; debug ("enable_dec_thread: Thread support enabled."); }
/* Use inferior's dlopen() to bring in some helper functions: */ void load_helpers(void) { struct value *dlfn, *args[2], *val; long rslt; args[0] = value_string(LIBCHECKPOINT_NAME, (strlen(LIBCHECKPOINT_NAME) + 1UL)); args[0] = value_coerce_array(args[0]); args[1] = value_from_longest(builtin_type_int, (LONGEST)RTLD_NOW); if (lookup_minimal_symbol("dlopen", 0, 0) && (dlfn = find_function_in_inferior("dlopen", builtin_type_int))) { val = call_function_by_hand_expecting_type(dlfn, builtin_type_int, 2, args, 1); rslt = (long)value_as_long(val); if (rslt == 0) warning("dlopen of checkpoint library returned NULL"); } else { warning("dlopen not found, libcheckpoint functions not loaded"); } }
/* 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; }
void gcc_convert_symbol (void *datum, struct gcc_c_context *gcc_context, enum gcc_c_oracle_request request, const char *identifier) { struct compile_c_instance *context = datum; domain_enum domain; int found = 0; switch (request) { case GCC_C_ORACLE_SYMBOL: domain = VAR_DOMAIN; break; case GCC_C_ORACLE_TAG: domain = STRUCT_DOMAIN; break; case GCC_C_ORACLE_LABEL: domain = LABEL_DOMAIN; break; default: gdb_assert_not_reached ("Unrecognized oracle request."); } /* We can't allow exceptions to escape out of this callback. Safest is to simply emit a gcc error. */ TRY { struct symbol *sym; sym = lookup_symbol (identifier, context->base.block, domain, NULL); if (sym != NULL) { convert_symbol_sym (context, identifier, sym, domain); found = 1; } else if (domain == VAR_DOMAIN) { struct bound_minimal_symbol bmsym; bmsym = lookup_minimal_symbol (identifier, NULL, NULL); if (bmsym.minsym != NULL) { convert_symbol_bmsym (context, bmsym); found = 1; } } } CATCH (e, RETURN_MASK_ALL) { C_CTX (context)->c_ops->error (C_CTX (context), e.message); }
static CORE_ADDR mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) { struct minimal_symbol *resolver; resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL); if (resolver && SYMBOL_VALUE_ADDRESS (resolver) == pc) return frame_unwind_caller_pc (get_current_frame ()); return glibc_skip_solib_resolver (gdbarch, 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; }
const char * d_main_name (void) { struct bound_minimal_symbol msym; msym = lookup_minimal_symbol (D_MAIN, NULL, NULL); if (msym.minsym != NULL) return D_MAIN; /* No known entry procedure found, the main program is probably not D. */ return NULL; }
static int kgdb_resolve_symbol(const char *name, kvaddr_t *kva) { struct minimal_symbol *ms; ms = lookup_minimal_symbol (name, NULL, NULL); if (ms == NULL) return (1); *kva = SYMBOL_VALUE_ADDRESS (ms); return (0); }
static bfd_vma call_target_sbrk (int sbrk_arg) { struct objfile *sbrk_objf; struct gdbarch *gdbarch; bfd_vma top_of_heap; struct value *target_sbrk_arg; struct value *sbrk_fn, *ret; bfd_vma tmp; if (lookup_minimal_symbol ("sbrk", NULL, NULL) != NULL) { sbrk_fn = find_function_in_inferior ("sbrk", &sbrk_objf); if (sbrk_fn == NULL) return (bfd_vma) 0; } else if (lookup_minimal_symbol ("_sbrk", NULL, NULL) != NULL) { sbrk_fn = find_function_in_inferior ("_sbrk", &sbrk_objf); if (sbrk_fn == NULL) return (bfd_vma) 0; } else return (bfd_vma) 0; gdbarch = get_objfile_arch (sbrk_objf); target_sbrk_arg = value_from_longest (builtin_type (gdbarch)->builtin_int, sbrk_arg); gdb_assert (target_sbrk_arg); ret = call_function_by_hand (sbrk_fn, 1, &target_sbrk_arg); if (ret == NULL) return (bfd_vma) 0; tmp = value_as_long (ret); if ((LONGEST) tmp <= 0 || (LONGEST) tmp == 0xffffffff) return (bfd_vma) 0; top_of_heap = tmp; return top_of_heap; }
static void som_solib_create_inferior_hook (int from_tty) { enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); struct minimal_symbol *msymbol; unsigned int dld_flags, status, have_endo; asection *shlib_info; char buf[4]; CORE_ADDR anaddr; /* First, remove all the solib event breakpoints. Their addresses may have changed since the last time we ran the program. */ remove_solib_event_breakpoints (); 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 == NULL) goto keep_going; anaddr = SYMBOL_VALUE_ADDRESS (msymbol); store_unsigned_integer (buf, 4, byte_order, PIDGET (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; }
ps_err_e ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, const char *name, paddr_t *sym_addr) { struct minimal_symbol *ms; /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */ ms = lookup_minimal_symbol (name, NULL, NULL); if (ms == NULL) return PS_NOSYM; *sym_addr = SYMBOL_VALUE_ADDRESS (ms); return PS_OK; }
ps_err_e ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj, const char *name, psaddr_t *sym_addr) { struct minimal_symbol *ms; CORE_ADDR addr; ms = lookup_minimal_symbol (name, NULL, NULL); if (ms == NULL) return PS_NOSYM; *sym_addr = SYMBOL_VALUE_ADDRESS (ms); return PS_OK; }
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 = &((struct tui_win_element *) locator->content[0])->which_element.locator; if (element->addr == 0) { struct 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 == 0) main_symbol = lookup_minimal_symbol ("MAIN", NULL, NULL); if (main_symbol == 0) main_symbol = lookup_minimal_symbol ("_start", NULL, NULL); if (main_symbol) addr = SYMBOL_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 (struct ps_prochandle *ph, const char *obj, const char *name, psaddr_t *sym_addr) { struct minimal_symbol *ms; CORE_ADDR addr; ms = lookup_minimal_symbol (name, NULL, NULL); if (ms == NULL) return PS_NOSYM; addr = SYMBOL_VALUE_ADDRESS (ms); store_typed_address(sym_addr, builtin_type_void_data_ptr, addr); return PS_OK; }
ps_err_e ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *ld_object_name, const char *ld_symbol_name, gdb_ps_addr_t * ld_symbol_addr) { struct minimal_symbol *ms; ms = lookup_minimal_symbol (ld_symbol_name, NULL, NULL); if (!ms) return PS_NOSYM; *ld_symbol_addr = SYMBOL_VALUE_ADDRESS (ms); return PS_OK; }
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; }