Version 0.127:
+libdw: new function dwarf_getsrcdirs
+
libdwfl: new functions dwfl_module_addrsym, dwfl_report_begin_add
Version 0.126:
+2007-04-16 Roland McGrath <roland@redhat.com>
+
+ * libdw.map (ELFUTILS_0.127): Add dwfl_module_address_section.
+
2007-04-05 Roland McGrath <roland@redhat.com>
+ * dwarf_getsrcdirs.c: New file.
+ * Makefile.am (libdw_a_SOURCES): Add it.
+ * libdw.h: Declare dwarf_getsrcdirs.
+ * libdw.map (ELFUTILS_0.127): Add it.
+
+ * libdwP.h (struct Dwarf_Files_s): New member ndirs.
+ * dwarf_getsrclines.c (dwarf_getsrclines): Don't clobber NDIRLIST to
+ zero before we use it to check for DWARF_E_INVALID_DIR_IDX.
+ Save DIRARRAY in the Dwarf_Files.
+
* dwarf_ranges.c (dwarf_ranges): Don't sign-extend 32-bit BEGIN
address to check for all-ones base address entry. Check directly.
Reported by Sébastien Dugué <sebastien.dugue@bull.net>.
## Process this file with automake to create Makefile.in
##
-## Copyright (C) 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
+## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
## This file is part of Red Hat elfutils.
##
## Red Hat elfutils is free software; you can redistribute it and/or modify
dwarf_lineendsequence.c dwarf_lineblock.c \
dwarf_lineprologueend.c dwarf_lineepiloguebegin.c \
dwarf_onesrcline.c dwarf_formblock.c \
- dwarf_getsrcfiles.c dwarf_filesrc.c \
+ dwarf_getsrcfiles.c dwarf_filesrc.c dwarf_getsrcdirs.c \
dwarf_getlocation.c dwarf_getstring.c dwarf_offabbrev.c \
dwarf_getaranges.c dwarf_onearange.c dwarf_getarangeinfo.c \
dwarf_getarange_addr.c dwarf_getattrs.c dwarf_formflag.c \
--- /dev/null
+/* Find include directories in source file information.
+ Copyright (C) 2007 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ In addition, as a special exception, Red Hat, Inc. gives You the
+ additional right to link the code of Red Hat elfutils with code licensed
+ under any Open Source Initiative certified open source license
+ (http://www.opensource.org/licenses/index.php) which requires the
+ distribution of source code with any binary distribution and to
+ distribute linked combinations of the two. Non-GPL Code permitted under
+ this exception must only link to the code of Red Hat elfutils through
+ those well defined interfaces identified in the file named EXCEPTION
+ found in the source code files (the "Approved Interfaces"). The files
+ of Non-GPL Code may instantiate templates or use macros or inline
+ functions from the Approved Interfaces without causing the resulting
+ work to be covered by the GNU General Public License. Only Red Hat,
+ Inc. may make changes or additions to the list of Approved Interfaces.
+ Red Hat's grant of this exception is conditioned upon your not adding
+ any new exceptions. If you wish to add a new Approved Interface or
+ exception, please contact Red Hat. You must obey the GNU General Public
+ License in all respects for all of the Red Hat elfutils code and other
+ code used in conjunction with Red Hat elfutils except the Non-GPL Code
+ covered by this exception. If you modify this file, you may extend this
+ exception to your version of the file, but you are not obligated to do
+ so. If you do not wish to provide this exception without modification,
+ you must delete this exception statement from your version and license
+ this file solely under the GPL without exception.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "libdwP.h"
+
+
+int
+dwarf_getsrcdirs (files, result, ndirs)
+ Dwarf_Files *files;
+ const char *const **result;
+ size_t *ndirs;
+{
+ if (files == NULL)
+ return -1;
+
+ *result = (void *) &files->info[files->nfiles];
+ *ndirs = files->ndirs;
+ return 0;
+}
/* Return line number information of CU.
- Copyright (C) 2004, 2005 Red Hat, Inc.
+ Copyright (C) 2004, 2005, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2004.
/* Rearrange the list in array form. */
struct dirlist **dirarray
= (struct dirlist **) alloca (ndirlist * sizeof (*dirarray));
- while (ndirlist-- > 0)
- {
- dirarray[ndirlist] = dirlist;
- dirlist = dirlist->next;
- }
+ for (unsigned int n = ndirlist; n-- > 0; dirlist = dirlist->next)
+ dirarray[n] = dirlist;
- /* Now read the files. */
+ /* Now read the files. */
struct filelist null_file =
{
.info =
/* Put all the files in an array. */
Dwarf_Files *files = libdw_alloc (dbg, Dwarf_Files,
sizeof (Dwarf_Files)
- + nfilelist * sizeof (Dwarf_Fileinfo),
- 1);
+ + nfilelist * sizeof (Dwarf_Fileinfo)
+ + (ndirlist + 1) * sizeof (char *),
+ 1);
+ const char **dirs = (void *) &files->info[nfilelist];
+
files->nfiles = nfilelist;
while (nfilelist-- > 0)
{
}
assert (filelist == NULL);
+ /* Put all the directory strings in an array. */
+ files->ndirs = ndirlist;
+ for (unsigned int i = 0; i < ndirlist; ++i)
+ dirs[i] = dirarray[i]->dir;
+ dirs[ndirlist] = NULL;
+
/* Remember the debugging descriptor. */
files->dbg = dbg;
/* Interfaces for libdw.
- Copyright (C) 2002, 2004, 2005, 2006 Red Hat, Inc.
+ Copyright (C) 2002, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Red Hat elfutils is free software; you can redistribute it and/or modify
extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx,
Dwarf_Word *mtime, Dwarf_Word *length);
+/* Return the directory list used in the file information extracted.
+ (*RESULT)[0] is the CU's DW_AT_comp_dir value, and may be null.
+ (*RESULT)[0..*NDIRS-1] are the compile-time include directory path
+ encoded by the compiler. */
+extern int dwarf_getsrcdirs (Dwarf_Files *files,
+ const char *const **result, size_t *ndirs)
+ __nonnull_attribute__ (2, 3);
+
/* Return location expression, decoded as a list of operations. */
extern int dwarf_getlocation (Dwarf_Attribute *attr, Dwarf_Op **expr,
ELFUTILS_0.127 {
global:
+ dwarf_getsrcdirs;
+
dwfl_module_addrsym;
dwfl_report_begin_add;
+ dwfl_module_address_section;
local:
*;
/* Internal definitions for libdwarf.
- Copyright (C) 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2002.
struct Dwarf_Files_s
{
Dwarf *dbg;
+ unsigned int ndirs;
unsigned int nfiles;
struct Dwarf_Fileinfo_s
{
Dwarf_Word mtime;
Dwarf_Word length;
} info[0];
+ /* nfiles of those, followed by char *[ndirs]. */
};
typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo;
+2007-04-16 Roland McGrath <roland@redhat.com>
+
+ * derelocate.c (cache_sections): Apply bias to sh_addr.
+ (compare_secrefs): Fix address comparison to avoid signed overflow.
+ (find_section): New function, broken out of ...
+ (dwfl_module_relocate_address): ... here, call it.
+ (check_module): New function, broken out of ...
+ (dwfl_module_relocate_address): ... here, call it.
+ (dwfl_module_address_section): New function.
+ * libdwfl.h: Declare it.
+
2007-03-26 Roland McGrath <roland@redhat.com>
* dwfl_module.c (__libdwfl_module_free): Free MOD itself.
struct secref *const *p1 = a;
struct secref *const *p2 = b;
- return (*p1)->start - (*p2)->start;
+ /* No signed difference calculation is correct here, since the
+ terms are unsigned and could be more than INT64_MAX apart. */
+ if ((*p1)->start < (*p2)->start)
+ return -1;
+ if ((*p1)->start > (*p2)->start)
+ return 1;
+
+ return 0;
}
static int
struct secref *newref = alloca (sizeof *newref);
newref->scn = scn;
newref->name = name;
- newref->start = shdr->sh_addr;
- newref->end = shdr->sh_addr + shdr->sh_size;
+ newref->start = shdr->sh_addr + mod->symfile->bias;
+ newref->end = newref->start + shdr->sh_size;
newref->next = refs;
refs = newref;
++nrefs;
return sections->refs[idx].name;
}
-int
-dwfl_module_relocate_address (Dwfl_Module *mod, Dwarf_Addr *addr)
+/* Check that MOD is valid and make sure its relocation has been done. */
+static bool
+check_module (Dwfl_Module *mod)
{
- if (mod == NULL)
- return -1;
+ if (INTUSE(dwfl_module_getsymtab) (mod) < 0)
+ {
+ Dwfl_Error error = dwfl_errno ();
+ if (error != DWFL_E_NO_SYMTAB)
+ {
+ __libdwfl_seterrno (error);
+ return true;
+ }
+ }
if (mod->dw == NULL)
{
Dwarf_Addr bias;
if (INTUSE(dwfl_module_getdwarf) (mod, &bias) == NULL)
- return -1;
+ {
+ Dwfl_Error error = dwfl_errno ();
+ if (error != DWFL_E_NO_DWARF)
+ {
+ __libdwfl_seterrno (error);
+ return true;
+ }
+ }
}
- if (mod->e_type != ET_REL)
- {
- *addr -= mod->debug.bias;
- return 0;
- }
+ return false;
+}
+/* Find the index in MOD->reloc_info.refs containing *ADDR. */
+static int
+find_section (Dwfl_Module *mod, Dwarf_Addr *addr)
+{
if (unlikely (mod->reloc_info == NULL) && cache_sections (mod) < 0)
return -1;
__libdw_seterrno (DWARF_E_NO_MATCH);
return -1;
}
+
+int
+dwfl_module_relocate_address (Dwfl_Module *mod, Dwarf_Addr *addr)
+{
+ if (check_module (mod))
+ return -1;
+
+ if (mod->e_type != ET_REL)
+ {
+ *addr -= mod->debug.bias;
+ return 0;
+ }
+
+ return find_section (mod, addr);
+}
INTDEF (dwfl_module_relocate_address)
+
+Elf_Scn *
+dwfl_module_address_section (Dwfl_Module *mod, Dwarf_Addr *address,
+ Dwarf_Addr *bias)
+{
+ if (check_module (mod))
+ return NULL;
+
+ int idx = find_section (mod, address);
+ if (idx < 0)
+ return NULL;
+
+ *bias = mod->symfile->bias;
+ return mod->reloc_info->refs[idx].scn;
+}
GElf_Sym *sym, GElf_Word *shndxp)
__nonnull_attribute__ (3);
+/* Find the ELF section that *ADDRESS lies inside and return it.
+ On success, adjusts *ADDRESS to be relative to the section,
+ and sets *BIAS to the difference between addresses used in
+ the returned section's headers and run-time addresses. */
+extern Elf_Scn *dwfl_module_address_section (Dwfl_Module *mod,
+ Dwarf_Addr *address,
+ Dwarf_Addr *bias)
+ __nonnull_attribute__ (2, 3);
+
/*** Dwarf access functions ***/
+2007-04-16 Roland McGrath <roland@redhat.com>
+
+ * dwfl-addr-sect.c: New file.
+ * Makefile.am (noinst_PROGRAMS): Add it.
+ (dwfl_addr_sect_LDADD): New variable.
+
+2007-04-05 Roland McGrath <roland@redhat.com>
+
+ * get-files.c: Test dwarf_getsrcdirs.
+ * run-get-files.sh: Update expected output.
+
2007-04-01 Roland McGrath <roland@redhat.com>
* run-allregs.sh: Updated expected output for x86_64.
get-aranges allfcts line2addr addrscopes funcscopes \
show-abbrev hash newscn ecp dwflmodtest \
find-prologues funcretval allregs rdwrmmap \
- dwfl-bug-addr-overflow arls dwfl-bug-fd-leak
+ dwfl-bug-addr-overflow arls dwfl-bug-fd-leak \
+ dwfl-addr-sect
# get-ciefde
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
dwfl_bug_addr_overflow_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
arls_LDADD = $(libelf) $(libmudflap)
dwfl_bug_fd_leak_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
+dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
CLEANFILES = xxx *.gcno *.gcda *gconv
--- /dev/null
+/* Test program for libdwfl ... foo
+ Copyright (C) 2007 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#include <config.h>
+#include <assert.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <error.h>
+#include <locale.h>
+#include <argp.h>
+#include ELFUTILS_HEADER(dwfl)
+#include <dwarf.h>
+
+
+static void
+handle_address (Dwfl *dwfl, Dwarf_Addr address)
+{
+ Dwfl_Module *mod = dwfl_addrmodule (dwfl, address);
+ Dwarf_Addr adjusted = address;
+ Dwarf_Addr bias;
+ Elf_Scn *scn = dwfl_module_address_section (mod, &adjusted, &bias);
+ if (scn == NULL)
+ error (EXIT_FAILURE, 0, "%#" PRIx64 ": dwfl_module_address_section: %s",
+ address, dwfl_errmsg (-1));
+ printf ("address %#" PRIx64 " => module \"%s\" section %zu + %#" PRIx64 "\n",
+ address,
+ dwfl_module_info (mod, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+ elf_ndxscn (scn), adjusted);
+}
+
+int
+main (int argc, char **argv)
+{
+ /* We use no threads here which can interfere with handling a stream. */
+ (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
+
+ /* Set locale. */
+ (void) setlocale (LC_ALL, "");
+
+ int remaining;
+ Dwfl *dwfl = NULL;
+ (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, &dwfl);
+ assert (dwfl != NULL);
+
+ int result = 0;
+ for (; remaining < argc; ++remaining)
+ {
+ char *endp;
+ uintmax_t addr = strtoumax (argv[remaining], &endp, 0);
+ if (endp != argv[remaining])
+ handle_address (dwfl, addr);
+ else
+ result = 1;
+ }
+
+ dwfl_end (dwfl);
+
+ return result;
+}
-/* Copyright (C) 2002, 2004, 2005 Red Hat, Inc.
+/* Copyright (C) 2002, 2004, 2005, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2002.
break;
}
+ const char *const *dirs;
+ size_t ndirs;
+ if (dwarf_getsrcdirs (files, &dirs, &ndirs) != 0)
+ {
+ printf ("%s: cannot get include directories\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+
+ if (dirs[0] == NULL)
+ puts (" dirs[0] = (null)");
+ else
+ printf (" dirs[0] = \"%s\"\n", dirs[0]);
+ for (size_t i = 1; i < ndirs; ++i)
+ printf (" dirs[%zu] = \"%s\"\n", i, dirs[i]);
+
for (size_t i = 0; i < nfiles; ++i)
printf (" file[%zu] = \"%s\"\n", i,
dwarf_filesrc (files, i, NULL, NULL));
#! /bin/sh
-# Copyright (C) 1999, 2000, 2002, 2004, 2005 Red Hat, Inc.
+# Copyright (C) 1999, 2000, 2002, 2004, 2005, 2007 Red Hat, Inc.
# This file is part of Red Hat elfutils.
# Written by Ulrich Drepper <drepper@redhat.com>, 1999.
#
testrun_compare ./get-files testfile testfile2 <<\EOF
cuhl = 11, o = 0, asz = 4, osz = 4, ncu = 191
+ dirs[0] = "/home/drepper/gnu/new-bu/build/ttt"
file[0] = "???"
file[1] = "/home/drepper/gnu/new-bu/build/ttt/m.c"
cuhl = 11, o = 114, asz = 4, osz = 4, ncu = 5617
+ dirs[0] = "/home/drepper/gnu/new-bu/build/ttt"
file[0] = "???"
file[1] = "/home/drepper/gnu/new-bu/build/ttt/b.c"
file[2] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h"
file[10] = "/usr/include/_G_config.h"
file[11] = "/usr/include/gconv.h"
cuhl = 11, o = 412, asz = 4, osz = 4, ncu = 5752
+ dirs[0] = "/home/drepper/gnu/new-bu/build/ttt"
file[0] = "???"
file[1] = "/home/drepper/gnu/new-bu/build/ttt/f.c"
cuhl = 11, o = 0, asz = 4, osz = 4, ncu = 2418
+ dirs[0] = "/shoggoth/drepper"
file[0] = "???"
file[1] = "/shoggoth/drepper/b.c"
file[2] = "/home/geoffk/objs/laurel-000912-branch/lib/gcc-lib/powerpc-unknown-linux-gnu/2.96-laurel-000912/include/stddef.h"
file[7] = "/usr/include/libio.h"
file[8] = "/usr/include/_G_config.h"
cuhl = 11, o = 213, asz = 4, osz = 4, ncu = 2521
+ dirs[0] = "/shoggoth/drepper"
file[0] = "???"
file[1] = "/shoggoth/drepper/f.c"
cuhl = 11, o = 267, asz = 4, osz = 4, ncu = 2680
+ dirs[0] = "/shoggoth/drepper"
file[0] = "???"
file[1] = "/shoggoth/drepper/m.c"
EOF