ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / formats / ctf-text / types / integer.c
index 9602a902a766d8673a14e8896ee91bc59e3d34e7..c08aa4bc24412b3573fd27af9b147ae703adb9dd 100644 (file)
@@ -31,6 +31,7 @@
 #include <inttypes.h>
 #include <stdint.h>
 #include <babeltrace/bitfield.h>
+#include <babeltrace/trace-debug-info.h>
 
 int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
@@ -100,10 +101,20 @@ int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *def
        {
                uint64_t v;
 
-               if (!integer_declaration->signedness)
+               if (!integer_declaration->signedness) {
                        v = integer_definition->value._unsigned;
-               else
+               } else {
                        v = (uint64_t) integer_definition->value._signed;
+                       if (integer_declaration->len < 64) {
+                               size_t len = integer_declaration->len;
+                               size_t rounded_len;
+
+                               assert(len != 0);
+                               /* Round length to the nearest 3-bit */
+                               rounded_len = (((len - 1) / 3) + 1) * 3;
+                               v &= ((uint64_t) 1 << rounded_len) - 1;
+                       }
+               }
 
                fprintf(pos->fp, "0%" PRIo64, v);
                break;
@@ -115,11 +126,14 @@ int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *def
                if (!integer_declaration->signedness) {
                        v = integer_definition->value._unsigned;
                } else {
-                       /* Round length to the nearest nibble */
-                       uint8_t rounded_len = ((integer_declaration->len + 3) & ~0x3);
-
                        v = (uint64_t) integer_definition->value._signed;
-                       v &= ((uint64_t) 1 << rounded_len) - 1;
+                       if (integer_declaration->len < 64) {
+                               /* Round length to the nearest nibble */
+                               uint8_t rounded_len =
+                                       ((integer_declaration->len + 3) & ~0x3);
+
+                               v &= ((uint64_t) 1 << rounded_len) - 1;
+                       }
                }
 
                fprintf(pos->fp, "0x%" PRIX64, v);
@@ -129,5 +143,7 @@ int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *def
                return -EINVAL;
        }
 
+       ctf_text_integer_write_debug_info(ppos, definition);
+
        return 0;
 }
This page took 0.024189 seconds and 4 git commands to generate.