blob: 04091733741c045a696acebf1389e71242576ca9 [file] [log] [blame]
Roland McGrath43da9892007-04-16 23:13:37 +00001/* Copyright (C) 2002, 2004, 2005, 2007 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00009
Mark Wielaardde2ed972012-06-05 17:15:16 +020010 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000011 WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000014
Mark Wielaardde2ed972012-06-05 17:15:16 +020015 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000017
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000018#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000022#include <fcntl.h>
23#include <libelf.h>
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000024#include ELFUTILS_HEADER(dw)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000025#include <stdio.h>
26#include <unistd.h>
27
28
29int
30main (int argc, char *argv[])
31{
32 int result = 0;
33 int cnt;
34
35 for (cnt = 1; cnt < argc; ++cnt)
36 {
37 int fd = open (argv[cnt], O_RDONLY);
38
39 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
40 if (dbg == NULL)
41 {
42 printf ("%s not usable\n", argv[cnt]);
43 result = 1;
44 if (fd != -1)
45 close (fd);
46 continue;
47 }
48
49 Dwarf_Off o = 0;
50 Dwarf_Off ncu;
51 Dwarf_Off ao;
52 size_t cuhl;
53 uint8_t asz;
54 uint8_t osz;
55 while (dwarf_nextcu (dbg, o, &ncu, &cuhl, &ao, &asz, &osz) == 0)
56 {
57 printf ("cuhl = %zu, o = %llu, asz = %hhu, osz = %hhu, ncu = %llu\n",
58 cuhl, (unsigned long long int) ao,
59 asz, osz, (unsigned long long int) ncu);
60
61 Dwarf_Die die_mem;
62 Dwarf_Die *die = dwarf_offdie (dbg, o + cuhl, &die_mem);
63 if (die == NULL)
64 {
65 printf ("%s: cannot get CU die\n", argv[cnt]);
66 result = 1;
67 break;
68 }
69
70 Dwarf_Files *files;
71 size_t nfiles;
72 if (dwarf_getsrcfiles (die, &files, &nfiles) != 0)
73 {
74 printf ("%s: cannot get files\n", argv[cnt]);
75 result = 1;
76 break;
77 }
78
Roland McGrath43da9892007-04-16 23:13:37 +000079 const char *const *dirs;
80 size_t ndirs;
81 if (dwarf_getsrcdirs (files, &dirs, &ndirs) != 0)
82 {
83 printf ("%s: cannot get include directories\n", argv[cnt]);
84 result = 1;
85 break;
86 }
87
88 if (dirs[0] == NULL)
89 puts (" dirs[0] = (null)");
90 else
91 printf (" dirs[0] = \"%s\"\n", dirs[0]);
92 for (size_t i = 1; i < ndirs; ++i)
93 printf (" dirs[%zu] = \"%s\"\n", i, dirs[i]);
94
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000095 for (size_t i = 0; i < nfiles; ++i)
96 printf (" file[%zu] = \"%s\"\n", i,
97 dwarf_filesrc (files, i, NULL, NULL));
98
99 o = ncu;
100 }
101
102 dwarf_end (dbg);
103 close (fd);
104 }
105
106 return result;
107}