Roland McGrath | e47ab76 | 2005-11-17 03:16:00 +0000 | [diff] [blame] | 1 | /* Test program for dwfl_module_return_value_location. |
| 2 | Copyright (C) 2005 Red Hat, Inc. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 3 | This file is part of Red Hat elfutils. |
Roland McGrath | e47ab76 | 2005-11-17 03:16:00 +0000 | [diff] [blame] | 4 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 5 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by the |
| 7 | Free Software Foundation; version 2 of the License. |
Roland McGrath | e47ab76 | 2005-11-17 03:16:00 +0000 | [diff] [blame] | 8 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 9 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along |
| 15 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
Ulrich Drepper | 1e9ef50 | 2006-04-04 22:29:06 +0000 | [diff] [blame] | 16 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 17 | |
| 18 | Red Hat elfutils is an included package of the Open Invention Network. |
| 19 | An included package of the Open Invention Network is a package for which |
| 20 | Open Invention Network licensees cross-license their patents. No patent |
| 21 | license is granted, either expressly or impliedly, by designation as an |
| 22 | included package. Should you wish to participate in the Open Invention |
| 23 | Network licensing program, please visit www.openinventionnetwork.com |
| 24 | <http://www.openinventionnetwork.com>. */ |
Roland McGrath | e47ab76 | 2005-11-17 03:16:00 +0000 | [diff] [blame] | 25 | |
| 26 | #include <config.h> |
| 27 | #include <assert.h> |
| 28 | #include <inttypes.h> |
| 29 | #include ELFUTILS_HEADER(dwfl) |
| 30 | #include <dwarf.h> |
| 31 | #include <argp.h> |
| 32 | #include <stdio.h> |
| 33 | #include <stdio_ext.h> |
| 34 | #include <locale.h> |
| 35 | #include <stdlib.h> |
| 36 | #include <error.h> |
| 37 | #include <string.h> |
| 38 | #include <fnmatch.h> |
| 39 | |
| 40 | |
| 41 | struct args |
| 42 | { |
| 43 | Dwfl *dwfl; |
| 44 | Dwarf_Die *cu; |
| 45 | Dwarf_Addr dwbias; |
| 46 | char **argv; |
| 47 | }; |
| 48 | |
| 49 | static int |
| 50 | handle_function (Dwarf_Die *funcdie, void *arg) |
| 51 | { |
| 52 | struct args *a = arg; |
| 53 | |
| 54 | const char *name = dwarf_diename (funcdie); |
| 55 | char **argv = a->argv; |
| 56 | if (argv[0] != NULL) |
| 57 | { |
| 58 | bool match; |
| 59 | do |
| 60 | match = fnmatch (*argv, name, 0) == 0; |
| 61 | while (!match && *++argv); |
| 62 | if (!match) |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | printf ("(%s) %s: ", dwfl_module_info (dwfl_cumodule (a->cu), NULL, |
| 67 | NULL, NULL, |
| 68 | NULL, NULL, |
| 69 | NULL, NULL), name); |
| 70 | |
| 71 | const Dwarf_Op *locops; |
| 72 | int nlocops = dwfl_module_return_value_location (dwfl_cumodule (a->cu), |
| 73 | funcdie, &locops); |
| 74 | if (nlocops < 0) |
| 75 | error (EXIT_FAILURE, 0, "dwfl_module_return_value_location: %s", |
| 76 | dwfl_errmsg (-1)); |
| 77 | else if (nlocops == 0) |
| 78 | puts ("returns no value"); |
| 79 | else |
| 80 | { |
| 81 | printf ("return value location:"); |
| 82 | for (int i = 0; i < nlocops; ++i) |
| 83 | printf (" {%#x, %#" PRIx64 "}", locops[i].atom, locops[i].number); |
| 84 | puts (""); |
| 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | int |
| 92 | main (int argc, char *argv[]) |
| 93 | { |
| 94 | int remaining; |
| 95 | |
| 96 | /* Set locale. */ |
| 97 | (void) setlocale (LC_ALL, ""); |
| 98 | |
| 99 | struct args a = { .dwfl = NULL, .cu = NULL }; |
| 100 | |
| 101 | (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, |
| 102 | &a.dwfl); |
| 103 | assert (a.dwfl != NULL); |
| 104 | a.argv = &argv[remaining]; |
| 105 | |
| 106 | int result = 0; |
| 107 | |
| 108 | while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL) |
| 109 | dwarf_getfuncs (a.cu, &handle_function, &a, 0); |
| 110 | |
Roland McGrath | 994b489 | 2005-12-05 22:46:21 +0000 | [diff] [blame] | 111 | dwfl_end (a.dwfl); |
| 112 | |
Roland McGrath | e47ab76 | 2005-11-17 03:16:00 +0000 | [diff] [blame] | 113 | return result; |
| 114 | } |