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

Subversion Repositories or1k

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

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
  enum __ORSIM_DEBUG_CLASS dbcl;
91
  int i;
92
  int disen;
93
  int all;
94
  const char *cend;
95
 
96
  while(*str) {
97
    cend = strpbrk(str, "+-");
98
    if(cend == str) {
99
      all = 1;
100
    } else {
101
      for(i = 0; i < 5; i++) {
102
        if(!strncmp(str, debug_classes[i], cend - str)) {
103
          dbcl = i;
104
          break;
105
        }
106
      }
107
      if(i > 4)
108
        fprintf(stderr, "Unknown class specified\n");
109
      all = 0;
110
    }
111
    disen = *cend == '+' ? 1 : 0;
112
    str = cend + 1;
113
    cend = strchr(str, ',');
114
    if(!cend)
115
      cend = str + strlen(str);
116
    for(i = 0; __orsim_dbchs[i]; i++)
117
      if(!strncmp(str, __orsim_dbchs[i] + 1, cend - str))
118
        break;
119
 
120
    if(!__orsim_dbchs[i])
121
      fprintf(stderr, "Unknown channel specified\n");
122
 
123
    if(all) {
124
      orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
125
      orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
126
      orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
127
      orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
128
    } else
129
      orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
130
    if(*cend)
131
      str = cend + 1;
132
    else
133
      str = cend;
134
  }
135
}

powered by: WebSVN 2.1.0

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