blob: ba8ae37115e43939f1578187fcaa0f42896075b8 [file] [log] [blame]
Roland McGrath07d4f2f2005-10-28 06:56:24 +00001/* Test program for dwarf_entry_breakpoints.
2 Copyright (C) 2005 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Roland McGrath07d4f2f2005-10-28 06:56:24 +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 McGrath07d4f2f2005-10-28 06:56:24 +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 McGrath07d4f2f2005-10-28 06:56:24 +000017
18#include <config.h>
19#include <assert.h>
20#include <inttypes.h>
Roland McGrathd7f8d0c2005-11-17 02:32:03 +000021#include ELFUTILS_HEADER(dwfl)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000022#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
Roland McGrath6724c902005-10-28 07:07:19 +000042handle_function (Dwarf_Die *func, void *arg)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000043{
44 struct args *a = arg;
45
Roland McGrath6724c902005-10-28 07:07:19 +000046 const char *name = dwarf_diename (func);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000047 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
Roland McGrath07d4f2f2005-10-28 06:56:24 +000058 if (dwarf_func_inline (func))
59 return 0;
60
61 Dwarf_Addr entrypc;
Roland McGrath6724c902005-10-28 07:07:19 +000062 if (dwarf_entrypc (func, &entrypc) != 0)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000063 error (EXIT_FAILURE, 0, "dwarf_entrypc: %s: %s",
Roland McGrath6724c902005-10-28 07:07:19 +000064 dwarf_diename (func), dwarf_errmsg (-1));
Roland McGrath07d4f2f2005-10-28 06:56:24 +000065 entrypc += a->dwbias;
66
Roland McGrath6724c902005-10-28 07:07:19 +000067 printf ("%-16s %#.16" PRIx64, dwarf_diename (func), entrypc);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000068
69 Dwarf_Addr *bkpts = NULL;
Roland McGrath6724c902005-10-28 07:07:19 +000070 int result = dwarf_entry_breakpoints (func, &bkpts);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000071 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
85int
86main (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
Roland McGrath994b4892005-12-05 22:46:21 +0000105 dwfl_end (a.dwfl);
106
Roland McGrath07d4f2f2005-10-28 06:56:24 +0000107 return result;
108}