Mercurial > hg > CbC > CbC_gcc
annotate gcc/dbgcnt.c @ 143:76e1cf5455ef
add cbc_gc test
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 Dec 2018 19:24:05 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
rev | line source |
---|---|
0 | 1 /* Debug counter for debugging support |
131 | 2 Copyright (C) 2006-2018 Free Software Foundation, Inc. |
0 | 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 | |
8 Software Foundation; either version 3, or (at your option) any later | |
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 | |
17 along with GCC; see the file COPYING3. If not see | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
18 <http://www.gnu.org/licenses/>. |
0 | 19 |
20 See dbgcnt.def for usage information. */ | |
21 | |
22 #include "config.h" | |
23 #include "system.h" | |
24 #include "coretypes.h" | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
25 #include "diagnostic-core.h" |
111 | 26 #include "dumpfile.h" |
0 | 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, | |
131 | 44 static unsigned int limit_high[debug_counter_number_of_counters] = |
0 | 45 { |
46 #include "dbgcnt.def" | |
47 }; | |
48 #undef DEBUG_COUNTER | |
49 | |
131 | 50 static unsigned int limit_low[debug_counter_number_of_counters]; |
51 | |
0 | 52 static unsigned int count[debug_counter_number_of_counters]; |
53 | |
54 bool | |
55 dbg_cnt_is_enabled (enum debug_counter index) | |
56 { | |
131 | 57 unsigned v = count[index]; |
58 return v > limit_low[index] && v <= limit_high[index]; | |
0 | 59 } |
60 | |
61 bool | |
62 dbg_cnt (enum debug_counter index) | |
63 { | |
64 count[index]++; | |
131 | 65 |
66 if (dump_file) | |
67 { | |
68 /* Do not print the info for default lower limit. */ | |
69 if (count[index] == limit_low[index] && limit_low[index] > 0) | |
70 fprintf (dump_file, "***dbgcnt: lower limit %d reached for %s.***\n", | |
71 limit_low[index], map[index].name); | |
72 else if (count[index] == limit_high[index]) | |
73 fprintf (dump_file, "***dbgcnt: upper limit %d reached for %s.***\n", | |
74 limit_high[index], map[index].name); | |
75 } | |
0 | 76 |
77 return dbg_cnt_is_enabled (index); | |
78 } | |
79 | |
80 static void | |
131 | 81 dbg_cnt_set_limit_by_index (enum debug_counter index, int low, int high) |
0 | 82 { |
131 | 83 limit_low[index] = low; |
84 limit_high[index] = high; | |
0 | 85 |
131 | 86 fprintf (stderr, "dbg_cnt '%s' set to %d-%d\n", map[index].name, low, high); |
0 | 87 } |
88 | |
89 static bool | |
131 | 90 dbg_cnt_set_limit_by_name (const char *name, int low, int high) |
0 | 91 { |
131 | 92 if (high < low) |
93 { | |
94 error ("-fdbg-cnt=%s:%d:%d has smaller upper limit than the lower", | |
95 name, low, high); | |
96 return false; | |
97 } | |
98 | |
99 if (low < 0) | |
100 { | |
101 error ("Lower limit %d of -fdbg-cnt=%s must be a non-negative number", low, | |
102 name); | |
103 return false; | |
104 } | |
105 | |
106 if (high < 0) | |
107 { | |
108 error ("Upper limit %d of -fdbg-cnt=%s must be a non-negative number", high, | |
109 name); | |
110 return false; | |
111 } | |
112 | |
0 | 113 int i; |
114 for (i = debug_counter_number_of_counters - 1; i >= 0; i--) | |
131 | 115 if (strcmp (map[i].name, name) == 0) |
0 | 116 break; |
117 | |
118 if (i < 0) | |
119 return false; | |
120 | |
131 | 121 dbg_cnt_set_limit_by_index ((enum debug_counter) i, low, high); |
0 | 122 return true; |
123 } | |
124 | |
125 | |
126 /* Process a single "name:value" pair. | |
127 Returns NULL if there's no valid pair is found. | |
128 Otherwise returns a pointer to the end of the pair. */ | |
129 | |
131 | 130 static bool |
0 | 131 dbg_cnt_process_single_pair (const char *arg) |
132 { | |
131 | 133 char *str = xstrdup (arg); |
134 char *name = strtok (str, ":"); | |
135 char *value1 = strtok (NULL, ":"); | |
136 char *value2 = strtok (NULL, ":"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
137 |
131 | 138 int high, low; |
139 | |
140 if (value1 == NULL) | |
141 return false; | |
0 | 142 |
131 | 143 if (value2 == NULL) |
144 { | |
145 low = 0; | |
146 high = strtol (value1, NULL, 10); | |
147 } | |
148 else | |
149 { | |
150 low = strtol (value1, NULL, 10); | |
151 high = strtol (value2, NULL, 10); | |
152 } | |
0 | 153 |
131 | 154 return dbg_cnt_set_limit_by_name (name, low, high); |
0 | 155 } |
156 | |
157 void | |
158 dbg_cnt_process_opt (const char *arg) | |
159 { | |
131 | 160 char *str = xstrdup (arg); |
161 const char *next = strtok (str, ","); | |
162 unsigned int start = 0; | |
163 | |
0 | 164 do { |
131 | 165 if (!dbg_cnt_process_single_pair (arg)) |
0 | 166 break; |
131 | 167 start += strlen (arg) + 1; |
168 next = strtok (NULL, ","); | |
169 } while (next != NULL); | |
0 | 170 |
131 | 171 if (next != NULL) |
0 | 172 { |
131 | 173 char *buffer = XALLOCAVEC (char, start + 2); |
174 sprintf (buffer, "%*c", start + 1, '^'); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
175 error ("cannot find a valid counter:value pair:"); |
131 | 176 error ("-fdbg-cnt=%s", next); |
0 | 177 error (" %s", buffer); |
178 } | |
179 } | |
180 | |
181 /* Print name, limit and count of all counters. */ | |
182 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
183 void |
0 | 184 dbg_cnt_list_all_counters (void) |
185 { | |
186 int i; | |
131 | 187 printf (" %-32s %-11s %-12s\n", "counter name", "low limit", |
188 "high limit"); | |
189 printf ("-----------------------------------------------------------------\n"); | |
0 | 190 for (i = 0; i < debug_counter_number_of_counters; i++) |
131 | 191 printf (" %-30s %11u %12u\n", |
192 map[i].name, limit_low[map[i].counter], limit_high[map[i].counter]); | |
0 | 193 printf ("\n"); |
194 } |