Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 1 | /* Test program for dwarf_entry_breakpoints. |
| 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 | 07d4f2f | 2005-10-28 06:56:24 +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 | 07d4f2f | 2005-10-28 06:56:24 +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 | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 25 | |
| 26 | #include <config.h> |
| 27 | #include <assert.h> |
| 28 | #include <inttypes.h> |
Roland McGrath | d7f8d0c | 2005-11-17 02:32:03 +0000 | [diff] [blame] | 29 | #include ELFUTILS_HEADER(dwfl) |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 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 |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 50 | handle_function (Dwarf_Die *func, void *arg) |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 51 | { |
| 52 | struct args *a = arg; |
| 53 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 54 | const char *name = dwarf_diename (func); |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 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 | |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 66 | if (dwarf_func_inline (func)) |
| 67 | return 0; |
| 68 | |
| 69 | Dwarf_Addr entrypc; |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 70 | if (dwarf_entrypc (func, &entrypc) != 0) |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 71 | error (EXIT_FAILURE, 0, "dwarf_entrypc: %s: %s", |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 72 | dwarf_diename (func), dwarf_errmsg (-1)); |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 73 | entrypc += a->dwbias; |
| 74 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 75 | printf ("%-16s %#.16" PRIx64, dwarf_diename (func), entrypc); |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 76 | |
| 77 | Dwarf_Addr *bkpts = NULL; |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 78 | int result = dwarf_entry_breakpoints (func, &bkpts); |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 79 | if (result <= 0) |
| 80 | printf ("\t%s\n", dwarf_errmsg (-1)); |
| 81 | else |
| 82 | { |
| 83 | for (int i = 0; i < result; ++i) |
| 84 | printf (" %#.16" PRIx64 "%s", bkpts[i] + a->dwbias, |
| 85 | i == result - 1 ? "\n" : ""); |
| 86 | free (bkpts); |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | int |
| 94 | main (int argc, char *argv[]) |
| 95 | { |
| 96 | int remaining; |
| 97 | |
| 98 | /* Set locale. */ |
| 99 | (void) setlocale (LC_ALL, ""); |
| 100 | |
| 101 | struct args a = { .dwfl = NULL, .cu = NULL }; |
| 102 | |
| 103 | (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, |
| 104 | &a.dwfl); |
| 105 | assert (a.dwfl != NULL); |
| 106 | a.argv = &argv[remaining]; |
| 107 | |
| 108 | int result = 0; |
| 109 | |
| 110 | while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL) |
| 111 | dwarf_getfuncs (a.cu, &handle_function, &a, 0); |
| 112 | |
Roland McGrath | 994b489 | 2005-12-05 22:46:21 +0000 | [diff] [blame] | 113 | dwfl_end (a.dwfl); |
| 114 | |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 115 | return result; |
| 116 | } |