From owner-svn-src-all@FreeBSD.ORG Wed Jan 21 15:19:38 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BA4D6106567A; Wed, 21 Jan 2009 15:19:38 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A82EF8FC12; Wed, 21 Jan 2009 15:19:38 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0LFJcVT081416; Wed, 21 Jan 2009 15:19:38 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0LFJc3x081415; Wed, 21 Jan 2009 15:19:38 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <200901211519.n0LFJc3x081415@svn.freebsd.org> From: John Baldwin Date: Wed, 21 Jan 2009 15:19:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187532 - stable/7/gnu/usr.bin/gdb/kgdb X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jan 2009 15:19:39 -0000 Author: jhb Date: Wed Jan 21 15:19:38 2009 New Revision: 187532 URL: http://svn.freebsd.org/changeset/base/187532 Log: MFC: Use existing GDB routines for parsing the section table of klds in the 'add-kld' command. Modified: stable/7/gnu/usr.bin/gdb/kgdb/ (props changed) stable/7/gnu/usr.bin/gdb/kgdb/kld.c Modified: stable/7/gnu/usr.bin/gdb/kgdb/kld.c ============================================================================== --- stable/7/gnu/usr.bin/gdb/kgdb/kld.c Wed Jan 21 15:06:53 2009 (r187531) +++ stable/7/gnu/usr.bin/gdb/kgdb/kld.c Wed Jan 21 15:19:38 2009 (r187532) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -196,39 +197,14 @@ find_kld_address (char *arg, CORE_ADDR * return (0); } -struct add_section_info { - struct section_addr_info *section_addrs; - int sect_index; - CORE_ADDR base_addr; -}; - -static void -add_section (bfd *bfd, asection *sect, void *arg) -{ - struct add_section_info *asi = arg; - CORE_ADDR address; - char *name; - - /* Ignore non-resident sections. */ - if ((bfd_get_section_flags(bfd, sect) & (SEC_ALLOC | SEC_LOAD)) == 0) - return; - - name = xstrdup(bfd_get_section_name(bfd, sect)); - make_cleanup(xfree, name); - address = asi->base_addr + bfd_get_section_vma(bfd, sect); - asi->section_addrs->other[asi->sect_index].name = name; - asi->section_addrs->other[asi->sect_index].addr = address; - asi->section_addrs->other[asi->sect_index].sectindex = sect->index; - printf_unfiltered("\t%s_addr = %s\n", name, local_hex_string(address)); - asi->sect_index++; -} - static void load_kld (char *path, CORE_ADDR base_addr, int from_tty) { - struct add_section_info asi; + struct section_addr_info *sap; + struct section_table *sections = NULL, *sections_end = NULL, *s; struct cleanup *cleanup; bfd *bfd; + int i; /* Open the kld. */ bfd = bfd_openr(path, gnutarget); @@ -244,19 +220,30 @@ load_kld (char *path, CORE_ADDR base_add if (bfd_get_section_by_name (bfd, ".text") == NULL) error("\"%s\": can't find text section", path); - printf_unfiltered("add symbol table from file \"%s\" at\n", path); + /* Build a section table from the bfd and relocate the sections. */ + if (build_section_table (bfd, §ions, §ions_end)) + error("\"%s\": can't find file sections", path); + cleanup = make_cleanup(xfree, sections); + for (s = sections; s < sections_end; s++) { + s->addr += base_addr; + s->endaddr += base_addr; + } + + /* Build a section addr info to pass to symbol_file_add(). */ + sap = build_section_addr_info_from_section_table (sections, + sections_end); + cleanup = make_cleanup((make_cleanup_ftype *)free_section_addr_info, + sap); - /* Build a section table for symbol_file_add() from the bfd sections. */ - asi.section_addrs = alloc_section_addr_info(bfd_count_sections(bfd)); - cleanup = make_cleanup(xfree, asi.section_addrs); - asi.sect_index = 0; - asi.base_addr = base_addr; - bfd_map_over_sections(bfd, add_section, &asi); + printf_unfiltered("add symbol table from file \"%s\" at\n", path); + for (i = 0; i < sap->num_sections; i++) + printf_unfiltered("\t%s_addr = %s\n", sap->other[i].name, + local_hex_string(sap->other[i].addr)); if (from_tty && (!query("%s", ""))) error("Not confirmed."); - symbol_file_add(path, from_tty, asi.section_addrs, 0, OBJF_USERLOADED); + symbol_file_add(path, from_tty, sap, 0, OBJF_USERLOADED); do_cleanups(cleanup); }