1 /* Debug counter for debugging support
2 Copyright (C) 2006, 2007 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>.
20 See dbgcnt.def for usage information. */
24 #include "coretypes.h"
32 struct string2counter_map
{
34 enum debug_counter counter
;
37 #define DEBUG_COUNTER(a) { #a , a },
39 static struct string2counter_map map
[debug_counter_number_of_counters
] =
45 #define DEBUG_COUNTER(a) UINT_MAX,
46 static unsigned int limit
[debug_counter_number_of_counters
] =
52 static unsigned int count
[debug_counter_number_of_counters
];
55 dbg_cnt_is_enabled (enum debug_counter index
)
57 return count
[index
] <= limit
[index
];
61 dbg_cnt (enum debug_counter index
)
64 if (dump_file
&& count
[index
] == limit
[index
])
65 fprintf (dump_file
, "***dbgcnt: limit reached for %s.***\n",
68 return dbg_cnt_is_enabled (index
);
73 dbg_cnt_set_limit_by_index (enum debug_counter index
, int value
)
77 fprintf (stderr
, "dbg_cnt '%s' set to %d\n", map
[index
].name
, value
);
81 dbg_cnt_set_limit_by_name (const char *name
, int len
, int value
)
84 for (i
= debug_counter_number_of_counters
- 1; i
>= 0; i
--)
85 if (!strncmp (map
[i
].name
, name
, len
))
91 dbg_cnt_set_limit_by_index (i
, value
);
96 /* Process a single "name:value" pair.
97 Returns NULL if there's no valid pair is found.
98 Otherwise returns a pointer to the end of the pair. */
101 dbg_cnt_process_single_pair (const char *arg
)
103 char *colon
= strchr (arg
, ':');
110 value
= strtol (colon
+ 1, &endptr
, 10);
112 if (endptr
!= NULL
&& endptr
!= colon
+ 1
113 && dbg_cnt_set_limit_by_name (arg
, colon
- arg
, value
))
120 dbg_cnt_process_opt (const char *arg
)
122 const char *start
= arg
;
125 next
= dbg_cnt_process_single_pair (arg
);
128 } while (*next
== ',' && (arg
= next
+ 1));
130 if (next
== NULL
|| *next
!= 0)
132 char *buffer
= alloca (arg
- start
+ 2);
133 sprintf (buffer
, "%*c", (int)(1 + (arg
- start
)), '^');
134 error ("Can not find a valid counter:value pair:");
135 error ("-fdbg-cnt=%s", start
);
136 error (" %s", buffer
);
140 /* Print name, limit and count of all counters. */
143 dbg_cnt_list_all_counters (void)
146 printf (" %-30s %-5s %-5s\n", "counter name", "limit", "value");
147 printf ("----------------------------------------------\n");
148 for (i
= 0; i
< debug_counter_number_of_counters
; i
++)
149 printf (" %-30s %5d %5u\n",
150 map
[i
].name
, limit
[map
[i
].counter
], count
[map
[i
].counter
]);