summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-06-14 18:26:18 +0100
committerRobin Watts <robin.watts@artifex.com>2016-06-14 18:30:13 +0100
commit3c889ceed3b9a78da16ea2387f3b8029e25aa15b (patch)
tree1521fe438bba73454e32f732b74801732621eaf9
parent3bc51652cc962f0256acdf37f52d0a7d98b20ed1 (diff)
downloadghostpdl-3c889ceed3b9a78da16ea2387f3b8029e25aa15b.tar.gz
Memento: Add Memento_tick()
Sometimes it can be useful to be able to run a program repeatedly and stop it at a given place, just before a problem occurs. Suppose you know that the problem occurs in the 'foo' function, but only after a number of runs. Insert a call to Memento_tick() at the top of foo, rebuild and run in the debugger. When the problem occurs, consult memento.sequence to see what event number we are on; suppose it's 1000. Then you can rerun the debugger with breakpoints on Memento_inited and Memento_breakpoint. When the program stops at Memento_inited, call Memento_breakAt(1000) and continue execution. The program will then stop in Memento_breakpoint within the Memento_tick call just before the problem occurs, enabling you to step forward and see what goes wrong.
-rw-r--r--base/memento.c17
-rw-r--r--base/memento.h2
2 files changed, 15 insertions, 4 deletions
diff --git a/base/memento.c b/base/memento.c
index fd95b6ffa..de3a82134 100644
--- a/base/memento.c
+++ b/base/memento.c
@@ -1529,7 +1529,7 @@ static void Memento_startFailing(void)
}
}
-static void Memento_event(void)
+static int Memento_event(void)
{
memento.sequence++;
if ((memento.sequence >= memento.paranoidAt) && (memento.paranoidAt != 0)) {
@@ -1550,8 +1550,9 @@ static void Memento_event(void)
if (memento.sequence == memento.breakAt) {
fprintf(stderr, "Breaking at event %d\n", memento.breakAt);
- Memento_breakpoint();
+ return 1;
}
+ return 0;
}
int Memento_breakAt(int event)
@@ -1573,6 +1574,14 @@ void *Memento_label(void *ptr, const char *label)
return ptr;
}
+void Memento_tick(void)
+{
+ if (!memento.inited)
+ Memento_init();
+
+ if (Memento_event()) Memento_breakpoint();
+}
+
int Memento_failThisEvent(void)
{
int failThisOne;
@@ -1580,7 +1589,7 @@ int Memento_failThisEvent(void)
if (!memento.inited)
Memento_init();
- Memento_event();
+ if (Memento_event()) Memento_breakpoint();
if ((memento.sequence >= memento.failAt) && (memento.failAt != 0))
Memento_startFailing();
@@ -1783,7 +1792,7 @@ static void do_free(void *blk, int eventType)
if (!memento.inited)
Memento_init();
- Memento_event();
+ if (Memento_event()) Memento_breakpoint();
if (blk == NULL)
return;
diff --git a/base/memento.h b/base/memento.h
index 722c000ea..ec830b41f 100644
--- a/base/memento.h
+++ b/base/memento.h
@@ -214,6 +214,7 @@ void Memento_listNewBlocks(void);
size_t Memento_setMax(size_t);
void Memento_stats(void);
void *Memento_label(void *, const char *);
+void Memento_tick(void);
void *Memento_malloc(size_t s);
void *Memento_realloc(void *, size_t s);
@@ -265,6 +266,7 @@ void *Memento_reference(void *blk);
#define Memento_takeRef(A) (A)
#define Memento_dropRef(A) (A)
#define Memento_reference(A) (A)
+#define Memento_tick() do {} while (0)
#endif /* MEMENTO */