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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [support/] [debug.c] - Blame information for rev 1765

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
#define __ORSIM_NO_DEC_DBCH
25
#include "debug.h"
26
 
27
#define DECLARE_DEBUG_CHANNEL(dbch) char __orsim_dbch_##dbch[] = "\0"#dbch;
28
#include "dbchs.h"
29
#undef DECLARE_DEBUG_CHANNEL
30
 
31
#define DECLARE_DEBUG_CHANNEL(dbch) __orsim_dbch_##dbch,
32
static char *__orsim_dbchs[] = {
33
#include "dbchs.h"
34
NULL };
35
#undef DECLARE_DEBUG_CHANNEL
36
 
37
static const char *debug_classes[] = { "trace", "fixme", "warn", "err" };
38
 
39
void orsim_dbg_log(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch,
40
                   const char *function, const char *format, ...)
41
{
42
  va_list ap;
43
  static int last_lf = 1; /* There *has* to be a better way */
44
 
45
  if(!(dbch[0] & (1 << dbcl)))
46
    return;
47
 
48
  if(last_lf)
49
    fprintf(stderr, "%s:%s:%s: ", debug_classes[dbcl], dbch + 1, function);
50
  last_lf = format[strlen(format) - 1] == '\n'; /* This is wrong... */
51
  va_start(ap, format);
52
  vfprintf(stderr, format, ap);
53
  va_end(ap);
54
}
55
 
56
void orsim_dbcl_set(enum __ORSIM_DEBUG_CLASS dbcl, char *dbch, int on)
57
{
58
  if(on)
59
    dbch[0] |= 1 << dbcl;
60
  else
61
    dbch[0] &= ~(1 << dbcl);
62
}
63
 
64
void orsim_dbcl_set_name(enum __ORSIM_DEBUG_CLASS dbcl, const char *dbch, int on)
65
{
66
  char **dbchs = __orsim_dbchs;
67
 
68
  for(dbchs = __orsim_dbchs; *dbchs; dbchs++) {
69
    if(!strcmp(*dbchs + 1, dbch)) {
70
      orsim_dbcl_set(dbcl, *dbchs, on);
71
      break;
72
    }
73
  }
74
}
75
 
76
void parse_dbchs(const char *str)
77
{
78
  enum __ORSIM_DEBUG_CLASS dbcl;
79
  int i;
80
  int disen;
81
  int all;
82
  const char *cend;
83
 
84
  while(*str) {
85
    cend = strpbrk(str, "+-");
86
    if(cend == str) {
87
      all = 1;
88
    } else {
89
      for(i = 0; i < 5; i++) {
90
        if(!strncmp(str, debug_classes[i], cend - str)) {
91
          dbcl = i;
92
          break;
93
        }
94
      }
95
      if(i > 4)
96
        fprintf(stderr, "Unknown class specified\n");
97
      all = 0;
98
    }
99
    disen = *cend == '+' ? 1 : 0;
100
    str = cend + 1;
101
    cend = strchr(str, ',');
102
    if(!cend)
103
      cend = str + strlen(str);
104
    for(i = 0; __orsim_dbchs[i]; i++)
105
      if(!strncmp(str, __orsim_dbchs[i] + 1, cend - str))
106
        break;
107
 
108
    if(!__orsim_dbchs[i])
109
      fprintf(stderr, "Unknown channel specified\n");
110
 
111
    if(all) {
112
      orsim_dbcl_set(__ORSIM_DBCL_TRACE, __orsim_dbchs[i], disen);
113
      orsim_dbcl_set(__ORSIM_DBCL_FIXME, __orsim_dbchs[i], disen);
114
      orsim_dbcl_set(__ORSIM_DBCL_WARN, __orsim_dbchs[i], disen);
115
      orsim_dbcl_set(__ORSIM_DBCL_ERR, __orsim_dbchs[i], disen);
116
    } else
117
      orsim_dbcl_set(dbcl, __orsim_dbchs[i], disen);
118
    if(*cend)
119
      str = cend + 1;
120
    else
121
      str = cend;
122
  }
123
}

powered by: WebSVN 2.1.0

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