summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorØyvind Harboe <oyvind.harboe@zylin.com>2010-09-20 11:50:32 +0200
committerØyvind Harboe <oyvind.harboe@zylin.com>2010-09-20 20:45:48 +0200
commit1abc26d7a2b7172184c64d2151bf4803699993da (patch)
treef8515d996fc07660b03345a3e53e580fa940be4f /src
parent6000411dddd9930b99a4931bc363f425cc0fdcda (diff)
downloadopenocd+libswd-1abc26d7a2b7172184c64d2151bf4803699993da.tar.gz
openocd+libswd-1abc26d7a2b7172184c64d2151bf4803699993da.tar.bz2
openocd+libswd-1abc26d7a2b7172184c64d2151bf4803699993da.tar.xz
openocd+libswd-1abc26d7a2b7172184c64d2151bf4803699993da.zip
helper: fix flaky capture command
capture of progress output would get polling results. This will break in the example below where polling output would override the tcl return value. capture {sleep 10000; set abc def} Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Diffstat (limited to 'src')
-rw-r--r--src/helper/command.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 086b03d3..1bd8c429 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -36,6 +36,7 @@
#endif
// @todo the inclusion of target.h here is a layering violation
+#include <jtag/jtag.h>
#include <target/target.h>
#include "command.h"
#include "configuration.h"
@@ -867,6 +868,9 @@ static char* openocd_jim_fgets(char *s, int size, void *cookie)
return NULL;
}
+/* Capture progress output and return as tcl return value. If the
+ * progress output was empty, return tcl return value.
+ */
static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2)
@@ -874,9 +878,21 @@ static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
struct log_capture_state *state = command_log_capture_start(interp);
+ /* disable polling during capture. This avoids capturing output
+ * from polling.
+ *
+ * This is necessary in order to avoid accidentially getting a non-empty
+ * string for tcl fn's.
+ */
+ bool save_poll = jtag_poll_get_enabled();
+
+ jtag_poll_set_enabled(false);
+
const char *str = Jim_GetString(argv[1], NULL);
int retcode = Jim_Eval_Named(interp, str, __THIS__FILE__, __LINE__);
+ jtag_poll_set_enabled(save_poll);
+
command_log_capture_finish(state);
return retcode;