From owner-p4-projects@FreeBSD.ORG Sun Feb 17 01:49:09 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5606216A468; Sun, 17 Feb 2008 01:49:09 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0266516A41B for ; Sun, 17 Feb 2008 01:49:09 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id D51F113C45B for ; Sun, 17 Feb 2008 01:49:08 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m1H1n8EJ093650 for ; Sun, 17 Feb 2008 01:49:08 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m1H1n8fm093647 for perforce@freebsd.org; Sun, 17 Feb 2008 01:49:08 GMT (envelope-from jb@freebsd.org) Date: Sun, 17 Feb 2008 01:49:08 GMT Message-Id: <200802170149.m1H1n8fm093647@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 135541 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Feb 2008 01:49:09 -0000 http://perforce.freebsd.org/chv.cgi?CH=135541 Change 135541 by jb@jb_freebsd1 on 2008/02/17 01:48:46 Add a linker method to get the CTF data and a function to load it into the elf_file structure. I chose to just include kern_ctf.c in both link_elf.c and link_elf_obj.c so that it doesn't have to exist twice. There is a lot of (annoyingly) similar code in link_elf.c and link_elf_obj.c. To use the CTF data in DDB, we need a clean-room coder to write the code based on what I say the format is. Affected files ... .. //depot/projects/dtrace/src/sys/kern/kern_ctf.c#1 add .. //depot/projects/dtrace/src/sys/kern/kern_linker.c#28 edit .. //depot/projects/dtrace/src/sys/kern/link_elf.c#15 edit .. //depot/projects/dtrace/src/sys/kern/link_elf_obj.c#12 edit .. //depot/projects/dtrace/src/sys/kern/linker_if.m#7 edit .. //depot/projects/dtrace/src/sys/sys/linker.h#19 edit Differences ... ==== //depot/projects/dtrace/src/sys/kern/kern_linker.c#28 (text+ko) ==== @@ -647,6 +647,14 @@ return (0); } +int +linker_ctf_get(linker_file_t file, const uint8_t **data, int *len) +{ + KLD_LOCK_ASSERT(); + + return (LINKER_CTF_GET(file, data, len)); +} + static int linker_file_add_dependency(linker_file_t file, linker_file_t dep) { ==== //depot/projects/dtrace/src/sys/kern/link_elf.c#15 (text+ko) ==== @@ -27,6 +27,7 @@ #include __FBSDID("$FreeBSD: src/sys/kern/link_elf.c,v 1.95 2008/01/13 14:44:09 attilio Exp $"); +#include "opt_ddb.h" #include "opt_gdb.h" #include "opt_mac.h" @@ -98,11 +99,15 @@ long ddbstrcnt; /* number of bytes in string table */ caddr_t symbase; /* malloc'ed symbold base */ caddr_t strbase; /* malloc'ed string base */ + caddr_t ctftab; /* CTF table */ + long ctfcnt; /* number of bytes in CTF table */ #ifdef GDB struct link_map gdb; /* hooks for gdb */ #endif } *elf_file_t; +#include + static int link_elf_link_common_finish(linker_file_t); static int link_elf_link_preload(linker_class_t cls, const char*, linker_file_t*); @@ -138,6 +143,7 @@ KOBJMETHOD(linker_lookup_set, link_elf_lookup_set), KOBJMETHOD(linker_each_function_name, link_elf_each_function_name), KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval), + KOBJMETHOD(linker_ctf_get, link_elf_ctf_get), { 0, 0 } }; @@ -909,6 +915,8 @@ free(ef->symbase, M_LINKER); if (ef->strbase) free(ef->strbase, M_LINKER); + if (ef->ctftab) + free(ef->ctftab, M_LINKER); } static void ==== //depot/projects/dtrace/src/sys/kern/link_elf_obj.c#12 (text+ko) ==== @@ -106,8 +106,13 @@ caddr_t shstrtab; /* Section name string table */ long shstrcnt; /* number of bytes in string table */ + caddr_t ctftab; /* CTF table */ + long ctfcnt; /* number of bytes in CTF table */ + } *elf_file_t; +#include + static int link_elf_link_preload(linker_class_t cls, const char *, linker_file_t *); static int link_elf_link_preload_finish(linker_file_t); @@ -142,6 +147,7 @@ KOBJMETHOD(linker_lookup_set, link_elf_lookup_set), KOBJMETHOD(linker_each_function_name, link_elf_each_function_name), KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval), + KOBJMETHOD(linker_ctf_get, link_elf_ctf_get), { 0, 0 } }; @@ -815,6 +821,8 @@ free(ef->relatab, M_LINKER); if (ef->progtab) free(ef->progtab, M_LINKER); + if (ef->ctftab) + free(ef->ctftab, M_LINKER); if (file->filename != NULL) preload_delete_name(file->filename); /* XXX reclaim module memory? */ @@ -847,6 +855,8 @@ free(ef->ddbstrtab, M_LINKER); if (ef->shstrtab) free(ef->shstrtab, M_LINKER); + if (ef->ctftab) + free(ef->ctftab, M_LINKER); } static const char * ==== //depot/projects/dtrace/src/sys/kern/linker_if.m#7 (text+ko) ==== @@ -96,6 +96,16 @@ }; # +# Load CTF data if necessary and if there is a .SUNW_ctf section +# in the ELF file, returning a pointer to the data and the length. +# +METHOD int ctf_get { + linker_file_t file; + const uint8_t **data; + int *len; +}; + +# # Load a file, returning the new linker_file_t in *result. If # the class does not recognise the file type, zero should be # returned, without modifying *result. If the file is ==== //depot/projects/dtrace/src/sys/sys/linker.h#19 (text+ko) ==== @@ -266,7 +266,7 @@ int elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu); const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx); const char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx); -int sdt_reloc_resolve(uint8_t *, void *); +int linker_ctf_get(linker_file_t, const uint8_t **, int *); int elf_cpu_load_file(linker_file_t); int elf_cpu_unload_file(linker_file_t);