summaryrefslogtreecommitdiff
path: root/libdw/dwarf_cu_info.c
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-05-20 10:35:34 +0200
committerMark Wielaard <mark@klomp.org>2018-05-24 17:34:17 +0200
commitac6960d6b8602df97b5964f66ffc7cd91fd16e5b (patch)
tree24f79d3ddc8c412468d709b478a6d6976624157e /libdw/dwarf_cu_info.c
parentc2d14cc492aa7fd28740d5789fede64ce81a063b (diff)
downloadelfutils-ac6960d6b8602df97b5964f66ffc7cd91fd16e5b.tar.gz
libdw: Add new dwarf_cu_info function.
This allows getting a (split) subdie lazily, only when needed. All arguments to dwarf_get_units are optional. When not given then unit DIE and sub DIE are not looked up. This new function allows them to be looked up when not immediately retrieved with dwarf_get_units, or for a Dwarf_CU gotten through some other way. Add a new testcase to make sure the results of calling dwarf_cu_info and dwarf_get_units are consistent. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdw/dwarf_cu_info.c')
-rw-r--r--libdw/dwarf_cu_info.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/libdw/dwarf_cu_info.c b/libdw/dwarf_cu_info.c
new file mode 100644
index 00000000..30aee6c7
--- /dev/null
+++ b/libdw/dwarf_cu_info.c
@@ -0,0 +1,103 @@
+/* Provides information and DIEs associated with the Dwarf_CU unit.
+ Copyright (C) 2018 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 <string.h>
+#include "libdwP.h"
+
+
+int
+dwarf_cu_info (Dwarf_CU *cu,
+ Dwarf_Half *version, uint8_t *unit_type,
+ Dwarf_Die *cudie, Dwarf_Die *subdie,
+ uint64_t *unit_id,
+ uint8_t *address_size, uint8_t *offset_size)
+{
+ if (cu == NULL)
+ return -1;
+
+ if (version != NULL)
+ *version = cu->version;
+
+ if (unit_type != NULL)
+ *unit_type = cu->unit_type;
+
+ if (cudie != NULL)
+ {
+ if (cu->version >= 2 && cu->version <= 5
+ && cu->unit_type >= DW_UT_compile
+ && cu->unit_type <= DW_UT_split_type)
+ *cudie = CUDIE (cu);
+ else
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+ }
+
+ if (subdie != NULL)
+ {
+ if (cu->version >= 2 && cu->version <= 5)
+ {
+ /* For types, return the actual type DIE. For skeletons,
+ find the associated split compile unit and return its
+ DIE. */
+ if (cu->unit_type == DW_UT_type
+ || cu->unit_type == DW_UT_split_type)
+ *subdie = SUBDIE(cu);
+ else if (cu->unit_type == DW_UT_skeleton)
+ {
+ Dwarf_CU *split_cu = __libdw_find_split_unit (cu);
+ if (split_cu != NULL)
+ *subdie = CUDIE(split_cu);
+ else
+ memset (subdie, '\0', sizeof (Dwarf_Die));
+ }
+ else
+ memset (subdie, '\0', sizeof (Dwarf_Die));
+ }
+ else
+ goto invalid;
+ }
+
+ if (unit_id != NULL)
+ *unit_id = cu->unit_id8;
+
+ if (address_size != NULL)
+ *address_size = cu->address_size;
+
+ if (offset_size != NULL)
+ *offset_size = cu->offset_size;
+
+ return 0;
+}