blob: 0a2e86e0d80d2ef92827491f3ede51ecff8c2982 [file] [log] [blame]
Roland McGrath07d4f2f2005-10-28 06:56:24 +00001/* Test program for dwarf_entry_breakpoints.
2 Copyright (C) 2005 Red Hat, Inc.
3
4 This program is Open Source software; you can redistribute it and/or
5 modify it under the terms of the Open Software License version 1.0 as
6 published by the Open Source Initiative.
7
8 You should have received a copy of the Open Software License along
9 with this program; if not, you may obtain a copy of the Open Software
10 License version 1.0 from http://www.opensource.org/licenses/osl.php or
11 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12 3001 King Ranch Road, Ukiah, CA 95482. */
13
14#include <config.h>
15#include <assert.h>
16#include <inttypes.h>
17#include <libdwfl.h>
18#include <dwarf.h>
19#include <argp.h>
20#include <stdio.h>
21#include <stdio_ext.h>
22#include <locale.h>
23#include <stdlib.h>
24#include <error.h>
25#include <string.h>
26#include <fnmatch.h>
27
28
29struct args
30{
31 Dwfl *dwfl;
32 Dwarf_Die *cu;
33 Dwarf_Addr dwbias;
34 char **argv;
35};
36
37static int
Roland McGrath6724c902005-10-28 07:07:19 +000038handle_function (Dwarf_Die *func, void *arg)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000039{
40 struct args *a = arg;
41
Roland McGrath6724c902005-10-28 07:07:19 +000042 const char *name = dwarf_diename (func);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000043 char **argv = a->argv;
44 if (argv[0] != NULL)
45 {
46 bool match;
47 do
48 match = fnmatch (*argv, name, 0) == 0;
49 while (!match && *++argv);
50 if (!match)
51 return 0;
52 }
53
Roland McGrath07d4f2f2005-10-28 06:56:24 +000054 if (dwarf_func_inline (func))
55 return 0;
56
57 Dwarf_Addr entrypc;
Roland McGrath6724c902005-10-28 07:07:19 +000058 if (dwarf_entrypc (func, &entrypc) != 0)
Roland McGrath07d4f2f2005-10-28 06:56:24 +000059 error (EXIT_FAILURE, 0, "dwarf_entrypc: %s: %s",
Roland McGrath6724c902005-10-28 07:07:19 +000060 dwarf_diename (func), dwarf_errmsg (-1));
Roland McGrath07d4f2f2005-10-28 06:56:24 +000061 entrypc += a->dwbias;
62
Roland McGrath6724c902005-10-28 07:07:19 +000063 printf ("%-16s %#.16" PRIx64, dwarf_diename (func), entrypc);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000064
65 Dwarf_Addr *bkpts = NULL;
Roland McGrath6724c902005-10-28 07:07:19 +000066 int result = dwarf_entry_breakpoints (func, &bkpts);
Roland McGrath07d4f2f2005-10-28 06:56:24 +000067 if (result <= 0)
68 printf ("\t%s\n", dwarf_errmsg (-1));
69 else
70 {
71 for (int i = 0; i < result; ++i)
72 printf (" %#.16" PRIx64 "%s", bkpts[i] + a->dwbias,
73 i == result - 1 ? "\n" : "");
74 free (bkpts);
75 }
76
77 return 0;
78}
79
80
81int
82main (int argc, char *argv[])
83{
84 int remaining;
85
86 /* Set locale. */
87 (void) setlocale (LC_ALL, "");
88
89 struct args a = { .dwfl = NULL, .cu = NULL };
90
91 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining,
92 &a.dwfl);
93 assert (a.dwfl != NULL);
94 a.argv = &argv[remaining];
95
96 int result = 0;
97
98 while ((a.cu = dwfl_nextcu (a.dwfl, a.cu, &a.dwbias)) != NULL)
99 dwarf_getfuncs (a.cu, &handle_function, &a, 0);
100
101 return result;
102}