From: Pierre-Marc Fournier Date: Tue, 17 Feb 2009 20:12:20 +0000 (-0500) Subject: ust: allow tracing of dynamically linked libraries X-Git-Tag: v1.9.1~1065 X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=c463904d75d0711fe6380ef0cda4ed07e6f7f969;p=lttng-ust.git ust: allow tracing of dynamically linked libraries - this also includes being able to link libmarkers dynamically - a special init function must be added via the MARKER_LIB macro --- diff --git a/hello/Makefile b/hello/Makefile index eeb43fdb..57cc8f2b 100644 --- a/hello/Makefile +++ b/hello/Makefile @@ -2,9 +2,9 @@ all: hello hello: hello.c #dynamic version -# gcc -g -I../libmarkers -I../share -I../libtracing -L../libmarkers -lmarkers -L../libtracectl -ltracectl -L../libtracing -ltracing -o hello hello.c marker-control.c serialize.c -static + gcc -g -Wl,--print-map -I../libmarkers -I../share -I../libtracing -L../libmarkers -lmarkers -L../libtracectl -ltracectl -L../libtracing -ltracing -o hello hello.c marker-control.c serialize.c #static version - gcc -g -I../libmarkers -I../share -I../libtracing -L../libmarkers -o hello hello.c marker-control.c serialize.c ../libtracing/*.c ../libmarkers/*.c ../libtracectl/*.c ../share/*.c +# gcc -g -I../libmarkers -I../share -I../libtracing -L../libmarkers -o hello hello.c marker-control.c serialize.c ../libtracing/*.c ../libmarkers/*.c ../libtracectl/*.c ../share/*.c clean: rm -rf hello *.o diff --git a/hello/hello.c b/hello/hello.c index d6750d06..ee7992b0 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -204,6 +204,11 @@ int main() printf("page size is %d\n", sysconf(_SC_PAGE_SIZE)); +// extern struct marker __start___markers[] __attribute__((visibility("hidden"))); +// extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); +// +// printf("the executable's markers start at %lx and end at %lx, the size of a marker is %d\n", __start___markers, __stop___markers, sizeof(struct marker)); + marker_control_init(); //marker_probe_register("abc", "testmark", "", probe, NULL); @@ -268,3 +273,5 @@ int main() return 0; } + +MARKER_LIB diff --git a/libmarkers/marker.c b/libmarkers/marker.c index d31f2cfa..139b4327 100644 --- a/libmarkers/marker.c +++ b/libmarkers/marker.c @@ -37,8 +37,8 @@ #include "tracercore.h" #include "tracer.h" -extern struct marker __start___markers[]; -extern struct marker __stop___markers[]; +extern struct marker __start___markers[] __attribute__((visibility("hidden"))); +extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); /* Set to 1 to enable marker debug output */ static const int marker_debug; @@ -705,9 +705,10 @@ void marker_update_probe_range(struct marker *begin, static void marker_update_probes(void) { /* Core kernel markers */ - marker_update_probe_range(__start___markers, __stop___markers); +//ust// marker_update_probe_range(__start___markers, __stop___markers); /* Markers in modules. */ //ust// module_update_markers(); + lib_update_markers(); //ust// tracepoint_probe_update_all(); /* Update immediate values */ core_imv_update(); @@ -1062,6 +1063,7 @@ static void marker_get_iter(struct marker_iter *iter) /* Core kernel markers */ if (!iter->lib) { + /* ust FIXME: how come we cannot disable the following line? we shouldn't need core stuff */ found = marker_get_iter_range(&iter->marker, __start___markers, __stop___markers); if (found) @@ -1443,6 +1445,17 @@ int lib_get_iter_markers(struct marker_iter *iter) return found; } +void lib_update_markers(void) +{ + struct lib *lib; + +//ust// mutex_lock(&module_mutex); + list_for_each_entry(lib, &libs, list) + marker_update_probe_range(lib->markers_start, + lib->markers_start + lib->markers_count); +//ust// mutex_unlock(&module_mutex); +} + int marker_register_lib(struct marker *markers_start, int markers_count) { struct lib *pl; @@ -1458,3 +1471,9 @@ int marker_register_lib(struct marker *markers_start, int markers_count) return 0; } + +static void __attribute__((constructor)) __markers__init(void) +{ + marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); + printf("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); +} diff --git a/libmarkers/marker.h b/libmarkers/marker.h index f26bcac0..b83ff65e 100644 --- a/libmarkers/marker.h +++ b/libmarkers/marker.h @@ -282,5 +282,15 @@ struct lib { struct list_head list; }; +int marker_register_lib(struct marker *markers_start, int markers_count); + +#define MARKER_LIB \ +extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \ +extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ + \ +static void __attribute__((constructor)) __markers__init(void) \ +{ \ + marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\ +} #endif