]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Add dwarf_line_file.
authorMark Wielaard <mark@klomp.org>
Fri, 21 Jul 2017 19:23:07 +0000 (21:23 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 26 Jul 2017 21:22:38 +0000 (23:22 +0200)
Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/Makefile.am
libdw/dwarf_line_file.c [new file with mode: 0644]
libdw/libdw.h
libdw/libdw.map
tests/ChangeLog
tests/get-lines.c

index 8eda70cdf9a8d94341521f34068825438ec79463..8b2ef75963d053aaa748c6e8114bd45162eb4081 100644 (file)
@@ -1,3 +1,10 @@
+2017-07-21  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_line_file.c: New file.
+       * Makefile.am (libdw_a_SOURCES): Add dwarf_line_file.c.
+       * libdw.h (dwarf_line_file): New function declaration.
+       * libdw.map (ELFUTILS_0.170): New. Add dwarf_line_file.
+
 2017-02-17  Ulf Hermann  <ulf.hermann@qt.io>
 
        * Makefile.am: Add libdw_so_LIBS to specify the archives libdw is is
index 634ac2ecff5dfd2d34eca37b0efb246d08aa3fde..ad031b11fbcfa298491a4cd693d1ecd70299fc1d 100644 (file)
@@ -65,7 +65,7 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \
                  dwarf_lineendsequence.c dwarf_lineblock.c \
                  dwarf_lineprologueend.c dwarf_lineepiloguebegin.c \
                  dwarf_lineisa.c dwarf_linediscriminator.c \
-                 dwarf_lineop_index.c \
+                 dwarf_lineop_index.c dwarf_line_file.c \
                  dwarf_onesrcline.c dwarf_formblock.c \
                  dwarf_getsrcfiles.c dwarf_filesrc.c dwarf_getsrcdirs.c \
                  dwarf_getlocation.c dwarf_getstring.c dwarf_offabbrev.c \
diff --git a/libdw/dwarf_line_file.c b/libdw/dwarf_line_file.c
new file mode 100644 (file)
index 0000000..e2df642
--- /dev/null
@@ -0,0 +1,52 @@
+/* Find line information for address.
+   Copyright (C) 2017 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   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 copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "libdwP.h"
+
+
+int
+dwarf_line_file (Dwarf_Line *line, Dwarf_Files **files, size_t *idx)
+{
+  if (line == NULL)
+    return -1;
+
+  if (line->file >= line->files->nfiles)
+    {
+      __libdw_seterrno (DWARF_E_INVALID_DWARF);
+      return -1;
+    }
+
+  *files = line->files;
+  *idx = line->file;
+
+  return 0;
+}
index 9ae80ebb3880a421d84497b6d813d6dec4e604e6..4903b55f4f3abae888b684695cb31880a6b3ff5d 100644 (file)
@@ -640,6 +640,11 @@ extern const char *dwarf_linesrc (Dwarf_Line *line,
 extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx,
                                  Dwarf_Word *mtime, Dwarf_Word *length);
 
+/* Return the Dwarf_Files and index associated with the given Dwarf_Line.  */
+extern int dwarf_line_file (Dwarf_Line *line,
+                           Dwarf_Files **files, size_t *idx)
+    __nonnull_attribute__ (2, 3);
+
 /* 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
index 83cb1d970f7c2a2f228ba529d89afc27c4d6419e..44e096aed7a8ec108abf4f2d9524d44adc99aeaf 100644 (file)
@@ -338,3 +338,8 @@ ELFUTILS_0.167 {
     dwelf_strent_str;
     dwelf_strtab_free;
 } ELFUTILS_0.165;
+
+ELFUTILS_0.170 {
+  global:
+    dwarf_line_file;
+} ELFUTILS_0.167;
index 0700e7ca5057646d65fd39248cfffb1db5df60a4..519f25a3bc3d96da5ad7a2b4e88507a56876df78 100644 (file)
@@ -1,3 +1,7 @@
+2017-07-21  Mark Wielaard  <mark@klomp.org>
+
+       * get-lines.c (main): Add dwarf_line_file test.
+
 2017-07-19  Gustavo Romero <gromero@linux.vnet.ibm.com>
 
        * run-addrcfi.sh: Update generic SPRs names to HTM SPRs names
index c361a2c32cd380139d1d4d85f6aa5c35b9fa5417..188d016243d9d4404a1fae3e0a61a0360e9f662c 100644 (file)
@@ -24,6 +24,7 @@
 #include <libelf.h>
 #include ELFUTILS_HEADER(dw)
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 
 
@@ -100,6 +101,28 @@ main (int argc, char *argv[])
              printf ("%" PRIx64 ": %s:%d:", (uint64_t) addr,
                      file ?: "???", line);
 
+             /* Getting the file path through the Dwarf_Files should
+                result in the same path.  */
+             Dwarf_Files *files;
+             size_t idx;
+             if (dwarf_line_file (l, &files, &idx) != 0)
+               {
+                 printf ("%s: cannot get file from line (%zd): %s\n",
+                         argv[cnt], i, dwarf_errmsg (-1));
+                 result = 1;
+                 break;
+               }
+             const char *path = dwarf_filesrc (files, idx, NULL, NULL);
+             if ((path == NULL && file != NULL)
+                 || (path != NULL && file == NULL)
+                 || (strcmp (file, path) != 0))
+               {
+                 printf ("%s: line %zd srcline (%s) != file srcline (%s)\n",
+                         argv[cnt], i, file ?: "???", path ?: "???");
+                 result = 1;
+                 break;
+               }
+
              int column;
              if (dwarf_linecol (l, &column) != 0)
                column = 0;