From 17586b80b19d963025a601c8409267b2dacde249 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 8 Nov 2016 18:06:19 -0300 Subject: [PATCH] validate: Use gst_debug_get_stack_trace instead of our implementation And remove now useless config.h.meson file --- validate/config.h.meson | 20 --- validate/configure.ac | 20 --- validate/gst/validate/Makefile.am | 8 +- validate/gst/validate/gst-validate-report.c | 144 +------------------- validate/gst/validate/meson.build | 6 +- validate/meson.build | 22 +-- 6 files changed, 6 insertions(+), 214 deletions(-) delete mode 100644 validate/config.h.meson diff --git a/validate/config.h.meson b/validate/config.h.meson deleted file mode 100644 index 26c3d9a8fd..0000000000 --- a/validate/config.h.meson +++ /dev/null @@ -1,20 +0,0 @@ -/* GStreamer API Version */ -#mesondefine GST_API_VERSION - -/* data dir */ -#mesondefine GST_DATADIR - -/* Define to the full name of this package. */ -#mesondefine PACKAGE_NAME - -/* directory where plugins are located */ -#mesondefine VALIDATEPLUGINDIR -#mesondefine HAVE_UNWIND -#mesondefine HAVE_BACKTRACE -#mesondefine HAVE_DW -#mesondefine GST_LICENSE -#mesondefine VERSION -#mesondefine PACKAGE -#mesondefine PACKAGE_VERSION -#mesondefine GST_PACKAGE_NAME -#mesondefine GST_PACKAGE_ORIGIN diff --git a/validate/configure.ac b/validate/configure.ac index 7b309867b1..abd6819899 100644 --- a/validate/configure.ac +++ b/validate/configure.ac @@ -205,26 +205,6 @@ PKG_CHECK_MODULES(JSON_GLIB, json-glib-1.0) AC_SUBST(JSON_GLIB_LIBS) AC_SUBST(JSON_GLIB_CFLAGS) -dnl libunwind is optionally used to generate backtraces -PKG_CHECK_MODULES(UNWIND, libunwind, HAVE_UNWIND=yes, HAVE_UNWIND=no) -if test "x$HAVE_UNWIND" = "xyes"; then - AC_DEFINE(HAVE_UNWIND, 1, [libunwind available]) -fi - -dnl libdw is optionally used to add source lines and numbers to backtraces -PKG_CHECK_MODULES(DW, libdw, HAVE_DW=yes, HAVE_DW=no) -if test "x$HAVE_DW" = "xyes"; then - AC_DEFINE(HAVE_DW, 1, [libdw available]) -fi - -dnl Check for backtrace() from libc -AC_CHECK_FUNC(backtrace, [ - AC_CHECK_HEADERS([execinfo.h], [ - AC_DEFINE(HAVE_BACKTRACE,1,[Have backtrace]) - ], [], []) -]) - - dnl checks for gstreamer AG_GST_CHECK_GST_CHECK($GST_API_VERSION, [$GST_REQ], no) diff --git a/validate/gst/validate/Makefile.am b/validate/gst/validate/Makefile.am index 04e4784e11..a87ed78a44 100644 --- a/validate/gst/validate/Makefile.am +++ b/validate/gst/validate/Makefile.am @@ -51,15 +51,13 @@ libgstvalidate_@GST_API_VERSION@_la_SOURCES = $(source_c) libgstvalidate_@GST_API_VERSION@include_HEADERS = $(source_h) libgstvalidate_@GST_API_VERSION@_la_CFLAGS = $(GST_ALL_CFLAGS)\ $(JSON_GLIB_CFLAGS) $(GIO_CFLAGS) $(GST_PBUTILS_CFLAGS) \ - $(DW_CFLAGS) \ -DGST_USE_UNSTABLE_API libgstvalidate_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) \ $(GST_LT_LDFLAGS) $(GIO_LDFLAGS) $(GST_PBUTILS_LDFAGS) libgstvalidate_@GST_API_VERSION@_la_LIBADD = \ $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) \ $(GST_ALL_LIBS) $(GIO_LIBS) $(GST_PBUTILS_LIBS) \ - $(JSON_GLIB_LIBS) $(GLIB_LIBS) $(LIBM) $(UNWIND_LIBS) \ - $(DW_LIBS) + $(JSON_GLIB_LIBS) $(GLIB_LIBS) $(LIBM) libgstvalidate_@GST_API_VERSION@includedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/validate @@ -68,7 +66,6 @@ plugin_LTLIBRARIES = libgstvalidateplugin-@GST_API_VERSION@.la libgstvalidateplugin_@GST_API_VERSION@_la_SOURCES = $(source_c) libgstvalidateplugin_@GST_API_VERSION@_la_CFLAGS = $(GST_ALL_CFLAGS)\ $(JSON_GLIB_CFLAGS) $(GIO_CFLAGS) $(GST_PBUTILS_CFLAGS) \ - $(DW_CFLAGS) \ -DGST_USE_UNSTABLE_API \ -D__GST_VALIDATE_PLUGIN libgstvalidateplugin_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) \ @@ -76,8 +73,7 @@ libgstvalidateplugin_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL libgstvalidateplugin_@GST_API_VERSION@_la_LIBADD = \ $(JSON_GLIB_CFLAGS) $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) \ $(GST_ALL_LIBS) $(GIO_LIBS) $(GST_PBUTILS_LIBS) \ - $(JSON_GLIB_LIBS) $(GLIB_LIBS) $(LIBM) $(UNWIND_LIBS) \ - $(DW_LIBS) + $(JSON_GLIB_LIBS) $(GLIB_LIBS) $(LIBM) CLEANFILES = diff --git a/validate/gst/validate/gst-validate-report.c b/validate/gst/validate/gst-validate-report.c index dac0ca4d1b..835c2a5afd 100644 --- a/validate/gst/validate/gst-validate-report.c +++ b/validate/gst/validate/gst-validate-report.c @@ -25,13 +25,6 @@ # include "config.h" #endif -#ifdef HAVE_UNWIND -/* No need for remote debugging so turn on the 'local only' optimizations in - * libunwind */ -#define UNW_LOCAL_ONLY -#include -#endif /* HAVE_UNWIND */ - #include /* fprintf */ #include @@ -58,141 +51,6 @@ GOutputStream *server_ostream = NULL; GType _gst_validate_report_type = 0; -#ifdef HAVE_UNWIND -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_DW -#include -#include -static void -append_debug_info (GString * trace, const void *ip) -{ - - char *debuginfo_path = NULL; - Dwarf_Addr addr; - Dwfl_Module *module; - const char *function_name; - Dwfl_Line *line; - - Dwfl_Callbacks callbacks = { - .find_elf = dwfl_linux_proc_find_elf, - .find_debuginfo = dwfl_standard_find_debuginfo, - .debuginfo_path = &debuginfo_path, - }; - - Dwfl *dwfl = dwfl_begin (&callbacks); - - assert (dwfl != NULL); - - assert (dwfl_linux_proc_report (dwfl, getpid ()) == 0); - assert (dwfl_report_end (dwfl, NULL, NULL) == 0); - - addr = (uintptr_t) ip; - - module = dwfl_addrmodule (dwfl, addr); - - function_name = dwfl_module_addrname (module, addr); - - g_string_append_printf (trace, "%s(", function_name ? function_name : "??"); - - line = dwfl_getsrc (dwfl, addr); - if (line != NULL) { - int nline; - Dwarf_Addr addr; - const char *filename = dwfl_lineinfo (line, &addr, - &nline, NULL, NULL, NULL); - g_string_append_printf (trace, "%s:%d", strrchr (filename, '/') + 1, nline); - } else { - const gchar *eflfile = NULL; - - dwfl_module_info (module, NULL, NULL, NULL, NULL, NULL, &eflfile, NULL); - g_string_append_printf (trace, "%s:%p", eflfile ? eflfile : "??", ip); - } -} -#endif - -static gchar * -generate_unwind_trace (void) -{ - unw_context_t uc; - unw_cursor_t cursor; - GString *trace = g_string_new (NULL); - - unw_getcontext (&uc); - unw_init_local (&cursor, &uc); - - while (unw_step (&cursor) > 0) { -#ifdef HAVE_DW - unw_word_t ip; - - unw_get_reg (&cursor, UNW_REG_IP, &ip); - append_debug_info (trace, (void *) (ip - 4)); - g_string_append (trace, ")\n"); -#else - char name[32]; - - unw_word_t offset; - unw_get_proc_name (&cursor, name, sizeof (name), &offset); - g_string_append_printf (trace, "%s (0x%lx)\n", name, (long) offset); -#endif - } - - return g_string_free (trace, FALSE); -} - -#endif /* HAVE_UNWIND */ - -#ifdef HAVE_BACKTRACE -#include -#define BT_BUF_SIZE 100 -static gchar * -generate_backtrace_trace (void) -{ - int j, nptrs; - void *buffer[BT_BUF_SIZE]; - char **strings; - GString *trace; - - trace = g_string_new (NULL); - nptrs = backtrace (buffer, BT_BUF_SIZE); - - strings = backtrace_symbols (buffer, nptrs); - - if (!strings) - return NULL; - - for (j = 0; j < nptrs; j++) - g_string_append_printf (trace, "%s\n", strings[j]); - - return g_string_free (trace, FALSE); -} -#endif /* HAVE_BACKTRACE */ - -static gchar * -generate_trace (void) -{ - gchar *trace = NULL; - -#ifdef HAVE_UNWIND - trace = generate_unwind_trace (); - if (trace) - return trace; -#endif /* HAVE_UNWIND */ - -#ifdef HAVE_BACKTRACE - trace = generate_backtrace_trace (); -#endif /* HAVE_BACKTRACE */ - - - return trace; -} - static JsonNode * gst_validate_report_serialize (GstValidateReport * report) { @@ -841,7 +699,7 @@ gst_validate_report_new (GstValidateIssue * issue, issue_type_details == GST_VALIDATE_SHOW_ALL || gst_validate_report_check_abort (report) || report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) - report->trace = generate_trace (); + report->trace = gst_debug_get_stack_trace (); return report; } diff --git a/validate/gst/validate/meson.build b/validate/gst/validate/meson.build index 976922ba64..7bd283a584 100644 --- a/validate/gst/validate/meson.build +++ b/validate/gst/validate/meson.build @@ -46,8 +46,7 @@ gstvalidate = shared_library('gstvalidate-1.0', install: true, c_args : [gst_c_args] + ['-D_GNU_SOURCE'], dependencies : [gst_dep, glib_dep, gio_dep, gmodule_dep, - gst_pbutils_dep, mathlib, json_dep, - unwind_dep, dw_dep]) + gst_pbutils_dep, mathlib, json_dep]) gstvalidate = shared_library('gstvalidateplugin', sources: gstvalidate_sources, @@ -56,8 +55,7 @@ gstvalidate = shared_library('gstvalidateplugin', c_args : [gst_c_args] + ['-D__GST_VALIDATE_PLUGIN', '-D_GNU_SOURCE'], install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')), dependencies : [gst_dep, glib_dep, gio_dep, gmodule_dep, - gst_pbutils_dep, mathlib, json_dep, unwind_dep, - dw_dep]) + gst_pbutils_dep, mathlib, json_dep]) validate_gen_sources = [] if build_gir diff --git a/validate/meson.build b/validate/meson.build index 96a17d7512..e6bdc559b6 100644 --- a/validate/meson.build +++ b/validate/meson.build @@ -2,24 +2,6 @@ inc_dirs = include_directories('.') cdata = configuration_data() -unwind_dep = dependency('libunwind', required : false) -dw_dep = dependency('libdw', required: false) -if unwind_dep.found() - cdata.set('HAVE_UNWIND', 1) - if dw_dep.found() - cdata.set('HAVE_DW', 1) - else - message('Support for backtraces is partial only.') - endif -else - if cc.has_function('backtrace') - cdata.set('HAVE_BACKTRACE', 1) - else - message('NO backtraces support.') - endif -endif - - cdata.set('GST_LICENSE', '"LGPL"') cdata.set('VERSION', '"@0@"'.format(gst_version)) cdata.set('PACKAGE', '"gst-validate"') @@ -30,9 +12,7 @@ cdata.set('VALIDATEPLUGINDIR', '"@0@/@1@/gstreamer-1.0/validate"'.format(get_opt cdata.set('GST_DATADIR', '"@0@/@1@"'.format(prefix, get_option('datadir'))) cdata.set('PACKAGE_NAME', '"GStreamer Validate"') cdata.set('PACKAGE_VERSION', '"@0@"'.format(gst_version)) -configure_file(input : 'config.h.meson', - output : 'config.h', - configuration : cdata) +configure_file(output : 'config.h', configuration : cdata) subdir('data') subdir('gst')