Add preload library for roundtrip spotting.

SVN revision: 47696
This commit is contained in:
Kim Woelders 2010-04-02 15:28:02 +00:00
parent 29a5b4489d
commit eb73aaf90a
4 changed files with 137 additions and 10 deletions

View File

@ -314,15 +314,22 @@ LDFLAGS="$SAVE_LDFLAGS"
AC_ARG_ENABLE(roothacklib,
[ --enable-roothacklib build window mode helper library @<:@default=yes@:>@],,
enable_roothacklib=yes)
if test "x$enable_roothacklib" = "xyes"; then
AC_CHECK_LIB(dl, dlopen, DLOPEN_LIBS=-ldl, enable_roothacklib=no)
enable_libhack=yes)
if test "x$enable_libhack" = "xyes"; then
AC_CHECK_LIB(dl, dlopen, DLOPEN_LIBS=-ldl, enable_libhack=no)
AC_SUBST(DLOPEN_LIBS)
fi
if test "x$enable_roothacklib" = "xyes"; then
AC_DEFINE(USE_ROOTHACKLIB, 1, [Use window mode helper library])
if test "x$enable_libhack" = "xyes"; then
AC_DEFINE(USE_LIBHACK, 1, [Use window mode helper library])
fi
AM_CONDITIONAL(BUILD_ROOTHACKLIB, test "x$enable_roothacklib" = "xyes")
AM_CONDITIONAL(BUILD_LIBHACK, test "x$enable_libhack" = "xyes")
AC_ARG_ENABLE(libtrip,
[ --enable-libtrip build debug library @<:@default=no@:>@],,
enable_libtrip=no)
AC_CHECK_HEADERS(execinfo.h,, enable_libtrip=no)
AC_CHECK_FUNCS(backtrace backtrace_symbols,, enable_libtrip=no)
AM_CONDITIONAL(BUILD_LIBTRIP, test "x$enable_libtrip" = "xyes")
AC_ARG_ENABLE(modules,
[ --enable-modules enable support for loadable modules @<:@default=no@:>@],,
@ -435,7 +442,7 @@ echo " Sync ......................... $enable_xsync"
echo " Composite .................... $enable_composite"
echo " Modules ...................... $enable_modules"
echo " Visibility hiding ............ $enable_visibility_hiding (only useful with modules)"
echo " Window mode helper library ... $enable_roothacklib"
echo " Window mode helper library ... $enable_libhack"
echo " Dialogs ...................... $enable_dialogs"
echo
echo "Experimental options - DO NOT USE unless you know what you are doing"

View File

@ -1,8 +1,10 @@
libe16dir = $(pkglibdir)
if BUILD_ROOTHACKLIB
libe16_LTLIBRARIES = $(LIB_HACK) $(LIB_TRIP)
libe16_LTLIBRARIES = libhack.la
if BUILD_LIBHACK
LIB_HACK = libhack.la
libhack_la_SOURCES = e16_hack.c
libhack_la_CPPFLAGS = -I$(top_srcdir)/src $(X_CFLAGS) $(CWARNFLAGS)
@ -11,3 +13,15 @@ libhack_la_LIBADD = $(DLOPEN_LIBS)
libhack_la_LDFLAGS = -avoid-version
endif
if BUILD_LIBTRIP
LIB_TRIP = libtrip.la
libtrip_la_SOURCES = e16_trip.c
libtrip_la_CPPFLAGS = -I$(top_srcdir)/src $(X_CFLAGS) $(CWARNFLAGS)
libtrip_la_LIBADD = $(DLOPEN_LIBS)
libtrip_la_LDFLAGS = -avoid-version
endif

106
lib/e16_trip.c Normal file
View File

@ -0,0 +1,106 @@
/*
* Copyright (C) 2010 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of the Software, its documentation and marketing & publicity
* materials, and acknowledgment shall be given in the documentation, materials
* and software packages that this Software was used.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Based on hack by raster - ecore_x/xlib/ecore_x.c.
*/
#include <dlfcn.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include "util.h"
typedef Status(RF) (Display * dpy, void *rep, int extra,
Bool discard);
/* find the real Xlib and the real X function */
static void *
GetFunc(const char *name)
{
void *lib_xlib;
void *func;
lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
func = dlsym(lib_xlib, name);
return func;
}
extern Status _XReply(Display * dpy, void *rep, int extra, Bool discard);
__EXPORT__ Status
_XReply(Display * dpy, void *rep, int extra, Bool discard)
{
static RF *func = NULL;
char s[1024], *p;
const char *name;
void *bt[128];
int i, n, l;
char **sym;
if (!func)
func = (RF *) GetFunc("_XReply");
l = 0;
l += snprintf(s + l, sizeof(s) - l, "RT: ");
n = backtrace(bt, 128);
if (n <= 0)
goto done;
sym = backtrace_symbols(bt, n);
if (!sym)
goto done;
for (i = 1; i < n; i++)
{
#if 1
name = strchr(sym[i], '(');
if (name)
{
name++;
p = strchr(name, '+');
if (!p)
p = strchr(name, ')');
if (p)
*p = '\0';
}
if (!name || *name == '\0')
name = "?";
l += snprintf(s + l, sizeof(s) - l, name);
#else
l += snprintf(s + l, sizeof(s) - l, sym[i]);
#endif
if (i < n - 1)
l += snprintf(s + l, sizeof(s) - l, " < ");
}
free(sym);
done:
printf("%s\n", s);
return func(dpy, rep, extra, discard);
}

View File

@ -58,7 +58,7 @@ ExecSetupEnv(int flags)
if (flags & EXEC_SET_STARTUP_ID)
StartupIdExport();
#if USE_ROOTHACKLIB
#if USE_LIBHACK
if (Mode.wm.window)
{
char buf[1024];