]> git.tdb.fi Git - gldbg.git/commitdiff
Remove dependencies to MSP libraries to make compiling on embedded platforms easier
authorMikko Rasa <tdb@tdb.fi>
Wed, 12 Jan 2011 14:06:41 +0000 (14:06 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 12 Jan 2011 14:06:41 +0000 (14:06 +0000)
17 files changed:
Makefile
flavors/gl/source/bufferstate.cpp
flavors/gl/source/glstate.cpp
flavors/gl/source/inspector.cpp
flavors/gl/source/profiler.cpp
flavors/gl/source/profiler.h
flavors/gl/source/texturestate.cpp
source/commandinterpreter.cpp
source/gldbg.cpp
source/gldbg.h
source/grabber.cpp
source/main.cpp [new file with mode: 0644]
source/process.cpp
source/strformat.cpp [new file with mode: 0644]
source/strformat.h [new file with mode: 0644]
source/tracer.cpp
source/tracer.h

index 4b171977e024674198ffa12efe6a22c34d90774f..2a7175a827ec18fb26b251ceb6c5372a0ff7b8c5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ CPPFLAGS := -I. -Isource -Iflavors/$(FLAVOR)/source
 CFLAGS := -ggdb -Wall -Wextra
 CXXFLAGS := $(CFLAGS)
 
-PACKAGES_gldbg := mspcore mspstrings mspio mspfs libpng12
+PACKAGES_gldbg := libpng12
 
 FLAVOR_ROOT := flavors/$(FLAVOR)
 VPATH := $(FLAVOR_ROOT)
@@ -26,9 +26,11 @@ SOURCES_glwrap := source/glwrap.c \
        source/packet.c \
        source/tmpalloc.c
 SOURCES_gldump := source/gldump.c
-SOURCES_gldbg := source/gldbg.cpp \
+SOURCES_gldbg := source/main.cpp \
+       source/gldbg.cpp \
        source/commandinterpreter.cpp \
        source/process.cpp \
+       source/strformat.cpp \
        source/tool.cpp
 SOURCES_tracer := source/tracer.cpp
 SOURCES_profiler := source/profiler.cpp
@@ -70,7 +72,7 @@ OBJECTS_all := $(call objs,$(SOURCES_all))
 DEPS_all := $(call deps,$(SOURCES_all) $(TEMPLATES))
 
 $(OBJECTS_gldbg): CXXFLAGS += $(shell pkg-config --cflags $(PACKAGES_gldbg))
-gldbg: LIBS += $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline
+gldbg: LIBS += $(shell pkg-config --libs $(PACKAGES_gldbg)) -lreadline -lrt
 gldump gldbg: LIBS += ./libgldbg.a
 glwrap.so: LDFLAGS += -s
 glwrap.so: LIBS += -ldl
index c8b9f1348e1858196be5115bb3b9e48704614680..5060e15e21fa2a359080be9dfbf64c305c789cf4 100644 (file)
@@ -1,18 +1,17 @@
 /* $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/strings/formatter.h>
 #include "arraysize.h"
 #include "arraystate.h"
 #include "bufferstate.h"
 #include "enums.h"
+#include "strformat.h"
 
 using namespace std;
-using namespace Msp;
 
 BufferContent::BufferContent():
        consistent(true),
@@ -113,7 +112,7 @@ string BufferContent::describe() const
 
                if(!result.empty())
                        result += '_';
-               result += format("%c%d%s", kind, i->size, type);
+               result += strformat("%c%d%s", kind, i->size, type);
        }
 
        return result;
@@ -170,9 +169,9 @@ string BufferState::describe() const
        if(content.stride)
        {
                const char *what = (content.arrays.front().kind==GL_ELEMENT_ARRAY_BUFFER ? "indices" : "vertices");
-               return format("%s, %d %s (%d bytes), %s",
-                       content.describe(), size/content.stride, what, size, describe_enum(usage, ""));
+               return content.describe()+strformat(", %d %s (%d bytes), %s",
+                       size/content.stride, what, size, describe_enum(usage, ""));
        }
        else
-               return format("%d bytes, %s", size, describe_enum(usage, ""));
+               return strformat("%d bytes, %s", size, describe_enum(usage, ""));
 }
index e33e49019bc6f660272a20b6cedd06fccef41354..f910b49cc041bd87ef2072f61837be3e41b2cfc6 100644 (file)
@@ -1,15 +1,14 @@
 /* $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/core/except.h>
+#include <stdexcept>
 #include "glstate.h"
 
 using namespace std;
-using namespace Msp;
 
 namespace {
 
@@ -147,7 +146,7 @@ const TextureState &GlState::get_texture(unsigned id) const
 {
        TextureMap::const_iterator i = textures.find(id);
        if(i==textures.end())
-               throw KeyError("Unknown texture");
+               throw runtime_error("Unknown texture");
        return i->second;
 }
 
@@ -155,7 +154,7 @@ const BufferState &GlState::get_buffer(unsigned id) const
 {
        BufferMap::const_iterator i = buffers.find(id);
        if(i==buffers.end())
-               throw KeyError("Unknown buffer");
+               throw runtime_error("Unknown buffer");
        return i->second;
 }
 
@@ -204,7 +203,7 @@ const ArrayState &GlState::get_array(GLenum array) const
        else if(array==GL_TEXTURE_COORD_ARRAY)
                return texcoord_arrays[client_active_tex];
        else
-               throw InvalidParameterValue("Invalid array");
+               throw logic_error("Invalid array");
 }
 
 const ArrayState &GlState::get_texture_coord_array(unsigned index) const
@@ -219,7 +218,7 @@ const ArrayState &GlState::get_attrib_array(unsigned index) const
                return i->second;
 
        // XXX Return a dummy?
-       throw KeyError("Unknown attribute array");
+       throw runtime_error("Unknown attribute array");
 }
 
 void GlState::set_current_texture(GLenum target, unsigned id)
index 5dcdf4147d3a6b670ffe8b57750a5ad256c993af..bbdcfedbf1f6054b778bcaf6c37bb79efa54510e 100644 (file)
@@ -1,17 +1,19 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
-#include <msp/io/print.h>
+#include <stdexcept>
+#include <cstdio>
+#include <cstdlib>
 #include "enums.h"
 #include "gldbg.h"
 #include "inspector.h"
+#include "strformat.h"
 
 using namespace std;
-using namespace Msp;
 
 Inspector::Inspector(GlDbg &dbg)
 {
@@ -49,35 +51,37 @@ void Inspector::cmd_state(const string &args)
        const GlState &glstate = state;
        if(args=="vertex")
        {
-               IO::print("Current vertex attributes:\n");
+               printf("Current vertex attributes:\n");
                const Vector4 &color = glstate.get_color();
-               IO::print("  Color:     [%05.3f, %05.3f, %05.3f, %05.3f]\n", color.r, color.g, color.b, color.a);
+               printf("  Color:     [%05.3f, %05.3f, %05.3f, %05.3f]\n", color.r, color.g, color.b, color.a);
                for(unsigned i=0; i<8; ++i)
                {
                        const Vector4 &texcoord = glstate.get_texcoord(i);
-                       IO::print("  TexCoord%d: [%05.3f, %05.3f, %05.3f, %05.3f]\n", i, texcoord.s, texcoord.t, texcoord.p, texcoord.q);
+                       printf("  TexCoord%d: [%05.3f, %05.3f, %05.3f, %05.3f]\n", i, texcoord.s, texcoord.t, texcoord.p, texcoord.q);
                }
                const Vector3 &normal = glstate.get_normal();
-               IO::print("  Normal:    [%05.3f, %05.3f, %05.3f]\n", normal.x, normal.y, normal.z);
+               printf("  Normal:    [%05.3f, %05.3f, %05.3f]\n", normal.x, normal.y, normal.z);
        }
        else if(args=="bind")
        {
-               IO::print("Current bindings:\n");
+               printf("Current bindings:\n");
                for(unsigned i=0; i<8; ++i)
                {
-                       IO::print("  Texture unit %d:\n", i);
+                       printf("  Texture unit %d:\n", i);
                        const TexUnitState &unit = glstate.get_texture_unit(i);
-                       IO::print("    GL_TEXTURE_2D: %s\n", unit.describe_binding(GL_TEXTURE_2D));
-                       IO::print("    GL_TEXTURE_3D: %s\n", unit.describe_binding(GL_TEXTURE_3D));
+                       string descr = unit.describe_binding(GL_TEXTURE_2D);
+                       printf("    GL_TEXTURE_2D: %s\n", descr.c_str());
+                       descr = unit.describe_binding(GL_TEXTURE_3D);
+                       printf("    GL_TEXTURE_3D: %s\n", descr.c_str());
                }
-               IO::print("  Buffers:\n");
+               printf("  Buffers:\n");
                const BufferState *buf = glstate.get_current_buffer(GL_ARRAY_BUFFER);
-               IO::print("    GL_ARRAY_BUFFER:         %d\n", (buf ? buf->id : 0));
+               printf("    GL_ARRAY_BUFFER:         %d\n", (buf ? buf->id : 0));
                buf = glstate.get_current_buffer(GL_ELEMENT_ARRAY_BUFFER);
-               IO::print("    GL_ELEMENT_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0));
+               printf("    GL_ELEMENT_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0));
        }
        else
-               throw InvalidParameterValue("Invalid or missing argument");
+               throw runtime_error("Invalid or missing argument");
 }
 
 void Inspector::cmd_texture(const string &args)
@@ -85,32 +89,37 @@ void Inspector::cmd_texture(const string &args)
        if(args.empty())
        {
                const map<unsigned, TextureState> &textures = state.get_textures();
-               IO::print("%d texture objects:\n", textures.size());
+               printf("%d texture objects:\n", textures.size());
                for(map<unsigned, TextureState>::const_iterator i = textures.begin(); i!=textures.end(); ++i)
                {
                        const TextureState &tex = i->second;
-                       IO::print("  %d: %s, %d images\n", i->first, tex.describe(), tex.images.size());
+                       string descr = tex.describe();
+                       printf("  %d: %s, %d images\n", i->first, descr.c_str(), tex.images.size());
                }
        }
        else
        {
-               unsigned id = lexical_cast<unsigned>(args);
+               char *end = 0;
+               unsigned id = strtoul(args.c_str(), &end, 0);
+               if(end && *end)
+                       throw runtime_error("Invalid texture id");
+
                const TextureState &tex = state.get_texture(id);
-               IO::print("Texture object %d\n", id);
-               IO::print("  Target:          %s\n", describe_enum(tex.target, "TextureTarget"));
-               IO::print("  Images:\n");
+               printf("Texture object %d\n", id);
+               printf("  Target:          %s\n", describe_enum(tex.target, "TextureTarget"));
+               printf("  Images:\n");
                for(unsigned i=0; i<tex.images.size(); ++i)
                {
-                       const TexImageState &img = tex.images[i];
-                       IO::print("    Level %2d:      %s\n", i, img.describe());
+                       string descr = tex.images[i].describe();
+                       printf("    Level %2d:      %s\n", i, descr.c_str());
                }
-               IO::print("  Min. filter:     %s\n", describe_enum(tex.min_filter, "TextureMinFilter"));
-               IO::print("  Mag. filter:     %s\n", describe_enum(tex.mag_filter, "TextureMagFilter"));
-               IO::print("  Wrap modes:      S=%s / T=%s / R=%s\n", describe_enum(tex.wrap_s, "TextureWrapMode"),
+               printf("  Min. filter:     %s\n", describe_enum(tex.min_filter, "TextureMinFilter"));
+               printf("  Mag. filter:     %s\n", describe_enum(tex.mag_filter, "TextureMagFilter"));
+               printf("  Wrap modes:      S=%s / T=%s / R=%s\n", describe_enum(tex.wrap_s, "TextureWrapMode"),
                        describe_enum(tex.wrap_t, "TextureWrapMode"), describe_enum(tex.wrap_r, "TextureWrapMode"));
-               IO::print("  Compare mode:    %s\n", describe_enum(tex.compare_mode, ""));
-               IO::print("  Compare func:    %s\n", describe_enum(tex.compare_func, "DepthFunction"));
-               IO::print("  Generate mipmap: %s\n", tex.generate_mipmap);
+               printf("  Compare mode:    %s\n", describe_enum(tex.compare_mode, ""));
+               printf("  Compare func:    %s\n", describe_enum(tex.compare_func, "DepthFunction"));
+               printf("  Generate mipmap: %s\n", (tex.generate_mipmap ? "true" : "false"));
        }
 }
 
@@ -119,26 +128,34 @@ void Inspector::cmd_buffer(const string &args)
        if(args.empty())
        {
                const GlState::BufferMap &buffers = state.get_buffers();
-               IO::print("%d buffers:\n", buffers.size());
+               printf("%d buffers:\n", buffers.size());
                for(GlState::BufferMap::const_iterator i=buffers.begin(); i!=buffers.end(); ++i)
-                       IO::print("  %d: %s\n", i->first, i->second.describe());
+               {
+                       string descr = i->second.describe();
+                       printf("  %d: %s\n", i->first, descr.c_str());
+               }
        }
        else
        {
-               unsigned id = lexical_cast<unsigned>(args);
+               char *end = 0;
+               unsigned id = strtoul(args.c_str(), &end, 0);
+               if(end && *end)
+                       throw runtime_error("Invalid buffer id");
+
                const BufferState &buf = state.get_buffer(id);
-               IO::print("Buffer %d:\n", id);
-               IO::print("  Size:  %d bytes\n", buf.size);
-               IO::print("  Usage: %s\n", describe_enum(buf.usage, ""));
+               printf("Buffer %d:\n", id);
+               printf("  Size:  %d bytes\n", buf.size);
+               printf("  Usage: %s\n", describe_enum(buf.usage, ""));
                if(buf.content.arrays.size()==1 && buf.content.arrays.front().kind==GL_ELEMENT_ARRAY_BUFFER)
                {
                        const BufferContent::Array &array = buf.content.arrays.front();
-                       IO::print("  Arrays:\n");
-                       IO::print("    0: Element indices, 1 %s\n", describe_enum(array.type, "DataType"));
+                       printf("  Arrays:\n");
+                       printf("    0: Element indices, 1 %s\n", describe_enum(array.type, "DataType"));
 
-                       IO::print("  Data:\n");
+                       printf("  Data:\n");
                        unsigned width = 1+buf.content.stride*2;
-                       string fmt = format(" %%%du", width);
+                       char fmt[6];
+                       snprintf(fmt, sizeof(fmt), " %%%du", width);
                        unsigned n_elems = buf.size/buf.content.stride;
                        string line;
                        const char *ptr = buf.data;
@@ -148,39 +165,39 @@ void Inspector::cmd_buffer(const string &args)
                                        line = "   ";
 
                                if(array.type==GL_UNSIGNED_BYTE)
-                                       line += format(fmt, *(reinterpret_cast<const unsigned char *>(ptr)+i));
+                                       line += strformat(fmt, *(reinterpret_cast<const unsigned char *>(ptr)+i));
                                else if(array.type==GL_UNSIGNED_SHORT)
-                                       line += format(fmt, *(reinterpret_cast<const unsigned short *>(ptr)+i));
+                                       line += strformat(fmt, *(reinterpret_cast<const unsigned short *>(ptr)+i));
                                else if(array.type==GL_UNSIGNED_INT)
-                                       line += format(fmt, *(reinterpret_cast<const unsigned *>(ptr)+i));
+                                       line += strformat(fmt, *(reinterpret_cast<const unsigned *>(ptr)+i));
 
                                if(line.size()+1+width>79)
                                {
-                                       IO::print("%s\n", line);
+                                       printf("%s\n", line.c_str());
                                        line.clear();
                                }
                        }
 
                        if(!line.empty())
-                               IO::print("%s\n", line);
+                               printf("%s\n", line.c_str());
                }
                else if(buf.content.stride)
                {
-                       IO::print("  Stride: %d bytes\n", buf.content.stride);
+                       printf("  Stride: %d bytes\n", buf.content.stride);
 
-                       IO::print("  Arrays:\n");
+                       printf("  Arrays:\n");
                        const vector<BufferContent::Array> &arrays = buf.content.arrays;
                        for(vector<BufferContent::Array>::const_iterator i=arrays.begin(); i!=arrays.end(); ++i)
                        {
                                if(i->kind)
-                                       IO::print("    %2d: %s, %d %s\n", i->offset,
+                                       printf("    %2d: %s, %d %s\n", i->offset,
                                                describe_enum(i->kind, ""), i->size, describe_enum(i->type, "DataType"));
                                else
-                                       IO::print("    %2d: Attrib %d, %d %s\n", i->offset,
+                                       printf("    %2d: Attrib %d, %d %s\n", i->offset,
                                                i->index, i->size, describe_enum(i->type, "DataType"));
                        }
 
-                       IO::print("  Data:\n");
+                       printf("  Data:\n");
                        string header;
                        for(vector<BufferContent::Array>::const_iterator i=arrays.begin(); i!=arrays.end(); ++i)
                        {
@@ -204,9 +221,9 @@ void Inspector::cmd_buffer(const string &args)
                                else if(!i->kind)
                                {
                                        if(i->size==1)
-                                               label = format("A %d", i->index);
+                                               label = strformat("A %d", i->index);
                                        else
-                                               label = format("Attrib %d", i->index);
+                                               label = strformat("Attrib %d", i->index);
                                }
 
                                unsigned width = i->size;
@@ -220,7 +237,7 @@ void Inspector::cmd_buffer(const string &args)
                                header += label;
                                header.append((width-label.size()+1)/2, ' ');
                        }
-                       IO::print("     %s\n", header);
+                       printf("     %s\n", header.c_str());
 
                        unsigned n_verts = buf.size/buf.content.stride;
                        for(unsigned i=0; i<n_verts; ++i)
@@ -237,13 +254,13 @@ void Inspector::cmd_buffer(const string &args)
                                        for(unsigned k=0; k<j->size; ++k)
                                        {
                                                if(j->type==GL_FLOAT)
-                                                       line += format(" %5.2f", *(reinterpret_cast<const float *>(base)+k));
+                                                       line += strformat(" %5.2f", *(reinterpret_cast<const float *>(base)+k));
                                                else if(j->type==GL_UNSIGNED_BYTE)
-                                                       line += format(" %3u", *(reinterpret_cast<const unsigned char *>(base)+k));
+                                                       line += strformat(" %3u", *(reinterpret_cast<const unsigned char *>(base)+k));
                                        }
                                }
 
-                               IO::print("%3d:%s\n", i, line);
+                               printf("%3d:%s\n", i, line.c_str());
                        }
                }
        }
index 37caa68636745f85c0f6290e006fef426618370c..4b95208c4b0425424a2ca89d5973d096a4cce049 100644 (file)
@@ -1,18 +1,17 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2010-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
-#include <msp/io/print.h>
-#include <msp/time/units.h>
-#include <msp/time/utils.h>
+#include <stdexcept>
+#include <cstdio>
+#include <ctime>
 #include "gldbg.h"
 #include "profiler.h"
 
 using namespace std;
-using namespace Msp;
 
 Profiler::Profiler(GlDbg &dbg):
        decoder(gldecoder_new(this, 0)),
@@ -44,12 +43,12 @@ void Profiler::cmd_profile(const string &args)
                draw_calls = 0;
                vertices = 0;
                triangles = 0;
-               start = Msp::Time::now();
+               start = get_time();
        }
        else if(args=="off")
                enabled = false;
        else
-               throw InvalidParameterValue("Invalid argument");
+               throw runtime_error("Invalid argument");
 }
 
 void Profiler::glDrawArrays(void *user_data, GLenum mode, int, int count)
@@ -93,18 +92,25 @@ void Profiler::glXSwapBuffers(void *user_data, Display *, GLXDrawable)
 {
        Profiler *self = reinterpret_cast<Profiler *>(user_data);
 
-       IO::print("%d draw calls, %d vertices, %d triangles\n", self->draw_calls, self->vertices, self->triangles);
+       printf("%d draw calls, %d vertices, %d triangles\n", self->draw_calls, self->vertices, self->triangles);
        self->draw_calls = 0;
        self->vertices = 0;
        self->triangles = 0;
 
        ++self->frames;
-       Msp::Time::TimeStamp t = Msp::Time::now();
-       Msp::Time::TimeDelta dt = t-self->start;
-       if(dt>Msp::Time::sec)
+       Time t = get_time();
+       float dt = (t-self->start)/1e6;
+       if(dt>1)
        {
-               Msp::IO::print("%d frames in %s seconds\n", self->frames, dt);
+               printf("%d frames in %.2f seconds\n", self->frames, dt);
                self->start = t;
                self->frames = 0;
        }
 }
+
+Profiler::Time Profiler::get_time()
+{
+       struct timespec ts;
+       clock_gettime(CLOCK_REALTIME, &ts);
+       return ts.tv_sec*1000000+ts.tv_nsec/1000;
+}
index 4d5c5a834641300fe247730ca94dd3f1c3f7a79d..547bd3514004f01b8ff540391ae62fbc24232954 100644 (file)
@@ -1,23 +1,24 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
 #ifndef PROFILER_H_
 #define PROFILER_H_
 
-#include <msp/time/timestamp.h>
 #include "gldecoder.h"
 #include "tool.h"
 
 class Profiler: public RegisteredTool<Profiler>
 {
 private:
+       typedef unsigned Time;
+
        GlDecoder *decoder;
        bool enabled;
-       Msp::Time::TimeStamp start;
+       Time start;
        unsigned frames;
        unsigned draw_calls;
        unsigned vertices;
@@ -34,6 +35,8 @@ private:
        static void glDrawElements(void *, GLenum, int, GLenum, const void *);
        static void glDrawRangeElements(void *, GLenum, unsigned, unsigned, int, GLenum, const void *);
        static void glXSwapBuffers(void *, Display *, GLXDrawable);
+
+       static Time get_time();
 };
 
 #endif
index 187707c3fb49da96c6056715ee8083a903b3d5e3..2bb4a172bad5f4ef965d741af8483b6992ee0ce6 100644 (file)
@@ -1,16 +1,15 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
-#include <msp/strings/formatter.h>
 #include "enums.h"
+#include "strformat.h"
 #include "texturestate.h"
 
 using namespace std;
-using namespace Msp;
 
 TexImageState::TexImageState():
        width(0),
@@ -29,14 +28,14 @@ void TexImageState::set_2d(GLenum ifmt, unsigned wd, unsigned ht)
 
 string TexImageState::describe() const
 {
-       string descr = format("%d", width);
+       string descr = strformat("%d", width);
        if(height)
        {
-               descr += format("x%d", height);
+               descr += strformat("x%d", height);
                if(depth)
-                       descr += format("x%d", height);
+                       descr += strformat("x%d", height);
        }
-       descr += format(", %s", describe_enum(internal_format, "PixelFormat"));
+       descr += strformat(", %s", describe_enum(internal_format, "PixelFormat"));
        return descr;
 }
 
@@ -103,7 +102,7 @@ string TextureState::describe() const
        if(images.empty())
                descr += ", undefined";
        else
-               descr += format(", %s", images.front().describe());
+               descr += ", "+images.front().describe();
        return descr;
 }
 
@@ -140,11 +139,11 @@ string TexUnitState::describe_binding(GLenum target) const
 {
        if(const TextureState *tex = get_current_texture(target))
        {
-               string descr = format("%d ", tex->id);
+               string descr = strformat("%d ", tex->id);
                if(tex->images.empty())
                        descr += "(undefined)";
                else
-                       descr += format("(%s)", tex->images.front().describe());
+                       descr += "("+tex->images.front().describe()+")";
                return descr;
        }
        else
index fe0c3f1bc5df51334de7b2c00233c659d05fb511..301535048bd6e8bcfe6084344b7aef248860ec65 100644 (file)
@@ -1,16 +1,14 @@
 /* $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 <stdexcept>
+#include <cstdlib>
 #include <signal.h>
 #include <readline/readline.h>
-#include <msp/core/except.h>
-#include <msp/io/print.h>
-#include <msp/strings/lexicalcast.h>
-#include <msp/strings/utils.h>
 #include "breakpoint.h"
 #include "commandinterpreter.h"
 #include "enums.h"
@@ -19,7 +17,6 @@ Distributed under the GPL
 #include "tracer.h"
 
 using namespace std;
-using namespace Msp;
 
 CommandInterpreter::CommandInterpreter(GlDbg &d):
        gldbg(d)
@@ -69,12 +66,12 @@ void CommandInterpreter::execute(const string &cmd)
        string name = cmd.substr(0, space);
        CommandMap::const_iterator i = commands.lower_bound(name);
        if(i==commands.end() || i->first.compare(0, name.size(), name))
-               throw KeyError("Unknown command", name);
+               throw runtime_error("Unknown command "+name);
        if(i->first!=name)
        {
                CommandMap::const_iterator j = i;
                if((++j)!=commands.end() && !j->first.compare(0, name.size(), name))
-                       throw KeyError("Ambiguous command", name);
+                       throw runtime_error("Ambiguous command "+name);
        }
 
        string args;
@@ -90,21 +87,21 @@ void CommandInterpreter::cmd_help(const string &args)
        {
                for(CommandMap::const_iterator i=commands.begin(); i!=commands.end(); ++i)
                        if(!dynamic_cast<const CommandAlias *>(i->second))
-                               IO::print("%-10s : %s\n", i->first, i->second->get_description());
+                               printf("%-10s : %s\n", i->first.c_str(), i->second->get_description().c_str());
        }
        else
        {
                CommandMap::const_iterator i = commands.find(args);
                if(i==commands.end())
-                       throw KeyError("Unknown command", args);
+                       throw runtime_error("Unknown command "+args);
 
                const Command *cmd = i->second;
                while(const CommandAlias *alias = dynamic_cast<const CommandAlias *>(cmd))
                        cmd = alias->get_target();
 
-               IO::print("%s : %s\n", i->first, cmd->get_description());
+               printf("%s : %s\n", i->first.c_str(), cmd->get_description().c_str());
                if(!cmd->get_help().empty())
-                       IO::print("\n%s", cmd->get_help());
+                       printf("\n%s", cmd->get_help().c_str());
        }
 }
 
@@ -117,7 +114,7 @@ void CommandInterpreter::cmd_break(const string &args)
 {
        unsigned short func = get_function(args.c_str());
        if(!func)
-               throw InvalidParameterValue("Unknown function");
+               throw runtime_error("Unknown function");
 
        gldbg.set_breakpoint(func, BREAK_CALL, 0);
 }
@@ -126,7 +123,7 @@ void CommandInterpreter::cmd_unbreak(const string &args)
 {
        unsigned short func = get_function(args.c_str());
        if(!func)
-               throw InvalidParameterValue("Unknown function");
+               throw runtime_error("Unknown function");
 
        gldbg.clear_breakpoint(func, BREAK_CALL, 0);
 }
@@ -145,7 +142,7 @@ void CommandInterpreter::cmd_finish(const string &)
 
 void CommandInterpreter::cmd_continue(const string &)
 {
-       IO::print("Continuing.\n");
+       printf("Continuing.\n");
        gldbg.get_process().resume();
 }
 
@@ -162,10 +159,13 @@ void CommandInterpreter::cmd_signal(const string &args)
                sig = SIGSEGV;
        else if(args=="TERM" || args=="SIGTERM")
                sig = SIGTERM;
-       else if(isnumrc(args))
-               sig = lexical_cast<unsigned>(args);
        else
-               throw InvalidParameterValue("Invalid signal specification");
+       {
+               char *end;
+               sig = strtoul(args.c_str(), &end, 0);
+               if(end && *end)
+                       throw runtime_error("Invalid signal specification");
+       }
        gldbg.get_process().resume(sig);
 }
 
@@ -178,7 +178,7 @@ void CommandInterpreter::cmd_exit(const string &)
 {
        if(gldbg.get_process().get_state()!=Process::INACTIVE)
        {
-               IO::print("Program is still running.  Kill it?\n");
+               printf("Program is still running.  Kill it?\n");
                char *answer = readline("[y/n] ");
                if(answer[0]=='y')
                {
@@ -186,7 +186,7 @@ void CommandInterpreter::cmd_exit(const string &)
                        gldbg.quit(true);
                }
                else
-                       IO::print("Not confirmed.\n");
+                       printf("Not confirmed.\n");
        }
        else
                gldbg.quit(false);
index 001742d39599b85942702f797d8e8ed383d7a16d..a7abf31e08ed848f205dbcc468d4b81706fd19c3 100644 (file)
@@ -1,31 +1,30 @@
 /* $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 <algorithm>
+#include <stdexcept>
 #include <cstdlib>
+#include <climits>
 #include <fcntl.h>
 #include <signal.h>
+#include <unistd.h>
 #include <sys/poll.h>
 #include <sys/socket.h>
 #include <readline/readline.h>
-#include <msp/core/except.h>
-#include <msp/fs/dir.h>
-#include <msp/io/print.h>
-#include <msp/strings/lexicalcast.h>
 #include "functions.h"
 #include "gldbg.h"
 #include "gldecoder.h"
 #include "packet.h"
+#include "strformat.h"
 #include "tool.h"
 
 using namespace std;
-using namespace Msp;
 
-Application::RegApp<GlDbg> GlDbg::reg;
+GlDbg *GlDbg::instance = 0;
 
 GlDbg::GlDbg(int argc, char **argv):
        cmd_interp(*this),
@@ -36,8 +35,13 @@ GlDbg::GlDbg(int argc, char **argv):
        stop_reason(0),
        current_break(0)
 {
-       FS::Path libdir = FS::get_sys_lib_dir(argv[0], "gldbg");
-       process.setenv("LD_PRELOAD", (libdir/"glwrap.so").str().c_str());
+       instance = this;
+
+       char buf[PATH_MAX];
+       unsigned len = readlink("/proc/self/exe", buf, sizeof(buf));
+       string exe(buf, len);
+       string::size_type slash = exe.rfind('/');
+       process.setenv("LD_PRELOAD", (exe.substr(0, slash+1)+"glwrap.so"));
 
        const list<Tool::Factory *> &factories = Tool::get_factories();
        for(list<Tool::Factory *>::const_iterator i=factories.begin(); i!=factories.end(); ++i)
@@ -52,15 +56,15 @@ GlDbg::~GlDbg()
 
 int GlDbg::main()
 {
-       catch_signal(SIGINT);
-       catch_signal(SIGCHLD);
-       set_loop_mode(TICK_BUSY);
+       signal(SIGINT, &sighandler);
+       signal(SIGCHLD, &sighandler);
 
-       IO::print("GLdbg 0.0\n");
-       IO::print("Copyright © 2009-2010 Mikkosoft Productions\n");
-       IO::print("Type \"help\" for a list of commands\n");
+       printf("GLdbg 0.0\n");
+       printf("Copyright © 2009-2010 Mikkosoft Productions\n");
+       printf("Type \"help\" for a list of commands\n");
 
-       Application::main();
+       while(1)
+               tick();
 
        return 0;
 }
@@ -68,7 +72,7 @@ int GlDbg::main()
 void GlDbg::launch()
 {
        if(process.get_state()!=Process::INACTIVE)
-               throw InvalidState("Program is already running");
+               throw runtime_error("Program is already running");
 
        int fds[2];
        socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
@@ -77,8 +81,8 @@ void GlDbg::launch()
        int flags = fcntl(sock_fd, F_GETFD);
        fcntl(sock_fd, F_SETFD, flags|FD_CLOEXEC);
 
-       process.setenv("GLWRAP_FD", lexical_cast(fds[1]));
-       process.setenv("GLWRAP_CTRL_FD", lexical_cast(fds[1]));
+       process.setenv("GLWRAP_FD", strformat("%d", fds[1]));
+       process.setenv("GLWRAP_CTRL_FD", strformat("%d", fds[1]));
        process.launch();
        close(fds[1]);
 
@@ -163,7 +167,7 @@ void GlDbg::resume_from_break(Tool *tool)
 void GlDbg::quit(bool force)
 {
        if(!force && process.get_state()!=Process::INACTIVE)
-               throw InvalidState("Program is still running");
+               throw runtime_error("Program is still running");
        exit(0);
 }
 
@@ -185,13 +189,13 @@ void GlDbg::tick()
                if(stop_reason)
                {
                        if(stop_reason==0x100)
-                               IO::print("Target process exited normally\n");
+                               printf("Target process exited normally\n");
                        else if((stop_reason>>8)==1)
-                               IO::print("Target process exited with status %d\n", stop_reason&0xFF);
+                               printf("Target process exited with status %d\n", stop_reason&0xFF);
                        else if((stop_reason>>8)==2)
-                               IO::print("Target process terminated with signal %d\n", stop_reason&0xFF);
+                               printf("Target process terminated with signal %d\n", stop_reason&0xFF);
                        else if((stop_reason>>8)==3)
-                               IO::print("Target process stopped by signal %d\n", stop_reason&0xFF);
+                               printf("Target process stopped by signal %d\n", stop_reason&0xFF);
 
                        stop_reason = 0;
                }
@@ -203,9 +207,9 @@ void GlDbg::tick()
                        {
                                cmd_interp.execute(line);
                        }
-                       catch(const Exception &e)
+                       catch(const exception &e)
                        {
-                               IO::print("%s\n", e.what());
+                               printf("%s\n", e.what());
                        }
                        free(line);
                }
@@ -250,7 +254,7 @@ void GlDbg::read_stream()
                                        }
 
                                        if(announce)
-                                               IO::print("Breakpoint: %s\n", get_function_name(func));
+                                               printf("Breakpoint: %s\n", get_function_name(func));
                                }
 
                                for(ToolList::iterator i=tools.begin(); i!=tools.end(); ++i)
@@ -291,7 +295,7 @@ GlDbg::Breakpoint *GlDbg::get_breakpoint(unsigned short func, unsigned char flag
 void GlDbg::sighandler(int sig)
 {
        if(sig==SIGCHLD)
-               got_sigchld = true;
+               instance->got_sigchld = true;
 }
 
 
index 99f0863c2c3f72cf91852ea0e356781aed23994c..dd6d60c6d8f1a97c13078d6da3fe51e82498228a 100644 (file)
@@ -1,24 +1,23 @@
 /* $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
 */
 
 #ifndef GLDBG_H_
 #define GLDBG_H_
 
+#include <list>
 #include <string>
 #include <vector>
-#include <msp/core/application.h>
-#include <msp/fs/path.h>
 #include "commandinterpreter.h"
 #include "packet.h"
 #include "process.h"
 
 class Tool;
 
-class GlDbg: public Msp::Application
+class GlDbg
 {
 private:
        typedef std::list<Tool *> ToolList;
@@ -51,7 +50,7 @@ private:
        const Breakpoint *current_break;
        ToolList break_holders;
 
-       static RegApp<GlDbg> reg;
+       static GlDbg *instance;
 
 public:
        GlDbg(int, char **);
@@ -72,7 +71,8 @@ private:
        void check_child();
        void read_stream();
        Breakpoint *get_breakpoint(unsigned short, unsigned char);
-       virtual void sighandler(int);
+
+       static void sighandler(int);
 };
 
 #endif
index e56622f4d9949f21936358550a278d7a023e7cbd..5b4023142a43f8b35ece195a59b1927e5fb8d1d0 100644 (file)
@@ -6,16 +6,16 @@ Distributed under the GPL
 */
 
 #include <algorithm>
+#include <stdexcept>
 #include <png.h>
-#include <msp/io/print.h>
 #include "arraysize.h"
 #include "breakpoint.h"
 #include "functions.h"
 #include "gldbg.h"
 #include "grabber.h"
+#include "strformat.h"
 
 using namespace std;
-using namespace Msp;
 
 Grabber::Grabber(GlDbg &g):
        gldbg(g),
@@ -124,7 +124,7 @@ void Grabber::cmd_autograb(const string &args)
                }
        }
        else
