[PATCH v3 2/6] libdw: Add dwarf_getalt, dwarf_setalt

Florian Weimer fweimer at redhat.com
Tue Apr 15 12:31:55 UTC 2014


Signed-off-by: Florian Weimer <fweimer at redhat.com>
---
 libdw/ChangeLog      |  7 +++++++
 libdw/Makefile.am    |  3 ++-
 libdw/dwarf_getalt.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 libdw/dwarf_setalt.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 libdw/libdw.h        |  9 +++++++++
 libdw/libdw.map      |  2 ++
 libdw/libdwP.h       |  2 ++
 7 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 libdw/dwarf_getalt.c
 create mode 100644 libdw/dwarf_setalt.c

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d740b2b..1ecdb02 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -6,6 +6,13 @@
 	(check_section): Obtain .gnu_debugaltlink section from the
 	setiondata array.
 
+	* dwarf_getalt.c, dwarf_setalt.c: New files.
+	* Makefile.am (libdw_a_SOURCES): Add them.
+	* libdw.h (dwarf_getalt, dwarf_setalt): Add function declarations.
+	* libdwP.h (dwarf_getalt, dwarf_setalt): Add internal function
+	declarations.
+	* libdw.map (ELFUTILS_0.159): Export the two new functions.
+
 2014-04-11  Mark Wielaard  <mjw at redhat.com>
 
 	* libdw.map (ELFUTILS_0.159): New. Add dwelf_elf_gnu_debuglink.
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index f8d8e0d..4fcd300 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -87,7 +87,8 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \
 		  dwarf_cfi_addrframe.c \
 		  dwarf_getcfi.c dwarf_getcfi_elf.c dwarf_cfi_end.c \
 		  dwarf_aggregate_size.c dwarf_getlocation_implicit_pointer.c \
-		  dwarf_getlocation_die.c dwarf_getlocation_attr.c
+		  dwarf_getlocation_die.c dwarf_getlocation_attr.c \
+		  dwarf_getalt.c dwarf_setalt.c
 
 if MAINTAINER_MODE
 BUILT_SOURCES = $(srcdir)/known-dwarf.h
diff --git a/libdw/dwarf_getalt.c b/libdw/dwarf_getalt.c
new file mode 100644
index 0000000..4351d94
--- /dev/null
+++ b/libdw/dwarf_getalt.c
@@ -0,0 +1,42 @@
+/* Create descriptor from ELF descriptor for processing file.
+   Copyright (C) 2014 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"
+
+Dwarf *
+dwarf_getalt (Dwarf *main)
+{
+  if (main == NULL)
+    return NULL;
+  return main->alt_dwarf;
+}
+INTDEF (dwarf_getalt)
diff --git a/libdw/dwarf_setalt.c b/libdw/dwarf_setalt.c
new file mode 100644
index 0000000..6767d11
--- /dev/null
+++ b/libdw/dwarf_setalt.c
@@ -0,0 +1,43 @@
+/* Create descriptor from ELF descriptor for processing file.
+   Copyright (C) 2014 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"
+
+void
+dwarf_setalt (Dwarf *main, Dwarf *alt)
+{
+  if (main->free_alt)
+    INTUSE (dwarf_end) (main->alt_dwarf);
+  main->free_alt = false;
+  main->alt_dwarf = alt;
+}
+INTDEF (dwarf_setalt)
diff --git a/libdw/libdw.h b/libdw/libdw.h
index 0d94c52..8e31ad6 100644
--- a/libdw/libdw.h
+++ b/libdw/libdw.h
@@ -260,6 +260,15 @@ extern Dwarf *dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp);
 /* Retrieve ELF descriptor used for DWARF access.  */
 extern Elf *dwarf_getelf (Dwarf *dwarf);
 
+/* Retrieve DWARF descriptor for debugaltlink data.  Returns NULL if
+   no alternate debug data has been supplied.  */
+extern Dwarf *dwarf_getalt (Dwarf *main);
+
+/* Provides the data referenced by the .gnu_debugaltlink section.  It
+   is the responsibility of the caller to ensure that the data
+   referenced by ALT stays valid until dwarf_end (MAIN) is called.  */
+extern void dwarf_setalt (Dwarf *main, Dwarf *alt);
+
 /* Release debugging handling context.  */
 extern int dwarf_end (Dwarf *dwarf);
 
diff --git a/libdw/libdw.map b/libdw/libdw.map
index 0e75fcb..71247e3 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -295,5 +295,7 @@ ELFUTILS_0.158 {
 
 ELFUTILS_0.159 {
   global:
+    dwarf_getalt;
+    dwarf_setalt;
     dwelf_elf_gnu_debuglink;
 } ELFUTILS_0.158;
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index a688456..1c94767 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -686,6 +686,7 @@ INTDECL (dwarf_formref_die)
 INTDECL (dwarf_formsdata)
 INTDECL (dwarf_formstring)
 INTDECL (dwarf_formudata)
+INTDECL (dwarf_getalt)
 INTDECL (dwarf_getarange_addr)
 INTDECL (dwarf_getarangeinfo)
 INTDECL (dwarf_getaranges)
@@ -701,6 +702,7 @@ INTDECL (dwarf_nextcu)
 INTDECL (dwarf_next_unit)
 INTDECL (dwarf_offdie)
 INTDECL (dwarf_ranges)
+INTDECL (dwarf_setalt)
 INTDECL (dwarf_siblingof)
 INTDECL (dwarf_srclang)
 INTDECL (dwarf_tag)
-- 
1.9.0



More information about the elfutils-devel mailing list