Imported Upstream version 0.155
[platform/upstream/elfutils.git] / tests / dwarf-getmacros.c
1 /* Test program for dwfl_module_return_value_location.
2    Copyright (C) 2009 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
28 int
29 main (int argc __attribute__ ((unused)), char *argv[])
30 {
31   const char *name = argv[1];
32   ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
33
34   int fd = open (name, O_RDONLY);
35   Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
36
37   Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
38   int mac (Dwarf_Macro *macro, void *data __attribute__ ((unused)))
39   {
40     unsigned int opcode;
41     dwarf_macro_opcode (macro, &opcode);
42     if (opcode == DW_MACINFO_define)
43       {
44         const char *value;
45         dwarf_macro_param2 (macro, NULL, &value);
46         puts (value);
47       }
48     return DWARF_CB_ABORT;
49   }
50
51   ptrdiff_t off = 0;
52   while ((off = dwarf_getmacros (cudie, mac, NULL, off)) > 0)
53     ;
54
55   return 0;
56 }