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

Subversion Repositories or1k

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

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
  if(!(dbch[0] & (1 << dbcl)))
56
    return;
57
 
58 1522 nogj
  if(last_lf)  {
59
    if(!TRACE_ON(cycles))
60
      fprintf(stderr, "%s:%s:%s: ", debug_classes[dbcl], dbch + 1, function);
61
    else
62
      fprintf(stderr, "%lld:%s:%s:%s: ", runtime.sim.cycles,
63
              debug_classes[dbcl], dbch + 1, function);
64
  }
65 1389 nogj
  last_lf = format[strlen(format) - 1] == '\n'; /* This is wrong... */
66
  va_start(ap, format);
67
  vfprintf(stderr, format, ap);
68
  va_end(ap);
69
}
70
 
71
void orsim_dbcl_set(enum __ORSIM_DEBUG_CLASS dbcl, char *dbch, int on)
72
{
73
  if(on)
74
    dbch[0] |= 1 << dbcl;
75
  else
76
    dbch[0] &= ~(1 << dbcl);
77
}
78
 
79
void orsim_dbcl_set_name(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch, int on)
80
{
81
  char **dbchs = __orsim_dbchs;
82
 
83
  for(dbchs = __orsim_dbchs; *dbchs; dbchs++) {
84
    if(!strcmp(*dbchs + 1, dbch)) {
85
      orsim_dbcl_set(dbcl, *dbchs, on);
86
      break;
87
    }
88
  }
89
}
90
 
91
void parse_dbchs(const char *str)
92
{
93
  enum __ORSIM_DEBUG_CLASS dbcl;
94
  int i;
95
  int disen;
96
  int all;
97
  const char *cend;
98
 
99
  while(*str) {
100
    cend = strpbrk(str, "+-");
101
    if(cend == str) {
102
      all = 1;
103
    } else {
104
      for(i = 0; i < 5; i++) {
105
        if(!strncmp(str, debug_classes[i], cend - str)) {
106
          dbcl = i;
107
          break;
108
        }
109
      }
110
      if(i > 4)
111
        fprintf(stderr, "Unknown class specified\n");
112
      all = 0;
113
    }
114
    disen = *cend == '+' ? 1 : 0;
115
    str = cend + 1;
116
    cend = strchr(str, ',');
117
    if(!cend)
118
      cend = str + strlen(str);
119
    for(i = 0; __orsim_dbchs[i]; i++)
120
      if(!strncmp(str, __orsim_dbchs[i] + 1, cend - str))
121
        break;
122
 
123
    if(!__orsim_dbchs[i])
124
      fprintf(stderr, "Unknown channel specified\n");
125
 
126
    if(all) {
127
      orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
128
      orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
129
      orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
130
      orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
131
    } else
132
      orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
133
    if(*cend)
134
      str = cend + 1;
135
    else
136
      str = cend;
137
  }
138
}

powered by: WebSVN 2.1.0

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