blob: ffa3e375aef9dd0cd494f3c0d7f94ad7b21f82ff [file] [log] [blame]
Marek Polacek48942212011-03-07 11:16:50 -08001/* Copyright (C) 2011 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Marek Polacek48942212011-03-07 11:16:50 -08003 Written by Marek Polacek <mpolacek@redhat.com>, 2011.
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.
Marek Polacek48942212011-03-07 11:16:50 -08009
Mark Wielaardde2ed972012-06-05 17:15:16 +020010 elfutils is distributed in the hope that it will be useful, but
Marek Polacek48942212011-03-07 11:16:50 -080011 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.
Marek Polacek48942212011-03-07 11:16:50 -080014
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/>. */
Marek Polacek48942212011-03-07 11:16:50 -080017
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
22#include ELFUTILS_HEADER(dwfl)
23#include <assert.h>
24#include <dwarf.h>
25#include <fcntl.h>
26#include <stdio.h>
27#include <unistd.h>
28
29
30int
31main (int argc, char *argv[])
32{
33 int cnt;
34
35 for (cnt = 1; cnt < argc; ++cnt)
36 {
37 Dwarf_Off offset = 0;
38 size_t len;
39
Josh Stone34254542015-10-09 10:10:37 -070040 int fd = open (argv[cnt], O_RDONLY);
Marek Polacek48942212011-03-07 11:16:50 -080041 if (fd == -1)
42 {
43 printf ("cannot open '%s': %m\n", argv[cnt]);
44 return 1;
45 }
46
47 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
48 if (dbg == NULL)
49 {
50 printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
51 close (fd);
52 return 1;
53 }
54
55 /* Try to use NULL Dwarf object. */
56 const char *str = dwarf_getstring (NULL, offset, &len);
57 assert (str == NULL);
58
59 /* Use insane offset. */
60 str = dwarf_getstring (dbg, ~0UL, &len);
61 assert (str == NULL);
62
63 /* Now do some real work. */
64 for (int i = 0; i < 100; ++i)
65 {
66 str = dwarf_getstring (dbg, offset, &len);
67 puts (str);
68
69 /* Advance. */
70 offset += len + 1;
71 }
72
Mark Wielaarda1372e02015-12-01 15:55:08 +010073 dwarf_end (dbg);
Marek Polacek48942212011-03-07 11:16:50 -080074 close (fd);
75 }
76
77 return 0;
78}