+
+LTTNG_HIDDEN
+bool lttng_userspace_probe_location_lookup_method_is_equal(
+ const struct lttng_userspace_probe_location_lookup_method *a,
+ const struct lttng_userspace_probe_location_lookup_method *b)
+{
+ bool is_equal = false;
+
+ if (!a || !b) {
+ goto end;
+ }
+
+ if (a == b) {
+ is_equal = true;
+ goto end;
+ }
+
+ if (a->type != b->type) {
+ goto end;
+ }
+
+ is_equal = true;
+end:
+ return is_equal;
+}
+
+LTTNG_HIDDEN
+bool lttng_userspace_probe_location_is_equal(
+ const struct lttng_userspace_probe_location *a,
+ const struct lttng_userspace_probe_location *b)
+{
+ bool is_equal = false;
+
+ if (!a || !b) {
+ goto end;
+ }
+
+ if (a == b) {
+ is_equal = true;
+ goto end;
+ }
+
+ if (!lttng_userspace_probe_location_lookup_method_is_equal(
+ a->lookup_method, b->lookup_method)) {
+ goto end;
+ }
+
+ if (a->type != b->type) {
+ goto end;
+ }
+
+ is_equal = a->equal ? a->equal(a, b) : true;
+end:
+ return is_equal;
+}
+
+LTTNG_HIDDEN
+unsigned long lttng_userspace_probe_location_hash(
+ const struct lttng_userspace_probe_location *location)
+{
+ return location->hash(location);
+}
+
+LTTNG_HIDDEN
+enum lttng_error_code lttng_userspace_probe_location_mi_serialize(
+ const struct lttng_userspace_probe_location *location,
+ struct mi_writer *writer)
+{
+ typedef enum lttng_error_code (*mi_fp)(
+ const struct lttng_userspace_probe_location *,
+ struct mi_writer *);
+
+ int ret;
+ enum lttng_error_code ret_code;
+ mi_fp mi_function = NULL;
+
+ assert(location);
+ assert(writer);
+
+ switch (lttng_userspace_probe_location_get_type(location)) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
+ mi_function = lttng_userspace_probe_location_function_mi_serialize;
+ break;
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
+ mi_function = lttng_userspace_probe_location_tracepoint_mi_serialize;
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ /* Open userspace probe location element. */
+ ret = mi_lttng_writer_open_element(
+ writer, mi_lttng_element_userspace_probe_location);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Underlying user space probe location. */
+ ret_code = mi_function(location, writer);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
+
+ /* Close userspace probe location element. */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto mi_error;
+ }
+
+ ret_code = LTTNG_OK;
+ goto end;
+
+mi_error:
+ ret_code = LTTNG_ERR_MI_IO_FAIL;
+end:
+ return ret_code;
+}
+
+enum lttng_error_code lttng_userspace_probe_location_lookup_method_mi_serialize(
+ const struct lttng_userspace_probe_location_lookup_method
+ *method,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ const char *type_element_str;
+
+ assert(method);
+ assert(writer);
+
+ switch (lttng_userspace_probe_location_lookup_method_get_type(method)) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT:
+ type_element_str =
+ mi_lttng_element_userspace_probe_location_lookup_method_function_default;
+ break;
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF:
+ type_element_str =
+ mi_lttng_element_userspace_probe_location_lookup_method_function_elf;
+ break;
+ case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT:
+ type_element_str =
+ mi_lttng_element_userspace_probe_location_lookup_method_tracepoint_sdt;
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ /* Open userspace probe location lookup method element. */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_userspace_probe_location_lookup_method);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* User space probe location lookup method empty element. */
+ ret = mi_lttng_writer_open_element(writer, type_element_str);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Close userspace probe location lookup method element. */
+ ret = mi_lttng_close_multi_element(writer, 2);
+ if (ret) {
+ goto mi_error;
+ }
+
+ ret_code = LTTNG_OK;
+ goto end;
+
+mi_error:
+ ret_code = LTTNG_ERR_MI_IO_FAIL;
+end:
+ return ret_code;
+}
+
+static enum lttng_error_code lttng_userspace_probe_location_tracepoint_mi_serialize(
+ const struct lttng_userspace_probe_location *location,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ const char *probe_name = NULL;
+ const char *provider_name = NULL;
+ const char *binary_path = NULL;
+ const struct lttng_userspace_probe_location_lookup_method
+ *lookup_method = NULL;
+
+ assert(location);
+ assert(writer);
+
+ probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(
+ location);
+ provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(
+ location);
+ binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path(
+ location);
+ lookup_method = lttng_userspace_probe_location_tracepoint_get_lookup_method(
+ location);
+
+ /* Open userspace probe location tracepoint element. */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_userspace_probe_location_tracepoint);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Probe name. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_userspace_probe_location_tracepoint_probe_name,
+ probe_name);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Provider name. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_userspace_probe_location_tracepoint_provider_name,
+ provider_name);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Binary path. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_userspace_probe_location_binary_path,
+ binary_path);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* The lookup method. */
+ ret_code = lttng_userspace_probe_location_lookup_method_mi_serialize(
+ lookup_method, writer);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
+
+ /* Close userspace probe location tracepoint. */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto mi_error;
+ }
+
+ ret_code = LTTNG_OK;
+ goto end;
+
+mi_error:
+ ret_code = LTTNG_ERR_MI_IO_FAIL;
+end:
+ return ret_code;
+}
+
+static enum lttng_error_code lttng_userspace_probe_location_function_mi_serialize(
+ const struct lttng_userspace_probe_location *location,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ const char *function_name = NULL;
+ const char *binary_path = NULL;
+ const char *instrumentation_type_str = NULL;
+ enum lttng_userspace_probe_location_function_instrumentation_type
+ instrumentation_type;
+ const struct lttng_userspace_probe_location_lookup_method
+ *lookup_method = NULL;
+
+ assert(location);
+ assert(writer);
+
+ function_name = lttng_userspace_probe_location_function_get_function_name(
+ location);
+ binary_path = lttng_userspace_probe_location_function_get_binary_path(
+ location);
+ instrumentation_type =
+ lttng_userspace_probe_location_function_get_instrumentation_type(
+ location);
+ lookup_method = lttng_userspace_probe_location_function_get_lookup_method(
+ location);
+
+ switch (instrumentation_type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY:
+ instrumentation_type_str =
+ mi_lttng_userspace_probe_location_function_instrumentation_type_entry;
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ /* Open userspace probe location function element. */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_userspace_probe_location_function);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Function name. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_userspace_probe_location_function_name,
+ function_name);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Binary path. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_userspace_probe_location_binary_path,
+ binary_path);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Instrumentation type. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_userspace_probe_location_function_instrumentation_type,
+ instrumentation_type_str);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* The lookup method. */
+ ret_code = lttng_userspace_probe_location_lookup_method_mi_serialize(
+ lookup_method, writer);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
+
+ /* Close userspace probe location function element. */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto mi_error;
+ }
+
+ ret_code = LTTNG_OK;
+ goto end;
+
+mi_error:
+ ret_code = LTTNG_ERR_MI_IO_FAIL;
+end:
+ return ret_code;
+}