Date: Mon, 9 Feb 2004 00:05:08 -0800 (PST) From: John Merryweather Cooper <coop9211@uidaho.edu> To: FreeBSD-gnats-submit@FreeBSD.org Subject: ports/62570: [NEW PORT] devel/fpc-gdb Message-ID: <20040209080508.ECE4ABAA@borgdemon.losaca.adelphia.net> Resent-Message-ID: <200402090810.i198AN3a072648@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 62570 >Category: ports >Synopsis: [NEW PORT] devel/fpc-gdb >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: maintainer-update >Submitter-Id: current-users >Arrival-Date: Mon Feb 09 00:10:23 PST 2004 >Closed-Date: >Last-Modified: >Originator: John Merryweather Cooper >Release: FreeBSD 4.9-STABLE i386 >Organization: >Environment: System: FreeBSD borgdemon.losaca.adelphia.net 4.9-STABLE FreeBSD 4.9-STABLE #11: Sun Feb 8 00:49:01 PST 2004 root@borgdemon.losaca.adelphia.net:/usr/obj/usr/src/sys/K6-2 i386 >Description: New port devel/fpc-gdb-5.2.1 is GNU GDB 5.2.1 modified for use with Free Pascal and to provide static libraries for linking with editors/fpc-ide. >How-To-Repeat: N/A >Fix: --- new-port-fpc-gdb begins here --- # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # fpc-gdb # fpc-gdb/files # fpc-gdb/files/patch-gdb_i386bsd-nat.c # fpc-gdb/files/patch-gdb_config_i386_fbsd.mh # fpc-gdb/files/patch-gdb_config_i386_nm-fbsd.h # fpc-gdb/files/patch-gdb_config_i386_tm-fbsd.h # fpc-gdb/files/patch-gdb_freebsd-uthread.c # fpc-gdb/files/patch-gdb_kvm-fbsd.c # fpc-gdb/files/patch-gdb_symfile.c # fpc-gdb/files/patch-gdb_target.c # fpc-gdb/files/patch-gdb_target.h # fpc-gdb/files/patch-gdb_version.in # fpc-gdb/files/patch-gdb_config_alpha_fbsd.mh # fpc-gdb/Makefile # fpc-gdb/distinfo # fpc-gdb/pkg-descr # fpc-gdb/pkg-plist # echo c - fpc-gdb mkdir -p fpc-gdb > /dev/null 2>&1 echo c - fpc-gdb/files mkdir -p fpc-gdb/files > /dev/null 2>&1 echo x - fpc-gdb/files/patch-gdb_i386bsd-nat.c sed 's/^X//' >fpc-gdb/files/patch-gdb_i386bsd-nat.c << 'END-of-fpc-gdb/files/patch-gdb_i386bsd-nat.c' X--- gdb/i386bsd-nat.c 2003/05/19 07:22:00 1.1 X+++ gdb/i386bsd-nat.c 2003/05/19 07:22:35 X@@ -305,7 +305,7 @@ X /* For some mysterious reason, some of the reserved bits in the X debug control register get set. Mask these off, otherwise the X ptrace call below will fail. */ X- dbregs.dr7 &= ~(0x0000fc00); X+ DBREG_DRX ((&dbregs), 7) = ~(0x0000fc00); X X DBREG_DRX ((&dbregs), regnum) = value; X X@@ -354,7 +354,7 @@ X return 0; X #endif X X- return dbregs.dr6; X+ return DBREG_DRX ((&dbregs), 6); X } X X #endif /* PT_GETDBREGS */ END-of-fpc-gdb/files/patch-gdb_i386bsd-nat.c echo x - fpc-gdb/files/patch-gdb_config_i386_fbsd.mh sed 's/^X//' >fpc-gdb/files/patch-gdb_config_i386_fbsd.mh << 'END-of-fpc-gdb/files/patch-gdb_config_i386_fbsd.mh' X--- gdb/config/i386/fbsd.mh Thu Jan 17 20:50:59 2002 X+++ gdb/config/i386/fbsd.mh Mon May 27 18:36:20 2002 X@@ -4,4 +4,4 @@ X X NAT_FILE= nm-fbsd.h X # NOTE: Do not spread NATDEPFILES over several lines - it hurts BSD make. X-NATDEPFILES= fork-child.o infptrace.o inftarg.o solib.o solib-svr4.o solib-legacy.o corelow.o core-aout.o core-regset.o i386-nat.o i387-nat.o i386bsd-nat.o i386fbsd-nat.o X+NATDEPFILES= fork-child.o infptrace.o inftarg.o solib.o solib-svr4.o solib-legacy.o corelow.o core-aout.o core-regset.o i386-nat.o i387-nat.o i386bsd-nat.o i386fbsd-nat.o kvm-fbsd.o freebsd-uthread.o xfreemod.o END-of-fpc-gdb/files/patch-gdb_config_i386_fbsd.mh echo x - fpc-gdb/files/patch-gdb_config_i386_nm-fbsd.h sed 's/^X//' >fpc-gdb/files/patch-gdb_config_i386_nm-fbsd.h << 'END-of-fpc-gdb/files/patch-gdb_config_i386_nm-fbsd.h' X--- gdb/config/i386/nm-fbsd.h Sat Jul 21 13:16:44 2001 X+++ gdb/config/i386/nm-fbsd.h Mon Jun 3 10:04:54 2002 X@@ -148,5 +152,32 @@ X #define ld_2 d_sdt X X #endif /* !SVR4_SHARED_LIBS */ X+ X+extern int kernel_debugging; X+extern int kernel_writablecore; X+ X+#if __FreeBSD_version >= 500032 X+#define ADDITIONAL_OPTIONS \ X+ {"kernel", no_argument, &kernel_debugging, 1}, \ X+ {"k", no_argument, &kernel_debugging, 1}, \ X+ {"wcore", no_argument, &kernel_writablecore, 1}, \ X+ {"w", no_argument, &kernel_writablecore, 1}, X+ X+#define ADDITIONAL_OPTION_HELP \ X+ "\ X+ --kernel Enable kernel debugging.\n\ X+ --wcore Make core file writable (only works for /dev/mem).\n\ X+ This option only works while debugging a kernel !!\n\ X+" X+ X+#define DEFAULT_PROMPT kernel_debugging?"(kgdb) ":"(gdb) " X+ X+/* misuse START_PROGRESS to test whether we're running as kgdb */ X+/* START_PROGRESS is called at the top of main */ X+#undef START_PROGRESS X+#define START_PROGRESS(STR,N) \ X+ if (!strcmp(STR, "kgdb")) \ X+ kernel_debugging = 1; X+#endif X X #endif /* NM_FBSD_H */ END-of-fpc-gdb/files/patch-gdb_config_i386_nm-fbsd.h echo x - fpc-gdb/files/patch-gdb_config_i386_tm-fbsd.h sed 's/^X//' >fpc-gdb/files/patch-gdb_config_i386_tm-fbsd.h << 'END-of-fpc-gdb/files/patch-gdb_config_i386_tm-fbsd.h' X--- gdb/config/i386/tm-fbsd.h Sat Jul 28 10:03:38 2001 X+++ gdb/config/i386/tm-fbsd.h Fri Jun 7 08:32:14 2002 X@@ -41,38 +45,42 @@ X /* Support for longjmp. */ X X /* Details about jmp_buf. It's supposed to be an array of integers. */ X- X-#define JB_ELEMENT_SIZE 4 /* Size of elements in jmp_buf. */ X-#define JB_PC 0 /* Array index of saved PC. */ X- X-/* Figure out where the longjmp will land. Store the address that X- longjmp will jump to in *ADDR, and return non-zero if successful. */ X- X #define GET_LONGJMP_TARGET(addr) get_longjmp_target (addr) X-extern int get_longjmp_target (CORE_ADDR *addr); X X X-/* Support for signal handlers. */ X+/* On FreeBSD, sigtramp has size 0x18 and is immediately below the X+ ps_strings struct which has size 0x10 and is at the top of the X+ user stack. */ X+ X+#undef SIGTRAMP_START X+#undef SIGTRAMP_END X+#define SIGTRAMP_START(pc) 0xbfbfdfd8 X+#define SIGTRAMP_END(pc) 0xbfbfdff0 X X-#define IN_SIGTRAMP(pc, name) i386bsd_in_sigtramp (pc, name) X-extern int i386bsd_in_sigtramp (CORE_ADDR pc, char *name); X- X-/* These defines allow the recognition of sigtramps as a function name X- <sigtramp>. X- X- FIXME: kettenis/2001-07-13: These should be added to the target X- vector and turned into functions when we go "multi-arch". */ X- X-#define SIGTRAMP_START(pc) i386bsd_sigtramp_start X-#define SIGTRAMP_END(pc) i386bsd_sigtramp_end X extern CORE_ADDR i386bsd_sigtramp_start; X extern CORE_ADDR i386bsd_sigtramp_end; X+extern CORE_ADDR fbsd_kern_frame_saved_pc(struct frame_info *fr); X X /* Override FRAME_SAVED_PC to enable the recognition of signal handlers. */ X X #undef FRAME_SAVED_PC X-#define FRAME_SAVED_PC(frame) i386bsd_frame_saved_pc (frame) X-extern CORE_ADDR i386bsd_frame_saved_pc (struct frame_info *frame); X+#if __FreeBSD_version >= 500032 X+#define FRAME_SAVED_PC(FRAME) \ X+ (kernel_debugging ? fbsd_kern_frame_saved_pc(FRAME) : \ X+ (((FRAME)->signal_handler_caller \ X+ ? sigtramp_saved_pc (FRAME) \ X+ : read_memory_integer ((FRAME)->frame + 4, 4)) \ X+ )) X+#else X+#define FRAME_SAVED_PC(FRAME) \ X+ (((FRAME)->signal_handler_caller \ X+ ? sigtramp_saved_pc (FRAME) \ X+ : read_memory_integer ((FRAME)->frame + 4, 4)) \ X+ ) X+#endif X+ X+/* Offset to saved PC in sigcontext, from <sys/signal.h>. */ X+#define SIGCONTEXT_PC_OFFSET 20 X X X /* Shared library support. */ END-of-fpc-gdb/files/patch-gdb_config_i386_tm-fbsd.h echo x - fpc-gdb/files/patch-gdb_freebsd-uthread.c sed 's/^X//' >fpc-gdb/files/patch-gdb_freebsd-uthread.c << 'END-of-fpc-gdb/files/patch-gdb_freebsd-uthread.c' X$FreeBSD: ports/devel/gdb52/files/patch-gdb_freebsd-uthread.c,v 1.2 2002/06/08 00:15:19 obrien Exp $ X X--- gdb/freebsd-uthread.c.orig Sat May 25 13:05:56 2002 X+++ gdb/freebsd-uthread.c Sat May 25 13:09:09 2002 X@@ -0,0 +1,915 @@ X+/* $FreeBSD: ports/devel/gdb52/files/patch-gdb_freebsd-uthread.c,v 1.2 2002/06/08 00:15:19 obrien Exp $ */ X+/* Low level interface for debugging FreeBSD user threads for GDB, the GNU debugger. X+ Copyright 1996, 1999 Free Software Foundation, Inc. X+ X+This file is part of GDB. X+ X+This program is free software; you can redistribute it and/or modify X+it under the terms of the GNU General Public License as published by X+the Free Software Foundation; either version 2 of the License, or X+(at your option) any later version. X+ X+This program is distributed in the hope that it will be useful, X+but WITHOUT ANY WARRANTY; without even the implied warranty of X+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X+GNU General Public License for more details. X+ X+You should have received a copy of the GNU General Public License X+along with this program; if not, write to the Free Software X+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ X+ X+/* This module implements a sort of half target that sits between the X+ machine-independent parts of GDB and the ptrace interface (infptrace.c) to X+ provide access to the FreeBSD user-mode thread implementation. X+ X+ FreeBSD threads are true user-mode threads, which are invoked via X+ the pthread_* interfaces. These are mostly implemented in X+ user-space, with all thread context kept in various structures that X+ live in the user's heap. For the most part, the kernel has no X+ knowlege of these threads. X+ X+ Based largely on hpux-thread.c X+ X+ */ X+ X+ X+#include "defs.h" X+#include <sys/queue.h> X+#include <signal.h> X+#include <setjmp.h> X+#include "gdbthread.h" X+#include "target.h" X+#include "inferior.h" X+#include <fcntl.h> X+#include <ucontext.h> X+#include <unistd.h> X+#include <sys/stat.h> X+#include "gdbcore.h" X+ X+extern int child_suppress_run; X+extern struct target_ops child_ops; /* target vector for inftarg.c */ X+ X+extern void _initialize_freebsd_uthread PARAMS ((void)); X+ X+/* Set to true while we are part-way through attaching */ X+static int freebsd_uthread_attaching; X+ X+static int freebsd_uthread_active = 0; X+static CORE_ADDR P_thread_list; X+static CORE_ADDR P_thread_run; X+ X+/* Pointer to the next function on the objfile event chain. */ X+static void (*target_new_objfile_chain) (struct objfile *objfile); X+ X+static void freebsd_uthread_resume PARAMS ((ptid_t pid, int step, X+ enum target_signal signo)); X+ X+static void init_freebsd_uthread_ops PARAMS ((void)); X+ X+static struct target_ops freebsd_uthread_ops; X+ X+static ptid_t find_active_ptid PARAMS ((void)); X+ X+struct cached_pthread { X+ u_int64_t uniqueid; X+ int state; X+ CORE_ADDR name; X+ union { X+ ucontext_t uc; X+ jmp_buf jb; X+ } ctx; X+}; X+ X+static ptid_t cached_ptid; X+static struct cached_pthread cached_pthread; X+static CORE_ADDR cached_pthread_addr; X+ X+LIST_HEAD(idmaplist, idmap); X+ X+struct idmap { X+ LIST_ENTRY(idmap) link; X+ u_int64_t uniqueid; X+ int tid; X+}; X+ X+#define MAPHASH_SIZE 257 X+#define TID_MIN 1 X+#define TID_MAX 16383 X+ X+static int tid_to_hash[TID_MAX + 1]; /* set to map_hash index */ X+static struct idmaplist map_hash[MAPHASH_SIZE]; X+static int next_free_tid = TID_MIN; /* first available tid */ X+static int last_free_tid = TID_MIN; /* first unavailable */ X+ X+static CORE_ADDR P_thread_next_offset; X+static CORE_ADDR P_thread_uniqueid_offset; X+static CORE_ADDR P_thread_state_offset; X+static CORE_ADDR P_thread_name_offset; X+static CORE_ADDR P_thread_ctx_offset; X+static CORE_ADDR P_thread_PS_RUNNING_value; X+static CORE_ADDR P_thread_PS_DEAD_value; X+ X+static int next_offset; X+static int uniqueid_offset; X+static int state_offset; X+static int name_offset; X+static int ctx_offset; X+static int PS_RUNNING_value; X+static int PS_DEAD_value; X+ X+#define UNIQUEID_HASH(id) (id % MAPHASH_SIZE) X+#define TID_ADD1(tid) (((tid) + 1) == TID_MAX + 1 \ X+ ? TID_MIN : (tid) + 1) X+#define IS_TID_FREE(tid) (tid_to_hash[tid] == -1) X+ X+static int X+get_new_tid(int h) X+{ X+ int tid = next_free_tid; X+ X+ tid_to_hash[tid] = h; X+ next_free_tid = TID_ADD1(next_free_tid); X+ if (next_free_tid == last_free_tid) X+ { X+ int i; X+ X+ for (i = last_free_tid; TID_ADD1(i) != last_free_tid; i = TID_ADD1(i)) X+ if (IS_TID_FREE(i)) X+ break; X+ if (TID_ADD1(i) == last_free_tid) X+ { X+ error("too many threads"); X+ return 0; X+ } X+ next_free_tid = i; X+ for (i = TID_ADD1(i); IS_TID_FREE(i); i = TID_ADD1(i)) X+ ; X+ last_free_tid = i; X+ } X+ X+ return tid; X+} X+ X+static ptid_t X+find_ptid(u_int64_t uniqueid) X+{ X+ int h = UNIQUEID_HASH(uniqueid); X+ struct idmap *im; X+ X+ LIST_FOREACH(im, &map_hash[h], link) X+ if (im->uniqueid == uniqueid) X+ return MERGEPID(PIDGET(inferior_ptid), im->tid); X+ X+ im = xmalloc(sizeof(struct idmap)); X+ im->uniqueid = uniqueid; X+ im->tid = get_new_tid(h); X+ LIST_INSERT_HEAD(&map_hash[h], im, link); X+ X+ return MERGEPID(PIDGET(inferior_ptid), im->tid); X+} X+ X+static void X+free_ptid(ptid_t ptid) X+{ X+ int tid = TIDGET(ptid); X+ int h = tid_to_hash[tid]; X+ struct idmap *im; X+ X+ if (!tid) return; X+ X+ LIST_FOREACH(im, &map_hash[h], link) X+ if (im->tid == tid) X+ break; X+ X+ if (!im) return; X+ X+ LIST_REMOVE(im, link); X+ tid_to_hash[tid] = -1; X+ free(im); X+} X+ X+#define READ_OFFSET(field) read_memory(P_thread_##field##_offset, \ X+ (char *) &field##_offset, \ X+ sizeof(field##_offset)) X+ X+#define READ_VALUE(name) read_memory(P_thread_##name##_value, \ X+ (char *) &name##_value, \ X+ sizeof(name##_value)) X+ X+static void X+read_thread_offsets (void) X+{ X+ READ_OFFSET(next); X+ READ_OFFSET(uniqueid); X+ READ_OFFSET(state); X+ READ_OFFSET(name); X+ READ_OFFSET(ctx); X+ X+ READ_VALUE(PS_RUNNING); X+ READ_VALUE(PS_DEAD); X+} X+ X+#define READ_FIELD(ptr, T, field, result) \ X+ read_memory ((ptr) + field##_offset, (char *) &(result), sizeof result) X+ X+static u_int64_t X+read_pthread_uniqueid (CORE_ADDR ptr) X+{ X+ u_int64_t uniqueid; X+ READ_FIELD(ptr, u_int64_t, uniqueid, uniqueid); X+ return uniqueid; X+} X+ X+static CORE_ADDR X+read_pthread_next (CORE_ADDR ptr) X+{ X+ CORE_ADDR next; X+ READ_FIELD(ptr, CORE_ADDR, next, next); X+ return next; X+} X+ X+static void X+read_cached_pthread (CORE_ADDR ptr, struct cached_pthread *cache) X+{ X+ READ_FIELD(ptr, u_int64_t, uniqueid, cache->uniqueid); X+ READ_FIELD(ptr, int, state, cache->state); X+ READ_FIELD(ptr, CORE_ADDR, name, cache->name); X+ READ_FIELD(ptr, ucontext_t, ctx, cache->ctx); X+} X+ X+static ptid_t X+find_active_ptid (void) X+{ X+ CORE_ADDR ptr; X+ X+ read_memory ((CORE_ADDR)P_thread_run, X+ (char *)&ptr, X+ sizeof ptr); X+ X+ return find_ptid(read_pthread_uniqueid(ptr)); X+} X+ X+static CORE_ADDR find_pthread_addr PARAMS ((ptid_t ptid)); X+static struct cached_pthread * find_pthread PARAMS ((ptid_t ptid)); X+ X+static CORE_ADDR X+find_pthread_addr (ptid_t ptid) X+{ X+ CORE_ADDR ptr; X+ X+ if (ptid_equal(ptid, cached_ptid)) X+ return cached_pthread_addr; X+ X+ read_memory ((CORE_ADDR)P_thread_list, X+ (char *)&ptr, X+ sizeof ptr); X+ X+ while (ptr != 0) X+ { X+ if (ptid_equal(find_ptid(read_pthread_uniqueid(ptr)), ptid)) X+ { X+ cached_ptid = ptid; X+ cached_pthread_addr = ptr; X+ read_cached_pthread(ptr, &cached_pthread); X+ return ptr; X+ } X+ ptr = read_pthread_next(ptr); X+ } X+ X+ return NULL; X+} X+ X+static struct cached_pthread * X+find_pthread (ptid_t ptid) X+{ X+ CORE_ADDR ptr; X+ X+ if (ptid_equal(ptid, cached_ptid)) X+ return &cached_pthread; X+ X+ read_memory ((CORE_ADDR)P_thread_list, X+ (char *)&ptr, X+ sizeof ptr); X+ X+ while (ptr != 0) X+ { X+ if (ptid_equal(find_ptid(read_pthread_uniqueid(ptr)), ptid)) X+ { X+ cached_ptid = ptid; X+ cached_pthread_addr = ptr; X+ read_cached_pthread(ptr, &cached_pthread); X+ return &cached_pthread; X+ } X+ ptr = read_pthread_next(ptr); X+ } X+ X+#if 0 X+ error ("Can't find pthread %d,%d", PIDGET(ptid), TIDGET(ptid)); X+#endif X+ return NULL; X+} X+ X+ X+/* Most target vector functions from here on actually just pass through to X+ inftarg.c, as they don't need to do anything specific for threads. */ X+ X+/* ARGSUSED */ X+static void X+freebsd_uthread_open (char *arg, int from_tty) X+{ X+ child_ops.to_open (arg, from_tty); X+} X+ X+/* Attach to process PID, then initialize for debugging it X+ and wait for the trace-trap that results from attaching. */ X+ X+static void X+freebsd_uthread_attach (char *args, int from_tty) X+{ X+ child_ops.to_attach (args, from_tty); X+ push_target (&freebsd_uthread_ops); X+ freebsd_uthread_attaching = 1; X+} X+ X+/* After an attach, see if the target is threaded */ X+ X+static void X+freebsd_uthread_post_attach (int pid) X+{ X+ if (freebsd_uthread_active) X+ { X+ read_thread_offsets (); X+ inferior_ptid = find_active_ptid (); X+ add_thread (inferior_ptid); X+ } X+ else X+ { X+ unpush_target (&freebsd_uthread_ops); X+ push_target (&child_ops); X+ } X+ X+ freebsd_uthread_attaching = 0; X+} X+ X+/* Take a program previously attached to and detaches it. X+ The program resumes execution and will no longer stop X+ on signals, etc. We'd better not have left any breakpoints X+ in the program or it'll die when it hits one. For this X+ to work, it may be necessary for the process to have been X+ previously attached. It *might* work if the program was X+ started via the normal ptrace (PTRACE_TRACEME). */ X+ X+static void X+freebsd_uthread_detach (char *args, int from_tty) X+{ X+ child_ops.to_detach (args, from_tty); X+} X+ X+/* Resume execution of process PID. If STEP is nozero, then X+ just single step it. If SIGNAL is nonzero, restart it with that X+ signal activated. We may have to convert pid from a thread-id to an LWP id X+ for procfs. */ X+ X+static void X+freebsd_uthread_resume (ptid_t ptid, int step, enum target_signal signo) X+{ X+ if (freebsd_uthread_attaching) X+ { X+ child_ops.to_resume (ptid, step, signo); X+ return; X+ } X+ X+ child_ops.to_resume (ptid, step, signo); X+ cached_ptid = MERGEPID(0, 0); X+} X+ X+/* Wait for any threads to stop. We may have to convert PID from a thread id X+ to a LWP id, and vice versa on the way out. */ X+ X+static ptid_t X+freebsd_uthread_wait (ptid_t ptid, struct target_waitstatus *ourstatus) X+{ X+ ptid_t rtnval; X+ X+ if (freebsd_uthread_attaching) X+ { X+ return child_ops.to_wait (ptid, ourstatus); X+ } X+ X+ rtnval = child_ops.to_wait (ptid, ourstatus); X+ X+ if (PIDGET(rtnval) >= 0) X+ { X+ rtnval = find_active_ptid (); X+ if (!in_thread_list (rtnval)) X+ add_thread (rtnval); X+ } X+ X+ return rtnval; X+} X+ X+#ifdef __i386__ X+ X+static char sigmap[MAX_NUM_REGS] = /* map reg to sigcontext */ X+{ X+ 12, /* eax */ X+ 11, /* ecx */ X+ 10, /* edx */ X+ 9, /* ebx */ X+ 8, /* esp */ X+ 7, /* ebp */ X+ 6, /* esi */ X+ 5, /* edi */ X+ 15, /* eip */ X+ 17, /* eflags */ X+ 16, /* cs */ X+ 19, /* ss */ X+ 4, /* ds */ X+ 3, /* es */ X+ 2, /* fs */ X+ 1, /* gs */ X+ -1, -1, -1, -1, -1, -1, -1, /* st0-st7 */ X+ -1, -1, -1, -1, -1, -1, -1, /* fctrl-fop */ X+ -1, -1, -1, -1, -1, -1, -1, /* xmm0-xmm7 */ X+ -1, /* mxcsr */ X+}; X+ X+static char jmpmap[MAX_NUM_REGS] = /* map reg to jmp_buf */ X+{ X+ 6, /* eax */ X+ -1, /* ecx */ X+ -1, /* edx */ X+ 1, /* ebx */ X+ 2, /* esp */ X+ 3, /* ebp */ X+ 4, /* esi */ X+ 5, /* edi */ X+ 0, /* eip */ X+ -1, /* eflags */ X+ -1, /* cs */ X+ -1, /* ss */ X+ -1, /* ds */ X+ -1, /* es */ X+ -1, /* fs */ X+ -1, /* gs */ X+ -1, -1, -1, -1, -1, -1, -1, /* st0-st7 */ X+ -1, -1, -1, -1, -1, -1, -1, /* fctrl-fop */ X+ -1, -1, -1, -1, -1, -1, -1, /* xmm0-xmm7 */ X+ -1, /* mxcsr */ X+}; X+ X+#endif X+ X+#ifdef __alpha__ X+ X+static char sigmap[NUM_REGS] = /* map reg to sigcontext */ X+{ X+ 1, 2, 3, 4, 5, 6, 7, 8, /* v0 - t6 */ X+ 9, 10, 11, 12, 13, 14, 15, 16, /* t7 - fp */ X+ 17, 18, 19, 20, 21, 22, 23, 24, /* a0 - t9 */ X+ 25, 26, 27, 28, 29, 30, 31, 32, /* t10 - zero */ X+ 38, 39, 40, 41, 42, 43, 44, 45, /* f0 - f7 */ X+ 46, 47, 48, 49, 50, 51, 52, 53, /* f8 - f15 */ X+ 54, 55, 56, 57, 58, 59, 60, 61, /* f16 - f23 */ X+ 62, 63, 64, 65, 66, 67, 68, 69, /* f24 - f31 */ X+ 33, -1 /* pc, vfp */ X+}; X+static char jmpmap[NUM_REGS] = { X+ 4, 5, 6, 7, 8, 9, 10, 11, /* v0 - t6 */ X+ 12, 13, 14, 15, 16, 17, 18, 19, /* t7 - fp */ X+ 20, 21, 22, 23, 24, 25, 26, 27, /* a0 - t9 */ X+ 28, 29, 30, 31, 32, 33, 34, 35, /* t10 - zero */ X+ 37, 38, 39, 40, 41, 42, 43, 44, /* f0 - f7 */ X+ 45, 46, 47, 48, 49, 50, 51, 52, /* f8 - f15 */ X+ 53, 54, 55, 56, 57, 58, 59, 60, /* f16 - f23 */ X+ 61, 62, 63, 64, 65, 66, 67, 68, /* f24 - f31 */ X+ 2, -1, /* pc, vfp */ X+}; X+ X+#endif X+ X+static void X+freebsd_uthread_fetch_registers (int regno) X+{ X+ struct cached_pthread *thread; X+ int active; X+ int first_regno, last_regno; X+ register_t *regbase; X+ char *regmap; X+ X+ if (freebsd_uthread_attaching || TIDGET(inferior_ptid) == 0) X+ { X+ child_ops.to_fetch_registers (regno); X+ return; X+ } X+ X+ thread = find_pthread (inferior_ptid); X+ active = (ptid_equal(inferior_ptid, find_active_ptid())); X+ X+ if (active) X+ { X+ child_ops.to_fetch_registers (regno); X+ return; X+ } X+ X+ if (regno == -1) X+ { X+ first_regno = 0; X+ last_regno = NUM_REGS - 1; X+ } X+ else X+ { X+ first_regno = regno; X+ last_regno = regno; X+ } X+ X+ regbase = (register_t*) &thread->ctx.jb[0]; X+ regmap = jmpmap; X+ X+ for (regno = first_regno; regno <= last_regno; regno++) X+ { X+ if (regmap[regno] == -1) X+ child_ops.to_fetch_registers (regno); X+ else X+ if (thread) X+ supply_register (regno, (char*) ®base[regmap[regno]]); X+ else X+ supply_register (regno, NULL); X+ } X+} X+ X+static void X+freebsd_uthread_store_registers (int regno) X+{ X+ struct cached_pthread *thread; X+ CORE_ADDR ptr; X+ int first_regno, last_regno; X+ u_int32_t *regbase; X+ char *regmap; X+ X+ if (freebsd_uthread_attaching) X+ { X+ child_ops.to_store_registers (regno); X+ return; X+ } X+ X+ thread = find_pthread (inferior_ptid); X+ X+ if (thread->state == PS_RUNNING_value) X+ { X+ child_ops.to_store_registers (regno); X+ return; X+ } X+ X+ if (regno == -1) X+ { X+ first_regno = 0; X+ last_regno = NUM_REGS - 1; X+ } X+ else X+ { X+ first_regno = regno; X+ last_regno = regno; X+ } X+ X+ regbase = (u_int32_t*) &thread->ctx.jb[0]; X+ regmap = jmpmap; X+ X+ ptr = find_pthread_addr (inferior_ptid); X+ for (regno = first_regno; regno <= last_regno; regno++) X+ { X+ if (regmap[regno] == -1) X+ child_ops.to_store_registers (regno); X+ else X+ { X+ u_int32_t *reg = ®base[regmap[regno]]; X+ int off; X+ X+ /* Hang onto cached value */ X+ memcpy(reg, registers + REGISTER_BYTE (regno), X+ REGISTER_RAW_SIZE (regno)); X+ X+ /* And push out to inferior */ X+ off = (char *) reg - (char *) thread; X+ write_memory (ptr + off, X+ registers + REGISTER_BYTE (regno), X+ REGISTER_RAW_SIZE (regno)); X+ } X+ } X+} X+ X+/* Get ready to modify the registers array. On machines which store X+ individual registers, this doesn't need to do anything. On machines X+ which store all the registers in one fell swoop, this makes sure X+ that registers contains all the registers from the program being X+ debugged. */ X+ X+static void X+freebsd_uthread_prepare_to_store (void) X+{ X+ child_ops.to_prepare_to_store (); X+} X+ X+static int X+freebsd_uthread_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, X+ int dowrite, struct mem_attrib *attrib, X+ struct target_ops *target) X+{ X+ return child_ops.to_xfer_memory (memaddr, myaddr, len, dowrite, X+ attrib, target); X+} X+ X+/* Print status information about what we're accessing. */ X+ X+static void X+freebsd_uthread_files_info (struct target_ops *ignore) X+{ X+ child_ops.to_files_info (ignore); X+} X+ X+static void X+freebsd_uthread_kill_inferior (void) X+{ X+ child_ops.to_kill (); X+} X+ X+static void X+freebsd_uthread_notice_signals (ptid_t ptid) X+{ X+ child_ops.to_notice_signals (ptid); X+} X+ X+/* Fork an inferior process, and start debugging it with /proc. */ X+ X+static void X+freebsd_uthread_create_inferior (char *exec_file, char *allargs, char **env) X+{ X+ child_ops.to_create_inferior (exec_file, allargs, env); X+ X+ if (PIDGET(inferior_ptid) && freebsd_uthread_active) X+ { X+ read_thread_offsets (); X+ push_target (&freebsd_uthread_ops); X+ inferior_ptid = find_active_ptid (); X+ add_thread (inferior_ptid); X+ } X+} X+ X+/* This routine is called to find out if the inferior is using threads. X+ We check for the _thread_run and _thread_list globals. */ X+ X+void X+freebsd_uthread_new_objfile (struct objfile *objfile) X+{ X+ struct minimal_symbol *ms; X+ X+ if (!objfile) X+ { X+ freebsd_uthread_active = 0; X+ return; X+ } X+ X+ ms = lookup_minimal_symbol ("_thread_run", NULL, objfile); X+ X+ if (!ms) X+ return; X+ X+ P_thread_run = SYMBOL_VALUE_ADDRESS (ms); X+ X+ ms = lookup_minimal_symbol ("_thread_list", NULL, objfile); X+ X+ if (!ms) X+ return; X+ X+ P_thread_list = SYMBOL_VALUE_ADDRESS (ms); X+ X+#define OFFSET_SYM(field) "_thread_" #field "_offset" X+#define LOOKUP_OFFSET(field) \ X+ do { \ X+ ms = lookup_minimal_symbol (OFFSET_SYM(field), NULL, objfile); \ X+ if (!ms) \ X+ return; \ X+ P_thread_##field##_offset = SYMBOL_VALUE_ADDRESS (ms); \ X+ } while (0); X+ X+#define VALUE_SYM(name) "_thread_" #name "_value" X+#define LOOKUP_VALUE(name) \ X+ do { \ X+ ms = lookup_minimal_symbol (VALUE_SYM(name), NULL, objfile); \ X+ if (!ms) \ X+ return; \ X+ P_thread_##name##_value = SYMBOL_VALUE_ADDRESS (ms); \ X+ } while (0); X+ X+ LOOKUP_OFFSET(next); X+ LOOKUP_OFFSET(uniqueid); X+ LOOKUP_OFFSET(state); X+ LOOKUP_OFFSET(name); X+ LOOKUP_OFFSET(ctx); X+ X+ LOOKUP_VALUE(PS_RUNNING); X+ LOOKUP_VALUE(PS_DEAD); X+ X+ freebsd_uthread_active = 1; X+} X+ X+/* Clean up after the inferior dies. */ X+ X+static void X+freebsd_uthread_mourn_inferior () X+{ X+ child_ops.to_mourn_inferior (); X+ unpush_target (&freebsd_uthread_ops); X+} X+ X+/* Mark our target-struct as eligible for stray "run" and "attach" commands. */ X+ X+static int X+freebsd_uthread_can_run () X+{ X+ return child_suppress_run; X+} X+ X+static int X+freebsd_uthread_thread_alive (ptid_t ptid) X+{ X+ struct cached_pthread *thread; X+ int ret = 0; X+ X+ if (freebsd_uthread_attaching) X+ return 1; X+ X+ /* X+ * We can get called from child_ops.to_wait() which passes the underlying X+ * pid (without a thread number). X+ */ X+ if (TIDGET(ptid) == 0) X+ return 1; X+ X+ if (find_pthread_addr (ptid) != 0) X+ { X+ thread = find_pthread (ptid); X+ ret = (thread->state != PS_DEAD_value); X+ } X+ X+ if (!ret) X+ free_ptid(ptid); X+ X+ return ret; X+} X+ X+static void X+freebsd_uthread_stop (void) X+{ X+ child_ops.to_stop (); X+} X+ X+static void X+freebsd_uthread_find_new_threads (void) X+{ X+ CORE_ADDR ptr; X+ int state; X+ u_int64_t uniqueid; X+ X+ read_memory ((CORE_ADDR)P_thread_list, X+ (char *)&ptr, X+ sizeof ptr); X+ X+ while (ptr != 0) X+ { X+ READ_FIELD(ptr, int, state, state); X+ READ_FIELD(ptr, u_int64_t, uniqueid, uniqueid); X+ if (state != PS_DEAD_value && X+ !in_thread_list (find_ptid(uniqueid))) X+ add_thread (find_ptid(uniqueid)); X+ ptr = read_pthread_next(ptr); X+ } X+} X+ X+/* MUST MATCH enum pthread_state */ X+static const char *statenames[] = { X+ "RUNNING", X+ "SIGTHREAD", X+ "MUTEX_WAIT", X+ "COND_WAIT", X+ "FDLR_WAIT", X+ "FDLW_WAIT", X+ "FDR_WAIT", X+ "FDW_WAIT", X+ "POLL_WAIT", X+ "FILE_WAIT", X+ "SELECT_WAIT", X+ "SLEEP_WAIT", X+ "WAIT_WAIT", X+ "SIGSUSPEND", X+ "SIGWAIT", X+ "SPINBLOCK", X+ "JOIN", X+ "SUSPENDED", X+ "DEAD", X+ "DEADLOCK", X+}; X+ X+#if 0 X+ X+static int X+freebsd_uthread_get_thread_info (ref, selection, info) X+ gdb_threadref *ref; X+ int selection; X+ struct gdb_ext_thread_info *info; X+{ X+ int pid = *ref; X+ struct cached_pthread *thread = find_pthread (pid); X+ struct cleanup *old_chain; X+ X+ old_chain = save_inferior_pid (); X+ inferior_pid = main_pid; X+ X+ memset(&info->threadid, 0, OPAQUETHREADBYTES); X+ X+ memcpy(&info->threadid, ref, sizeof *ref); X+ info->active = thread->state == PS_RUNNING_value; X+ strcpy(info->display, statenames[thread->state]); X+ if (thread->name) X+ read_memory ((CORE_ADDR) thread->name, info->shortname, 32); X+ else X+ strcpy(info->shortname, ""); X+ X+ do_cleanups (old_chain); X+ return (0); X+} X+ X+#endif X+ X+char * X+freebsd_uthread_pid_to_str (ptid_t ptid) X+{ X+ static char buf[30]; X+ X+ if (STREQ (current_target.to_shortname, "freebsd-uthreads")) X+ sprintf (buf, "Process %d, Thread %ld", X+ PIDGET(ptid), TIDGET(ptid)); X+ else X+ sprintf (buf, "Process %d", PIDGET(ptid)); X+ X+ return buf; X+} X+ X+ X+static void X+init_freebsd_uthread_ops () X+{ X+ freebsd_uthread_ops.to_shortname = "freebsd-uthreads"; X+ freebsd_uthread_ops.to_longname = "FreeBSD uthreads"; X+ freebsd_uthread_ops.to_doc = "FreeBSD user threads support."; X+ freebsd_uthread_ops.to_open = freebsd_uthread_open; X+ freebsd_uthread_ops.to_attach = freebsd_uthread_attach; X+ freebsd_uthread_ops.to_post_attach = freebsd_uthread_post_attach; X+ freebsd_uthread_ops.to_detach = freebsd_uthread_detach; X+ freebsd_uthread_ops.to_resume = freebsd_uthread_resume; X+ freebsd_uthread_ops.to_wait = freebsd_uthread_wait; X+ freebsd_uthread_ops.to_fetch_registers = freebsd_uthread_fetch_registers; X+ freebsd_uthread_ops.to_store_registers = freebsd_uthread_store_registers; X+ freebsd_uthread_ops.to_prepare_to_store = freebsd_uthread_prepare_to_store; X+ freebsd_uthread_ops.to_xfer_memory = freebsd_uthread_xfer_memory; X+ freebsd_uthread_ops.to_files_info = freebsd_uthread_files_info; X+ freebsd_uthread_ops.to_insert_breakpoint = memory_insert_breakpoint; X+ freebsd_uthread_ops.to_remove_breakpoint = memory_remove_breakpoint; X+ freebsd_uthread_ops.to_terminal_init = terminal_init_inferior; X+ freebsd_uthread_ops.to_terminal_inferior = terminal_inferior; X+ freebsd_uthread_ops.to_terminal_ours_for_output = terminal_ours_for_output; X+ freebsd_uthread_ops.to_terminal_ours = terminal_ours; X+ freebsd_uthread_ops.to_terminal_info = child_terminal_info; X+ freebsd_uthread_ops.to_kill = freebsd_uthread_kill_inferior; X+ freebsd_uthread_ops.to_create_inferior = freebsd_uthread_create_inferior; X+ freebsd_uthread_ops.to_mourn_inferior = freebsd_uthread_mourn_inferior; X+ freebsd_uthread_ops.to_can_run = freebsd_uthread_can_run; X+ freebsd_uthread_ops.to_notice_signals = freebsd_uthread_notice_signals; X+ freebsd_uthread_ops.to_thread_alive = freebsd_uthread_thread_alive; X+ freebsd_uthread_ops.to_stop = freebsd_uthread_stop; X+ freebsd_uthread_ops.to_stratum = process_stratum; X+ freebsd_uthread_ops.to_has_all_memory = 1; X+ freebsd_uthread_ops.to_has_memory = 1; X+ freebsd_uthread_ops.to_has_stack = 1; X+ freebsd_uthread_ops.to_has_registers = 1; X+ freebsd_uthread_ops.to_has_execution = 1; X+ freebsd_uthread_ops.to_has_thread_control = 0; X+ freebsd_uthread_ops.to_magic = OPS_MAGIC; X+ freebsd_uthread_ops.to_find_new_threads = freebsd_uthread_find_new_threads; X+ freebsd_uthread_ops.to_pid_to_str = freebsd_uthread_pid_to_str; X+#if 0 X+ freebsd_uthread_vec.get_thread_info = freebsd_uthread_get_thread_info; X+#endif X+} X+ X+void X+_initialize_freebsd_uthread () X+{ X+ init_freebsd_uthread_ops (); X+ add_target (&freebsd_uthread_ops); X+ X+ target_new_objfile_chain = target_new_objfile_hook; X+ target_new_objfile_hook = freebsd_uthread_new_objfile; X+ X+ child_suppress_run = 1; X+} X END-of-fpc-gdb/files/patch-gdb_freebsd-uthread.c echo x - fpc-gdb/files/patch-gdb_kvm-fbsd.c sed 's/^X//' >fpc-gdb/files/patch-gdb_kvm-fbsd.c << 'END-of-fpc-gdb/files/patch-gdb_kvm-fbsd.c' X--- gdb/kvm-fbsd.c Mon Jun 3 11:32:24 2002 X+++ gdb/kvm-fbsd.c Mon Jun 3 11:30:35 2002 X@@ -0,0 +1,1055 @@ X+/* Live and postmortem kernel debugging functions for FreeBSD. X+ Copyright 1996 Free Software Foundation, Inc. X+ X+This file is part of GDB. X+ X+This program is free software; you can redistribute it and/or modify X+it under the terms of the GNU General Public License as published by X+the Free Software Foundation; either version 2 of the License, or X+(at your option) any later version. X+ X+This program is distributed in the hope that it will be useful, X+but WITHOUT ANY WARRANTY; without even the implied warranty of X+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X+GNU General Public License for more details. X+ X+You should have received a copy of the GNU General Public License X+along with this program; if not, write to the Free Software X+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ X+ X+/* $FreeBSD: ports/devel/gdb52/files/patch-gdb_kvm-fbsd.c,v 1.1 2002/06/06 03:56:34 mp Exp $ */ X+ X+#include "defs.h" X+ X+#include <ctype.h> X+#include <errno.h> X+#include <signal.h> X+#include <fcntl.h> X+#include <paths.h> X+#include <sys/sysctl.h> X+#include <sys/param.h> X+#include <sys/time.h> X+#include <sys/proc.h> X+#include <sys/user.h> X+#include "frame.h" /* required by inferior.h */ X+#include "inferior.h" X+#include "symtab.h" X+#include "symfile.h" X+#include "objfiles.h" X+#include "command.h" X+#include "bfd.h" X+#include "target.h" X+#include "gdbcore.h" X+#include <sys/stat.h> X+#include <unistd.h> X+#include <vm/vm.h> X+#include <vm/vm_param.h> X+ X+#include <machine/vmparam.h> X+#include <machine/pcb.h> X+#include <machine/tss.h> X+#include <machine/frame.h> X+ X+#if __FreeBSD_version >= 500032 && defined(i386) X+#define _KERNEL X+#include <sys/pcpu.h> X+#undef _KERNEL X+ X+static void kcore_files_info PARAMS ((struct target_ops *)); X+ X+static void kcore_close PARAMS ((int)); X+ X+static void get_kcore_registers PARAMS ((int)); X+ X+static int kcore_xfer_kmem PARAMS ((CORE_ADDR, char *, int, int, struct mem_attrib *attrib, struct target_ops *)); X+ X+static int xfer_umem PARAMS ((CORE_ADDR, char *, int, int)); X+ X+static CORE_ADDR ksym_lookup PARAMS ((const char *)); X+ X+static int read_pcb PARAMS ((int, CORE_ADDR)); X+ X+static struct proc * curProc PARAMS ((void)); X+ X+static int set_proc_context PARAMS ((CORE_ADDR paddr)); X+ X+static void kcore_open PARAMS ((char *filename, int from_tty)); X+ X+static void kcore_detach PARAMS ((char *args, int from_tty)); X+ X+static void set_proc_cmd PARAMS ((char *arg, int from_tty)); X+ X+static void set_cpu_cmd PARAMS ((char *arg, int from_tty)); X+ X+static CORE_ADDR kvtophys PARAMS ((int, CORE_ADDR)); X+ X+static int physrd PARAMS ((int, u_int, char*, int)); X+ X+static int kvm_open PARAMS ((const char *efile, char *cfile, char *sfile, X+ int perm, char *errout)); X+ X+static int kvm_close PARAMS ((int fd)); X+ X+static int kvm_write PARAMS ((int core_kd, CORE_ADDR memaddr, X+ char *myaddr, int len)); X+ X+static int kvm_read PARAMS ((int core_kd, CORE_ADDR memaddr, X+ char *myaddr, int len)); X+ X+static int kvm_uread PARAMS ((int core_kd, struct proc *p, X+ CORE_ADDR memaddr, char *myaddr, X+ int len)); X+ X+static int kernel_core_file_hook PARAMS ((int fd, CORE_ADDR addr, X+ char *buf, int len)); X+ X+static CORE_ADDR kvm_getpcpu PARAMS ((int cfd, int cpuid)); X+ X+static struct kinfo_proc * kvm_getprocs PARAMS ((int cfd, int op, X+ CORE_ADDR proc, int *cnt)); X+ X+extern struct target_ops kcore_ops; /* Forward decl */ X+ X+/* Non-zero means we are debugging a kernel core file */ X+int kernel_debugging = 0; X+int kernel_writablecore = 0; X+ X+static char *core_file; X+static int core_kd = -1; X+static struct proc *cur_proc; X+static CORE_ADDR kernel_start; X+ X+static CORE_ADDR pcpu; X+#define PCPU_OFFSET(name) \ X+ offsetof(struct pcpu, pc_ ## name) X+ X+/* X+ * Symbol names of kernel entry points. Use special frames. X+ */ X+#define KSYM_TRAP "calltrap" X+#define KSYM_INTR "Xintr" X+#define KSYM_FASTINTR "Xfastintr" X+#define KSYM_SYSCALL "Xsyscall" X+ X+/* X+ * Read the "thing" at kernel address 'addr' into the space pointed to X+ * by point. The length of the "thing" is determined by the type of p. X+ * Result is non-zero if transfer fails. X+ */ X+#define kvread(addr, p) \ X+ (target_read_memory ((CORE_ADDR)(addr), (char *)(p), sizeof(*(p)))) X+ X+ X+ X+/* X+ * The following is FreeBSD-specific hackery to decode special frames X+ * and elide the assembly-language stub. This could be made faster by X+ * defining a frame_type field in the machine-dependent frame information, X+ * but we don't think that's too important right now. X+ */ X+enum frametype { tf_normal, tf_trap, tf_interrupt, tf_syscall }; X+ X+CORE_ADDR X+fbsd_kern_frame_saved_pc (fr) X+struct frame_info *fr; X+{ X+ struct minimal_symbol *sym; X+ CORE_ADDR this_saved_pc; X+ enum frametype frametype; X+ X+ this_saved_pc = read_memory_integer (fr->frame + 4, 4); X+ sym = lookup_minimal_symbol_by_pc (this_saved_pc); X+ frametype = tf_normal; X+ if (sym != NULL) { X+ if (strcmp (SYMBOL_NAME(sym), KSYM_TRAP) == 0) X+ frametype = tf_trap; X+ else if (strncmp (SYMBOL_NAME(sym), KSYM_INTR, X+ strlen(KSYM_INTR)) == 0 || strncmp (SYMBOL_NAME(sym), X+ KSYM_FASTINTR, strlen(KSYM_FASTINTR)) == 0) X+ frametype = tf_interrupt; X+ else if (strcmp (SYMBOL_NAME(sym), KSYM_SYSCALL) == 0) X+ frametype = tf_syscall; X+ } X+ X+ switch (frametype) { X+ case tf_normal: X+ return (this_saved_pc); X+ X+#define oEIP offsetof(struct trapframe, tf_eip) X+ X+ case tf_trap: X+ return (read_memory_integer (fr->frame + 8 + oEIP, 4)); X+ X+ case tf_interrupt: X+ return (read_memory_integer (fr->frame + 12 + oEIP, 4)); X+ X+ case tf_syscall: X+ return (read_memory_integer (fr->frame + 8 + oEIP, 4)); X+#undef oEIP X+ } X+} X+ X+static CORE_ADDR X+ksym_lookup (name) X+const char *name; X+{ X+ struct minimal_symbol *sym; X+ X+ sym = lookup_minimal_symbol (name, NULL, NULL); X+ if (sym == NULL) X+ error ("kernel symbol `%s' not found.", name); X+ X+ return SYMBOL_VALUE_ADDRESS (sym); X+} X+ X+static struct proc * X+curProc () X+{ X+ struct proc *p; X+ struct thread *td; X+ CORE_ADDR addr = pcpu + PCPU_OFFSET (curthread); X+ X+ if (kvread (addr, &td)) X+ error ("cannot read thread pointer at %x\n", addr); X+ addr = (CORE_ADDR)td + offsetof(struct thread, td_proc); X+ if (kvread (addr, &p)) X+ error ("cannot read proc pointer at %x\n", addr); X+ return p; X+} X+ X+/* X+ * Set the process context to that of the proc structure at X+ * system address paddr. X+ */ X+static int X+set_proc_context (paddr) X+ CORE_ADDR paddr; X+{ X+ struct proc p; X+ X+ if (paddr < kernel_start) X+ return (1); X+ X+ cur_proc = (struct proc *)paddr; X+#ifdef notyet X+ set_kernel_boundaries (cur_proc); X+#endif X+ X+ /* Fetch all registers from core file */ X+ target_fetch_registers (-1); X+ X+ /* Now, set up the frame cache, and print the top of stack */ X+ flush_cached_frames (); X+ set_current_frame (create_new_frame (read_fp (), read_pc ())); X+ select_frame (get_current_frame (), 0); X+ return (0); X+} X+ X+/* Discard all vestiges of any previous core file X+ and mark data and stack spaces as empty. */ X+ X+/* ARGSUSED */ X+static void X+kcore_close (quitting) X+ int quitting; X+{ X+ inferior_ptid = null_ptid; /* Avoid confusion from thread stuff */ X+ X+ if (core_kd) X+ { X+ kvm_close (core_kd); X+ free (core_file); X+ core_file = NULL; X+ core_kd = -1; X+ } X+} X+ X+/* This routine opens and sets up the core file bfd */ X+ X+static void X+kcore_open (filename, from_tty) X+ char *filename; X+ int from_tty; X+{ X+ const char *p; X+ struct cleanup *old_chain; X+ char buf[256], *cp; X+ int ontop; X+ CORE_ADDR addr; X+ struct pcb pcb; X+ X+ target_preopen (from_tty); X+ X+ unpush_target (&kcore_ops); X+ X+ if (!filename) X+ { X+ /*error (core_kd?*/ X+ error ( (core_kd >= 0)? X+ "No core file specified. (Use `detach' to stop debugging a core file.)" X+ : "No core file specified."); X+ } X+ X+ filename = tilde_expand (filename); X+ if (filename[0] != '/') X+ { X+ cp = concat (current_directory, "/", filename, NULL); X+ free (filename); X+ filename = cp; X+ } X+ X+ old_chain = make_cleanup (free, filename); X+ X+ /* X+ * gdb doesn't really do anything if the exec-file couldn't X+ * be opened (in that case exec_bfd is NULL). Usually that's X+ * no big deal, but kvm_open needs the exec-file's name, X+ * which results in dereferencing a NULL pointer, a real NO-NO ! X+ * So, check here if the open of the exec-file succeeded. X+ */ X+ if (exec_bfd == NULL) /* the open failed */ X+ error ("kgdb could not open the exec-file, please check the name you used !"); X+ X+ core_kd = kvm_open (exec_bfd->filename, filename, NULL, X+ kernel_writablecore? O_RDWR : O_RDONLY, "kgdb: "); X+ if (core_kd < 0) X+ perror_with_name (filename); X+ X+ /* Looks semi-reasonable. Toss the old core file and work on the new. */ X+ X+ discard_cleanups (old_chain); /* Don't free filename any more */ X+ core_file = filename; X+ ontop = !push_target (&kcore_ops); X+ X+ kernel_start = bfd_get_start_address (exec_bfd); /* XXX */ X+ X+ /* print out the panic string if there is one */ X+ if (kvread (ksym_lookup ("panicstr"), &addr) == 0 X+ && addr != 0 X+ && target_read_memory (addr, buf, sizeof (buf)) == 0) X+ { X+ for (cp = buf; cp < &buf[sizeof (buf)] && *cp; cp++) X+ if (!isascii (*cp) || (!isprint (*cp) && !isspace (*cp))) X+ *cp = '?'; X+ *cp = '\0'; X+ if (buf[0] != '\0') X+ printf ("panicstr: %s\n", buf); X+ } X+ X+ /* Print all the panic messages if possible. */ X+ if (symfile_objfile != NULL) X+ { X+ printf ("panic messages:\n---\n"); X+ snprintf (buf, sizeof buf, X+ "/sbin/dmesg -N %s -M %s | \ X+ /usr/bin/awk '/^(panic:|Fatal trap) / { printing = 1 } \ X+ { if (printing) print $0 }'", X+ symfile_objfile->name, filename); X+ fflush(stdout); X+ system (buf); X+ printf ("---\n"); X+ } X+ X+ if (!ontop) X+ { X+ warning ("you won't be able to access this core file until you terminate\n\ X+your %s; do ``info files''", target_longname); X+ return; X+ } X+ X+ /* we may need this later */ X+ cur_proc = (struct proc *)curProc (); X+ /* Now, set up the frame cache, and print the top of stack */ X+ flush_cached_frames (); X+ set_current_frame (create_new_frame (read_fp (), read_pc ())); X+ select_frame (get_current_frame (), 0); X+ print_stack_frame (selected_frame, selected_frame_level, 1); X+} X+ X+static void X+kcore_detach (args, from_tty) X+ char *args; X+ int from_tty; X+{ X+ if (args) X+ error ("Too many arguments"); X+ unpush_target (&kcore_ops); X+ reinit_frame_cache (); X+ if (from_tty) X+ printf_filtered ("No kernel core file now.\n"); X+} X+ X+/* Get the registers out of a core file. This is the machine- X+ independent part. Fetch_core_registers is the machine-dependent X+ part, typically implemented in the xm-file for each architecture. */ X+ X+/* We just get all the registers, so we don't use regno. */ X+/* ARGSUSED */ X+static void X+get_kcore_registers (regno) X+ int regno; X+{ X+ struct pcb *pcbaddr; X+ struct thread *mainthread; X+ X+ /* find the pcb for the current process */ X+ if (cur_proc == NULL) X+ error ("get_kcore_registers no proc"); X+ if (kvread (&TAILQ_FIRST(&cur_proc->p_threads), &mainthread)) /* XXXKSE */ X+ error ("cannot read main thread for proc at %#x", cur_proc); X+ if (kvread (&mainthread->td_pcb, &pcbaddr)) /* XXXKSE */ X+ error ("cannot read pcb pointer for proc at %#x", cur_proc); X+ if (read_pcb (core_kd, (CORE_ADDR)pcbaddr) < 0) X+ error ("cannot read pcb at %#x", pcbaddr); X+} X+ X+static void X+kcore_files_info (t) X+ struct target_ops *t; X+{ X+ printf ("\t`%s'\n", core_file); X+} X+ X+static CORE_ADDR X+ksym_maxuseraddr() X+{ X+ static CORE_ADDR maxuseraddr; X+ struct minimal_symbol *sym; X+ X+ if (maxuseraddr == 0) X+ { X+ sym = lookup_minimal_symbol ("PTmap", NULL, NULL); X+ if (sym == NULL) { X+ maxuseraddr = VM_MAXUSER_ADDRESS; X+ } else { X+ maxuseraddr = SYMBOL_VALUE_ADDRESS (sym); X+ } X+ } X+ return maxuseraddr; X+} X+ X+static int X+kcore_xfer_kmem (memaddr, myaddr, len, write, attrib, target) X+ CORE_ADDR memaddr; X+ char *myaddr; X+ int len; X+ int write; X+ struct mem_attrib *attrib; X+ struct target_ops *target; X+{ X+ int ns; X+ int nu; X+ X+ if (memaddr >= ksym_maxuseraddr()) X+ nu = 0; X+ else X+ { X+ nu = xfer_umem (memaddr, myaddr, len, write); X+ if (nu <= 0) X+ return (0); X+ if (nu == len) X+ return (nu); X+ memaddr += nu; X+ if (memaddr != ksym_maxuseraddr()) X+ return (nu); X+ myaddr += nu; X+ len -= nu; X+ } X+ X+ ns = (write ? kvm_write : kvm_read) (core_kd, memaddr, myaddr, len); X+ if (ns < 0) X+ ns = 0; X+ X+ return (nu + ns); X+} X+ X+static int X+xfer_umem (memaddr, myaddr, len, write) X+ CORE_ADDR memaddr; X+ char *myaddr; X+ int len; X+ int write; /* ignored */ X+{ X+ int n; X+ struct proc proc; X+ X+ if (cur_proc == NULL || kvread (cur_proc, &proc)) X+ error ("cannot read proc at %#x", cur_proc); X+ n = kvm_uread (core_kd, &proc, memaddr, myaddr, len) ; X+ X+ if (n < 0) X+ return 0; X+ return n; X+} X+ X+static CORE_ADDR X+ksym_kernbase() X+{ X+ static CORE_ADDR kernbase; X+ struct minimal_symbol *sym; X+ X+ if (kernbase == 0) X+ { X+ sym = lookup_minimal_symbol ("kernbase", NULL, NULL); X+ if (sym == NULL) { X+ kernbase = KERNBASE; X+ } else { X+ kernbase = SYMBOL_VALUE_ADDRESS (sym); X+ } X+ } X+ return kernbase; X+} X+ X+#define KERNOFF (ksym_kernbase()) X+#define INKERNEL(x) ((x) >= KERNOFF) X+ X+static CORE_ADDR sbr; X+static CORE_ADDR curpcb; X+static int found_pcb; X+static int devmem; X+static int kfd; X+static struct pcb pcb; X+ X+static void X+set_proc_cmd (arg, from_tty) X+ char *arg; X+ int from_tty; X+{ X+ CORE_ADDR paddr; X+ struct kinfo_proc *kp; X+ int cnt = 0; X+ X+ if (!arg) X+ error_no_arg ("proc address for new current process"); X+ if (!kernel_debugging) X+ error ("not debugging kernel"); X+ X+ paddr = (CORE_ADDR)parse_and_eval_address (arg); X+ /* assume it's a proc pointer if it's in the kernel */ X+ if (paddr >= kernel_start) { X+ if (set_proc_context(paddr)) X+ error("invalid proc address"); X+ } else { X+ kp = kvm_getprocs(core_kd, KERN_PROC_PID, paddr, &cnt); X+ if (!cnt) X+ error("invalid pid"); X+ if (set_proc_context((CORE_ADDR)kp->ki_paddr)) X+ error("invalid proc address"); X+ } X+} X+ X+static void X+set_cpu_cmd (arg, from_tty) X+ char *arg; X+ int from_tty; X+{ X+ CORE_ADDR paddr; X+ CORE_ADDR pcaddr; X+ struct kinfo_proc *kp; X+ int cpu, cfd; X+ X+ if (!arg) X+ error_no_arg ("cpu number"); X+ if (!kernel_debugging) X+ error ("not debugging kernel"); X+ X+ cfd = core_kd; X+ cpu = (int)parse_and_eval_address (arg); X+ if ((pcaddr = kvm_getpcpu (cfd, cpu)) == NULL) X+ error ("cpu number out of range"); X+ X+ pcpu = pcaddr; X+ curpcb = kvtophys(cfd, pcpu + PCPU_OFFSET (curpcb)); X+ physrd (cfd, curpcb, (char*)&curpcb, sizeof curpcb); X+ X+ if (!devmem) X+ paddr = ksym_lookup ("dumppcb") - KERNOFF; X+ else X+ paddr = kvtophys (cfd, curpcb); X+ read_pcb (cfd, paddr); X+ printf ("initial pcb at %lx\n", (unsigned long)paddr); X+ X+ if ((cur_proc = curProc())) X+ target_fetch_registers (-1); X+ X+ /* Now, set up the frame cache, and print the top of stack */ X+ flush_cached_frames (); X+ set_current_frame (create_new_frame (read_fp (), read_pc ())); X+ select_frame (get_current_frame (), 0); X+ print_stack_frame (selected_frame, selected_frame_level, 1); X+} X+ X+/* substitutes for the stuff in libkvm which doesn't work */ X+/* most of this was taken from the old kgdb */ X+ X+/* we don't need all this stuff, but the call should look the same */ X+ X+static int X+kvm_open (efile, cfile, sfile, perm, errout) X+ const char *efile; X+ char *cfile; X+ char *sfile; /* makes this kvm_open more compatible to the one in libkvm */ X+ int perm; X+ char *errout; /* makes this kvm_open more compatible to the one in libkvm */ X+{ X+ struct stat stb; X+ int cfd; X+ CORE_ADDR paddr; X+ X+ if ((cfd = open (cfile, perm, 0)) < 0) X+ return (cfd); X+ X+ if ((pcpu = kvm_getpcpu (cfd, 0)) == NULL) X+ return (-1); X+ X+ fstat (cfd, &stb); X+ if ((stb.st_mode & S_IFMT) == S_IFCHR X+ && stb.st_rdev == makedev (2, 0)) X+ { X+ devmem = 1; X+ kfd = open (_PATH_KMEM, perm, 0); X+ } X+ X+ physrd (cfd, ksym_lookup ("IdlePTD") - KERNOFF, (char*)&sbr, sizeof sbr); X+ printf ("IdlePTD at phsyical address 0x%08lx\n", (unsigned long)sbr); X+ curpcb = kvtophys(cfd, pcpu + PCPU_OFFSET (curpcb)); X+ physrd (cfd, curpcb, (char*)&curpcb, sizeof curpcb); X+ X+ found_pcb = 1; /* for vtophys */ X+ if (!devmem) X+ paddr = ksym_lookup ("dumppcb") - KERNOFF; X+ else X+ paddr = kvtophys (cfd, curpcb); X+ read_pcb (cfd, paddr); X+ printf ("initial pcb at physical address 0x%08lx\n", (unsigned long)paddr); X+ X+ return (cfd); X+} X+ X+static int X+kvm_close (fd) X+ int fd; X+{ X+ return (close (fd)); X+} X+ X+static int X+kvm_write (core_kd, memaddr, myaddr, len) X+ int core_kd; X+ CORE_ADDR memaddr; X+ char *myaddr; X+{ X+ int cc; X+ X+ if (devmem) X+ { X+ if (kfd > 0) X+ { X+ /* X+ * Just like kvm_read, only we write. X+ */ X+ errno = 0; X+ if (lseek (kfd, (off_t)memaddr, 0) < 0 X+ && errno != 0) X+ { X+ error ("kvm_write:invalid address (%x)", memaddr); X+ return (0); X+ } X+ cc = write (kfd, myaddr, len); X+ if (cc < 0) X+ { X+ error ("kvm_write:write failed"); X+ return (0); X+ } X+ else if (cc < len) X+ error ("kvm_write:short write"); X+ return (cc); X+ } X+ else X+ return (0); X+ } X+ else X+ { X+ printf ("kvm_write not implemented for dead kernels\n"); X+ return (0); X+ } X+ /* NOTREACHED */ X+} X+ X+static int X+kvm_read (core_kd, memaddr, myaddr, len) X+ int core_kd; X+ CORE_ADDR memaddr; X+ char *myaddr; X+{ X+ return (kernel_core_file_hook (core_kd, memaddr, myaddr, len)); X+} X+ X+static int X+kvm_uread (core_kd, p, memaddr, myaddr, len) X+ int core_kd; X+ register struct proc *p; X+ CORE_ADDR memaddr; X+ char *myaddr; X+ int len; X+{ X+ register char *cp; X+ char procfile[MAXPATHLEN]; X+ ssize_t amount; X+ int fd; X+ X+ if (devmem) X+ { X+ sprintf (procfile, "/proc/%d/mem", p->p_pid); X+ fd = open (procfile, O_RDONLY, 0); X+ if (fd < 0) X+ { X+ error ("cannot open %s", procfile); X+ close (fd); X+ return (0); X+ } X+ X+ cp = myaddr; X+ while (len > 0) X+ { X+ errno = 0; X+ if (lseek (fd, (off_t)memaddr, 0) == -1 && errno != 0) X+ { X+ error ("invalid address (%x) in %s", memaddr, procfile); X+ break; X+ } X+ amount = read (fd, cp, len); X+ if (amount < 0) X+ { X+ error ("error reading %s", procfile); X+ break; X+ } X+ if (amount == 0) X+ { X+ error ("EOF reading %s", procfile); X+ break; X+ } X+ cp += amount; X+ memaddr += amount; X+ len -= amount; X+ } X+ X+ close (fd); X+ return ((ssize_t) (cp - myaddr)); X+ } X+ else X+ return (kernel_core_file_hook (core_kd, memaddr, myaddr, len)); X+} X+ X+static struct kinfo_proc kp; X+ X+/* X+ * try to do what kvm_proclist in libkvm would do X+ */ X+static int X+kvm_proclist (cfd, pid, p, cnt) X+int cfd, pid, *cnt; X+struct proc *p; X+{ X+ struct proc lp; X+ X+ for (; p != NULL; p = LIST_NEXT(&lp, p_list)) { X+ if (!kvm_read(cfd, (CORE_ADDR)p, (char *)&lp, sizeof (lp))) X+ return (0); X+ if (lp.p_pid != pid) X+ continue; X+ kp.ki_paddr = p; X+ *cnt = 1; X+ return (1); X+ } X+ *cnt = 0; X+ return (0); X+} X+ X+/* X+ * try to do what kvm_deadprocs in libkvm would do X+ */ X+static struct kinfo_proc * X+kvm_deadprocs (cfd, pid, cnt) X+int cfd, pid, *cnt; X+{ X+ CORE_ADDR allproc, zombproc; X+ struct proc *p; X+ X+ allproc = ksym_lookup("allproc"); X+ if (kvm_read(cfd, allproc, (char *)&p, sizeof (p)) == 0) X+ return (NULL); X+ kvm_proclist (cfd, pid, p, cnt); X+ if (!*cnt) { X+ zombproc = ksym_lookup("zombproc"); X+ if (kvm_read(cfd, zombproc, (char *)&p, sizeof (p)) == 0) X+ return (NULL); X+ kvm_proclist (cfd, pid, p, cnt); X+ } X+ return (&kp); X+} X+ X+static CORE_ADDR X+kvm_getpcpu (cfd, cpuid) X+int cfd, cpuid; X+{ X+ SLIST_HEAD(, pcpu) pcpu_head; X+ struct pcpu lpc; X+ struct pcpu *pc; X+ X+ physrd (cfd, ksym_lookup ("cpuhead") - KERNOFF, (char*)&pcpu_head, X+ sizeof pcpu_head); X+ pc = SLIST_FIRST (&pcpu_head); X+ for (; pc != NULL; pc = SLIST_NEXT (&lpc, pc_allcpu)) X+ { X+ kvm_read (cfd, (CORE_ADDR)pc, (char*)&lpc, sizeof lpc); X+ if (lpc.pc_cpuid == cpuid) X+ break; X+ } X+ X+ return ((CORE_ADDR)pc); X+} X+ X+/* X+ * try to do what kvm_getprocs in libkvm would do X+ */ X+static struct kinfo_proc * X+kvm_getprocs (cfd, op, proc, cnt) X+int cfd, op, *cnt; X+CORE_ADDR proc; X+{ X+ int mib[4], size; X+ X+ *cnt = 0; X+ /* assume it's a pid */ X+ if (devmem) { /* "live" kernel, use sysctl */ X+ mib[0] = CTL_KERN; X+ mib[1] = KERN_PROC; X+ mib[2] = KERN_PROC_PID; X+ mib[3] = (int)proc; X+ size = sizeof (kp); X+ if (sysctl (mib, 4, &kp, &size, NULL, 0) < 0) { X+ perror("sysctl"); X+ *cnt = 0; X+ return (NULL); X+ } X+ if (!size) X+ *cnt = 0; X+ else X+ *cnt = 1; X+ return (&kp); X+ } else X+ return (kvm_deadprocs (cfd, (int)proc, cnt)); X+} X+ X+static int X+physrd (cfd, addr, dat, len) X+ int cfd; X+ u_int addr; X+ char *dat; X+ int len; X+{ X+ if (lseek (cfd, (off_t)addr, L_SET) == -1) X+ return (-1); X+ return (read (cfd, dat, len)); X+} X+ X+static CORE_ADDR X+kvtophys (fd, addr) X+ int fd; X+ CORE_ADDR addr; X+{ X+ CORE_ADDR v; X+ unsigned int pte; X+ static CORE_ADDR PTD = -1; X+ CORE_ADDR current_ptd; X+ X+ /* X+ * We may no longer have a linear system page table... X+ * X+ * Here's the scoop. IdlePTD contains the physical address X+ * of a page table directory that always maps the kernel. X+ * IdlePTD is in memory that is mapped 1-to-1, so we can X+ * find it easily given its 'virtual' address from ksym_lookup(). X+ * For hysterical reasons, the value of IdlePTD is stored in sbr. X+ * X+ * To look up a kernel address, we first convert it to a 1st-level X+ * address and look it up in IdlePTD. This gives us the physical X+ * address of a page table page; we extract the 2nd-level part of X+ * VA and read the 2nd-level pte. Finally, we add the offset part X+ * of the VA into the physical address from the pte and return it. X+ * X+ * User addresses are a little more complicated. If we don't have X+ * a current PCB from read_pcb(), we use PTD, which is the (fixed) X+ * virtual address of the current ptd. Since it's NOT in 1-to-1 X+ * kernel space, we must look it up using IdlePTD. If we do have X+ * a pcb, we get the ptd from pcb_ptd. X+ */ X+ X+ if (INKERNEL (addr)) X+ current_ptd = sbr; X+ else if (found_pcb == 0) X+ { X+ if (PTD == -1) X+ PTD = kvtophys (fd, ksym_lookup ("PTD")); X+ current_ptd = PTD; X+ } X+ else X+ current_ptd = pcb.pcb_cr3; X+ X+ /* X+ * Read the first-level page table (ptd). X+ */ X+ v = current_ptd + ( (unsigned)addr >> PDRSHIFT) * sizeof pte; X+ if (physrd (fd, v, (char *)&pte, sizeof pte) < 0 || (pte&PG_V) == 0) X+ return (~0); X+ X+ if (pte & PG_PS) X+ { X+ /* X+ * No second-level page table; ptd describes one 4MB page. X+ * (We assume that the kernel wouldn't set PG_PS without enabling X+ * it cr0, and that the kernel doesn't support 36-bit physical X+ * addresses). X+ */ X+#define PAGE4M_MASK (NBPDR - 1) X+#define PG_FRAME4M (~PAGE4M_MASK) X+ addr = (pte & PG_FRAME4M) + (addr & PAGE4M_MASK); X+ } X+ else X+ { X+ /* X+ * Read the second-level page table. X+ */ X+ v = (pte&PG_FRAME) + ((addr >> PAGE_SHIFT)&(NPTEPG-1)) * sizeof pte; X+ if (physrd (fd, v, (char *) &pte, sizeof (pte)) < 0 || (pte&PG_V) == 0) X+ return (~0); X+ X+ addr = (pte & PG_FRAME) + (addr & PAGE_MASK); X+ } X+#if 0 X+ printf ("vtophys (%x) -> %x\n", oldaddr, addr); X+#endif X+ return (addr); X+} X+ X+static int X+read_pcb (fd, uaddr) X+ int fd; X+ CORE_ADDR uaddr; X+{ X+ int i; X+ int noreg; X+ CORE_ADDR nuaddr = uaddr; X+ X+ /* need this for the `proc' command to work */ X+ if (INKERNEL(uaddr)) X+ nuaddr = kvtophys(fd, uaddr); X+ X+ if (physrd (fd, nuaddr, (char *)&pcb, sizeof pcb) < 0) X+ { X+ error ("cannot read pcb at %x\n", uaddr); X+ return (-1); X+ } X+ X+ /* X+ * get the register values out of the sys pcb and X+ * store them where `read_register' will find them. X+ */ X+ /* X+ * XXX many registers aren't available. X+ * XXX for the non-core case, the registers are stale - they are for X+ * the last context switch to the debugger. X+ * XXX gcc's register numbers aren't all #defined in tm-i386.h. X+ */ X+ noreg = 0; X+ for (i = 0; i < 3; ++i) /* eax,ecx,edx */ X+ supply_register (i, (char *)&noreg); X+ supply_register (3, (char *)&pcb.pcb_ebx); X+ supply_register (SP_REGNUM, (char *)&pcb.pcb_esp); X+ supply_register (FP_REGNUM, (char *)&pcb.pcb_ebp); X+ supply_register (6, (char *)&pcb.pcb_esi); X+ supply_register (7, (char *)&pcb.pcb_edi); X+ supply_register (PC_REGNUM, (char *)&pcb.pcb_eip); X+ for (i = 9; i < 14; ++i) /* eflags, cs, ss, ds, es, fs */ X+ supply_register (i, (char *)&noreg); X+ supply_register (15, (char *)&pcb.pcb_gs); X+ X+ /* XXX 80387 registers? */ X+} X+ X+/* X+ * read len bytes from kernel virtual address 'addr' into local X+ * buffer 'buf'. Return numbert of bytes if read ok, 0 otherwise. On read X+ * errors, portion of buffer not read is zeroed. X+ */ X+ X+static int X+kernel_core_file_hook (fd, addr, buf, len) X+ int fd; X+ CORE_ADDR addr; X+ char *buf; X+ int len; X+{ X+ int i; X+ CORE_ADDR paddr; X+ register char *cp; X+ int cc; X+ X+ cp = buf; X+ X+ while (len > 0) X+ { X+ paddr = kvtophys (fd, addr); X+ if (paddr == ~0) X+ { X+ memset (buf, '\000', len); X+ break; X+ } X+ /* we can't read across a page boundary */ X+ i = min (len, PAGE_SIZE - (addr & PAGE_MASK)); X+ if ( (cc = physrd (fd, paddr, cp, i)) <= 0) X+ { X+ memset (cp, '\000', len); X+ return (cp - buf); X+ } X+ cp += cc; X+ addr += cc; X+ len -= cc; X+ } X+ return (cp - buf); X+} X+ X+static struct target_ops kcore_ops; X+ X+#else X+int kernel_debugging = 0; X+#endif X+ X+void X+_initialize_kcorelow() X+{ X+#if __FreeBSD_version >= 500032 && defined(i386) X+ kcore_ops.to_shortname = "kcore"; X+ kcore_ops.to_longname = "Kernel core dump file"; X+ kcore_ops.to_doc = X+ "Use a core file as a target. Specify the filename of the core file."; X+ kcore_ops.to_open = kcore_open; X+ kcore_ops.to_close = kcore_close; X+ kcore_ops.to_attach = find_default_attach; X+ kcore_ops.to_detach = kcore_detach; X+ kcore_ops.to_fetch_registers = get_kcore_registers; X+ kcore_ops.to_xfer_memory = kcore_xfer_kmem; X+ kcore_ops.to_files_info = kcore_files_info; X+ kcore_ops.to_create_inferior = find_default_create_inferior; X+ kcore_ops.to_stratum = kcore_stratum; X+ kcore_ops.to_has_memory = 1; X+ kcore_ops.to_has_stack = 1; X+ kcore_ops.to_has_registers = 1; X+ kcore_ops.to_magic = OPS_MAGIC; X+ X+ add_target (&kcore_ops); X+ add_com ("proc", class_obscure, set_proc_cmd, "Set current process context"); X+ add_com ("cpu", class_obscure, set_cpu_cmd, "Set current cpu"); X+#endif X+} END-of-fpc-gdb/files/patch-gdb_kvm-fbsd.c echo x - fpc-gdb/files/patch-gdb_symfile.c sed 's/^X//' >fpc-gdb/files/patch-gdb_symfile.c << 'END-of-fpc-gdb/files/patch-gdb_symfile.c' X--- gdb/symfile.c Tue Feb 26 17:40:36 2002 X+++ gdb/symfile.c Wed May 29 11:10:17 2002 X@@ -1546,11 +1546,7 @@ X char *val = sect_opts[i].value; X char *sec = sect_opts[i].name; X X- val = sect_opts[i].value; X- if (val[0] == '0' && val[1] == 'x') X- addr = strtoul (val+2, NULL, 16); X- else X- addr = strtoul (val, NULL, 10); X+ addr = parse_and_eval_address(val); X X /* Here we store the section offsets in the order they were X entered on the command line. */ END-of-fpc-gdb/files/patch-gdb_symfile.c echo x - fpc-gdb/files/patch-gdb_target.c sed 's/^X//' >fpc-gdb/files/patch-gdb_target.c << 'END-of-fpc-gdb/files/patch-gdb_target.c' X--- gdb/target.c.orig Thu Jan 31 17:01:21 2002 X+++ gdb/target.c Fri Jun 7 16:36:06 2002 X@@ -1361,7 +1361,11 @@ X for (t = target_structs; t < target_structs + target_struct_size; X ++t) X { X+#if defined(__FreeBSD__) && defined(__i386__) X+ if ((*t)->to_stratum == (kernel_debugging ? kcore_stratum : core_stratum)) X+#else X if ((*t)->to_stratum == core_stratum) X+#endif X { X runable = *t; X ++count; END-of-fpc-gdb/files/patch-gdb_target.c echo x - fpc-gdb/files/patch-gdb_target.h sed 's/^X//' >fpc-gdb/files/patch-gdb_target.h << 'END-of-fpc-gdb/files/patch-gdb_target.h' X--- gdb/target.h Sat Feb 9 20:08:42 2002 X+++ gdb/target.h Fri May 24 08:38:31 2002 X@@ -52,6 +52,7 @@ X dummy_stratum, /* The lowest of the low */ X file_stratum, /* Executable files, etc */ X core_stratum, /* Core dump files */ X+ kcore_stratum, /* Kernel core files */ X download_stratum, /* Downloading of remote targets */ X process_stratum, /* Executing processes */ X thread_stratum /* Executing threads */ END-of-fpc-gdb/files/patch-gdb_target.h echo x - fpc-gdb/files/patch-gdb_version.in sed 's/^X//' >fpc-gdb/files/patch-gdb_version.in << 'END-of-fpc-gdb/files/patch-gdb_version.in' X--- gdb/version.in Fri Apr 26 18:04:22 2002 X+++ gdb/version.in Mon Jun 3 08:14:54 2002 X@@ -1 +1 @@ X-5.2 X+5.2 (FreeBSD) END-of-fpc-gdb/files/patch-gdb_version.in echo x - fpc-gdb/files/patch-gdb_config_alpha_fbsd.mh sed 's/^X//' >fpc-gdb/files/patch-gdb_config_alpha_fbsd.mh << 'END-of-fpc-gdb/files/patch-gdb_config_alpha_fbsd.mh' X--- gdb/config/alpha/fbsd.mh Sat Jan 19 17:12:50 2002 X+++ gdb/config/alpha/fbsd.mh Mon Jun 3 08:03:39 2002 X@@ -1,5 +1,5 @@ X # Host: FreeBSD/Alpha X NATDEPFILES= fork-child.o infptrace.o inftarg.o \ X solib.o solib-svr4.o solib-legacy.o \ X- corelow.o core-regset.o alphabsd-nat.o X+ corelow.o core-regset.o alphabsd-nat.o freebsd-uthread.o X NAT_FILE= nm-fbsd.h END-of-fpc-gdb/files/patch-gdb_config_alpha_fbsd.mh echo x - fpc-gdb/Makefile sed 's/^X//' >fpc-gdb/Makefile << 'END-of-fpc-gdb/Makefile' X# ex:ts=8 X# Ports collection makefile for: FPC-GDB 5.2.1 X# Date created: 8 February 2004 X# Whom: John Merryweather Cooper <coop9211@uidaho.edu> X# X# $FreeBSD$ X# X XPORTNAME= gdb XPORTVERSION= 5.2.1 XCATEGORIES= devel lang XMASTER_SITES= ${MASTER_SITE_SOURCEWARE} XMASTER_SITE_SUBDIR= gdb/releases XPKGNAMEPREFIX= fpc- X XPATCH_SITES= ftp://ftp.freepascal.org/fpc/contrib/libgdb/v5.2.1 \ X http://planetmirror.com/pub/fpc/contrib/libgdb/v5.2.1/ \ X ftp://ftp.jp.freepascal.org/mirror/fpc/contrib/libgdb/v5.2.1/ \ X ftp://freepascal.stack.nl/pub/fpc/contrib/libgdb/v5.2.1/ \ X ftp://ftp.no.freepascal.org/pub/fpc/contrib/libgdb/v5.2.1/ \ X ftp://ftp.us.freepascal.org/pub/fpc/contrib/libgdb/v5.2.1/ \ X ${MASTER_SITE_LOCAL} XPATCH_SITE_SUBDIR= obrien XPATCHFILES= gdb521.dif gdb521_xfree-loadmod.diff X XMAINTAINER= coop9211@uidaho.edu XCOMMENT= GNU GDB 5.2.1 modified for Free Pascal X X.include <bsd.port.pre.mk> X XNO_LATEST_LINK= yes XUSE_GMAKE= yes XGNU_CONFIGURE= yes XUSE_REINPLACE= yes XCONFIGURE_ARGS= --program-suffix=fpc XAR?= /usr/bin/ar X Xpre-configure: X cd ${WRKSRC} ; ${RM} -rf dejagnu expect sim tcl texinfo X Xpost-configure: X# if devel/bison is installed, build will fail --> force yacc X @${FIND} ${WRKSRC} -name "Makefile*" | ${XARGS} \ X ${REINPLACE_CMD} 's|bison -y|yacc|g' X Xdo-install: X @${INSTALL_PROGRAM} ${WRKSRC}/gdb/gdb \ X ${PREFIX}/bin/gdbfpc X cd ${WRKSRC}/gdb && ${AR} -rs libgdb.a cli*.o mi*.o X cd ${WRKSRC}/bfd && ${AR} -rs libbfd.a *.o X cd ${WRKSRC}/opcodes && ${AR} -rs libopcodes.a *.o X @${MKDIR} ${PREFIX}/lib/fpc/1.0.10/units/freebsd/gdbint/libgdb X @${INSTALL_DATA} \ X ${WRKSRC}/gdb/libgdb.a \ X ${WRKSRC}/bfd/libbfd.a \ X ${WRKSRC}/opcodes/libopcodes.a \ X ${WRKSRC}/libiberty/libiberty.a \ X ${WRKSRC}/intl/libintl.a \ X ${PREFIX}/lib/fpc/1.0.10/units/freebsd/gdbint/libgdb X Xcklatest: X ncftpls \ X ftp://mirrors.rcn.net/mirrors/sources.redhat.com/${MASTER_SITE_SUBDIR}/ \ X | ${GREP} gdb+dejagnu- X X.include <bsd.port.post.mk> END-of-fpc-gdb/Makefile echo x - fpc-gdb/distinfo sed 's/^X//' >fpc-gdb/distinfo << 'END-of-fpc-gdb/distinfo' XMD5 (gdb-5.2.1.tar.gz) = e9766842f1bbc6c2353de1410d8c0de0 XSIZE (gdb-5.2.1.tar.gz) = 14715792 XMD5 (gdb521.dif) = a83edfef16ee5b78c97517588459bbe2 XSIZE (gdb521.dif) = 19633 XMD5 (gdb521_xfree-loadmod.diff) = 0cafd6520d86caa207a2f7a54f981d06 XSIZE (gdb521_xfree-loadmod.diff) = 29594 END-of-fpc-gdb/distinfo echo x - fpc-gdb/pkg-descr sed 's/^X//' >fpc-gdb/pkg-descr << 'END-of-fpc-gdb/pkg-descr' XGNU GDB 5.2.1 modified to work with Free Pascal. X XWWW: http://www.freepascal.org/ X X-- XJohn Merryweather Cooper <coop9211@uidaho.edu> END-of-fpc-gdb/pkg-descr echo x - fpc-gdb/pkg-plist sed 's/^X//' >fpc-gdb/pkg-plist << 'END-of-fpc-gdb/pkg-plist' Xbin/gdbfpc Xlib/fpc/1.0.10/units/freebsd/gdbint/libgdb/libbfd.a Xlib/fpc/1.0.10/units/freebsd/gdbint/libgdb/libgdb.a Xlib/fpc/1.0.10/units/freebsd/gdbint/libgdb/libiberty.a Xlib/fpc/1.0.10/units/freebsd/gdbint/libgdb/libintl.a Xlib/fpc/1.0.10/units/freebsd/gdbint/libgdb/libopcodes.a X@dirrm lib/fpc/1.0.10/units/freebsd/gdbint/libgdb X@dirrm lib/fpc/1.0.10/units/freebsd/gdbint X@dirrm lib/fpc/1.0.10/units/freebsd X@dirrm lib/fpc/1.0.10/units X@dirrm lib/fpc/1.0.10 X@dirrm lib/fpc END-of-fpc-gdb/pkg-plist exit --- new-port-fpc-gdb ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040209080508.ECE4ABAA>