-               throw InvalidParameterValue("Invalid autograb mode");
+               throw runtime_error("Invalid autograb mode");
 }
 
 void Grabber::grab()
@@ -220,13 +220,13 @@ void Grabber::glReadPixels(void *user_data, int, int, int width, int height, GLe
 {
        Grabber *self = reinterpret_cast<Grabber *>(user_data);
        
-       string fn = Msp::format("grab-%04d-%04d.png", self->frame_num, self->grab_num);
+       string fn = strformat("grab-%04d-%04d.png", self->frame_num, self->grab_num);
        if(format==GL_RGBA && type==GL_UNSIGNED_BYTE)
        {
                if(self->write_png(fn, width, height, data)<0)
-                       IO::print("Failed to write png file %s\n", fn);
+                       printf("Failed to write png file %s\n", fn.c_str());
                else
-                       IO::print("Grabbed %dx%d png image to %s\n", width, height, fn);
+                       printf("Grabbed %dx%d png image to %s\n", width, height, fn.c_str());
        }
 
        ++self->grab_num;
diff --git a/source/main.cpp b/source/main.cpp
new file mode 100644 (file)
index 0000000..53722be
--- /dev/null
@@ -0,0 +1,14 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2011  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include "gldbg.h"
+
+int main(int argc, char **argv)
+{
+       GlDbg gldbg(argc, argv);
+       return gldbg.main();
+}
index 0fc9e98f6410e0b6657a50106a1d2459385d594e..e198df2d10e63d6914a61b23cdb2b5f36b7b861e 100644 (file)
@@ -1,20 +1,20 @@
 /* $Id$
 
 This file is part of gldbg
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009, 2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the GPL
 */
 
+#include <stdexcept>
 #include <cstdlib>
 #include <cerrno>
 #include <cstring>
 #include <sys/ptrace.h>
 #include <sys/wait.h>
-#include <msp/core/except.h>
 #include "process.h"
+#include "strformat.h"
 
 using namespace std;
-using namespace Msp;
 
 Process::Process(const vector<string> &a):
        args(a),
@@ -30,7 +30,7 @@ void Process::setenv(const string &key, const string &value)
 void Process::launch()
 {
        if(state!=INACTIVE)
-               throw InvalidState("Program is already running");
+               throw logic_error("Program is already running");
 
        pid = fork();
        if(pid==0)
@@ -48,7 +48,7 @@ void Process::launch()
        else if(pid>0)
                state = STARTING;
        else
-               throw SystemError("Could not launch process", errno);
+               throw runtime_error(strformat("Could not launch process: %s", strerror(errno)));
 }
 
 int Process::check()
@@ -90,7 +90,7 @@ int Process::check()
 void Process::resume(int sig)
 {
        if(state!=STOPPED)
-               throw InvalidState("Program is not stopped");
+               throw logic_error("Program is not stopped");
        ptrace(PTRACE_CONT, 0, (void *)sig);
        state = RUNNING;
 }
@@ -98,7 +98,7 @@ void Process::resume(int sig)
 void Process::kill()
 {
        if(state==INACTIVE)
-               throw InvalidState("Program is not running");
+               throw logic_error("Program is not running");
        ptrace(PTRACE_KILL, 0, 0);
        // Make the debugger wait() for us
        state = RUNNING;
@@ -108,6 +108,6 @@ long Process::ptrace(int req, void *addr, void *data)
 {
        int ret = ::ptrace((__ptrace_request)req, pid, addr, data);
        if(ret==-1 && ((req!=PTRACE_PEEKTEXT && req!=PTRACE_PEEKDATA && req!=PTRACE_PEEKUSER) || errno))
-               throw SystemError("ptrace error", errno);
+               throw runtime_error(strformat("ptrace error: %s", strerror(errno)));
        return ret;
 }
diff --git a/source/strformat.cpp b/source/strformat.cpp
new file mode 100644 (file)
index 0000000..188b121
--- /dev/null
@@ -0,0 +1,22 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2011  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include <stdio.h>
+#include <stdarg.h>
+#include "strformat.h"
+
+using namespace std;
+
+string strformat(const char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       char buf[2048];
+       vsnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+       return buf;
+}
diff --git a/source/strformat.h b/source/strformat.h
new file mode 100644 (file)
index 0000000..94ce9a6
--- /dev/null
@@ -0,0 +1,15 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2011  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#ifndef STRFORMAT_H_
+#define STRFORMAT_H_
+
+#include <string>
+
+std::string strformat(const char *, ...);
+
+#endif
index 9f703f1e673cd7a78d90dbebc084b3bbb9c4b435..5a02354739287bc42b4fae02f2f78298dad092d9 100644 (file)
@@ -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 <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)
@@ -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());
        }
 }
index 651bfc1ecf1df7006d7f88170cd7a24bb129c993..38ebc01bef69e842dacd39c0c90db4f115f72731 100644 (file)
@@ -1,14 +1,14 @@
 /* $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
 */
 
 #ifndef TRACER_H_
 #define TRACER_H_
 
-#include <msp/io/base.h>
+#include <cstdio>
 #include "tool.h"
 
 struct GlPrint;
@@ -17,8 +17,8 @@ class Tracer: public RegisteredTool<Tracer>
 {
 private:
        GlPrint *glprint;
-       Msp::IO::Base *out;
-       bool delete_out;
+       FILE *out;
+       bool close_out;
        bool enabled;
 
 public:
@@ -27,7 +27,7 @@ public:
 
        virtual void decode(const char *, unsigned);
 private:
-       void set_output(Msp::IO::Base *, bool);
+       void set_output(FILE *, bool);
        void cmd_trace(const std::string &);
 };