blob: 8d19d11710afc650a68d3d2c901db31971c5cf86 [file] [log] [blame]
Roland McGrathe47ab762005-11-17 03:16:00 +00001/* Test program for dwfl_module_return_value_location.
2 Copyright (C) 2005 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Roland McGrathe47ab762005-11-17 03:16:00 +00004
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.
Roland McGrathe47ab762005-11-17 03:16:00 +00009
Mark Wielaardde2ed972012-06-05 17:15:16 +020010 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000011 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.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000014
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/>. */
Roland McGrathe47ab762005-11-17 03:16:00 +000017
18#include <config.h>
19#include <assert.h>
20#include <inttypes.h>
21#include ELFUTILS_HEADER(dwfl)
22#include <dwarf.h>
23#include <argp.h>
24#include <stdio.h>
25#include <stdio_ext.h>
26#include <locale.h>
27#include <stdlib.h>
28#include <error.h>
29#include <string.h>
30#include <fnmatch.h>
31
32
33struct args
34{
35 Dwfl *dwfl;
36 Dwarf_Die *cu;
37 Dwarf_Addr dwbias;
38 char **argv;
39};
40
41static int
42handle_function (Dwarf_Die *funcdie, void *arg)
43{
44 struct args *a = arg;
45
46 const char *name = dwarf_diename (funcdie);
47 char **argv = a->argv;
48 if (argv[0] != NULL)
49 {
50 bool match;
51 do
52 match = fnmatch (*argv, name, 0) == 0;
53 while (!match && *++argv);
54 if (!match)
55 return 0;
56 }
57
58 printf ("(%s) %s: ", dwfl_module_info (dwfl_cumodule (a->cu), NULL,
59 NULL, NULL,
60 NULL, NULL,
61 NULL, NULL), name);
62
63 const Dwarf_Op *locops;
64 int nlocops = dwfl_module_return_value_location (dwfl_cumodule (a->cu),
65 funcdie, &locops);
66 if (nlocops < 0)
67 error (EXIT_FAILURE, 0, "dwfl_module_return_value_location: %s",
68 dwfl_errmsg (-1));
69 else if (nlocops == 0)
70 puts ("returns no value");
71 else
72 {
73 printf ("return value location:");
74 for (int i = 0; i < nlocops; ++i)
75 printf (" {%#x, %#" PRIx64 "}", locops[i].atom, locops[i].number);
76 puts ("");
77 }
78
79 return 0;
80}
81
82
83int
84main (int argc, char *argv[])
85{
86 int remaining;
87
88 /* Set locale. */
89 (void) setlocale (LC_ALL, "");
90
91 struct args a = { .dwfl = NULL, .cu = NULL };
92
93 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining,
94 &a.dwfl);
95 assert (a.dwfl != NULL);
96 a.argv = &argv[remaining];
97
98 int result = 0;
99
100 while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL)
101 dwarf_getfuncs (a.cu, &handle_function, &a, 0);
102
Roland McGrath994b4892005-12-05 22:46:21 +0000103 dwfl_end (a.dwfl);
104
Roland McGrathe47ab762005-11-17 03:16:00 +0000105 return result;
106}