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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [support/] [debug.c] - Blame information for rev 1748

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

Line No. Rev Author Line
1 1389 nogj
/* debug.c -- Debug channel support code
2 1748 jeremybenn
 
3 1389 nogj
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
4 1748 jeremybenn
   Copyright (C) 2008 Embecosm Limited
5 1389 nogj
 
6 1748 jeremybenn
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7 1389 nogj
 
8 1748 jeremybenn
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9 1389 nogj
 
10 1748 jeremybenn
   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 1389 nogj
 
15 1748 jeremybenn
   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 1389 nogj
 
20 1748 jeremybenn
   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 1389 nogj
 
23 1748 jeremybenn
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
/* Autoconf and/or portability configuration */
28 1522 nogj
#include "config.h"
29 1748 jeremybenn
#include "port.h"
30 1522 nogj
 
31 1748 jeremybenn
/* System includes */
32
#include <stdlib.h>
33
#include <stdio.h>
34
#include <stdarg.h>
35 1522 nogj
 
36 1748 jeremybenn
/* Package includes */
37 1522 nogj
#include "arch.h"
38
#include "sim-config.h"
39
 
40 1389 nogj
#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 1748 jeremybenn
 
56 1389 nogj
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 1522 nogj
  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 1389 nogj
  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 1557 nogj
  enum __ORSIM_DEBUG_CLASS dbcl = 0;
98 1389 nogj
  int i;
99
  int disen;
100
  int all;
101
  const char *cend;
102 1589 nogj
  const char *chan_end;
103 1389 nogj
 
104
  while(*str) {
105
    cend = strpbrk(str, "+-");
106 1589 nogj
    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 1389 nogj
    if(cend == str) {
117
      all = 1;
118
    } else {
119 1569 nogj
      for(i = 0; i < 4; i++) {
120 1389 nogj
        if(!strncmp(str, debug_classes[i], cend - str)) {
121
          dbcl = i;
122
          break;
123
        }
124
      }
125 1569 nogj
      if(i >= 4)
126 1389 nogj
        fprintf(stderr, "Unknown class specified\n");
127
      all = 0;
128
    }
129 1589 nogj
    cend++;
130
 
131 1389 nogj
    for(i = 0; __orsim_dbchs[i]; i++)
132 1589 nogj
      if(!strncmp(cend, __orsim_dbchs[i] + 1, chan_end - cend))
133 1389 nogj
        break;
134
 
135
    if(!__orsim_dbchs[i])
136
      fprintf(stderr, "Unknown channel specified\n");
137 1569 nogj
    else if(all) {
138 1389 nogj
      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 1589 nogj
    if(*chan_end)
145
      str = chan_end + 1;
146 1389 nogj
    else
147 1589 nogj
      str = chan_end;
148 1389 nogj
  }
149
}
150 1748 jeremybenn
 
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.