efa76b0443ad276581f38d3c4dc6aed117a27281
2 * Copyright (c) 2001-2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
39 #include "base/misc.hh"
40 #include "base/trace.hh"
41 #include "base/str.hh"
42 #include "base/varargs.hh"
47 const string
DefaultName("global");
48 FlagVec
flags(NumFlags
, false);
52 // This variable holds the output stream for debug information. Other
53 // than setting up/redirecting this stream, do *NOT* reference this
54 // directly; use DebugOut() (see below) to access this stream for
57 ostream
*dprintf_stream
= &cerr
;
74 fatal("Trace::Log::init called twice!");
79 buffer
= new Record
*[size
];
81 for (int i
= 0; i
< size
; ++i
) {
85 nextRecPtr
= &buffer
[0];
86 wrapRecPtr
= &buffer
[size
];
92 for (int i
= 0; i
< size
; ++i
) {
101 Log::append(Record
*rec
)
103 // dump record to output stream if there's one open
104 if (dprintf_stream
!= NULL
) {
105 rec
->dump(*dprintf_stream
);
110 // no buffering: justget rid of it now
111 if (buffer
== NULL
) {
116 Record
*oldRec
= *nextRecPtr
;
118 if (oldRec
!= NULL
) {
119 // log has wrapped: overwrite
125 if (++nextRecPtr
== wrapRecPtr
) {
126 nextRecPtr
= &buffer
[0];
132 Log::dump(ostream
&os
)
134 if (buffer
== NULL
) {
138 Record
**bufPtr
= nextRecPtr
;
140 if (*bufPtr
== NULL
) {
141 // next record slot is empty: log must not be full yet.
142 // start dumping from beginning of buffer
147 Record
*rec
= *bufPtr
;
151 if (++bufPtr
== wrapRecPtr
) {
154 } while (bufPtr
!= nextRecPtr
);
157 PrintfRecord::~PrintfRecord()
161 PrintfRecord::dump(ostream
&os
)
167 args
.push_front(name
);
170 if (cycle
!= (Tick
)-1) {
172 args
.push_front(cycle
);
177 ccprintf(os
, fmt
.c_str(), args
);
181 DataRecord::DataRecord(Tick _cycle
, const string
&_name
,
182 const void *_data
, int _len
)
183 : Record(_cycle
), name(_name
), len(_len
)
185 data
= new uint8_t[len
];
186 memcpy(data
, _data
, len
);
189 DataRecord::~DataRecord()
195 DataRecord::dump(ostream
&os
)
199 for (i
= 0; i
< len
; i
+= 16) {
200 ccprintf(os
, "%d: %s: %08x ", cycle
, name
, i
);
204 for (j
= 0; j
< c
; j
++) {
205 ccprintf(os
, "%02x ", data
[i
+ j
] & 0xff);
206 if ((j
& 0xf) == 7 && j
> 0)
214 for (j
= 0; j
< c
; j
++) {
215 int ch
= data
[i
+ j
] & 0x7f;
217 "%c", (char)(isprint(ch
) ? ch
: ' '));