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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [support/] [debug.c] - Blame information for rev 1780

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
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
#include <stdio.h>
21
#include <stdarg.h>
22
#include <string.h>
23
 
24 1522 nogj
#include "config.h"
25
 
26
#ifdef HAVE_INTTYPES_H
27
#include <inttypes.h>
28
#endif
29
 
30
#include "port.h"
31
#include "arch.h"
32
#include "sim-config.h"
33
 
34 1389 nogj
#define __ORSIM_NO_DEC_DBCH
35
#include "debug.h"
36
 
37
#define DECLARE_DEBUG_CHANNEL(dbch) char __orsim_dbch_##dbch[] = "\0"#dbch;
38
#include "dbchs.h"
39
#undef DECLARE_DEBUG_CHANNEL
40
 
41
#define DECLARE_DEBUG_CHANNEL(dbch) __orsim_dbch_##dbch,
42
static char *__orsim_dbchs[] = {
43
#include "dbchs.h"
44
NULL };
45
#undef DECLARE_DEBUG_CHANNEL
46
 
47
static const char *debug_classes[] = { "trace", "fixme", "warn", "err" };
48
 
49
void orsim_dbg_log(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch,
50
                   const char *function, const char *format, ...)
51
{
52
  va_list ap;
53
  static int last_lf = 1; /* There *has* to be a better way */
54
 
55 1522 nogj
  if(last_lf)  {
56
    if(!TRACE_ON(cycles))
57
      fprintf(stderr, "%s:%s:%s: ", debug_classes[dbcl], dbch + 1, function);
58
    else
59
      fprintf(stderr, "%lld:%s:%s:%s: ", runtime.sim.cycles,
60
              debug_classes[dbcl], dbch + 1, function);
61
  }
62 1389 nogj
  last_lf = format[strlen(format) - 1] == '\n'; /* This is wrong... */
63
  va_start(ap, format);
64
  vfprintf(stderr, format, ap);
65
  va_end(ap);
66
}
67
 
68
void orsim_dbcl_set(enum __ORSIM_DEBUG_CLASS dbcl, char *dbch, int on)
69
{
70
  if(on)
71
    dbch[0] |= 1 << dbcl;
72
  else
73
    dbch[0] &= ~(1 << dbcl);
74
}
75
 
76
void orsim_dbcl_set_name(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch, int on)
77
{
78
  char **dbchs = __orsim_dbchs;
79
 
80
  for(dbchs = __orsim_dbchs; *dbchs; dbchs++) {
81
    if(!strcmp(*dbchs + 1, dbch)) {
82
      orsim_dbcl_set(dbcl, *dbchs, on);
83
      break;
84
    }
85
  }
86
}
87
 
88
void parse_dbchs(const char *str)
89
{
90 1557 nogj
  enum __ORSIM_DEBUG_CLASS dbcl = 0;
91 1389 nogj
  int i;
92
  int disen;
93
  int all;
94
  const char *cend;
95 1589 nogj
  const char *chan_end;
96 1389 nogj
 
97
  while(*str) {
98
    cend = strpbrk(str, "+-");
99 1589 nogj
    chan_end = strchr(str, ',');
100
    if(!chan_end)
101
      chan_end = str + strlen(str);
102
 
103
    if(!cend || (cend > chan_end)) {
104
      disen = 1;
105
      cend = --str;
106
    } else
107
      disen = *cend == '+' ? 1 : 0;
108
 
109 1389 nogj
    if(cend == str) {
110
      all = 1;
111
    } else {
112 1569 nogj
      for(i = 0; i < 4; i++) {
113 1389 nogj
        if(!strncmp(str, debug_classes[i], cend - str)) {
114
          dbcl = i;
115
          break;
116
        }
117
      }
118 1569 nogj
      if(i >= 4)
119 1389 nogj
        fprintf(stderr, "Unknown class specified\n");
120
      all = 0;
121
    }
122 1589 nogj
    cend++;
123
 
124 1389 nogj
    for(i = 0; __orsim_dbchs[i]; i++)
125 1589 nogj
      if(!strncmp(cend, __orsim_dbchs[i] + 1, chan_end - cend))
126 1389 nogj
        break;
127
 
128
    if(!__orsim_dbchs[i])
129
      fprintf(stderr, "Unknown channel specified\n");
130 1569 nogj
    else if(all) {
131 1389 nogj
      orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
132
      orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
133
      orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
134
      orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
135
    } else
136
      orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
137 1589 nogj
    if(*chan_end)
138
      str = chan_end + 1;
139 1389 nogj
    else
140 1589 nogj
      str = chan_end;
141 1389 nogj
  }
142
}

powered by: WebSVN 2.1.0

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