Add systemtap probes to refcounted data

Probes allow us to debug refcounting bugs.
This commit is contained in:
Emmanuele Bassi 2018-07-03 17:45:49 +01:00
parent 4248b4b300
commit c342105e76
4 changed files with 67 additions and 0 deletions

View File

@ -27,6 +27,8 @@
#include "valgrind.h"
#endif
#include "glib_trace.h"
#include <string.h>
#define G_ARC_BOX(p) (GArcBox *) (((char *) (p)) - G_ARC_BOX_SIZE)
@ -289,6 +291,8 @@ gpointer
g_atomic_ref_count_inc (&real_box->ref_count);
TRACE (GLIB_RCBOX_ACQUIRE (mem_block, 1));
return mem_block;
}
@ -335,8 +339,12 @@ g_atomic_rc_box_release_full (gpointer mem_block,
if (g_atomic_ref_count_dec (&real_box->ref_count))
{
TRACE (GLIB_RCBOX_RELEASE (mem_block, 1));
if (clear_func != NULL)
clear_func (mem_block);
TRACE (GLIB_RCBOX_FREE (mem_block));
g_free (real_box);
}
}

View File

@ -598,3 +598,48 @@ probe glib.thread_spawned = process("@ABS_GLIB_RUNTIME_LIBDIR@/libglib-2.0.so.0.
name = user_string($arg3);
probestr = sprintf("glib.thread_spawned(%p, %p, %s)", func, data, name);
}
/**
* probe glib.rcbox_alloc - Called when a refcounted block is initially requested
* @mem: Raw memory pointer returned
* @n_bytes: number of bytes
* @atomic: Boolean value, %TRUE if this block is atomically refcounted
* @zeroed: Boolean value, %TRUE if this block was filled with NUL bytes
*/
probe glib.rcbox_alloc = process("@ABS_GLIB_RUNTIME_LIBDIR@/libglib-2.0.so.0.@LT_CURRENT@.@LT_REVISION@").mark("rcbox__alloc")
{
mem = $arg1;
n_bytes = $arg2;
atomic = $arg3;
zeroed = $arg4;
probestr = sprintf("glib.rcbox_alloc(n_bytes=%d) -> %p", n_bytes, mem);
}
/**
* probe glib.rcbox_acquire - Called when a refcounted block acquires a ref
*/
probe glib.rcbox_acquire = process("@ABS_GLIB_RUNTIME_LIBDIR@/libglib-2.0.so.0.@LT_CURRENT@.@LT_REVISION@").mark("rcbox__acquire")
{
mem = $arg1; /* ARG: @mem: Raw memory pointer */
atomic = $arg2; /* ARG: @atomic: Boolean value, %TRUE if the reference was acquired atomically */
probestr = sprintf("glib.rcbox_acquire(mem=%p)", mem);
}
/**
* probe glib.rcbox_release - Called when a refcounted block acquires a ref
*/
probe glib.rcbox_acquire = process("@ABS_GLIB_RUNTIME_LIBDIR@/libglib-2.0.so.0.@LT_CURRENT@.@LT_REVISION@").mark("rcbox__release")
{
mem = $arg1; /* ARG: @mem: Raw memory pointer */
atomic = $arg2; /* ARG: @atomic: Boolean value, %TRUE if the reference was released atomically */
probestr = sprintf("glib.rcbox_release(mem=%p)", mem);
}
/**
* probe glib.rcbox_free - Called when a refcounted block is freed
*/
probe glib.rcbox_free = process("@ABS_GLIB_RUNTIME_LIBDIR@/libglib-2.0.so.0.@LT_CURRENT@.@LT_REVISION@").mark("rcbox__free")
{
mem = $arg1; /* ARG: @mem: Raw memory pointer */
probestr = sprintf("glib.rcbox_free(mem=%p)", mem);
}

View File

@ -43,4 +43,8 @@ provider glib {
probe source__set_name(void*, const char*);
probe source__before_free(void*, void*, void*);
probe thread__spawned(void*, void*, char*);
probe rcbox__alloc(void*, unsigned int, unsigned int, unsigned int);
probe rcbox__acquire(void*, unsigned int);
probe rcbox__release(void*, unsigned int);
probe rcbox__free(void*);
};

View File

@ -28,6 +28,8 @@
#include "valgrind.h"
#endif
#include "glib_trace.h"
#include <string.h>
/**
@ -229,6 +231,8 @@ g_rc_box_alloc_full (gsize block_size,
g_ref_count_init (&real_box->ref_count);
}
TRACE (GLIB_RCBOX_ALLOC (allocated, block_size, atomic, clear));
return allocated + private_size;
}
@ -364,6 +368,8 @@ gpointer
g_ref_count_inc (&real_box->ref_count);
TRACE (GLIB_RCBOX_ACQUIRE (mem_block, 0));
return mem_block;
}
@ -410,8 +416,12 @@ g_rc_box_release_full (gpointer mem_block,
if (g_ref_count_dec (&real_box->ref_count))
{
TRACE (GLIB_RCBOX_RELEASE (mem_block, 0));
if (clear_func != NULL)
clear_func (mem_block);
TRACE (GLIB_RCBOX_FREE (mem_block));
g_free (real_box);
}
}