+ /* Duplicate the binary fd */
+ fd = lttng_userspace_probe_location_tracepoint_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;
+ }
+
+ /*
+ * 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 close_fd;
+ }
+ break;
+ default:
+ /* Invalid probe location lookup method. */
+ goto close_fd;
+ }
+
+ /* 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(new_location, new_fd) < 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);
+close_fd:
+ if (close(new_fd) < 0) {
+ PERROR("Error closing duplicated file descriptor in error path");
+ }
+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)");
+ 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)");
+ 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)");
+ 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)");
+ 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)");
+ 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)");
+ goto end;