From: Jérémie Galarneau Date: Tue, 28 Aug 2018 23:05:25 +0000 (-0400) Subject: Add function instrumentation type accessors to function location type X-Git-Tag: v2.11.0-rc1~51 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9d3981b5c746b87954c46218b2c7c6e76ae7ed46;p=lttng-tools.git Add function instrumentation type accessors to function location type Since the uprobe instrumentation is currently limited to function entries, and since support for the instrumentation function return is planned to be introduced at some point, it makes sense to introduce an "instrumentation type" attribute on function locations. Currently, the only available instrumentation type is "entry", which matches what is supported by the kernel tracer as of 2.11. In the future, a RETURN and ENTRY_RETURN/BOTH instrumentation type could be added without changing the default behavior of rules such a userspace probe. Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/userspace-probe-internal.h b/include/lttng/userspace-probe-internal.h index 8708ec01c..909d56c53 100644 --- a/include/lttng/userspace-probe-internal.h +++ b/include/lttng/userspace-probe-internal.h @@ -102,6 +102,7 @@ struct lttng_userspace_probe_location_function { * Set to -1 if not open. */ int binary_fd; + enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type; }; struct lttng_userspace_probe_location_tracepoint { diff --git a/include/lttng/userspace-probe.h b/include/lttng/userspace-probe.h index 6b9036307..cedb7d8b8 100644 --- a/include/lttng/userspace-probe.h +++ b/include/lttng/userspace-probe.h @@ -69,9 +69,15 @@ lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create(void); */ struct lttng_userspace_probe_location; +enum lttng_userspace_probe_location_status { + LTTNG_USERSPACE_PROBE_LOCATION_STATUS_OK = 0, + /* Invalid parameters provided. */ + LTTNG_USERSPACE_PROBE_LOCATION_STATUS_INVALID = -1, +}; + enum lttng_userspace_probe_location_type { LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN = -1, - /* Function entry. */ + /* Function. */ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION = 0, /* SDT probe's callsites. */ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT = 1, @@ -90,6 +96,13 @@ lttng_userspace_probe_location_get_type( extern void lttng_userspace_probe_location_destroy( struct lttng_userspace_probe_location *location); + +enum lttng_userspace_probe_location_function_instrumentation_type { + LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_UNKNOWN = -1, + /* Only instrument the function's entry. */ + LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY = 0, +}; + /* * Create a probe location of the function type. * Receives the target binary file path and function to instrument. @@ -122,6 +135,27 @@ extern const char *lttng_userspace_probe_location_function_get_function_name( extern int lttng_userspace_probe_location_function_get_binary_fd( const struct lttng_userspace_probe_location *location); +/* + * Get the instrumentation type of the function probe location. + */ +extern enum lttng_userspace_probe_location_function_instrumentation_type +lttng_userspace_probe_location_function_get_instrumentation_type( + const struct lttng_userspace_probe_location *location); + +/* + * Get the instrumentation type of the function probe location. + * Defaults to + * LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY. + * + * Returns LTTNG_USERSPACE_PROBE_LOCATION_STATUS_OK on success, + * LTTNG_USERSPACE_PROBE_LOCATION_STATUS_INVALID if invalid parameters + * are provided. + */ +extern enum lttng_userspace_probe_location_status +lttng_userspace_probe_location_function_set_instrumentation_type( + const struct lttng_userspace_probe_location *location, + enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type); + /* * Get the lookup method of the given userspace probe location. * Returns NULL if the probe location type is unsupported. diff --git a/src/common/userspace-probe.c b/src/common/userspace-probe.c index 37bdcc7b1..7f038f5b5 100644 --- a/src/common/userspace-probe.c +++ b/src/common/userspace-probe.c @@ -196,6 +196,8 @@ lttng_userspace_probe_location_function_create_no_check(const char *binary_path, location->function_name = function_name_copy; location->binary_path = binary_path_copy; location->binary_fd = binary_fd; + location->instrumentation_type = + LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY; ret = &location->parent; ret->lookup_method = lookup_method; @@ -692,6 +694,52 @@ end: return ret; } +enum lttng_userspace_probe_location_function_instrumentation_type +lttng_userspace_probe_location_function_get_instrumentation_type( + const struct lttng_userspace_probe_location *location) +{ + enum lttng_userspace_probe_location_function_instrumentation_type type; + struct lttng_userspace_probe_location_function *function_location; + + if (!location || lttng_userspace_probe_location_get_type(location) != + LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION) { + ERR("Invalid argument(s)"); + type = LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_UNKNOWN; + goto end; + } + + function_location = container_of(location, + struct lttng_userspace_probe_location_function, parent); + type = function_location->instrumentation_type; +end: + return type; +} + +enum lttng_userspace_probe_location_status +lttng_userspace_probe_location_function_set_instrumentation_type( + const struct lttng_userspace_probe_location *location, + enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type) +{ + enum lttng_userspace_probe_location_status status = + LTTNG_USERSPACE_PROBE_LOCATION_STATUS_OK; + struct lttng_userspace_probe_location_function *function_location; + + if (!location || lttng_userspace_probe_location_get_type(location) != + LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION || + instrumentation_type != + LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY) { + ERR("Invalid argument(s)"); + status = LTTNG_USERSPACE_PROBE_LOCATION_STATUS_INVALID; + goto end; + } + + function_location = container_of(location, + struct lttng_userspace_probe_location_function, parent); + function_location->instrumentation_type = instrumentation_type; +end: + return status; +} + int lttng_userspace_probe_location_tracepoint_get_binary_fd( const struct lttng_userspace_probe_location *location) {