Index: head/gnu/usr.bin/gdb/kgdb/main.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/main.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/main.c (revision 298363) @@ -1,483 +1,481 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* libgdb stuff. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern frame_unwind_sniffer_ftype *kgdb_sniffer_kluge; #include "kgdb.h" static int dumpnr; static int quiet; static int verbose; static char crashdir[PATH_MAX]; static char *kernel; static char *remote; static char *vmcore; static struct ui_file *parse_gdberr; static void (*kgdb_new_objfile_chain)(struct objfile * objfile); static void usage(void) { fprintf(stderr, "usage: %s [-afqvw] [-b rate] [-d crashdir] [-c core | -n dumpnr | -r device]\n" "\t[kernel [core]]\n", getprogname()); exit(1); } static void kernel_from_dumpnr(int nr) { char path[PATH_MAX]; FILE *info; char *s; struct stat st; int l; /* * If there's a kernel image right here in the crash directory, then * use it. The kernel image is either called kernel. or is in a * subdirectory kernel. and called kernel. The latter allows us * to collect the modules in the same place. */ snprintf(path, sizeof(path), "%s/kernel.%d", crashdir, nr); if (stat(path, &st) == 0) { if (S_ISREG(st.st_mode)) { kernel = strdup(path); return; } if (S_ISDIR(st.st_mode)) { snprintf(path, sizeof(path), "%s/kernel.%d/kernel", crashdir, nr); if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { kernel = strdup(path); return; } } } /* * No kernel image here. Parse the dump header. The kernel object * directory can be found there and we probably have the kernel * image still in it. The object directory may also have a kernel * with debugging info (called kernel.debug). If we have a debug * kernel, use it. */ snprintf(path, sizeof(path), "%s/info.%d", crashdir, nr); info = fopen(path, "r"); if (info == NULL) { warn("%s", path); return; } while (fgets(path, sizeof(path), info) != NULL) { l = strlen(path); if (l > 0 && path[l - 1] == '\n') path[--l] = '\0'; if (strncmp(path, " ", 4) == 0) { s = strchr(path, ':'); s = (s == NULL) ? path + 4 : s + 1; l = snprintf(path, sizeof(path), "%s/kernel.debug", s); if (stat(path, &st) == -1 || !S_ISREG(st.st_mode)) { path[l - 6] = '\0'; if (stat(path, &st) == -1 || !S_ISREG(st.st_mode)) break; } kernel = strdup(path); break; } } fclose(info); } static void kgdb_new_objfile(struct objfile *objfile) { static int once = 1; kld_new_objfile(objfile); kgdb_trgt_new_objfile(objfile); if (kgdb_new_objfile_chain != NULL) kgdb_new_objfile_chain(objfile); if (once && objfile != NULL && objfile == symfile_objfile) { /* * The initial kernel has just been loaded. Start the * remote target if we have one. */ once = 0; if (remote != NULL) push_remote_target (remote, 0); } } /* * Parse an expression and return its value. If 'quiet' is true, then * any error messages from the parser are masked. */ CORE_ADDR kgdb_parse_1(const char *exp, int quiet) { struct ui_file *old_stderr; struct cleanup *old_chain; struct expression *expr; struct value *val; char *s; CORE_ADDR n; old_stderr = gdb_stderr; if (quiet) gdb_stderr = parse_gdberr; n = 0; s = xstrdup(exp); old_chain = make_cleanup(xfree, s); if (gdb_parse_exp_1(&s, NULL, 0, &expr) && *s == '\0') { make_cleanup(free_current_contents, &expr); if (gdb_evaluate_expression(expr, &val)) n = value_as_address(val); } do_cleanups(old_chain); gdb_stderr = old_stderr; return (n); } #define MSGBUF_SEQ_TO_POS(size, seq) ((seq) % (size)) void kgdb_dmesg(void) { CORE_ADDR bufp; int size, rseq, wseq; char c; /* * Display the unread portion of the message buffer. This gives the * user a some initial data to work from. */ if (quiet) return; bufp = kgdb_parse("msgbufp->msg_ptr"); size = (int)kgdb_parse("msgbufp->msg_size"); if (bufp == 0 || size == 0) return; rseq = (int)kgdb_parse("msgbufp->msg_rseq"); wseq = (int)kgdb_parse("msgbufp->msg_wseq"); rseq = MSGBUF_SEQ_TO_POS(size, rseq); wseq = MSGBUF_SEQ_TO_POS(size, wseq); if (rseq == wseq) return; printf("\nUnread portion of the kernel message buffer:\n"); while (rseq < wseq) { read_memory(bufp + rseq, &c, 1); putchar(c); rseq++; if (rseq == size) rseq = 0; } if (c != '\n') putchar('\n'); putchar('\n'); } static void kgdb_init(char *argv0 __unused) { parse_gdberr = mem_fileopen(); set_prompt("(kgdb) "); initialize_kgdb_target(); initialize_kld_target(); kgdb_new_objfile_chain = target_new_objfile_hook; target_new_objfile_hook = kgdb_new_objfile; } /* * Remote targets can support any number of syntaxes and we want to * support them all with one addition: we support specifying a device * node for a serial device without the "/dev/" prefix. * * What we do is to stat(2) the existing remote target first. If that * fails, we try it with "/dev/" prepended. If that succeeds we use * the resulting path, otherwise we use the original target. If * either stat(2) succeeds make sure the file is either a character * device or a FIFO. */ static void verify_remote(void) { char path[PATH_MAX]; struct stat st; if (stat(remote, &st) != 0) { snprintf(path, sizeof(path), "/dev/%s", remote); if (stat(path, &st) != 0) return; free(remote); remote = strdup(path); } if (!S_ISCHR(st.st_mode) && !S_ISFIFO(st.st_mode)) errx(1, "%s: not a special file, FIFO or socket", remote); } static void add_arg(struct captured_main_args *args, char *arg) { args->argc++; args->argv = reallocf(args->argv, (args->argc + 1) * sizeof(char *)); if (args->argv == NULL) err(1, "Out of memory building argument list"); args->argv[args->argc] = arg; } int main(int argc, char *argv[]) { char path[PATH_MAX]; struct stat st; struct captured_main_args args; char *s; int a, ch; dumpnr = -1; strlcpy(crashdir, "/var/crash", sizeof(crashdir)); s = getenv("KGDB_CRASH_DIR"); if (s != NULL) strlcpy(crashdir, s, sizeof(crashdir)); /* Convert long options into short options. */ for (a = 1; a < argc; a++) { s = argv[a]; if (s[0] == '-') { s++; /* Long options take either 1 or 2 dashes. */ if (s[0] == '-') s++; if (strcmp(s, "quiet") == 0) argv[a] = "-q"; else if (strcmp(s, "fullname") == 0) argv[a] = "-f"; } } quiet = 0; memset (&args, 0, sizeof args); args.use_windows = 0; args.interpreter_p = INTERP_CONSOLE; args.argv = malloc(sizeof(char *)); args.argv[0] = argv[0]; while ((ch = getopt(argc, argv, "ab:c:d:fn:qr:vw")) != -1) { switch (ch) { case 'a': annotation_level++; break; case 'b': { int i; char *p; i = strtol(optarg, &p, 0); if (*p != '\0' || p == optarg) warnx("warning: could not set baud rate to `%s'.\n", optarg); else baud_rate = i; break; } case 'c': /* use given core file. */ if (vmcore != NULL) { warnx("option %c: can only be specified once", optopt); usage(); /* NOTREACHED */ } vmcore = strdup(optarg); break; case 'd': /* lookup dumps in given directory. */ strlcpy(crashdir, optarg, sizeof(crashdir)); break; case 'f': annotation_level = 1; break; case 'n': /* use dump with given number. */ dumpnr = strtol(optarg, &s, 0); if (dumpnr < 0 || *s != '\0') { warnx("option %c: invalid kernel dump number", optopt); usage(); /* NOTREACHED */ } break; case 'q': quiet = 1; add_arg(&args, "-q"); break; case 'r': /* use given device for remote session. */ if (remote != NULL) { warnx("option %c: can only be specified once", optopt); usage(); /* NOTREACHED */ } remote = strdup(optarg); break; case 'v': /* increase verbosity. */ verbose++; break; case 'w': /* core file is writeable. */ add_arg(&args, "--write"); break; case '?': default: usage(); } } if (((vmcore != NULL) ? 1 : 0) + ((dumpnr >= 0) ? 1 : 0) + ((remote != NULL) ? 1 : 0) > 1) { warnx("options -c, -n and -r are mutually exclusive"); usage(); /* NOTREACHED */ } if (verbose > 1) warnx("using %s as the crash directory", crashdir); if (argc > optind) kernel = strdup(argv[optind++]); if (argc > optind && (dumpnr >= 0 || remote != NULL)) { warnx("options -n and -r do not take a core file. Ignored"); optind = argc; } if (dumpnr >= 0) { snprintf(path, sizeof(path), "%s/vmcore.%d", crashdir, dumpnr); if (stat(path, &st) == -1) err(1, "%s", path); if (!S_ISREG(st.st_mode)) errx(1, "%s: not a regular file", path); vmcore = strdup(path); } else if (remote != NULL) { verify_remote(); } else if (argc > optind) { if (vmcore == NULL) vmcore = strdup(argv[optind++]); if (argc > optind) warnx("multiple core files specified. Ignored"); } else if (vmcore == NULL && kernel == NULL) { vmcore = strdup(_PATH_MEM); kernel = strdup(getbootfile()); } if (verbose) { if (vmcore != NULL) warnx("core file: %s", vmcore); if (remote != NULL) warnx("device file: %s", remote); if (kernel != NULL) warnx("kernel image: %s", kernel); } /* A remote target requires an explicit kernel argument. */ if (remote != NULL && kernel == NULL) { warnx("remote debugging requires a kernel"); usage(); /* NOTREACHED */ } /* If we don't have a kernel image yet, try to find one. */ if (kernel == NULL) { if (dumpnr >= 0) kernel_from_dumpnr(dumpnr); if (kernel == NULL) errx(1, "couldn't find a suitable kernel image"); if (verbose) warnx("kernel image: %s", kernel); } add_arg(&args, kernel); if (vmcore != NULL) add_arg(&args, vmcore); /* The libgdb code uses optind too. Reset it... */ optind = 0; /* Terminate argv list. */ add_arg(&args, NULL); init_ui_hook = kgdb_init; -#if TARGET_CPUARCH == arm frame_tdep_pc_fixup = kgdb_trgt_pc_fixup; -#endif kgdb_sniffer_kluge = kgdb_trgt_trapframe_sniffer; return (gdb_main(&args)); } Index: head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/trgt_amd64.c (revision 298363) @@ -1,197 +1,210 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kgdb.h" CORE_ADDR kgdb_trgt_core_pcb(u_int cpuid) { return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); } void kgdb_trgt_fetch_registers(int regno __unused) { struct kthr *kt; struct pcb pcb; kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL) return; if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { warnx("kvm_read: %s", kvm_geterr(kvm)); memset(&pcb, 0, sizeof(pcb)); } supply_register(AMD64_RBX_REGNUM, (char *)&pcb.pcb_rbx); supply_register(AMD64_RBP_REGNUM, (char *)&pcb.pcb_rbp); supply_register(AMD64_RSP_REGNUM, (char *)&pcb.pcb_rsp); supply_register(AMD64_R8_REGNUM + 4, (char *)&pcb.pcb_r12); supply_register(AMD64_R8_REGNUM + 5, (char *)&pcb.pcb_r13); supply_register(AMD64_R8_REGNUM + 6, (char *)&pcb.pcb_r14); supply_register(AMD64_R15_REGNUM, (char *)&pcb.pcb_r15); supply_register(AMD64_RIP_REGNUM, (char *)&pcb.pcb_rip); } void kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } void kgdb_trgt_new_objfile(struct objfile *objfile) { } struct kgdb_frame_cache { CORE_ADDR pc; CORE_ADDR sp; }; static int kgdb_trgt_frame_offset[20] = { offsetof(struct trapframe, tf_rax), offsetof(struct trapframe, tf_rbx), offsetof(struct trapframe, tf_rcx), offsetof(struct trapframe, tf_rdx), offsetof(struct trapframe, tf_rsi), offsetof(struct trapframe, tf_rdi), offsetof(struct trapframe, tf_rbp), offsetof(struct trapframe, tf_rsp), offsetof(struct trapframe, tf_r8), offsetof(struct trapframe, tf_r9), offsetof(struct trapframe, tf_r10), offsetof(struct trapframe, tf_r11), offsetof(struct trapframe, tf_r12), offsetof(struct trapframe, tf_r13), offsetof(struct trapframe, tf_r14), offsetof(struct trapframe, tf_r15), offsetof(struct trapframe, tf_rip), offsetof(struct trapframe, tf_rflags), offsetof(struct trapframe, tf_cs), offsetof(struct trapframe, tf_ss) }; static struct kgdb_frame_cache * kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); frame_unwind_register(next_frame, SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SP_REGNUM)); } return (cache); } static void kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_frame_cache *cache; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { char dummy_valuep[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; int ofs, regsz; regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; ofs = (regnum >= AMD64_RAX_REGNUM && regnum <= AMD64_EFLAGS_REGNUM + 2) ? kgdb_trgt_frame_offset[regnum] : -1; if (ofs == -1) return; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *addrp = cache->sp + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_trapframe_unwind = { UNKNOWN_FRAME, &kgdb_trgt_trapframe_this_id, &kgdb_trgt_trapframe_prev_register }; const struct frame_unwind * kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) { char *pname; CORE_ADDR pc; pc = frame_pc_unwind(next_frame); pname = NULL; find_pc_partial_function(pc, &pname, NULL, NULL); if (pname == NULL) return (NULL); if (strcmp(pname, "calltrap") == 0 || strcmp(pname, "nmi_calltrap") == 0 || (pname[0] == 'X' && pname[1] != '_')) return (&kgdb_trgt_trapframe_unwind); /* printf("%s: %lx =%s\n", __func__, pc, pname); */ return (NULL); } + +/* + * This function ensures, that the PC is inside the + * function section which is understood by GDB. + * + * Return 0 when fixup is necessary, -1 otherwise. + */ +int +kgdb_trgt_pc_fixup(CORE_ADDR *pc __unused) +{ + + return (-1); +} Index: head/gnu/usr.bin/gdb/kgdb/trgt_i386.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_i386.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/trgt_i386.c (revision 298363) @@ -1,387 +1,400 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kgdb.h" static int ofs_fix; CORE_ADDR kgdb_trgt_core_pcb(u_int cpuid) { return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); } void kgdb_trgt_fetch_registers(int regno __unused) { struct kthr *kt; struct pcb pcb; kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL) return; if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { warnx("kvm_read: %s", kvm_geterr(kvm)); memset(&pcb, 0, sizeof(pcb)); } supply_register(I386_EBX_REGNUM, (char *)&pcb.pcb_ebx); supply_register(I386_ESP_REGNUM, (char *)&pcb.pcb_esp); supply_register(I386_EBP_REGNUM, (char *)&pcb.pcb_ebp); supply_register(I386_ESI_REGNUM, (char *)&pcb.pcb_esi); supply_register(I386_EDI_REGNUM, (char *)&pcb.pcb_edi); supply_register(I386_EIP_REGNUM, (char *)&pcb.pcb_eip); } void kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } void kgdb_trgt_new_objfile(struct objfile *objfile) { /* * In revision 1.117 of i386/i386/exception.S trap handlers * were changed to pass trapframes by reference rather than * by value. Detect this by seeing if the first instruction * at the 'calltrap' label is a "push %esp" which has the * opcode 0x54. */ if (kgdb_parse("((char *)calltrap)[0]") == 0x54) ofs_fix = 4; else ofs_fix = 0; } struct kgdb_tss_cache { CORE_ADDR pc; CORE_ADDR sp; CORE_ADDR tss; }; static int kgdb_trgt_tss_offset[15] = { offsetof(struct i386tss, tss_eax), offsetof(struct i386tss, tss_ecx), offsetof(struct i386tss, tss_edx), offsetof(struct i386tss, tss_ebx), offsetof(struct i386tss, tss_esp), offsetof(struct i386tss, tss_ebp), offsetof(struct i386tss, tss_esi), offsetof(struct i386tss, tss_edi), offsetof(struct i386tss, tss_eip), offsetof(struct i386tss, tss_eflags), offsetof(struct i386tss, tss_cs), offsetof(struct i386tss, tss_ss), offsetof(struct i386tss, tss_ds), offsetof(struct i386tss, tss_es), offsetof(struct i386tss, tss_fs) }; /* * If the current thread is executing on a CPU, fetch the common_tss * for that CPU. * * This is painful because 'struct pcpu' is variant sized, so we can't * use it. Instead, we lookup the GDT selector for this CPU and * extract the base of the TSS from there. */ static CORE_ADDR kgdb_trgt_fetch_tss(void) { struct kthr *kt; struct segment_descriptor sd; uintptr_t addr, cpu0prvpage, tss; kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL || kt->cpu == NOCPU || kt->cpu < 0) return (0); addr = kgdb_lookup("gdt"); if (addr == 0) return (0); addr += (kt->cpu * NGDT + GPROC0_SEL) * sizeof(sd); if (kvm_read(kvm, addr, &sd, sizeof(sd)) != sizeof(sd)) { warnx("kvm_read: %s", kvm_geterr(kvm)); return (0); } if (sd.sd_type != SDT_SYS386BSY) { warnx("descriptor is not a busy TSS"); return (0); } tss = sd.sd_hibase << 24 | sd.sd_lobase; /* * In SMP kernels, the TSS is stored as part of the per-CPU * data. On older kernels, the CPU0's private page * is stored at an address that isn't mapped in minidumps. * However, the data is mapped at the alternate cpu0prvpage * address. Thus, if the TSS is at the invalid address, * change it to be relative to cpu0prvpage instead. */ if (trunc_page(tss) == 0xffc00000) { addr = kgdb_lookup("cpu0prvpage"); if (addr == 0) return (0); if (kvm_read(kvm, addr, &cpu0prvpage, sizeof(cpu0prvpage)) != sizeof(cpu0prvpage)) { warnx("kvm_read: %s", kvm_geterr(kvm)); return (0); } tss = cpu0prvpage + (tss & PAGE_MASK); } return ((CORE_ADDR)tss); } static struct kgdb_tss_cache * kgdb_trgt_tss_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_tss_cache *cache; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_tss_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); frame_unwind_register(next_frame, SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SP_REGNUM)); cache->tss = kgdb_trgt_fetch_tss(); } return (cache); } static void kgdb_trgt_dblfault_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_tss_cache *cache; cache = kgdb_trgt_tss_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_dblfault_prev_register(struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { char dummy_valuep[MAX_REGISTER_SIZE]; struct kgdb_tss_cache *cache; int ofs, regsz; regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM) ? kgdb_trgt_tss_offset[regnum] : -1; if (ofs == -1) return; cache = kgdb_trgt_tss_cache(next_frame, this_cache); if (cache->tss == 0) return; *addrp = cache->tss + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_dblfault_unwind = { UNKNOWN_FRAME, &kgdb_trgt_dblfault_this_id, &kgdb_trgt_dblfault_prev_register }; struct kgdb_frame_cache { int frame_type; CORE_ADDR pc; CORE_ADDR sp; }; #define FT_NORMAL 1 #define FT_INTRFRAME 2 #define FT_INTRTRAPFRAME 3 #define FT_TIMERFRAME 4 static int kgdb_trgt_frame_offset[15] = { offsetof(struct trapframe, tf_eax), offsetof(struct trapframe, tf_ecx), offsetof(struct trapframe, tf_edx), offsetof(struct trapframe, tf_ebx), offsetof(struct trapframe, tf_esp), offsetof(struct trapframe, tf_ebp), offsetof(struct trapframe, tf_esi), offsetof(struct trapframe, tf_edi), offsetof(struct trapframe, tf_eip), offsetof(struct trapframe, tf_eflags), offsetof(struct trapframe, tf_cs), offsetof(struct trapframe, tf_ss), offsetof(struct trapframe, tf_ds), offsetof(struct trapframe, tf_es), offsetof(struct trapframe, tf_fs) }; static struct kgdb_frame_cache * kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; char *pname; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); find_pc_partial_function(cache->pc, &pname, NULL, NULL); if (pname[0] != 'X') cache->frame_type = FT_NORMAL; else if (strcmp(pname, "Xtimerint") == 0) cache->frame_type = FT_TIMERFRAME; else if (strcmp(pname, "Xcpustop") == 0 || strcmp(pname, "Xrendezvous") == 0 || strcmp(pname, "Xipi_intr_bitmap_handler") == 0 || strcmp(pname, "Xlazypmap") == 0) cache->frame_type = FT_INTRTRAPFRAME; else cache->frame_type = FT_INTRFRAME; frame_unwind_register(next_frame, SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SP_REGNUM)); } return (cache); } static void kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_frame_cache *cache; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { char dummy_valuep[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; int ofs, regsz; regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM) ? kgdb_trgt_frame_offset[regnum] + ofs_fix : -1; if (ofs == -1) return; cache = kgdb_trgt_frame_cache(next_frame, this_cache); switch (cache->frame_type) { case FT_NORMAL: break; case FT_INTRFRAME: ofs += 4; break; case FT_TIMERFRAME: break; case FT_INTRTRAPFRAME: ofs -= ofs_fix; break; default: fprintf_unfiltered(gdb_stderr, "Correct FT_XXX frame offsets " "for %d\n", cache->frame_type); break; } *addrp = cache->sp + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_trapframe_unwind = { UNKNOWN_FRAME, &kgdb_trgt_trapframe_this_id, &kgdb_trgt_trapframe_prev_register }; const struct frame_unwind * kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) { char *pname; CORE_ADDR pc; pc = frame_pc_unwind(next_frame); pname = NULL; find_pc_partial_function(pc, &pname, NULL, NULL); if (pname == NULL) return (NULL); if (strcmp(pname, "dblfault_handler") == 0) return (&kgdb_trgt_dblfault_unwind); if (strcmp(pname, "calltrap") == 0 || (pname[0] == 'X' && pname[1] != '_')) return (&kgdb_trgt_trapframe_unwind); /* printf("%s: %llx =%s\n", __func__, pc, pname); */ return (NULL); } + +/* + * This function ensures, that the PC is inside the + * function section which is understood by GDB. + * + * Return 0 when fixup is necessary, -1 otherwise. + */ +int +kgdb_trgt_pc_fixup(CORE_ADDR *pc __unused) +{ + + return (-1); +} Index: head/gnu/usr.bin/gdb/kgdb/trgt_mips.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_mips.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/trgt_mips.c (revision 298363) @@ -1,240 +1,253 @@ /* * Copyright (c) 2007 Juniper Networks, Inc. * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * from: src/gnu/usr.bin/gdb/kgdb/trgt_alpha.c,v 1.2.2.1 2005/09/15 05:32:10 marcel */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef CROSS_DEBUGGER #include #endif #include "kgdb.h" CORE_ADDR kgdb_trgt_core_pcb(u_int cpuid) { return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); } void kgdb_trgt_fetch_registers(int regno __unused) { #ifndef CROSS_DEBUGGER struct kthr *kt; struct pcb pcb; kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL) return; if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { warnx("kvm_read: %s", kvm_geterr(kvm)); memset(&pcb, 0, sizeof(pcb)); } supply_register(MIPS_S0_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S0]); supply_register(MIPS_S1_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S1]); supply_register(MIPS_S2_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S2]); supply_register(MIPS_S3_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S3]); supply_register(MIPS_S4_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S4]); supply_register(MIPS_S5_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S5]); supply_register(MIPS_S6_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S6]); supply_register(MIPS_S7_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S7]); supply_register(MIPS_SP_REGNUM, (char *)&pcb.pcb_context[PCB_REG_SP]); supply_register(MIPS_FP_REGNUM, (char *)&pcb.pcb_context[PCB_REG_GP]); supply_register(MIPS_RA_REGNUM, (char *)&pcb.pcb_context[PCB_REG_RA]); supply_register(MIPS_EMBED_PC_REGNUM, (char *)&pcb.pcb_context[PCB_REG_PC]); #endif } void kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "Unimplemented function: %s\n", __func__); } void kgdb_trgt_new_objfile(struct objfile *objfile) { } #ifndef CROSS_DEBUGGER struct kgdb_frame_cache { CORE_ADDR pc; CORE_ADDR sp; }; static int kgdb_trgt_frame_offset[] = { offsetof(struct trapframe, zero), offsetof(struct trapframe, ast), offsetof(struct trapframe, v0), offsetof(struct trapframe, v1), offsetof(struct trapframe, a0), offsetof(struct trapframe, a1), offsetof(struct trapframe, a2), offsetof(struct trapframe, a3), #if defined(__mips_n32) || defined(__mips_n64) offsetof(struct trapframe, a4), offsetof(struct trapframe, a5), offsetof(struct trapframe, a6), offsetof(struct trapframe, a7), offsetof(struct trapframe, t0), offsetof(struct trapframe, t1), offsetof(struct trapframe, t2), offsetof(struct trapframe, t3), #else offsetof(struct trapframe, t0), offsetof(struct trapframe, t1), offsetof(struct trapframe, t2), offsetof(struct trapframe, t3), offsetof(struct trapframe, t4), offsetof(struct trapframe, t5), offsetof(struct trapframe, t6), offsetof(struct trapframe, t7), #endif offsetof(struct trapframe, s0), offsetof(struct trapframe, s1), offsetof(struct trapframe, s2), offsetof(struct trapframe, s3), offsetof(struct trapframe, s4), offsetof(struct trapframe, s5), offsetof(struct trapframe, s6), offsetof(struct trapframe, s7), offsetof(struct trapframe, t8), offsetof(struct trapframe, t9), offsetof(struct trapframe, k0), offsetof(struct trapframe, k1), offsetof(struct trapframe, gp), offsetof(struct trapframe, sp), offsetof(struct trapframe, s8), offsetof(struct trapframe, ra), }; static struct kgdb_frame_cache * kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); frame_unwind_register(next_frame, SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SP_REGNUM)); } return (cache); } static void kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_frame_cache *cache; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame __unused, void **this_cache __unused, int regnum __unused, int *optimizedp __unused, enum lval_type *lvalp __unused, CORE_ADDR *addrp __unused, int *realnump __unused, void *valuep __unused) { char dummy_valuep[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; int ofs, regsz; regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; ofs = (regnum >= 0 && regnum <= MIPS_RA_REGNUM) ? kgdb_trgt_frame_offset[regnum] : -1; if (ofs == -1) return; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *addrp = cache->sp + ofs * 8; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_trapframe_unwind = { UNKNOWN_FRAME, &kgdb_trgt_trapframe_this_id, &kgdb_trgt_trapframe_prev_register }; #endif const struct frame_unwind * kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) { #ifndef CROSS_DEBUGGER char *pname; CORE_ADDR pc; pc = frame_pc_unwind(next_frame); pname = NULL; find_pc_partial_function(pc, &pname, NULL, NULL); if (pname == NULL) return (NULL); if ((strcmp(pname, "MipsKernIntr") == 0) || (strcmp(pname, "MipsKernGenException") == 0) || (strcmp(pname, "MipsUserIntr") == 0) || (strcmp(pname, "MipsUserGenException") == 0)) return (&kgdb_trgt_trapframe_unwind); #endif return (NULL); } + +/* + * This function ensures, that the PC is inside the + * function section which is understood by GDB. + * + * Return 0 when fixup is necessary, -1 otherwise. + */ +int +kgdb_trgt_pc_fixup(CORE_ADDR *pc __unused) +{ + + return (-1); +} Index: head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/trgt_powerpc.c (revision 298363) @@ -1,201 +1,214 @@ /*- * Copyright (c) 2006 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #ifdef CROSS_DEBUGGER #include #include #else #include #include #endif #include #include #include #include #include #include #include #include #include #include #include "kgdb.h" CORE_ADDR kgdb_trgt_core_pcb(u_int cpuid) { return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); } void kgdb_trgt_fetch_registers(int regno __unused) { struct kthr *kt; struct pcb pcb; struct gdbarch_tdep *tdep; int i; tdep = gdbarch_tdep (current_gdbarch); kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL) return; if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { warnx("kvm_read: %s", kvm_geterr(kvm)); memset(&pcb, 0, sizeof(pcb)); } /* * r14-r31 are saved in the pcb */ for (i = 14; i <= 31; i++) { supply_register(tdep->ppc_gp0_regnum + i, (char *)&pcb.pcb_context[i]); } /* r1 is saved in the sp field */ supply_register(tdep->ppc_gp0_regnum + 1, (char *)&pcb.pcb_sp); supply_register(tdep->ppc_lr_regnum, (char *)&pcb.pcb_lr); supply_register(tdep->ppc_cr_regnum, (char *)&pcb.pcb_cr); } void kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } void kgdb_trgt_new_objfile(struct objfile *objfile) { } struct kgdb_frame_cache { CORE_ADDR pc; CORE_ADDR sp; }; static struct kgdb_frame_cache * kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); frame_unwind_register(next_frame, SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SP_REGNUM)); } return (cache); } static void kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_frame_cache *cache; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { char dummy_valuep[MAX_REGISTER_SIZE]; struct gdbarch_tdep *tdep; struct kgdb_frame_cache *cache; int ofs, regsz; tdep = gdbarch_tdep(current_gdbarch); regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; if (regnum >= tdep->ppc_gp0_regnum && regnum <= tdep->ppc_gplast_regnum) ofs = offsetof(struct trapframe, fixreg[regnum - tdep->ppc_gp0_regnum]); else if (regnum == tdep->ppc_lr_regnum) ofs = offsetof(struct trapframe, lr); else if (regnum == tdep->ppc_cr_regnum) ofs = offsetof(struct trapframe, cr); else if (regnum == tdep->ppc_xer_regnum) ofs = offsetof(struct trapframe, xer); else if (regnum == tdep->ppc_ctr_regnum) ofs = offsetof(struct trapframe, ctr); else if (regnum == PC_REGNUM) ofs = offsetof(struct trapframe, srr0); else return; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *addrp = cache->sp + 8 + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_trapframe_unwind = { UNKNOWN_FRAME, &kgdb_trgt_trapframe_this_id, &kgdb_trgt_trapframe_prev_register }; const struct frame_unwind * kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) { char *pname; CORE_ADDR pc; pc = frame_pc_unwind(next_frame); pname = NULL; find_pc_partial_function(pc, &pname, NULL, NULL); if (pname == NULL) return (NULL); if (strcmp(pname, "asttrapexit") == 0 || strcmp(pname, "trapexit") == 0) return (&kgdb_trgt_trapframe_unwind); /* printf("%s: %llx =%s\n", __func__, pc, pname); */ return (NULL); } + +/* + * This function ensures, that the PC is inside the + * function section which is understood by GDB. + * + * Return 0 when fixup is necessary, -1 otherwise. + */ +int +kgdb_trgt_pc_fixup(CORE_ADDR *pc __unused) +{ + + return (-1); +} Index: head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/trgt_powerpc64.c (revision 298363) @@ -1,198 +1,211 @@ /*- * Copyright (c) 2006 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kgdb.h" CORE_ADDR kgdb_trgt_core_pcb(u_int cpuid) { return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); } void kgdb_trgt_fetch_registers(int regno __unused) { struct kthr *kt; struct pcb pcb; struct gdbarch_tdep *tdep; int i; tdep = gdbarch_tdep (current_gdbarch); kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL) return; if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { warnx("kvm_read: %s", kvm_geterr(kvm)); memset(&pcb, 0, sizeof(pcb)); } /* * r14-r31 are saved in the pcb */ for (i = 14; i <= 31; i++) { supply_register(tdep->ppc_gp0_regnum + i, (char *)&pcb.pcb_context[i]); } /* r1 is saved in the sp field */ supply_register(tdep->ppc_gp0_regnum + 1, (char *)&pcb.pcb_sp); /* r2 is saved in the toc field */ supply_register(tdep->ppc_gp0_regnum + 2, (char *)&pcb.pcb_toc); supply_register(tdep->ppc_lr_regnum, (char *)&pcb.pcb_lr); supply_register(tdep->ppc_cr_regnum, (char *)&pcb.pcb_cr); } void kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } void kgdb_trgt_new_objfile(struct objfile *objfile) { } struct kgdb_frame_cache { CORE_ADDR pc; CORE_ADDR sp; }; static struct kgdb_frame_cache * kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); frame_unwind_register(next_frame, SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SP_REGNUM)); } return (cache); } static void kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_frame_cache *cache; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { char dummy_valuep[MAX_REGISTER_SIZE]; struct gdbarch_tdep *tdep; struct kgdb_frame_cache *cache; int ofs, regsz; tdep = gdbarch_tdep(current_gdbarch); regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; if (regnum >= tdep->ppc_gp0_regnum && regnum <= tdep->ppc_gplast_regnum) ofs = offsetof(struct trapframe, fixreg[regnum - tdep->ppc_gp0_regnum]); else if (regnum == tdep->ppc_lr_regnum) ofs = offsetof(struct trapframe, lr); else if (regnum == tdep->ppc_cr_regnum) ofs = offsetof(struct trapframe, cr); else if (regnum == tdep->ppc_xer_regnum) ofs = offsetof(struct trapframe, xer); else if (regnum == tdep->ppc_ctr_regnum) ofs = offsetof(struct trapframe, ctr); else if (regnum == PC_REGNUM) ofs = offsetof(struct trapframe, srr0); else return; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *addrp = cache->sp + 48 + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_trapframe_unwind = { UNKNOWN_FRAME, &kgdb_trgt_trapframe_this_id, &kgdb_trgt_trapframe_prev_register }; const struct frame_unwind * kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) { char *pname; CORE_ADDR pc; pc = frame_pc_unwind(next_frame); pname = NULL; find_pc_partial_function(pc, &pname, NULL, NULL); if (pname == NULL) return (NULL); if (strcmp(pname, "asttrapexit") == 0 || strcmp(pname, "trapexit") == 0) return (&kgdb_trgt_trapframe_unwind); /* printf("%s: %llx =%s\n", __func__, pc, pname); */ return (NULL); } + +/* + * This function ensures, that the PC is inside the + * function section which is understood by GDB. + * + * Return 0 when fixup is necessary, -1 otherwise. + */ +int +kgdb_trgt_pc_fixup(CORE_ADDR *pc __unused) +{ + + return (-1); +} Index: head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c =================================================================== --- head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c (revision 298362) +++ head/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c (revision 298363) @@ -1,205 +1,218 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kgdb.h" CORE_ADDR kgdb_trgt_core_pcb(u_int cpuid) { return (kgdb_trgt_stop_pcb(cpuid, sizeof(struct pcb))); } void kgdb_trgt_fetch_registers(int regno __unused) { struct kthr *kt; struct pcb pcb; kt = kgdb_thr_lookup_tid(ptid_get_pid(inferior_ptid)); if (kt == NULL) return; if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) { warnx("kvm_read: %s", kvm_geterr(kvm)); memset(&pcb, 0, sizeof(pcb)); } supply_register(SPARC_SP_REGNUM, (char *)&pcb.pcb_sp); sparc_supply_rwindow(current_regcache, pcb.pcb_sp, -1); supply_register(SPARC64_PC_REGNUM, (char *)&pcb.pcb_pc); pcb.pcb_pc += 4; supply_register(SPARC64_NPC_REGNUM, (char *)&pcb.pcb_pc); } void kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } void kgdb_trgt_new_objfile(struct objfile *objfile) { } struct kgdb_frame_cache { CORE_ADDR pc; CORE_ADDR sp; CORE_ADDR fp; }; static struct kgdb_frame_cache * kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache) { char buf[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; cache = *this_cache; if (cache == NULL) { cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache); *this_cache = cache; cache->pc = frame_func_unwind(next_frame); frame_unwind_register(next_frame, SPARC_SP_REGNUM, buf); cache->sp = extract_unsigned_integer(buf, register_size(current_gdbarch, SPARC_SP_REGNUM)); frame_unwind_register(next_frame, SPARC_FP_REGNUM, buf); cache->fp = extract_unsigned_integer(buf, register_size(current_gdbarch, SPARC_FP_REGNUM)); cache->fp += BIAS - sizeof(struct trapframe); } return (cache); } static void kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, struct frame_id *this_id) { struct kgdb_frame_cache *cache; cache = kgdb_trgt_frame_cache(next_frame, this_cache); *this_id = frame_id_build(cache->sp, cache->pc); } static void kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame, void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, void *valuep) { char dummy_valuep[MAX_REGISTER_SIZE]; struct kgdb_frame_cache *cache; int ofs, regsz; regsz = register_size(current_gdbarch, regnum); if (valuep == NULL) valuep = dummy_valuep; memset(valuep, 0, regsz); *optimizedp = 0; *addrp = 0; *lvalp = not_lval; *realnump = -1; cache = kgdb_trgt_frame_cache(next_frame, this_cache); switch (regnum) { case SPARC_SP_REGNUM: ofs = offsetof(struct trapframe, tf_sp); break; case SPARC64_PC_REGNUM: ofs = offsetof(struct trapframe, tf_tpc); break; case SPARC64_NPC_REGNUM: ofs = offsetof(struct trapframe, tf_tnpc); break; case SPARC_O0_REGNUM: case SPARC_O1_REGNUM: case SPARC_O2_REGNUM: case SPARC_O3_REGNUM: case SPARC_O4_REGNUM: case SPARC_O5_REGNUM: case SPARC_O7_REGNUM: ofs = offsetof(struct trapframe, tf_out) + (regnum - SPARC_O0_REGNUM) * 8; break; default: if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) { ofs = (regnum - SPARC_L0_REGNUM) * 8; *addrp = cache->sp + BIAS + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } return; } *addrp = cache->fp + ofs; *lvalp = lval_memory; target_read_memory(*addrp, valuep, regsz); } static const struct frame_unwind kgdb_trgt_trapframe_unwind = { UNKNOWN_FRAME, &kgdb_trgt_trapframe_this_id, &kgdb_trgt_trapframe_prev_register }; const struct frame_unwind * kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) { char *pname; CORE_ADDR pc; pc = frame_func_unwind(next_frame); pname = NULL; find_pc_partial_function(pc, &pname, NULL, NULL); if (pname == NULL) return (NULL); if (strcmp(pname, "tl0_intr") == 0 || strcmp(pname, "tl0_trap") == 0 || strcmp(pname, "tl1_intr") == 0 || strcmp(pname, "tl1_trap") == 0) return (&kgdb_trgt_trapframe_unwind); /* printf("%s: %lx =%s\n", __func__, pc, pname); */ return (NULL); } + +/* + * This function ensures, that the PC is inside the + * function section which is understood by GDB. + * + * Return 0 when fixup is necessary, -1 otherwise. + */ +int +kgdb_trgt_pc_fixup(CORE_ADDR *pc __unused) +{ + + return (-1); +}