OSDN Git Service

Merge dataflow branch into mainline
[pf3gnuchains/gcc-fork.git] / gcc / dbgcnt.c
1 /* Debug counter for debugging support
2    Copyright (C) 2006, 2007 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 2, 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 COPYING.  If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.  
20
21 See dbgcnt.def for usage information.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26
27 #include "dbgcnt.h"
28
29 struct string2counter_map {
30   const char *name;
31   enum debug_counter counter;
32 };
33
34 #define DEBUG_COUNTER(a) { #a , a },
35
36 static struct string2counter_map map[debug_counter_number_of_counters] =
37 {
38 #include "dbgcnt.def"
39 };
40 #undef DEBUG_COUNTER
41
42 #define DEBUG_COUNTER(a) UINT_MAX,
43 static unsigned int limit[debug_counter_number_of_counters] =
44 {
45 #include "dbgcnt.def"
46 };
47 #undef DEBUG_COUNTER
48
49 static unsigned int count[debug_counter_number_of_counters];
50
51 bool
52 dbg_cnt_is_enabled (enum debug_counter index)
53 {
54   return count[index] <= limit[index];
55 }
56
57 bool
58 dbg_cnt (enum debug_counter index)
59 {
60   count[index]++;
61   return dbg_cnt_is_enabled (index);
62 }
63
64
65 static void
66 dbg_cnt_set_limit_by_index (enum debug_counter index, int value)
67 {
68   limit[index] = value;
69
70   fprintf (stderr, "dbg_cnt '%s' set to %d\n", map[index].name, value);
71 }
72
73 static void
74 dbg_cnt_set_limit_by_name (const char *name, int len, int value)
75 {
76   int i;
77   for (i = debug_counter_number_of_counters - 1; i >= 0; i--)
78     if (!strncmp (map[i].name, name, len))
79       break;
80
81   if (i < 0)
82     return;
83
84   dbg_cnt_set_limit_by_index (i, value);
85 }
86
87 void
88 dbg_cnt_process_opt (const char *arg)
89 {
90    char *colon = strchr (arg, ':');
91    char *comma;
92    
93    if (colon == NULL)
94      return;
95
96    dbg_cnt_set_limit_by_name (arg, colon - arg, atoi (colon + 1));
97
98    comma = strchr (colon + 1, ',');
99    while (comma)
100      {
101        colon = strchr (comma + 1, ':');
102        if (colon == NULL || !(colon[1] >= '0' && colon[1] <= '9'))
103          return;
104        dbg_cnt_set_limit_by_name (comma + 1, colon - (comma + 1), atoi (colon + 1));
105        comma = strchr (colon + 1, ',');
106      }
107 }