Mercurial > hg > CbC > CbC_gcc
comparison gcc/dbgcnt.c @ 132:d34655255c78
update gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 10:21:07 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
130:e108057fa461 | 132:d34655255c78 |
---|---|
1 /* Debug counter for debugging support | 1 /* Debug counter for debugging support |
2 Copyright (C) 2006-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2006-2018 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 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 | 7 the terms of the GNU General Public License as published by the Free |
39 #include "dbgcnt.def" | 39 #include "dbgcnt.def" |
40 }; | 40 }; |
41 #undef DEBUG_COUNTER | 41 #undef DEBUG_COUNTER |
42 | 42 |
43 #define DEBUG_COUNTER(a) UINT_MAX, | 43 #define DEBUG_COUNTER(a) UINT_MAX, |
44 static unsigned int limit[debug_counter_number_of_counters] = | 44 static unsigned int limit_high[debug_counter_number_of_counters] = |
45 { | 45 { |
46 #include "dbgcnt.def" | 46 #include "dbgcnt.def" |
47 }; | 47 }; |
48 #undef DEBUG_COUNTER | 48 #undef DEBUG_COUNTER |
49 | |
50 static unsigned int limit_low[debug_counter_number_of_counters]; | |
49 | 51 |
50 static unsigned int count[debug_counter_number_of_counters]; | 52 static unsigned int count[debug_counter_number_of_counters]; |
51 | 53 |
52 bool | 54 bool |
53 dbg_cnt_is_enabled (enum debug_counter index) | 55 dbg_cnt_is_enabled (enum debug_counter index) |
54 { | 56 { |
55 return count[index] <= limit[index]; | 57 unsigned v = count[index]; |
58 return v > limit_low[index] && v <= limit_high[index]; | |
56 } | 59 } |
57 | 60 |
58 bool | 61 bool |
59 dbg_cnt (enum debug_counter index) | 62 dbg_cnt (enum debug_counter index) |
60 { | 63 { |
61 count[index]++; | 64 count[index]++; |
62 if (dump_file && count[index] == limit[index]) | 65 |
63 fprintf (dump_file, "***dbgcnt: limit reached for %s.***\n", | 66 if (dump_file) |
64 map[index].name); | 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 } | |
65 | 76 |
66 return dbg_cnt_is_enabled (index); | 77 return dbg_cnt_is_enabled (index); |
67 } | 78 } |
68 | 79 |
80 static void | |
81 dbg_cnt_set_limit_by_index (enum debug_counter index, int low, int high) | |
82 { | |
83 limit_low[index] = low; | |
84 limit_high[index] = high; | |
69 | 85 |
70 static void | 86 fprintf (stderr, "dbg_cnt '%s' set to %d-%d\n", map[index].name, low, high); |
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 } | 87 } |
77 | 88 |
78 static bool | 89 static bool |
79 dbg_cnt_set_limit_by_name (const char *name, int len, int value) | 90 dbg_cnt_set_limit_by_name (const char *name, int low, int high) |
80 { | 91 { |
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 | |
81 int i; | 113 int i; |
82 for (i = debug_counter_number_of_counters - 1; i >= 0; i--) | 114 for (i = debug_counter_number_of_counters - 1; i >= 0; i--) |
83 if (strncmp (map[i].name, name, len) == 0 | 115 if (strcmp (map[i].name, name) == 0) |
84 && map[i].name[len] == '\0') | |
85 break; | 116 break; |
86 | 117 |
87 if (i < 0) | 118 if (i < 0) |
88 return false; | 119 return false; |
89 | 120 |
90 dbg_cnt_set_limit_by_index ((enum debug_counter) i, value); | 121 dbg_cnt_set_limit_by_index ((enum debug_counter) i, low, high); |
91 return true; | 122 return true; |
92 } | 123 } |
93 | 124 |
94 | 125 |
95 /* Process a single "name:value" pair. | 126 /* Process a single "name:value" pair. |
96 Returns NULL if there's no valid pair is found. | 127 Returns NULL if there's no valid pair is found. |
97 Otherwise returns a pointer to the end of the pair. */ | 128 Otherwise returns a pointer to the end of the pair. */ |
98 | 129 |
99 static const char * | 130 static bool |
100 dbg_cnt_process_single_pair (const char *arg) | 131 dbg_cnt_process_single_pair (const char *arg) |
101 { | 132 { |
102 const char *colon = strchr (arg, ':'); | 133 char *str = xstrdup (arg); |
103 char *endptr = NULL; | 134 char *name = strtok (str, ":"); |
104 int value; | 135 char *value1 = strtok (NULL, ":"); |
136 char *value2 = strtok (NULL, ":"); | |
105 | 137 |
106 if (colon == NULL) | 138 int high, low; |
107 return NULL; | |
108 | 139 |
109 value = strtol (colon + 1, &endptr, 10); | 140 if (value1 == NULL) |
141 return false; | |
110 | 142 |
111 if (endptr != NULL && endptr != colon + 1 | 143 if (value2 == NULL) |
112 && dbg_cnt_set_limit_by_name (arg, colon - arg, value)) | 144 { |
113 return endptr; | 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 } | |
114 | 153 |
115 return NULL; | 154 return dbg_cnt_set_limit_by_name (name, low, high); |
116 } | 155 } |
117 | 156 |
118 void | 157 void |
119 dbg_cnt_process_opt (const char *arg) | 158 dbg_cnt_process_opt (const char *arg) |
120 { | 159 { |
121 const char *start = arg; | 160 char *str = xstrdup (arg); |
122 const char *next; | 161 const char *next = strtok (str, ","); |
162 unsigned int start = 0; | |
163 | |
123 do { | 164 do { |
124 next = dbg_cnt_process_single_pair (arg); | 165 if (!dbg_cnt_process_single_pair (arg)) |
125 if (next == NULL) | |
126 break; | 166 break; |
127 } while (*next == ',' && (arg = next + 1)); | 167 start += strlen (arg) + 1; |
168 next = strtok (NULL, ","); | |
169 } while (next != NULL); | |
128 | 170 |
129 if (next == NULL || *next != 0) | 171 if (next != NULL) |
130 { | 172 { |
131 char *buffer = XALLOCAVEC (char, arg - start + 2); | 173 char *buffer = XALLOCAVEC (char, start + 2); |
132 sprintf (buffer, "%*c", (int)(1 + (arg - start)), '^'); | 174 sprintf (buffer, "%*c", start + 1, '^'); |
133 error ("cannot find a valid counter:value pair:"); | 175 error ("cannot find a valid counter:value pair:"); |
134 error ("-fdbg-cnt=%s", start); | 176 error ("-fdbg-cnt=%s", next); |
135 error (" %s", buffer); | 177 error (" %s", buffer); |
136 } | 178 } |
137 } | 179 } |
138 | 180 |
139 /* Print name, limit and count of all counters. */ | 181 /* Print name, limit and count of all counters. */ |
140 | 182 |
141 void | 183 void |
142 dbg_cnt_list_all_counters (void) | 184 dbg_cnt_list_all_counters (void) |
143 { | 185 { |
144 int i; | 186 int i; |
145 printf (" %-30s %-5s %-5s\n", "counter name", "limit", "value"); | 187 printf (" %-32s %-11s %-12s\n", "counter name", "low limit", |
146 printf ("----------------------------------------------\n"); | 188 "high limit"); |
189 printf ("-----------------------------------------------------------------\n"); | |
147 for (i = 0; i < debug_counter_number_of_counters; i++) | 190 for (i = 0; i < debug_counter_number_of_counters; i++) |
148 printf (" %-30s %5d %5u\n", | 191 printf (" %-30s %11u %12u\n", |
149 map[i].name, limit[map[i].counter], count[map[i].counter]); | 192 map[i].name, limit_low[map[i].counter], limit_high[map[i].counter]); |
150 printf ("\n"); | 193 printf ("\n"); |
151 } | 194 } |