Brian Silverman | 8649792 | 2018-02-10 19:28:39 -0500 | [diff] [blame] | 1 | /* Test program for dwarf_entry_breakpoints. |
| 2 | Copyright (C) 2005 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 <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 | |
| 33 | struct args |
| 34 | { |
| 35 | Dwfl *dwfl; |
| 36 | Dwarf_Die *cu; |
| 37 | Dwarf_Addr dwbias; |
| 38 | char **argv; |
| 39 | }; |
| 40 | |
| 41 | static int |
| 42 | handle_function (Dwarf_Die *func, void *arg) |
| 43 | { |
| 44 | struct args *a = arg; |
| 45 | |
| 46 | const char *name = dwarf_diename (func); |
| 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 | if (dwarf_func_inline (func)) |
| 59 | return 0; |
| 60 | |
| 61 | Dwarf_Addr entrypc; |
| 62 | if (dwarf_entrypc (func, &entrypc) != 0) |
| 63 | error (EXIT_FAILURE, 0, "dwarf_entrypc: %s: %s", |
| 64 | dwarf_diename (func), dwarf_errmsg (-1)); |
| 65 | entrypc += a->dwbias; |
| 66 | |
| 67 | printf ("%-16s %#.16" PRIx64, dwarf_diename (func), entrypc); |
| 68 | |
| 69 | Dwarf_Addr *bkpts = NULL; |
| 70 | int result = dwarf_entry_breakpoints (func, &bkpts); |
| 71 | if (result <= 0) |
| 72 | printf ("\t%s\n", dwarf_errmsg (-1)); |
| 73 | else |
| 74 | { |
| 75 | for (int i = 0; i < result; ++i) |
| 76 | printf (" %#.16" PRIx64 "%s", bkpts[i] + a->dwbias, |
| 77 | i == result - 1 ? "\n" : ""); |
| 78 | free (bkpts); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | int |
| 86 | main (int argc, char *argv[]) |
| 87 | { |
| 88 | int remaining; |
| 89 | |
| 90 | /* Set locale. */ |
| 91 | (void) setlocale (LC_ALL, ""); |
| 92 | |
| 93 | struct args a = { .dwfl = NULL, .cu = NULL }; |
| 94 | |
| 95 | (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, |
| 96 | &a.dwfl); |
| 97 | assert (a.dwfl != NULL); |
| 98 | a.argv = &argv[remaining]; |
| 99 | |
| 100 | int result = 0; |
| 101 | |
| 102 | while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL) |
| 103 | dwarf_getfuncs (a.cu, &handle_function, &a, 0); |
| 104 | |
| 105 | dwfl_end (a.dwfl); |
| 106 | |
| 107 | return result; |
| 108 | } |