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)); }
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)); }
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; }
/* 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"); } }
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 int derive_heap_segment (bfd *abfd, bfd_vma *bottom, bfd_vma *top) { bfd_vma top_of_data_memory = 0; bfd_vma top_of_heap = 0; bfd_size_type sec_size; struct value *zero, *sbrk; bfd_vma sec_vaddr; asection *sec; gdb_assert (bottom); gdb_assert (top); /* This function depends on being able to call a function in the inferior. */ if (!target_has_execution) return 0; /* The following code assumes that the link map is arranged as follows (low to high addresses): --------------------------------- | text sections | --------------------------------- | data sections (including bss) | --------------------------------- | heap | --------------------------------- */ for (sec = abfd->sections; sec; sec = sec->next) { if (bfd_get_section_flags (abfd, sec) & SEC_DATA || strcmp (".bss", bfd_section_name (abfd, sec)) == 0) { sec_vaddr = bfd_get_section_vma (abfd, sec); sec_size = bfd_get_section_size (sec); if (sec_vaddr + sec_size > top_of_data_memory) top_of_data_memory = sec_vaddr + sec_size; } } /* Now get the top-of-heap by calling sbrk in the inferior. */ if (lookup_minimal_symbol ("sbrk", NULL, NULL) != NULL) { sbrk = find_function_in_inferior ("sbrk"); if (sbrk == NULL) return 0; } else if (lookup_minimal_symbol ("_sbrk", NULL, NULL) != NULL) { sbrk = find_function_in_inferior ("_sbrk"); if (sbrk == NULL) return 0; } else return 0; zero = value_from_longest (builtin_type_int, 0); gdb_assert (zero); sbrk = call_function_by_hand (sbrk, 1, &zero); if (sbrk == NULL) return 0; top_of_heap = value_as_long (sbrk); /* Return results. */ if (top_of_heap > top_of_data_memory) { *bottom = top_of_data_memory; *top = top_of_heap; return 1; } /* No additional heap space needs to be saved. */ return 0; }