OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [dbgcnt.c] - Blame information for rev 865

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.