2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <common/error.h>
20 #include <common/macros.h>
21 #include <common/compat/string.h>
23 #include <lttng/constant.h>
24 #include <lttng/userspace-probe-internal.h>
26 enum lttng_userspace_probe_location_lookup_method_type
27 lttng_userspace_probe_location_lookup_method_get_type(
28 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
30 return lookup_method
? lookup_method
->type
:
31 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_UNKNOWN
;
34 void lttng_userspace_probe_location_lookup_method_destroy(
35 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
44 struct lttng_userspace_probe_location_lookup_method
*
45 lttng_userspace_probe_location_lookup_method_function_elf_create(void)
47 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
48 struct lttng_userspace_probe_location_lookup_method_elf
*elf_method
;
50 elf_method
= zmalloc(sizeof(*elf_method
));
56 ret
= &elf_method
->parent
;
57 ret
->type
= LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
;
62 struct lttng_userspace_probe_location_lookup_method
*
63 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create(void)
65 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
66 struct lttng_userspace_probe_location_lookup_method_sdt
*sdt_method
;
68 sdt_method
= zmalloc(sizeof(*sdt_method
));
74 ret
= &sdt_method
->parent
;
75 ret
->type
= LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
;
80 enum lttng_userspace_probe_location_type
lttng_userspace_probe_location_get_type(
81 const struct lttng_userspace_probe_location
*location
)
83 return location
? location
->type
:
84 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN
;
88 void lttng_userspace_probe_location_function_destroy(
89 struct lttng_userspace_probe_location
*location
)
91 struct lttng_userspace_probe_location_function
*location_function
= NULL
;
95 location_function
= container_of(location
,
96 struct lttng_userspace_probe_location_function
, parent
);
98 assert(location_function
);
100 free(location_function
->function_name
);
101 free(location_function
->binary_path
);
102 if (location_function
->binary_fd
>= 0) {
103 if (close(location_function
->binary_fd
)) {
111 void lttng_userspace_probe_location_tracepoint_destroy(
112 struct lttng_userspace_probe_location
*location
)
114 struct lttng_userspace_probe_location_tracepoint
*location_tracepoint
= NULL
;
118 location_tracepoint
= container_of(location
,
119 struct lttng_userspace_probe_location_tracepoint
,
122 assert(location_tracepoint
);
124 free(location_tracepoint
->probe_name
);
125 free(location_tracepoint
->provider_name
);
126 free(location_tracepoint
->binary_path
);
127 if (location_tracepoint
->binary_fd
>= 0) {
128 if (close(location_tracepoint
->binary_fd
)) {
135 void lttng_userspace_probe_location_destroy(
136 struct lttng_userspace_probe_location
*location
)
142 lttng_userspace_probe_location_lookup_method_destroy(
143 location
->lookup_method
);
145 switch (location
->type
) {
146 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
147 lttng_userspace_probe_location_function_destroy(location
);
149 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
150 lttng_userspace_probe_location_tracepoint_destroy(location
);
157 static struct lttng_userspace_probe_location
*
158 lttng_userspace_probe_location_function_create_no_check(const char *binary_path
,
159 const char *function_name
,
160 struct lttng_userspace_probe_location_lookup_method
*lookup_method
,
164 char *function_name_copy
= NULL
, *binary_path_copy
= NULL
;
165 struct lttng_userspace_probe_location
*ret
= NULL
;
166 struct lttng_userspace_probe_location_function
*location
;
169 binary_fd
= open(binary_path
, O_RDONLY
);
171 PERROR("Error opening the binary");
178 function_name_copy
= lttng_strndup(function_name
, LTTNG_SYMBOL_NAME_LEN
);
179 if (!function_name_copy
) {
180 PERROR("Error duplicating the function name");
184 binary_path_copy
= lttng_strndup(binary_path
, LTTNG_PATH_MAX
);
185 if (!binary_path_copy
) {
186 PERROR("Error duplicating the function name");
190 location
= zmalloc(sizeof(*location
));
192 PERROR("Error allocating userspace probe location");
196 location
->function_name
= function_name_copy
;
197 location
->binary_path
= binary_path_copy
;
198 location
->binary_fd
= binary_fd
;
199 location
->instrumentation_type
=
200 LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY
;
202 ret
= &location
->parent
;
203 ret
->lookup_method
= lookup_method
;
204 ret
->type
= LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
;
208 free(function_name_copy
);
209 free(binary_path_copy
);
210 if (binary_fd
>= 0) {
211 if (close(binary_fd
)) {
212 PERROR("Error closing binary fd in error path");
219 static struct lttng_userspace_probe_location
*
220 lttng_userspace_probe_location_tracepoint_create_no_check(const char *binary_path
,
221 const char *provider_name
, const char *probe_name
,
222 struct lttng_userspace_probe_location_lookup_method
*lookup_method
,
226 char *probe_name_copy
= NULL
;
227 char *provider_name_copy
= NULL
;
228 char *binary_path_copy
= NULL
;
229 struct lttng_userspace_probe_location
*ret
= NULL
;
230 struct lttng_userspace_probe_location_tracepoint
*location
;
233 binary_fd
= open(binary_path
, O_RDONLY
);
242 probe_name_copy
= lttng_strndup(probe_name
, LTTNG_SYMBOL_NAME_LEN
);
243 if (!probe_name_copy
) {
244 PERROR("lttng_strndup");
248 provider_name_copy
= lttng_strndup(provider_name
, LTTNG_SYMBOL_NAME_LEN
);
249 if (!provider_name_copy
) {
250 PERROR("lttng_strndup");
254 binary_path_copy
= lttng_strndup(binary_path
, LTTNG_PATH_MAX
);
255 if (!binary_path_copy
) {
256 PERROR("lttng_strndup");
260 location
= zmalloc(sizeof(*location
));
266 location
->probe_name
= probe_name_copy
;
267 location
->provider_name
= provider_name_copy
;
268 location
->binary_path
= binary_path_copy
;
269 location
->binary_fd
= binary_fd
;
271 ret
= &location
->parent
;
272 ret
->lookup_method
= lookup_method
;
273 ret
->type
= LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
;
277 free(probe_name_copy
);
278 free(provider_name_copy
);
279 free(binary_path_copy
);
280 if (binary_fd
>= 0) {
281 if (close(binary_fd
)) {
282 PERROR("Error closing binary fd in error path");
289 struct lttng_userspace_probe_location
*
290 lttng_userspace_probe_location_function_create(const char *binary_path
,
291 const char *function_name
,
292 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
294 struct lttng_userspace_probe_location
*ret
= NULL
;
296 if (!binary_path
|| !function_name
) {
297 ERR("Invalid argument(s)");
301 switch (lttng_userspace_probe_location_lookup_method_get_type(
303 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
304 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
307 /* Invalid probe location lookup method. */
311 ret
= lttng_userspace_probe_location_function_create_no_check(
312 binary_path
, function_name
, lookup_method
, true);
317 struct lttng_userspace_probe_location
*
318 lttng_userspace_probe_location_tracepoint_create(const char *binary_path
,
319 const char *provider_name
, const char *probe_name
,
320 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
322 struct lttng_userspace_probe_location
*ret
= NULL
;
324 if (!binary_path
|| !probe_name
|| !provider_name
) {
325 ERR("Invalid argument(s)");
329 switch (lttng_userspace_probe_location_lookup_method_get_type(
331 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
334 /* Invalid probe location lookup method. */
338 ret
= lttng_userspace_probe_location_tracepoint_create_no_check(
339 binary_path
, provider_name
, probe_name
, lookup_method
, true);
344 static struct lttng_userspace_probe_location_lookup_method
*
345 lttng_userspace_probe_location_lookup_method_function_elf_copy(
346 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
348 struct lttng_userspace_probe_location_lookup_method
*parent
= NULL
;
349 struct lttng_userspace_probe_location_lookup_method_elf
*elf_method
;
351 assert(lookup_method
);
352 assert(lookup_method
->type
==
353 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
);
355 elf_method
= zmalloc(sizeof(*elf_method
));
357 PERROR("Error allocating ELF userspace probe lookup method");
361 elf_method
->parent
.type
= lookup_method
->type
;
362 parent
= &elf_method
->parent
;
371 static struct lttng_userspace_probe_location_lookup_method
*
372 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy(
373 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
375 struct lttng_userspace_probe_location_lookup_method
*parent
= NULL
;
376 struct lttng_userspace_probe_location_lookup_method_sdt
*sdt_method
;
378 assert(lookup_method
);
379 assert(lookup_method
->type
==
380 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
);
382 sdt_method
= zmalloc(sizeof(*sdt_method
));
388 sdt_method
->parent
.type
= lookup_method
->type
;
389 parent
= &sdt_method
->parent
;
399 static struct lttng_userspace_probe_location
*
400 lttng_userspace_probe_location_function_copy(
401 const struct lttng_userspace_probe_location
*location
)
403 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
404 struct lttng_userspace_probe_location
*new_location
= NULL
;
405 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
406 const char *binary_path
= NULL
;
407 const char *function_name
= NULL
;
411 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
413 /* Get probe location fields */
414 binary_path
= lttng_userspace_probe_location_function_get_binary_path(location
);
416 ERR("Userspace probe binary path is NULL");
420 function_name
= lttng_userspace_probe_location_function_get_function_name(location
);
421 if (!function_name
) {
422 ERR("Userspace probe function name is NULL");
426 /* Duplicate the binary fd */
427 fd
= lttng_userspace_probe_location_function_get_binary_fd(location
);
429 ERR("Error getting file descriptor to binary");
435 PERROR("Error duplicating file descriptor to binary");
440 * Duplicate probe location method fields
442 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(
443 location
->lookup_method
);
444 switch (lookup_type
) {
445 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
447 lttng_userspace_probe_location_lookup_method_function_elf_copy(
448 location
->lookup_method
);
449 if (!lookup_method
) {
454 /* Invalid probe location lookup method. */
458 /* Create the probe_location */
459 new_location
= lttng_userspace_probe_location_function_create_no_check(
460 binary_path
, function_name
, lookup_method
, false);
462 goto destroy_lookup_method
;
465 /* Set the duplicated fd to the new probe_location */
466 if (lttng_userspace_probe_location_function_set_binary_fd(new_location
, new_fd
) < 0) {
467 goto destroy_probe_location
;
472 destroy_probe_location
:
473 lttng_userspace_probe_location_destroy(new_location
);
474 destroy_lookup_method
:
475 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
477 if (close(new_fd
) < 0) {
478 PERROR("Error closing duplicated file descriptor in error path");
486 static struct lttng_userspace_probe_location
*
487 lttng_userspace_probe_location_tracepoint_copy(
488 const struct lttng_userspace_probe_location
*location
)
490 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
491 struct lttng_userspace_probe_location
*new_location
= NULL
;
492 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
493 const char *binary_path
= NULL
;
494 const char *probe_name
= NULL
;
495 const char *provider_name
= NULL
;
499 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
501 /* Get probe location fields */
502 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(location
);
504 ERR("Userspace probe binary path is NULL");
508 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(location
);
510 ERR("Userspace probe probe name is NULL");
514 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(location
);
515 if (!provider_name
) {
516 ERR("Userspace probe provider name is NULL");
520 /* Duplicate the binary fd */
521 fd
= lttng_userspace_probe_location_tracepoint_get_binary_fd(location
);
523 ERR("Error getting file descriptor to binary");
529 PERROR("Error duplicating file descriptor to binary");
534 * Duplicate probe location method fields
536 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(
537 location
->lookup_method
);
538 switch (lookup_type
) {
539 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
541 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy(
542 location
->lookup_method
);
543 if (!lookup_method
) {
548 /* Invalid probe location lookup method. */
552 /* Create the probe_location */
553 new_location
= lttng_userspace_probe_location_tracepoint_create_no_check(
554 binary_path
, provider_name
, probe_name
, lookup_method
, false);
556 goto destroy_lookup_method
;
559 /* Set the duplicated fd to the new probe_location */
560 if (lttng_userspace_probe_location_tracepoint_set_binary_fd(new_location
, new_fd
) < 0) {
561 goto destroy_probe_location
;
566 destroy_probe_location
:
567 lttng_userspace_probe_location_destroy(new_location
);
568 destroy_lookup_method
:
569 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
571 if (close(new_fd
) < 0) {
572 PERROR("Error closing duplicated file descriptor in error path");
580 const char *lttng_userspace_probe_location_function_get_binary_path(
581 const struct lttng_userspace_probe_location
*location
)
583 const char *ret
= NULL
;
584 struct lttng_userspace_probe_location_function
*function_location
;
586 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
587 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
588 ERR("Invalid argument(s)");
592 function_location
= container_of(location
,
593 struct lttng_userspace_probe_location_function
,
595 ret
= function_location
->binary_path
;
600 const char *lttng_userspace_probe_location_tracepoint_get_binary_path(
601 const struct lttng_userspace_probe_location
*location
)
603 const char *ret
= NULL
;
604 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
606 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
607 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
608 ERR("Invalid argument(s)");
612 tracepoint_location
= container_of(location
,
613 struct lttng_userspace_probe_location_tracepoint
,
615 ret
= tracepoint_location
->binary_path
;
620 const char *lttng_userspace_probe_location_function_get_function_name(
621 const struct lttng_userspace_probe_location
*location
)
623 const char *ret
= NULL
;
624 struct lttng_userspace_probe_location_function
*function_location
;
626 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
627 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
628 ERR("Invalid argument(s)");
632 function_location
= container_of(location
,
633 struct lttng_userspace_probe_location_function
, parent
);
634 ret
= function_location
->function_name
;
639 const char *lttng_userspace_probe_location_tracepoint_get_probe_name(
640 const struct lttng_userspace_probe_location
*location
)
642 const char *ret
= NULL
;
643 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
645 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
646 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
647 ERR("Invalid argument(s)");
651 tracepoint_location
= container_of(location
,
652 struct lttng_userspace_probe_location_tracepoint
, parent
);
653 ret
= tracepoint_location
->probe_name
;
658 const char *lttng_userspace_probe_location_tracepoint_get_provider_name(
659 const struct lttng_userspace_probe_location
*location
)
661 const char *ret
= NULL
;
662 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
664 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
665 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
666 ERR("Invalid argument(s)");
670 tracepoint_location
= container_of(location
,
671 struct lttng_userspace_probe_location_tracepoint
, parent
);
672 ret
= tracepoint_location
->provider_name
;
677 int lttng_userspace_probe_location_function_get_binary_fd(
678 const struct lttng_userspace_probe_location
*location
)
681 struct lttng_userspace_probe_location_function
*function_location
;
683 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
684 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
685 ERR("Invalid argument(s)");
689 function_location
= container_of(location
,
690 struct lttng_userspace_probe_location_function
, parent
);
691 ret
= function_location
->binary_fd
;
696 enum lttng_userspace_probe_location_function_instrumentation_type
697 lttng_userspace_probe_location_function_get_instrumentation_type(
698 const struct lttng_userspace_probe_location
*location
)
700 enum lttng_userspace_probe_location_function_instrumentation_type type
;
701 struct lttng_userspace_probe_location_function
*function_location
;
703 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
704 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
705 ERR("Invalid argument(s)");
706 type
= LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_UNKNOWN
;
710 function_location
= container_of(location
,
711 struct lttng_userspace_probe_location_function
, parent
);
712 type
= function_location
->instrumentation_type
;
717 enum lttng_userspace_probe_location_status
718 lttng_userspace_probe_location_function_set_instrumentation_type(
719 const struct lttng_userspace_probe_location
*location
,
720 enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type
)
722 enum lttng_userspace_probe_location_status status
=
723 LTTNG_USERSPACE_PROBE_LOCATION_STATUS_OK
;
724 struct lttng_userspace_probe_location_function
*function_location
;
726 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
727 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
||
728 instrumentation_type
!=
729 LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY
) {
730 ERR("Invalid argument(s)");
731 status
= LTTNG_USERSPACE_PROBE_LOCATION_STATUS_INVALID
;
735 function_location
= container_of(location
,
736 struct lttng_userspace_probe_location_function
, parent
);
737 function_location
->instrumentation_type
= instrumentation_type
;
742 int lttng_userspace_probe_location_tracepoint_get_binary_fd(
743 const struct lttng_userspace_probe_location
*location
)
746 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
748 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
749 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
750 ERR("Invalid argument(s)");
754 tracepoint_location
= container_of(location
,
755 struct lttng_userspace_probe_location_tracepoint
, parent
);
756 ret
= tracepoint_location
->binary_fd
;
761 static struct lttng_userspace_probe_location_lookup_method
*
762 lttng_userspace_probe_location_function_get_lookup_method(
763 const struct lttng_userspace_probe_location
*location
)
765 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
767 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
768 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
769 ERR("Invalid argument(s)");
773 ret
= location
->lookup_method
;
778 static struct lttng_userspace_probe_location_lookup_method
*
779 lttng_userspace_probe_location_tracepoint_get_lookup_method(
780 const struct lttng_userspace_probe_location
*location
)
782 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
784 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
785 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
786 ERR("Invalid argument(s)");
790 ret
= location
->lookup_method
;
795 const struct lttng_userspace_probe_location_lookup_method
*
796 lttng_userspace_probe_location_get_lookup_method(
797 const struct lttng_userspace_probe_location
*location
)
799 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
802 switch (location
->type
) {
803 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
804 ret
= lttng_userspace_probe_location_function_get_lookup_method(
807 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
808 ret
= lttng_userspace_probe_location_tracepoint_get_lookup_method(
812 ERR("Unknowned lookup method.");
819 int lttng_userspace_probe_location_lookup_method_serialize(
820 struct lttng_userspace_probe_location_lookup_method
*method
,
821 struct lttng_dynamic_buffer
*buffer
)
824 struct lttng_userspace_probe_location_lookup_method_comm
827 lookup_method_comm
.type
= (int8_t) (method
? method
->type
:
828 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
);
830 ret
= lttng_dynamic_buffer_append(buffer
, &lookup_method_comm
,
831 sizeof(lookup_method_comm
));
836 ret
= sizeof(lookup_method_comm
);
842 int lttng_userspace_probe_location_function_serialize(
843 const struct lttng_userspace_probe_location
*location
,
844 struct lttng_dynamic_buffer
*buffer
,
848 size_t function_name_len
, binary_path_len
;
849 struct lttng_userspace_probe_location_function
*location_function
;
850 struct lttng_userspace_probe_location_function_comm location_function_comm
;
853 assert(lttng_userspace_probe_location_get_type(location
) ==
854 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
856 location_function
= container_of(location
,
857 struct lttng_userspace_probe_location_function
,
859 if (!location_function
->function_name
|| !location_function
->binary_path
) {
860 ret
= -LTTNG_ERR_INVALID
;
864 if (binary_fd
&& location_function
->binary_fd
< 0) {
865 ret
= -LTTNG_ERR_INVALID
;
870 *binary_fd
= location_function
->binary_fd
;
873 function_name_len
= strlen(location_function
->function_name
);
874 if (function_name_len
== 0) {
875 ret
= -LTTNG_ERR_INVALID
;
878 binary_path_len
= strlen(location_function
->binary_path
);
879 if (binary_path_len
== 0) {
880 ret
= -LTTNG_ERR_INVALID
;
884 location_function_comm
.function_name_len
= function_name_len
+ 1;
885 location_function_comm
.binary_path_len
= binary_path_len
+ 1;
888 ret
= lttng_dynamic_buffer_append(buffer
,
889 &location_function_comm
,
890 sizeof(location_function_comm
));
892 ret
= -LTTNG_ERR_INVALID
;
895 ret
= lttng_dynamic_buffer_append(buffer
,
896 location_function
->function_name
,
897 location_function_comm
.function_name_len
);
899 ret
= -LTTNG_ERR_INVALID
;
902 ret
= lttng_dynamic_buffer_append(buffer
,
903 location_function
->binary_path
,
904 location_function_comm
.binary_path_len
);
906 ret
= -LTTNG_ERR_INVALID
;
910 ret
= sizeof(location_function_comm
) +
911 location_function_comm
.function_name_len
+
912 location_function_comm
.binary_path_len
;
918 int lttng_userspace_probe_location_tracepoint_serialize(
919 const struct lttng_userspace_probe_location
*location
,
920 struct lttng_dynamic_buffer
*buffer
,
924 size_t probe_name_len
, provider_name_len
, binary_path_len
;
925 struct lttng_userspace_probe_location_tracepoint
*location_tracepoint
;
926 struct lttng_userspace_probe_location_tracepoint_comm location_tracepoint_comm
;
929 assert(lttng_userspace_probe_location_get_type(location
) ==
930 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
932 location_tracepoint
= container_of(location
,
933 struct lttng_userspace_probe_location_tracepoint
,
935 if (!location_tracepoint
->probe_name
||
936 !location_tracepoint
->provider_name
||
937 !location_tracepoint
->binary_path
) {
938 ret
= -LTTNG_ERR_INVALID
;
942 if (binary_fd
&& location_tracepoint
->binary_fd
< 0) {
943 ret
= -LTTNG_ERR_INVALID
;
948 *binary_fd
= location_tracepoint
->binary_fd
;
951 probe_name_len
= strlen(location_tracepoint
->probe_name
);
952 if (probe_name_len
== 0) {
953 ret
= -LTTNG_ERR_INVALID
;
957 provider_name_len
= strlen(location_tracepoint
->provider_name
);
958 if (provider_name_len
== 0) {
959 ret
= -LTTNG_ERR_INVALID
;
963 binary_path_len
= strlen(location_tracepoint
->binary_path
);
964 if (binary_path_len
== 0) {
965 ret
= -LTTNG_ERR_INVALID
;
969 location_tracepoint_comm
.probe_name_len
= probe_name_len
+ 1;
970 location_tracepoint_comm
.provider_name_len
= provider_name_len
+ 1;
971 location_tracepoint_comm
.binary_path_len
= binary_path_len
+ 1;
974 ret
= lttng_dynamic_buffer_append(buffer
,
975 &location_tracepoint_comm
,
976 sizeof(location_tracepoint_comm
));
978 ret
= -LTTNG_ERR_INVALID
;
981 ret
= lttng_dynamic_buffer_append(buffer
,
982 location_tracepoint
->probe_name
,
983 location_tracepoint_comm
.probe_name_len
);
985 ret
= -LTTNG_ERR_INVALID
;
988 ret
= lttng_dynamic_buffer_append(buffer
,
989 location_tracepoint
->provider_name
,
990 location_tracepoint_comm
.provider_name_len
);
992 ret
= -LTTNG_ERR_INVALID
;
995 ret
= lttng_dynamic_buffer_append(buffer
,
996 location_tracepoint
->binary_path
,
997 location_tracepoint_comm
.binary_path_len
);
999 ret
= -LTTNG_ERR_INVALID
;
1003 ret
= sizeof(location_tracepoint_comm
) +
1004 location_tracepoint_comm
.probe_name_len
+
1005 location_tracepoint_comm
.provider_name_len
+
1006 location_tracepoint_comm
.binary_path_len
;
1012 int lttng_userspace_probe_location_serialize(
1013 const struct lttng_userspace_probe_location
*location
,
1014 struct lttng_dynamic_buffer
*buffer
,
1017 int ret
, buffer_use
= 0;
1018 struct lttng_userspace_probe_location_comm location_generic_comm
;
1021 ERR("Invalid argument(s)");
1022 ret
= -LTTNG_ERR_INVALID
;
1026 memset(&location_generic_comm
, 0, sizeof(location_generic_comm
));
1028 location_generic_comm
.type
= (int8_t) location
->type
;
1030 ret
= lttng_dynamic_buffer_append(buffer
, &location_generic_comm
,
1031 sizeof(location_generic_comm
));
1036 buffer_use
+= sizeof(location_generic_comm
);
1038 switch (lttng_userspace_probe_location_get_type(location
)) {
1039 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1040 ret
= lttng_userspace_probe_location_function_serialize(
1041 location
, buffer
, binary_fd
);
1043 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1044 ret
= lttng_userspace_probe_location_tracepoint_serialize(
1045 location
, buffer
, binary_fd
);
1048 ERR("Unsupported probe location type");
1049 ret
= -LTTNG_ERR_INVALID
;
1057 ret
= lttng_userspace_probe_location_lookup_method_serialize(
1058 location
->lookup_method
, buffer
);
1068 int lttng_userspace_probe_location_function_create_from_buffer(
1069 const struct lttng_buffer_view
*buffer
,
1070 struct lttng_userspace_probe_location
**location
)
1072 struct lttng_userspace_probe_location_function_comm
*location_function_comm
;
1073 const char *function_name_src
, *binary_path_src
;
1074 char *function_name
= NULL
, *binary_path
= NULL
;
1078 assert(buffer
->data
);
1081 location_function_comm
=
1082 (struct lttng_userspace_probe_location_function_comm
*) buffer
->data
;
1084 const size_t expected_size
= sizeof(*location_function_comm
) +
1085 location_function_comm
->function_name_len
+
1086 location_function_comm
->binary_path_len
;
1088 if (buffer
->size
< expected_size
) {
1089 ret
= -LTTNG_ERR_INVALID
;
1093 function_name_src
= buffer
->data
+ sizeof(*location_function_comm
);
1094 binary_path_src
= function_name_src
+
1095 location_function_comm
->function_name_len
;
1097 if (function_name_src
[location_function_comm
->function_name_len
- 1] != '\0') {
1098 ret
= -LTTNG_ERR_INVALID
;
1101 if (binary_path_src
[location_function_comm
->binary_path_len
- 1] != '\0') {
1102 ret
= -LTTNG_ERR_INVALID
;
1106 function_name
= lttng_strndup(function_name_src
, LTTNG_SYMBOL_NAME_LEN
);
1107 if (!function_name
) {
1108 PERROR("lttng_strndup");
1112 binary_path
= lttng_strndup(binary_path_src
, LTTNG_PATH_MAX
);
1114 PERROR("lttng_strndup");
1118 *location
= lttng_userspace_probe_location_function_create_no_check(
1119 binary_path
, function_name
, NULL
, false);
1121 ret
= -LTTNG_ERR_INVALID
;
1125 ret
= (int) expected_size
;
1127 free(function_name
);
1133 int lttng_userspace_probe_location_tracepoint_create_from_buffer(
1134 const struct lttng_buffer_view
*buffer
,
1135 struct lttng_userspace_probe_location
**location
)
1137 struct lttng_userspace_probe_location_tracepoint_comm
*location_tracepoint_comm
;
1138 const char *probe_name_src
, *provider_name_src
, *binary_path_src
;
1139 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1143 assert(buffer
->data
);
1146 location_tracepoint_comm
=
1147 (struct lttng_userspace_probe_location_tracepoint_comm
*) buffer
->data
;
1149 const size_t expected_size
= sizeof(*location_tracepoint_comm
) +
1150 location_tracepoint_comm
->probe_name_len
+
1151 location_tracepoint_comm
->provider_name_len
+
1152 location_tracepoint_comm
->binary_path_len
;
1154 if (buffer
->size
< expected_size
) {
1155 ret
= -LTTNG_ERR_INVALID
;
1159 probe_name_src
= buffer
->data
+ sizeof(*location_tracepoint_comm
);
1160 provider_name_src
= probe_name_src
+
1161 location_tracepoint_comm
->probe_name_len
;
1162 binary_path_src
= provider_name_src
+
1163 location_tracepoint_comm
->provider_name_len
;
1165 if (probe_name_src
[location_tracepoint_comm
->probe_name_len
- 1] != '\0') {
1166 ret
= -LTTNG_ERR_INVALID
;
1170 if (provider_name_src
[location_tracepoint_comm
->provider_name_len
- 1] != '\0') {
1171 ret
= -LTTNG_ERR_INVALID
;
1175 if (binary_path_src
[location_tracepoint_comm
->binary_path_len
- 1] != '\0') {
1176 ret
= -LTTNG_ERR_INVALID
;
1180 probe_name
= lttng_strndup(probe_name_src
, LTTNG_SYMBOL_NAME_LEN
);
1182 PERROR("lttng_strndup");
1185 provider_name
= lttng_strndup(provider_name_src
, LTTNG_SYMBOL_NAME_LEN
);
1186 if (!provider_name
) {
1187 PERROR("lttng_strndup");
1191 binary_path
= lttng_strndup(binary_path_src
, LTTNG_SYMBOL_NAME_LEN
);
1193 PERROR("lttng_strndup");
1197 *location
= lttng_userspace_probe_location_tracepoint_create_no_check(
1198 binary_path
, provider_name
, probe_name
, NULL
, false);
1200 ret
= -LTTNG_ERR_INVALID
;
1204 ret
= (int) expected_size
;
1207 free(provider_name
);
1213 int lttng_userspace_probe_location_lookup_method_create_from_buffer(
1214 struct lttng_buffer_view
*buffer
,
1215 struct lttng_userspace_probe_location_lookup_method
**lookup_method
)
1218 struct lttng_userspace_probe_location_lookup_method_comm
*lookup_comm
;
1219 enum lttng_userspace_probe_location_lookup_method_type type
;
1222 assert(buffer
->data
);
1223 assert(lookup_method
);
1225 if (buffer
->size
< sizeof(*lookup_comm
)) {
1226 ret
= -LTTNG_ERR_INVALID
;
1230 lookup_comm
= (struct lttng_userspace_probe_location_lookup_method_comm
*)
1232 type
= (enum lttng_userspace_probe_location_lookup_method_type
)
1235 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1236 *lookup_method
= NULL
;
1238 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1240 lttng_userspace_probe_location_lookup_method_function_elf_create();
1241 if (!(*lookup_method
)) {
1242 ret
= -LTTNG_ERR_INVALID
;
1246 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1248 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1249 if (!(*lookup_method
)) {
1250 ret
= -LTTNG_ERR_INVALID
;
1255 ret
= -LTTNG_ERR_INVALID
;
1259 ret
= sizeof(*lookup_comm
);
1265 int lttng_userspace_probe_location_create_from_buffer(
1266 const struct lttng_buffer_view
*buffer
,
1267 struct lttng_userspace_probe_location
**location
)
1269 struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1270 struct lttng_userspace_probe_location_comm
*probe_location_comm
;
1271 enum lttng_userspace_probe_location_type type
;
1272 struct lttng_buffer_view lookup_method_view
;
1278 assert(buffer
->data
);
1281 lookup_method
= NULL
;
1283 if (buffer
->size
<= sizeof(*probe_location_comm
)) {
1284 ret
= -LTTNG_ERR_INVALID
;
1288 probe_location_comm
=
1289 (struct lttng_userspace_probe_location_comm
*) buffer
->data
;
1290 type
= (enum lttng_userspace_probe_location_type
) probe_location_comm
->type
;
1291 consumed
+= sizeof(*probe_location_comm
);
1294 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1296 struct lttng_buffer_view view
= lttng_buffer_view_from_view(
1297 buffer
, consumed
, buffer
->size
- consumed
);
1299 ret
= lttng_userspace_probe_location_function_create_from_buffer(
1306 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1308 struct lttng_buffer_view view
= lttng_buffer_view_from_view(
1309 buffer
, consumed
, buffer
->size
- consumed
);
1311 ret
= lttng_userspace_probe_location_tracepoint_create_from_buffer(
1319 ret
= -LTTNG_ERR_INVALID
;
1324 if (buffer
->size
<= consumed
) {
1325 ret
= -LTTNG_ERR_INVALID
;
1329 lookup_method_view
= lttng_buffer_view_from_view(buffer
, consumed
,
1330 buffer
->size
- consumed
);
1331 ret
= lttng_userspace_probe_location_lookup_method_create_from_buffer(
1332 &lookup_method_view
, &lookup_method
);
1334 ret
= -LTTNG_ERR_INVALID
;
1338 assert(lookup_method
);
1339 (*location
)->lookup_method
= lookup_method
;
1340 lookup_method
= NULL
;
1347 int lttng_userspace_probe_location_function_set_binary_fd(
1348 struct lttng_userspace_probe_location
*location
, int binary_fd
)
1351 struct lttng_userspace_probe_location_function
*function_location
;
1354 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
1356 function_location
= container_of(location
,
1357 struct lttng_userspace_probe_location_function
, parent
);
1358 if (function_location
->binary_fd
>= 0) {
1359 ret
= close(function_location
->binary_fd
);
1362 ret
= -LTTNG_ERR_INVALID
;
1367 function_location
->binary_fd
= binary_fd
;
1373 int lttng_userspace_probe_location_tracepoint_set_binary_fd(
1374 struct lttng_userspace_probe_location
*location
, int binary_fd
)
1377 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
1380 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
1382 tracepoint_location
= container_of(location
,
1383 struct lttng_userspace_probe_location_tracepoint
, parent
);
1384 if (tracepoint_location
->binary_fd
>= 0) {
1385 ret
= close(tracepoint_location
->binary_fd
);
1388 ret
= -LTTNG_ERR_INVALID
;
1393 tracepoint_location
->binary_fd
= binary_fd
;
1399 int lttng_userspace_probe_location_function_flatten(
1400 const struct lttng_userspace_probe_location
*location
,
1401 struct lttng_dynamic_buffer
*buffer
)
1403 struct lttng_userspace_probe_location_lookup_method_elf flat_lookup_method
;
1404 struct lttng_userspace_probe_location_function
*probe_function
;
1405 struct lttng_userspace_probe_location_function flat_probe
;
1406 size_t function_name_len
, binary_path_len
;
1407 size_t padding_needed
= 0;
1408 char *flat_probe_start
;
1409 int storage_needed
= 0;
1414 if (location
->lookup_method
&& location
->lookup_method
->type
!=
1415 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
) {
1416 ret
= -LTTNG_ERR_INVALID
;
1420 probe_function
= container_of(location
,
1421 struct lttng_userspace_probe_location_function
,
1423 assert(probe_function
->function_name
);
1424 assert(probe_function
->binary_path
);
1427 sizeof(struct lttng_userspace_probe_location_function
);
1428 function_name_len
= strlen(probe_function
->function_name
) + 1;
1429 binary_path_len
= strlen(probe_function
->binary_path
) + 1;
1430 storage_needed
+= function_name_len
+ binary_path_len
;
1433 * The lookup method is aligned to 64-bit within the buffer.
1434 * This is needed even if there is no lookup method since
1435 * the next structure in the buffer probably needs to be
1436 * aligned too (depending on the arch).
1438 padding_needed
= ALIGN_TO(storage_needed
, sizeof(uint64_t)) - storage_needed
;
1439 storage_needed
+= padding_needed
;
1441 if (location
->lookup_method
) {
1442 /* NOTE: elf look-up method is assumed here. */
1443 storage_needed
+= sizeof(struct lttng_userspace_probe_location_lookup_method_elf
);
1447 ret
= storage_needed
;
1451 if (lttng_dynamic_buffer_get_capacity_left(buffer
) < storage_needed
) {
1452 ret
= lttng_dynamic_buffer_set_capacity(buffer
,
1453 buffer
->size
+ storage_needed
);
1459 memset(&flat_probe
, 0, sizeof(flat_probe
));
1461 flat_probe_start
= buffer
->data
+ buffer
->size
;
1462 flat_probe
.parent
.type
= location
->type
;
1464 * The lookup method, if present, is the last element in the flat
1465 * representation of the probe.
1467 if (location
->lookup_method
) {
1468 flat_probe
.parent
.lookup_method
=
1469 (struct lttng_userspace_probe_location_lookup_method
*)
1470 (flat_probe_start
+ sizeof(flat_probe
) +
1471 function_name_len
+ binary_path_len
+ padding_needed
);
1473 flat_probe
.parent
.lookup_method
= NULL
;
1476 flat_probe
.function_name
= flat_probe_start
+ sizeof(flat_probe
);
1477 flat_probe
.binary_path
= flat_probe
.function_name
+ function_name_len
;
1478 flat_probe
.binary_fd
= -1;
1479 ret
= lttng_dynamic_buffer_append(buffer
, &flat_probe
,
1480 sizeof(flat_probe
));
1485 ret
= lttng_dynamic_buffer_append(buffer
,
1486 probe_function
->function_name
, function_name_len
);
1490 ret
= lttng_dynamic_buffer_append(buffer
,
1491 probe_function
->binary_path
, binary_path_len
);
1496 /* Insert padding before the lookup method. */
1497 ret
= lttng_dynamic_buffer_set_size(buffer
,
1498 buffer
->size
+ padding_needed
);
1503 if (!location
->lookup_method
) {
1504 /* Not an error, the default method is used. */
1505 ret
= storage_needed
;
1509 memset(&flat_lookup_method
, 0, sizeof(flat_lookup_method
));
1510 flat_lookup_method
.parent
.type
=
1511 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
;
1512 ret
= lttng_dynamic_buffer_append(buffer
,
1513 &flat_lookup_method
, sizeof(flat_lookup_method
));
1517 ret
= storage_needed
;
1523 int lttng_userspace_probe_location_tracepoint_flatten(
1524 const struct lttng_userspace_probe_location
*location
,
1525 struct lttng_dynamic_buffer
*buffer
)
1527 struct lttng_userspace_probe_location_lookup_method_sdt flat_lookup_method
;
1528 struct lttng_userspace_probe_location_tracepoint
*probe_tracepoint
;
1529 struct lttng_userspace_probe_location_tracepoint flat_probe
;
1530 size_t probe_name_len
, provider_name_len
, binary_path_len
;
1531 size_t padding_needed
= 0;
1532 int storage_needed
= 0;
1533 char *flat_probe_start
;
1538 /* Only SDT tracepoints are supported at the moment */
1539 if (location
->lookup_method
&& location
->lookup_method
->type
!=
1540 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
) {
1541 ret
= -LTTNG_ERR_INVALID
;
1544 probe_tracepoint
= container_of(location
,
1545 struct lttng_userspace_probe_location_tracepoint
,
1547 assert(probe_tracepoint
->probe_name
);
1548 assert(probe_tracepoint
->provider_name
);
1549 assert(probe_tracepoint
->binary_path
);
1551 /* Compute the storage space needed to flatten the probe location */
1552 storage_needed
+= sizeof(struct lttng_userspace_probe_location_tracepoint
);
1554 probe_name_len
= strlen(probe_tracepoint
->probe_name
) + 1;
1555 provider_name_len
= strlen(probe_tracepoint
->provider_name
) + 1;
1556 binary_path_len
= strlen(probe_tracepoint
->binary_path
) + 1;
1558 storage_needed
+= probe_name_len
+ provider_name_len
+ binary_path_len
;
1561 * The lookup method is aligned to 64-bit within the buffer.
1562 * This is needed even if there is no lookup method since
1563 * the next structure in the buffer probably needs to be
1564 * aligned too (depending on the arch).
1566 padding_needed
= ALIGN_TO(storage_needed
, sizeof(uint64_t)) - storage_needed
;
1567 storage_needed
+= padding_needed
;
1569 if (location
->lookup_method
) {
1570 /* NOTE: elf look-up method is assumed here. */
1572 sizeof(struct lttng_userspace_probe_location_lookup_method_elf
);
1576 * If the caller set buffer to NULL, return the size of the needed buffer.
1579 ret
= storage_needed
;
1583 if (lttng_dynamic_buffer_get_capacity_left(buffer
) < storage_needed
) {
1584 ret
= lttng_dynamic_buffer_set_capacity(buffer
,
1585 buffer
->size
+ storage_needed
);
1591 memset(&flat_probe
, 0, sizeof(flat_probe
));
1593 flat_probe_start
= buffer
->data
+ buffer
->size
;
1594 flat_probe
.parent
.type
= location
->type
;
1597 * The lookup method, if present, is the last element in the flat
1598 * representation of the probe.
1600 if (location
->lookup_method
) {
1601 flat_probe
.parent
.lookup_method
=
1602 (struct lttng_userspace_probe_location_lookup_method
*)
1603 (flat_probe_start
+ sizeof(flat_probe
) +
1604 probe_name_len
+ provider_name_len
+
1605 binary_path_len
+ padding_needed
);
1607 flat_probe
.parent
.lookup_method
= NULL
;
1610 flat_probe
.probe_name
= flat_probe_start
+ sizeof(flat_probe
);
1611 flat_probe
.provider_name
= flat_probe
.probe_name
+ probe_name_len
;
1612 flat_probe
.binary_path
= flat_probe
.provider_name
+ provider_name_len
;
1613 flat_probe
.binary_fd
= -1;
1614 ret
= lttng_dynamic_buffer_append(buffer
, &flat_probe
, sizeof(flat_probe
));
1619 /* Append all the fields to the buffer */
1620 ret
= lttng_dynamic_buffer_append(buffer
,
1621 probe_tracepoint
->probe_name
, probe_name_len
);
1625 ret
= lttng_dynamic_buffer_append(buffer
,
1626 probe_tracepoint
->provider_name
, provider_name_len
);
1630 ret
= lttng_dynamic_buffer_append(buffer
,
1631 probe_tracepoint
->binary_path
, binary_path_len
);
1636 /* Insert padding before the lookup method. */
1637 ret
= lttng_dynamic_buffer_set_size(buffer
, buffer
->size
+ padding_needed
);
1642 if (!location
->lookup_method
) {
1643 /* Not an error, the default method is used. */
1644 ret
= storage_needed
;
1648 memset(&flat_lookup_method
, 0, sizeof(flat_lookup_method
));
1650 flat_lookup_method
.parent
.type
=
1651 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
;
1652 ret
= lttng_dynamic_buffer_append(buffer
,
1653 &flat_lookup_method
, sizeof(flat_lookup_method
));
1657 ret
= storage_needed
;
1663 int lttng_userspace_probe_location_flatten(
1664 const struct lttng_userspace_probe_location
*location
,
1665 struct lttng_dynamic_buffer
*buffer
)
1669 ret
= -LTTNG_ERR_INVALID
;
1673 /* Only types currently supported. */
1674 switch (location
->type
) {
1675 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1676 ret
= lttng_userspace_probe_location_function_flatten(location
, buffer
);
1678 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1679 ret
= lttng_userspace_probe_location_tracepoint_flatten(location
, buffer
);
1682 ret
= -LTTNG_ERR_INVALID
;
1691 struct lttng_userspace_probe_location
*lttng_userspace_probe_location_copy(
1692 const struct lttng_userspace_probe_location
*location
)
1694 struct lttng_userspace_probe_location
*new_location
= NULL
;
1695 enum lttng_userspace_probe_location_type type
;
1701 type
= lttng_userspace_probe_location_get_type(location
);
1703 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1705 lttng_userspace_probe_location_function_copy(location
);
1706 if (!new_location
) {
1710 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1712 lttng_userspace_probe_location_tracepoint_copy(location
);
1713 if (!new_location
) {
1718 new_location
= NULL
;
1722 return new_location
;