]>
Commit | Line | Data |
---|---|---|
6fb5fa3c | 1 | /* Debug counter for debugging support |
85ec4feb | 2 | Copyright (C) 2006-2018 Free Software Foundation, Inc. |
6fb5fa3c DB |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 8 | Software Foundation; either version 3, or (at your option) any later |
6fb5fa3c DB |
9 | version. |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
9dcd6f09 | 17 | along with GCC; see the file COPYING3. If not see |
b8698a0f | 18 | <http://www.gnu.org/licenses/>. |
6fb5fa3c DB |
19 | |
20 | See dbgcnt.def for usage information. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
718f9c0f | 25 | #include "diagnostic-core.h" |
7ee2468b | 26 | #include "dumpfile.h" |
6fb5fa3c DB |
27 | |
28 | #include "dbgcnt.h" | |
29 | ||
30 | struct string2counter_map { | |
31 | const char *name; | |
32 | enum debug_counter counter; | |
33 | }; | |
34 | ||
35 | #define DEBUG_COUNTER(a) { #a , a }, | |
36 | ||
37 | static struct string2counter_map map[debug_counter_number_of_counters] = | |
38 | { | |
39 | #include "dbgcnt.def" | |
40 | }; | |
41 | #undef DEBUG_COUNTER | |
42 | ||
43 | #define DEBUG_COUNTER(a) UINT_MAX, | |
44 | static unsigned int limit[debug_counter_number_of_counters] = | |
45 | { | |
46 | #include "dbgcnt.def" | |
47 | }; | |
48 | #undef DEBUG_COUNTER | |
49 | ||
50 | static unsigned int count[debug_counter_number_of_counters]; | |
51 | ||
52 | bool | |
53 | dbg_cnt_is_enabled (enum debug_counter index) | |
54 | { | |
55 | return count[index] <= limit[index]; | |
56 | } | |
57 | ||
58 | bool | |
59 | dbg_cnt (enum debug_counter index) | |
60 | { | |
61 | count[index]++; | |
cc806ac1 | 62 | if (dump_file && count[index] == limit[index]) |
b8698a0f | 63 | fprintf (dump_file, "***dbgcnt: limit reached for %s.***\n", |
cc806ac1 RS |
64 | map[index].name); |
65 | ||
6fb5fa3c DB |
66 | return dbg_cnt_is_enabled (index); |
67 | } | |
68 | ||
69 | ||
70 | static void | |
71 | dbg_cnt_set_limit_by_index (enum debug_counter index, int value) | |
72 | { | |
73 | limit[index] = value; | |
74 | ||
75 | fprintf (stderr, "dbg_cnt '%s' set to %d\n", map[index].name, value); | |
76 | } | |
77 | ||
0a090f42 | 78 | static bool |
6fb5fa3c DB |
79 | dbg_cnt_set_limit_by_name (const char *name, int len, int value) |
80 | { | |
81 | int i; | |
82 | for (i = debug_counter_number_of_counters - 1; i >= 0; i--) | |
d0763469 XDL |
83 | if (strncmp (map[i].name, name, len) == 0 |
84 | && map[i].name[len] == '\0') | |
6fb5fa3c DB |
85 | break; |
86 | ||
87 | if (i < 0) | |
0a090f42 | 88 | return false; |
6fb5fa3c | 89 | |
bbbbb16a | 90 | dbg_cnt_set_limit_by_index ((enum debug_counter) i, value); |
0a090f42 | 91 | return true; |
6fb5fa3c DB |
92 | } |
93 | ||
0a090f42 SP |
94 | |
95 | /* Process a single "name:value" pair. | |
96 | Returns NULL if there's no valid pair is found. | |
97 | Otherwise returns a pointer to the end of the pair. */ | |
98 | ||
99 | static const char * | |
100 | dbg_cnt_process_single_pair (const char *arg) | |
6fb5fa3c | 101 | { |
86373e7e | 102 | const char *colon = strchr (arg, ':'); |
0a090f42 SP |
103 | char *endptr = NULL; |
104 | int value; | |
b8698a0f | 105 | |
6fb5fa3c | 106 | if (colon == NULL) |
0a090f42 SP |
107 | return NULL; |
108 | ||
109 | value = strtol (colon + 1, &endptr, 10); | |
6fb5fa3c | 110 | |
0a090f42 SP |
111 | if (endptr != NULL && endptr != colon + 1 |
112 | && dbg_cnt_set_limit_by_name (arg, colon - arg, value)) | |
113 | return endptr; | |
b8698a0f | 114 | |
0a090f42 SP |
115 | return NULL; |
116 | } | |
6fb5fa3c | 117 | |
0a090f42 SP |
118 | void |
119 | dbg_cnt_process_opt (const char *arg) | |
120 | { | |
121 | const char *start = arg; | |
122 | const char *next; | |
123 | do { | |
124 | next = dbg_cnt_process_single_pair (arg); | |
125 | if (next == NULL) | |
126 | break; | |
127 | } while (*next == ',' && (arg = next + 1)); | |
128 | ||
129 | if (next == NULL || *next != 0) | |
6fb5fa3c | 130 | { |
f883e0a7 | 131 | char *buffer = XALLOCAVEC (char, arg - start + 2); |
0a090f42 | 132 | sprintf (buffer, "%*c", (int)(1 + (arg - start)), '^'); |
d8a07487 | 133 | error ("cannot find a valid counter:value pair:"); |
0a090f42 SP |
134 | error ("-fdbg-cnt=%s", start); |
135 | error (" %s", buffer); | |
6fb5fa3c DB |
136 | } |
137 | } | |
0a090f42 SP |
138 | |
139 | /* Print name, limit and count of all counters. */ | |
140 | ||
b8698a0f | 141 | void |
cc806ac1 | 142 | dbg_cnt_list_all_counters (void) |
0a090f42 SP |
143 | { |
144 | int i; | |
145 | printf (" %-30s %-5s %-5s\n", "counter name", "limit", "value"); | |
146 | printf ("----------------------------------------------\n"); | |
147 | for (i = 0; i < debug_counter_number_of_counters; i++) | |
148 | printf (" %-30s %5d %5u\n", | |
149 | map[i].name, limit[map[i].counter], count[map[i].counter]); | |
150 | printf ("\n"); | |
151 | } |