From ceabb767180e064629b5a9ab4ed14449da864763 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 7 Apr 2020 13:07:54 -0400 Subject: [PATCH] tracepoint: Refactor representation of nested types Refactor enumeration, sequence, array, structure, and variant types. Implement internal data structures to support nested types. All probe providers using ctf_enum(), ctf_array*() and ctf_sequence*() are switched to this new internal type representation. Each of sequence, array, struct and variant gain a "alignment" property, which is a feature which was needed in lttng-modules to express alignment for an array or sequence of bits. Signed-off-by: Mathieu Desnoyers --- instrumentation/events/lttng-module/net.h | 215 ++++----- .../headers/syscalls_pointers_override.h | 145 +++--- lttng-context-callstack-legacy-impl.h | 57 ++- lttng-context-callstack-stackwalk-impl.h | 62 ++- lttng-context-callstack.c | 66 +-- lttng-context-cgroup-ns.c | 12 +- lttng-context-cpu-id.c | 12 +- lttng-context-egid.c | 12 +- lttng-context-euid.c | 12 +- lttng-context-gid.c | 12 +- lttng-context-hostname.c | 17 +- lttng-context-interruptible.c | 12 +- lttng-context-ipc-ns.c | 12 +- lttng-context-migratable.c | 12 +- lttng-context-mnt-ns.c | 12 +- lttng-context-need-reschedule.c | 12 +- lttng-context-net-ns.c | 12 +- lttng-context-nice.c | 12 +- lttng-context-perf-counters.c | 12 +- lttng-context-pid-ns.c | 12 +- lttng-context-pid.c | 12 +- lttng-context-ppid.c | 12 +- lttng-context-preemptible.c | 12 +- lttng-context-prio.c | 12 +- lttng-context-procname.c | 17 +- lttng-context-sgid.c | 12 +- lttng-context-suid.c | 12 +- lttng-context-tid.c | 12 +- lttng-context-uid.c | 12 +- lttng-context-user-ns.c | 12 +- lttng-context-uts-ns.c | 12 +- lttng-context-vegid.c | 12 +- lttng-context-veuid.c | 12 +- lttng-context-vgid.c | 12 +- lttng-context-vpid.c | 12 +- lttng-context-vppid.c | 12 +- lttng-context-vsgid.c | 12 +- lttng-context-vsuid.c | 12 +- lttng-context-vtid.c | 12 +- lttng-context-vuid.c | 12 +- lttng-context.c | 82 +--- lttng-events.c | 450 ++++++++++-------- lttng-events.h | 97 ++-- lttng-filter-interpreter.c | 29 +- lttng-filter-specialize.c | 66 +-- lttng-filter.c | 61 +-- probes/lttng-kprobes.c | 12 +- probes/lttng-kretprobes.c | 24 +- probes/lttng-tracepoint-event-impl.h | 89 ++-- probes/lttng-uprobes.c | 12 +- 50 files changed, 1026 insertions(+), 871 deletions(-) diff --git a/instrumentation/events/lttng-module/net.h b/instrumentation/events/lttng-module/net.h index 66fd1f59..55aba4e0 100644 --- a/instrumentation/events/lttng-module/net.h +++ b/instrumentation/events/lttng-module/net.h @@ -138,34 +138,42 @@ static struct lttng_event_field transport_fields[] = { [0] = { .name = "unknown", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(emptyfields), - .u._struct.fields = emptyfields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(emptyfields), + .u.struct_nestable.fields = emptyfields, + .u.struct_nestable.alignment = 0, }, + .nofilter = 1, }, [1] = { .name = "tcp", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(tcpfields), - .u._struct.fields = tcpfields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(tcpfields), + .u.struct_nestable.fields = tcpfields, + .u.struct_nestable.alignment = 0, }, + .nofilter = 1, }, [2] = { .name = "udp", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(udpfields), - .u._struct.fields = udpfields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(udpfields), + .u.struct_nestable.fields = udpfields, + .u.struct_nestable.alignment = 0, }, + .nofilter = 1, }, [3] = { .name = "icmp", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(icmpfields), - .u._struct.fields = icmpfields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(icmpfields), + .u.struct_nestable.fields = icmpfields, + .u.struct_nestable.alignment = 0, }, + .nofilter = 1, }, }; @@ -341,18 +349,13 @@ static struct lttng_event_field ipv4fields[] = { [7] = { .name = "protocol", .type = { - .atype = atype_enum, - .u.basic.enumeration.desc = + .atype = atype_enum_nestable, + .u.enum_nestable.desc = &proto_transport_header_type, - .u.basic.enumeration.container_type = { - .size = 8, - .alignment = 8, - .signedness = 0, - .reverse_byte_order = - __BIG_ENDIAN != __BYTE_ORDER, - .base = 10, - .encoding = lttng_encode_none, - }, + .u.enum_nestable.container_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, -1, + __BIG_ENDIAN, 10, none)), }, }, [8] = { @@ -363,47 +366,46 @@ static struct lttng_event_field ipv4fields[] = { [9] = { .name = "saddr", .type = { - .atype = atype_array, - .u.array.elem_type = - __type_integer(uint8_t, 0, 0, 0, - __BIG_ENDIAN, 10, none), - .u.array.length = 4, - .u.array.elem_alignment = lttng_alignof(uint8_t), + .atype = atype_array_nestable, + .u.array_nestable.elem_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, 0, + __BIG_ENDIAN, 10, none)), + .u.array_nestable.length = 4, + .u.array_nestable.alignment = lttng_alignof(uint8_t), }, }, [10] = { .name = "daddr", .type = { - .atype = atype_array, - .u.array.elem_type = - __type_integer(uint8_t, 0, 0, 0, - __BIG_ENDIAN, 10, none), - .u.array.length = 4, - .u.array.elem_alignment = lttng_alignof(uint8_t), + .atype = atype_array_nestable, + .u.array_nestable.elem_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, 0, + __BIG_ENDIAN, 10, none)), + .u.array_nestable.length = 4, + .u.array_nestable.alignment = lttng_alignof(uint8_t), }, }, [11] = { .name = "transport_header_type", .type = { - .atype = atype_enum, - .u.basic.enumeration.desc = &transport_header_type, - .u.basic.enumeration.container_type = { - .size = 8, - .alignment = 8, - .signedness = 0, - .reverse_byte_order = 0, - .base = 10, - .encoding = lttng_encode_none, - }, + .atype = atype_enum_nestable, + .u.enum_nestable.desc = &transport_header_type, + .u.enum_nestable.container_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, -1, + __BYTE_ORDER, 10, none)), }, }, [12] = { .name = "transport_header", .type = { - .atype = atype_variant, - .u.variant.tag_name = "transport_header_type", - .u.variant.choices = transport_fields, - .u.variant.nr_choices = ARRAY_SIZE(transport_fields), + .atype = atype_variant_nestable, + .u.variant_nestable.tag_name = "transport_header_type", + .u.variant_nestable.choices = transport_fields, + .u.variant_nestable.nr_choices = ARRAY_SIZE(transport_fields), + .u.variant_nestable.alignment = 0, }, }, }; @@ -422,12 +424,13 @@ static struct lttng_event_field ipv6fields[] = { [2] = { .name = "flow_lbl", .type = { - .atype = atype_array, - .u.array.elem_type = - __type_integer(uint8_t, 0, 0, 0, - __BIG_ENDIAN, 16, none), - .u.array.length = 3, - .u.array.elem_alignment = lttng_alignof(uint8_t), + .atype = atype_array_nestable, + .u.array_nestable.elem_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, 0, + __BIG_ENDIAN, 16, none)), + .u.array_nestable.length = 3, + .u.array_nestable.alignment = lttng_alignof(uint8_t), }, }, [3] = { @@ -438,18 +441,13 @@ static struct lttng_event_field ipv6fields[] = { [4] = { .name = "nexthdr", .type = { - .atype = atype_enum, - .u.basic.enumeration.desc = + .atype = atype_enum_nestable, + .u.enum_nestable.desc = &proto_transport_header_type, - .u.basic.enumeration.container_type = { - .size = 8, - .alignment = 8, - .signedness = 0, - .reverse_byte_order = - __BIG_ENDIAN != __BYTE_ORDER, - .base = 10, - .encoding = lttng_encode_none, - }, + .u.enum_nestable.container_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, -1, + __BIG_ENDIAN, 10, none)), }, }, [5] = { @@ -460,47 +458,46 @@ static struct lttng_event_field ipv6fields[] = { [6] = { .name = "saddr", .type = { - .atype = atype_array, - .u.array.elem_type = - __type_integer(uint16_t, 0, 0, 0, - __BIG_ENDIAN, 16, none), - .u.array.length = 8, - .u.array.elem_alignment = lttng_alignof(uint16_t), + .atype = atype_array_nestable, + .u.array_nestable.elem_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint16_t, 0, 0, 0, + __BIG_ENDIAN, 16, none)), + .u.array_nestable.length = 8, + .u.array_nestable.alignment = lttng_alignof(uint16_t), }, }, [7] = { .name = "daddr", .type = { - .atype = atype_array, - .u.array.elem_type = - __type_integer(uint16_t, 0, 0, 0, - __BIG_ENDIAN, 16, none), - .u.array.length = 8, - .u.array.elem_alignment = lttng_alignof(uint16_t), + .atype = atype_array_nestable, + .u.array_nestable.elem_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint16_t, 0, 0, 0, + __BIG_ENDIAN, 16, none)), + .u.array_nestable.length = 8, + .u.array_nestable.alignment = lttng_alignof(uint16_t), }, }, [8] = { .name = "transport_header_type", .type = { - .atype = atype_enum, - .u.basic.enumeration.desc = &transport_header_type, - .u.basic.enumeration.container_type = { - .size = 8, - .alignment = 8, - .signedness = 0, - .reverse_byte_order = 0, - .base = 10, - .encoding = lttng_encode_none, - }, + .atype = atype_enum_nestable, + .u.enum_nestable.desc = &transport_header_type, + .u.enum_nestable.container_type = + __LTTNG_COMPOUND_LITERAL(struct lttng_type, + __type_integer(uint8_t, 0, 0, -1, + __BYTE_ORDER, 10, none)), }, }, [9] = { .name = "transport_header", .type = { - .atype = atype_variant, - .u.variant.tag_name = "transport_header_type", - .u.variant.choices = transport_fields, - .u.variant.nr_choices = ARRAY_SIZE(transport_fields), + .atype = atype_variant_nestable, + .u.variant_nestable.tag_name = "transport_header_type", + .u.variant_nestable.choices = transport_fields, + .u.variant_nestable.nr_choices = ARRAY_SIZE(transport_fields), + .u.variant_nestable.alignment = 0, }, }, }; @@ -509,25 +506,28 @@ static struct lttng_event_field network_fields[] = { [0] = { .name = "unknown", .type = { - .atype = atype_struct, - .u._struct.nr_fields = 0, - .u._struct.fields = emptyfields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = 0, + .u.struct_nestable.fields = emptyfields, + .u.struct_nestable.alignment = 0, }, }, [1] = { .name = "ipv4", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(ipv4fields), - .u._struct.fields = ipv4fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(ipv4fields), + .u.struct_nestable.fields = ipv4fields, + .u.struct_nestable.alignment = 0, }, }, [2] = { .name = "ipv6", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(ipv6fields), - .u._struct.fields = ipv6fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(ipv6fields), + .u.struct_nestable.fields = ipv6fields, + .u.struct_nestable.alignment = 0, }, }, }; @@ -591,11 +591,14 @@ LTTNG_TRACEPOINT_EVENT_CLASS(net_dev_template, network_header_type, __get_network_header_type(skb)) ctf_custom_field( ctf_custom_type( - .atype = atype_variant, - .u.variant.tag_name = "network_header_type", - .u.variant.choices = network_fields, - .u.variant.nr_choices = - ARRAY_SIZE(network_fields), + { + .atype = atype_variant_nestable, + .u.variant_nestable.tag_name = "network_header_type", + .u.variant_nestable.choices = network_fields, + .u.variant_nestable.nr_choices = + ARRAY_SIZE(network_fields), + .u.variant_nestable.alignment = 0, + } ), network_header, ctf_custom_code( diff --git a/instrumentation/syscalls/headers/syscalls_pointers_override.h b/instrumentation/syscalls/headers/syscalls_pointers_override.h index d4c7ab04..89f2cd8e 100644 --- a/instrumentation/syscalls/headers/syscalls_pointers_override.h +++ b/instrumentation/syscalls/headers/syscalls_pointers_override.h @@ -149,25 +149,36 @@ end: ; /* Label at end of compound statement. */ \ #define LTTNG_SYSCALL_SELECT_fds_field_LE(name, input) \ ctf_custom_field( \ ctf_custom_type( \ - .atype = atype_sequence, \ - .u.sequence.length_type = __type_integer( \ - uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none), \ - .u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0, \ - __BYTE_ORDER, 16, none), \ + __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none) \ ), \ - name, \ + _ ## name ## _length, \ ctf_custom_code( \ - unsigned int src; \ - unsigned int nr_bytes_out = 0; \ - \ if (input) { \ ctf_integer_type(uint8_t, tp_locvar->nr_bytes) \ ctf_align(uint8_t) \ } else { \ ctf_integer_type(uint8_t, 0) \ ctf_align(uint8_t) \ - goto skip_##name; \ } \ + ) \ + ) \ + ctf_custom_field( \ + ctf_custom_type( \ + { \ + .atype = atype_sequence_nestable, \ + .u.sequence_nestable.length_name = "_" #name "_length", \ + .u.sequence_nestable.elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 16, none)), \ + .u.sequence_nestable.alignment = 0, \ + } \ + ), \ + name, \ + ctf_custom_code( \ + unsigned int src; \ + unsigned int nr_bytes_out = 0; \ + \ + if (!input) \ + goto skip_##name; \ \ for (src = 0; src < tp_locvar->nr_ulong; src++) { \ int dst; \ @@ -186,24 +197,34 @@ end: ; /* Label at end of compound statement. */ \ #define LTTNG_SYSCALL_SELECT_fds_field_BE(name, input) \ ctf_custom_field( \ ctf_custom_type( \ - .atype = atype_sequence, \ - .u.sequence.length_type = __type_integer( \ - uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none), \ - .u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0, \ - __BYTE_ORDER, 16, none), \ + __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 10, none) \ ), \ - name, \ + _ ## name ## _length, \ ctf_custom_code( \ - unsigned int src, nr_bytes_out = 0; \ - \ if (input) { \ ctf_integer_type(uint8_t, tp_locvar->nr_bytes) \ ctf_align(uint8_t) \ } else { \ ctf_integer_type(uint8_t, 0) \ ctf_align(uint8_t) \ - goto skip_##name; \ } \ + ) \ + ) \ + ctf_custom_field( \ + ctf_custom_type( \ + { \ + .atype = atype_sequence_nestable, \ + .u.sequence_nestable.elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(uint8_t, 0, 0, 0, __BYTE_ORDER, 16, none)), \ + .u.sequence_nestable.alignment = 0, \ + } \ + ), \ + name, \ + ctf_custom_code( \ + unsigned int src, nr_bytes_out = 0; \ + \ + if (!input) \ + goto skip_##name; \ \ for (src = 0; src < tp_locvar->nr_ulong; src++) { \ int dst; \ @@ -353,17 +374,19 @@ static struct lttng_event_field lttng_pollfd_fields[] = { [2] = { .name = "events", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields), - .u._struct.fields = lttng_pollfd_flag_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields), + .u.struct_nestable.fields = lttng_pollfd_flag_fields, + .u.struct_nestable.alignment = 0, } }, }; static struct lttng_type lttng_pollfd_elem = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields), - .u._struct.fields = lttng_pollfd_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_pollfd_fields), + .u.struct_nestable.fields = lttng_pollfd_fields, + .u.struct_nestable.alignment = 0, }; #endif /* ONCE_LTTNG_TRACE_POLL_H */ @@ -432,9 +455,11 @@ end: \ sc_in( \ ctf_custom_field( \ ctf_custom_type( \ - .atype = atype_sequence_compound, \ - .u.sequence_compound.length_name = "fds_length", \ - .u.sequence_compound.elem_type = <tng_pollfd_elem, \ + { \ + .atype = atype_sequence_nestable, \ + .u.sequence_nestable.length_name = "fds_length", \ + .u.sequence_nestable.elem_type = <tng_pollfd_elem, \ + } \ ), \ fds, \ ctf_custom_code( \ @@ -453,9 +478,11 @@ end: \ sc_out( \ ctf_custom_field( \ ctf_custom_type( \ - .atype = atype_sequence_compound, \ - .u.sequence_compound.length_name = "fds_length", \ - .u.sequence_compound.elem_type = <tng_pollfd_elem, \ + { \ + .atype = atype_sequence_nestable, \ + .u.sequence_nestable.length_name = "fds_length", \ + .u.sequence_nestable.elem_type = <tng_pollfd_elem, \ + } \ ), \ fds, \ ctf_custom_code( \ @@ -619,9 +646,10 @@ static struct lttng_event_field epoll_ctl_fields[] = { [0] = { .name = "data_union", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields), - .u._struct.fields = lttng_epoll_data_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields), + .u.struct_nestable.fields = lttng_epoll_data_fields, + .u.struct_nestable.alignment = 0, } }, [1] = { @@ -631,9 +659,10 @@ static struct lttng_event_field epoll_ctl_fields[] = { [2] = { .name = "events", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields), - .u._struct.fields = lttng_epoll_ctl_events_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields), + .u.struct_nestable.fields = lttng_epoll_ctl_events_fields, + .u.struct_nestable.alignment = 0, } }, }; @@ -662,9 +691,12 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl, sc_in( ctf_custom_field( ctf_custom_type( - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(epoll_ctl_fields), - .u._struct.fields = epoll_ctl_fields, + { + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(epoll_ctl_fields), + .u.struct_nestable.fields = epoll_ctl_fields, + .u.struct_nestable.alignment = 0, + } ), event, ctf_custom_code( @@ -697,9 +729,10 @@ static struct lttng_event_field lttng_epoll_wait_fields[] = { [0] = { .name = "data_union", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields), - .u._struct.fields = lttng_epoll_data_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields), + .u.struct_nestable.fields = lttng_epoll_data_fields, + .u.struct_nestable.alignment = 0, } }, [1] = { @@ -709,17 +742,19 @@ static struct lttng_event_field lttng_epoll_wait_fields[] = { [2] = { .name = "events", .type = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields), - .u._struct.fields = lttng_epoll_ctl_events_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields), + .u.struct_nestable.fields = lttng_epoll_ctl_events_fields, + .u.struct_nestable.alignment = 0, } }, }; static struct lttng_type lttng_epoll_wait_elem = { - .atype = atype_struct, - .u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields), - .u._struct.fields = lttng_epoll_wait_fields, + .atype = atype_struct_nestable, + .u.struct_nestable.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields), + .u.struct_nestable.fields = lttng_epoll_wait_fields, + .u.struct_nestable.alignment = 0, }; #endif /* ONCE_LTTNG_TRACE_EPOLL_H */ @@ -778,11 +813,13 @@ static struct lttng_type lttng_epoll_wait_elem = { #define LTTNG_SYSCALL_EPOLL_WAIT_fds_field \ ctf_custom_field( \ ctf_custom_type( \ - .atype = atype_sequence_compound, \ - .u.sequence_compound.length_name = \ - "fds_length", \ - .u.sequence_compound.elem_type = \ - <tng_epoll_wait_elem, \ + { \ + .atype = atype_sequence_nestable, \ + .u.sequence_nestable.length_name = \ + "fds_length", \ + .u.sequence_nestable.elem_type = \ + <tng_epoll_wait_elem, \ + } \ ), \ fds, \ ctf_custom_code( \ diff --git a/lttng-context-callstack-legacy-impl.h b/lttng-context-callstack-legacy-impl.h index 31942fd1..8d78fb95 100644 --- a/lttng-context-callstack-legacy-impl.h +++ b/lttng-context-callstack-legacy-impl.h @@ -36,6 +36,7 @@ struct field_data { struct lttng_cs_type { const char *name; + const char *length_name; const char *save_func_name; void (*save_func)(struct stack_trace *trace); }; @@ -43,11 +44,13 @@ struct lttng_cs_type { static struct lttng_cs_type cs_types[] = { { .name = "callstack_kernel", + .length_name = "_callstack_kernel_length", .save_func_name = "save_stack_trace", .save_func = NULL, }, { .name = "callstack_user", + .length_name = "_callstack_user_length", .save_func_name = "save_stack_trace_user", .save_func = NULL, }, @@ -59,6 +62,12 @@ const char *lttng_cs_ctx_mode_name(enum lttng_cs_ctx_modes mode) return cs_types[mode].name; } +static +const char *lttng_cs_ctx_mode_length_name(enum lttng_cs_ctx_modes mode) +{ + return cs_types[mode].length_name; +} + static int init_type(enum lttng_cs_ctx_modes mode) { @@ -130,14 +139,26 @@ struct stack_trace *stack_trace_context(struct lttng_ctx_field *field, return &cs->dispatch[buffer_nesting].stack_trace; } +static +size_t lttng_callstack_length_get_size(size_t offset, struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct lttng_channel *chan) +{ + size_t orig_offset = offset; + + offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); + offset += sizeof(unsigned int); + return offset - orig_offset; +} + /* * In order to reserve the correct size, the callstack is computed. The * resulting callstack is saved to be accessed in the record step. */ static -size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, - struct lib_ring_buffer_ctx *ctx, - struct lttng_channel *chan) +size_t lttng_callstack_sequence_get_size(size_t offset, struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct lttng_channel *chan) { struct stack_trace *trace; struct field_data *fdata = field->priv; @@ -146,8 +167,6 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, /* do not write data if no space is available */ trace = stack_trace_context(field, ctx); if (unlikely(!trace)) { - offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); - offset += sizeof(unsigned int); offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); return offset - orig_offset; } @@ -173,8 +192,6 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, && trace->entries[trace->nr_entries - 1] == ULONG_MAX) { trace->nr_entries--; } - offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); - offset += sizeof(unsigned int); offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); offset += sizeof(unsigned long) * trace->nr_entries; /* Add our own ULONG_MAX delimiter to show incomplete stack. */ @@ -184,26 +201,38 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, } static -void lttng_callstack_record(struct lttng_ctx_field *field, +void lttng_callstack_length_record(struct lttng_ctx_field *field, struct lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { struct stack_trace *trace = stack_trace_context(field, ctx); unsigned int nr_seq_entries; + lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); if (unlikely(!trace)) { nr_seq_entries = 0; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); - chan->ops->event_write(ctx, &nr_seq_entries, sizeof(unsigned int)); - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); + } else { + nr_seq_entries = trace->nr_entries; + if (trace->nr_entries == trace->max_entries) + nr_seq_entries++; + } + chan->ops->event_write(ctx, &nr_seq_entries, sizeof(unsigned int)); +} +static +void lttng_callstack_sequence_record(struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct lttng_channel *chan) +{ + struct stack_trace *trace = stack_trace_context(field, ctx); + unsigned int nr_seq_entries; + + lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); + if (unlikely(!trace)) { return; } - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); nr_seq_entries = trace->nr_entries; if (trace->nr_entries == trace->max_entries) nr_seq_entries++; - chan->ops->event_write(ctx, &nr_seq_entries, sizeof(unsigned int)); - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); chan->ops->event_write(ctx, trace->entries, sizeof(unsigned long) * trace->nr_entries); /* Add our own ULONG_MAX delimiter to show incomplete stack. */ diff --git a/lttng-context-callstack-stackwalk-impl.h b/lttng-context-callstack-stackwalk-impl.h index 6a46c351..42f4273d 100644 --- a/lttng-context-callstack-stackwalk-impl.h +++ b/lttng-context-callstack-stackwalk-impl.h @@ -53,6 +53,19 @@ const char *lttng_cs_ctx_mode_name(enum lttng_cs_ctx_modes mode) } } +static +const char *lttng_cs_ctx_mode_length_name(enum lttng_cs_ctx_modes mode) +{ + switch (mode) { + case CALLSTACK_KERNEL: + return "_callstack_kernel_length"; + case CALLSTACK_USER: + return "_callstack_user_length"; + default: + return NULL; + } +} + static int init_type_callstack_kernel(void) { @@ -142,14 +155,26 @@ struct lttng_stack_trace *stack_trace_context(struct lttng_ctx_field *field, return &cs->stack_trace[buffer_nesting]; } +static +size_t lttng_callstack_length_get_size(size_t offset, struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct lttng_channel *chan) +{ + size_t orig_offset = offset; + + offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); + offset += sizeof(unsigned int); + return offset - orig_offset; +} + /* * In order to reserve the correct size, the callstack is computed. The * resulting callstack is saved to be accessed in the record step. */ static -size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, - struct lib_ring_buffer_ctx *ctx, - struct lttng_channel *chan) +size_t lttng_callstack_sequence_get_size(size_t offset, struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct lttng_channel *chan) { struct lttng_stack_trace *trace; struct field_data *fdata = field->priv; @@ -158,8 +183,6 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, /* do not write data if no space is available */ trace = stack_trace_context(field, ctx); if (unlikely(!trace)) { - offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); - offset += sizeof(unsigned int); offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); return offset - orig_offset; } @@ -188,8 +211,6 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, * If the array is filled, add our own marker to show that the * stack is incomplete. */ - offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); - offset += sizeof(unsigned int); offset += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); offset += sizeof(unsigned long) * trace->nr_entries; /* Add our own ULONG_MAX delimiter to show incomplete stack. */ @@ -199,26 +220,39 @@ size_t lttng_callstack_get_size(size_t offset, struct lttng_ctx_field *field, } static -void lttng_callstack_record(struct lttng_ctx_field *field, +void lttng_callstack_length_record(struct lttng_ctx_field *field, struct lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { struct lttng_stack_trace *trace = stack_trace_context(field, ctx); unsigned int nr_seq_entries; + lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); if (unlikely(!trace)) { nr_seq_entries = 0; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); - chan->ops->event_write(ctx, &nr_seq_entries, sizeof(unsigned int)); - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); + } else { + nr_seq_entries = trace->nr_entries; + if (trace->nr_entries == MAX_ENTRIES) + nr_seq_entries++; + } + chan->ops->event_write(ctx, &nr_seq_entries, sizeof(unsigned int)); +} + +static +void lttng_callstack_sequence_record(struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct lttng_channel *chan) +{ + struct lttng_stack_trace *trace = stack_trace_context(field, ctx); + unsigned int nr_seq_entries; + + lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); + if (unlikely(!trace)) { return; } - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned int)); nr_seq_entries = trace->nr_entries; if (trace->nr_entries == MAX_ENTRIES) nr_seq_entries++; - chan->ops->event_write(ctx, &nr_seq_entries, sizeof(unsigned int)); - lib_ring_buffer_align_ctx(ctx, lttng_alignof(unsigned long)); chan->ops->event_write(ctx, trace->entries, sizeof(unsigned long) * trace->nr_entries); /* Add our own ULONG_MAX delimiter to show incomplete stack. */ diff --git a/lttng-context-callstack.c b/lttng-context-callstack.c index 881c36e5..317efdf4 100644 --- a/lttng-context-callstack.c +++ b/lttng-context-callstack.c @@ -48,6 +48,7 @@ #include "wrapper/ringbuffer/frontend.h" #include "wrapper/vmalloc.h" #include "lttng-tracer.h" +#include "lttng-endian.h" #ifdef CONFIG_ARCH_STACKWALK #include "lttng-context-callstack-stackwalk-impl.h" @@ -87,28 +88,38 @@ error_alloc: } static -void lttng_callstack_destroy(struct lttng_ctx_field *field) +void lttng_callstack_sequence_destroy(struct lttng_ctx_field *field) { struct field_data *fdata = field->priv; field_data_free(fdata); } +static const struct lttng_type sequence_elem_type = + __type_integer(unsigned long, 0, 0, -1, __BYTE_ORDER, 16, none); + static int __lttng_add_callstack_generic(struct lttng_ctx **ctx, enum lttng_cs_ctx_modes mode) { const char *ctx_name = lttng_cs_ctx_mode_name(mode); - struct lttng_ctx_field *field; + const char *ctx_length_name = lttng_cs_ctx_mode_length_name(mode); + struct lttng_ctx_field *length_field, *sequence_field; + struct lttng_event_field *field; struct field_data *fdata; int ret; ret = init_type(mode); if (ret) return ret; - field = lttng_append_context(ctx); - if (!field) + length_field = lttng_append_context(ctx); + if (!length_field) + return -ENOMEM; + sequence_field = lttng_append_context(ctx); + if (!sequence_field) { + lttng_remove_context_field(ctx, length_field); return -ENOMEM; + } if (lttng_find_context(*ctx, ctx_name)) { ret = -EEXIST; goto error_find; @@ -119,35 +130,36 @@ int __lttng_add_callstack_generic(struct lttng_ctx **ctx, goto error_create; } - field->event_field.name = ctx_name; - field->event_field.type.atype = atype_sequence; - field->event_field.type.u.sequence.elem_type.atype = atype_integer; - field->event_field.type.u.sequence.elem_type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - field->event_field.type.u.sequence.elem_type.u.basic.integer.alignment = lttng_alignof(long) * CHAR_BIT; - field->event_field.type.u.sequence.elem_type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); - field->event_field.type.u.sequence.elem_type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.sequence.elem_type.u.basic.integer.base = 16; - field->event_field.type.u.sequence.elem_type.u.basic.integer.encoding = lttng_encode_none; - - field->event_field.type.u.sequence.length_type.atype = atype_integer; - field->event_field.type.u.sequence.length_type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.sequence.length_type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.sequence.length_type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.sequence.length_type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.sequence.length_type.u.basic.integer.base = 10; - field->event_field.type.u.sequence.length_type.u.basic.integer.encoding = lttng_encode_none; - - field->get_size_arg = lttng_callstack_get_size; - field->record = lttng_callstack_record; - field->priv = fdata; - field->destroy = lttng_callstack_destroy; + field = &length_field->event_field; + field->name = ctx_length_name; + field->type.atype = atype_integer; + field->type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->type.u.integer.reverse_byte_order = 0; + field->type.u.integer.base = 10; + field->type.u.integer.encoding = lttng_encode_none; + length_field->get_size_arg = lttng_callstack_length_get_size; + length_field->record = lttng_callstack_length_record; + + field = &sequence_field->event_field; + field->name = ctx_name; + field->type.atype = atype_sequence_nestable; + field->type.u.sequence_nestable.elem_type = &sequence_elem_type; + field->type.u.sequence_nestable.alignment = 0; + sequence_field->get_size_arg = lttng_callstack_sequence_get_size; + sequence_field->record = lttng_callstack_sequence_record; + sequence_field->priv = fdata; + sequence_field->destroy = lttng_callstack_sequence_destroy; + wrapper_vmalloc_sync_all(); return 0; error_create: field_data_free(fdata); error_find: - lttng_remove_context_field(ctx, field); + lttng_remove_context_field(ctx, sequence_field); + lttng_remove_context_field(ctx, length_field); return ret; } diff --git a/lttng-context-cgroup-ns.c b/lttng-context-cgroup-ns.c index 35accb85..a7f4e80f 100644 --- a/lttng-context-cgroup-ns.c +++ b/lttng-context-cgroup-ns.c @@ -87,12 +87,12 @@ int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "cgroup_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = cgroup_ns_get_size; field->record = cgroup_ns_record; field->get_value = cgroup_ns_get_value; diff --git a/lttng-context-cpu-id.c b/lttng-context-cpu-id.c index de3d3c1f..d3d55b88 100644 --- a/lttng-context-cpu-id.c +++ b/lttng-context-cpu-id.c @@ -58,12 +58,12 @@ int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "cpu_id"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = cpu_id_get_size; field->record = cpu_id_record; field->get_value = cpu_id_get_value; diff --git a/lttng-context-egid.c b/lttng-context-egid.c index 43744a6a..fcd01461 100644 --- a/lttng-context-egid.c +++ b/lttng-context-egid.c @@ -60,12 +60,12 @@ int lttng_add_egid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "egid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = egid_get_size; field->record = egid_record; field->get_value = egid_get_value; diff --git a/lttng-context-euid.c b/lttng-context-euid.c index fe0fb39d..b4b72184 100644 --- a/lttng-context-euid.c +++ b/lttng-context-euid.c @@ -60,12 +60,12 @@ int lttng_add_euid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "euid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = euid_get_size; field->record = euid_record; field->get_value = euid_get_value; diff --git a/lttng-context-gid.c b/lttng-context-gid.c index 8348a9d0..586934ed 100644 --- a/lttng-context-gid.c +++ b/lttng-context-gid.c @@ -60,12 +60,12 @@ int lttng_add_gid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "gid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = gid_get_size; field->record = gid_record; field->get_value = gid_get_value; diff --git a/lttng-context-hostname.c b/lttng-context-hostname.c index 6f9d130c..0bbb1c78 100644 --- a/lttng-context-hostname.c +++ b/lttng-context-hostname.c @@ -75,6 +75,9 @@ void hostname_get_value(struct lttng_ctx_field *field, value->str = hostname; } +static const struct lttng_type hostname_array_elem_type = + __type_integer(char, 0, 0, -1, __BYTE_ORDER, 10, UTF8); + int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx) { struct lttng_ctx_field *field; @@ -87,15 +90,11 @@ int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx) return -EEXIST; } field->event_field.name = "hostname"; - field->event_field.type.atype = atype_array; - field->event_field.type.u.array.elem_type.atype = atype_integer; - field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT; - field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT; - field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char); - field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.array.elem_type.u.basic.integer.base = 10; - field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8; - field->event_field.type.u.array.length = LTTNG_HOSTNAME_CTX_LEN; + field->event_field.type.atype = atype_array_nestable; + field->event_field.type.u.array_nestable.elem_type = + &hostname_array_elem_type; + field->event_field.type.u.array_nestable.length = LTTNG_HOSTNAME_CTX_LEN; + field->event_field.type.u.array_nestable.alignment = 0; field->get_size = hostname_get_size; field->record = hostname_record; diff --git a/lttng-context-interruptible.c b/lttng-context-interruptible.c index 24866a4a..c07cba18 100644 --- a/lttng-context-interruptible.c +++ b/lttng-context-interruptible.c @@ -65,12 +65,12 @@ int lttng_add_interruptible_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "interruptible"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(int8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(int8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(int8_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(int8_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(int8_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(int8_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = interruptible_get_size; field->record = interruptible_record; field->get_value = interruptible_get_value; diff --git a/lttng-context-ipc-ns.c b/lttng-context-ipc-ns.c index 0673044d..cccd9766 100644 --- a/lttng-context-ipc-ns.c +++ b/lttng-context-ipc-ns.c @@ -86,12 +86,12 @@ int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "ipc_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = ipc_ns_get_size; field->record = ipc_ns_record; field->get_value = ipc_ns_get_value; diff --git a/lttng-context-migratable.c b/lttng-context-migratable.c index 95f868e2..1a0dc4a1 100644 --- a/lttng-context-migratable.c +++ b/lttng-context-migratable.c @@ -58,12 +58,12 @@ int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "migratable"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uint8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uint8_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uint8_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uint8_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = migratable_get_size; field->record = migratable_record; field->get_value = migratable_get_value; diff --git a/lttng-context-mnt-ns.c b/lttng-context-mnt-ns.c index 9443f409..02940139 100644 --- a/lttng-context-mnt-ns.c +++ b/lttng-context-mnt-ns.c @@ -88,12 +88,12 @@ int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "mnt_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = mnt_ns_get_size; field->record = mnt_ns_record; field->get_value = mnt_ns_get_value; diff --git a/lttng-context-need-reschedule.c b/lttng-context-need-reschedule.c index 3f52d7bd..9a51f0c6 100644 --- a/lttng-context-need-reschedule.c +++ b/lttng-context-need-reschedule.c @@ -58,12 +58,12 @@ int lttng_add_need_reschedule_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "need_reschedule"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uint8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uint8_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uint8_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uint8_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = need_reschedule_get_size; field->record = need_reschedule_record; field->get_value = need_reschedule_get_value; diff --git a/lttng-context-net-ns.c b/lttng-context-net-ns.c index 2222080a..4584991f 100644 --- a/lttng-context-net-ns.c +++ b/lttng-context-net-ns.c @@ -87,12 +87,12 @@ int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "net_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = net_ns_get_size; field->record = net_ns_record; field->get_value = net_ns_get_value; diff --git a/lttng-context-nice.c b/lttng-context-nice.c index 035b7c05..89283d0f 100644 --- a/lttng-context-nice.c +++ b/lttng-context-nice.c @@ -58,12 +58,12 @@ int lttng_add_nice_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "nice"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = nice_get_size; field->record = nice_record; field->get_value = nice_get_value; diff --git a/lttng-context-perf-counters.c b/lttng-context-perf-counters.c index 03de7b42..1c5ab9fb 100644 --- a/lttng-context-perf-counters.c +++ b/lttng-context-perf-counters.c @@ -310,12 +310,12 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, field->event_field.name = name_alloc; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uint64_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uint64_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uint64_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uint64_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uint64_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uint64_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = perf_counter_get_size; field->record = perf_counter_record; field->u.perf_counter = perf_field; diff --git a/lttng-context-pid-ns.c b/lttng-context-pid-ns.c index c749b678..e4d3a3a3 100644 --- a/lttng-context-pid-ns.c +++ b/lttng-context-pid-ns.c @@ -88,12 +88,12 @@ int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "pid_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = pid_ns_get_size; field->record = pid_ns_record; field->get_value = pid_ns_get_value; diff --git a/lttng-context-pid.c b/lttng-context-pid.c index b5d9c5c9..3cdc5128 100644 --- a/lttng-context-pid.c +++ b/lttng-context-pid.c @@ -58,12 +58,12 @@ int lttng_add_pid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "pid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = pid_get_size; field->record = pid_record; field->get_value = pid_get_value; diff --git a/lttng-context-ppid.c b/lttng-context-ppid.c index b75b099f..8935fad0 100644 --- a/lttng-context-ppid.c +++ b/lttng-context-ppid.c @@ -80,12 +80,12 @@ int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "ppid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = ppid_get_size; field->record = ppid_record; field->get_value = ppid_get_value; diff --git a/lttng-context-preemptible.c b/lttng-context-preemptible.c index c1c293be..6a40f03a 100644 --- a/lttng-context-preemptible.c +++ b/lttng-context-preemptible.c @@ -76,12 +76,12 @@ int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "preemptible"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uint8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uint8_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uint8_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uint8_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = preemptible_get_size; field->record = preemptible_record; field->get_value = preemptible_get_value; diff --git a/lttng-context-prio.c b/lttng-context-prio.c index b3e942d1..9cd843d5 100644 --- a/lttng-context-prio.c +++ b/lttng-context-prio.c @@ -79,12 +79,12 @@ int lttng_add_prio_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "prio"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = prio_get_size; field->record = prio_record; field->get_value = prio_get_value; diff --git a/lttng-context-procname.c b/lttng-context-procname.c index f1605a0a..8e4bbf97 100644 --- a/lttng-context-procname.c +++ b/lttng-context-procname.c @@ -14,6 +14,7 @@ #include #include #include +#include static size_t procname_get_size(size_t offset) @@ -46,6 +47,9 @@ void procname_get_value(struct lttng_ctx_field *field, value->str = current->comm; } +static const struct lttng_type procname_array_elem_type = + __type_integer(char, 0, 0, -1, __BYTE_ORDER, 10, UTF8); + int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) { struct lttng_ctx_field *field; @@ -58,15 +62,10 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) return -EEXIST; } field->event_field.name = "procname"; - field->event_field.type.atype = atype_array; - field->event_field.type.u.array.elem_type.atype = atype_integer; - field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT; - field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT; - field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char); - field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.array.elem_type.u.basic.integer.base = 10; - field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8; - field->event_field.type.u.array.length = sizeof(current->comm); + field->event_field.type.atype = atype_array_nestable; + field->event_field.type.u.array_nestable.elem_type = &procname_array_elem_type; + field->event_field.type.u.array_nestable.length = sizeof(current->comm); + field->event_field.type.u.array_nestable.alignment = 0; field->get_size = procname_get_size; field->record = procname_record; diff --git a/lttng-context-sgid.c b/lttng-context-sgid.c index e6f1a636..4f58a14f 100644 --- a/lttng-context-sgid.c +++ b/lttng-context-sgid.c @@ -60,12 +60,12 @@ int lttng_add_sgid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "sgid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = sgid_get_size; field->record = sgid_record; field->get_value = sgid_get_value; diff --git a/lttng-context-suid.c b/lttng-context-suid.c index 9b0f44d6..4b8477e5 100644 --- a/lttng-context-suid.c +++ b/lttng-context-suid.c @@ -60,12 +60,12 @@ int lttng_add_suid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "suid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = suid_get_size; field->record = suid_record; field->get_value = suid_get_value; diff --git a/lttng-context-tid.c b/lttng-context-tid.c index 736d13d8..5f8e68fa 100644 --- a/lttng-context-tid.c +++ b/lttng-context-tid.c @@ -61,12 +61,12 @@ int lttng_add_tid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "tid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = tid_get_size; field->record = tid_record; field->get_value = tid_get_value; diff --git a/lttng-context-uid.c b/lttng-context-uid.c index c0e9c8f7..c7a2bb18 100644 --- a/lttng-context-uid.c +++ b/lttng-context-uid.c @@ -60,12 +60,12 @@ int lttng_add_uid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "uid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = uid_get_size; field->record = uid_record; field->get_value = uid_get_value; diff --git a/lttng-context-user-ns.c b/lttng-context-user-ns.c index 940e4210..ff56f551 100644 --- a/lttng-context-user-ns.c +++ b/lttng-context-user-ns.c @@ -72,12 +72,12 @@ int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "user_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = user_ns_get_size; field->record = user_ns_record; field->get_value = user_ns_get_value; diff --git a/lttng-context-uts-ns.c b/lttng-context-uts-ns.c index 7f80bbdf..67c42764 100644 --- a/lttng-context-uts-ns.c +++ b/lttng-context-uts-ns.c @@ -86,12 +86,12 @@ int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "uts_ns"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned int); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(unsigned int) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned int); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = uts_ns_get_size; field->record = uts_ns_record; field->get_value = uts_ns_get_value; diff --git a/lttng-context-vegid.c b/lttng-context-vegid.c index 5d970565..501b01e6 100644 --- a/lttng-context-vegid.c +++ b/lttng-context-vegid.c @@ -60,12 +60,12 @@ int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vegid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vegid_get_size; field->record = vegid_record; field->get_value = vegid_get_value; diff --git a/lttng-context-veuid.c b/lttng-context-veuid.c index c1c840e1..a8810a77 100644 --- a/lttng-context-veuid.c +++ b/lttng-context-veuid.c @@ -60,12 +60,12 @@ int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "veuid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = veuid_get_size; field->record = veuid_record; field->get_value = veuid_get_value; diff --git a/lttng-context-vgid.c b/lttng-context-vgid.c index cb924205..92ac567b 100644 --- a/lttng-context-vgid.c +++ b/lttng-context-vgid.c @@ -60,12 +60,12 @@ int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vgid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vgid_get_size; field->record = vgid_record; field->get_value = vgid_get_value; diff --git a/lttng-context-vpid.c b/lttng-context-vpid.c index 6b8b7f1f..31a2c15e 100644 --- a/lttng-context-vpid.c +++ b/lttng-context-vpid.c @@ -73,12 +73,12 @@ int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vpid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vpid_get_size; field->record = vpid_record; field->get_value = vpid_get_value; diff --git a/lttng-context-vppid.c b/lttng-context-vppid.c index 691cf4fd..43bfcc12 100644 --- a/lttng-context-vppid.c +++ b/lttng-context-vppid.c @@ -102,12 +102,12 @@ int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vppid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vppid_get_size; field->record = vppid_record; field->get_value = vppid_get_value; diff --git a/lttng-context-vsgid.c b/lttng-context-vsgid.c index 9f48efb4..20987dde 100644 --- a/lttng-context-vsgid.c +++ b/lttng-context-vsgid.c @@ -60,12 +60,12 @@ int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vsgid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vsgid_get_size; field->record = vsgid_record; field->get_value = vsgid_get_value; diff --git a/lttng-context-vsuid.c b/lttng-context-vsuid.c index 491d8e37..7cefd535 100644 --- a/lttng-context-vsuid.c +++ b/lttng-context-vsuid.c @@ -60,12 +60,12 @@ int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vsuid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vsuid_get_size; field->record = vsuid_record; field->get_value = vsuid_get_value; diff --git a/lttng-context-vtid.c b/lttng-context-vtid.c index c6baeb16..a7da7d2e 100644 --- a/lttng-context-vtid.c +++ b/lttng-context-vtid.c @@ -73,12 +73,12 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vtid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vtid_get_size; field->record = vtid_record; field->get_value = vtid_get_value; diff --git a/lttng-context-vuid.c b/lttng-context-vuid.c index 826e2bff..427ada71 100644 --- a/lttng-context-vuid.c +++ b/lttng-context-vuid.c @@ -60,12 +60,12 @@ int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx) } field->event_field.name = "vuid"; field->event_field.type.atype = atype_integer; - field->event_field.type.u.basic.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.basic.integer.reverse_byte_order = 0; - field->event_field.type.u.basic.integer.base = 10; - field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field.type.u.integer.reverse_byte_order = 0; + field->event_field.type.u.integer.base = 10; + field->event_field.type.u.integer.encoding = lttng_encode_none; field->get_size = vuid_get_size; field->record = vuid_record; field->get_value = vuid_get_value; diff --git a/lttng-context.c b/lttng-context.c index 825eda5e..54fa4478 100644 --- a/lttng-context.c +++ b/lttng-context.c @@ -112,95 +112,65 @@ void lttng_context_update(struct lttng_ctx *ctx) type = &ctx->fields[i].event_field.type; switch (type->atype) { case atype_integer: - field_align = type->u.basic.integer.alignment; + field_align = type->u.integer.alignment; break; - case atype_array: - case atype_array_bitfield: + case atype_array_nestable: { - struct lttng_basic_type *btype; + const struct lttng_type *nested_type; - btype = &type->u.array.elem_type; - switch (btype->atype) { + nested_type = type->u.array_nestable.elem_type; + switch (nested_type->atype) { case atype_integer: - field_align = btype->u.basic.integer.alignment; + field_align = nested_type->u.integer.alignment; break; case atype_string: break; - case atype_array: - case atype_sequence: - case atype_array_bitfield: - case atype_sequence_bitfield: - case atype_struct: - case atype_array_compound: - case atype_sequence_compound: - case atype_variant: + case atype_array_nestable: + case atype_sequence_nestable: + case atype_struct_nestable: + case atype_variant_nestable: default: WARN_ON_ONCE(1); break; } + field_align = max_t(size_t, field_align, + type->u.array_nestable.alignment); break; } - case atype_sequence: - case atype_sequence_bitfield: + case atype_sequence_nestable: { - struct lttng_basic_type *btype; + const struct lttng_type *nested_type; - btype = &type->u.sequence.length_type; - switch (btype->atype) { + nested_type = type->u.sequence_nestable.elem_type; + switch (nested_type->atype) { case atype_integer: - field_align = btype->u.basic.integer.alignment; - break; - - case atype_string: - case atype_array: - case atype_sequence: - case atype_array_bitfield: - case atype_sequence_bitfield: - case atype_struct: - case atype_array_compound: - case atype_sequence_compound: - case atype_variant: - default: - WARN_ON_ONCE(1); - break; - } - - btype = &type->u.sequence.elem_type; - switch (btype->atype) { - case atype_integer: - field_align = max_t(size_t, - field_align, - btype->u.basic.integer.alignment); + field_align = nested_type->u.integer.alignment; break; case atype_string: break; - case atype_array: - case atype_sequence: - case atype_array_bitfield: - case atype_sequence_bitfield: - case atype_struct: - case atype_array_compound: - case atype_sequence_compound: - case atype_variant: + case atype_array_nestable: + case atype_sequence_nestable: + case atype_struct_nestable: + case atype_variant_nestable: default: WARN_ON_ONCE(1); break; } + field_align = max_t(size_t, field_align, + type->u.sequence_nestable.alignment); break; } case atype_string: break; - case atype_struct: - case atype_array_compound: - case atype_sequence_compound: - case atype_variant: + case atype_struct_nestable: + case atype_variant_nestable: break; - case atype_enum: + case atype_enum_nestable: default: WARN_ON_ONCE(1); break; diff --git a/lttng-events.c b/lttng-events.c index c8e4cd76..c14ea3f2 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -71,6 +71,10 @@ int _lttng_session_metadata_statedump(struct lttng_session *session); static void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream); static +int _lttng_type_statedump(struct lttng_session *session, + const struct lttng_type *type, + size_t nesting); +static int _lttng_field_statedump(struct lttng_session *session, const struct lttng_event_field *field, size_t nesting); @@ -1754,6 +1758,45 @@ int print_tabs(struct lttng_session *session, size_t nesting) return 0; } +static +int lttng_field_name_statedump(struct lttng_session *session, + const struct lttng_event_field *field, + size_t nesting) +{ + return lttng_metadata_printf(session, " _%s;\n", field->name); +} + +static +int _lttng_integer_type_statedump(struct lttng_session *session, + const struct lttng_type *type, + size_t nesting) +{ + int ret; + + WARN_ON_ONCE(type->atype != atype_integer); + ret = print_tabs(session, nesting); + if (ret) + return ret; + ret = lttng_metadata_printf(session, + "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s }", + type->u.integer.size, + type->u.integer.alignment, + type->u.integer.signedness, + (type->u.integer.encoding == lttng_encode_none) + ? "none" + : (type->u.integer.encoding == lttng_encode_UTF8) + ? "UTF8" + : "ASCII", + type->u.integer.base, +#if __BYTE_ORDER == __BIG_ENDIAN + type->u.integer.reverse_byte_order ? " byte_order = le;" : "" +#else + type->u.integer.reverse_byte_order ? " byte_order = be;" : "" +#endif + ); + return ret; +} + /* * Must be called with sessions_mutex held. */ @@ -1764,6 +1807,9 @@ int _lttng_struct_type_statedump(struct lttng_session *session, { int ret; uint32_t i, nr_fields; + unsigned int alignment; + + WARN_ON_ONCE(type->atype != atype_struct_nestable); ret = print_tabs(session, nesting); if (ret) @@ -1772,11 +1818,11 @@ int _lttng_struct_type_statedump(struct lttng_session *session, "struct {\n"); if (ret) return ret; - nr_fields = type->u._struct.nr_fields; + nr_fields = type->u.struct_nestable.nr_fields; for (i = 0; i < nr_fields; i++) { const struct lttng_event_field *iter_field; - iter_field = &type->u._struct.fields[i]; + iter_field = &type->u.struct_nestable.fields[i]; ret = _lttng_field_statedump(session, iter_field, nesting + 1); if (ret) return ret; @@ -1784,8 +1830,15 @@ int _lttng_struct_type_statedump(struct lttng_session *session, ret = print_tabs(session, nesting); if (ret) return ret; - ret = lttng_metadata_printf(session, - "}"); + alignment = type->u.struct_nestable.alignment; + if (alignment) { + ret = lttng_metadata_printf(session, + "} align(%u)", + alignment); + } else { + ret = lttng_metadata_printf(session, + "}"); + } return ret; } @@ -1793,7 +1846,7 @@ int _lttng_struct_type_statedump(struct lttng_session *session, * Must be called with sessions_mutex held. */ static -int _lttng_struct_statedump(struct lttng_session *session, +int _lttng_struct_field_statedump(struct lttng_session *session, const struct lttng_event_field *field, size_t nesting) { @@ -1803,10 +1856,7 @@ int _lttng_struct_statedump(struct lttng_session *session, &field->type, nesting); if (ret) return ret; - ret = lttng_metadata_printf(session, - "_%s;\n", - field->name); - return ret; + return lttng_field_name_statedump(session, field, nesting); } /* @@ -1820,19 +1870,25 @@ int _lttng_variant_type_statedump(struct lttng_session *session, int ret; uint32_t i, nr_choices; + WARN_ON_ONCE(type->atype != atype_variant_nestable); + /* + * CTF 1.8 does not allow expressing nonzero variant alignment in a nestable way. + */ + if (type->u.variant_nestable.alignment != 0) + return -EINVAL; ret = print_tabs(session, nesting); if (ret) return ret; ret = lttng_metadata_printf(session, "variant <_%s> {\n", - type->u.variant.tag_name); + type->u.variant_nestable.tag_name); if (ret) return ret; - nr_choices = type->u.variant.nr_choices; + nr_choices = type->u.variant_nestable.nr_choices; for (i = 0; i < nr_choices; i++) { const struct lttng_event_field *iter_field; - iter_field = &type->u.variant.choices[i]; + iter_field = &type->u.variant_nestable.choices[i]; ret = _lttng_field_statedump(session, iter_field, nesting + 1); if (ret) return ret; @@ -1849,7 +1905,7 @@ int _lttng_variant_type_statedump(struct lttng_session *session, * Must be called with sessions_mutex held. */ static -int _lttng_variant_statedump(struct lttng_session *session, +int _lttng_variant_field_statedump(struct lttng_session *session, const struct lttng_event_field *field, size_t nesting) { @@ -1859,43 +1915,54 @@ int _lttng_variant_statedump(struct lttng_session *session, &field->type, nesting); if (ret) return ret; - ret = lttng_metadata_printf(session, - "_%s;\n", - field->name); - return ret; + return lttng_field_name_statedump(session, field, nesting); } /* * Must be called with sessions_mutex held. */ static -int _lttng_array_compound_statedump(struct lttng_session *session, +int _lttng_array_field_statedump(struct lttng_session *session, const struct lttng_event_field *field, size_t nesting) { int ret; const struct lttng_type *elem_type; - /* Only array of structures and variants are currently supported. */ - elem_type = field->type.u.array_compound.elem_type; - switch (elem_type->atype) { - case atype_struct: - ret = _lttng_struct_type_statedump(session, elem_type, nesting); + WARN_ON_ONCE(field->type.atype != atype_array_nestable); + + if (field->type.u.array_nestable.alignment) { + ret = print_tabs(session, nesting); if (ret) return ret; - break; - case atype_variant: - ret = _lttng_variant_type_statedump(session, elem_type, nesting); + ret = lttng_metadata_printf(session, + "struct { } align(%u) _%s_padding;\n", + field->type.u.array_nestable.alignment * CHAR_BIT, + field->name); + if (ret) + return ret; + } + /* + * Nested compound types: Only array of structures and variants are + * currently supported. + */ + elem_type = field->type.u.array_nestable.elem_type; + switch (elem_type->atype) { + case atype_integer: + case atype_struct_nestable: + case atype_variant_nestable: + ret = _lttng_type_statedump(session, elem_type, nesting); if (ret) return ret; break; + default: return -EINVAL; } ret = lttng_metadata_printf(session, " _%s[%u];\n", field->name, - field->type.u.array_compound.length); + field->type.u.array_nestable.length); return ret; } @@ -1903,7 +1970,7 @@ int _lttng_array_compound_statedump(struct lttng_session *session, * Must be called with sessions_mutex held. */ static -int _lttng_sequence_compound_statedump(struct lttng_session *session, +int _lttng_sequence_field_statedump(struct lttng_session *session, const struct lttng_event_field *field, size_t nesting) { @@ -1911,28 +1978,43 @@ int _lttng_sequence_compound_statedump(struct lttng_session *session, const char *length_name; const struct lttng_type *elem_type; - length_name = field->type.u.sequence_compound.length_name; + WARN_ON_ONCE(field->type.atype != atype_sequence_nestable); - /* Only array of structures and variants are currently supported. */ - elem_type = field->type.u.sequence_compound.elem_type; - switch (elem_type->atype) { - case atype_struct: - ret = _lttng_struct_type_statedump(session, elem_type, nesting); + length_name = field->type.u.sequence_nestable.length_name; + + if (field->type.u.sequence_nestable.alignment) { + ret = print_tabs(session, nesting); if (ret) return ret; - break; - case atype_variant: - ret = _lttng_variant_type_statedump(session, elem_type, nesting); + ret = lttng_metadata_printf(session, + "struct { } align(%u) _%s_padding;\n", + field->type.u.sequence_nestable.alignment * CHAR_BIT, + field->name); + if (ret) + return ret; + } + + /* + * Nested compound types: Only array of structures and variants are + * currently supported. + */ + elem_type = field->type.u.sequence_nestable.elem_type; + switch (elem_type->atype) { + case atype_integer: + case atype_struct_nestable: + case atype_variant_nestable: + ret = _lttng_type_statedump(session, elem_type, nesting); if (ret) return ret; break; + default: return -EINVAL; } ret = lttng_metadata_printf(session, " _%s[ _%s ];\n", field->name, - length_name); + field->type.u.sequence_nestable.length_name); return ret; } @@ -1940,41 +2022,35 @@ int _lttng_sequence_compound_statedump(struct lttng_session *session, * Must be called with sessions_mutex held. */ static -int _lttng_enum_statedump(struct lttng_session *session, - const struct lttng_event_field *field, +int _lttng_enum_type_statedump(struct lttng_session *session, + const struct lttng_type *type, size_t nesting) { const struct lttng_enum_desc *enum_desc; - const struct lttng_integer_type *container_type; + const struct lttng_type *container_type; int ret; unsigned int i, nr_entries; - enum_desc = field->type.u.basic.enumeration.desc; - container_type = &field->type.u.basic.enumeration.container_type; + container_type = type->u.enum_nestable.container_type; + if (container_type->atype != atype_integer) { + ret = -EINVAL; + goto end; + } + enum_desc = type->u.enum_nestable.desc; nr_entries = enum_desc->nr_entries; ret = print_tabs(session, nesting); if (ret) goto end; - ret = lttng_metadata_printf(session, - "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n", - container_type->size, - container_type->alignment, - container_type->signedness, - (container_type->encoding == lttng_encode_none) - ? "none" - : (container_type->encoding == lttng_encode_UTF8) - ? "UTF8" - : "ASCII", - container_type->base, -#if __BYTE_ORDER == __BIG_ENDIAN - container_type->reverse_byte_order ? " byte_order = le;" : "" -#else - container_type->reverse_byte_order ? " byte_order = be;" : "" -#endif - ); + ret = lttng_metadata_printf(session, "enum : "); if (ret) - goto end; + goto end; + ret = _lttng_integer_type_statedump(session, container_type, 0); + if (ret) + goto end; + ret = lttng_metadata_printf(session, " {\n"); + if (ret) + goto end; /* Dump all entries */ for (i = 0; i < nr_entries; i++) { const struct lttng_enum_entry *entry = &enum_desc->entries[i]; @@ -2053,8 +2129,7 @@ int _lttng_enum_statedump(struct lttng_session *session, ret = print_tabs(session, nesting); if (ret) goto end; - ret = lttng_metadata_printf(session, "} _%s;\n", - field->name); + ret = lttng_metadata_printf(session, "}"); end: return ret; } @@ -2063,165 +2138,132 @@ end: * Must be called with sessions_mutex held. */ static -int _lttng_field_statedump(struct lttng_session *session, +int _lttng_enum_field_statedump(struct lttng_session *session, + const struct lttng_event_field *field, + size_t nesting) +{ + int ret; + + ret = _lttng_enum_type_statedump(session, &field->type, nesting); + if (ret) + return ret; + return lttng_field_name_statedump(session, field, nesting); +} + +static +int _lttng_integer_field_statedump(struct lttng_session *session, + const struct lttng_event_field *field, + size_t nesting) +{ + int ret; + + ret = _lttng_integer_type_statedump(session, &field->type, nesting); + if (ret) + return ret; + return lttng_field_name_statedump(session, field, nesting); +} + +static +int _lttng_string_type_statedump(struct lttng_session *session, + const struct lttng_type *type, + size_t nesting) +{ + int ret; + + WARN_ON_ONCE(type->atype != atype_string); + /* Default encoding is UTF8 */ + ret = print_tabs(session, nesting); + if (ret) + return ret; + ret = lttng_metadata_printf(session, + "string%s", + type->u.string.encoding == lttng_encode_ASCII ? + " { encoding = ASCII; }" : ""); + return ret; +} + +static +int _lttng_string_field_statedump(struct lttng_session *session, const struct lttng_event_field *field, size_t nesting) +{ + int ret; + + WARN_ON_ONCE(field->type.atype != atype_string); + ret = _lttng_string_type_statedump(session, &field->type, nesting); + if (ret) + return ret; + return lttng_field_name_statedump(session, field, nesting); +} + +/* + * Must be called with sessions_mutex held. + */ +static +int _lttng_type_statedump(struct lttng_session *session, + const struct lttng_type *type, + size_t nesting) { int ret = 0; - switch (field->type.atype) { + switch (type->atype) { case atype_integer: - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n", - field->type.u.basic.integer.size, - field->type.u.basic.integer.alignment, - field->type.u.basic.integer.signedness, - (field->type.u.basic.integer.encoding == lttng_encode_none) - ? "none" - : (field->type.u.basic.integer.encoding == lttng_encode_UTF8) - ? "UTF8" - : "ASCII", - field->type.u.basic.integer.base, -#if __BYTE_ORDER == __BIG_ENDIAN - field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", -#else - field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", -#endif - field->name); + ret = _lttng_integer_type_statedump(session, type, nesting); break; - case atype_enum: - ret = _lttng_enum_statedump(session, field, nesting); + case atype_enum_nestable: + ret = _lttng_enum_type_statedump(session, type, nesting); break; - case atype_array: - case atype_array_bitfield: - { - const struct lttng_basic_type *elem_type; - - elem_type = &field->type.u.array.elem_type; - if (field->type.u.array.elem_alignment) { - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "struct { } align(%u) _%s_padding;\n", - field->type.u.array.elem_alignment * CHAR_BIT, - field->name); - if (ret) - return ret; - } - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n", - elem_type->u.basic.integer.size, - elem_type->u.basic.integer.alignment, - elem_type->u.basic.integer.signedness, - (elem_type->u.basic.integer.encoding == lttng_encode_none) - ? "none" - : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8) - ? "UTF8" - : "ASCII", - elem_type->u.basic.integer.base, -#if __BYTE_ORDER == __BIG_ENDIAN - elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", -#else - elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", -#endif - field->name, field->type.u.array.length); + case atype_string: + ret = _lttng_string_type_statedump(session, type, nesting); break; + case atype_struct_nestable: + ret = _lttng_struct_type_statedump(session, type, nesting); + break; + case atype_variant_nestable: + ret = _lttng_variant_type_statedump(session, type, nesting); + break; + + /* Nested arrays and sequences are not supported yet. */ + case atype_array_nestable: + case atype_sequence_nestable: + default: + WARN_ON_ONCE(1); + return -EINVAL; } - case atype_sequence: - case atype_sequence_bitfield: - { - const struct lttng_basic_type *elem_type; - const struct lttng_basic_type *length_type; + return ret; +} - elem_type = &field->type.u.sequence.elem_type; - length_type = &field->type.u.sequence.length_type; - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n", - length_type->u.basic.integer.size, - (unsigned int) length_type->u.basic.integer.alignment, - length_type->u.basic.integer.signedness, - (length_type->u.basic.integer.encoding == lttng_encode_none) - ? "none" - : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8) - ? "UTF8" - : "ASCII"), - length_type->u.basic.integer.base, -#if __BYTE_ORDER == __BIG_ENDIAN - length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", -#else - length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", -#endif - field->name); - if (ret) - return ret; +/* + * Must be called with sessions_mutex held. + */ +static +int _lttng_field_statedump(struct lttng_session *session, + const struct lttng_event_field *field, + size_t nesting) +{ + int ret = 0; - if (field->type.u.sequence.elem_alignment) { - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "struct { } align(%u) _%s_padding;\n", - field->type.u.sequence.elem_alignment * CHAR_BIT, - field->name); - if (ret) - return ret; - } - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n", - elem_type->u.basic.integer.size, - (unsigned int) elem_type->u.basic.integer.alignment, - elem_type->u.basic.integer.signedness, - (elem_type->u.basic.integer.encoding == lttng_encode_none) - ? "none" - : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8) - ? "UTF8" - : "ASCII"), - elem_type->u.basic.integer.base, -#if __BYTE_ORDER == __BIG_ENDIAN - elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "", -#else - elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "", -#endif - field->name, - field->name); + switch (field->type.atype) { + case atype_integer: + ret = _lttng_integer_field_statedump(session, field, nesting); + break; + case atype_enum_nestable: + ret = _lttng_enum_field_statedump(session, field, nesting); break; - } - case atype_string: - /* Default encoding is UTF8 */ - ret = print_tabs(session, nesting); - if (ret) - return ret; - ret = lttng_metadata_printf(session, - "string%s _%s;\n", - field->type.u.basic.string.encoding == lttng_encode_ASCII ? - " { encoding = ASCII; }" : "", - field->name); + ret = _lttng_string_field_statedump(session, field, nesting); break; - case atype_struct: - ret = _lttng_struct_statedump(session, field, nesting); + case atype_struct_nestable: + ret = _lttng_struct_field_statedump(session, field, nesting); break; - case atype_array_compound: - ret = _lttng_array_compound_statedump(session, field, nesting); + case atype_array_nestable: + ret = _lttng_array_field_statedump(session, field, nesting); break; - case atype_sequence_compound: - ret = _lttng_sequence_compound_statedump(session, field, nesting); + case atype_sequence_nestable: + ret = _lttng_sequence_field_statedump(session, field, nesting); break; - case atype_variant: - ret = _lttng_variant_statedump(session, field, nesting); + case atype_variant_nestable: + ret = _lttng_variant_field_statedump(session, field, nesting); break; default: diff --git a/lttng-events.h b/lttng-events.h index ec23512a..8197eb83 100644 --- a/lttng-events.h +++ b/lttng-events.h @@ -20,6 +20,7 @@ #include #include #include +#include #define lttng_is_signed_type(type) (((type)(-1)) < 0) @@ -35,16 +36,12 @@ struct lib_ring_buffer_config; enum abstract_types { atype_integer, - atype_enum, - atype_array, - atype_sequence, atype_string, - atype_struct, - atype_array_compound, /* Array of compound types. */ - atype_sequence_compound, /* Sequence of compound types. */ - atype_variant, - atype_array_bitfield, - atype_sequence_bitfield, + atype_enum_nestable, + atype_array_nestable, + atype_sequence_nestable, + atype_struct_nestable, + atype_variant_nestable, NR_ABSTRACT_TYPES, }; @@ -77,7 +74,7 @@ struct lttng_enum_entry { _byte_order, _base, _encoding) \ { \ .atype = atype_integer, \ - .u.basic.integer = \ + .u.integer = \ { \ .size = (_size) ? : sizeof(_type) * CHAR_BIT, \ .alignment = (_alignment) ? : lttng_alignof(_type) * CHAR_BIT, \ @@ -97,55 +94,38 @@ struct lttng_integer_type { enum lttng_string_encodings encoding; }; -union _lttng_basic_type { - struct lttng_integer_type integer; - struct { - const struct lttng_enum_desc *desc; /* Enumeration mapping */ - struct lttng_integer_type container_type; - } enumeration; - struct { - enum lttng_string_encodings encoding; - } string; -}; - -struct lttng_basic_type { - enum abstract_types atype; - union { - union _lttng_basic_type basic; - } u; -}; - struct lttng_type { enum abstract_types atype; union { - union _lttng_basic_type basic; + struct lttng_integer_type integer; struct { - struct lttng_basic_type elem_type; - unsigned int length; /* num. elems. */ - unsigned int elem_alignment; /* alignment override */ - } array; + enum lttng_string_encodings encoding; + } string; struct { - struct lttng_basic_type length_type; - struct lttng_basic_type elem_type; - unsigned int elem_alignment; /* alignment override */ - } sequence; + const struct lttng_enum_desc *desc; /* Enumeration mapping */ + const struct lttng_type *container_type; + } enum_nestable; struct { - uint32_t nr_fields; - struct lttng_event_field *fields; /* Array of fields. */ - } _struct; + const struct lttng_type *elem_type; + unsigned int length; /* Num. elems. */ + unsigned int alignment; + } array_nestable; struct { - struct lttng_type *elem_type; - unsigned int length; /* num. elems. */ - } array_compound; + const char *length_name; /* Length field name. */ + const struct lttng_type *elem_type; + unsigned int alignment; /* Alignment before elements. */ + } sequence_nestable; struct { - struct lttng_type *elem_type; - const char *length_name; - } sequence_compound; + unsigned int nr_fields; + const struct lttng_event_field *fields; /* Array of fields. */ + unsigned int alignment; + } struct_nestable; struct { const char *tag_name; - struct lttng_event_field *choices; /* Array of fields. */ - uint32_t nr_choices; - } variant; + const struct lttng_event_field *choices; /* Array of fields. */ + unsigned int nr_choices; + unsigned int alignment; + } variant_nestable; } u; }; @@ -161,7 +141,8 @@ struct lttng_event_field { const char *name; struct lttng_type type; unsigned int nowrite:1, /* do not write into trace */ - user:1; /* fetch from user-space */ + user:1, /* fetch from user-space */ + nofilter:1; /* do not consider for filter */ }; union lttng_ctx_value { @@ -982,4 +963,20 @@ extern const struct file_operations lttng_syscall_list_fops; #define TRACEPOINT_HAS_DATA_ARG +static inline bool lttng_is_bytewise_integer(const struct lttng_type *type) +{ + if (type->atype != atype_integer) + return false; + switch (type->u.integer.size) { + case 8: /* Fall-through. */ + case 16: /* Fall-through. */ + case 32: /* Fall-through. */ + case 64: + break; + default: + return false; + } + return true; +} + #endif /* _LTTNG_EVENTS_H */ diff --git a/lttng-filter-interpreter.c b/lttng-filter-interpreter.c index 3dad6cc6..c7ce7d33 100644 --- a/lttng-filter-interpreter.c +++ b/lttng-filter-interpreter.c @@ -288,7 +288,7 @@ static int context_get_index(struct lttng_probe_ctx *lttng_probe_ctx, switch (field->type.atype) { case atype_integer: ctx_field->get_value(ctx_field, lttng_probe_ctx, &v); - if (field->type.u.basic.integer.signedness) { + if (field->type.u.integer.signedness) { ptr->object_type = OBJECT_TYPE_S64; ptr->u.s64 = v.s64; ptr->ptr = &ptr->u.s64; @@ -298,10 +298,10 @@ static int context_get_index(struct lttng_probe_ctx *lttng_probe_ctx, ptr->ptr = &ptr->u.u64; } break; - case atype_enum: + case atype_enum_nestable: { const struct lttng_integer_type *itype = - &field->type.u.basic.enumeration.container_type; + &field->type.u.enum_nestable.container_type->u.integer; ctx_field->get_value(ctx_field, lttng_probe_ctx, &v); if (itype->signedness) { @@ -315,12 +315,12 @@ static int context_get_index(struct lttng_probe_ctx *lttng_probe_ctx, } break; } - case atype_array: - if (field->type.u.array.elem_type.atype != atype_integer) { + case atype_array_nestable: + if (!lttng_is_bytewise_integer(field->type.u.array_nestable.elem_type)) { printk(KERN_WARNING "Array nesting only supports integer types.\n"); return -EINVAL; } - if (field->type.u.array.elem_type.u.basic.integer.encoding == lttng_encode_none) { + if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) { printk(KERN_WARNING "Only string arrays are supported for contexts.\n"); return -EINVAL; } @@ -328,12 +328,12 @@ static int context_get_index(struct lttng_probe_ctx *lttng_probe_ctx, ctx_field->get_value(ctx_field, lttng_probe_ctx, &v); ptr->ptr = v.str; break; - case atype_sequence: - if (field->type.u.sequence.elem_type.atype != atype_integer) { + case atype_sequence_nestable: + if (!lttng_is_bytewise_integer(field->type.u.sequence_nestable.elem_type)) { printk(KERN_WARNING "Sequence nesting only supports integer types.\n"); return -EINVAL; } - if (field->type.u.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) { + if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) { printk(KERN_WARNING "Only string sequences are supported for contexts.\n"); return -EINVAL; } @@ -341,20 +341,17 @@ static int context_get_index(struct lttng_probe_ctx *lttng_probe_ctx, ctx_field->get_value(ctx_field, lttng_probe_ctx, &v); ptr->ptr = v.str; break; - case atype_array_bitfield: - printk(KERN_WARNING "Bitfield array type is not supported.\n"); - return -EINVAL; - case atype_sequence_bitfield: - printk(KERN_WARNING "Bitfield sequence type is not supported.\n"); - return -EINVAL; case atype_string: ptr->object_type = OBJECT_TYPE_STRING; ctx_field->get_value(ctx_field, lttng_probe_ctx, &v); ptr->ptr = v.str; break; - case atype_struct: + case atype_struct_nestable: printk(KERN_WARNING "Structure type cannot be loaded.\n"); return -EINVAL; + case atype_variant_nestable: + printk(KERN_WARNING "Variant type cannot be loaded.\n"); + return -EINVAL; default: printk(KERN_WARNING "Unknown type: %d", (int) field->type.atype); return -EINVAL; diff --git a/lttng-filter-specialize.c b/lttng-filter-specialize.c index 4f9a0cd1..3dc82d84 100644 --- a/lttng-filter-specialize.c +++ b/lttng-filter-specialize.c @@ -198,14 +198,20 @@ static int specialize_get_index(struct bytecode_runtime *runtime, switch (stack_top->load.object_type) { case OBJECT_TYPE_ARRAY: { + const struct lttng_integer_type *integer_type; const struct lttng_event_field *field; uint32_t elem_len, num_elems; int signedness; field = stack_top->load.field; - elem_len = field->type.u.array.elem_type.u.basic.integer.size; - signedness = field->type.u.array.elem_type.u.basic.integer.signedness; - num_elems = field->type.u.array.length; + if (!lttng_is_bytewise_integer(field->type.u.array_nestable.elem_type)) { + ret = -EINVAL; + goto end; + } + integer_type = &field->type.u.array_nestable.elem_type->u.integer; + num_elems = field->type.u.array_nestable.length; + elem_len = integer_type->size; + signedness = integer_type->signedness; if (index >= num_elems) { ret = -EINVAL; goto end; @@ -218,20 +224,26 @@ static int specialize_get_index(struct bytecode_runtime *runtime, gid.array_len = num_elems * (elem_len / CHAR_BIT); gid.elem.type = stack_top->load.object_type; gid.elem.len = elem_len; - if (field->type.u.array.elem_type.u.basic.integer.reverse_byte_order) + if (integer_type->reverse_byte_order) gid.elem.rev_bo = true; stack_top->load.rev_bo = gid.elem.rev_bo; break; } case OBJECT_TYPE_SEQUENCE: { + const struct lttng_integer_type *integer_type; const struct lttng_event_field *field; uint32_t elem_len; int signedness; field = stack_top->load.field; - elem_len = field->type.u.sequence.elem_type.u.basic.integer.size; - signedness = field->type.u.sequence.elem_type.u.basic.integer.signedness; + if (!lttng_is_bytewise_integer(field->type.u.sequence_nestable.elem_type)) { + ret = -EINVAL; + goto end; + } + integer_type = &field->type.u.sequence_nestable.elem_type->u.integer; + elem_len = integer_type->size; + signedness = integer_type->signedness; ret = specialize_get_index_object_type(&stack_top->load.object_type, signedness, elem_len); if (ret) @@ -239,7 +251,7 @@ static int specialize_get_index(struct bytecode_runtime *runtime, gid.offset = index * (elem_len / CHAR_BIT); gid.elem.type = stack_top->load.object_type; gid.elem.len = elem_len; - if (field->type.u.sequence.elem_type.u.basic.integer.reverse_byte_order) + if (integer_type->reverse_byte_order) gid.elem.rev_bo = true; stack_top->load.rev_bo = gid.elem.rev_bo; break; @@ -305,16 +317,16 @@ static int specialize_load_object(const struct lttng_event_field *field, */ switch (field->type.atype) { case atype_integer: - if (field->type.u.basic.integer.signedness) + if (field->type.u.integer.signedness) load->object_type = OBJECT_TYPE_S64; else load->object_type = OBJECT_TYPE_U64; load->rev_bo = false; break; - case atype_enum: + case atype_enum_nestable: { const struct lttng_integer_type *itype = - &field->type.u.basic.enumeration.container_type; + &field->type.u.enum_nestable.container_type->u.integer; if (itype->signedness) load->object_type = OBJECT_TYPE_S64; @@ -323,15 +335,15 @@ static int specialize_load_object(const struct lttng_event_field *field, load->rev_bo = false; break; } - case atype_array: - if (field->type.u.array.elem_type.atype != atype_integer) { + case atype_array_nestable: + if (!lttng_is_bytewise_integer(field->type.u.array_nestable.elem_type)) { printk(KERN_WARNING "Array nesting only supports integer types.\n"); return -EINVAL; } if (is_context) { load->object_type = OBJECT_TYPE_STRING; } else { - if (field->type.u.array.elem_type.u.basic.integer.encoding == lttng_encode_none) { + if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) { load->object_type = OBJECT_TYPE_ARRAY; load->field = field; } else { @@ -339,15 +351,15 @@ static int specialize_load_object(const struct lttng_event_field *field, } } break; - case atype_sequence: - if (field->type.u.sequence.elem_type.atype != atype_integer) { + case atype_sequence_nestable: + if (!lttng_is_bytewise_integer(field->type.u.sequence_nestable.elem_type)) { printk(KERN_WARNING "Sequence nesting only supports integer types.\n"); return -EINVAL; } if (is_context) { load->object_type = OBJECT_TYPE_STRING; } else { - if (field->type.u.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) { + if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) { load->object_type = OBJECT_TYPE_SEQUENCE; load->field = field; } else { @@ -355,18 +367,15 @@ static int specialize_load_object(const struct lttng_event_field *field, } } break; - case atype_array_bitfield: - printk(KERN_WARNING "Bitfield array type is not supported.\n"); - return -EINVAL; - case atype_sequence_bitfield: - printk(KERN_WARNING "Bitfield sequence type is not supported.\n"); - return -EINVAL; case atype_string: load->object_type = OBJECT_TYPE_STRING; break; - case atype_struct: + case atype_struct_nestable: printk(KERN_WARNING "Structure type cannot be loaded.\n"); return -EINVAL; + case atype_variant_nestable: + printk(KERN_WARNING "Variant type cannot be loaded.\n"); + return -EINVAL; default: printk(KERN_WARNING "Unknown type: %d", (int) field->type.atype); return -EINVAL; @@ -428,6 +437,9 @@ static int specialize_event_payload_lookup(struct lttng_event *event, name = runtime->p.bc->bc.data + runtime->p.bc->bc.reloc_offset + offset; for (i = 0; i < nr_fields; i++) { field = &desc->fields[i]; + if (field->nofilter) { + continue; + } if (!strcmp(field->name, name)) { found = true; break; @@ -435,13 +447,11 @@ static int specialize_event_payload_lookup(struct lttng_event *event, /* compute field offset on stack */ switch (field->type.atype) { case atype_integer: - case atype_enum: + case atype_enum_nestable: field_offset += sizeof(int64_t); break; - case atype_array: - case atype_sequence: - case atype_array_bitfield: - case atype_sequence_bitfield: + case atype_array_nestable: + case atype_sequence_nestable: field_offset += sizeof(unsigned long); field_offset += sizeof(void *); break; diff --git a/lttng-filter.c b/lttng-filter.c index 325ae7bb..45319d6f 100644 --- a/lttng-filter.c +++ b/lttng-filter.c @@ -191,6 +191,8 @@ int apply_field_reloc(struct lttng_event *event, return -EINVAL; nr_fields = desc->nr_fields; for (i = 0; i < nr_fields; i++) { + if (fields[i].nofilter) + continue; if (!strcmp(fields[i].name, field_name)) { field = &fields[i]; break; @@ -198,23 +200,26 @@ int apply_field_reloc(struct lttng_event *event, /* compute field offset */ switch (fields[i].type.atype) { case atype_integer: - case atype_enum: + case atype_enum_nestable: field_offset += sizeof(int64_t); break; - case atype_array: - case atype_sequence: - case atype_array_bitfield: - case atype_sequence_bitfield: + case atype_array_nestable: + if (!lttng_is_bytewise_integer(fields[i].type.u.array_nestable.elem_type)) + return -EINVAL; + field_offset += sizeof(unsigned long); + field_offset += sizeof(void *); + break; + case atype_sequence_nestable: + if (!lttng_is_bytewise_integer(fields[i].type.u.sequence_nestable.elem_type)) + return -EINVAL; field_offset += sizeof(unsigned long); field_offset += sizeof(void *); break; case atype_string: field_offset += sizeof(void *); break; - case atype_struct: /* Unsupported. */ - case atype_array_compound: /* Unsupported. */ - case atype_sequence_compound: /* Unsupported. */ - case atype_variant: /* Unsupported. */ + case atype_struct_nestable: /* Unsupported. */ + case atype_variant_nestable: /* Unsupported. */ default: return -EINVAL; } @@ -237,11 +242,11 @@ int apply_field_reloc(struct lttng_event *event, field_ref = (struct field_ref *) op->data; switch (field->type.atype) { case atype_integer: - case atype_enum: + case atype_enum_nestable: op->op = FILTER_OP_LOAD_FIELD_REF_S64; break; - case atype_array: - case atype_sequence: + case atype_array_nestable: + case atype_sequence_nestable: if (field->user) op->op = FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE; else @@ -253,12 +258,8 @@ int apply_field_reloc(struct lttng_event *event, else op->op = FILTER_OP_LOAD_FIELD_REF_STRING; break; - case atype_struct: /* Unsupported. */ - case atype_array_compound: /* Unsupported. */ - case atype_sequence_compound: /* Unsupported. */ - case atype_variant: /* Unsupported. */ - case atype_array_bitfield: /* Unsupported. */ - case atype_sequence_bitfield: /* Unsupported. */ + case atype_struct_nestable: /* Unsupported. */ + case atype_variant_nestable: /* Unsupported. */ default: return -EINVAL; } @@ -307,22 +308,28 @@ int apply_context_reloc(struct lttng_event *event, field_ref = (struct field_ref *) op->data; switch (ctx_field->event_field.type.atype) { case atype_integer: - case atype_enum: + case atype_enum_nestable: op->op = FILTER_OP_GET_CONTEXT_REF_S64; break; /* Sequence and array supported as string */ case atype_string: - case atype_array: - case atype_sequence: BUG_ON(ctx_field->event_field.user); op->op = FILTER_OP_GET_CONTEXT_REF_STRING; break; - case atype_struct: /* Unsupported. */ - case atype_array_compound: /* Unsupported. */ - case atype_sequence_compound: /* Unsupported. */ - case atype_variant: /* Unsupported. */ - case atype_array_bitfield: /* Unsupported. */ - case atype_sequence_bitfield: /* Unsupported. */ + case atype_array_nestable: + if (!lttng_is_bytewise_integer(ctx_field->event_field.type.u.array_nestable.elem_type)) + return -EINVAL; + BUG_ON(ctx_field->event_field.user); + op->op = FILTER_OP_GET_CONTEXT_REF_STRING; + break; + case atype_sequence_nestable: + if (!lttng_is_bytewise_integer(ctx_field->event_field.type.u.sequence_nestable.elem_type)) + return -EINVAL; + BUG_ON(ctx_field->event_field.user); + op->op = FILTER_OP_GET_CONTEXT_REF_STRING; + break; + case atype_struct_nestable: /* Unsupported. */ + case atype_variant_nestable: /* Unsupported. */ default: return -EINVAL; } diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index a6e2ca1c..40fe0f68 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -76,12 +76,12 @@ int lttng_create_kprobe_event(const char *name, struct lttng_event *event) } field->name = "ip"; field->type.atype = atype_integer; - field->type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - field->type.u.basic.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - field->type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); - field->type.u.basic.integer.reverse_byte_order = 0; - field->type.u.basic.integer.base = 16; - field->type.u.basic.integer.encoding = lttng_encode_none; + field->type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + field->type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + field->type.u.integer.signedness = lttng_is_signed_type(unsigned long); + field->type.u.integer.reverse_byte_order = 0; + field->type.u.integer.base = 16; + field->type.u.integer.encoding = lttng_encode_none; desc->owner = THIS_MODULE; event->desc = desc; diff --git a/probes/lttng-kretprobes.c b/probes/lttng-kretprobes.c index 9ef4eefa..40938f2b 100644 --- a/probes/lttng-kretprobes.c +++ b/probes/lttng-kretprobes.c @@ -130,21 +130,21 @@ int lttng_create_kprobe_event(const char *name, struct lttng_event *event, } fields[0].name = "ip"; fields[0].type.atype = atype_integer; - fields[0].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); - fields[0].type.u.basic.integer.reverse_byte_order = 0; - fields[0].type.u.basic.integer.base = 16; - fields[0].type.u.basic.integer.encoding = lttng_encode_none; + fields[0].type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + fields[0].type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + fields[0].type.u.integer.signedness = lttng_is_signed_type(unsigned long); + fields[0].type.u.integer.reverse_byte_order = 0; + fields[0].type.u.integer.base = 16; + fields[0].type.u.integer.encoding = lttng_encode_none; fields[1].name = "parent_ip"; fields[1].type.atype = atype_integer; - fields[1].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - fields[1].type.u.basic.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - fields[1].type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); - fields[1].type.u.basic.integer.reverse_byte_order = 0; - fields[1].type.u.basic.integer.base = 16; - fields[1].type.u.basic.integer.encoding = lttng_encode_none; + fields[1].type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + fields[1].type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + fields[1].type.u.integer.signedness = lttng_is_signed_type(unsigned long); + fields[1].type.u.integer.reverse_byte_order = 0; + fields[1].type.u.integer.base = 16; + fields[1].type.u.integer.encoding = lttng_encode_none; desc->owner = THIS_MODULE; event->desc = desc; diff --git a/probes/lttng-tracepoint-event-impl.h b/probes/lttng-tracepoint-event-impl.h index b304dde3..5f77bf4d 100644 --- a/probes/lttng-tracepoint-event-impl.h +++ b/probes/lttng-tracepoint-event-impl.h @@ -257,29 +257,34 @@ void __event_template_proto___##_name(void); #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ { \ .name = #_item, \ - .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\ + .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none), \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef _ctf_array_encoded -#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ +#define _ctf_array_encoded(_type, _item, _src, _length, \ + _encoding, _byte_order, _elem_type_base, _user, _nowrite) \ { \ .name = #_item, \ .type = \ { \ - .atype = atype_array, \ + .atype = atype_array_nestable, \ .u = \ { \ - .array = \ + .array_nestable = \ { \ - .elem_type = __type_integer(_type, 0, 0, 0, _byte_order, _base, _encoding), \ + .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(_type, 0, 0, -1, _byte_order, _elem_type_base, _encoding)), \ .length = _length, \ + .alignment = 0, \ } \ } \ }, \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef _ctf_array_bitfield @@ -288,65 +293,84 @@ void __event_template_proto___##_name(void); .name = #_item, \ .type = \ { \ - .atype = atype_array_bitfield, \ + .atype = atype_array_nestable, \ .u = \ { \ - .array = \ + .array_nestable = \ { \ - .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \ + .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none)), \ .length = (_length) * sizeof(_type) * CHAR_BIT, \ - .elem_alignment = lttng_alignof(_type), \ + .alignment = lttng_alignof(_type), \ } \ } \ }, \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef _ctf_sequence_encoded #define _ctf_sequence_encoded(_type, _item, _src, \ _length_type, _src_length, _encoding, \ - _byte_order, _base, _user, _nowrite) \ + _byte_order, _elem_type_base, _user, _nowrite) \ + { \ + .name = "_" #_item "_length", \ + .type = __type_integer(_length_type, 0, 0, -1, __BYTE_ORDER, 10, none), \ + .nowrite = _nowrite, \ + .nofilter = 1, \ + }, \ { \ .name = #_item, \ .type = \ { \ - .atype = atype_sequence, \ + .atype = atype_sequence_nestable, \ .u = \ { \ - .sequence = \ + .sequence_nestable = \ { \ - .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \ - .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \ + .length_name = "_" #_item "_length", \ + .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(_type, 0, 0, -1, _byte_order, _elem_type_base, _encoding)), \ + .alignment = 0, \ }, \ }, \ }, \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef _ctf_sequence_bitfield #define _ctf_sequence_bitfield(_type, _item, _src, \ _length_type, _src_length, \ _user, _nowrite) \ + { \ + .name = "_" #_item "_length", \ + .type = __type_integer(_length_type, 0, 0, -1, __BYTE_ORDER, 10, none), \ + .nowrite = _nowrite, \ + .nofilter = 1, \ + }, \ { \ .name = #_item, \ .type = \ { \ - .atype = atype_sequence_bitfield, \ + .atype = atype_sequence_nestable, \ .u = \ { \ - .sequence = \ + .sequence_nestable = \ { \ - .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \ - .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \ - .elem_alignment = lttng_alignof(_type), \ + .length_name = "_" #_item "_length", \ + .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none)), \ + .alignment = lttng_alignof(_type), \ }, \ }, \ }, \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef _ctf_string @@ -358,11 +382,12 @@ void __event_template_proto___##_name(void); .atype = atype_string, \ .u = \ { \ - .basic = { .string = { .encoding = lttng_encode_UTF8 } } \ + .string = { .encoding = lttng_encode_UTF8 }, \ }, \ }, \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef _ctf_enum @@ -370,34 +395,28 @@ void __event_template_proto___##_name(void); { \ .name = #_item, \ .type = { \ - .atype = atype_enum, \ + .atype = atype_enum_nestable, \ .u = { \ - .basic = { \ - .enumeration = { \ - .desc = &__enum_##_name, \ - .container_type = { \ - .size = sizeof(_type) * CHAR_BIT, \ - .alignment = lttng_alignof(_type) * CHAR_BIT, \ - .signedness = lttng_is_signed_type(_type), \ - .reverse_byte_order = 0, \ - .base = 10, \ - .encoding = lttng_encode_none, \ - }, \ - }, \ - }, \ + .enum_nestable = { \ + .desc = &__enum_##_name, \ + .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ + __type_integer(_type, 0, 0, -1, __BYTE_ORDER, 10, none)), \ + }, \ }, \ }, \ .nowrite = _nowrite, \ .user = _user, \ + .nofilter = 0, \ }, #undef ctf_custom_field #define ctf_custom_field(_type, _item, _code) \ { \ .name = #_item, \ - .type = { _type }, \ + .type = _type, \ .nowrite = 0, \ .user = 0, \ + .nofilter = 1, \ }, #undef ctf_custom_type diff --git a/probes/lttng-uprobes.c b/probes/lttng-uprobes.c index 10f435fe..175c0dd9 100644 --- a/probes/lttng-uprobes.c +++ b/probes/lttng-uprobes.c @@ -92,12 +92,12 @@ int lttng_create_uprobe_event(const char *name, struct lttng_event *event) } fields[0].name = "ip"; fields[0].type.atype = atype_integer; - fields[0].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); - fields[0].type.u.basic.integer.reverse_byte_order = 0; - fields[0].type.u.basic.integer.base = 16; - fields[0].type.u.basic.integer.encoding = lttng_encode_none; + fields[0].type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + fields[0].type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + fields[0].type.u.integer.signedness = lttng_is_signed_type(unsigned long); + fields[0].type.u.integer.reverse_byte_order = 0; + fields[0].type.u.integer.base = 16; + fields[0].type.u.integer.encoding = lttng_encode_none; desc->owner = THIS_MODULE; event->desc = desc; -- 2.34.1