blob: 4bcf96ce78d4970fd1da2f0c97ceb5209e385e91 [file] [log] [blame]
Petr Machatab4da85d2015-02-11 22:11:46 +01001/* Test program for dwarf_ranges
2 Copyright (C) 2015 Red Hat, Inc.
3 This file is part of elfutils.
4
5 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.
9
10 elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 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/>. */
17
18#include <config.h>
19#include ELFUTILS_HEADER(dw)
20#include <dwarf.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <fcntl.h>
24#include <stdio.h>
25#include <stdint.h>
26#include <stdlib.h>
27#include <assert.h>
28#include <inttypes.h>
29
30int
31main (int argc, char *argv[])
32{
33 assert (argc >= 3);
34 const char *name = argv[1];
35 ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
36
37 int fd = open (name, O_RDONLY);
38 Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
39
40 Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
41
42 Dwarf_Addr base, start, end;
43 for (ptrdiff_t off = 0;
44 (off = dwarf_ranges (cudie, off, &base, &start, &end)); )
45 if (off == -1)
46 {
47 puts (dwarf_errmsg (dwarf_errno ()));
48 break;
49 }
50 else
51 fprintf (stderr, "%"PRIx64"..%"PRIx64" (base %"PRIx64")\n",
52 start, end, base);
53
54 dwarf_end (dbg);
55
56 return 0;
57}