diff options
author | Thomas White <taw@physics.org> | 2018-03-18 22:37:36 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-03-18 23:09:25 +0100 |
commit | 546bfb401b943b0b5e91f3674c450c4a78aeb6aa (patch) | |
tree | cac2f216fefcc7995f114d8ab19d68b9553b5252 /src | |
parent | ffa123e5ba835bb68b063b017df144fb7f5d05ce (diff) |
debugger: Tidy up and simplify
Diffstat (limited to 'src')
-rw-r--r-- | src/debugger.c | 118 |
1 files changed, 13 insertions, 105 deletions
diff --git a/src/debugger.c b/src/debugger.c index 8ac275d..07ea546 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -38,26 +38,12 @@ #define MAX_DEBUG_RUNS (1024) -struct run_debug -{ - enum para_type para_type; - - int np; - void *scblock; /* Don't you dare try to dereference this. */ - void *rscblock; /* Or this. */ -}; - - struct debugwindow { GtkWidget *window; GtkWidget *drawingarea; struct frame *fr; guint timeout; - - int n_changed; - int changesig; - struct run_debug *runs; }; @@ -104,8 +90,7 @@ static const char *str_type(enum para_type t) } static void debug_text_para(Paragraph *para, cairo_t *cr, double *ypos, - PangoFontDescription *fontdesc, - struct run_debug *rd, int *dpos, int *changesig) + PangoFontDescription *fontdesc) { int i, nrun; char tmp[256]; @@ -129,77 +114,15 @@ static void debug_text_para(Paragraph *para, cairo_t *cr, double *ypos, scblock); } plot_text(cr, ypos, fontdesc, tmp); - (*dpos)++; } } - snprintf(tmp, 255, "Newline at end: %p\n", get_newline_at_end(para)); - plot_text(cr, ypos, fontdesc, tmp); -} - - -static void debug_other_para(Paragraph *para, cairo_t *cr, double *ypos, - PangoFontDescription *fontdesc) -{ - char tmp[256]; - SCBlock *scblock = para_scblock(para); - SCBlock *rscblock = para_rscblock(para); - - if ( scblock == rscblock ) { - snprintf(tmp, 255, "SCBlock %p\n", scblock); - } else { - snprintf(tmp, 255, "SCBlock %p / %p\n", scblock, rscblock); - } - + snprintf(tmp, 255, "Newline at end: %p", get_newline_at_end(para)); plot_text(cr, ypos, fontdesc, tmp); } -static void record_runs(struct debugwindow *dbgw) -{ - int i; - int n = 0; - - for ( i=0; i<dbgw->fr->n_paras; i++ ) { - - int j, nrun; - Paragraph *para = dbgw->fr->paras[i]; - - dbgw->runs[n].para_type = para_type(para); - - if ( para_type(para) != PARA_TYPE_TEXT ) { - n++; - continue; - } - - nrun = para_debug_num_runs(para); - - for ( j=0; j<nrun; j++ ) { - - SCBlock *scblock; - SCBlock *rscblock; - - if ( para_debug_run_info(para, j, &scblock, &rscblock) ) continue; - - dbgw->runs[n].np = i; - dbgw->runs[n].scblock = scblock; - dbgw->runs[n].rscblock = rscblock; - n++; - - if ( n == MAX_DEBUG_RUNS ) { - printf("Too many runs to debug\n"); - return; - } - - } - - } - - dbgw->changesig = 0; -} - - static gboolean dbg_draw_sig(GtkWidget *da, cairo_t *cr, struct debugwindow *dbgw) { int width, height; @@ -207,9 +130,6 @@ static gboolean dbg_draw_sig(GtkWidget *da, cairo_t *cr, struct debugwindow *dbg PangoFontDescription *fontdesc; int i; double ypos = 10.0; - int dpos = 0; - int changesig = 0; - int npr = 10; /* Not zero */ /* Background */ width = gtk_widget_get_allocated_width(GTK_WIDGET(da)); @@ -231,33 +151,26 @@ static gboolean dbg_draw_sig(GtkWidget *da, cairo_t *cr, struct debugwindow *dbg for ( i=0; i<dbgw->fr->n_paras; i++ ) { enum para_type t = para_type(dbgw->fr->paras[i]); - - /* Jump the "old values" pointer forward to the next paragraph start */ - while ( dbgw->runs[dpos].np == npr ) dpos++; - npr = dbgw->runs[dpos].np; + SCBlock *scblock = para_scblock(dbgw->fr->paras[i]); + SCBlock *rscblock = para_rscblock(dbgw->fr->paras[i]); plot_hr(cr, &ypos, width); snprintf(tmp, 255, "Paragraph %i: type %s", i, str_type(t)); plot_text(cr, &ypos, fontdesc, tmp); - if ( t == PARA_TYPE_TEXT ) { - debug_text_para(dbgw->fr->paras[i], cr, &ypos, fontdesc, - dbgw->runs, &dpos, &changesig); + if ( scblock == rscblock ) { + snprintf(tmp, 255, "SCBlock %p", scblock); } else { - debug_other_para(dbgw->fr->paras[i], cr, &ypos, fontdesc); + snprintf(tmp, 255, "SCBlock %p / %p", scblock, rscblock); } + plot_text(cr, &ypos, fontdesc, tmp); - } - - if ( changesig == dbgw->changesig ) { - dbgw->n_changed++; - if ( dbgw->n_changed >= 5 ) { - record_runs(dbgw); - dbgw->n_changed = 0; + if ( t == PARA_TYPE_TEXT ) { + debug_text_para(dbgw->fr->paras[i], cr, &ypos, fontdesc); } - } else { - dbgw->changesig = changesig; - dbgw->n_changed = 0; + + plot_text(cr, &ypos, fontdesc, ""); + } pango_font_description_free(fontdesc); @@ -296,11 +209,6 @@ void open_debugger(struct frame *fr) if ( dbgw == NULL ) return; dbgw->fr = fr; - dbgw->runs = malloc(MAX_DEBUG_RUNS * sizeof(struct run_debug)); - if ( dbgw->runs == NULL ) return; - - dbgw->n_changed = 0; - record_runs(dbgw); dbgw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_role(GTK_WINDOW(dbgw->window), "debugger"); |