#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <signal.h>
#include <wchar.h>
#include <time.h>
#include <unistd.h>
+#include "core.h"
#include "safe.h"
#include "list.h"
#include "misc.h"
}
time_t edlib_timing = 0;
-/* Set this to False when using gdb. It must be
- * extern to avoid it being optimised away.
- */
-extern bool edlib_timing_allowed;
-bool edlib_timing_allowed = True;
+
+static int _debugger_present = -1;
+static void _sigtrap_handler(int signum)
+{
+ _debugger_present = 0;
+ signal(SIGTRAP, SIG_DFL);
+}
+
+bool debugger_is_present(void)
+{
+ if (_debugger_present < 0) {
+ _debugger_present = 1;
+ signal(SIGTRAP, _sigtrap_handler);
+ raise(SIGTRAP);
+ }
+ return _debugger_present;
+}
int times_up(void)
{
return 1;
now = time(NULL);
if (edlib_timing + 15 < now) {
+ /* If running under gdb, then I was probaly delayed
+ * by single-stepping, so don't through an error
+ */
+ if (debugger_is_present())
+ return 0;
edlib_timing = 1;
return 1;
}
void time_starts(void)
{
- if (edlib_timing_allowed)
+ if (_debugger_present != 1)
edlib_timing = time(NULL);
}
return ts->tv_nsec / 1000 / 1000 + ts->tv_sec * 1000;
}
+extern bool debugger_is_present(void);
+
static inline bool pane_too_long(struct pane *p safe, unsigned int msec)
{
- extern bool edlib_timing_allowed;
struct timespec ts;
unsigned int duration;
- if (!edlib_timing_allowed)
- return False;
+
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
duration = ts_to_ms(&ts) - p->timestamp;
if (msec < 100)
msec = 100;
- return (duration > msec);
+ if (duration <= msec)
+ return False;
+ return ! debugger_is_present();
}
static inline void pane_set_time(struct pane *p safe)