* jvspec.c (jvgenmain_spec): Don't handle -fnew-verifier.
[gcc.git] / gcc / dbgcnt.c
1 /* Debug counter for debugging support
2 Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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
18 <http://www.gnu.org/licenses/>.
19
20 See dbgcnt.def for usage information. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "diagnostic-core.h"
26 #include "toplev.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "output.h"
30
31 #include "dbgcnt.h"
32
33 struct string2counter_map {
34 const char *name;
35 enum debug_counter counter;
36 };
37
38 #define DEBUG_COUNTER(a) { #a , a },
39
40 static struct string2counter_map map[debug_counter_number_of_counters] =
41 {
42 #include "dbgcnt.def"
43 };
44 #undef DEBUG_COUNTER
45
46 #define DEBUG_COUNTER(a) UINT_MAX,
47 static unsigned int limit[debug_counter_number_of_counters] =
48 {
49 #include "dbgcnt.def"
50 };
51 #undef DEBUG_COUNTER
52
53 static unsigned int count[debug_counter_number_of_counters];
54
55 bool
56 dbg_cnt_is_enabled (enum debug_counter index)
57 {
58 return count[index] <= limit[index];
59 }
60
61 bool
62 dbg_cnt (enum debug_counter index)
63 {
64 count[index]++;
65 if (dump_file && count[index] == limit[index])
66 fprintf (dump_file, "***dbgcnt: limit reached for %s.***\n",
67 map[index].name);
68
69 return dbg_cnt_is_enabled (index);
70 }
71
72
73 static void
74 dbg_cnt_set_limit_by_index (enum debug_counter index, int value)
75 {
76 limit[index] = value;
77
78 fprintf (stderr, "dbg_cnt '%s' set to %d\n", map[index].name, value);
79 }
80
81 static bool
82 dbg_cnt_set_limit_by_name (const char *name, int len, int value)
83 {
84 int i;
85 for (i = debug_counter_number_of_counters - 1; i >= 0; i--)
86 if (strncmp (map[i].name, name, len) == 0
87 && map[i].name[len] == '\0')
88 break;
89
90 if (i < 0)
91 return false;
92
93 dbg_cnt_set_limit_by_index ((enum debug_counter) i, value);
94 return true;
95 }
96
97
98 /* Process a single "name:value" pair.
99 Returns NULL if there's no valid pair is found.
100 Otherwise returns a pointer to the end of the pair. */
101
102 static const char *
103 dbg_cnt_process_single_pair (const char *arg)
104 {
105 const char *colon = strchr (arg, ':');
106 char *endptr = NULL;
107 int value;
108
109 if (colon == NULL)
110 return NULL;
111
112 value = strtol (colon + 1, &endptr, 10);
113
114 if (endptr != NULL && endptr != colon + 1
115 && dbg_cnt_set_limit_by_name (arg, colon - arg, value))
116 return endptr;
117
118 return NULL;
119 }
120
121 void
122 dbg_cnt_process_opt (const char *arg)
123 {
124 const char *start = arg;
125 const char *next;
126 do {
127 next = dbg_cnt_process_single_pair (arg);
128 if (next == NULL)
129 break;
130 } while (*next == ',' && (arg = next + 1));
131
132 if (next == NULL || *next != 0)
133 {
134 char *buffer = XALLOCAVEC (char, arg - start + 2);
135 sprintf (buffer, "%*c", (int)(1 + (arg - start)), '^');
136 error ("Can not find a valid counter:value pair:");
137 error ("-fdbg-cnt=%s", start);
138 error (" %s", buffer);
139 }
140 }
141
142 /* Print name, limit and count of all counters. */
143
144 void
145 dbg_cnt_list_all_counters (void)
146 {
147 int i;
148 printf (" %-30s %-5s %-5s\n", "counter name", "limit", "value");
149 printf ("----------------------------------------------\n");
150 for (i = 0; i < debug_counter_number_of_counters; i++)
151 printf (" %-30s %5d %5u\n",
152 map[i].name, limit[map[i].counter], count[map[i].counter]);
153 printf ("\n");
154 }