+
+static struct lttng_kernel_probe_location *
+lttng_kernel_probe_location_symbol_copy(
+ const struct lttng_kernel_probe_location *location)
+{
+ struct lttng_kernel_probe_location *new_location = NULL;
+ struct lttng_kernel_probe_location_symbol *symbol_location;
+ enum lttng_kernel_probe_location_status status;
+ const char *symbol_name = NULL;
+ uint64_t offset;
+
+ assert(location);
+ assert(location->type == LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET);
+ symbol_location = container_of(
+ location, typeof(*symbol_location), parent);
+
+ /* Get probe location offset */
+ status = lttng_kernel_probe_location_symbol_get_offset(location, &offset);
+ if (status != LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK) {
+ ERR("Get kernel probe location offset failed.");
+ goto error;
+ }
+
+ symbol_name = lttng_kernel_probe_location_symbol_get_name(location);
+ if (!symbol_name) {
+ ERR("Kernel probe symbol name is NULL.");
+ goto error;
+ }
+
+ /* Create the probe_location */
+ new_location = lttng_kernel_probe_location_symbol_create(
+ symbol_name, offset);
+
+ goto end;
+
+error:
+ new_location = NULL;
+end:
+ return new_location;
+}
+static struct lttng_kernel_probe_location *
+lttng_kernel_probe_location_address_copy(
+ const struct lttng_kernel_probe_location *location)
+{
+ struct lttng_kernel_probe_location *new_location = NULL;
+ struct lttng_kernel_probe_location_address *address_location;
+ enum lttng_kernel_probe_location_status status;
+ uint64_t address;
+
+ assert(location);
+ assert(location->type == LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS);
+ address_location = container_of(
+ location, typeof(*address_location), parent);
+
+
+ /* Get probe location fields */
+ status = lttng_kernel_probe_location_address_get_address(location, &address);
+ if (status != LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK) {
+ ERR("Get kernel probe address failed.");
+ goto error;
+ }
+
+ /* Create the probe_location */
+ new_location = lttng_kernel_probe_location_address_create(address);
+
+ goto end;
+
+error:
+ new_location = NULL;
+end:
+ return new_location;
+}
+
+LTTNG_HIDDEN
+struct lttng_kernel_probe_location *lttng_kernel_probe_location_copy(
+ const struct lttng_kernel_probe_location *location)
+{
+ struct lttng_kernel_probe_location *new_location = NULL;
+ enum lttng_kernel_probe_location_type type;
+
+ if (!location) {
+ goto err;
+ }
+
+ type = lttng_kernel_probe_location_get_type(location);
+ switch (type) {
+ case LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS:
+ new_location =
+ lttng_kernel_probe_location_address_copy(location);
+ if (!new_location) {
+ goto err;
+ }
+ break;
+ case LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET:
+ new_location =
+ lttng_kernel_probe_location_symbol_copy(location);
+ if (!new_location) {
+ goto err;
+ }
+ break;
+ default:
+ new_location = NULL;
+ goto err;
+ }
+err:
+ return new_location;
+}
+
+LTTNG_HIDDEN
+unsigned long lttng_kernel_probe_location_hash(
+ const struct lttng_kernel_probe_location *location)
+{
+ return location->hash(location);
+}
+
+static
+enum lttng_error_code lttng_kernel_probe_location_address_mi_serialize(
+ const struct lttng_kernel_probe_location *location,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ enum lttng_kernel_probe_location_status status;
+ uint64_t address;
+
+ assert(location);
+ assert(writer);
+ assert(location->type == LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS);
+
+ status = lttng_kernel_probe_location_address_get_address(
+ location, &address);
+ assert(status == LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK);
+
+ /* Open kernel probe location address element. */
+ ret = mi_lttng_writer_open_element(
+ writer, mi_lttng_element_kernel_probe_location_address);
+ if (ret) {
+ goto mi_error;
+ }
+
+ ret = mi_lttng_writer_write_element_unsigned_int(writer,
+ mi_lttng_element_kernel_probe_location_address_address,
+ address);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Close kernel probe location address 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;
+}
+
+static
+enum lttng_error_code lttng_kernel_probe_location_symbol_mi_serialize(
+ const struct lttng_kernel_probe_location *location,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ enum lttng_kernel_probe_location_status status;
+ const char *name = NULL;
+ uint64_t offset;
+
+ assert(location);
+ assert(writer);
+ assert(location->type ==
+ LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET);
+
+ name = lttng_kernel_probe_location_symbol_get_name(location);
+ assert(name);
+
+ status = lttng_kernel_probe_location_symbol_get_offset(
+ location, &offset);
+ assert(status == LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK);
+
+ /* Open kernel probe location symbol offset element. */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_kernel_probe_location_symbol_offset);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Name. */
+ ret = mi_lttng_writer_write_element_string(writer,
+ mi_lttng_element_kernel_probe_location_symbol_offset_name,
+ name);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Offset. */
+ ret = mi_lttng_writer_write_element_unsigned_int(writer,
+ mi_lttng_element_kernel_probe_location_symbol_offset_offset,
+ offset);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Close kernel probe location symbol offset 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;
+}
+
+LTTNG_HIDDEN
+enum lttng_error_code lttng_kernel_probe_location_mi_serialize(
+ const struct lttng_kernel_probe_location *location,
+ struct mi_writer *writer)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+
+ assert(location);
+ assert(writer);
+
+ /* Open kernel probe location element. */
+ ret = mi_lttng_writer_open_element(
+ writer, mi_lttng_element_kernel_probe_location);
+ if (ret) {
+ goto mi_error;
+ }
+
+ /* Serialize the location sub type. */
+ ret_code = location->mi_serialize(location, writer);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
+
+ /* Close kernel 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;
+}