summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-23 14:46:04 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-23 14:46:04 -0300
commitf5fa04cbf3ac9011f4f144cd68543f8d9536e3fd (patch)
treeac9160ef7ef5963e296144fb75845db56ba62e7c
parent061dd9094a903be73e3aa7a65aafb8bcb70010b7 (diff)
downloadeeshow-f5fa04cbf3ac9011f4f144cd68543f8d9536e3fd.tar.gz
eeshow-f5fa04cbf3ac9011f4f144cd68543f8d9536e3fd.tar.bz2
eeshow-f5fa04cbf3ac9011f4f144cd68543f8d9536e3fd.zip
misc/diag.h (BUG): more useful diagnostics; replace all "abort" with it
-rw-r--r--TODO2
-rw-r--r--gfx/cro.c2
-rw-r--r--gfx/pdftoc.c4
-rw-r--r--gfx/record.c3
-rw-r--r--gfx/text.c5
-rw-r--r--gui/gui.c4
-rw-r--r--gui/history.c5
-rw-r--r--gui/input.c12
-rw-r--r--kicad/delta.c5
-rw-r--r--kicad/dwg.c3
-rw-r--r--kicad/ext.c6
-rw-r--r--kicad/lib-parse.c2
-rw-r--r--kicad/lib-render.c12
-rw-r--r--kicad/pro.c3
-rw-r--r--kicad/sch-parse.c2
-rw-r--r--kicad/sexpr.c4
-rw-r--r--misc/diag.h10
17 files changed, 51 insertions, 33 deletions
diff --git a/TODO b/TODO
index 7651e85..2f81a5e 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,7 @@
Parsing and input processing:
- unify alignment, direction
- on parse error, politely complain, don't terminate;
- convert abort / assert(0) to proper error indications
+- convert assert(0) to proper error indications (BUG or such)
- quoted strings can have embedded double quotes, with \" (see parse_field)
- check what happens with UTF-8 (c4puter/motherboard)
diff --git a/gfx/cro.c b/gfx/cro.c
index 91e0ed4..1e229d5 100644
--- a/gfx/cro.c
+++ b/gfx/cro.c
@@ -220,7 +220,7 @@ static void cr_text(void *ctx, int x, int y, const char *s, unsigned size,
cairo_rel_move_to(cc->cr, -ext.width, 0);
break;
default:
- abort();
+ BUG("invalid alignment %d", align);
}
cairo_show_text(cc->cr, s);
diff --git a/gfx/pdftoc.c b/gfx/pdftoc.c
index dd30ded..39d59bd 100644
--- a/gfx/pdftoc.c
+++ b/gfx/pdftoc.c
@@ -173,7 +173,7 @@ static void line(struct pdftoc *ctx, const char *s)
}
break;
case xref:
- abort();
+ BUG("cannot be in xref");
case trailer:
if (sscanf(s, " /Root %d 0 R", &ctx->root) == 1)
break;
@@ -181,7 +181,7 @@ static void line(struct pdftoc *ctx, const char *s)
break;
break;
default:
- abort();
+ BUG("invalid state %d", ctx->state);
}
}
diff --git a/gfx/record.c b/gfx/record.c
index f224a48..0add67f 100644
--- a/gfx/record.c
+++ b/gfx/record.c
@@ -16,6 +16,7 @@
#include <math.h>
#include "misc/util.h"
+#include "misc/diag.h"
#include "gfx/style.h"
#include "gfx/gfx.h"
#include "gfx/text.h"
@@ -289,7 +290,7 @@ void record_replay(const struct record *rec)
obj->color, layer->layer);
break;
default:
- abort();
+ BUG("invalid object type %d", obj->type);
}
}
diff --git a/gfx/text.c b/gfx/text.c
index 46147c5..1d6d38a 100644
--- a/gfx/text.c
+++ b/gfx/text.c
@@ -17,6 +17,7 @@
#include <string.h>
#include "misc/util.h"
+#include "misc/diag.h"
#include "gfx/misc.h"
#include "gfx/style.h"
#include "gfx/gfx.h"
@@ -64,7 +65,7 @@ enum text_align text_flip(enum text_align align)
case text_max:
return text_min;
default:
- abort();
+ BUG("invalid alignment %d", align);
}
}
@@ -87,7 +88,7 @@ static int align(int dim, enum text_align align)
case text_max:
return dim;
default:
- abort();
+ BUG("invalid alignment %d", align);
}
}
diff --git a/gui/gui.c b/gui/gui.c
index 4f38325..5fe3cc9 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -99,13 +99,13 @@ static void select_subsheet(void *user)
go_to_sheet(ctx, sheet);
return;
}
- abort();
+ BUG("new sheet not found");
}
for (sheet = ctx->old_hist->sheets; sheet; sheet = sheet->next)
if (sheet->sch == obj->u.sheet.sheet)
goto found;
- abort();
+ BUG("old sheet not found");
found:
sheet = find_corresponding_sheet(ctx->new_hist->sheets,
diff --git a/gui/history.c b/gui/history.c
index 85a798d..47de575 100644
--- a/gui/history.c
+++ b/gui/history.c
@@ -18,6 +18,7 @@
#include <pango/pangocairo.h>
#include "misc/util.h"
+#include "misc/diag.h"
#include "file/git-hist.h"
#include "gui/fmt-pango.h"
#include "gui/style.h"
@@ -60,7 +61,7 @@ static void set_history_style(struct gui_hist *h, bool current)
style.frame = COLOR(FRAME_SEL_NEW);
break;
default:
- abort();
+ BUG("invalid mode %d", ctx->selecting);
}
if (ctx->new_hist == h || ctx->old_hist == h) {
@@ -170,7 +171,7 @@ static void click_history(void *user)
ctx->old_hist = h;
break;
default:
- abort();
+ BUG("invalid mode %d", ctx->selecting);
}
ctx->diff_mode = diff_delta;
diff --git a/gui/input.c b/gui/input.c
index b8d388f..f005527 100644
--- a/gui/input.c
+++ b/gui/input.c
@@ -65,7 +65,7 @@ static const char *state(void)
case input_dragging:
return "DRAGGING";
default:
- abort();
+ BUG("invalid state %d", sp->state);
}
}
@@ -133,7 +133,7 @@ static void hover_update(int x, int y)
break;
case input_dragging:
default:
- abort();
+ BUG("invalid state %d", sp->state);
}
if (sp->ops->hover_end)
@@ -164,7 +164,7 @@ void input_update(void)
case input_dragging:
break;
default:
- abort();
+ BUG("invalid state %d", sp->state);
}
}
@@ -210,7 +210,7 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event,
clicked_y = event->y;
break;
default:
- abort();
+ BUG("invalid state %d", sp->state);
}
return TRUE;
}
@@ -244,7 +244,7 @@ static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
clicked_y = event->y;
break;
default:
- abort();
+ BUG("invalid state %d", sp->state);
}
return TRUE;
@@ -294,7 +294,7 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
}
break;
default:
- abort();
+ BUG("invalid state %d", sp->state);
}
return TRUE;
diff --git a/kicad/delta.c b/kicad/delta.c
index d07915d..9eb05bb 100644
--- a/kicad/delta.c
+++ b/kicad/delta.c
@@ -17,6 +17,7 @@
#include <string.h>
#include "misc/util.h"
+#include "misc/diag.h"
#include "gfx/text.h"
#include "kicad/lib.h"
#include "kicad/sch.h"
@@ -98,7 +99,7 @@ static bool comp_eq_obj(const struct lib_obj *a, const struct lib_obj *b)
!strcmp(a->u.pin.name, b->u.pin.name) &&
!strcmp(a->u.pin.number, b->u.pin.number);
default:
- abort();
+ BUG("invalid type %d", a->type);
}
}
@@ -320,7 +321,7 @@ static bool obj_eq(const struct sch_obj *a, const struct sch_obj *b,
return 0;
return sheet_eq(a->u.sheet.sheet, b->u.sheet.sheet);
default:
- abort();
+ BUG("invalid type %d", a->type);
}
}
diff --git a/kicad/dwg.c b/kicad/dwg.c
index 261d0c3..799c329 100644
--- a/kicad/dwg.c
+++ b/kicad/dwg.c
@@ -18,6 +18,7 @@
#include <assert.h>
#include "misc/util.h"
+#include "misc/diag.h"
#include "gfx/misc.h"
#include "gfx/style.h"
#include "gfx/text.h"
@@ -74,7 +75,7 @@ static enum box_type flip_box(enum box_type box)
case box_both:
return box_both;
default:
- abort();
+ BUG("invalid box type %d", box);
}
}
diff --git a/kicad/ext.c b/kicad/ext.c
index d4221ee..fe85c44 100644
--- a/kicad/ext.c
+++ b/kicad/ext.c
@@ -46,13 +46,15 @@ void classify_files(struct file_names *fn, char *const *args,
unsigned n_args)
{
unsigned i;
+ enum ext ext;
fn->pro = fn->sch = fn->pl = NULL;
fn->libs = NULL;
fn->n_libs = 0;
for (i = 0; i != n_args; i++) {
- switch (identify(args[i])) {
+ ext = identify(args[i]);
+ switch (ext) {
case ext_unknown:
fatal("%s: unknown file type", args[i]);
case ext_project:
@@ -80,7 +82,7 @@ void classify_files(struct file_names *fn, char *const *args,
fn->pl = args[i];
break;
default:
- abort();
+ BUG("invalid extension code %d", ext);
}
}
}
diff --git a/kicad/lib-parse.c b/kicad/lib-parse.c
index 0d5d493..47081e7 100644
--- a/kicad/lib-parse.c
+++ b/kicad/lib-parse.c
@@ -313,7 +313,7 @@ static bool lib_parse_line(const struct file *file,
}
break;
default:
- abort();
+ BUG("invalid state %d", lib->state);
}
fatal("%u: cannot parse\n\"%s\"\n", file->lineno, line);
}
diff --git a/kicad/lib-render.c b/kicad/lib-render.c
index 54361ca..f73b227 100644
--- a/kicad/lib-render.c
+++ b/kicad/lib-render.c
@@ -71,7 +71,7 @@ static void draw_poly(const struct lib_poly *poly, const int m[6])
LAYER_COMP_DWG_BG);
break;
default:
- abort();
+ BUG("invalid fill '%c'", poly->fill);
}
}
@@ -97,7 +97,7 @@ static void draw_rect(const struct lib_rect *rect, const int m[6])
LAYER_COMP_DWG_BG);
break;
default:
- abort();
+ BUG("invalid fill '%c'", rect->fill);
}
}
@@ -125,7 +125,7 @@ static void draw_circ(const struct lib_circ *circ, const int m[6])
LAYER_COMP_DWG_BG);
break;
default:
- abort();
+ BUG("invalid fill '%c'", circ->fill);
}
}
@@ -422,7 +422,7 @@ static void draw_pin(const struct comp *comp, const struct lib_pin *pin,
hor = text_max;
break;
default:
- abort();
+ BUG("invalid orientation '%c'", pin->orient);
}
draw_pin_line(pin, shape, dx, dy, m);
@@ -474,7 +474,7 @@ static void draw_text(const struct lib_text *text, const int m[6])
txt.vert = text_flip(txt.vert);
break;
default:
- abort();
+ BUG("unknown rotation %d", txt.rot);
}
text_fig(&txt, COLOR_COMP_DWG, WIDTH_COMP_DWG);
@@ -533,7 +533,7 @@ static void draw(const struct comp *comp, const struct lib_obj *obj,
draw_pin(comp, &obj->u.pin, m);
break;
default:
- abort();
+ BUG("invalid object type %d", obj->type);
}
}
diff --git a/kicad/pro.c b/kicad/pro.c
index f077fe3..a113ba1 100644
--- a/kicad/pro.c
+++ b/kicad/pro.c
@@ -16,6 +16,7 @@
#include <assert.h>
#include "misc/util.h"
+#include "misc/diag.h"
#include "file/file.h"
#include "kicad/ext.h"
#include "kicad/pro.h"
@@ -77,7 +78,7 @@ static bool pro_parse_line(const struct file *file,
}
break;
default:
- abort();
+ BUG("invalid state %d", pro->state);
}
return 1;
}
diff --git a/kicad/sch-parse.c b/kicad/sch-parse.c
index 456ad13..08d7dd8 100644
--- a/kicad/sch-parse.c
+++ b/kicad/sch-parse.c
@@ -599,7 +599,7 @@ static bool parse_line(const struct file *file, void *user, const char *line)
case sch_eof:
return 1;
default:
- abort();
+ BUG("invalid state %d", ctx->state);
}
fatal("%s:%u: cannot parse\n\"%s\"\n", file->name, file->lineno, line);
}
diff --git a/kicad/sexpr.c b/kicad/sexpr.c
index 6f0fd2f..84871b9 100644
--- a/kicad/sexpr.c
+++ b/kicad/sexpr.c
@@ -108,7 +108,7 @@ static void end_string(struct sexpr_ctx *ctx, const char *end)
*t++ = '\t';
continue;
case 0:
- abort();
+ BUG("escaped NUL");
default:
break;
}
@@ -203,7 +203,7 @@ bool sexpr_parse(struct sexpr_ctx *ctx, const char *s)
case failed:
return 0;
default:
- abort();
+ BUG("invalid state %d", ctx->state);
}
s++;
}
diff --git a/misc/diag.h b/misc/diag.h
index 0184f15..5e2df87 100644
--- a/misc/diag.h
+++ b/misc/diag.h
@@ -23,6 +23,16 @@
extern unsigned verbose;
+/* ----- Internal errors --------------------------------------------------- */
+
+
+#define STRINGIFY(s) #s
+#define STRINGIFY_EXPAND(s) STRINGIFY(s)
+
+#define BUG(...) \
+ fatal("BUG " __FILE__ ":" STRINGIFY_EXPAND(__LINE__) ": " __VA_ARGS__)
+
+
/* ----- Specialized diagnostic functions ---------------------------------- */