From 2f654ebb05e0cb5f9851be27f2fb0dde37b5f633 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 19 Nov 2014 16:50:59 +0100 Subject: [PATCH 1/4] Fix implicit function when libunwind is disabled The '#endif' is position on a weird place which results in a compile warning (-Wimplicit-function). Fix this and print a diagnostic message on startup if a backtrace is requested but support is missing. Note: only affects builds where you manually disable HAVE_LIBUNWIND. --- gobject-list.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gobject-list.c b/gobject-list.c index 2974f60..9ea9080 100644 --- a/gobject-list.c +++ b/gobject-list.c @@ -124,6 +124,10 @@ display_filter (DisplayFlags flags) g_strfreev (tokens); } +#ifndef HAVE_LIBUNWIND + if (display_flags & DISPLAY_FLAG_BACKTRACE) + g_print ("Warning: backtrace is not available, it needs libunwind\n"); +#endif parsed = TRUE; } @@ -171,6 +175,7 @@ print_trace (void) g_print ("#%d %s + [0x%08x]\n", stack_num++, name, (unsigned int)off); } +#endif } static void @@ -190,7 +195,6 @@ _dump_object_list (GHashTable *hash) obj, G_OBJECT_TYPE_NAME (obj), obj->ref_count); } g_print ("%u objects\n", g_hash_table_size (hash)); -#endif } static void From 79529392a3513cd2859706143c190036add22906 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 19 Nov 2014 20:51:10 +0100 Subject: [PATCH 2/4] Improve unw_get_proc_name error check The length param of unw_get_proc_name already takes care of the terminator, so remove the subtraction. The manual describes that the error code is given by the negative, so fix the condition checking against UNW_ENOMEM (verified by shrinking the buffer). Finally, the error message confused me (as a user) as it seems to suggest something about the process name (rather than procedure). Mention the more applicable "frame" instead (longer alternative: "procedure name of frame"). --- gobject-list.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gobject-list.c b/gobject-list.c index 9ea9080..d1974d4 100644 --- a/gobject-list.c +++ b/gobject-list.c @@ -166,10 +166,11 @@ print_trace (void) unw_word_t off; int result; - result = unw_get_proc_name (&cursor, name, sizeof (name) - 1, &off); - if (result < 0 && result != UNW_ENOMEM) + result = unw_get_proc_name (&cursor, name, sizeof (name), &off); + if (result < 0 && result != -UNW_ENOMEM) { - g_print ("Error getting proc name\n"); + g_print ("Error getting frame: %s (%d)\n", + unw_strerror (result), -result); break; } From 2aeffbd8087220e65cc520d692d66e55cc8769c9 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 20 Nov 2014 16:10:28 +0100 Subject: [PATCH 3/4] Makefile: allow compiler override, split obj generation Allow a different compiler to be specified and split the actual object compile to a different target. Add a Phony target to avoid breaking when a literal "all" or "clean" exist. --- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f0208cf..a4e1bea 100644 --- a/Makefile +++ b/Makefile @@ -7,19 +7,24 @@ else optional_libs= endif +CC ?= cc FLAGS=`pkg-config --cflags gobject-2.0` LIBS=`pkg-config --libs gobject-2.0 $(optional_libs)` +OBJS = gobject-list.o all: libgobject-list.so +.PHONY: all clean clean: - rm -f libgobject-list.so gobject-list.o + rm -f libgobject-list.so $(OBJS) -libgobject-list.so: gobject-list.c +%.o: %.c + $(CC) -fPIC -rdynamic -g -c -Wall ${FLAGS} ${BUILD_OPTIONS} $< + +libgobject-list.so: $(OBJS) ifeq ($(HAVE_LIBUNWIND), 1) @echo "Building with backtrace support (libunwind)" else @echo "Building without backtrace support (libunwind disabled)" endif - $(CC) -fPIC -rdynamic -g -c -Wall ${FLAGS} ${BUILD_OPTIONS} $< - $(CC) -shared -Wl,-soname,$@ -o $@ gobject-list.o -lc -ldl ${LIBS} + $(CC) -shared -Wl,-soname,$@ -o $@ $^ -lc -ldl ${LIBS} From 26698ea17c556d605352b743bca62692184a17ec Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 20 Nov 2014 16:12:19 +0100 Subject: [PATCH 4/4] Annotate for -Wunused-parameter, add -Wextra Useful during development. --- Makefile | 2 +- gobject-list.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a4e1bea..684cde8 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ clean: rm -f libgobject-list.so $(OBJS) %.o: %.c - $(CC) -fPIC -rdynamic -g -c -Wall ${FLAGS} ${BUILD_OPTIONS} $< + $(CC) -fPIC -rdynamic -g -c -Wall -Wextra ${FLAGS} ${BUILD_OPTIONS} $< libgobject-list.so: $(OBJS) ifeq ($(HAVE_LIBUNWIND), 1) diff --git a/gobject-list.c b/gobject-list.c index d1974d4..891a1ce 100644 --- a/gobject-list.c +++ b/gobject-list.c @@ -199,7 +199,7 @@ _dump_object_list (GHashTable *hash) } static void -_sig_usr1_handler (int signal) +_sig_usr1_handler (G_GNUC_UNUSED int signal) { g_print ("Living Objects:\n"); @@ -209,7 +209,7 @@ _sig_usr1_handler (int signal) } static void -_sig_usr2_handler (int signal) +_sig_usr2_handler (G_GNUC_UNUSED int signal) { GHashTableIter iter; gpointer obj, type; @@ -315,7 +315,7 @@ get_func (const char *func_name) } static void -_object_finalized (gpointer data, +_object_finalized (G_GNUC_UNUSED gpointer data, GObject *obj) { G_LOCK (gobject_list);