Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * jitdump.h: jitted code info encapsulation file format |
| 3 | * |
| 4 | * Adapted from OProfile GPLv2 support jidump.h: |
| 5 | * Copyright 2007 OProfile authors |
| 6 | * Jens Wilke |
| 7 | * Daniel Hansel |
| 8 | * Copyright IBM Corporation 2007 |
| 9 | */ |
| 10 | #ifndef JITDUMP_H |
| 11 | #define JITDUMP_H |
| 12 | |
| 13 | #include <sys/time.h> |
| 14 | #include <time.h> |
| 15 | #include <stdint.h> |
| 16 | |
| 17 | /* JiTD */ |
| 18 | #define JITHEADER_MAGIC 0x4A695444 |
| 19 | #define JITHEADER_MAGIC_SW 0x4454694A |
| 20 | |
| 21 | #define PADDING_8ALIGNED(x) ((((x) + 7) & 7) ^ 7) |
| 22 | |
| 23 | #define JITHEADER_VERSION 1 |
| 24 | |
| 25 | enum jitdump_flags_bits { |
Adrian Hunter | 2a28e23 | 2016-03-08 10:38:50 +0200 | [diff] [blame] | 26 | JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT, |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 27 | JITDUMP_FLAGS_MAX_BIT, |
| 28 | }; |
| 29 | |
Adrian Hunter | 2a28e23 | 2016-03-08 10:38:50 +0200 | [diff] [blame] | 30 | #define JITDUMP_FLAGS_ARCH_TIMESTAMP (1ULL << JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT) |
| 31 | |
Stephane Eranian | 9b07e27 | 2015-11-30 10:02:21 +0100 | [diff] [blame] | 32 | #define JITDUMP_FLAGS_RESERVED (JITDUMP_FLAGS_MAX_BIT < 64 ? \ |
| 33 | (~((1ULL << JITDUMP_FLAGS_MAX_BIT) - 1)) : 0) |
| 34 | |
| 35 | struct jitheader { |
| 36 | uint32_t magic; /* characters "jItD" */ |
| 37 | uint32_t version; /* header version */ |
| 38 | uint32_t total_size; /* total size of header */ |
| 39 | uint32_t elf_mach; /* elf mach target */ |
| 40 | uint32_t pad1; /* reserved */ |
| 41 | uint32_t pid; /* JIT process id */ |
| 42 | uint64_t timestamp; /* timestamp */ |
| 43 | uint64_t flags; /* flags */ |
| 44 | }; |
| 45 | |
| 46 | enum jit_record_type { |
| 47 | JIT_CODE_LOAD = 0, |
| 48 | JIT_CODE_MOVE = 1, |
| 49 | JIT_CODE_DEBUG_INFO = 2, |
| 50 | JIT_CODE_CLOSE = 3, |
| 51 | |
| 52 | JIT_CODE_MAX, |
| 53 | }; |
| 54 | |
| 55 | /* record prefix (mandatory in each record) */ |
| 56 | struct jr_prefix { |
| 57 | uint32_t id; |
| 58 | uint32_t total_size; |
| 59 | uint64_t timestamp; |
| 60 | }; |
| 61 | |
| 62 | struct jr_code_load { |
| 63 | struct jr_prefix p; |
| 64 | |
| 65 | uint32_t pid; |
| 66 | uint32_t tid; |
| 67 | uint64_t vma; |
| 68 | uint64_t code_addr; |
| 69 | uint64_t code_size; |
| 70 | uint64_t code_index; |
| 71 | }; |
| 72 | |
| 73 | struct jr_code_close { |
| 74 | struct jr_prefix p; |
| 75 | }; |
| 76 | |
| 77 | struct jr_code_move { |
| 78 | struct jr_prefix p; |
| 79 | |
| 80 | uint32_t pid; |
| 81 | uint32_t tid; |
| 82 | uint64_t vma; |
| 83 | uint64_t old_code_addr; |
| 84 | uint64_t new_code_addr; |
| 85 | uint64_t code_size; |
| 86 | uint64_t code_index; |
| 87 | }; |
| 88 | |
| 89 | struct debug_entry { |
| 90 | uint64_t addr; |
| 91 | int lineno; /* source line number starting at 1 */ |
| 92 | int discrim; /* column discriminator, 0 is default */ |
| 93 | const char name[0]; /* null terminated filename, \xff\0 if same as previous entry */ |
| 94 | }; |
| 95 | |
| 96 | struct jr_code_debug_info { |
| 97 | struct jr_prefix p; |
| 98 | |
| 99 | uint64_t code_addr; |
| 100 | uint64_t nr_entry; |
| 101 | struct debug_entry entries[0]; |
| 102 | }; |
| 103 | |
| 104 | union jr_entry { |
| 105 | struct jr_code_debug_info info; |
| 106 | struct jr_code_close close; |
| 107 | struct jr_code_load load; |
| 108 | struct jr_code_move move; |
| 109 | struct jr_prefix prefix; |
| 110 | }; |
| 111 | |
| 112 | static inline struct debug_entry * |
| 113 | debug_entry_next(struct debug_entry *ent) |
| 114 | { |
| 115 | void *a = ent + 1; |
| 116 | size_t l = strlen(ent->name) + 1; |
| 117 | return a + l; |
| 118 | } |
| 119 | |
| 120 | static inline char * |
| 121 | debug_entry_file(struct debug_entry *ent) |
| 122 | { |
| 123 | void *a = ent + 1; |
| 124 | return a; |
| 125 | } |
| 126 | |
| 127 | #endif /* !JITDUMP_H */ |