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 if (binary_fd
>= 0) {
280 if (close(binary_fd
)) {
281 PERROR("Error closing binary fd in error path");
288 struct lttng_userspace_probe_location
*
289 lttng_userspace_probe_location_function_create(const char *binary_path
,
290 const char *function_name
,
291 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
293 struct lttng_userspace_probe_location
*ret
= NULL
;
295 if (!binary_path
|| !function_name
) {
296 ERR("Invalid argument(s)");
300 switch (lttng_userspace_probe_location_lookup_method_get_type(
302 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
303 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
306 /* Invalid probe location lookup method. */
310 ret
= lttng_userspace_probe_location_function_create_no_check(
311 binary_path
, function_name
, lookup_method
, true);
316 struct lttng_userspace_probe_location
*
317 lttng_userspace_probe_location_tracepoint_create(const char *binary_path
,
318 const char *provider_name
, const char *probe_name
,
319 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
321 struct lttng_userspace_probe_location
*ret
= NULL
;
323 if (!binary_path
|| !probe_name
|| !provider_name
) {
324 ERR("Invalid argument(s)");
328 switch (lttng_userspace_probe_location_lookup_method_get_type(
330 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
333 /* Invalid probe location lookup method. */
337 ret
= lttng_userspace_probe_location_tracepoint_create_no_check(
338 binary_path
, provider_name
, probe_name
, lookup_method
, true);
343 static struct lttng_userspace_probe_location_lookup_method
*
344 lttng_userspace_probe_location_lookup_method_function_elf_copy(
345 const struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
347 struct lttng_userspace_probe_location_lookup_method
*parent
= NULL
;
348 struct lttng_userspace_probe_location_lookup_method_elf
*elf_method
;
350 assert(lookup_method
);
351 assert(lookup_method
->type
==
352 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
);
354 elf_method
= zmalloc(sizeof(*elf_method
));
356 PERROR("Error allocating ELF userspace probe lookup method");
360 elf_method
->parent
.type
= lookup_method
->type
;
361 parent
= &elf_method
->parent
;
370 static struct lttng_userspace_probe_location_lookup_method
*
371 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy(
372 struct lttng_userspace_probe_location_lookup_method
*lookup_method
)
374 struct lttng_userspace_probe_location_lookup_method
*parent
= NULL
;
375 struct lttng_userspace_probe_location_lookup_method_sdt
*sdt_method
;
377 assert(lookup_method
);
378 assert(lookup_method
->type
==
379 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
);
381 sdt_method
= zmalloc(sizeof(*sdt_method
));
387 sdt_method
->parent
.type
= lookup_method
->type
;
388 parent
= &sdt_method
->parent
;
398 static struct lttng_userspace_probe_location
*
399 lttng_userspace_probe_location_function_copy(
400 const struct lttng_userspace_probe_location
*location
)
402 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
403 struct lttng_userspace_probe_location
*new_location
= NULL
;
404 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
405 char *binary_path
= NULL
;
406 char *function_name
= NULL
;
410 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
412 /* Duplicate probe location fields */
414 lttng_strndup(lttng_userspace_probe_location_function_get_binary_path(location
),
421 lttng_strndup(lttng_userspace_probe_location_function_get_function_name(location
),
422 LTTNG_SYMBOL_NAME_LEN
);
423 if (!function_name
) {
424 PERROR("Error duplicating function name string");
428 /* Duplicate the binary fd */
429 fd
= dup(lttng_userspace_probe_location_function_get_binary_fd(location
));
431 PERROR("Error duplicating file descriptor to binary");
436 * Duplicate probe location method fields
438 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(
439 location
->lookup_method
);
440 switch (lookup_type
) {
441 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
443 lttng_userspace_probe_location_lookup_method_function_elf_copy(
444 location
->lookup_method
);
445 if (!lookup_method
) {
450 /* Invalid probe location lookup method. */
454 /* Create the probe_location */
455 new_location
= lttng_userspace_probe_location_function_create_no_check(
456 binary_path
, function_name
, lookup_method
, true);
458 goto destroy_lookup_method
;
461 /* Set the duplicated fd to the new probe_location */
462 if (lttng_userspace_probe_location_function_set_binary_fd(new_location
, fd
) < 0) {
463 goto destroy_probe_location
;
468 destroy_probe_location
:
469 lttng_userspace_probe_location_destroy(new_location
);
470 destroy_lookup_method
:
471 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
474 PERROR("Error closing duplicated file descriptor in error path");
484 static struct lttng_userspace_probe_location
*
485 lttng_userspace_probe_location_tracepoint_copy(
486 const struct lttng_userspace_probe_location
*location
)
488 enum lttng_userspace_probe_location_lookup_method_type lookup_type
;
489 struct lttng_userspace_probe_location
*new_location
= NULL
;
490 struct lttng_userspace_probe_location_lookup_method
*lookup_method
= NULL
;
491 char *binary_path
= NULL
;
492 char *probe_name
= NULL
;
493 char *provider_name
= NULL
;
497 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
499 /* Duplicate probe location fields */
501 lttng_strndup(lttng_userspace_probe_location_tracepoint_get_binary_path(location
),
504 PERROR("lttng_strndup");
509 lttng_strndup(lttng_userspace_probe_location_tracepoint_get_probe_name(location
),
510 LTTNG_SYMBOL_NAME_LEN
);
512 PERROR("lttng_strndup");
517 lttng_strndup(lttng_userspace_probe_location_tracepoint_get_provider_name(location
),
518 LTTNG_SYMBOL_NAME_LEN
);
519 if (!provider_name
) {
520 PERROR("lttng_strndup");
524 /* Duplicate the binary fd */
525 fd
= dup(lttng_userspace_probe_location_tracepoint_get_binary_fd(location
));
532 * Duplicate probe location method fields
534 lookup_type
= lttng_userspace_probe_location_lookup_method_get_type(
535 location
->lookup_method
);
536 switch (lookup_type
) {
537 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
539 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy(
540 location
->lookup_method
);
541 if (!lookup_method
) {
546 /* Invalid probe location lookup method. */
550 /* Create the probe_location */
551 new_location
= lttng_userspace_probe_location_tracepoint_create_no_check(
552 binary_path
, provider_name
, probe_name
, lookup_method
, true);
554 goto destroy_lookup_method
;
557 /* Set the duplicated fd to the new probe_location */
558 if (lttng_userspace_probe_location_tracepoint_set_binary_fd(new_location
, fd
) < 0) {
559 goto destroy_probe_location
;
564 destroy_probe_location
:
565 lttng_userspace_probe_location_destroy(new_location
);
566 destroy_lookup_method
:
567 lttng_userspace_probe_location_lookup_method_destroy(lookup_method
);
581 const char *lttng_userspace_probe_location_function_get_binary_path(
582 const struct lttng_userspace_probe_location
*location
)
584 const char *ret
= NULL
;
585 struct lttng_userspace_probe_location_function
*function_location
;
587 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
588 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
589 ERR("Invalid argument(s)");
593 function_location
= container_of(location
,
594 struct lttng_userspace_probe_location_function
,
596 ret
= function_location
->binary_path
;
601 const char *lttng_userspace_probe_location_tracepoint_get_binary_path(
602 const struct lttng_userspace_probe_location
*location
)
604 const char *ret
= NULL
;
605 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
607 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
608 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
609 ERR("Invalid argument(s)");
613 tracepoint_location
= container_of(location
,
614 struct lttng_userspace_probe_location_tracepoint
,
616 ret
= tracepoint_location
->binary_path
;
621 const char *lttng_userspace_probe_location_function_get_function_name(
622 const struct lttng_userspace_probe_location
*location
)
624 const char *ret
= NULL
;
625 struct lttng_userspace_probe_location_function
*function_location
;
627 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
628 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
629 ERR("Invalid argument(s)");
633 function_location
= container_of(location
,
634 struct lttng_userspace_probe_location_function
, parent
);
635 ret
= function_location
->function_name
;
640 const char *lttng_userspace_probe_location_tracepoint_get_probe_name(
641 const struct lttng_userspace_probe_location
*location
)
643 const char *ret
= NULL
;
644 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
646 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
647 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
648 ERR("Invalid argument(s)");
652 tracepoint_location
= container_of(location
,
653 struct lttng_userspace_probe_location_tracepoint
, parent
);
654 ret
= tracepoint_location
->probe_name
;
659 const char *lttng_userspace_probe_location_tracepoint_get_provider_name(
660 const struct lttng_userspace_probe_location
*location
)
662 const char *ret
= NULL
;
663 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
665 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
666 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
667 ERR("Invalid argument(s)");
671 tracepoint_location
= container_of(location
,
672 struct lttng_userspace_probe_location_tracepoint
, parent
);
673 ret
= tracepoint_location
->provider_name
;
678 int lttng_userspace_probe_location_function_get_binary_fd(
679 const struct lttng_userspace_probe_location
*location
)
682 struct lttng_userspace_probe_location_function
*function_location
;
684 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
685 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
686 ERR("Invalid argument(s)");
690 function_location
= container_of(location
,
691 struct lttng_userspace_probe_location_function
, parent
);
692 ret
= function_location
->binary_fd
;
697 enum lttng_userspace_probe_location_function_instrumentation_type
698 lttng_userspace_probe_location_function_get_instrumentation_type(
699 const struct lttng_userspace_probe_location
*location
)
701 enum lttng_userspace_probe_location_function_instrumentation_type type
;
702 struct lttng_userspace_probe_location_function
*function_location
;
704 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
705 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
706 ERR("Invalid argument(s)");
707 type
= LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_UNKNOWN
;
711 function_location
= container_of(location
,
712 struct lttng_userspace_probe_location_function
, parent
);
713 type
= function_location
->instrumentation_type
;
718 enum lttng_userspace_probe_location_status
719 lttng_userspace_probe_location_function_set_instrumentation_type(
720 const struct lttng_userspace_probe_location
*location
,
721 enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type
)
723 enum lttng_userspace_probe_location_status status
=
724 LTTNG_USERSPACE_PROBE_LOCATION_STATUS_OK
;
725 struct lttng_userspace_probe_location_function
*function_location
;
727 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
728 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
||
729 instrumentation_type
!=
730 LTTNG_USERSPACE_PROBE_LOCATION_FUNCTION_INSTRUMENTATION_TYPE_ENTRY
) {
731 ERR("Invalid argument(s)");
732 status
= LTTNG_USERSPACE_PROBE_LOCATION_STATUS_INVALID
;
736 function_location
= container_of(location
,
737 struct lttng_userspace_probe_location_function
, parent
);
738 function_location
->instrumentation_type
= instrumentation_type
;
743 int lttng_userspace_probe_location_tracepoint_get_binary_fd(
744 const struct lttng_userspace_probe_location
*location
)
747 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
749 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
750 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
751 ERR("Invalid argument(s)");
755 tracepoint_location
= container_of(location
,
756 struct lttng_userspace_probe_location_tracepoint
, parent
);
757 ret
= tracepoint_location
->binary_fd
;
762 static struct lttng_userspace_probe_location_lookup_method
*
763 lttng_userspace_probe_location_function_get_lookup_method(
764 const struct lttng_userspace_probe_location
*location
)
766 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
768 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
769 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
) {
770 ERR("Invalid argument(s)");
774 ret
= location
->lookup_method
;
779 static struct lttng_userspace_probe_location_lookup_method
*
780 lttng_userspace_probe_location_tracepoint_get_lookup_method(
781 const struct lttng_userspace_probe_location
*location
)
783 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
785 if (!location
|| lttng_userspace_probe_location_get_type(location
) !=
786 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
) {
787 ERR("Invalid argument(s)");
791 ret
= location
->lookup_method
;
796 const struct lttng_userspace_probe_location_lookup_method
*
797 lttng_userspace_probe_location_get_lookup_method(
798 const struct lttng_userspace_probe_location
*location
)
800 struct lttng_userspace_probe_location_lookup_method
*ret
= NULL
;
803 switch (location
->type
) {
804 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
805 ret
= lttng_userspace_probe_location_function_get_lookup_method(
808 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
809 ret
= lttng_userspace_probe_location_tracepoint_get_lookup_method(
813 ERR("Unknowned lookup method.");
820 int lttng_userspace_probe_location_lookup_method_serialize(
821 struct lttng_userspace_probe_location_lookup_method
*method
,
822 struct lttng_dynamic_buffer
*buffer
)
825 struct lttng_userspace_probe_location_lookup_method_comm
828 lookup_method_comm
.type
= (int8_t) (method
? method
->type
:
829 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
);
831 ret
= lttng_dynamic_buffer_append(buffer
, &lookup_method_comm
,
832 sizeof(lookup_method_comm
));
837 ret
= sizeof(lookup_method_comm
);
843 int lttng_userspace_probe_location_function_serialize(
844 const struct lttng_userspace_probe_location
*location
,
845 struct lttng_dynamic_buffer
*buffer
,
849 size_t function_name_len
, binary_path_len
;
850 struct lttng_userspace_probe_location_function
*location_function
;
851 struct lttng_userspace_probe_location_function_comm location_function_comm
;
854 assert(lttng_userspace_probe_location_get_type(location
) ==
855 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
857 location_function
= container_of(location
,
858 struct lttng_userspace_probe_location_function
,
860 if (!location_function
->function_name
|| !location_function
->binary_path
) {
861 ret
= -LTTNG_ERR_INVALID
;
865 if (binary_fd
&& location_function
->binary_fd
< 0) {
866 ret
= -LTTNG_ERR_INVALID
;
871 *binary_fd
= location_function
->binary_fd
;
874 function_name_len
= strlen(location_function
->function_name
);
875 if (function_name_len
== 0) {
876 ret
= -LTTNG_ERR_INVALID
;
879 binary_path_len
= strlen(location_function
->binary_path
);
880 if (binary_path_len
== 0) {
881 ret
= -LTTNG_ERR_INVALID
;
885 location_function_comm
.function_name_len
= function_name_len
+ 1;
886 location_function_comm
.binary_path_len
= binary_path_len
+ 1;
889 ret
= lttng_dynamic_buffer_append(buffer
,
890 &location_function_comm
,
891 sizeof(location_function_comm
));
893 ret
= -LTTNG_ERR_INVALID
;
896 ret
= lttng_dynamic_buffer_append(buffer
,
897 location_function
->function_name
,
898 location_function_comm
.function_name_len
);
900 ret
= -LTTNG_ERR_INVALID
;
903 ret
= lttng_dynamic_buffer_append(buffer
,
904 location_function
->binary_path
,
905 location_function_comm
.binary_path_len
);
907 ret
= -LTTNG_ERR_INVALID
;
911 ret
= sizeof(location_function_comm
) +
912 location_function_comm
.function_name_len
+
913 location_function_comm
.binary_path_len
;
919 int lttng_userspace_probe_location_tracepoint_serialize(
920 const struct lttng_userspace_probe_location
*location
,
921 struct lttng_dynamic_buffer
*buffer
,
925 size_t probe_name_len
, provider_name_len
, binary_path_len
;
926 struct lttng_userspace_probe_location_tracepoint
*location_tracepoint
;
927 struct lttng_userspace_probe_location_tracepoint_comm location_tracepoint_comm
;
930 assert(lttng_userspace_probe_location_get_type(location
) ==
931 LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
933 location_tracepoint
= container_of(location
,
934 struct lttng_userspace_probe_location_tracepoint
,
936 if (!location_tracepoint
->probe_name
||
937 !location_tracepoint
->provider_name
||
938 !location_tracepoint
->binary_path
) {
939 ret
= -LTTNG_ERR_INVALID
;
943 if (binary_fd
&& location_tracepoint
->binary_fd
< 0) {
944 ret
= -LTTNG_ERR_INVALID
;
949 *binary_fd
= location_tracepoint
->binary_fd
;
952 probe_name_len
= strlen(location_tracepoint
->probe_name
);
953 if (probe_name_len
== 0) {
954 ret
= -LTTNG_ERR_INVALID
;
958 provider_name_len
= strlen(location_tracepoint
->provider_name
);
959 if (provider_name_len
== 0) {
960 ret
= -LTTNG_ERR_INVALID
;
964 binary_path_len
= strlen(location_tracepoint
->binary_path
);
965 if (binary_path_len
== 0) {
966 ret
= -LTTNG_ERR_INVALID
;
970 location_tracepoint_comm
.probe_name_len
= probe_name_len
+ 1;
971 location_tracepoint_comm
.provider_name_len
= provider_name_len
+ 1;
972 location_tracepoint_comm
.binary_path_len
= binary_path_len
+ 1;
975 ret
= lttng_dynamic_buffer_append(buffer
,
976 &location_tracepoint_comm
,
977 sizeof(location_tracepoint_comm
));
979 ret
= -LTTNG_ERR_INVALID
;
982 ret
= lttng_dynamic_buffer_append(buffer
,
983 location_tracepoint
->probe_name
,
984 location_tracepoint_comm
.probe_name_len
);
986 ret
= -LTTNG_ERR_INVALID
;
989 ret
= lttng_dynamic_buffer_append(buffer
,
990 location_tracepoint
->provider_name
,
991 location_tracepoint_comm
.provider_name_len
);
993 ret
= -LTTNG_ERR_INVALID
;
996 ret
= lttng_dynamic_buffer_append(buffer
,
997 location_tracepoint
->binary_path
,
998 location_tracepoint_comm
.binary_path_len
);
1000 ret
= -LTTNG_ERR_INVALID
;
1004 ret
= sizeof(location_tracepoint_comm
) +
1005 location_tracepoint_comm
.probe_name_len
+
1006 location_tracepoint_comm
.provider_name_len
+
1007 location_tracepoint_comm
.binary_path_len
;
1013 int lttng_userspace_probe_location_serialize(
1014 const struct lttng_userspace_probe_location
*location
,
1015 struct lttng_dynamic_buffer
*buffer
,
1018 int ret
, buffer_use
= 0;
1019 struct lttng_userspace_probe_location_comm location_generic_comm
;
1022 ERR("Invalid argument(s)");
1023 ret
= -LTTNG_ERR_INVALID
;
1027 memset(&location_generic_comm
, 0, sizeof(location_generic_comm
));
1029 location_generic_comm
.type
= (int8_t) location
->type
;
1031 ret
= lttng_dynamic_buffer_append(buffer
, &location_generic_comm
,
1032 sizeof(location_generic_comm
));
1037 buffer_use
+= sizeof(location_generic_comm
);
1039 switch (lttng_userspace_probe_location_get_type(location
)) {
1040 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1041 ret
= lttng_userspace_probe_location_function_serialize(
1042 location
, buffer
, binary_fd
);
1044 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1045 ret
= lttng_userspace_probe_location_tracepoint_serialize(
1046 location
, buffer
, binary_fd
);
1049 ERR("Unsupported probe location type");
1050 ret
= -LTTNG_ERR_INVALID
;
1058 ret
= lttng_userspace_probe_location_lookup_method_serialize(
1059 location
->lookup_method
, buffer
);
1069 int lttng_userspace_probe_location_function_create_from_buffer(
1070 const struct lttng_buffer_view
*buffer
,
1071 struct lttng_userspace_probe_location
**location
)
1073 struct lttng_userspace_probe_location_function_comm
*location_function_comm
;
1074 const char *function_name_src
, *binary_path_src
;
1075 char *function_name
= NULL
, *binary_path
= NULL
;
1079 assert(buffer
->data
);
1082 location_function_comm
=
1083 (struct lttng_userspace_probe_location_function_comm
*) buffer
->data
;
1085 const size_t expected_size
= sizeof(*location_function_comm
) +
1086 location_function_comm
->function_name_len
+
1087 location_function_comm
->binary_path_len
;
1089 if (buffer
->size
< expected_size
) {
1090 ret
= -LTTNG_ERR_INVALID
;
1094 function_name_src
= buffer
->data
+ sizeof(*location_function_comm
);
1095 binary_path_src
= function_name_src
+
1096 location_function_comm
->function_name_len
;
1098 if (function_name_src
[location_function_comm
->function_name_len
- 1] != '\0') {
1099 ret
= -LTTNG_ERR_INVALID
;
1102 if (binary_path_src
[location_function_comm
->binary_path_len
- 1] != '\0') {
1103 ret
= -LTTNG_ERR_INVALID
;
1107 function_name
= lttng_strndup(function_name_src
, LTTNG_SYMBOL_NAME_LEN
);
1108 if (!function_name
) {
1109 PERROR("lttng_strndup");
1113 binary_path
= lttng_strndup(binary_path_src
, LTTNG_PATH_MAX
);
1115 PERROR("lttng_strndup");
1119 *location
= lttng_userspace_probe_location_function_create_no_check(
1120 binary_path
, function_name
, NULL
, false);
1122 ret
= -LTTNG_ERR_INVALID
;
1126 ret
= (int) expected_size
;
1128 free(function_name
);
1134 int lttng_userspace_probe_location_tracepoint_create_from_buffer(
1135 const struct lttng_buffer_view
*buffer
,
1136 struct lttng_userspace_probe_location
**location
)
1138 struct lttng_userspace_probe_location_tracepoint_comm
*location_tracepoint_comm
;
1139 const char *probe_name_src
, *provider_name_src
, *binary_path_src
;
1140 char *probe_name
= NULL
, *provider_name
= NULL
, *binary_path
= NULL
;
1144 assert(buffer
->data
);
1147 location_tracepoint_comm
=
1148 (struct lttng_userspace_probe_location_tracepoint_comm
*) buffer
->data
;
1150 const size_t expected_size
= sizeof(*location_tracepoint_comm
) +
1151 location_tracepoint_comm
->probe_name_len
+
1152 location_tracepoint_comm
->provider_name_len
+
1153 location_tracepoint_comm
->binary_path_len
;
1155 if (buffer
->size
< expected_size
) {
1156 ret
= -LTTNG_ERR_INVALID
;
1160 probe_name_src
= buffer
->data
+ sizeof(*location_tracepoint_comm
);
1161 provider_name_src
= probe_name_src
+
1162 location_tracepoint_comm
->probe_name_len
;
1163 binary_path_src
= provider_name_src
+
1164 location_tracepoint_comm
->provider_name_len
;
1166 if (probe_name_src
[location_tracepoint_comm
->probe_name_len
- 1] != '\0') {
1167 ret
= -LTTNG_ERR_INVALID
;
1171 if (provider_name_src
[location_tracepoint_comm
->provider_name_len
- 1] != '\0') {
1172 ret
= -LTTNG_ERR_INVALID
;
1176 if (binary_path_src
[location_tracepoint_comm
->binary_path_len
- 1] != '\0') {
1177 ret
= -LTTNG_ERR_INVALID
;
1181 probe_name
= lttng_strndup(probe_name_src
, LTTNG_SYMBOL_NAME_LEN
);
1183 PERROR("lttng_strndup");
1186 provider_name
= lttng_strndup(provider_name_src
, LTTNG_SYMBOL_NAME_LEN
);
1187 if (!provider_name
) {
1188 PERROR("lttng_strndup");
1192 binary_path
= lttng_strndup(binary_path_src
, LTTNG_SYMBOL_NAME_LEN
);
1194 PERROR("lttng_strndup");
1198 *location
= lttng_userspace_probe_location_tracepoint_create_no_check(
1199 binary_path
, provider_name
, probe_name
, NULL
, false);
1201 ret
= -LTTNG_ERR_INVALID
;
1205 ret
= (int) expected_size
;
1208 free(provider_name
);
1214 int lttng_userspace_probe_location_lookup_method_create_from_buffer(
1215 struct lttng_buffer_view
*buffer
,
1216 struct lttng_userspace_probe_location_lookup_method
**lookup_method
)
1219 struct lttng_userspace_probe_location_lookup_method_comm
*lookup_comm
;
1220 enum lttng_userspace_probe_location_lookup_method_type type
;
1223 assert(buffer
->data
);
1224 assert(lookup_method
);
1226 if (buffer
->size
< sizeof(*lookup_comm
)) {
1227 ret
= -LTTNG_ERR_INVALID
;
1231 lookup_comm
= (struct lttng_userspace_probe_location_lookup_method_comm
*)
1233 type
= (enum lttng_userspace_probe_location_lookup_method_type
)
1236 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT
:
1237 *lookup_method
= NULL
;
1239 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
:
1241 lttng_userspace_probe_location_lookup_method_function_elf_create();
1242 if (!(*lookup_method
)) {
1243 ret
= -LTTNG_ERR_INVALID
;
1247 case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
:
1249 lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create();
1250 if (!(*lookup_method
)) {
1251 ret
= -LTTNG_ERR_INVALID
;
1256 ret
= -LTTNG_ERR_INVALID
;
1260 ret
= sizeof(*lookup_comm
);
1266 int lttng_userspace_probe_location_create_from_buffer(
1267 const struct lttng_buffer_view
*buffer
,
1268 struct lttng_userspace_probe_location
**location
)
1270 struct lttng_userspace_probe_location_lookup_method
*lookup_method
;
1271 struct lttng_userspace_probe_location_comm
*probe_location_comm
;
1272 enum lttng_userspace_probe_location_type type
;
1273 struct lttng_buffer_view lookup_method_view
;
1279 assert(buffer
->data
);
1282 lookup_method
= NULL
;
1284 if (buffer
->size
<= sizeof(*probe_location_comm
)) {
1285 ret
= -LTTNG_ERR_INVALID
;
1289 probe_location_comm
=
1290 (struct lttng_userspace_probe_location_comm
*) buffer
->data
;
1291 type
= (enum lttng_userspace_probe_location_type
) probe_location_comm
->type
;
1292 consumed
+= sizeof(*probe_location_comm
);
1295 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1297 struct lttng_buffer_view view
= lttng_buffer_view_from_view(
1298 buffer
, consumed
, buffer
->size
- consumed
);
1300 ret
= lttng_userspace_probe_location_function_create_from_buffer(
1307 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1309 struct lttng_buffer_view view
= lttng_buffer_view_from_view(
1310 buffer
, consumed
, buffer
->size
- consumed
);
1312 ret
= lttng_userspace_probe_location_tracepoint_create_from_buffer(
1320 ret
= -LTTNG_ERR_INVALID
;
1325 if (buffer
->size
<= consumed
) {
1326 ret
= -LTTNG_ERR_INVALID
;
1330 lookup_method_view
= lttng_buffer_view_from_view(buffer
, consumed
,
1331 buffer
->size
- consumed
);
1332 ret
= lttng_userspace_probe_location_lookup_method_create_from_buffer(
1333 &lookup_method_view
, &lookup_method
);
1335 ret
= -LTTNG_ERR_INVALID
;
1339 assert(lookup_method
);
1340 (*location
)->lookup_method
= lookup_method
;
1341 lookup_method
= NULL
;
1348 int lttng_userspace_probe_location_function_set_binary_fd(
1349 struct lttng_userspace_probe_location
*location
, int binary_fd
)
1352 struct lttng_userspace_probe_location_function
*function_location
;
1355 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
);
1357 function_location
= container_of(location
,
1358 struct lttng_userspace_probe_location_function
, parent
);
1359 if (function_location
->binary_fd
>= 0) {
1360 ret
= close(function_location
->binary_fd
);
1363 ret
= -LTTNG_ERR_INVALID
;
1368 function_location
->binary_fd
= binary_fd
;
1374 int lttng_userspace_probe_location_tracepoint_set_binary_fd(
1375 struct lttng_userspace_probe_location
*location
, int binary_fd
)
1378 struct lttng_userspace_probe_location_tracepoint
*tracepoint_location
;
1381 assert(location
->type
== LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
);
1383 tracepoint_location
= container_of(location
,
1384 struct lttng_userspace_probe_location_tracepoint
, parent
);
1385 if (tracepoint_location
->binary_fd
>= 0) {
1386 ret
= close(tracepoint_location
->binary_fd
);
1389 ret
= -LTTNG_ERR_INVALID
;
1394 tracepoint_location
->binary_fd
= binary_fd
;
1400 int lttng_userspace_probe_location_function_flatten(
1401 const struct lttng_userspace_probe_location
*location
,
1402 struct lttng_dynamic_buffer
*buffer
)
1404 struct lttng_userspace_probe_location_lookup_method_elf flat_lookup_method
;
1405 struct lttng_userspace_probe_location_function
*probe_function
;
1406 struct lttng_userspace_probe_location_function flat_probe
;
1407 size_t function_name_len
, binary_path_len
;
1408 size_t padding_needed
= 0;
1409 char *flat_probe_start
;
1410 int storage_needed
= 0;
1415 if (location
->lookup_method
&& location
->lookup_method
->type
!=
1416 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
) {
1417 ret
= -LTTNG_ERR_INVALID
;
1421 probe_function
= container_of(location
,
1422 struct lttng_userspace_probe_location_function
,
1424 assert(probe_function
->function_name
);
1425 assert(probe_function
->binary_path
);
1428 sizeof(struct lttng_userspace_probe_location_function
);
1429 function_name_len
= strlen(probe_function
->function_name
) + 1;
1430 binary_path_len
= strlen(probe_function
->binary_path
) + 1;
1431 storage_needed
+= function_name_len
+ binary_path_len
;
1434 * The lookup method is aligned to 64-bit within the buffer.
1435 * This is needed even if there is no lookup method since
1436 * the next structure in the buffer probably needs to be
1437 * aligned too (depending on the arch).
1439 padding_needed
= ALIGN_TO(storage_needed
, sizeof(uint64_t)) - storage_needed
;
1440 storage_needed
+= padding_needed
;
1442 if (location
->lookup_method
) {
1443 /* NOTE: elf look-up method is assumed here. */
1444 storage_needed
+= sizeof(struct lttng_userspace_probe_location_lookup_method_elf
);
1448 ret
= storage_needed
;
1452 if (lttng_dynamic_buffer_get_capacity_left(buffer
) < storage_needed
) {
1453 ret
= lttng_dynamic_buffer_set_capacity(buffer
,
1454 buffer
->size
+ storage_needed
);
1460 memset(&flat_probe
, 0, sizeof(flat_probe
));
1462 flat_probe_start
= buffer
->data
+ buffer
->size
;
1463 flat_probe
.parent
.type
= location
->type
;
1465 * The lookup method, if present, is the last element in the flat
1466 * representation of the probe.
1468 if (location
->lookup_method
) {
1469 flat_probe
.parent
.lookup_method
=
1470 (struct lttng_userspace_probe_location_lookup_method
*)
1471 (flat_probe_start
+ sizeof(flat_probe
) +
1472 function_name_len
+ binary_path_len
+ padding_needed
);
1474 flat_probe
.parent
.lookup_method
= NULL
;
1477 flat_probe
.function_name
= flat_probe_start
+ sizeof(flat_probe
);
1478 flat_probe
.binary_path
= flat_probe
.function_name
+ function_name_len
;
1479 flat_probe
.binary_fd
= -1;
1480 ret
= lttng_dynamic_buffer_append(buffer
, &flat_probe
,
1481 sizeof(flat_probe
));
1486 ret
= lttng_dynamic_buffer_append(buffer
,
1487 probe_function
->function_name
, function_name_len
);
1491 ret
= lttng_dynamic_buffer_append(buffer
,
1492 probe_function
->binary_path
, binary_path_len
);
1497 /* Insert padding before the lookup method. */
1498 ret
= lttng_dynamic_buffer_set_size(buffer
,
1499 buffer
->size
+ padding_needed
);
1504 if (!location
->lookup_method
) {
1505 /* Not an error, the default method is used. */
1506 ret
= storage_needed
;
1510 memset(&flat_lookup_method
, 0, sizeof(flat_lookup_method
));
1511 flat_lookup_method
.parent
.type
=
1512 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF
;
1513 ret
= lttng_dynamic_buffer_append(buffer
,
1514 &flat_lookup_method
, sizeof(flat_lookup_method
));
1518 ret
= storage_needed
;
1524 int lttng_userspace_probe_location_tracepoint_flatten(
1525 const struct lttng_userspace_probe_location
*location
,
1526 struct lttng_dynamic_buffer
*buffer
)
1528 struct lttng_userspace_probe_location_lookup_method_sdt flat_lookup_method
;
1529 struct lttng_userspace_probe_location_tracepoint
*probe_tracepoint
;
1530 struct lttng_userspace_probe_location_tracepoint flat_probe
;
1531 size_t probe_name_len
, provider_name_len
, binary_path_len
;
1532 size_t padding_needed
= 0;
1533 int storage_needed
= 0;
1534 char *flat_probe_start
;
1539 /* Only SDT tracepoints are supported at the moment */
1540 if (location
->lookup_method
&& location
->lookup_method
->type
!=
1541 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
) {
1542 ret
= -LTTNG_ERR_INVALID
;
1545 probe_tracepoint
= container_of(location
,
1546 struct lttng_userspace_probe_location_tracepoint
,
1548 assert(probe_tracepoint
->probe_name
);
1549 assert(probe_tracepoint
->provider_name
);
1550 assert(probe_tracepoint
->binary_path
);
1552 /* Compute the storage space needed to flatten the probe location */
1553 storage_needed
+= sizeof(struct lttng_userspace_probe_location_tracepoint
);
1555 probe_name_len
= strlen(probe_tracepoint
->probe_name
) + 1;
1556 provider_name_len
= strlen(probe_tracepoint
->provider_name
) + 1;
1557 binary_path_len
= strlen(probe_tracepoint
->binary_path
) + 1;
1559 storage_needed
+= probe_name_len
+ provider_name_len
+ binary_path_len
;
1562 * The lookup method is aligned to 64-bit within the buffer.
1563 * This is needed even if there is no lookup method since
1564 * the next structure in the buffer probably needs to be
1565 * aligned too (depending on the arch).
1567 padding_needed
= ALIGN_TO(storage_needed
, sizeof(uint64_t)) - storage_needed
;
1568 storage_needed
+= padding_needed
;
1570 if (location
->lookup_method
) {
1571 /* NOTE: elf look-up method is assumed here. */
1573 sizeof(struct lttng_userspace_probe_location_lookup_method_elf
);
1577 * If the caller set buffer to NULL, return the size of the needed buffer.
1580 ret
= storage_needed
;
1584 if (lttng_dynamic_buffer_get_capacity_left(buffer
) < storage_needed
) {
1585 ret
= lttng_dynamic_buffer_set_capacity(buffer
,
1586 buffer
->size
+ storage_needed
);
1592 memset(&flat_probe
, 0, sizeof(flat_probe
));
1594 flat_probe_start
= buffer
->data
+ buffer
->size
;
1595 flat_probe
.parent
.type
= location
->type
;
1598 * The lookup method, if present, is the last element in the flat
1599 * representation of the probe.
1601 if (location
->lookup_method
) {
1602 flat_probe
.parent
.lookup_method
=
1603 (struct lttng_userspace_probe_location_lookup_method
*)
1604 (flat_probe_start
+ sizeof(flat_probe
) +
1605 probe_name_len
+ provider_name_len
+
1606 binary_path_len
+ padding_needed
);
1608 flat_probe
.parent
.lookup_method
= NULL
;
1611 flat_probe
.probe_name
= flat_probe_start
+ sizeof(flat_probe
);
1612 flat_probe
.provider_name
= flat_probe
.probe_name
+ probe_name_len
;
1613 flat_probe
.binary_path
= flat_probe
.provider_name
+ provider_name_len
;
1614 flat_probe
.binary_fd
= -1;
1615 ret
= lttng_dynamic_buffer_append(buffer
, &flat_probe
, sizeof(flat_probe
));
1620 /* Append all the fields to the buffer */
1621 ret
= lttng_dynamic_buffer_append(buffer
,
1622 probe_tracepoint
->probe_name
, probe_name_len
);
1626 ret
= lttng_dynamic_buffer_append(buffer
,
1627 probe_tracepoint
->provider_name
, provider_name_len
);
1631 ret
= lttng_dynamic_buffer_append(buffer
,
1632 probe_tracepoint
->binary_path
, binary_path_len
);
1637 /* Insert padding before the lookup method. */
1638 ret
= lttng_dynamic_buffer_set_size(buffer
, buffer
->size
+ padding_needed
);
1643 if (!location
->lookup_method
) {
1644 /* Not an error, the default method is used. */
1645 ret
= storage_needed
;
1649 memset(&flat_lookup_method
, 0, sizeof(flat_lookup_method
));
1651 flat_lookup_method
.parent
.type
=
1652 LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT
;
1653 ret
= lttng_dynamic_buffer_append(buffer
,
1654 &flat_lookup_method
, sizeof(flat_lookup_method
));
1658 ret
= storage_needed
;
1664 int lttng_userspace_probe_location_flatten(
1665 const struct lttng_userspace_probe_location
*location
,
1666 struct lttng_dynamic_buffer
*buffer
)
1670 ret
= -LTTNG_ERR_INVALID
;
1674 /* Only types currently supported. */
1675 switch (location
->type
) {
1676 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1677 ret
= lttng_userspace_probe_location_function_flatten(location
, buffer
);
1679 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1680 ret
= lttng_userspace_probe_location_tracepoint_flatten(location
, buffer
);
1683 ret
= -LTTNG_ERR_INVALID
;
1692 struct lttng_userspace_probe_location
*lttng_userspace_probe_location_copy(
1693 const struct lttng_userspace_probe_location
*location
)
1695 struct lttng_userspace_probe_location
*new_location
= NULL
;
1696 enum lttng_userspace_probe_location_type type
;
1702 type
= lttng_userspace_probe_location_get_type(location
);
1704 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
1706 lttng_userspace_probe_location_function_copy(location
);
1707 if (!new_location
) {
1711 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
1713 lttng_userspace_probe_location_tracepoint_copy(location
);
1714 if (!new_location
) {
1719 new_location
= NULL
;
1723 return new_location
;