From: Pierre-Marc Fournier Date: Tue, 27 Oct 2009 21:33:04 +0000 (-0400) Subject: markers: save marker location in struct marker X-Git-Tag: v0.1~75 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3ea1e2fc7178db75f09e3d5630516858c8a783d5;p=ust.git markers: save marker location in struct marker This is for gdb static tracepoints. --- diff --git a/libust/marker.c b/libust/marker.c index 3152947..8b12019 100644 --- a/libust/marker.c +++ b/libust/marker.c @@ -43,6 +43,8 @@ extern struct marker __start___markers[] __attribute__((visibility("hidden"))); extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); +extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden"))); +extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden"))); /* Set to 1 to enable marker debug output */ static const int marker_debug; @@ -1496,15 +1498,22 @@ static void new_markers(struct marker *start, struct marker *end) } } -int marker_register_lib(struct marker *markers_start, int markers_count) +int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count) { struct lib *pl; + struct marker_addr *addr; pl = (struct lib *) malloc(sizeof(struct lib)); pl->markers_start = markers_start; + pl->markers_addr_start = marker_addr_start; pl->markers_count = markers_count; + lock_markers(); + for(addr = marker_addr_start; addr < marker_addr_start + markers_count; addr++) + addr->marker->location = addr->addr; + unlock_markers(); + /* FIXME: maybe protect this with its own mutex? */ lock_markers(); list_add(&pl->list, &libs); @@ -1533,8 +1542,8 @@ static int initialized = 0; void __attribute__((constructor)) init_markers(void) { if(!initialized) { - marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); - DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); + marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); + //DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers); initialized = 1; } } diff --git a/libust/marker.h b/libust/marker.h index 5fe50a9..246d174 100644 --- a/libust/marker.h +++ b/libust/marker.h @@ -31,6 +31,7 @@ #include "kernelcompat.h" #include #include "localerr.h" +#include "registers.h" //ust// struct module; //ust// struct task_struct; @@ -74,6 +75,7 @@ struct marker { struct marker_probe_closure *multi; const char *tp_name; /* Optional tracepoint name */ void *tp_cb; /* Optional tracepoint callback */ + void *location; /* Address of marker in code */ } __attribute__((aligned(8))); #define CONFIG_MARKERS @@ -91,7 +93,16 @@ struct marker { sizeof(#name)], \ 0, 0, 0, 0, marker_probe_cb, \ { __mark_empty_function, NULL}, \ - NULL, tp_name_str, tp_cb } + NULL, tp_name_str, tp_cb }; \ + asm (".section __marker_addr,\"aw\",@progbits\n\t" \ + _ASM_PTR "%c[marker_struct], (1f)\n\t" \ + ".previous\n\t" \ + "\n\t" \ + "1:\n\t" \ + :: [marker_struct] "i" (&__mark_##channel##_##name));\ + save_registers(®s) + + #define DEFINE_MARKER(channel, name, format) \ _DEFINE_MARKER(channel, name, NULL, NULL, format) @@ -287,24 +298,30 @@ extern int is_marker_enabled(const char *channel, const char *name); //ust// } //ust// #endif +struct marker_addr { + struct marker *marker; + void *addr; +}; struct lib { struct marker *markers_start; + struct marker_addr *markers_addr_start; int markers_count; struct list_head list; }; -extern 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) \ -{ \ - DBG("next registration in "__FILE__"\n");\ - marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\ +extern int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count); + +#define MARKER_LIB \ +extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \ +extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ +extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden"))); \ +extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden"))); \ + \ +static void __attribute__((constructor)) __markers__init(void) \ +{ \ + DBG("next registration in "__FILE__"\n"); \ + marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \ } extern void marker_set_new_marker_cb(void (*cb)(struct marker *)); diff --git a/libust/tracectl.c b/libust/tracectl.c index d4cd594..ed90257 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -117,7 +117,7 @@ static void print_markers(FILE *fp) marker_iter_start(&iter); while(iter.marker) { - fprintf(fp, "marker: %s/%s %d \"%s\"\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format); + fprintf(fp, "marker: %s/%s %d \"%s\" %p\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format, iter.marker->location); marker_iter_next(&iter); } unlock_markers(); @@ -837,7 +837,7 @@ static void auto_probe_connect(struct marker *m) if(result && result != -EEXIST) ERR("ltt_marker_connect (marker = %s/%s, errno = %d)", m->channel, m->name, -result); - DBG("auto connected marker %s %s to probe default", m->channel, m->name); + DBG("auto connected marker %s (addr: %p) %s to probe default", m->channel, m, m->name); }