X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fuprobe.cpp;h=c6a2d9429090f3ce2141f0fbdd66ecc51272ff75;hp=21b5e90e6b2bcc60173ab9954ac03c84084e3785;hb=HEAD;hpb=4971b7f0243bd3a7a661bcf1cfe95f0f8014b59b diff --git a/src/bin/lttng/uprobe.cpp b/src/bin/lttng/uprobe.cpp index 21b5e90e6..60fd5f619 100644 --- a/src/bin/lttng/uprobe.cpp +++ b/src/bin/lttng/uprobe.cpp @@ -5,20 +5,18 @@ * */ -#include "uprobe.h" +#include "command.hpp" +#include "common/compat/getenv.hpp" +#include "common/path.hpp" +#include "common/string-utils/string-utils.hpp" +#include "common/utils.hpp" +#include "lttng/constant.h" +#include "uprobe.hpp" -#include #include +#include #include -#include "common/compat/getenv.h" -#include "common/string-utils/string-utils.h" -#include "common/utils.h" -#include "common/path.h" -#include "lttng/constant.h" - -#include "command.h" - /* * Walk the directories in the PATH environment variable to find the target * binary passed as parameter. @@ -28,13 +26,12 @@ * LTTNG_PATH_MAX bytes long. * On failure, returns -1; */ -static -int walk_command_search_path(const char *binary, char *binary_full_path) +static int walk_command_search_path(const char *binary, char *binary_full_path) { - char *tentative_binary_path = NULL; - char *command_search_path = NULL; - char *curr_search_dir_end = NULL; - char *curr_search_dir = NULL; + char *tentative_binary_path = nullptr; + char *command_search_path = nullptr; + char *curr_search_dir_end = nullptr; + char *curr_search_dir = nullptr; struct stat stat_output; int ret = 0; @@ -58,7 +55,7 @@ int walk_command_search_path(const char *binary, char *binary_full_path) * This char array is used to concatenate path to binary to look for * the binary. */ - tentative_binary_path = (char *) zmalloc(LTTNG_PATH_MAX * sizeof(char)); + tentative_binary_path = calloc(LTTNG_PATH_MAX); if (!tentative_binary_path) { ret = -1; goto alloc_error; @@ -71,7 +68,7 @@ int walk_command_search_path(const char *binary, char *binary_full_path) * matching character. */ curr_search_dir_end = strchr(curr_search_dir, ':'); - if (curr_search_dir_end != NULL) { + if (curr_search_dir_end != nullptr) { /* * Add a NULL byte to the end of the first token so it * can be used as a string. @@ -86,14 +83,14 @@ int walk_command_search_path(const char *binary, char *binary_full_path) * Build the tentative path to the binary using the current * search directory and the name of the binary. */ - ret = snprintf(tentative_binary_path, LTTNG_PATH_MAX, "%s/%s", - curr_search_dir, binary); + ret = snprintf( + tentative_binary_path, LTTNG_PATH_MAX, "%s/%s", curr_search_dir, binary); if (ret < 0) { goto free_binary_path; } if (ret < LTTNG_PATH_MAX) { - /* - * Use STAT(2) to see if the file exists. + /* + * Use STAT(2) to see if the file exists. */ ret = stat(tentative_binary_path, &stat_output); if (ret == 0) { @@ -102,18 +99,17 @@ int walk_command_search_path(const char *binary, char *binary_full_path) * symlink and not a special file (e.g. * device). */ - if (S_ISREG(stat_output.st_mode) - || S_ISLNK(stat_output.st_mode)) { + if (S_ISREG(stat_output.st_mode) || S_ISLNK(stat_output.st_mode)) { /* * Found a match, set the out parameter * and return success. */ ret = lttng_strncpy(binary_full_path, - tentative_binary_path, - LTTNG_PATH_MAX); + tentative_binary_path, + LTTNG_PATH_MAX); if (ret == -1) { ERR("Source path does not fit " - "in destination buffer."); + "in destination buffer."); } goto free_binary_path; } @@ -121,7 +117,7 @@ int walk_command_search_path(const char *binary, char *binary_full_path) } /* Go to the next entry in the $PATH variable. */ curr_search_dir = curr_search_dir_end + 1; - } while (curr_search_dir_end != NULL); + } while (curr_search_dir_end != nullptr); free_binary_path: free(tentative_binary_path); @@ -144,8 +140,7 @@ end: * elf:/path/to/binary:my_symbol+0x323 * elf:/path/to/binary:my_symbol+43 */ -static -int warn_userspace_probe_syntax(const char *symbol) +static int warn_userspace_probe_syntax(const char *symbol) { int ret; @@ -197,16 +192,16 @@ error: * target_path to the path to the binary. */ int parse_userspace_probe_opts(const char *opt, - struct lttng_userspace_probe_location **probe_location) + struct lttng_userspace_probe_location **probe_location) { int ret = CMD_SUCCESS; size_t num_token = 0; - char *target_path = NULL; - char *unescaped_target_path = NULL; - char *real_target_path = NULL; - char *symbol_name = NULL, *probe_name = NULL, *provider_name = NULL; - struct lttng_userspace_probe_location *probe_location_local = NULL; - struct lttng_userspace_probe_location_lookup_method *lookup_method = NULL; + char *target_path = nullptr; + char *unescaped_target_path = nullptr; + char *real_target_path = nullptr; + char *symbol_name = nullptr, *probe_name = nullptr, *provider_name = nullptr; + struct lttng_userspace_probe_location *probe_location_local = nullptr; + struct lttng_userspace_probe_location_lookup_method *lookup_method = nullptr; struct lttng_dynamic_pointer_array tokens; LTTNG_ASSERT(opt); @@ -239,7 +234,9 @@ int parse_userspace_probe_opts(const char *opt, case 2: /* When the probe type is omitted we assume ELF for now. */ case 3: - if (num_token == 3 && strcmp((const char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0), "elf") == 0) { + if (num_token == 3 && + strcmp((const char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0), + "elf") == 0) { target_path = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 1); symbol_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 2); } else if (num_token == 2) { @@ -249,8 +246,7 @@ int parse_userspace_probe_opts(const char *opt, ret = CMD_ERROR; goto end; } - lookup_method = - lttng_userspace_probe_location_lookup_method_function_elf_create(); + lookup_method = lttng_userspace_probe_location_lookup_method_function_elf_create(); if (!lookup_method) { WARN("Failed to create ELF lookup method"); ret = CMD_ERROR; @@ -258,9 +254,11 @@ int parse_userspace_probe_opts(const char *opt, } break; case 4: - if (strcmp((const char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0), "sdt") == 0) { + if (strcmp((const char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 0), + "sdt") == 0) { target_path = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 1); - provider_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 2); + provider_name = + (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 2); probe_name = (char *) lttng_dynamic_pointer_array_get_pointer(&tokens, 3); } else { ret = CMD_ERROR; @@ -290,9 +288,9 @@ int parse_userspace_probe_opts(const char *opt, * If there is not forward slash in the path. Walk the $PATH else * expand. */ - if (strchr(unescaped_target_path, '/') == NULL) { + if (strchr(unescaped_target_path, '/') == nullptr) { /* Walk the $PATH variable to find the targeted binary. */ - real_target_path = (char *) zmalloc(LTTNG_PATH_MAX * sizeof(char)); + real_target_path = calloc(LTTNG_PATH_MAX); if (!real_target_path) { PERROR("Error allocating path buffer"); ret = CMD_ERROR; @@ -340,7 +338,7 @@ int parse_userspace_probe_opts(const char *opt, } probe_location_local = lttng_userspace_probe_location_function_create( - real_target_path, symbol_name, lookup_method); + real_target_path, symbol_name, lookup_method); if (!probe_location_local) { WARN("Failed to create function probe location"); ret = CMD_ERROR; @@ -348,11 +346,11 @@ int parse_userspace_probe_opts(const char *opt, } /* Ownership transferred to probe_location. */ - lookup_method = NULL; + lookup_method = nullptr; break; case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT: probe_location_local = lttng_userspace_probe_location_tracepoint_create( - real_target_path, provider_name, probe_name, lookup_method); + real_target_path, provider_name, probe_name, lookup_method); if (!probe_location_local) { WARN("Failed to create function probe location"); ret = CMD_ERROR; @@ -360,7 +358,7 @@ int parse_userspace_probe_opts(const char *opt, } /* Ownership transferred to probe_location. */ - lookup_method = NULL; + lookup_method = nullptr; break; default: ret = CMD_ERROR; @@ -372,7 +370,7 @@ int parse_userspace_probe_opts(const char *opt, * caller. */ *probe_location = probe_location_local; - probe_location_local = NULL; + probe_location_local = nullptr; end: lttng_userspace_probe_location_destroy(probe_location_local);