X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fuserspace-probe.c;h=b6e5083a2907c35836c4b856882004b669feee5b;hp=89066bf0549a553df0564528d450a7763910ccc0;hb=14c4262b940630bbb75f68b8c2eaef2b134a62d9;hpb=87597c2c3bbaa1502ad2025cbf16704829f3b464 diff --git a/src/common/userspace-probe.c b/src/common/userspace-probe.c index 89066bf05..b6e5083a2 100644 --- a/src/common/userspace-probe.c +++ b/src/common/userspace-probe.c @@ -38,26 +38,7 @@ void lttng_userspace_probe_location_lookup_method_destroy( return; } - switch (lookup_method->type) { - case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF: - { - struct lttng_userspace_probe_location_lookup_method_elf *elf_method = - container_of(lookup_method, - struct lttng_userspace_probe_location_lookup_method_elf, parent); - free(elf_method); - break; - } - case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT: - { - struct lttng_userspace_probe_location_lookup_method_sdt *sdt_method = - container_of(lookup_method, - struct lttng_userspace_probe_location_lookup_method_sdt, parent); - free(sdt_method); - break; - } - default: - break; - } + free(lookup_method); } struct lttng_userspace_probe_location_lookup_method * @@ -169,7 +150,7 @@ void lttng_userspace_probe_location_destroy( lttng_userspace_probe_location_tracepoint_destroy(location); break; default: - free(location); + abort(); } } @@ -215,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; @@ -293,6 +276,7 @@ lttng_userspace_probe_location_tracepoint_create_no_check(const char *binary_pat error: free(probe_name_copy); free(provider_name_copy); + free(binary_path_copy); if (binary_fd >= 0) { if (close(binary_fd)) { PERROR("Error closing binary fd in error path"); @@ -419,32 +403,35 @@ lttng_userspace_probe_location_function_copy( enum lttng_userspace_probe_location_lookup_method_type lookup_type; struct lttng_userspace_probe_location *new_location = NULL; struct lttng_userspace_probe_location_lookup_method *lookup_method = NULL; - char *binary_path = NULL; - char *function_name = NULL; - int fd; + const char *binary_path = NULL; + const char *function_name = NULL; + int fd, new_fd; assert(location); assert(location->type == LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION); - /* Duplicate probe location fields */ - binary_path = - lttng_strndup(lttng_userspace_probe_location_function_get_binary_path(location), - LTTNG_PATH_MAX); + /* Get probe location fields */ + binary_path = lttng_userspace_probe_location_function_get_binary_path(location); if (!binary_path) { + ERR("Userspace probe binary path is NULL"); goto error; } - function_name = - lttng_strndup(lttng_userspace_probe_location_function_get_function_name(location), - LTTNG_SYMBOL_NAME_LEN); + function_name = lttng_userspace_probe_location_function_get_function_name(location); if (!function_name) { - PERROR("Error duplicating function name string"); + ERR("Userspace probe function name is NULL"); goto error; } /* Duplicate the binary fd */ - fd = dup(lttng_userspace_probe_location_function_get_binary_fd(location)); + fd = lttng_userspace_probe_location_function_get_binary_fd(location); if (fd == -1) { + ERR("Error getting file descriptor to binary"); + goto error; + } + + new_fd = dup(fd); + if (new_fd == -1) { PERROR("Error duplicating file descriptor to binary"); goto error; } @@ -470,13 +457,13 @@ lttng_userspace_probe_location_function_copy( /* Create the probe_location */ new_location = lttng_userspace_probe_location_function_create_no_check( - binary_path, function_name, lookup_method, true); + binary_path, function_name, lookup_method, false); if (!new_location) { goto destroy_lookup_method; } /* Set the duplicated fd to the new probe_location */ - if (lttng_userspace_probe_location_function_set_binary_fd(new_location, fd) < 0) { + if (lttng_userspace_probe_location_function_set_binary_fd(new_location, new_fd) < 0) { goto destroy_probe_location; } @@ -487,12 +474,10 @@ destroy_probe_location: destroy_lookup_method: lttng_userspace_probe_location_lookup_method_destroy(lookup_method); close_fd: - if (close(fd) < 0) { + if (close(new_fd) < 0) { PERROR("Error closing duplicated file descriptor in error path"); } error: - free(function_name); - free(binary_path); new_location = NULL; end: return new_location; @@ -505,43 +490,43 @@ lttng_userspace_probe_location_tracepoint_copy( enum lttng_userspace_probe_location_lookup_method_type lookup_type; struct lttng_userspace_probe_location *new_location = NULL; struct lttng_userspace_probe_location_lookup_method *lookup_method = NULL; - char *binary_path = NULL; - char *probe_name = NULL; - char *provider_name = NULL; - int fd; + const char *binary_path = NULL; + const char *probe_name = NULL; + const char *provider_name = NULL; + int fd, new_fd; assert(location); assert(location->type == LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT); - /* Duplicate probe location fields */ - binary_path = - lttng_strndup(lttng_userspace_probe_location_tracepoint_get_binary_path(location), - LTTNG_PATH_MAX); + /* Get probe location fields */ + binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path(location); if (!binary_path) { - PERROR("lttng_strndup"); + ERR("Userspace probe binary path is NULL"); goto error; } - probe_name = - lttng_strndup(lttng_userspace_probe_location_tracepoint_get_probe_name(location), - LTTNG_SYMBOL_NAME_LEN); + probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location); if (!probe_name) { - PERROR("lttng_strndup"); + ERR("Userspace probe probe name is NULL"); goto error; } - provider_name = - lttng_strndup(lttng_userspace_probe_location_tracepoint_get_provider_name(location), - LTTNG_SYMBOL_NAME_LEN); + provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location); if (!provider_name) { - PERROR("lttng_strndup"); + ERR("Userspace probe provider name is NULL"); goto error; } /* Duplicate the binary fd */ - fd = dup(lttng_userspace_probe_location_tracepoint_get_binary_fd(location)); + fd = lttng_userspace_probe_location_tracepoint_get_binary_fd(location); if (fd == -1) { - PERROR("dup"); + ERR("Error getting file descriptor to binary"); + goto error; + } + + new_fd = dup(fd); + if (new_fd == -1) { + PERROR("Error duplicating file descriptor to binary"); goto error; } @@ -566,13 +551,13 @@ lttng_userspace_probe_location_tracepoint_copy( /* Create the probe_location */ new_location = lttng_userspace_probe_location_tracepoint_create_no_check( - binary_path, provider_name, probe_name, lookup_method, true); + binary_path, provider_name, probe_name, lookup_method, false); if (!new_location) { goto destroy_lookup_method; } /* Set the duplicated fd to the new probe_location */ - if (lttng_userspace_probe_location_tracepoint_set_binary_fd(new_location, fd) < 0) { + if (lttng_userspace_probe_location_tracepoint_set_binary_fd(new_location, new_fd) < 0) { goto destroy_probe_location; } @@ -583,13 +568,10 @@ destroy_probe_location: destroy_lookup_method: lttng_userspace_probe_location_lookup_method_destroy(lookup_method); close_fd: - if (close(fd) < 0) { - PERROR("close"); + if (close(new_fd) < 0) { + PERROR("Error closing duplicated file descriptor in error path"); } error: - free(provider_name); - free(probe_name); - free(binary_path); new_location = NULL; end: return new_location; @@ -711,6 +693,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) {