1 /*
2 Copyright (C) 1999 T. Scott Dattalo
3
4 This file is part of gpsim.
5
6 gpsim 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, or (at your option)
9 any later version.
10
11 gpsim 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 gpsim; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25
26 #include "command.h"
27 #include "cmd_log.h"
28 #include "../src/trace_orb.h"
29 #include "../src/pic-processor.h"
30 #include "../src/trace.h"
31
32 #include "cmd_break.h"
33
34 cmd_log c_log;
35
36 #define LOG_ON 1
37 #define LOG_OFF 2
38 #define WRITE 3
39 #define READ 4
40 #define LOG_LXT 5
41
42
43 static cmd_options cmd_trace_options[] =
44 {
45 {"on", LOG_ON, OPT_TT_BITFLAG},
46 {"off", LOG_OFF, OPT_TT_BITFLAG},
47 {"w", WRITE, OPT_TT_BITFLAG},
48 {"r", READ, OPT_TT_BITFLAG},
49 {"lxt", LOG_LXT, OPT_TT_BITFLAG},
50 { 0,0,0}
51 };
52
cmd_log()53 cmd_log::cmd_log()
54 : command("log",0)
55 {
56 brief_doc = string("Log/record events to a file");
57
58 long_doc = string ("\n\
59 The log command will record simulation history in a file. It's similar to the\n\
60 break command\n\
61 log [[on|lxt [file_name]]|[off]]\n\
62 Enables or disables logging. Specify no options to see log status.\n\
63 The lxt option encodes the log file so that an external viewer\n\
64 like gtkwave can be used to view the file.\n\
65 log w|r reg [, expr]\n\
66 Specify a register to log. See the break command for expression syntax\n\
67 \n Examples:\n\
68 \tlog - Display log status\n\
69 \tlog on - Begin logging in file gpsim.log\n\
70 \tlog on file.log - Begin logging in file file.log\n\
71 \tlog lxt - Begin lxt logging in file gpsim.lxt\n\
72 \tlog lxt file.lxt - Begin lxt logging in file file.lxt\n\
73 \tlog off - Stop logging\n\
74 \tlog w temp_hi - Log all writes to reg temp_hi\n\
75 ");
76
77 op = cmd_trace_options;
78 }
79
log()80 void cmd_log::log()
81 {
82 GetTraceLog().status();
83 }
84
85
86
87
log(cmd_options * opt,ExprList_t * eList)88 void cmd_log::log(cmd_options *opt, ExprList_t *eList)
89 {
90
91 if (!opt) {
92 log();
93 return;
94 }
95
96 switch(opt->value) {
97 case LOG_ON:
98 case LOG_LXT:
99 {
100 int fmt = opt->value==LOG_ON ? TRACE_FILE_FORMAT_ASCII : TRACE_FILE_FORMAT_LXT;
101 //const char *fn=0;
102 if (eList) {
103 ExprList_itor ei = eList->begin();
104 Expression *pFirst = *ei;
105 LiteralString *pString=0;
106 string m;
107 if (pFirst) {
108 pString = dynamic_cast<LiteralString*>(pFirst);
109 if (pString) {
110 String *pS = (String *)pString->evaluate();
111 GetTraceLog().enable_logging(pS->getVal(),fmt);
112 delete pFirst;
113 delete pS;
114 }
115 }
116 } else
117 GetTraceLog().enable_logging(0,fmt);
118 }
119 break;
120 case LOG_OFF:
121 GetTraceLog().disable_logging();
122 break;
123 default:
124 c_break.set_break(opt,eList,true);
125 }
126
127 }
128
129
log(cmd_options * opt)130 void cmd_log::log(cmd_options *opt)
131 {
132
133 switch(opt->value) {
134 case LOG_ON:
135 GetTraceLog().enable_logging(0);
136 break;
137 case LOG_OFF:
138 GetTraceLog().disable_logging();
139 break;
140 case LOG_LXT:
141 GetTraceLog().enable_logging(0,TRACE_FILE_FORMAT_LXT);
142 break;
143 default:
144 cout << " Invalid log option\n";
145 }
146
147 }
148