00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <fstream>
00027
00028 #include <stdlib.h>
00029
00030 #include "dumpargs.h"
00031 #include "../helper.h"
00032 #include "../avrerror.h"
00033
00034 using namespace std;
00035
00036 void SetDumpTraceArgs(const vector<string> &traceopts, AvrDevice *dev) {
00037 DumpManager *dman = DumpManager::Instance();
00038 for(size_t i = 0; i < traceopts.size(); i++) {
00039 vector<string> ls = split(traceopts[i], ":");
00040 if(ls.size() < 1)
00041 avr_error("Invalid tracing option '%s'.", traceopts[i].c_str());
00042 Dumper *d;
00043 TraceSet ts;
00044 cerr << "Enabling tracer: '";
00045 if(ls[0] == "warnread") {
00046 cerr << "warnread'." << endl;
00047 if(ls.size() > 1)
00048 avr_error("Invalid number of options for 'warnread'.");
00049 ts = dman->all();
00050 d = new WarnUnknown(dev);
00051 } else if (ls[0] == "vcd") {
00052 cerr << "vcd'." << endl;
00053 if(ls.size() < 3 || ls.size() > 4)
00054 avr_error("Invalid number of options for 'vcd'.");
00055 cerr << "Reading values to trace from '" << ls[1] << "'." << endl;
00056
00057 ifstream is(ls[1].c_str());
00058 if(is.is_open() == 0)
00059 avr_error("Can't open '%s'", ls[1].c_str());
00060
00061 cerr << "Output VCD file is '" << ls[2] << "'." << endl;
00062 ts = dman->load(is);
00063
00064 bool rs = false, ws = false;
00065 if(ls.size() == 4) {
00066 if(ls[3] == "rw") {
00067 rs = ws = true;
00068 } else if(ls[3] == "r") {
00069 rs = true;
00070 } else if(ls[3] == "w") {
00071 ws = true;
00072 } else
00073 avr_error("Invalid read/write strobe specifier '%s'", ls[3].c_str());
00074 }
00075 d = new DumpVCD(ls[2], "ns", rs, ws);
00076 } else
00077 avr_error("Unknown tracer '%s'", ls[0].c_str());
00078 dman->addDumper(d, ts);
00079 }
00080 }
00081
00082 void ShowRegisteredTraceValues(const string &outname) {
00083 cerr << "Dumping traceable values to ";
00084 if(outname != "-")
00085 cerr << "'" << outname << "'." << endl;
00086 else
00087 cerr << "stdout." << endl;
00088
00089 ostream *outf;
00090 if(outname != "-")
00091 outf = new ofstream(outname.c_str());
00092 else
00093 outf = &cout;
00094
00095 DumpManager::Instance()->save(*outf);
00096
00097 if(outf != &cout)
00098 delete outf;
00099 }
00100
00101