Skip to content

Commit 6ef0958

Browse files
committed
Merge pull request #7 from Lekensteyn/fix-libunwind
libunwind fixes (compile fix, fix error condition/message)
2 parents 0b632ac + 26698ea commit 6ef0958

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ else
77
optional_libs=
88
endif
99

10+
CC ?= cc
1011
FLAGS=`pkg-config --cflags gobject-2.0`
1112
LIBS=`pkg-config --libs gobject-2.0 $(optional_libs)`
1213

14+
OBJS = gobject-list.o
1315

1416
all: libgobject-list.so
17+
.PHONY: all clean
1518
clean:
16-
rm -f libgobject-list.so gobject-list.o
19+
rm -f libgobject-list.so $(OBJS)
1720

18-
libgobject-list.so: gobject-list.c
21+
%.o: %.c
22+
$(CC) -fPIC -rdynamic -g -c -Wall -Wextra ${FLAGS} ${BUILD_OPTIONS} $<
23+
24+
libgobject-list.so: $(OBJS)
1925
ifeq ($(HAVE_LIBUNWIND), 1)
2026
@echo "Building with backtrace support (libunwind)"
2127
else
2228
@echo "Building without backtrace support (libunwind disabled)"
2329
endif
24-
$(CC) -fPIC -rdynamic -g -c -Wall ${FLAGS} ${BUILD_OPTIONS} $<
25-
$(CC) -shared -Wl,-soname,$@ -o $@ gobject-list.o -lc -ldl ${LIBS}
30+
$(CC) -shared -Wl,-soname,$@ -o $@ $^ -lc -ldl ${LIBS}

gobject-list.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ display_filter (DisplayFlags flags)
124124

125125
g_strfreev (tokens);
126126
}
127+
#ifndef HAVE_LIBUNWIND
128+
if (display_flags & DISPLAY_FLAG_BACKTRACE)
129+
g_print ("Warning: backtrace is not available, it needs libunwind\n");
130+
#endif
127131

128132
parsed = TRUE;
129133
}
@@ -162,15 +166,17 @@ print_trace (void)
162166
unw_word_t off;
163167
int result;
164168

165-
result = unw_get_proc_name (&cursor, name, sizeof (name) - 1, &off);
166-
if (result < 0 && result != UNW_ENOMEM)
169+
result = unw_get_proc_name (&cursor, name, sizeof (name), &off);
170+
if (result < 0 && result != -UNW_ENOMEM)
167171
{
168-
g_print ("Error getting proc name\n");
172+
g_print ("Error getting frame: %s (%d)\n",
173+
unw_strerror (result), -result);
169174
break;
170175
}
171176

172177
g_print ("#%d %s + [0x%08x]\n", stack_num++, name, (unsigned int)off);
173178
}
179+
#endif
174180
}
175181

176182
static void
@@ -190,11 +196,10 @@ _dump_object_list (GHashTable *hash)
190196
obj, G_OBJECT_TYPE_NAME (obj), obj->ref_count);
191197
}
192198
g_print ("%u objects\n", g_hash_table_size (hash));
193-
#endif
194199
}
195200

196201
static void
197-
_sig_usr1_handler (int signal)
202+
_sig_usr1_handler (G_GNUC_UNUSED int signal)
198203
{
199204
g_print ("Living Objects:\n");
200205

@@ -204,7 +209,7 @@ _sig_usr1_handler (int signal)
204209
}
205210

206211
static void
207-
_sig_usr2_handler (int signal)
212+
_sig_usr2_handler (G_GNUC_UNUSED int signal)
208213
{
209214
GHashTableIter iter;
210215
gpointer obj, type;
@@ -310,7 +315,7 @@ get_func (const char *func_name)
310315
}
311316

312317
static void
313-
_object_finalized (gpointer data,
318+
_object_finalized (G_GNUC_UNUSED gpointer data,
314319
GObject *obj)
315320
{
316321
G_LOCK (gobject_list);

0 commit comments

Comments
 (0)