From owner-svn-src-head@freebsd.org Thu Nov 12 22:01:01 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5E596A2D722; Thu, 12 Nov 2015 22:01:01 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3492F1CCC; Thu, 12 Nov 2015 22:01:01 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tACM10NT091550; Thu, 12 Nov 2015 22:01:00 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tACM0xtq091540; Thu, 12 Nov 2015 22:00:59 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201511122200.tACM0xtq091540@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 12 Nov 2015 22:00:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290728 - in head/sys: amd64/include i386/include kern vm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2015 22:01:01 -0000 Author: jhb Date: Thu Nov 12 22:00:59 2015 New Revision: 290728 URL: https://svnweb.freebsd.org/changeset/base/290728 Log: Export various helper variables describing the layout and size of certain kernel structures for use by debuggers. This mostly aids in examining cores from a kernel without debug symbols as a debugger can infer these values if debug symbols are available. One set of variables describes the layout of 'struct linker_file' to walk the list of loaded kernel modules. A second set of variables describes the layout of 'struct proc' and 'struct thread' to walk the list of processes in the kernel and the threads in each process. The 'pcb_size' variable is used to index into the stoppcbs[] array. The 'vm_maxuser_address' is used to distinguish kernel virtual addresses from user addresses. This doesn't have to be perfect, and 'vm_maxuser_address' is a cheap and simple way to differentiate kernel pointers from simple values like TIDs and PIDs. While here, annotate the fields in struct pcb used by kgdb on amd64 and i386 to note that their ABI should be preserved. Annotations for other platforms will be added in the future. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D3773 Modified: head/sys/amd64/include/pcb.h head/sys/i386/include/pcb.h head/sys/kern/kern_linker.c head/sys/kern/kern_mib.c head/sys/kern/kern_proc.c head/sys/vm/vm_kern.c Modified: head/sys/amd64/include/pcb.h ============================================================================== --- head/sys/amd64/include/pcb.h Thu Nov 12 21:37:58 2015 (r290727) +++ head/sys/amd64/include/pcb.h Thu Nov 12 22:00:59 2015 (r290728) @@ -44,15 +44,19 @@ #include #ifdef __amd64__ +/* + * NB: The fields marked with (*) are used by kernel debuggers. Their + * ABI should be preserved. + */ struct pcb { - register_t pcb_r15; - register_t pcb_r14; - register_t pcb_r13; - register_t pcb_r12; - register_t pcb_rbp; - register_t pcb_rsp; - register_t pcb_rbx; - register_t pcb_rip; + register_t pcb_r15; /* (*) */ + register_t pcb_r14; /* (*) */ + register_t pcb_r13; /* (*) */ + register_t pcb_r12; /* (*) */ + register_t pcb_rbp; /* (*) */ + register_t pcb_rsp; /* (*) */ + register_t pcb_rbx; /* (*) */ + register_t pcb_rip; /* (*) */ register_t pcb_fsbase; register_t pcb_gsbase; register_t pcb_kgsbase; Modified: head/sys/i386/include/pcb.h ============================================================================== --- head/sys/i386/include/pcb.h Thu Nov 12 21:37:58 2015 (r290727) +++ head/sys/i386/include/pcb.h Thu Nov 12 22:00:59 2015 (r290728) @@ -44,13 +44,17 @@ #endif #include +/* + * NB: The fields marked with (*) are used by kernel debuggers. Their + * ABI should be preserved. + */ struct pcb { - int pcb_edi; - int pcb_esi; - int pcb_ebp; - int pcb_esp; - int pcb_ebx; - int pcb_eip; + int pcb_edi; /* (*) */ + int pcb_esi; /* (*) */ + int pcb_ebp; /* (*) */ + int pcb_esp; /* (*) */ + int pcb_ebx; /* (*) */ + int pcb_eip; /* (*) */ struct segment_descriptor pcb_fsd; struct segment_descriptor pcb_gsd; int pcb_ds; Modified: head/sys/kern/kern_linker.c ============================================================================== --- head/sys/kern/kern_linker.c Thu Nov 12 21:37:58 2015 (r290727) +++ head/sys/kern/kern_linker.c Thu Nov 12 22:00:59 2015 (r290728) @@ -70,6 +70,12 @@ SYSCTL_INT(_debug, OID_AUTO, kld_debug, &kld_debug, 0, "Set various levels of KLD debug"); #endif +/* These variables are used by kernel debuggers to enumerate loaded files. */ +const int kld_off_address = offsetof(struct linker_file, address); +const int kld_off_filename = offsetof(struct linker_file, filename); +const int kld_off_pathname = offsetof(struct linker_file, pathname); +const int kld_off_next = offsetof(struct linker_file, link.tqe_next); + /* * static char *linker_search_path(const char *name, struct mod_depend * *verinfo); Modified: head/sys/kern/kern_mib.c ============================================================================== --- head/sys/kern/kern_mib.c Thu Nov 12 21:37:58 2015 (r290727) +++ head/sys/kern/kern_mib.c Thu Nov 12 22:00:59 2015 (r290728) @@ -580,6 +580,11 @@ SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)"); +/* Used by kernel debuggers. */ +const int pcb_size = sizeof(struct pcb); +SYSCTL_INT(_debug_sizeof, OID_AUTO, pcb, CTLFLAG_RD, + SYSCTL_NULL_INT_PTR, sizeof(struct pcb), "sizeof(struct pcb)"); + /* XXX compatibility, remove for 6.0 */ #include #include Modified: head/sys/kern/kern_proc.c ============================================================================== --- head/sys/kern/kern_proc.c Thu Nov 12 21:37:58 2015 (r290727) +++ head/sys/kern/kern_proc.c Thu Nov 12 22:00:59 2015 (r290728) @@ -139,6 +139,21 @@ struct sx proctree_lock; struct mtx ppeers_lock; uma_zone_t proc_zone; +/* + * The offset of various fields in struct proc and struct thread. + * These are used by kernel debuggers to enumerate kernel threads and + * processes. + */ +const int proc_off_p_pid = offsetof(struct proc, p_pid); +const int proc_off_p_comm = offsetof(struct proc, p_comm); +const int proc_off_p_list = offsetof(struct proc, p_list); +const int proc_off_p_threads = offsetof(struct proc, p_threads); +const int thread_off_td_tid = offsetof(struct thread, td_tid); +const int thread_off_td_name = offsetof(struct thread, td_name); +const int thread_off_td_oncpu = offsetof(struct thread, td_oncpu); +const int thread_off_td_pcb = offsetof(struct thread, td_pcb); +const int thread_off_td_plist = offsetof(struct thread, td_plist); + int kstack_pages = KSTACK_PAGES; SYSCTL_INT(_kern, OID_AUTO, kstack_pages, CTLFLAG_RD, &kstack_pages, 0, "Kernel stack size in pages"); Modified: head/sys/vm/vm_kern.c ============================================================================== --- head/sys/vm/vm_kern.c Thu Nov 12 21:37:58 2015 (r290727) +++ head/sys/vm/vm_kern.c Thu Nov 12 22:00:59 2015 (r290728) @@ -94,6 +94,9 @@ vm_map_t pipe_map; const void *zero_region; CTASSERT((ZERO_REGION_SIZE & PAGE_MASK) == 0); +/* NB: Used by kernel debuggers. */ +const u_long vm_maxuser_address = VM_MAXUSER_ADDRESS; + SYSCTL_ULONG(_vm, OID_AUTO, min_kernel_address, CTLFLAG_RD, SYSCTL_NULL_ULONG_PTR, VM_MIN_KERNEL_ADDRESS, "Min kernel address");