/* $Id$
This file is part of gldbg
-Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions
Distributed under the GPL
*/
-#include <msp/io/file.h>
-#include <msp/io/print.h>
+#include <stdexcept>
#include "gldbg.h"
#include "glprint.h"
#include "tracer.h"
using namespace std;
-using namespace Msp;
Tracer::Tracer(GlDbg &dbg):
glprint(new GlPrint(0, 16384)),
out(0),
- delete_out(true),
+ close_out(true),
enabled(true)
{
dbg.get_command_interpreter().register_command("trace", this, &Tracer::cmd_trace)
Tracer::~Tracer()
{
delete glprint;
- if(delete_out)
- delete out;
+ if(close_out && out)
+ fclose(out);
}
-void Tracer::set_output(IO::Base *o, bool d)
+void Tracer::set_output(FILE *o, bool d)
{
- if(delete_out)
- delete out;
+ if(close_out && out)
+ fclose(out);
out = o;
- delete_out = d;
+ close_out = d;
}
void Tracer::decode(const char *data, unsigned len)
{
const char *buf = glprint->get_buffer();
if(buf[0])
- IO::print(*out, "%s\n", buf);
+ fprintf(out, "%s\n", buf);
}
}
{
if(args.empty() || args=="-")
{
- set_output(&IO::cout, false);
- IO::print("Tracing to stdout\n");
+ set_output(stdout, false);
+ printf("Tracing to stdout\n");
}
else if(args=="on")
{
if(!out)
- throw InvalidState("Output is not set");
+ throw runtime_error("Output is not set");
enabled = true;
- IO::print("Tracing enabled\n");
+ printf("Tracing enabled\n");
}
else if(args=="off")
{
enabled = false;
- IO::print("Tracing disabled\n");
+ printf("Tracing disabled\n");
}
else if(args=="end")
{
set_output(0, true);
- IO::print("Tracing terminated\n");
+ printf("Tracing terminated\n");
}
else
{
- set_output(new IO::File(args, IO::M_WRITE), true);
- IO::print("Tracing to %s\n", args);
+ FILE *f = fopen(args.c_str(), "w");
+ if(!f)
+ throw runtime_error("Could not open trace file");
+
+ set_output(f, true);
+ printf("Tracing to %s\n", args.c_str());
}
}