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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [support/] [debug.c] - Blame information for rev 588

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

Line No. Rev Author Line
1 19 jeremybenn
/* debug.c -- Debug channel support code
2
 
3
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
4
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
/* Autoconf and/or portability configuration */
28
#include "config.h"
29
#include "port.h"
30
 
31
/* System includes */
32
#include <stdlib.h>
33
#include <stdio.h>
34
#include <stdarg.h>
35
 
36
/* Package includes */
37
#include "arch.h"
38
#include "sim-config.h"
39
 
40
#define __ORSIM_NO_DEC_DBCH
41
#include "debug.h"
42
 
43
#define DECLARE_DEBUG_CHANNEL(dbch) char __orsim_dbch_##dbch[] = "\0"#dbch;
44
#include "dbchs.h"
45
#undef DECLARE_DEBUG_CHANNEL
46
 
47
#define DECLARE_DEBUG_CHANNEL(dbch) __orsim_dbch_##dbch,
48
static char *__orsim_dbchs[] = {
49
#include "dbchs.h"
50
NULL };
51
#undef DECLARE_DEBUG_CHANNEL
52
 
53
static const char *debug_classes[] = { "trace", "fixme", "warn", "err" };
54
 
55
 
56
void orsim_dbg_log(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch,
57
                   const char *function, const char *format, ...)
58
{
59
  va_list ap;
60
  static int last_lf = 1; /* There *has* to be a better way */
61
 
62
  if(last_lf)  {
63
    if(!TRACE_ON(cycles))
64
      fprintf(stderr, "%s:%s:%s: ", debug_classes[dbcl], dbch + 1, function);
65
    else
66
      fprintf(stderr, "%lld:%s:%s:%s: ", runtime.sim.cycles,
67
              debug_classes[dbcl], dbch + 1, function);
68
  }
69
  last_lf = format[strlen(format) - 1] == '\n'; /* This is wrong... */
70
  va_start(ap, format);
71
  vfprintf(stderr, format, ap);
72
  va_end(ap);
73
}
74
 
75
void orsim_dbcl_set(enum __ORSIM_DEBUG_CLASS dbcl, char *dbch, int on)
76
{
77
  if(on)
78
    dbch[0] |= 1 << dbcl;
79
  else
80
    dbch[0] &= ~(1 << dbcl);
81
}
82
 
83
void orsim_dbcl_set_name(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch, int on)
84
{
85
  char **dbchs = __orsim_dbchs;
86
 
87
  for(dbchs = __orsim_dbchs; *dbchs; dbchs++) {
88
    if(!strcmp(*dbchs + 1, dbch)) {
89
      orsim_dbcl_set(dbcl, *dbchs, on);
90
      break;
91
    }
92
  }
93
}
94
 
95
void parse_dbchs(const char *str)
96
{
97
  enum __ORSIM_DEBUG_CLASS dbcl = 0;
98
  int i;
99
  int disen;
100
  int all;
101
  const char *cend;
102
  const char *chan_end;
103
 
104
  while(*str) {
105
    cend = strpbrk(str, "+-");
106
    chan_end = strchr(str, ',');
107
    if(!chan_end)
108
      chan_end = str + strlen(str);
109
 
110
    if(!cend || (cend > chan_end)) {
111
      disen = 1;
112
      cend = --str;
113
    } else
114
      disen = *cend == '+' ? 1 : 0;
115
 
116
    if(cend == str) {
117
      all = 1;
118
    } else {
119
      for(i = 0; i < 4; i++) {
120
        if(!strncmp(str, debug_classes[i], cend - str)) {
121
          dbcl = i;
122
          break;
123
        }
124
      }
125
      if(i >= 4)
126
        fprintf(stderr, "Unknown class specified\n");
127
      all = 0;
128
    }
129
    cend++;
130
 
131
    for(i = 0; __orsim_dbchs[i]; i++)
132
      if(!strncmp(cend, __orsim_dbchs[i] + 1, chan_end - cend))
133
        break;
134
 
135
    if(!__orsim_dbchs[i])
136
      fprintf(stderr, "Unknown channel specified\n");
137
    else if(all) {
138
      orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
139
      orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
140
      orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
141
      orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
142
    } else
143
      orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
144
    if(*chan_end)
145
      str = chan_end + 1;
146
    else
147
      str = chan_end;
148
  }
149
}
150
 
151
 
152
/*---------------------------------------------------------------------------*/
153
/*!Internal debug function
154
 
155
   Print the message if the level is greater than or equal to that specified
156
   in the configuration.
157
 
158
   @param[in] level   The debug level of this message
159
   @param[in] format  Varargs format string
160
   @param[in] ...     The varargs required by the string                     */
161
/*---------------------------------------------------------------------------*/
162
void
163
debug (int         level,
164
       const char *format,
165
                   ...)
166
{
167
  if (config.sim.debug >= level)
168
    {
169
      va_list  ap;
170
 
171
      va_start (ap, format);
172
      vfprintf (runtime.sim.fout, format, ap);
173
      fflush (runtime.sim.fout);
174
    }
175
}       /* debug() */
176
 
177
 

powered by: WebSVN 2.1.0

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