Patchwork [07/13] fs-tests: integck: add debug compilation target

login
register
mail settings
Submitter Artem Bityutskiy
Date April 22, 2011, 5:25 p.m.
Message ID <1303493124-7619-8-git-send-email-dedekind1@gmail.com>
Download mbox | patch
Permalink /patch/92558/
State New
Headers show

Comments

Artem Bityutskiy - April 22, 2011, 5:25 p.m.
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

I often need to use gdb to debug integck, or sometimes even attach
already running integck. But when it is compiled with optimizations, it
is nearly impossible to use gdb. Introduce 'debug' target to compile
integck without optimizations.

Additionally, to make the stack backtraces work, add a dirty hack to
integck.c to remove all the static keywords - this turns static
functions to non-static and makes them appear in stack backtraces.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 tests/fs-tests/integrity/Makefile  |    5 +++++
 tests/fs-tests/integrity/integck.c |   10 ++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

Patch

diff --git a/tests/fs-tests/integrity/Makefile b/tests/fs-tests/integrity/Makefile
index 976c3ce..2cdd470 100644
--- a/tests/fs-tests/integrity/Makefile
+++ b/tests/fs-tests/integrity/Makefile
@@ -13,5 +13,10 @@  TARGETS = integck
 
 all: $(TARGETS)
 
+# Disable optimizations to make it possible to use gdb comfortably
+# Use -rdynamic to have stack backtraces
+debug:
+	gcc $(CFLAGS) -O0 -D INTEGCK_DEBUG -rdynamic integck.c -o integck
+
 clean:
 	rm -f *.o $(TARGETS)
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index f09cfaf..fbd6cc5 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -41,6 +41,16 @@ 
 #define PROGRAM_NAME "integck"
 #include "common.h"
 
+/*
+ * WARNING! This is a dirty hack! The symbols for static functions are not
+ * printed in the stack backtrace. So we remove ths 'static' keyword using the
+ * pre-processor. This is really error-prone because this won't work if, e.g.,
+ * local static variables were used.
+ */
+#ifdef INTEGCK_DEBUG
+#define static
+#endif
+
 #define MAX_RANDOM_SEED 10000000
 
 /* The pattern for the top directory where we run the test */