Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions gobject-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Philip Withnall <philip.withnall@collabora.co.uk>
*/
#include <glib-object.h>
#include <glib/gprintf.h>

/**
* In later versions of GLib, g_object_ref is defined as a macro to make the
Expand Down Expand Up @@ -133,7 +134,7 @@ display_filter (DisplayFlags flags)
}
#ifndef HAVE_LIBUNWIND
if (display_flags & DISPLAY_FLAG_BACKTRACE)
g_print ("Warning: backtrace is not available, it needs libunwind\n");
g_fprintf (stderr, "Warning: backtrace is not available, it needs libunwind\n");
#endif

parsed = TRUE;
Expand Down Expand Up @@ -176,12 +177,12 @@ print_trace (void)
result = unw_get_proc_name (&cursor, name, sizeof (name), &off);
if (result < 0 && result != -UNW_ENOMEM)
{
g_print ("Error getting frame: %s (%d)\n",
g_fprintf (stderr, "Error getting frame: %s (%d)\n",
unw_strerror (result), -result);
break;
}

g_print ("#%d %s + [0x%08x]\n", stack_num++, name, (unsigned int)off);
g_fprintf (stderr, "#%d %s + [0x%08x]\n", stack_num++, name, (unsigned int)off);
}
#endif
}
Expand All @@ -199,16 +200,16 @@ _dump_object_list (GHashTable *hash)
if (obj == NULL || obj->ref_count == 0)
continue;

g_print (" - %p, %s: %u refs\n",
g_fprintf (stderr, " - %p, %s: %u refs\n",
obj, G_OBJECT_TYPE_NAME (obj), obj->ref_count);
}
g_print ("%u objects\n", g_hash_table_size (hash));
g_fprintf (stderr, "%u objects\n", g_hash_table_size (hash));
}

static void
_sig_usr1_handler (G_GNUC_UNUSED int signal)
{
g_print ("Living Objects:\n");
g_fprintf (stderr, "Living Objects:\n");

G_LOCK (gobject_list);
_dump_object_list (gobject_list_state.objects);
Expand All @@ -223,28 +224,28 @@ _sig_usr2_handler (G_GNUC_UNUSED int signal)

G_LOCK (gobject_list);

g_print ("Added Objects:\n");
g_fprintf (stderr, "Added Objects:\n");
_dump_object_list (gobject_list_state.added);

g_print ("\nRemoved Objects:\n");
g_fprintf (stderr, "\nRemoved Objects:\n");
g_hash_table_iter_init (&iter, gobject_list_state.removed);
while (g_hash_table_iter_next (&iter, &obj, &type))
{
g_print (" - %p, %s\n", obj, (gchar *) type);
g_fprintf (stderr, " - %p, %s\n", obj, (gchar *) type);
}
g_print ("%u objects\n", g_hash_table_size (gobject_list_state.removed));
g_fprintf (stderr, "%u objects\n", g_hash_table_size (gobject_list_state.removed));

g_hash_table_remove_all (gobject_list_state.added);
g_hash_table_remove_all (gobject_list_state.removed);
g_print ("\nSaved new check point\n");
g_fprintf (stderr, "\nSaved new check point\n");

G_UNLOCK (gobject_list);
}

static void
print_still_alive (void)
{
g_print ("\nStill Alive:\n");
g_fprintf (stderr, "\nStill Alive:\n");

G_LOCK (gobject_list);
_dump_object_list (gobject_list_state.objects);
Expand Down Expand Up @@ -331,7 +332,7 @@ _object_finalized (G_GNUC_UNUSED gpointer data,
{
g_mutex_lock(&output_mutex);

g_print (" -- Finalized object %p, %s\n", obj, G_OBJECT_TYPE_NAME (obj));
g_fprintf (stderr, " -- Finalized object %p, %s\n", obj, G_OBJECT_TYPE_NAME (obj));
print_trace();

g_mutex_unlock(&output_mutex);
Expand Down Expand Up @@ -376,7 +377,7 @@ g_object_new (GType type,
{
g_mutex_lock(&output_mutex);

g_print (" ++ Created object %p, %s\n", obj, obj_name);
g_fprintf (stderr, " ++ Created object %p, %s\n", obj, obj_name);
print_trace();

g_mutex_unlock(&output_mutex);
Expand Down Expand Up @@ -428,7 +429,7 @@ g_object_ref (gpointer object)
{
g_mutex_lock(&output_mutex);

g_print (" + Reffed object %p, %s; ref_count: %d -> %d\n",
g_fprintf (stderr, " + Reffed object %p, %s; ref_count: %d -> %d\n",
obj, obj_name, ref_count, obj->ref_count);
print_trace();

Expand All @@ -453,7 +454,7 @@ g_object_unref (gpointer object)
{
g_mutex_lock(&output_mutex);

g_print (" - Unreffed object %p, %s; ref_count: %d -> %d\n",
g_fprintf (stderr, " - Unreffed object %p, %s; ref_count: %d -> %d\n",
obj, obj_name, obj->ref_count, obj->ref_count - 1);
print_trace();

Expand Down
31 changes: 31 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
project('gobject-list', 'c')

cc = meson.get_compiler('c')

c_args = cc.get_supported_arguments([
'-fPIC',
'-rdynamic',
'-g',
'-Wall',
'-Wextra',
])

libunwind_dep = dependency('libunwind', required: false)
libgobject_dep = dependency('gobject-2.0')
libc_dep = cc.find_library('c')
libdl_dep = cc.find_library('dl')

if libunwind_dep.found()
add_project_arguments(['-DHAVE_LIBUNWIND'], language: 'c')
endif

libgobject_list = library('gobject-list',
c_args: c_args,
sources: ['gobject-list.c'],
dependencies: [libunwind_dep, libgobject_dep, libc_dep, libdl_dep],
install: not meson.is_subproject(),
)

libgobject_list_dep = declare_dependency(
link_with: libgobject_list,
)