当前位置:   article > 正文

Common Trace Format

the common trace format (ctf)
  1. Common Trace Format (CTF) Specification (v1.8.1)
  2. Mathieu Desnoyers, EfficiOS Inc.
  3. The goal of the present document is to specify a trace format that suits the
  4. needs of the embedded, telecom, high-performance and kernel communities. It is
  5. based on the Common Trace Format Requirements (v1.4) document. It is designed to
  6. allow traces to be natively generated by the Linux kernel, Linux user-space
  7. applications written in C/C++, and hardware components. One major element of
  8. CTF is the Trace Stream Description Language (TSDL) which flexibility
  9. enables description of various binary trace stream layouts.
  10. The latest version of this document can be found at:
  11. git tree: git://git.efficios.com/ctf.git
  12. gitweb: http://git.efficios.com/?p=ctf.git
  13. A reference implementation of a library to read and write this trace format is
  14. being implemented within the BabelTrace project, a converter between trace
  15. formats. The development tree is available at:
  16. git tree: git://git.efficios.com/babeltrace.git
  17. gitweb: http://git.efficios.com/?p=babeltrace.git
  18. The CE Workgroup of the Linux Foundation, Ericsson, and EfficiOS have
  19. sponsored this work.
  20. Table of Contents
  21. 1. Preliminary definitions
  22. 2. High-level representation of a trace
  23. 3. Event stream
  24. 4. Types
  25. 4.1 Basic types
  26. 4.1.1 Type inheritance
  27. 4.1.2 Alignment
  28. 4.1.3 Byte order
  29. 4.1.4 Size
  30. 4.1.5 Integers
  31. 4.1.6 GNU/C bitfields
  32. 4.1.7 Floating point
  33. 4.1.8 Enumerations
  34. 4.2 Compound types
  35. 4.2.1 Structures
  36. 4.2.2 Variants (Discriminated/Tagged Unions)
  37. 4.2.3 Arrays
  38. 4.2.4 Sequences
  39. 4.2.5 Strings
  40. 5. Event Packet Header
  41. 5.1 Event Packet Header Description
  42. 5.2 Event Packet Context Description
  43. 6. Event Structure
  44. 6.1 Event Header
  45. 6.1.1 Type 1 - Few event IDs
  46. 6.1.2 Type 2 - Many event IDs
  47. 6.2 Event Context
  48. 6.3 Event Payload
  49. 6.3.1 Padding
  50. 6.3.2 Alignment
  51. 7. Trace Stream Description Language (TSDL)
  52. 7.1 Meta-data
  53. 7.2 Declaration vs Definition
  54. 7.3 TSDL Scopes
  55. 7.3.1 Lexical Scope
  56. 7.3.2 Static and Dynamic Scopes
  57. 7.4 TSDL Examples
  58. 8. Clocks
  59. 1. Preliminary definitions
  60. - Event Trace: An ordered sequence of events.
  61. - Event Stream: An ordered sequence of events, containing a subset of the
  62. trace event types.
  63. - Event Packet: A sequence of physically contiguous events within an event
  64. stream.
  65. - Event: This is the basic entry in a trace. (aka: a trace record).
  66. - An event identifier (ID) relates to the class (a type) of event within
  67. an event stream.
  68. e.g. event: irq_entry.
  69. - An event (or event record) relates to a specific instance of an event
  70. class.
  71. e.g. event: irq_entry, at time X, on CPU Y
  72. - Source Architecture: Architecture writing the trace.
  73. - Reader Architecture: Architecture reading the trace.
  74. 2. High-level representation of a trace
  75. A trace is divided into multiple event streams. Each event stream contains a
  76. subset of the trace event types.
  77. The final output of the trace, after its generation and optional transport over
  78. the network, is expected to be either on permanent or temporary storage in a
  79. virtual file system. Because each event stream is appended to while a trace is
  80. being recorded, each is associated with a distinct set of files for
  81. output. Therefore, a stored trace can be represented as a directory
  82. containing zero, one or more files per stream.
  83. Meta-data description associated with the trace contains information on
  84. trace event types expressed in the Trace Stream Description Language
  85. (TSDL). This language describes:
  86. - Trace version.
  87. - Types available.
  88. - Per-trace event header description.
  89. - Per-stream event header description.
  90. - Per-stream event context description.
  91. - Per-event
  92. - Event type to stream mapping.
  93. - Event type to name mapping.
  94. - Event type to ID mapping.
  95. - Event context description.
  96. - Event fields description.
  97. 3. Event stream
  98. An event stream can be divided into contiguous event packets of variable
  99. size. These subdivisions have a variable size. An event packet can
  100. contain a certain amount of padding at the end. The stream header is
  101. repeated at the beginning of each event packet. The rationale for the
  102. event stream design choices is explained in Appendix B. Stream Header
  103. Rationale.
  104. The event stream header will therefore be referred to as the "event packet
  105. header" throughout the rest of this document.
  106. 4. Types
  107. Types are organized as type classes. Each type class belong to either of two
  108. kind of types: basic types or compound types.
  109. 4.1 Basic types
  110. A basic type is a scalar type, as described in this section. It includes
  111. integers, GNU/C bitfields, enumerations, and floating point values.
  112. 4.1.1 Type inheritance
  113. Type specifications can be inherited to allow deriving types from a
  114. type class. For example, see the uint32_t named type derived from the "integer"
  115. type class below ("Integers" section). Types have a precise binary
  116. representation in the trace. A type class has methods to read and write these
  117. types, but must be derived into a type to be usable in an event field.
  118. 4.1.2 Alignment
  119. We define "byte-packed" types as aligned on the byte size, namely 8-bit.
  120. We define "bit-packed" types as following on the next bit, as defined by the
  121. "Integers" section.
  122. Each basic type must specify its alignment, in bits. Examples of
  123. possible alignments are: bit-packed (align = 1), byte-packed (align =
  124. 8), or word-aligned (e.g. align = 32 or align = 64). The choice depends
  125. on the architecture preference and compactness vs performance trade-offs
  126. of the implementation. Architectures providing fast unaligned write
  127. byte-packed basic types to save space, aligning each type on byte
  128. boundaries (8-bit). Architectures with slow unaligned writes align types
  129. on specific alignment values. If no specific alignment is declared for a
  130. type, it is assumed to be bit-packed for integers with size not multiple
  131. of 8 bits and for gcc bitfields. All other basic types are byte-packed
  132. by default. It is however recommended to always specify the alignment
  133. explicitly. Alignment values must be power of two. Compound types are
  134. aligned as specified in their individual specification.
  135. TSDL meta-data attribute representation of a specific alignment:
  136. align = value; /* value in bits */
  137. 4.1.3 Byte order
  138. By default, the native endianness of the source architecture the trace is used.
  139. Byte order can be overridden for a basic type by specifying a "byte_order"
  140. attribute. Typical use-case is to specify the network byte order (big endian:
  141. "be") to save data captured from the network into the trace without conversion.
  142. If not specified, the byte order is native.
  143. TSDL meta-data representation:
  144. byte_order = native OR network OR be OR le; /* network and be are aliases */
  145. 4.1.4 Size
  146. Type size, in bits, for integers and floats is that returned by "sizeof()" in C
  147. multiplied by CHAR_BIT.
  148. We require the size of "char" and "unsigned char" types (CHAR_BIT) to be fixed
  149. to 8 bits for cross-endianness compatibility.
  150. TSDL meta-data representation:
  151. size = value; (value is in bits)
  152. 4.1.5 Integers
  153. Signed integers are represented in two-complement. Integer alignment,
  154. size, signedness and byte ordering are defined in the TSDL meta-data.
  155. Integers aligned on byte size (8-bit) and with length multiple of byte
  156. size (8-bit) correspond to the C99 standard integers. In addition,
  157. integers with alignment and/or size that are _not_ a multiple of the
  158. byte size are permitted; these correspond to the C99 standard bitfields,
  159. with the added specification that the CTF integer bitfields have a fixed
  160. binary representation. A MIT-licensed reference implementation of the
  161. CTF portable bitfields is available at:
  162. http://git.efficios.com/?p=babeltrace.git;a=blob;f=include/babeltrace/bitfield.h
  163. Binary representation of integers:
  164. - On little and big endian:
  165. - Within a byte, high bits correspond to an integer high bits, and low bits
  166. correspond to low bits.
  167. - On little endian:
  168. - Integer across multiple bytes are placed from the less significant to the
  169. most significant.
  170. - Consecutive integers are placed from lower bits to higher bits (even within
  171. a byte).
  172. - On big endian:
  173. - Integer across multiple bytes are placed from the most significant to the
  174. less significant.
  175. - Consecutive integers are placed from higher bits to lower bits (even within
  176. a byte).
  177. This binary representation is derived from the bitfield implementation in GCC
  178. for little and big endian. However, contrary to what GCC does, integers can
  179. cross units boundaries (no padding is required). Padding can be explicitly
  180. added (see 4.1.6 GNU/C bitfields) to follow the GCC layout if needed.
  181. TSDL meta-data representation:
  182. integer {
  183. signed = true OR false; /* default false */
  184. byte_order = native OR network OR be OR le; /* default native */
  185. size = value; /* value in bits, no default */
  186. align = value; /* value in bits */
  187. /* based used for pretty-printing output, default: decimal. */
  188. base = decimal OR dec OR OR d OR i OR u OR 10 OR hexadecimal OR hex OR x OR X OR p OR 16
  189. OR octal OR oct OR o OR 8 OR binary OR b OR 2;
  190. /* character encoding, default: none */
  191. encoding = none or UTF8 or ASCII;
  192. }
  193. Example of type inheritance (creation of a uint32_t named type):
  194. typealias integer {
  195. size = 32;
  196. signed = false;
  197. align = 32;
  198. } := uint32_t;
  199. Definition of a named 5-bit signed bitfield:
  200. typealias integer {
  201. size = 5;
  202. signed = true;
  203. align = 1;
  204. } := int5_t;
  205. The character encoding field can be used to specify that the integer
  206. must be printed as a text character when read. e.g.:
  207. typealias integer {
  208. size = 8;
  209. align = 8;
  210. signed = false;
  211. encoding = UTF8;
  212. } := utf_char;
  213. 4.1.6 GNU/C bitfields
  214. The GNU/C bitfields follow closely the integer representation, with a
  215. particularity on alignment: if a bitfield cannot fit in the current unit, the
  216. unit is padded and the bitfield starts at the following unit. The unit size is
  217. defined by the size of the type "unit_type".
  218. TSDL meta-data representation:
  219. unit_type name:size;
  220. As an example, the following structure declared in C compiled by GCC:
  221. struct example {
  222. short a:12;
  223. short b:5;
  224. };
  225. The example structure is aligned on the largest element (short). The second
  226. bitfield would be aligned on the next unit boundary, because it would not fit in
  227. the current unit.
  228. 4.1.7 Floating point
  229. The floating point values byte ordering is defined in the TSDL meta-data.
  230. Floating point values follow the IEEE 754-2008 standard interchange formats.
  231. Description of the floating point values include the exponent and mantissa size
  232. in bits. Some requirements are imposed on the floating point values:
  233. - FLT_RADIX must be 2.
  234. - mant_dig is the number of digits represented in the mantissa. It is specified
  235. by the ISO C99 standard, section 5.2.4, as FLT_MANT_DIG, DBL_MANT_DIG and
  236. LDBL_MANT_DIG as defined by <float.h>.
  237. - exp_dig is the number of digits represented in the exponent. Given that
  238. mant_dig is one bit more than its actual size in bits (leading 1 is not
  239. needed) and also given that the sign bit always takes one bit, exp_dig can be
  240. specified as:
  241. - sizeof(float) * CHAR_BIT - FLT_MANT_DIG
  242. - sizeof(double) * CHAR_BIT - DBL_MANT_DIG
  243. - sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG
  244. TSDL meta-data representation:
  245. floating_point {
  246. exp_dig = value;
  247. mant_dig = value;
  248. byte_order = native OR network OR be OR le;
  249. align = value;
  250. }
  251. Example of type inheritance:
  252. typealias floating_point {
  253. exp_dig = 8; /* sizeof(float) * CHAR_BIT - FLT_MANT_DIG */
  254. mant_dig = 24; /* FLT_MANT_DIG */
  255. byte_order = native;
  256. align = 32;
  257. } := float;
  258. TODO: define NaN, +inf, -inf behavior.
  259. Bit-packed, byte-packed or larger alignments can be used for floating
  260. point values, similarly to integers.
  261. 4.1.8 Enumerations
  262. Enumerations are a mapping between an integer type and a table of strings. The
  263. numerical representation of the enumeration follows the integer type specified
  264. by the meta-data. The enumeration mapping table is detailed in the enumeration
  265. description within the meta-data. The mapping table maps inclusive value
  266. ranges (or single values) to strings. Instead of being limited to simple
  267. "value -> string" mappings, these enumerations map
  268. "[ start_value ... end_value ] -> string", which map inclusive ranges of
  269. values to strings. An enumeration from the C language can be represented in
  270. this format by having the same start_value and end_value for each element, which
  271. is in fact a range of size 1. This single-value range is supported without
  272. repeating the start and end values with the value = string declaration.
  273. enum name : integer_type {
  274. somestring = start_value1 ... end_value1,
  275. "other string" = start_value2 ... end_value2,
  276. yet_another_string, /* will be assigned to end_value2 + 1 */
  277. "some other string" = value,
  278. ...
  279. };
  280. If the values are omitted, the enumeration starts at 0 and increment of 1 for
  281. each entry:
  282. enum name : unsigned int {
  283. ZERO,
  284. ONE,
  285. TWO,
  286. TEN = 10,
  287. ELEVEN,
  288. };
  289. Overlapping ranges within a single enumeration are implementation defined.
  290. A nameless enumeration can be declared as a field type or as part of a typedef:
  291. enum : integer_type {
  292. ...
  293. }
  294. Enumerations omitting the container type ": integer_type" use the "int"
  295. type (for compatibility with C99). The "int" type must be previously
  296. declared. E.g.:
  297. typealias integer { size = 32; align = 32; signed = true } := int;
  298. enum {
  299. ...
  300. }
  301. 4.2 Compound types
  302. Compound are aggregation of type declarations. Compound types include
  303. structures, variant, arrays, sequences, and strings.
  304. 4.2.1 Structures
  305. Structures are aligned on the largest alignment required by basic types
  306. contained within the structure. (This follows the ISO/C standard for structures)
  307. TSDL meta-data representation of a named structure:
  308. struct name {
  309. field_type field_name;
  310. field_type field_name;
  311. ...
  312. };
  313. Example:
  314. struct example {
  315. integer { /* Nameless type */
  316. size = 16;
  317. signed = true;
  318. align = 16;
  319. } first_field_name;
  320. uint64_t second_field_name; /* Named type declared in the meta-data */
  321. };
  322. The fields are placed in a sequence next to each other. They each
  323. possess a field name, which is a unique identifier within the structure.
  324. The identifier is not allowed to use any reserved keyword
  325. (see Section C.1.2). Replacing reserved keywords with
  326. underscore-prefixed field names is recommended. Fields starting with an
  327. underscore should have their leading underscore removed by the CTF trace
  328. readers.
  329. A nameless structure can be declared as a field type or as part of a typedef:
  330. struct {
  331. ...
  332. }
  333. Alignment for a structure compound type can be forced to a minimum value
  334. by adding an "align" specifier after the declaration of a structure
  335. body. This attribute is read as: align(value). The value is specified in
  336. bits. The structure will be aligned on the maximum value between this
  337. attribute and the alignment required by the basic types contained within
  338. the structure. e.g.
  339. struct {
  340. ...
  341. } align(32)
  342. 4.2.2 Variants (Discriminated/Tagged Unions)
  343. A CTF variant is a selection between different types. A CTF variant must
  344. always be defined within the scope of a structure or within fields
  345. contained within a structure (defined recursively). A "tag" enumeration
  346. field must appear in either the same static scope, prior to the variant
  347. field (in field declaration order), in an upper static scope , or in an
  348. upper dynamic scope (see Section 7.3.2). The type selection is indicated
  349. by the mapping from the enumeration value to the string used as variant
  350. type selector. The field to use as tag is specified by the "tag_field",
  351. specified between "< >" after the "variant" keyword for unnamed
  352. variants, and after "variant name" for named variants.
  353. The alignment of the variant is the alignment of the type as selected by the tag
  354. value for the specific instance of the variant. The alignment of the type
  355. containing the variant is independent of the variant alignment. The size of the
  356. variant is the size as selected by the tag value for the specific instance of
  357. the variant.
  358. Each variant type selector possess a field name, which is a unique
  359. identifier within the variant. The identifier is not allowed to use any
  360. reserved keyword (see Section C.1.2). Replacing reserved keywords with
  361. underscore-prefixed field names is recommended. Fields starting with an
  362. underscore should have their leading underscore removed by the CTF trace
  363. readers.
  364. A named variant declaration followed by its definition within a structure
  365. declaration:
  366. variant name {
  367. field_type sel1;
  368. field_type sel2;
  369. field_type sel3;
  370. ...
  371. };
  372. struct {
  373. enum : integer_type { sel1, sel2, sel3, ... } tag_field;
  374. ...
  375. variant name <tag_field> v;
  376. }
  377. An unnamed variant definition within a structure is expressed by the following
  378. TSDL meta-data:
  379. struct {
  380. enum : integer_type { sel1, sel2, sel3, ... } tag_field;
  381. ...
  382. variant <tag_field> {
  383. field_type sel1;
  384. field_type sel2;
  385. field_type sel3;
  386. ...
  387. } v;
  388. }
  389. Example of a named variant within a sequence that refers to a single tag field:
  390. variant example {
  391. uint32_t a;
  392. uint64_t b;
  393. short c;
  394. };
  395. struct {
  396. enum : uint2_t { a, b, c } choice;
  397. unsigned int seqlen;
  398. variant example <choice> v[seqlen];
  399. }
  400. Example of an unnamed variant:
  401. struct {
  402. enum : uint2_t { a, b, c, d } choice;
  403. /* Unrelated fields can be added between the variant and its tag */
  404. int32_t somevalue;
  405. variant <choice> {
  406. uint32_t a;
  407. uint64_t b;
  408. short c;
  409. struct {
  410. unsigned int field1;
  411. uint64_t field2;
  412. } d;
  413. } s;
  414. }
  415. Example of an unnamed variant within an array:
  416. struct {
  417. enum : uint2_t { a, b, c } choice;
  418. variant <choice> {
  419. uint32_t a;
  420. uint64_t b;
  421. short c;
  422. } v[10];
  423. }
  424. Example of a variant type definition within a structure, where the defined type
  425. is then declared within an array of structures. This variant refers to a tag
  426. located in an upper static scope. This example clearly shows that a variant
  427. type definition referring to the tag "x" uses the closest preceding field from
  428. the static scope of the type definition.
  429. struct {
  430. enum : uint2_t { a, b, c, d } x;
  431. typedef variant <x> { /*
  432. * "x" refers to the preceding "x" enumeration in the
  433. * static scope of the type definition.
  434. */
  435. uint32_t a;
  436. uint64_t b;
  437. short c;
  438. } example_variant;
  439. struct {
  440. enum : int { x, y, z } x; /* This enumeration is not used by "v". */
  441. example_variant v; /*
  442. * "v" uses the "enum : uint2_t { a, b, c, d }"
  443. * tag.
  444. */
  445. } a[10];
  446. }
  447. 4.2.3 Arrays
  448. Arrays are fixed-length. Their length is declared in the type
  449. declaration within the meta-data. They contain an array of "inner type"
  450. elements, which can refer to any type not containing the type of the
  451. array being declared (no circular dependency). The length is the number
  452. of elements in an array.
  453. TSDL meta-data representation of a named array:
  454. typedef elem_type name[length];
  455. A nameless array can be declared as a field type within a structure, e.g.:
  456. uint8_t field_name[10];
  457. Arrays are always aligned on their element alignment requirement.
  458. 4.2.4 Sequences
  459. Sequences are dynamically-sized arrays. They refer to a a "length"
  460. unsigned integer field, which must appear in either the same static scope,
  461. prior to the sequence field (in field declaration order), in an upper
  462. static scope, or in an upper dynamic scope (see Section 7.3.2). This
  463. length field represents the number of elements in the sequence. The
  464. sequence per se is an array of "inner type" elements.
  465. TSDL meta-data representation for a sequence type definition:
  466. struct {
  467. unsigned int length_field;
  468. typedef elem_type typename[length_field];
  469. typename seq_field_name;
  470. }
  471. A sequence can also be declared as a field type, e.g.:
  472. struct {
  473. unsigned int length_field;
  474. long seq_field_name[length_field];
  475. }
  476. Multiple sequences can refer to the same length field, and these length
  477. fields can be in a different upper dynamic scope:
  478. e.g., assuming the stream.event.header defines:
  479. stream {
  480. ...
  481. id = 1;
  482. event.header := struct {
  483. uint16_t seq_len;
  484. };
  485. };
  486. event {
  487. ...
  488. stream_id = 1;
  489. fields := struct {
  490. long seq_a[stream.event.header.seq_len];
  491. char seq_b[stream.event.header.seq_len];
  492. };
  493. };
  494. The sequence elements follow the "array" specifications.
  495. 4.2.5 Strings
  496. Strings are an array of bytes of variable size and are terminated by a '\0'
  497. "NULL" character. Their encoding is described in the TSDL meta-data. In
  498. absence of encoding attribute information, the default encoding is
  499. UTF-8.
  500. TSDL meta-data representation of a named string type:
  501. typealias string {
  502. encoding = UTF8 OR ASCII;
  503. } := name;
  504. A nameless string type can be declared as a field type:
  505. string field_name; /* Use default UTF8 encoding */
  506. Strings are always aligned on byte size.
  507. 5. Event Packet Header
  508. The event packet header consists of two parts: the "event packet header"
  509. is the same for all streams of a trace. The second part, the "event
  510. packet context", is described on a per-stream basis. Both are described
  511. in the TSDL meta-data. The packets are aligned on architecture-page-sized
  512. addresses.
  513. Event packet header (all fields are optional, specified by TSDL meta-data):
  514. - Magic number (CTF magic number: 0xC1FC1FC1) specifies that this is a
  515. CTF packet. This magic number is optional, but when present, it should
  516. come at the very beginning of the packet.
  517. - Trace UUID, used to ensure the event packet match the meta-data used.
  518. (note: we cannot use a meta-data checksum in every cases instead of a
  519. UUID because meta-data can be appended to while tracing is active)
  520. This field is optional.
  521. - Stream ID, used as reference to stream description in meta-data.
  522. This field is optional if there is only one stream description in the
  523. meta-data, but becomes required if there are more than one stream in
  524. the TSDL meta-data description.
  525. Event packet context (all fields are optional, specified by TSDL meta-data):
  526. - Event packet content size (in bits).
  527. - Event packet size (in bits, includes padding).
  528. - Event packet content checksum. Checksum excludes the event packet
  529. header.
  530. - Per-stream event packet sequence count (to deal with UDP packet loss). The
  531. number of significant sequence counter bits should also be present, so
  532. wrap-arounds are dealt with correctly.
  533. - Time-stamp at the beginning and time-stamp at the end of the event packet.
  534. Both timestamps are written in the packet header, but sampled respectively
  535. while (or before) writing the first event and while (or after) writing the
  536. last event in the packet. The inclusive range between these timestamps should
  537. include all event timestamps assigned to events contained within the packet.
  538. - Events discarded count
  539. - Snapshot of a per-stream free-running counter, counting the number of
  540. events discarded that were supposed to be written in the stream prior to
  541. the first event in the event packet.
  542. * Note: producer-consumer buffer full condition should fill the current
  543. event packet with padding so we know exactly where events have been
  544. discarded.
  545. - Lossless compression scheme used for the event packet content. Applied
  546. directly to raw data. New types of compression can be added in following
  547. versions of the format.
  548. 0: no compression scheme
  549. 1: bzip2
  550. 2: gzip
  551. 3: xz
  552. - Cypher used for the event packet content. Applied after compression.
  553. 0: no encryption
  554. 1: AES
  555. - Checksum scheme used for the event packet content. Applied after encryption.
  556. 0: no checksum
  557. 1: md5
  558. 2: sha1
  559. 3: crc32
  560. 5.1 Event Packet Header Description
  561. The event packet header layout is indicated by the trace packet.header
  562. field. Here is a recommended structure type for the packet header with
  563. the fields typically expected (although these fields are each optional):
  564. struct event_packet_header {
  565. uint32_t magic;
  566. uint8_t uuid[16];
  567. uint32_t stream_id;
  568. };
  569. trace {
  570. ...
  571. packet.header := struct event_packet_header;
  572. };
  573. If the magic number is not present, tools such as "file" will have no
  574. mean to discover the file type.
  575. If the uuid is not present, no validation that the meta-data actually
  576. corresponds to the stream is performed.
  577. If the stream_id packet header field is missing, the trace can only
  578. contain a single stream. Its "id" field can be left out, and its events
  579. don't need to declare a "stream_id" field.
  580. 5.2 Event Packet Context Description
  581. Event packet context example. These are declared within the stream declaration
  582. in the meta-data. All these fields are optional. If the packet size field is
  583. missing, the whole stream only contains a single packet. If the content
  584. size field is missing, the packet is filled (no padding). The content
  585. and packet sizes include all headers.
  586. An example event packet context type:
  587. struct event_packet_context {
  588. uint64_t timestamp_begin;
  589. uint64_t timestamp_end;
  590. uint32_t checksum;
  591. uint32_t stream_packet_count;
  592. uint32_t events_discarded;
  593. uint32_t cpu_id;
  594. uint32_t/uint16_t content_size;
  595. uint32_t/uint16_t packet_size;
  596. uint8_t compression_scheme;
  597. uint8_t encryption_scheme;
  598. uint8_t checksum_scheme;
  599. };
  600. 6. Event Structure
  601. The overall structure of an event is:
  602. 1 - Stream Packet Context (as specified by the stream meta-data)
  603. 2 - Event Header (as specified by the stream meta-data)
  604. 3 - Stream Event Context (as specified by the stream meta-data)
  605. 4 - Event Context (as specified by the event meta-data)
  606. 5 - Event Payload (as specified by the event meta-data)
  607. This structure defines an implicit dynamic scoping, where variants
  608. located in inner structures (those with a higher number in the listing
  609. above) can refer to the fields of outer structures (with lower number in
  610. the listing above). See Section 7.3 TSDL Scopes for more detail.
  611. 6.1 Event Header
  612. Event headers can be described within the meta-data. We hereby propose, as an
  613. example, two types of events headers. Type 1 accommodates streams with less than
  614. 31 event IDs. Type 2 accommodates streams with 31 or more event IDs.
  615. One major factor can vary between streams: the number of event IDs assigned to
  616. a stream. Luckily, this information tends to stay relatively constant (modulo
  617. event registration while trace is being recorded), so we can specify different
  618. representations for streams containing few event IDs and streams containing
  619. many event IDs, so we end up representing the event ID and time-stamp as
  620. densely as possible in each case.
  621. The header is extended in the rare occasions where the information cannot be
  622. represented in the ranges available in the standard event header. They are also
  623. used in the rare occasions where the data required for a field could not be
  624. collected: the flag corresponding to the missing field within the missing_fields
  625. array is then set to 1.
  626. Types uintX_t represent an X-bit unsigned integer, as declared with
  627. either:
  628. typealias integer { size = X; align = X; signed = false } := uintX_t;
  629. or
  630. typealias integer { size = X; align = 1; signed = false } := uintX_t;
  631. 6.1.1 Type 1 - Few event IDs
  632. - Aligned on 32-bit (or 8-bit if byte-packed, depending on the architecture
  633. preference).
  634. - Native architecture byte ordering.
  635. - For "compact" selection
  636. - Fixed size: 32 bits.
  637. - For "extended" selection
  638. - Size depends on the architecture and variant alignment.
  639. struct event_header_1 {
  640. /*
  641. * id: range: 0 - 30.
  642. * id 31 is reserved to indicate an extended header.
  643. */
  644. enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
  645. variant <id> {
  646. struct {
  647. uint27_t timestamp;
  648. } compact;
  649. struct {
  650. uint32_t id; /* 32-bit event IDs */
  651. uint64_t timestamp; /* 64-bit timestamps */
  652. } extended;
  653. } v;
  654. } align(32); /* or align(8) */
  655. 6.1.2 Type 2 - Many event IDs
  656. - Aligned on 16-bit (or 8-bit if byte-packed, depending on the architecture
  657. preference).
  658. - Native architecture byte ordering.
  659. - For "compact" selection
  660. - Size depends on the architecture and variant alignment.
  661. - For "extended" selection
  662. - Size depends on the architecture and variant alignment.
  663. struct event_header_2 {
  664. /*
  665. * id: range: 0 - 65534.
  666. * id 65535 is reserved to indicate an extended header.
  667. */
  668. enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;
  669. variant <id> {
  670. struct {
  671. uint32_t timestamp;
  672. } compact;
  673. struct {
  674. uint32_t id; /* 32-bit event IDs */
  675. uint64_t timestamp; /* 64-bit timestamps */
  676. } extended;
  677. } v;
  678. } align(16); /* or align(8) */
  679. 6.2 Event Context
  680. The event context contains information relative to the current event.
  681. The choice and meaning of this information is specified by the TSDL
  682. stream and event meta-data descriptions. The stream context is applied
  683. to all events within the stream. The stream context structure follows
  684. the event header. The event context is applied to specific events. Its
  685. structure follows the stream context structure.
  686. An example of stream-level event context is to save the event payload size with
  687. each event, or to save the current PID with each event. These are declared
  688. within the stream declaration within the meta-data:
  689. stream {
  690. ...
  691. event.context := struct {
  692. uint pid;
  693. uint16_t payload_size;
  694. };
  695. };
  696. An example of event-specific event context is to declare a bitmap of missing
  697. fields, only appended after the stream event context if the extended event
  698. header is selected. NR_FIELDS is the number of fields within the event (a
  699. numeric value).
  700. event {
  701. context = struct {
  702. variant <id> {
  703. struct { } compact;
  704. struct {
  705. uint1_t missing_fields[NR_FIELDS]; /* missing event fields bitmap */
  706. } extended;
  707. } v;
  708. };
  709. ...
  710. }
  711. 6.3 Event Payload
  712. An event payload contains fields specific to a given event type. The fields
  713. belonging to an event type are described in the event-specific meta-data
  714. within a structure type.
  715. 6.3.1 Padding
  716. No padding at the end of the event payload. This differs from the ISO/C standard
  717. for structures, but follows the CTF standard for structures. In a trace, even
  718. though it makes sense to align the beginning of a structure, it really makes no
  719. sense to add padding at the end of the structure, because structures are usually
  720. not followed by a structure of the same type.
  721. This trick can be done by adding a zero-length "end" field at the end of the C
  722. structures, and by using the offset of this field rather than using sizeof()
  723. when calculating the size of a structure (see Appendix "A. Helper macros").
  724. 6.3.2 Alignment
  725. The event payload is aligned on the largest alignment required by types
  726. contained within the payload. (This follows the ISO/C standard for structures)
  727. 7. Trace Stream Description Language (TSDL)
  728. The Trace Stream Description Language (TSDL) allows expression of the
  729. binary trace streams layout in a C99-like Domain Specific Language
  730. (DSL).
  731. 7.1 Meta-data
  732. The trace stream layout description is located in the trace meta-data.
  733. The meta-data is itself located in a stream identified by its name:
  734. "metadata".
  735. The meta-data description can be expressed in two different formats:
  736. text-only and packet-based. The text-only description facilitates
  737. generation of meta-data and provides a convenient way to enter the
  738. meta-data information by hand. The packet-based meta-data provides the
  739. CTF stream packet facilities (checksumming, compression, encryption,
  740. network-readiness) for meta-data stream generated and transported by a
  741. tracer.
  742. The text-only meta-data file is a plain-text TSDL description. This file
  743. must begin with the following characters to identify the file as a CTF
  744. TSDL text-based metadata file (without the double-quotes) :
  745. "/* CTF"
  746. It must be followed by a space, and the version of the specification
  747. followed by the CTF trace, e.g.:
  748. " 1.8"
  749. These characters allow automated discovery of file type and CTF
  750. specification version. They are interpreted as a the beginning of a
  751. comment by the TSDL metadata parser. The comment can be continued to
  752. contain extra commented characters before it is closed.
  753. The packet-based meta-data is made of "meta-data packets", which each
  754. start with a meta-data packet header. The packet-based meta-data
  755. description is detected by reading the magic number "0x75D11D57" at the
  756. beginning of the file. This magic number is also used to detect the
  757. endianness of the architecture by trying to read the CTF magic number
  758. and its counterpart in reversed endianness. The events within the
  759. meta-data stream have no event header nor event context. Each event only
  760. contains a "sequence" payload, which is a sequence of bits using the
  761. "trace.packet.header.content_size" field as a placeholder for its length
  762. (the packet header size should be substracted). The formatting of this
  763. sequence of bits is a plain-text representation of the TSDL description.
  764. Each meta-data packet start with a special packet header, specific to
  765. the meta-data stream, which contains, exactly:
  766. struct metadata_packet_header {
  767. uint32_t magic; /* 0x75D11D57 */
  768. uint8_t uuid[16]; /* Unique Universal Identifier */
  769. uint32_t checksum; /* 0 if unused */
  770. uint32_t content_size; /* in bits */
  771. uint32_t packet_size; /* in bits */
  772. uint8_t compression_scheme; /* 0 if unused */
  773. uint8_t encryption_scheme; /* 0 if unused */
  774. uint8_t checksum_scheme; /* 0 if unused */
  775. uint8_t major; /* CTF spec version major number */
  776. uint8_t minor; /* CTF spec version minor number */
  777. };
  778. The packet-based meta-data can be converted to a text-only meta-data by
  779. concatenating all the strings in contains.
  780. In the textual representation of the meta-data, the text contained
  781. within "/*" and "*/", as well as within "//" and end of line, are
  782. treated as comments. Boolean values can be represented as true, TRUE,
  783. or 1 for true, and false, FALSE, or 0 for false. Within the string-based
  784. meta-data description, the trace UUID is represented as a string of
  785. hexadecimal digits and dashes "-". In the event packet header, the trace
  786. UUID is represented as an array of bytes.
  787. 7.2 Declaration vs Definition
  788. A declaration associates a layout to a type, without specifying where
  789. this type is located in the event structure hierarchy (see Section 6).
  790. This therefore includes typedef, typealias, as well as all type
  791. specifiers. In certain circumstances (typedef, structure field and
  792. variant field), a declaration is followed by a declarator, which specify
  793. the newly defined type name (for typedef), or the field name (for
  794. declarations located within structure and variants). Array and sequence,
  795. declared with square brackets ("[" "]"), are part of the declarator,
  796. similarly to C99. The enumeration base type is specified by
  797. ": enum_base", which is part of the type specifier. The variant tag
  798. name, specified between "<" ">", is also part of the type specifier.
  799. A definition associates a type to a location in the event structure
  800. hierarchy (see Section 6). This association is denoted by ":=", as shown
  801. in Section 7.3.
  802. 7.3 TSDL Scopes
  803. TSDL uses three different types of scoping: a lexical scope is used for
  804. declarations and type definitions, and static and dynamic scopes are
  805. used for variants references to tag fields (with relative and absolute
  806. path lookups) and for sequence references to length fields.
  807. 7.3.1 Lexical Scope
  808. Each of "trace", "env", "stream", "event", "struct" and "variant" have
  809. their own nestable declaration scope, within which types can be declared
  810. using "typedef" and "typealias". A root declaration scope also contains
  811. all declarations located outside of any of the aforementioned
  812. declarations. An inner declaration scope can refer to type declared
  813. within its container lexical scope prior to the inner declaration scope.
  814. Redefinition of a typedef or typealias is not valid, although hiding an
  815. upper scope typedef or typealias is allowed within a sub-scope.
  816. 7.3.2 Static and Dynamic Scopes
  817. A local static scope consists in the scope generated by the declaration
  818. of fields within a compound type. A static scope is a local static scope
  819. augmented with the nested sub-static-scopes it contains.
  820. A dynamic scope consists in the static scope augmented with the
  821. implicit event structure definition hierarchy presented at Section 6.
  822. Multiple declarations of the same field name within a local static scope
  823. is not valid. It is however valid to re-use the same field name in
  824. different local scopes.
  825. Nested static and dynamic scopes form lookup paths. These are used for
  826. variant tag and sequence length references. They are used at the variant
  827. and sequence definition site to look up the location of the tag field
  828. associated with a variant, and to lookup up the location of the length
  829. field associated with a sequence.
  830. Variants and sequences can refer to a tag field either using a relative
  831. path or an absolute path. The relative path is relative to the scope in
  832. which the variant or sequence performing the lookup is located.
  833. Relative paths are only allowed to lookup within the same static scope,
  834. which includes its nested static scopes. Lookups targeting parent static
  835. scopes need to be performed with an absolute path.
  836. Absolute path lookups use the full path including the dynamic scope
  837. followed by a "." and then the static scope. Therefore, variants (or
  838. sequences) in lower levels in the dynamic scope (e.g. event context) can
  839. refer to a tag (or length) field located in upper levels (e.g. in the
  840. event header) by specifying, in this case, the associated tag with
  841. <stream.event.header.field_name>. This allows, for instance, the event
  842. context to define a variant referring to the "id" field of the event
  843. header as selector.
  844. The dynamic scope prefixes are thus:
  845. - Trace Environment: <env. >,
  846. - Trace Packet Header: <trace.packet.header. >,
  847. - Stream Packet Context: <stream.packet.context. >,
  848. - Event Header: <stream.event.header. >,
  849. - Stream Event Context: <stream.event.context. >,
  850. - Event Context: <event.context. >,
  851. - Event Payload: <event.fields. >.
  852. The target dynamic scope must be specified explicitly when referring to
  853. a field outside of the static scope (absolute scope reference). No
  854. conflict can occur between relative and dynamic paths, because the
  855. keywords "trace", "stream", and "event" are reserved, and thus
  856. not permitted as field names. It is recommended that field names
  857. clashing with CTF and C99 reserved keywords use an underscore prefix to
  858. eliminate the risk of generating a description containing an invalid
  859. field name. Consequently, fields starting with an underscore should have
  860. their leading underscore removed by the CTF trace readers.
  861. The information available in the dynamic scopes can be thought of as the
  862. current tracing context. At trace production, information about the
  863. current context is saved into the specified scope field levels. At trace
  864. consumption, for each event, the current trace context is therefore
  865. readable by accessing the upper dynamic scopes.
  866. 7.4 TSDL Examples
  867. The grammar representing the TSDL meta-data is presented in Appendix C.
  868. TSDL Grammar. This section presents a rather lighter reading that
  869. consists in examples of TSDL meta-data, with template values.
  870. The stream "id" can be left out if there is only one stream in the
  871. trace. The event "id" field can be left out if there is only one event
  872. in a stream.
  873. trace {
  874. major = value; /* CTF spec version major number */
  875. minor = value; /* CTF spec version minor number */
  876. uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; /* Trace UUID */
  877. byte_order = be OR le; /* Endianness (required) */
  878. packet.header := struct {
  879. uint32_t magic;
  880. uint8_t uuid[16];
  881. uint32_t stream_id;
  882. };
  883. };
  884. /*
  885. * The "env" (environment) scope contains assignment expressions. The
  886. * field names and content are implementation-defined.
  887. */
  888. env {
  889. pid = value; /* example */
  890. proc_name = "name"; /* example */
  891. ...
  892. };
  893. stream {
  894. id = stream_id;
  895. /* Type 1 - Few event IDs; Type 2 - Many event IDs. See section 6.1. */
  896. event.header := event_header_1 OR event_header_2;
  897. event.context := struct {
  898. ...
  899. };
  900. packet.context := struct {
  901. ...
  902. };
  903. };
  904. event {
  905. name = "event_name";
  906. id = value; /* Numeric identifier within the stream */
  907. stream_id = stream_id;
  908. loglevel = value;
  909. context := struct {
  910. ...
  911. };
  912. fields := struct {
  913. ...
  914. };
  915. };
  916. /* More detail on types in section 4. Types */
  917. /*
  918. * Named types:
  919. *
  920. * Type declarations behave similarly to the C standard.
  921. */
  922. typedef aliased_type_specifiers new_type_declarators;
  923. /* e.g.: typedef struct example new_type_name[10]; */
  924. /*
  925. * typealias
  926. *
  927. * The "typealias" declaration can be used to give a name (including
  928. * pointer declarator specifier) to a type. It should also be used to
  929. * map basic C types (float, int, unsigned long, ...) to a CTF type.
  930. * Typealias is a superset of "typedef": it also allows assignment of a
  931. * simple variable identifier to a type.
  932. */
  933. typealias type_class {
  934. ...
  935. } := type_specifiers type_declarator;
  936. /*
  937. * e.g.:
  938. * typealias integer {
  939. * size = 32;
  940. * align = 32;
  941. * signed = false;
  942. * } := struct page *;
  943. *
  944. * typealias integer {
  945. * size = 32;
  946. * align = 32;
  947. * signed = true;
  948. * } := int;
  949. */
  950. struct name {
  951. ...
  952. };
  953. variant name {
  954. ...
  955. };
  956. enum name : integer_type {
  957. ...
  958. };
  959. /*
  960. * Unnamed types, contained within compound type fields, typedef or typealias.
  961. */
  962. struct {
  963. ...
  964. }
  965. struct {
  966. ...
  967. } align(value)
  968. variant {
  969. ...
  970. }
  971. enum : integer_type {
  972. ...
  973. }
  974. typedef type new_type[length];
  975. struct {
  976. type field_name[length];
  977. }
  978. typedef type new_type[length_type];
  979. struct {
  980. type field_name[length_type];
  981. }
  982. integer {
  983. ...
  984. }
  985. floating_point {
  986. ...
  987. }
  988. struct {
  989. integer_type field_name:size; /* GNU/C bitfield */
  990. }
  991. struct {
  992. string field_name;
  993. }
  994. 8. Clocks
  995. Clock metadata allows to describe the clock topology of the system, as
  996. well as to detail each clock parameter. In absence of clock description,
  997. it is assumed that all fields named "timestamp" use the same clock
  998. source, which increments once per nanosecond.
  999. Describing a clock and how it is used by streams is threefold: first,
  1000. the clock and clock topology should be described in a "clock"
  1001. description block, e.g.:
  1002. clock {
  1003. name = cycle_counter_sync;
  1004. uuid = "62189bee-96dc-11e0-91a8-cfa3d89f3923";
  1005. description = "Cycle counter synchronized across CPUs";
  1006. freq = 1000000000; /* frequency, in Hz */
  1007. /* precision in seconds is: 1000 * (1/freq) */
  1008. precision = 1000;
  1009. /*
  1010. * clock value offset from Epoch is:
  1011. * offset_s + (offset * (1/freq))
  1012. */
  1013. offset_s = 1326476837;
  1014. offset = 897235420;
  1015. absolute = FALSE;
  1016. };
  1017. The mandatory "name" field specifies the name of the clock identifier,
  1018. which can later be used as a reference. The optional field "uuid" is the
  1019. unique identifier of the clock. It can be used to correlate different
  1020. traces that use the same clock. An optional textual description string
  1021. can be added with the "description" field. The "freq" field is the
  1022. initial frequency of the clock, in Hz. If the "freq" field is not
  1023. present, the frequency is assumed to be 1000000000 (providing clock
  1024. increment of 1 ns). The optional "precision" field details the
  1025. uncertainty on the clock measurements, in (1/freq) units. The "offset_s"
  1026. and "offset" fields indicate the offset from POSIX.1 Epoch, 1970-01-01
  1027. 00:00:00 +0000 (UTC), to the zero of value of the clock. The "offset_s"
  1028. field is in seconds. The "offset" field is in (1/freq) units. If any of
  1029. the "offset_s" or "offset" field is not present, it is assigned the 0
  1030. value. The field "absolute" is TRUE if the clock is a global reference
  1031. across different clock uuid (e.g. NTP time). Otherwise, "absolute" is
  1032. FALSE, and the clock can be considered as synchronized only with other
  1033. clocks that have the same uuid.
  1034. Secondly, a reference to this clock should be added within an integer
  1035. type:
  1036. typealias integer {
  1037. size = 64; align = 1; signed = false;
  1038. map = clock.cycle_counter_sync.value;
  1039. } := uint64_ccnt_t;
  1040. Thirdly, stream declarations can reference the clock they use as a
  1041. time-stamp source:
  1042. struct packet_context {
  1043. uint64_ccnt_t ccnt_begin;
  1044. uint64_ccnt_t ccnt_end;
  1045. /* ... */
  1046. };
  1047. stream {
  1048. /* ... */
  1049. event.header := struct {
  1050. uint64_ccnt_t timestamp;
  1051. /* ... */
  1052. }
  1053. packet.context := struct packet_context;
  1054. };
  1055. For a N-bit integer type referring to a clock, if the integer overflows
  1056. compared to the N low order bits of the clock prior value, then it is
  1057. assumed that one, and only one, overflow occurred. It is therefore
  1058. important that events encoding time on a small number of bits happen
  1059. frequently enough to detect when more than one N-bit overflow occurs.
  1060. In a packet context, clock field names ending with "_begin" and "_end"
  1061. have a special meaning: this refers to the time-stamps at, respectively,
  1062. the beginning and the end of each packet.
  1063. A. Helper macros
  1064. The two following macros keep track of the size of a GNU/C structure without
  1065. padding at the end by placing HEADER_END as the last field. A one byte end field
  1066. is used for C90 compatibility (C99 flexible arrays could be used here). Note
  1067. that this does not affect the effective structure size, which should always be
  1068. calculated with the header_sizeof() helper.
  1069. #define HEADER_END char end_field
  1070. #define header_sizeof(type) offsetof(typeof(type), end_field)
  1071. B. Stream Header Rationale
  1072. An event stream is divided in contiguous event packets of variable size. These
  1073. subdivisions allow the trace analyzer to perform a fast binary search by time
  1074. within the stream (typically requiring to index only the event packet headers)
  1075. without reading the whole stream. These subdivisions have a variable size to
  1076. eliminate the need to transfer the event packet padding when partially filled
  1077. event packets must be sent when streaming a trace for live viewing/analysis.
  1078. An event packet can contain a certain amount of padding at the end. Dividing
  1079. streams into event packets is also useful for network streaming over UDP and
  1080. flight recorder mode tracing (a whole event packet can be swapped out of the
  1081. buffer atomically for reading).
  1082. The stream header is repeated at the beginning of each event packet to allow
  1083. flexibility in terms of:
  1084. - streaming support,
  1085. - allowing arbitrary buffers to be discarded without making the trace
  1086. unreadable,
  1087. - allow UDP packet loss handling by either dealing with missing event packet
  1088. or asking for re-transmission.
  1089. - transparently support flight recorder mode,
  1090. - transparently support crash dump.
  1091. C. TSDL Grammar
  1092. /*
  1093. * Common Trace Format (CTF) Trace Stream Description Language (TSDL) Grammar.
  1094. *
  1095. * Inspired from the C99 grammar:
  1096. * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf (Annex A)
  1097. * and c++1x grammar (draft)
  1098. * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3291.pdf (Annex A)
  1099. *
  1100. * Specialized for CTF needs by including only constant and declarations from
  1101. * C99 (excluding function declarations), and by adding support for variants,
  1102. * sequences and CTF-specific specifiers. Enumeration container types
  1103. * semantic is inspired from c++1x enum-base.
  1104. */
  1105. 1) Lexical grammar
  1106. 1.1) Lexical elements
  1107. token:
  1108. keyword
  1109. identifier
  1110. constant
  1111. string-literal
  1112. punctuator
  1113. 1.2) Keywords
  1114. keyword: is one of
  1115. align
  1116. const
  1117. char
  1118. clock
  1119. double
  1120. enum
  1121. env
  1122. event
  1123. floating_point
  1124. float
  1125. integer
  1126. int
  1127. long
  1128. short
  1129. signed
  1130. stream
  1131. string
  1132. struct
  1133. trace
  1134. typealias
  1135. typedef
  1136. unsigned
  1137. variant
  1138. void
  1139. _Bool
  1140. _Complex
  1141. _Imaginary
  1142. 1.3) Identifiers
  1143. identifier:
  1144. identifier-nondigit
  1145. identifier identifier-nondigit
  1146. identifier digit
  1147. identifier-nondigit:
  1148. nondigit
  1149. universal-character-name
  1150. any other implementation-defined characters
  1151. nondigit:
  1152. _
  1153. [a-zA-Z] /* regular expression */
  1154. digit:
  1155. [0-9] /* regular expression */
  1156. 1.4) Universal character names
  1157. universal-character-name:
  1158. \u hex-quad
  1159. \U hex-quad hex-quad
  1160. hex-quad:
  1161. hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit
  1162. 1.5) Constants
  1163. constant:
  1164. integer-constant
  1165. enumeration-constant
  1166. character-constant
  1167. integer-constant:
  1168. decimal-constant integer-suffix-opt
  1169. octal-constant integer-suffix-opt
  1170. hexadecimal-constant integer-suffix-opt
  1171. decimal-constant:
  1172. nonzero-digit
  1173. decimal-constant digit
  1174. octal-constant:
  1175. 0
  1176. octal-constant octal-digit
  1177. hexadecimal-constant:
  1178. hexadecimal-prefix hexadecimal-digit
  1179. hexadecimal-constant hexadecimal-digit
  1180. hexadecimal-prefix:
  1181. 0x
  1182. 0X
  1183. nonzero-digit:
  1184. [1-9]
  1185. integer-suffix:
  1186. unsigned-suffix long-suffix-opt
  1187. unsigned-suffix long-long-suffix
  1188. long-suffix unsigned-suffix-opt
  1189. long-long-suffix unsigned-suffix-opt
  1190. unsigned-suffix:
  1191. u
  1192. U
  1193. long-suffix:
  1194. l
  1195. L
  1196. long-long-suffix:
  1197. ll
  1198. LL
  1199. enumeration-constant:
  1200. identifier
  1201. string-literal
  1202. character-constant:
  1203. ' c-char-sequence '
  1204. L' c-char-sequence '
  1205. c-char-sequence:
  1206. c-char
  1207. c-char-sequence c-char
  1208. c-char:
  1209. any member of source charset except single-quote ('), backslash
  1210. (\), or new-line character.
  1211. escape-sequence
  1212. escape-sequence:
  1213. simple-escape-sequence
  1214. octal-escape-sequence
  1215. hexadecimal-escape-sequence
  1216. universal-character-name
  1217. simple-escape-sequence: one of
  1218. \' \" \? \\ \a \b \f \n \r \t \v
  1219. octal-escape-sequence:
  1220. \ octal-digit
  1221. \ octal-digit octal-digit
  1222. \ octal-digit octal-digit octal-digit
  1223. hexadecimal-escape-sequence:
  1224. \x hexadecimal-digit
  1225. hexadecimal-escape-sequence hexadecimal-digit
  1226. 1.6) String literals
  1227. string-literal:
  1228. " s-char-sequence-opt "
  1229. L" s-char-sequence-opt "
  1230. s-char-sequence:
  1231. s-char
  1232. s-char-sequence s-char
  1233. s-char:
  1234. any member of source charset except double-quote ("), backslash
  1235. (\), or new-line character.
  1236. escape-sequence
  1237. 1.7) Punctuators
  1238. punctuator: one of
  1239. [ ] ( ) { } . -> * + - < > : ; ... = ,
  1240. 2) Phrase structure grammar
  1241. primary-expression:
  1242. identifier
  1243. constant
  1244. string-literal
  1245. ( unary-expression )
  1246. postfix-expression:
  1247. primary-expression
  1248. postfix-expression [ unary-expression ]
  1249. postfix-expression . identifier
  1250. postfix-expressoin -> identifier
  1251. unary-expression:
  1252. postfix-expression
  1253. unary-operator postfix-expression
  1254. unary-operator: one of
  1255. + -
  1256. assignment-operator:
  1257. =
  1258. type-assignment-operator:
  1259. :=
  1260. constant-expression-range:
  1261. unary-expression ... unary-expression
  1262. 2.2) Declarations:
  1263. declaration:
  1264. declaration-specifiers declarator-list-opt ;
  1265. ctf-specifier ;
  1266. declaration-specifiers:
  1267. storage-class-specifier declaration-specifiers-opt
  1268. type-specifier declaration-specifiers-opt
  1269. type-qualifier declaration-specifiers-opt
  1270. declarator-list:
  1271. declarator
  1272. declarator-list , declarator
  1273. abstract-declarator-list:
  1274. abstract-declarator
  1275. abstract-declarator-list , abstract-declarator
  1276. storage-class-specifier:
  1277. typedef
  1278. type-specifier:
  1279. void
  1280. char
  1281. short
  1282. int
  1283. long
  1284. float
  1285. double
  1286. signed
  1287. unsigned
  1288. _Bool
  1289. _Complex
  1290. _Imaginary
  1291. struct-specifier
  1292. variant-specifier
  1293. enum-specifier
  1294. typedef-name
  1295. ctf-type-specifier
  1296. align-attribute:
  1297. align ( unary-expression )
  1298. struct-specifier:
  1299. struct identifier-opt { struct-or-variant-declaration-list-opt } align-attribute-opt
  1300. struct identifier align-attribute-opt
  1301. struct-or-variant-declaration-list:
  1302. struct-or-variant-declaration
  1303. struct-or-variant-declaration-list struct-or-variant-declaration
  1304. struct-or-variant-declaration:
  1305. specifier-qualifier-list struct-or-variant-declarator-list ;
  1306. declaration-specifiers-opt storage-class-specifier declaration-specifiers-opt declarator-list ;
  1307. typealias declaration-specifiers abstract-declarator-list type-assignment-operator declaration-specifiers abstract-declarator-list ;
  1308. typealias declaration-specifiers abstract-declarator-list type-assignment-operator declarator-list ;
  1309. specifier-qualifier-list:
  1310. type-specifier specifier-qualifier-list-opt
  1311. type-qualifier specifier-qualifier-list-opt
  1312. struct-or-variant-declarator-list:
  1313. struct-or-variant-declarator
  1314. struct-or-variant-declarator-list , struct-or-variant-declarator
  1315. struct-or-variant-declarator:
  1316. declarator
  1317. declarator-opt : unary-expression
  1318. variant-specifier:
  1319. variant identifier-opt variant-tag-opt { struct-or-variant-declaration-list }
  1320. variant identifier variant-tag
  1321. variant-tag:
  1322. < unary-expression >
  1323. enum-specifier:
  1324. enum identifier-opt { enumerator-list }
  1325. enum identifier-opt { enumerator-list , }
  1326. enum identifier
  1327. enum identifier-opt : declaration-specifiers { enumerator-list }
  1328. enum identifier-opt : declaration-specifiers { enumerator-list , }
  1329. enumerator-list:
  1330. enumerator
  1331. enumerator-list , enumerator
  1332. enumerator:
  1333. enumeration-constant
  1334. enumeration-constant assignment-operator unary-expression
  1335. enumeration-constant assignment-operator constant-expression-range
  1336. type-qualifier:
  1337. const
  1338. declarator:
  1339. pointer-opt direct-declarator
  1340. direct-declarator:
  1341. identifier
  1342. ( declarator )
  1343. direct-declarator [ unary-expression ]
  1344. abstract-declarator:
  1345. pointer-opt direct-abstract-declarator
  1346. direct-abstract-declarator:
  1347. identifier-opt
  1348. ( abstract-declarator )
  1349. direct-abstract-declarator [ unary-expression ]
  1350. direct-abstract-declarator [ ]
  1351. pointer:
  1352. * type-qualifier-list-opt
  1353. * type-qualifier-list-opt pointer
  1354. type-qualifier-list:
  1355. type-qualifier
  1356. type-qualifier-list type-qualifier
  1357. typedef-name:
  1358. identifier
  1359. 2.3) CTF-specific declarations
  1360. ctf-specifier:
  1361. clock { ctf-assignment-expression-list-opt }
  1362. event { ctf-assignment-expression-list-opt }
  1363. stream { ctf-assignment-expression-list-opt }
  1364. env { ctf-assignment-expression-list-opt }
  1365. trace { ctf-assignment-expression-list-opt }
  1366. typealias declaration-specifiers abstract-declarator-list type-assignment-operator declaration-specifiers abstract-declarator-list
  1367. typealias declaration-specifiers abstract-declarator-list type-assignment-operator declarator-list
  1368. ctf-type-specifier:
  1369. floating_point { ctf-assignment-expression-list-opt }
  1370. integer { ctf-assignment-expression-list-opt }
  1371. string { ctf-assignment-expression-list-opt }
  1372. string
  1373. ctf-assignment-expression-list:
  1374. ctf-assignment-expression ;
  1375. ctf-assignment-expression-list ctf-assignment-expression ;
  1376. ctf-assignment-expression:
  1377. unary-expression assignment-operator unary-expression
  1378. unary-expression type-assignment-operator type-specifier
  1379. declaration-specifiers-opt storage-class-specifier declaration-specifiers-opt declarator-list
  1380. typealias declaration-specifiers abstract-declarator-list type-assignment-operator declaration-specifiers abstract-declarator-list
  1381. typealias declaration-specifiers abstract-declarator-list type-assignment-operator declarator-list

转载于:https://my.oschina.net/u/263896/blog/53175

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/561432
推荐阅读
相关标签
  

闽ICP备14008679号