summaryrefslogtreecommitdiffstats
path: root/tests/get-units-split.c
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-07-04 00:31:46 +0200
committerMark Wielaard <mark@klomp.org>2018-07-04 00:31:46 +0200
commit94c975eefdfbfa9319b7bab69600c76fe6be7910 (patch)
treee29e208499440fdbaac2a867bcd7029f12e89a7a /tests/get-units-split.c
parent766df1e15c1e8f8bc9890e7538eb2ef15a6516dc (diff)
parentaa36de0335e3ce12898954985a208f6336731289 (diff)
Merge tag 'elfutils-0.173' into mjw/RH-DTSdts-0.173
elfutils 0.173 release Removed riscv backend for now. Removed new arm32 tests. Added various new files to libdw_static_pic.a to support split dwarf.
Diffstat (limited to 'tests/get-units-split.c')
-rw-r--r--tests/get-units-split.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/get-units-split.c b/tests/get-units-split.c
new file mode 100644
index 00000000..410483a0
--- /dev/null
+++ b/tests/get-units-split.c
@@ -0,0 +1,101 @@
+/* Test dwarf_get_units finds split DWO CUs.
+ 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 the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ 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 this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+#include ELFUTILS_HEADER(dw)
+#include <stdio.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ for (int i = 1; i < argc; i++)
+ {
+ printf ("file: %s\n", argv[i]);
+ int fd = open (argv[i], O_RDONLY);
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1));
+ return -1;
+ }
+
+ Dwarf_CU *cu = NULL;
+ Dwarf_Die cudie, subdie;
+ uint8_t unit_type;
+ int count = 0;
+ while (dwarf_get_units (dbg, cu, &cu, NULL,
+ &unit_type, &cudie, &subdie) == 0)
+ {
+ count++;
+ printf ("Got cudie unit_type: %" PRIx8 "\n", unit_type);
+
+ if (unit_type == DW_UT_skeleton)
+ {
+ Dwarf_CU *skel_cu = cudie.cu;
+ Dwarf_CU *split_cu = subdie.cu;
+ Dwarf_Die skel_die, split_die;
+ uint64_t skel_id, split_id;
+
+ printf ("Found a skeleton unit, with split die: %s\n",
+ dwarf_diename (&subdie));
+
+ if (dwarf_cu_die (skel_cu, &skel_die, NULL, NULL, NULL, NULL,
+ &skel_id, NULL) == NULL)
+ {
+ printf ("bad skel_cu: %s\n", dwarf_errmsg (-1));
+ return -1;
+ }
+
+ if (dwarf_cu_die (split_cu, &split_die, NULL, NULL, NULL, NULL,
+ &split_id, NULL) == NULL)
+ {
+ printf ("bad skel_cu: %s\n", dwarf_errmsg (-1));
+ return -1;
+ }
+
+ if (skel_id != split_id)
+ {
+ printf ("Skeleton id and Split id not equal!\n");
+ return -1;
+ }
+ }
+ }
+
+ if (count == 0)
+ {
+ printf ("No units found\n");
+ return -1;
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+
+ printf ("\n");
+ }
+
+ return 0;
+}