From f0480b52756120e3a195dff4ce737160d4e6039a Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sat, 14 Mar 2015 03:18:15 +0200 Subject: [PATCH 1/2] Add debugger transport torture option --- Makefile | 1 + src/duk_debugger.c | 6 ++++++ src/duk_features.h.in | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d26721da..d255638a 100644 --- a/Makefile +++ b/Makefile @@ -202,6 +202,7 @@ CCOPTS_FEATURES += -DDUK_OPT_DEBUGGER_SUPPORT CCOPTS_FEATURES += -DDUK_OPT_DEBUGGER_FWD_PRINTALERT CCOPTS_FEATURES += -DDUK_OPT_DEBUGGER_FWD_LOGGING CCOPTS_FEATURES += -DDUK_OPT_DEBUGGER_DUMPHEAP +#CCOPTS_FEATURES += -DDUK_OPT_DEBUGGER_TRANSPORT_TORTURE CCOPTS_FEATURES += -DDUK_OPT_TARGET_INFO='"duk command built from Duktape repo"' #CCOPTS_FEATURES += -DDUK_OPT_NO_JX #CCOPTS_FEATURES += -DDUK_OPT_NO_JC diff --git a/src/duk_debugger.c b/src/duk_debugger.c index 462cb12f..c4e7eb02 100644 --- a/src/duk_debugger.c +++ b/src/duk_debugger.c @@ -168,6 +168,9 @@ DUK_INTERNAL void duk_debug_read_bytes(duk_hthread *thr, duk_uint8_t *data, duk_ } DUK_ASSERT(heap->dbg_read_cb != NULL); DUK_ASSERT(left >= 1); +#if defined(DUK_USE_DEBUGGER_TRANSPORT_TORTURE) + left = 1; +#endif got = heap->dbg_read_cb(heap->dbg_udata, (char *) p, left); if (got == 0 || got > left) { DUK_D(DUK_DPRINT("connection error during read, return zero data")); @@ -477,6 +480,9 @@ DUK_INTERNAL void duk_debug_write_bytes(duk_hthread *thr, const duk_uint8_t *dat } DUK_ASSERT(heap->dbg_write_cb != NULL); DUK_ASSERT(left >= 1); +#if defined(DUK_USE_DEBUGGER_TRANSPORT_TORTURE) + left = 1; +#endif got = heap->dbg_write_cb(heap->dbg_udata, (const char *) p, left); if (got == 0 || got > left) { DUK_D(DUK_DPRINT("connection error during write")); diff --git a/src/duk_features.h.in b/src/duk_features.h.in index fee609e7..b7f0be8b 100644 --- a/src/duk_features.h.in +++ b/src/duk_features.h.in @@ -2262,7 +2262,6 @@ typedef FILE duk_file; #define DUK_USE_DOUBLE_LINKED_HEAP #define DUK_USE_MARK_AND_SWEEP #define DUK_USE_MS_STRINGTABLE_RESIZE -#undef DUK_USE_GC_TORTURE #if defined(DUK_OPT_NO_REFERENCE_COUNTING) #undef DUK_USE_REFERENCE_COUNTING @@ -2291,6 +2290,7 @@ typedef FILE duk_file; #undef DUK_USE_MS_STRINGTABLE_RESIZE #endif +#undef DUK_USE_GC_TORTURE #if defined(DUK_OPT_GC_TORTURE) #define DUK_USE_GC_TORTURE #endif @@ -2382,6 +2382,12 @@ typedef FILE duk_file; #define DUK_USE_DEBUGGER_DUMPHEAP #endif +/* Debugger transport read/write torture. */ +#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE +#if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE) +#define DUK_USE_DEBUGGER_TRANSPORT_TORTURE +#endif + /* For opcodes with indirect indices, check final index against stack size. * This should not be necessary because the compiler is trusted, and we don't * bound check non-indirect indices either. From 33af4a977b3e0eeb8610d771dd5f5b5135e5b98c Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sat, 14 Mar 2015 03:18:49 +0200 Subject: [PATCH 2/2] Document DUK_OPT_DEBUGGER_TRANSPORT_TORTURE --- doc/feature-options.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/feature-options.rst b/doc/feature-options.rst index b4618db3..86771311 100644 --- a/doc/feature-options.rst +++ b/doc/feature-options.rst @@ -749,6 +749,13 @@ Support the DumpHeap command. This is optional because the command is not always needed. The command also has a relatively large footprint (about 10% of debugger code); in absolute terms it's about 1kB of code footprint. +DUK_OPT_DEBUGGER_TRANSPORT_TORTURE +---------------------------------- + +Development time option: force debugger transport torture. Concretely this +now causes Duktape to read/write debug protocol data in 1-byte increments, +which stresses message parsing and transport code. + Debugging options =================