+ function_name = lttng_userspace_probe_location_function_get_function_name(location);
+ if (!function_name) {
+ ERR("Userspace probe function name is NULL");
+ goto error;
+ }
+
+ /*
+ * Duplicate probe location method fields
+ */
+ lookup_type = lttng_userspace_probe_location_lookup_method_get_type(
+ location->lookup_method);
+ switch (lookup_type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF:
+ lookup_method =
+ lttng_userspace_probe_location_lookup_method_function_elf_copy(
+ location->lookup_method);
+ if (!lookup_method) {
+ goto error;
+ }
+ break;
+ default:
+ /* Invalid probe location lookup method. */
+ goto error;
+ }
+
+ /* Create the probe_location */
+ new_location = lttng_userspace_probe_location_function_create_no_check(
+ 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_handle(new_location,
+ function_location->binary_fd_handle) < 0) {
+ goto destroy_probe_location;
+ }
+
+ goto end;
+
+destroy_probe_location:
+ lttng_userspace_probe_location_destroy(new_location);
+destroy_lookup_method:
+ lttng_userspace_probe_location_lookup_method_destroy(lookup_method);
+error:
+ new_location = NULL;
+end:
+ return new_location;
+}
+
+static struct lttng_userspace_probe_location *
+lttng_userspace_probe_location_tracepoint_copy(
+ const struct lttng_userspace_probe_location *location)
+{
+ 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;
+ const char *binary_path = NULL;
+ const char *probe_name = NULL;
+ const char *provider_name = NULL;
+ struct lttng_userspace_probe_location_tracepoint *tracepoint_location;
+
+ assert(location);
+ assert(location->type == LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT);
+ tracepoint_location = container_of(
+ location, typeof(*tracepoint_location), parent);
+
+ /* Get probe location fields */
+ binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path(location);
+ if (!binary_path) {
+ ERR("Userspace probe binary path is NULL");
+ goto error;
+ }
+
+ probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location);
+ if (!probe_name) {
+ ERR("Userspace probe probe name is NULL");
+ goto error;
+ }
+
+ provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location);
+ if (!provider_name) {
+ ERR("Userspace probe provider name is NULL");
+ goto error;
+ }
+
+ /*
+ * Duplicate probe location method fields
+ */
+ lookup_type = lttng_userspace_probe_location_lookup_method_get_type(
+ location->lookup_method);
+ switch (lookup_type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT:
+ lookup_method =
+ lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy(
+ location->lookup_method);
+ if (!lookup_method) {
+ goto error;
+ }
+ break;
+ default:
+ /* Invalid probe location lookup method. */
+ goto error;
+ }
+
+ /* Create the probe_location */
+ new_location = lttng_userspace_probe_location_tracepoint_create_no_check(
+ 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_handle(new_location,
+ tracepoint_location->binary_fd_handle) < 0) {
+ goto destroy_probe_location;
+ }
+
+ goto end;
+
+destroy_probe_location:
+ lttng_userspace_probe_location_destroy(new_location);
+destroy_lookup_method:
+ lttng_userspace_probe_location_lookup_method_destroy(lookup_method);
+error:
+ new_location = NULL;
+end:
+ return new_location;
+}
+
+const char *lttng_userspace_probe_location_function_get_binary_path(
+ const struct lttng_userspace_probe_location *location)
+{
+ const char *ret = NULL;
+ 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) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ function_location = container_of(location,
+ struct lttng_userspace_probe_location_function,
+ parent);
+ ret = function_location->binary_path;
+end:
+ return ret;
+}
+
+const char *lttng_userspace_probe_location_tracepoint_get_binary_path(
+ const struct lttng_userspace_probe_location *location)
+{
+ const char *ret = NULL;
+ struct lttng_userspace_probe_location_tracepoint *tracepoint_location;
+
+ if (!location || lttng_userspace_probe_location_get_type(location) !=
+ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT) {
+ ERR("Invalid argument(s) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ tracepoint_location = container_of(location,
+ struct lttng_userspace_probe_location_tracepoint,
+ parent);
+ ret = tracepoint_location->binary_path;
+end:
+ return ret;
+}
+
+const char *lttng_userspace_probe_location_function_get_function_name(
+ const struct lttng_userspace_probe_location *location)
+{
+ const char *ret = NULL;
+ 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) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ function_location = container_of(location,
+ struct lttng_userspace_probe_location_function, parent);
+ ret = function_location->function_name;
+end:
+ return ret;
+}
+
+const char *lttng_userspace_probe_location_tracepoint_get_probe_name(
+ const struct lttng_userspace_probe_location *location)
+{
+ const char *ret = NULL;
+ struct lttng_userspace_probe_location_tracepoint *tracepoint_location;
+
+ if (!location || lttng_userspace_probe_location_get_type(location) !=
+ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT) {
+ ERR("Invalid argument(s) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ tracepoint_location = container_of(location,
+ struct lttng_userspace_probe_location_tracepoint, parent);
+ ret = tracepoint_location->probe_name;
+end:
+ return ret;
+}
+
+const char *lttng_userspace_probe_location_tracepoint_get_provider_name(
+ const struct lttng_userspace_probe_location *location)
+{
+ const char *ret = NULL;
+ struct lttng_userspace_probe_location_tracepoint *tracepoint_location;
+
+ if (!location || lttng_userspace_probe_location_get_type(location) !=
+ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT) {
+ ERR("Invalid argument(s) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ tracepoint_location = container_of(location,
+ struct lttng_userspace_probe_location_tracepoint, parent);
+ ret = tracepoint_location->provider_name;
+end:
+ return ret;
+}
+
+int lttng_userspace_probe_location_function_get_binary_fd(
+ const struct lttng_userspace_probe_location *location)
+{
+ int ret = -1;
+ 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) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ function_location = container_of(location,
+ struct lttng_userspace_probe_location_function, parent);
+ ret = function_location->binary_fd_handle ?
+ fd_handle_get_fd(function_location->binary_fd_handle) : -1;
+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) passed to '%s'", __FUNCTION__);
+ 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) passed to '%s'", __FUNCTION__);
+ 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)
+{
+ int ret = -1;
+ struct lttng_userspace_probe_location_tracepoint *tracepoint_location;
+
+ if (!location || lttng_userspace_probe_location_get_type(location) !=
+ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT) {
+ ERR("Invalid argument(s) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ tracepoint_location = container_of(location,
+ struct lttng_userspace_probe_location_tracepoint, parent);
+ ret = tracepoint_location->binary_fd_handle ?
+ fd_handle_get_fd(tracepoint_location->binary_fd_handle) : -1;
+end:
+ return ret;
+}
+
+static struct lttng_userspace_probe_location_lookup_method *
+lttng_userspace_probe_location_function_get_lookup_method(
+ const struct lttng_userspace_probe_location *location)
+{
+ struct lttng_userspace_probe_location_lookup_method *ret = NULL;
+
+ if (!location || lttng_userspace_probe_location_get_type(location) !=
+ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION) {
+ ERR("Invalid argument(s) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ ret = location->lookup_method;
+end:
+ return ret;
+}
+
+static struct lttng_userspace_probe_location_lookup_method *
+lttng_userspace_probe_location_tracepoint_get_lookup_method(
+ const struct lttng_userspace_probe_location *location)
+{
+ struct lttng_userspace_probe_location_lookup_method *ret = NULL;
+
+ if (!location || lttng_userspace_probe_location_get_type(location) !=
+ LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT) {
+ ERR("Invalid argument(s) passed to '%s'", __FUNCTION__);
+ goto end;
+ }
+
+ ret = location->lookup_method;
+end:
+ return ret;
+}
+
+const struct lttng_userspace_probe_location_lookup_method *
+lttng_userspace_probe_location_get_lookup_method(
+ const struct lttng_userspace_probe_location *location)
+{
+ struct lttng_userspace_probe_location_lookup_method *ret = NULL;
+
+ assert(location);
+ switch (location->type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
+ ret = lttng_userspace_probe_location_function_get_lookup_method(
+ location);
+ break;
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
+ ret = lttng_userspace_probe_location_tracepoint_get_lookup_method(
+ location);
+ break;
+ default:
+ ERR("Unknowned lookup method.");
+ break;
+ }
+ return ret;
+}
+
+static
+int lttng_userspace_probe_location_lookup_method_serialize(
+ struct lttng_userspace_probe_location_lookup_method *method,
+ struct lttng_payload *payload)