void ppc_print_boundaries (ppc_function_boundaries * bounds) { if (bounds->prologue_start != INVALID_ADDRESS) { printf_filtered (" The function prologue begins at 0x%s.\n", paddr_nz (bounds->prologue_start)); } if (bounds->body_start != INVALID_ADDRESS) { printf_filtered (" The function body begins at 0x%s.\n", paddr_nz (bounds->body_start)); } if (bounds->epilogue_start != INVALID_ADDRESS) { printf_filtered (" The function epilogue begins at 0x%s.\n", paddr_nz (bounds->epilogue_start)); } if (bounds->function_end != INVALID_ADDRESS) { printf_filtered (" The function ends at 0x%s.\n", paddr_nz (bounds->function_end)); } }
static int gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, struct mem_attrib *attrib, struct target_ops *target) { if (!program_loaded) error ("No program loaded."); if (sr_get_debug ()) { /* FIXME: Send to something other than STDOUT? */ printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x"); gdb_print_host_address (myaddr, gdb_stdout); printf_filtered (", memaddr 0x%s, len %d, write %d\n", paddr_nz (memaddr), len, write); if (sr_get_debug () && write) dump_mem (myaddr, len); } if (write) { len = sim_write (gdbsim_desc, memaddr, myaddr, len); } else { len = sim_read (gdbsim_desc, memaddr, myaddr, len); if (sr_get_debug () && len > 0) dump_mem (myaddr, len); } return len; }
static int gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read, int write, int exec, void *data) { bfd *obfd = data; asection *osec; flagword flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD; /* If the memory segment has no permissions set, ignore it, otherwise when we later try to access it for read/write, we'll get an error or jam the kernel. */ if (read == 0 && write == 0 && exec == 0) { if (info_verbose) { fprintf_filtered (gdb_stdout, "Ignore segment, %s bytes at 0x%s\n", paddr_d (size), paddr_nz (vaddr)); } return 0; } if (write == 0) { /* See if this region of memory lies inside a known file on disk. If so, we can avoid copying its contents by clearing SEC_LOAD. */ struct objfile *objfile; struct obj_section *objsec; ALL_OBJSECTIONS (objfile, objsec) { bfd *abfd = objfile->obfd; asection *asec = objsec->the_bfd_section; bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd, asec); bfd_vma start = objsec->addr & -align; bfd_vma end = (objsec->endaddr + align - 1) & -align; /* Match if either the entire memory region lies inside the section (i.e. a mapping covering some pages of a large segment) or the entire section lies inside the memory region (i.e. a mapping covering multiple small sections). This BFD was synthesized from reading target memory, we don't want to omit that. */ if (((vaddr >= start && vaddr + size <= end) || (start >= vaddr && end <= vaddr + size)) && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY)) { flags &= ~SEC_LOAD; flags |= SEC_NEVER_LOAD; goto keep; /* break out of two nested for loops */ } } keep: flags |= SEC_READONLY; }
/* FIXME: needs comment: */ static void scm_ipruk(const char *hdr, LONGEST ptr, struct ui_file *stream) { fprintf_filtered(stream, "#<unknown-%s", hdr); #define SCM_SIZE TYPE_LENGTH(builtin_type_scm) if (SCM_CELLP(ptr)) fprintf_filtered(stream, " (0x%lx . 0x%lx) @", (long)SCM_CAR(ptr), (long)SCM_CDR(ptr)); fprintf_filtered(stream, " 0x%s>", paddr_nz(ptr)); }
/* Print a natural-language description of SYMBOL to STREAM. */ static int locexpr_describe_location (struct symbol *symbol, struct ui_file *stream) { /* FIXME: be more extensive. */ struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol); int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); if (dlbaton->size == 1 && dlbaton->data[0] >= DW_OP_reg0 && dlbaton->data[0] <= DW_OP_reg31) { struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); struct gdbarch *gdbarch = get_objfile_arch (objfile); int regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, dlbaton->data[0] - DW_OP_reg0); fprintf_filtered (stream, "a variable in register %s", gdbarch_register_name (gdbarch, regno)); return 1; } /* The location expression for a TLS variable looks like this (on a 64-bit LE machine): DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address) 0x3 is the encoding for DW_OP_addr, which has an operand as long as the size of an address on the target machine (here is 8 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address. The operand represents the offset at which the variable is within the thread local storage. */ if (dlbaton->size > 1 && dlbaton->data[dlbaton->size - 1] == DW_OP_GNU_push_tls_address) if (dlbaton->data[0] == DW_OP_addr) { struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); struct gdbarch *gdbarch = get_objfile_arch (objfile); CORE_ADDR offset = dwarf2_read_address (gdbarch, &dlbaton->data[1], &dlbaton->data[dlbaton->size - 1], addr_size); fprintf_filtered (stream, "a thread-local variable at offset %s in the " "thread-local storage for `%s'", paddr_nz (offset), objfile->name); return 1; } fprintf_filtered (stream, "a variable with complex or multiple locations (DWARF2)"); return 1; }
int fbsd_find_memory_regions (int (*func) (CORE_ADDR, unsigned long, int, int, int, void *), void *obfd) { pid_t pid = ptid_get_pid (inferior_ptid); char *mapfilename; FILE *mapfile; unsigned long start, end, size; char protection[4]; int read, write, exec; struct cleanup *cleanup; mapfilename = xstrprintf ("/proc/%ld/map", (long) pid); cleanup = make_cleanup (xfree, mapfilename); mapfile = fopen (mapfilename, "r"); if (mapfile == NULL) error (_("Couldn't open %s."), mapfilename); make_cleanup_fclose (mapfile); if (info_verbose) fprintf_filtered (gdb_stdout, "Reading memory regions from %s\n", mapfilename); /* Now iterate until end-of-file. */ while (fbsd_read_mapping (mapfile, &start, &end, &protection[0])) { size = end - start; read = (strchr (protection, 'r') != 0); write = (strchr (protection, 'w') != 0); exec = (strchr (protection, 'x') != 0); if (info_verbose) { fprintf_filtered (gdb_stdout, "Save segment, %ld bytes at 0x%s (%c%c%c)\n", size, paddr_nz (start), read ? 'r' : '-', write ? 'w' : '-', exec ? 'x' : '-'); } /* Invoke the callback function to create the corefile segment. */ func (start, size, read, write, exec, obfd); } do_cleanups (cleanup); return 0; }
static void udot_info (char *dummy1, int dummy2) { #if defined (KERNEL_U_SIZE) long udot_off; /* Offset into user struct */ int udot_val; /* Value from user struct at udot_off */ char mess[128]; /* For messages */ #endif if (!target_has_execution) { error (_("The program is not being run.")); } #if !defined (KERNEL_U_SIZE) /* Adding support for this command is easy. Typically you just add a routine, called "kernel_u_size" that returns the size of the user struct, to the appropriate *-nat.c file and then add to the native config file "#define KERNEL_U_SIZE kernel_u_size()" */ error (_("Don't know how large ``struct user'' is in this version of gdb.")); #else for (udot_off = 0; udot_off < KERNEL_U_SIZE; udot_off += sizeof (udot_val)) { if ((udot_off % 24) == 0) { if (udot_off > 0) { printf_filtered ("\n"); } printf_filtered ("%s:", paddr (udot_off)); } udot_val = ptrace (PT_READ_U, PIDGET (inferior_ptid), (PTRACE_TYPE_ARG3) udot_off, 0); if (errno != 0) { sprintf (mess, "\nreading user struct at offset 0x%s", paddr_nz (udot_off)); perror_with_name (mess); } /* Avoid using nonportable (?) "*" in print specs */ printf_filtered (sizeof (int) == 4 ? " 0x%08x" : " 0x%16x", udot_val); } printf_filtered ("\n"); #endif }
void win32_xfer_shared_library (const char* so_name, CORE_ADDR load_addr, struct obstack *obstack) { char *p; obstack_grow_str (obstack, "<library name=\""); p = xml_escape_text (so_name); obstack_grow_str (obstack, p); xfree (p); obstack_grow_str (obstack, "\"><segment address=\"0x"); /* The symbols in a dll are offset by 0x1000, which is the the offset from 0 of the first byte in an image - because of the file header and the section alignment. */ p = paddr_nz (load_addr + 0x1000); obstack_grow_str (obstack, p); obstack_grow_str (obstack, "\"/></library>"); }
static int gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write, struct mem_attrib *attrib, struct target_ops *target) { /* If no program is running yet, then ignore the simulator for memory. Pass the request down to the next target, hopefully an exec file. */ if (!target_has_execution) return 0; if (!program_loaded) error (_("No program loaded.")); if (sr_get_debug ()) { /* FIXME: Send to something other than STDOUT? */ printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x"); gdb_print_host_address (myaddr, gdb_stdout); printf_filtered (", memaddr 0x%s, len %d, write %d\n", paddr_nz (memaddr), len, write); if (sr_get_debug () && write) dump_mem (myaddr, len); } if (write) { len = sim_write (gdbsim_desc, memaddr, myaddr, len); } else { len = sim_read (gdbsim_desc, memaddr, myaddr, len); if (sr_get_debug () && len > 0) dump_mem (myaddr, len); } return len; }
void ppc_print_properties (ppc_function_properties * props) { if (props->frameless) { printf_filtered (" No stack frame has been allocated.\n"); } else { printf_filtered (" A stack frame has been allocated.\n"); } if (props->frameptr_reg >= 0) { printf_filtered (" The stack pointer has been saved by alloca() in r%d.\n", props->frameptr_reg); } if (props->offset < 0) { printf_filtered (" No registers have been saved.\n"); } else { if (props->offset >= 0) { printf_filtered (" %d bytes of integer and floating-point registers have been saved:\n", props->offset); printf_filtered (" 0x%s is the stack setup address.\n", paddr_nz (props->stack_offset_pc)); } if (props->saved_gpr >= 0) { printf_filtered (" General-purpose registers r%d--r%d have been saved at offset 0x%x.\n", props->saved_gpr, 31, props->gpr_offset); } else { printf_filtered (" No general-purpose registers have been saved.\n"); } if (props->saved_fpr >= 0) { printf_filtered (" Floating-point registers r%d--r%d have been saved at offset 0x%x.\n", props->saved_fpr, 31, props->fpr_offset); } else { printf_filtered (" No floating-point registers have been saved.\n"); } } if (props->lr_saved) { printf_filtered (" The link register has been saved at offset 0x%x.\n", props->lr_offset); } else { if (props->lr_invalid != 0) printf_filtered (" The link register is still valid.\n"); else if (props->lr_reg > -1) printf_filtered (" The link register is stored in r%d.\n", props->lr_reg); else printf_filtered (" I have no idea where the link register is stored.\n"); } if (props->cr_saved) { printf_filtered (" The condition register has been saved at offset 0x%x.\n", props->cr_offset); } }
void pef_load_library (const struct dyld_path_info *d, struct dyld_objfile_entry *e) { bfd *pbfd = NULL; bfd *sbfd = NULL; char *symname = NULL; asection *csection = NULL; asection *dsection = NULL; struct section_addr_info *addrs; unsigned int i = 0; pbfd = inferior_bfd (e->dyld_name, e->dyld_addr, e->dyld_slide, e->dyld_length); if (strcmp (bfd_get_target (pbfd), "pef-xlib") == 0) { return; } if (strcmp (bfd_get_target (pbfd), "pef") != 0) { warning ("Unable to read symbols from %s: invalid file format \"%s\".", bfd_get_filename (pbfd), bfd_get_target (pbfd)); return; } csection = bfd_get_section_by_name (pbfd, "code"); if (csection == NULL) { warning ("Unable to find 'code' section in pef container \"%s\" at address 0x%s for 0x%lx", e->dyld_name, paddr_nz (e->dyld_addr), (unsigned long) e->dyld_length); return; } dsection = bfd_get_section_by_name (pbfd, "packed-data"); if (dsection == NULL) { warning ("Unable to find 'packed-data' section in pef container \"%s\" at address 0x%s for 0x%lx", e->dyld_name, paddr_nz (e->dyld_addr), (unsigned long) e->dyld_length); return; } symname = xmalloc (strlen (e->dyld_name) + strlen (".xSYM") + 1); sprintf (symname, "%s%s", e->dyld_name, ".xSYM"); sbfd = bfd_openr (symname, "sym"); if (sbfd == NULL) { warning ("unable to open \"%s\": %s", symname, bfd_errmsg (bfd_get_error ())); } addrs = alloc_section_addr_info (bfd_count_sections (pbfd)); for (i = 0; i < addrs->num_sections; i++) { addrs->other[i].name = NULL; addrs->other[i].addr = e->dyld_addr; addrs->other[i].sectindex = 0; } addrs->addrs_are_offsets = 1; if (pbfd != NULL) { if (!bfd_check_format (pbfd, bfd_object)) { warning ("file \"%s\" is not a valid symbol file", pbfd->filename); } else { symbol_file_add_bfd_safe (pbfd, 0, addrs, 0, 0, 0, e->load_flag, 0, 0, NULL); } } addrs->other[0].name = "code"; addrs->other[0].addr = e->dyld_addr + csection->vma; addrs->other[0].sectindex = 0; addrs->other[1].name = "packed-data"; addrs->other[1].addr = e->dyld_addr + dsection->vma; addrs->other[1].sectindex = 1; for (i = 2; i < addrs->num_sections; i++) { addrs->other[i].name = NULL; addrs->other[i].addr = e->dyld_addr + csection->vma; addrs->other[i].sectindex = 0; } addrs->addrs_are_offsets = 1; if (sbfd != NULL) { if (!bfd_check_format (sbfd, bfd_object)) { warning ("file \"%s\" is not a valid symbol file", sbfd->filename); } else { symbol_file_add_bfd_safe (sbfd, 0, addrs, 0, 0, 0, e->load_flag, 0, 0, NULL); } } }
/* Print the contents of the target's AUXV on the specified file. */ int fprint_target_auxv (struct ui_file *file, struct target_ops *ops) { CORE_ADDR type, val; gdb_byte *data; int len = target_auxv_read (ops, &data); gdb_byte *ptr = data; int ents = 0; if (len <= 0) return len; while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0) { extern int addressprint; const char *name = "???"; const char *description = ""; enum { dec, hex, str } flavor = hex; switch (type) { #define TAG(tag, text, kind) \ case tag: name = #tag; description = text; flavor = kind; break TAG (AT_NULL, _("End of vector"), hex); TAG (AT_IGNORE, _("Entry should be ignored"), hex); TAG (AT_EXECFD, _("File descriptor of program"), dec); TAG (AT_PHDR, _("Program headers for program"), hex); TAG (AT_PHENT, _("Size of program header entry"), dec); TAG (AT_PHNUM, _("Number of program headers"), dec); TAG (AT_PAGESZ, _("System page size"), dec); TAG (AT_BASE, _("Base address of interpreter"), hex); TAG (AT_FLAGS, _("Flags"), hex); TAG (AT_ENTRY, _("Entry point of program"), hex); TAG (AT_NOTELF, _("Program is not ELF"), dec); TAG (AT_UID, _("Real user ID"), dec); TAG (AT_EUID, _("Effective user ID"), dec); TAG (AT_GID, _("Real group ID"), dec); TAG (AT_EGID, _("Effective group ID"), dec); TAG (AT_CLKTCK, _("Frequency of times()"), dec); TAG (AT_PLATFORM, _("String identifying platform"), str); TAG (AT_HWCAP, _("Machine-dependent CPU capability hints"), hex); TAG (AT_FPUCW, _("Used FPU control word"), dec); TAG (AT_DCACHEBSIZE, _("Data cache block size"), dec); TAG (AT_ICACHEBSIZE, _("Instruction cache block size"), dec); TAG (AT_UCACHEBSIZE, _("Unified cache block size"), dec); TAG (AT_IGNOREPPC, _("Entry should be ignored"), dec); TAG (AT_SYSINFO, _("Special system info/entry points"), hex); TAG (AT_SYSINFO_EHDR, _("System-supplied DSO's ELF header"), hex); TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), dec); TAG (AT_SUN_UID, _("Effective user ID"), dec); TAG (AT_SUN_RUID, _("Real user ID"), dec); TAG (AT_SUN_GID, _("Effective group ID"), dec); TAG (AT_SUN_RGID, _("Real group ID"), dec); TAG (AT_SUN_LDELF, _("Dynamic linker's ELF header"), hex); TAG (AT_SUN_LDSHDR, _("Dynamic linker's section headers"), hex); TAG (AT_SUN_LDNAME, _("String giving name of dynamic linker"), str); TAG (AT_SUN_LPAGESZ, _("Large pagesize"), dec); TAG (AT_SUN_PLATFORM, _("Platform name string"), str); TAG (AT_SUN_HWCAP, _("Machine-dependent CPU capability hints"), hex); TAG (AT_SUN_IFLUSH, _("Should flush icache?"), dec); TAG (AT_SUN_CPU, _("CPU name string"), str); TAG (AT_SUN_EMUL_ENTRY, _("COFF entry point address"), hex); TAG (AT_SUN_EMUL_EXECFD, _("COFF executable file descriptor"), dec); TAG (AT_SUN_EXECNAME, _("Canonicalized file name given to execve"), str); TAG (AT_SUN_MMU, _("String for name of MMU module"), str); TAG (AT_SUN_LDDATA, _("Dynamic linker's data segment address"), hex); } fprintf_filtered (file, "%-4s %-20s %-30s ", paddr_d (type), name, description); switch (flavor) { case dec: fprintf_filtered (file, "%s\n", paddr_d (val)); break; case hex: fprintf_filtered (file, "0x%s\n", paddr_nz (val)); break; case str: if (addressprint) fprintf_filtered (file, "0x%s", paddr_nz (val)); val_print_string (val, -1, 1, file); fprintf_filtered (file, "\n"); break; } ++ents; } xfree (data); return ents; }
int java_value_print (struct value *val, struct ui_file *stream, int format, enum val_prettyprint pretty) { struct type *type; CORE_ADDR address; int i; char *name; type = VALUE_TYPE (val); address = VALUE_ADDRESS (val) + VALUE_OFFSET (val); if (is_object_type (type)) { CORE_ADDR obj_addr; /* Get the run-time type, and cast the object into that */ obj_addr = unpack_pointer (type, VALUE_CONTENTS (val)); if (obj_addr != 0) { type = type_from_class (java_class_from_object (val)); type = lookup_pointer_type (type); val = value_at (type, address, NULL); } } if (TYPE_CODE (type) == TYPE_CODE_PTR && !value_logical_not (val)) type_print (TYPE_TARGET_TYPE (type), "", stream, -1); name = TYPE_TAG_NAME (type); if (TYPE_CODE (type) == TYPE_CODE_STRUCT && name != NULL && (i = strlen (name), name[i - 1] == ']')) { char buf4[4]; long length; unsigned int things_printed = 0; int reps; struct type *el_type = java_primitive_type_from_name (name, i - 2); i = 0; read_memory (address + JAVA_OBJECT_SIZE, buf4, 4); length = (long) extract_signed_integer (buf4, 4); fprintf_filtered (stream, "{length: %ld", length); if (el_type == NULL) { CORE_ADDR element; CORE_ADDR next_element = -1; /* dummy initial value */ address += JAVA_OBJECT_SIZE + 4; /* Skip object header and length. */ while (i < length && things_printed < print_max) { char *buf; buf = alloca (TARGET_PTR_BIT / HOST_CHAR_BIT); fputs_filtered (", ", stream); wrap_here (n_spaces (2)); if (i > 0) element = next_element; else { read_memory (address, buf, sizeof (buf)); address += TARGET_PTR_BIT / HOST_CHAR_BIT; element = extract_address (buf, sizeof (buf)); } for (reps = 1; i + reps < length; reps++) { read_memory (address, buf, sizeof (buf)); address += TARGET_PTR_BIT / HOST_CHAR_BIT; next_element = extract_address (buf, sizeof (buf)); if (next_element != element) break; } if (reps == 1) fprintf_filtered (stream, "%d: ", i); else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); if (element == 0) fprintf_filtered (stream, "null"); else fprintf_filtered (stream, "@%s", paddr_nz (element)); things_printed++; i += reps; } } else { struct value *v = allocate_value (el_type); struct value *next_v = allocate_value (el_type); VALUE_ADDRESS (v) = address + JAVA_OBJECT_SIZE + 4; VALUE_ADDRESS (next_v) = VALUE_ADDRESS (v); while (i < length && things_printed < print_max) { fputs_filtered (", ", stream); wrap_here (n_spaces (2)); if (i > 0) { struct value *tmp; tmp = next_v; next_v = v; v = tmp; } else { VALUE_LAZY (v) = 1; VALUE_OFFSET (v) = 0; } VALUE_OFFSET (next_v) = VALUE_OFFSET (v); for (reps = 1; i + reps < length; reps++) { VALUE_LAZY (next_v) = 1; VALUE_OFFSET (next_v) += TYPE_LENGTH (el_type); if (memcmp (VALUE_CONTENTS (v), VALUE_CONTENTS (next_v), TYPE_LENGTH (el_type)) != 0) break; } if (reps == 1) fprintf_filtered (stream, "%d: ", i); else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); val_print (VALUE_TYPE (v), VALUE_CONTENTS (v), 0, 0, stream, format, 2, 1, pretty); things_printed++; i += reps; } } if (i < length) fprintf_filtered (stream, "..."); fprintf_filtered (stream, "}"); return 0; } /* If it's type String, print it */ if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_TARGET_TYPE (type) && TYPE_NAME (TYPE_TARGET_TYPE (type)) && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "java.lang.String") == 0 && (format == 0 || format == 's') && address != 0 && value_as_address (val) != 0) { struct value *data_val; CORE_ADDR data; struct value *boffset_val; unsigned long boffset; struct value *count_val; unsigned long count; struct value *mark; mark = value_mark (); /* Remember start of new values */ data_val = value_struct_elt (&val, NULL, "data", NULL, NULL); data = value_as_address (data_val); boffset_val = value_struct_elt (&val, NULL, "boffset", NULL, NULL); boffset = value_as_address (boffset_val); count_val = value_struct_elt (&val, NULL, "count", NULL, NULL); count = value_as_address (count_val); value_free_to_mark (mark); /* Release unnecessary values */ val_print_string (data + boffset, count, 2, stream); return 0; } return (val_print (type, VALUE_CONTENTS (val), 0, address, stream, format, 1, 0, pretty)); }
int java_value_print (struct value *val, struct ui_file *stream, const struct value_print_options *options) { struct type *type; CORE_ADDR address; int i; char *name; struct value_print_options opts; type = value_type (val); address = value_address (val); if (is_object_type (type)) { CORE_ADDR obj_addr; /* Get the run-time type, and cast the object into that */ obj_addr = unpack_pointer (type, value_contents (val)); if (obj_addr != 0) { type = type_from_class (java_class_from_object (val)); type = lookup_pointer_type (type); val = value_at (type, address); } } if (TYPE_CODE (type) == TYPE_CODE_PTR && !value_logical_not (val)) type_print (TYPE_TARGET_TYPE (type), "", stream, -1); name = TYPE_TAG_NAME (type); if (TYPE_CODE (type) == TYPE_CODE_STRUCT && name != NULL && (i = strlen (name), name[i - 1] == ']')) { gdb_byte buf4[4]; long length; unsigned int things_printed = 0; int reps; struct type *el_type = java_primitive_type_from_name (name, i - 2); i = 0; read_memory (address + JAVA_OBJECT_SIZE, buf4, 4); length = (long) extract_signed_integer (buf4, 4); fprintf_filtered (stream, "{length: %ld", length); if (el_type == NULL) { CORE_ADDR element; CORE_ADDR next_element = -1; /* dummy initial value */ address += JAVA_OBJECT_SIZE + 4; /* Skip object header and length. */ while (i < length && things_printed < options->print_max) { gdb_byte *buf; buf = alloca (gdbarch_ptr_bit (current_gdbarch) / HOST_CHAR_BIT); fputs_filtered (", ", stream); wrap_here (n_spaces (2)); if (i > 0) element = next_element; else { read_memory (address, buf, sizeof (buf)); address += gdbarch_ptr_bit (current_gdbarch) / HOST_CHAR_BIT; /* FIXME: cagney/2003-05-24: Bogus or what. It pulls a host sized pointer out of the target and then extracts that as an address (while assuming that the address is unsigned)! */ element = extract_unsigned_integer (buf, sizeof (buf)); } for (reps = 1; i + reps < length; reps++) { read_memory (address, buf, sizeof (buf)); address += gdbarch_ptr_bit (current_gdbarch) / HOST_CHAR_BIT; /* FIXME: cagney/2003-05-24: Bogus or what. It pulls a host sized pointer out of the target and then extracts that as an address (while assuming that the address is unsigned)! */ next_element = extract_unsigned_integer (buf, sizeof (buf)); if (next_element != element) break; } if (reps == 1) fprintf_filtered (stream, "%d: ", i); else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); if (element == 0) fprintf_filtered (stream, "null"); else fprintf_filtered (stream, "@%s", paddr_nz (element)); things_printed++; i += reps; } } else { struct value *v = allocate_value (el_type); struct value *next_v = allocate_value (el_type); set_value_address (v, address + JAVA_OBJECT_SIZE + 4); set_value_address (next_v, value_raw_address (v)); while (i < length && things_printed < options->print_max) { fputs_filtered (", ", stream); wrap_here (n_spaces (2)); if (i > 0) { struct value *tmp; tmp = next_v; next_v = v; v = tmp; } else { set_value_lazy (v, 1); set_value_offset (v, 0); } set_value_offset (next_v, value_offset (v)); for (reps = 1; i + reps < length; reps++) { set_value_lazy (next_v, 1); set_value_offset (next_v, value_offset (next_v) + TYPE_LENGTH (el_type)); if (memcmp (value_contents (v), value_contents (next_v), TYPE_LENGTH (el_type)) != 0) break; } if (reps == 1) fprintf_filtered (stream, "%d: ", i); else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); opts = *options; opts.deref_ref = 1; common_val_print (v, stream, 1, &opts, current_language); things_printed++; i += reps; } } if (i < length) fprintf_filtered (stream, "..."); fprintf_filtered (stream, "}"); return 0; } /* If it's type String, print it */ if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_TARGET_TYPE (type) && TYPE_TAG_NAME (TYPE_TARGET_TYPE (type)) && strcmp (TYPE_TAG_NAME (TYPE_TARGET_TYPE (type)), "java.lang.String") == 0 && (options->format == 0 || options->format == 's') && address != 0 && value_as_address (val) != 0) { struct value *data_val; CORE_ADDR data; struct value *boffset_val; unsigned long boffset; struct value *count_val; unsigned long count; struct value *mark; mark = value_mark (); /* Remember start of new values */ data_val = value_struct_elt (&val, NULL, "data", NULL, NULL); data = value_as_address (data_val); boffset_val = value_struct_elt (&val, NULL, "boffset", NULL, NULL); boffset = value_as_address (boffset_val); count_val = value_struct_elt (&val, NULL, "count", NULL, NULL); count = value_as_address (count_val); value_free_to_mark (mark); /* Release unnecessary values */ val_print_string (java_char_type, data + boffset, count, stream, options); return 0; } opts = *options; opts.deref_ref = 1; return common_val_print (val, stream, 0, &opts, current_language); }
static void restore_section_callback(bfd *ibfd, asection *isec, void *args) { struct callback_data *data = (struct callback_data *)args; bfd_vma sec_start = bfd_section_vma(ibfd, isec); bfd_size_type size = bfd_section_size(ibfd, isec); bfd_vma sec_end = (sec_start + size); bfd_size_type sec_offset = 0UL; bfd_size_type sec_load_count = size; struct cleanup *old_chain; gdb_byte *buf; int ret; /* Ignore non-loadable sections, eg. from elf files: */ if (!(bfd_get_section_flags(ibfd, isec) & SEC_LOAD)) return; /* Does the section overlap with the desired restore range? */ if ((sec_end <= data->load_start) || ((data->load_end > 0) && (sec_start >= data->load_end))) { /* No, no useable data in this section. */ printf_filtered(_("skipping section %s...\n"), bfd_section_name(ibfd, isec)); return; } /* Compare section address range with user-requested address range (if any). Compute where the actual transfer should start and end. */ if (sec_start < data->load_start) sec_offset = (data->load_start - sec_start); /* Size of a partial transfer: */ sec_load_count -= sec_offset; if ((data->load_end > 0) && (sec_end > data->load_end)) sec_load_count -= (sec_end - data->load_end); /* Get the data. */ buf = (gdb_byte *)xmalloc((size_t)size); old_chain = make_cleanup(xfree, buf); if (!bfd_get_section_contents(ibfd, isec, buf, 0, size)) error(_("Failed to read bfd file %s: '%s'."), bfd_get_filename(ibfd), bfd_errmsg(bfd_get_error())); printf_filtered("Restoring section %s (0x%lx to 0x%lx)", bfd_section_name(ibfd, isec), (unsigned long)sec_start, (unsigned long)sec_end); if ((data->load_offset != 0) || (data->load_start != 0) || (data->load_end != 0)) printf_filtered(" into memory (0x%s to 0x%s)\n", paddr_nz((unsigned long)sec_start + sec_offset + data->load_offset), paddr_nz((unsigned long)sec_start + sec_offset + data->load_offset + sec_load_count)); else puts_filtered("\n"); /* Write the data: */ ret = target_write_memory((sec_start + sec_offset + data->load_offset), (buf + sec_offset), (int)sec_load_count); if (ret != 0) warning(_("restore: memory write failed (%s)."), safe_strerror(ret)); do_cleanups(old_chain); return; }
CORE_ADDR ppc_parse_instructions (CORE_ADDR start, CORE_ADDR end, ppc_function_properties * props) { CORE_ADDR pc = start; CORE_ADDR last_recognized_insn = start; int unrecognized_insn_count = 0; /* We want to allow some unrecognized instructions, but we don't want to keep scanning forever. So this is the number of unrecognized instructions before we bail from the prologue scanning. */ int max_insn = 6; /* If we don't recognize an instruction, keep going at least this long. This is supposed to handle the case where instructions we don't recognize get inserted into the prologue. */ int saw_pic_base_setup = 0; unsigned int lr_reg = 0xffffffff; /* temporary cookies that we use to tell us that we have seen the lr moved into a gpr. * Set to 0xffffffff at start. * Set to the stw instruction for the register we see in the mflr. * Set to 0 when we see the lr get stored on the stack. */ unsigned int lr_64_reg = 0xffffffff; /* temporary cookies that we use to tell us that we have seen the lr moved into a gpr. This version is for std - used for 64 bit PPC. * Set to 0xffffffff at start. * Set to the stw instruction for the register we see in the mflr. * Set to 0 when we see the lr get stored on the stack. */ unsigned int cr_reg = 0xffffffff; /* Same as lr_reg but for condition reg. */ int offset2 = 0; /* This seems redundant to me, but I am not going to bother to take it out right now. */ CHECK_FATAL (props != NULL); ppc_clear_function_properties (props); CHECK_FATAL (start != INVALID_ADDRESS); /* instructions must be word-aligned */ CHECK_FATAL ((start % 4) == 0); /* instructions must be word-aligned */ CHECK_FATAL ((end == INVALID_ADDRESS) || (end % 4) == 0); CHECK_FATAL ((end >= start) || (end == INVALID_ADDRESS)); for (pc = start; (end == INVALID_ADDRESS) || (pc < end); pc += 4) { ULONGEST op = 0; int insn_recognized = 1; if (!safe_read_memory_unsigned_integer (pc, 4, &op)) { ppc_debug ("ppc_parse_instructions: Got an error reading at 0x%s", paddr_nz (pc)); /* We got an error reading the PC, so let's get out of here... */ return last_recognized_insn; } /* This bcl is part of the sequence: mflr r0 (optional - only if leaf function) bcl .+4 mflr r31 mtlr r0 (do this if you stored it at the top) */ if ((op & 0xfe000005) == 0x42000005) /* bcl .+4 another relocatable way to access global data */ { props->lr_invalid = pc; saw_pic_base_setup = 1; props->pic_base_address = pc + 4; goto processed_insn; } /* This mr r31,r12 is part of an ObjC selector prologue like this: mflr r0 stmw r30,-8(r1) mr r31,r12 (the PIC base was in r12, put it in r31) But don't get tricked into using this expression if we've already seen a normal pic base mflr insn. Note: By convention, the address of the start of the function is placed in R12 when calling an ObjC selector, so we stuff the START address we were given in to pic_base_address on the hope that START was actually the start of the function. */ if (!saw_pic_base_setup && (op == 0x7d9f6378 || op == 0x7d9e6378)) { saw_pic_base_setup = 1; props->pic_base_reg = (op & 0x1f0000) >> 16; props->pic_base_address = start; goto processed_insn; } /* Look at other branch instructions. There are a couple of MacOS X Special purpose routines that are used in function prologues. These are: * saveWorld: used to be used in user code to set up info for C++ exceptions, though now it is only used in throw itself. * saveFP: saves the FP registers AND the lr * saveVec: saves the AltiVec registers. If the bl is not one of these, we are probably not in a prologue, and we should get out... */ else if ((op & 0xfc000003) == 0x48000001) /* bl <FN> */
/* FIXME: needs comment: */ void scm_scmval_print(LONGEST svalue, struct ui_file *stream, int format, int deref_ref, int recurse, enum val_prettyprint pretty) { taloop: switch (7 & (int)svalue) { case 2: case 6: print_longest(stream, (format ? format : 'd'), 1, (svalue >> 2)); break; case 4: if (SCM_ICHRP(svalue)) { svalue = SCM_ICHR(svalue); scm_printchar((int)svalue, stream); break; } else if (SCM_IFLAGP(svalue) && ((size_t)SCM_ISYMNUM(svalue) < (sizeof(scm_isymnames) / sizeof(char *)))) { fputs_filtered(SCM_ISYMCHARS(svalue), stream); break; } else if (SCM_ILOCP(svalue)) { fprintf_filtered(stream, "#@%ld%c%ld", (long)SCM_IFRAME(svalue), (SCM_ICDRP(svalue) ? '-' : '+'), (long)SCM_IDIST(svalue)); break; } else goto idef; break; case 1: /* gloc */ svalue = SCM_CAR (svalue - 1); goto taloop; default: idef: scm_ipruk ("immediate", svalue, stream); break; case 0: switch (SCM_TYP7 (svalue)) { case scm_tcs_cons_gloc: if (SCM_CDR (SCM_CAR (svalue) - 1L) == 0) { #if 0 SCM name; #endif /* 0 */ fputs_filtered ("#<latte ", stream); #if 1 fputs_filtered ("???", stream); #else name = ((SCM n *) (STRUCT_TYPE (exp)))[struct_i_name]; scm_lfwrite (CHARS (name), (sizet) sizeof (char), (sizet) LENGTH (name), port); #endif /* 1 */ fprintf_filtered (stream, " #X%s>", paddr_nz (svalue)); break; } /* -Wimplicit-fallthrough vs. -Wdeclaration-after-statement: */ goto imcar_noncase_label; imcar_noncase_label: case scm_tcs_cons_imcar: case scm_tcs_cons_nimcar: fputs_filtered ("(", stream); scm_scmlist_print (svalue, stream, format, deref_ref, recurse + 1, pretty); fputs_filtered (")", stream); break; case scm_tcs_closures: fputs_filtered ("#<CLOSURE ", stream); scm_scmlist_print (SCM_CODE (svalue), stream, format, deref_ref, recurse + 1, pretty); fputs_filtered (">", stream); break; case scm_tc7_string: { size_t len = SCM_LENGTH(svalue); CORE_ADDR addr = (CORE_ADDR)SCM_CDR(svalue); size_t i; size_t done = 0UL; size_t buf_size; gdb_byte buffer[64]; int truncate = (print_max && (len > print_max)); if (truncate) len = print_max; fputs_filtered ("\"", stream); for (; done < len; done += buf_size) { buf_size = min((len - done), 64); read_memory((addr + done), buffer, (int)buf_size); for (i = 0; i < buf_size; ++i) switch (buffer[i]) { case '\"': case '\\': fputs_filtered("\\", stream); goto the_default_label; the_default_label: default: fprintf_filtered(stream, "%c", buffer[i]); } } fputs_filtered((truncate ? "...\"" : "\""), stream); break; } break; case scm_tcs_symbols: { const size_t len = min(SCM_LENGTH(svalue), MAX_ALLOCA_SIZE); char *str = (char *)alloca(min(len, MAX_ALLOCA_SIZE)); read_memory(SCM_CDR(svalue), (gdb_byte *)str, (int)(len + 1)); /* Should handle weird characters, FIXME: do it. */ str[len] = '\0'; fputs_filtered(str, stream); break; } case scm_tc7_vector: { long len = SCM_LENGTH(svalue); int i; LONGEST elements = SCM_CDR(svalue); fputs_filtered ("#(", stream); for (i = 0; i < len; ++i) { if (i > 0) fputs_filtered (" ", stream); scm_scmval_print (scm_get_field (elements, i), stream, format, deref_ref, recurse + 1, pretty); } fputs_filtered (")", stream); } break; #if 0 case tc7_lvector: { SCM result; SCM hook; hook = scm_get_lvector_hook (exp, LV_PRINT_FN); if (hook == BOOL_F) { scm_puts ("#<locked-vector ", port); scm_intprint (CDR (exp), 16, port); scm_puts (">", port); } else { result = scm_apply (hook, scm_listify (exp, port, (writing ? BOOL_T : BOOL_F), SCM_UNDEFINED), EOL); if (result == BOOL_F) goto punk; } break; } break; case tc7_bvect: case tc7_ivect: case tc7_uvect: case tc7_fvect: case tc7_dvect: case tc7_cvect: scm_raprin1 (exp, port, writing); break; #endif /* 0 */ case scm_tcs_subrs: { int index = (int)(SCM_CAR(svalue) >> 8); #if 1 char str[20]; snprintf(str, sizeof(str), "#%d", index); #else char *str = (index ? SCM_CHARS(scm_heap_org + index) : ""); # define SCM_CHARS(x) ((char *)(SCM_CDR(x))) char *str = CHARS(SNAME(exp)); #endif /* 1 */ fprintf_filtered(stream, "#<primitive-procedure %s>", str); } break; #if 0 #ifdef CCLO case tc7_cclo: scm_puts ("#<compiled-closure ", port); scm_iprin1 (CCLO_SUBR (exp), port, writing); scm_putc ('>', port); break; #endif case tc7_contin: fprintf_filtered (stream, "#<continuation %d @ #X%lx >", LENGTH (svalue), (long) CHARS (svalue)); break; case tc7_port: i = PTOBNUM (exp); if (i < scm_numptob && scm_ptobs[i].print && (scm_ptobs[i].print) (exp, port, writing)) break; goto punk; case tc7_smob: i = SMOBNUM (exp); if (i < scm_numsmob && scm_smobs[i].print && (scm_smobs[i].print) (exp, port, writing)) break; goto punk; #endif default: #if 0 punk: #endif scm_ipruk ("type", svalue, stream); } break; } }
/* APPLE LOCAL BEGIN: segment binary file download: */ static void restore_binary_file(char *filename, struct callback_data *data) { FILE *file = fopen_with_cleanup(filename, FOPEN_RB); gdb_byte *buf; long len; long total_file_bytes; long bytes_to_read_from_file; CORE_ADDR addrp; /* Get the file size for reading: */ if (fseek(file, 0L, SEEK_END) == 0) total_file_bytes = ftell(file); else perror_with_name(filename); if (total_file_bytes <= (int)data->load_start) error(_("Start address is greater than length of binary file %s."), filename); bytes_to_read_from_file = (int)data->load_end; if (bytes_to_read_from_file == 0) bytes_to_read_from_file = total_file_bytes; if (data->load_start > 0) bytes_to_read_from_file -= (int)data->load_start; if (bytes_to_read_from_file > total_file_bytes) bytes_to_read_from_file = total_file_bytes; printf_filtered("Restoring binary file %s into memory (0x%s to 0x%s)\n", filename, paddr_nz(data->load_start + data->load_offset), paddr_nz(data->load_start + data->load_offset + bytes_to_read_from_file)); /* Now set the file pos to the requested load start pos: */ if (fseek(file, (long)data->load_start, SEEK_SET) != 0) perror_with_name(filename); if (bytes_to_read_from_file > g_max_binary_file_chunk) len = g_max_binary_file_chunk; else len = bytes_to_read_from_file; buf = (gdb_byte *)xmalloc(len); make_cleanup(xfree, buf); addrp = (data->load_start + data->load_offset); /* BYTES_TO_READ_FROM_FILE decreases each time through this loop; we read g_max_binary_file_chunk or less bytes at each iteration. */ while (bytes_to_read_from_file > 0) { int max_errors; /* The last chunk we shall be reading -- at this point our LEN buffer is larger than the remaining number of bytes to be read; cap it so we do NOT read off the end of the file. */ if (len > bytes_to_read_from_file) len = bytes_to_read_from_file; if (fread(buf, 1, len, file) != (size_t)len) perror_with_name(filename); max_errors = 2; while (max_errors > 0) { printf_unfiltered(_("Writing 0x%s bytes to 0x%s\n"), paddr_nz(len), paddr_nz(addrp)); gdb_flush (gdb_stdout); if (target_write_memory(addrp, buf, (int)len) == 0) { addrp += len; break; } else { warning(_("restore: memory write failed - retrying.")); max_errors--; } } if (max_errors == 0) error ("restore: memory write failed."); bytes_to_read_from_file -= len; } }