#endif /* HAVE_DW */
static gchar *
-generate_unwind_trace (void)
+generate_unwind_trace (GstStackTraceFlags flags)
{
unw_context_t uc;
unw_cursor_t cursor;
GString *trace = g_string_new (NULL);
#ifdef HAVE_DW
- Dwfl *dwfl;
-
+ Dwfl *dwfl = NULL;
Dwfl_Callbacks callbacks = {
.find_elf = dwfl_linux_proc_find_elf,
.find_debuginfo = dwfl_standard_find_debuginfo,
};
- dwfl = dwfl_begin (&callbacks);
+ if ((flags & GST_STACK_TRACE_SHOW_FULL))
+ dwfl = dwfl_begin (&callbacks);
#endif /* HAVE_DW */
unw_getcontext (&uc);
}
#ifdef HAVE_DW
- dwfl_end (dwfl);
+ if (dwfl)
+ dwfl_end (dwfl);
#endif
return g_string_free (trace, FALSE);
/**
* gst_debug_get_stack_trace:
+ * @flags: A set of #GstStackTraceFlags to determine how the stack
+ * trace should look like. Pass 0 to retrieve a minimal backtrace.
*
* If libunwind or glibc backtrace are present, a stack trace
* is returned.
+ *
+ * Since: 1.12
*/
gchar *
-gst_debug_get_stack_trace (void)
+gst_debug_get_stack_trace (GstStackTraceFlags flags)
{
gchar *trace = NULL;
+#ifdef HAVE_BACKTRACE
+ gboolean have_backtrace = TRUE;
+#else
+ gboolean have_backtrace = FALSE;
+#endif
#ifdef HAVE_UNWIND
- trace = generate_unwind_trace ();
- if (trace)
- return trace;
+ if ((flags & GST_STACK_TRACE_SHOW_FULL) || !have_backtrace)
+ trace = generate_unwind_trace (flags);
#endif /* HAVE_UNWIND */
-#ifdef HAVE_BACKTRACE
- trace = generate_backtrace_trace ();
-#endif /* HAVE_BACKTRACE */
+ if (trace)
+ return trace;
+ else if (have_backtrace)
+ return generate_backtrace_trace ();
- return trace;
+ return NULL;
}
/**
void
gst_debug_print_stack_trace (void)
{
- gchar *trace = gst_debug_get_stack_trace ();
+ gchar *trace = gst_debug_get_stack_trace (GST_STACK_TRACE_SHOW_FULL);
if (trace)
g_print ("%s\n", trace);
} GstDebugColorFlags;
/**
+ * GstStackTraceFlags:
+ * @GST_STACK_TRACE_SHOW_FULL: Try to retrieve as much information as
+ * possible when getting the stack trace
+ */
+typedef enum {
+ GST_STACK_TRACE_SHOW_FULL = 1 << 0
+} GstStackTraceFlags;
+
+/**
* GstDebugColorMode:
* @GST_DEBUG_COLOR_MODE_OFF: Do not use colors in logs.
* @GST_DEBUG_COLOR_MODE_ON: Paint logs in a platform-specific way.
void gst_debug_print_stack_trace (void);
-gchar * gst_debug_get_stack_trace (void);
+gchar * gst_debug_get_stack_trace (GstStackTraceFlags flags);
G_END_DECLS
GST_OBJECT_LOCK (self);
if (self->log_stack_trace) {
- trace = gst_debug_get_stack_trace ();
+ trace = gst_debug_get_stack_trace (GST_STACK_TRACE_SHOW_FULL);
}
g_hash_table_insert (self->objects, object, trace);
gchar *trace;
/* Test if we can retrieve backtrace */
- trace = gst_debug_get_stack_trace ();
+ trace = gst_debug_get_stack_trace (GST_STACK_TRACE_SHOW_FULL);
if (trace) {
self->log_stack_trace = TRUE;
g_free (trace);