1 /* Copyright (C) 2002 Red Hat, Inc.
2 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
3
4 This program is Open Source software; you can redistribute it and/or
5 modify it under the terms of the Open Software License version 1.0 as
6 published by the Open Source Initiative.
7
8 You should have received a copy of the Open Software License along
9 with this program; if not, you may obtain a copy of the Open Software
10 License version 1.0 from http://www.opensource.org/licenses/osl.php or
11 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12 3001 King Ranch Road, Ukiah, CA 95482. */
13
14 #include <fcntl.h>
15 #include <libelf.h>
16 #include <libdw.h>
17 #include <stdio.h>
18 #include <unistd.h>
19
20
21 static int globcnt;
22
23 static int
callback(Dwarf * dbg,Dwarf_Global * gl,void * arg)24 callback (Dwarf *dbg, Dwarf_Global *gl, void *arg)
25 {
26 int result = DWARF_CB_OK;
27
28 printf (" [%2d] \"%s\", die: %llu, cu: %llu\n",
29 globcnt++, gl->name, (unsigned long long int) gl->die_offset,
30 (unsigned long long int) gl->cu_offset);
31
32 Dwarf_Die cu_die;
33 const char *cuname;
34 if (dwarf_offdie (dbg, gl->cu_offset, &cu_die) == NULL
35 || (cuname = dwarf_diename (&cu_die)) == NULL)
36 {
37 puts ("failed to get CU die");
38 result = DWARF_CB_ABORT;
39 }
40 else
41 printf ("CU name: \"%s\"\n", cuname);
42
43 const char *diename;
44 Dwarf_Die die;
45 if (dwarf_offdie (dbg, gl->die_offset, &die) == NULL
46 || (diename = dwarf_diename (&die)) == NULL)
47 {
48 puts ("failed to get object die");
49 result = DWARF_CB_ABORT;
50 }
51 else
52 printf ("object name: \"%s\"\n", diename);
53
54 return result;
55 }
56
57
58 int
main(int argc,char * argv[])59 main (int argc, char *argv[])
60 {
61 int result = 0;
62 int cnt;
63
64 for (cnt = 1; cnt < argc; ++cnt)
65 {
66 int fd = open (argv[cnt], O_RDONLY);
67 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
68 if (dbg == NULL)
69 {
70 printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
71 result = 1;
72 close (fd);
73 continue;
74 }
75
76 globcnt = 0;
77
78 if (dwarf_getpubnames (dbg, callback, NULL, 0) != 0)
79 {
80 printf ("dwarf_get_pubnames didn't return zero: %s\n",
81 dwarf_errmsg (-1));
82 result = 1;
83 }
84
85 dwarf_end (dbg);
86 close (fd);
87 }
88
89 return result;
90 }
91