summaryrefslogtreecommitdiffstats
path: root/tests/dwarf-print.cc
blob: 739b49b02cddf8888bb8d2fa8e2deab6a84c9cc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Test program for elfutils::dwarf basics.
   Copyright (C) 2009 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 <errno.h>
#include <error.h>
#include <fcntl.h>
#include <libintl.h>

#include "c++/dwarf"

using namespace elfutils;
using namespace std;

#include "print-die.hh"

static Dwarf *
open_file (const char *fname)
{
  int fd = open (fname, O_RDONLY);
  if (unlikely (fd == -1))
    error (2, errno, gettext ("cannot open '%s'"), fname);
  Dwarf *dw = dwarf_begin (fd, DWARF_C_READ);
  if (dw == NULL)
    {
      error (2, 0,
	     gettext ("cannot create DWARF descriptor for '%s': %s"),
	     fname, dwarf_errmsg (-1));
    }
  return dw;
}

int
main (int argc, char *argv[])
{
  unsigned int depth;
  print_die_main (argc, argv, depth);

  for (int i = 1; i < argc; ++i)
    print_file (argv[i], dwarf (open_file (argv[i])), depth);

  return 0;
}