X-Git-Url: http://git.tdb.fi/?p=gldbg.git;a=blobdiff_plain;f=source%2Ftracer.cpp;h=5a02354739287bc42b4fae02f2f78298dad092d9;hp=9f703f1e673cd7a78d90dbebc084b3bbb9c4b435;hb=81f1ddee977603293d0c5710f2db69130dac6a96;hpb=a51c2557622ea93944e24f58845609526eb46ec1 diff --git a/source/tracer.cpp b/source/tracer.cpp index 9f703f1..5a02354 100644 --- a/source/tracer.cpp +++ b/source/tracer.cpp @@ -1,23 +1,21 @@ /* $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 -#include +#include #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) @@ -35,16 +33,16 @@ Tracer::Tracer(GlDbg &dbg): 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) @@ -57,7 +55,7 @@ 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); } } @@ -65,29 +63,33 @@ void Tracer::cmd_trace(const string &args) { 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()); } }