blob: c0e73d0d2ce3640e1759b5617a17f36b0e21f5b1 [file] [log] [blame]
Roland McGrath07d4f2f2005-10-28 06:56:24 +00001/* Test program for dwarf_entry_breakpoints.
2 Copyright (C) 2005 Red Hat, Inc.
Ulrich Drepper361df7d2006-04-04 21:38:57 +00003 This file is part of Red Hat elfutils.
Roland McGrath07d4f2f2005-10-28 06:56:24 +00004
Ulrich Drepper361df7d2006-04-04 21:38:57 +00005 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 McGrath07d4f2f2005-10-28 06:56:24 +00008
Ulrich Drepper361df7d2006-04-04 21:38:57 +00009 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 Drepper1e9ef502006-04-04 22:29:06 +000016 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000017
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 McGrath07d4f2f2005-10-28 06:56:24 +000025
26#include <config.h>
27#include <assert.h>
28#include <inttypes.h>
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000029#include ELFUTILS_HEADER(dwfl)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000030#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
41struct args
42{
43 Dwfl *dwfl;
44 Dwarf_Die *cu;
45 Dwarf_Addr dwbias;
46 char **argv;
47};
48
49static int
Roland McGrath6724c902005-10-28 07:07:19 +000050handle_function (Dwarf_Die *func, void *arg)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000051{
52 struct args *a = arg;
53
Roland McGrath6724c902005-10-28 07:07:19 +000054 const char *name = dwarf_diename (func);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000055 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 McGrath07d4f2f2005-10-28 06:56:24 +000066 if (dwarf_func_inline (func))
67 return 0;
68
69 Dwarf_Addr entrypc;
Roland McGrath6724c902005-10-28 07:07:19 +000070 if (dwarf_entrypc (func, &entrypc) != 0)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000071 error (EXIT_FAILURE, 0, "dwarf_entrypc: %s: %s",
Roland McGrath6724c902005-10-28 07:07:19 +000072 dwarf_diename (func), dwarf_errmsg (-1));
Roland McGrath07d4f2f2005-10-28 06:56:24 +000073 entrypc += a->dwbias;
74
Roland McGrath6724c902005-10-28 07:07:19 +000075 printf ("%-16s %#.16" PRIx64, dwarf_diename (func), entrypc);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000076
77 Dwarf_Addr *bkpts = NULL;
Roland McGrath6724c902005-10-28 07:07:19 +000078 int result = dwarf_entry_breakpoints (func, &bkpts);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000079 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
93int
94main (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 McGrath994b4892005-12-05 22:46:21 +0000113 dwfl_end (a.dwfl);
114
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000115 return result;
116}