14 #include <linux/compiler.h> 15 #include <sys/types.h> 30 #include "../util/jitdump.h" 32 #define BUFFER_EXT_DFL_SIZE (4 * 1024) 51 warnx(
"DUMP for %s", msg);
52 for (i = 0 ; i < be->
cur_pos; i++)
53 warnx(
"%4zu 0x%02x", i, (((
char *)be->
data)[i]) & 0xff);
63 if ((be->
cur_pos + sz) < be_sz) {
74 tmp = realloc(be->
data, be_sz);
144 #define DW_LNS_num_opcode (DW_LNS_set_isa + 1) 151 .minimum_instruction_length = 1,
152 .default_is_stmt = 1,
160 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1
164 [DW_LNS_advance_pc] = 1,
165 [DW_LNS_advance_line] = 1,
166 [DW_LNS_set_file] = 1,
167 [DW_LNS_set_column] = 1,
168 [DW_LNS_fixed_advance_pc] = 1,
169 [DW_LNS_set_isa] = 1,
177 .debug_abbrev_offset = 0,
178 .pointer_size =
sizeof(
void *)
195 ubyte cur = data & 0x7F;
206 int negative = data < 0;
207 int size =
sizeof(long) * CHAR_BIT;
209 ubyte cur = data & 0x7F;
212 data |= - (1 << (size - 7));
213 if ((data == 0 && !(cur & 0x40)) ||
214 (data == -1l && (cur & 0x40)))
223 void *
data,
size_t data_len)
296 unsigned int last_line,
297 unsigned long last_vma)
300 unsigned long delta_addr;
305 temp = (ent->
lineno - last_line) - default_debug_line_header.
line_base;
319 if (delta_addr <= 256 / default_debug_line_header.
line_range) {
320 unsigned long opcode = temp +
321 (delta_addr * default_debug_line_header.
line_range) +
324 return opcode <= 255 ? opcode : 0;
331 unsigned long code_addr)
347 unsigned long last_vma = code_addr;
348 char const *cur_filename = NULL;
349 unsigned long cur_file_idx = 0;
356 ubyte special_opcode;
361 if (!cur_filename || strcmp(cur_filename, ent->name)) {
363 cur_filename = ent->name;
369 if (special_opcode != 0) {
370 last_line = ent->lineno;
371 last_vma = ent->addr;
377 if (last_line != ent->lineno) {
379 last_line = ent->lineno;
385 if (last_vma != ent->addr) {
387 last_vma = ent->addr;
401 unsigned long code_addr)
409 sizeof(default_debug_line_header));
447 size_t offset_debug_line)
453 sizeof(default_comp_unit_header));
465 void *
debug,
int nr_debug_entries,
473 for (i = 0; i < nr_debug_entries; i++) {
506 warnx(
"cannot create section");
510 d = elf_newdata(scn);
512 warnx(
"cannot get new data");
519 d->d_type = ELF_T_BYTE;
521 d->d_version = EV_CURRENT;
525 warnx(
"cannot get section header");
530 shdr->sh_type = SHT_PROGBITS;
533 shdr->sh_entsize = 0;
540 warnx(
"cannot create section");
544 d = elf_newdata(scn);
546 warnx(
"cannot get new data");
553 d->d_type = ELF_T_BYTE;
555 d->d_version = EV_CURRENT;
559 warnx(
"cannot get section header");
564 shdr->sh_type = SHT_PROGBITS;
567 shdr->sh_entsize = 0;
574 warnx(
"cannot create section");
578 d = elf_newdata(scn);
580 warnx(
"cannot get new data");
587 d->d_type = ELF_T_BYTE;
589 d->d_version = EV_CURRENT;
593 warnx(
"cannot get section header");
598 shdr->sh_type = SHT_PROGBITS;
601 shdr->sh_entsize = 0;
606 if (elf_update(e, ELF_C_WRITE) < 0) {
607 warnx(
"elf_update debug failed");
static void emit_uword(struct buffer_ext *be, uword data)
static size_t buffer_ext_size(struct buffer_ext *be)
#define BUFFER_EXT_DFL_SIZE
#define DW_LNS_num_opcode
static struct compilation_unit_header default_comp_unit_header
static void add_debug_abbrev(struct buffer_ext *be)
static void add_compilation_unit(struct buffer_ext *be, size_t offset_debug_line)
static ubyte get_special_opcode(struct debug_entry *ent, unsigned int last_line, unsigned long last_vma)
static void emit_signed_LEB128(struct buffer_ext *be, long data)
static void emit_lne_set_address(struct buffer_ext *be, void *address)
static void * buffer_ext_addr(struct buffer_ext *be)
static void emit_unsigned_LEB128(struct buffer_ext *be, unsigned long data)
static void emit_opcode(struct buffer_ext *be, ubyte opcode)
struct debug_line_header __packed
static ubyte standard_opcode_length[]
static void emit_extended_opcode(struct buffer_ext *be, ubyte opcode, void *data, size_t data_len)
static void emit_lne_define_filename(struct buffer_ext *be, const char *filename)
static void emit_advance_pc(struct buffer_ext *be, unsigned long delta_pc)
static int buffer_ext_add(struct buffer_ext *be, void *addr, size_t sz)
int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_entries)
static struct debug_line_header const default_debug_line_header
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms
static void add_debug_line(struct buffer_ext *be, struct debug_entry *ent, size_t nr_entry, unsigned long code_addr)
static void buffer_ext_init(struct buffer_ext *be)
static void emit_advance_lineno(struct buffer_ext *be, long delta_lineno)
static void buffer_ext_dump(struct buffer_ext *be, const char *msg)
static int jit_process_debug_info(uint64_t code_addr, void *debug, int nr_debug_entries, struct buffer_ext *dl, struct buffer_ext *da, struct buffer_ext *di)
static void emit_opcode_signed(struct buffer_ext *be, ubyte opcode, long data)
static void emit_lne_end_of_sequence(struct buffer_ext *be)
static void emit_opcode_unsigned(struct buffer_ext *be, ubyte opcode, unsigned long data)
static void emit_lineno_info(struct buffer_ext *be, struct debug_entry *ent, size_t nr_entry, unsigned long code_addr)
static void emit_set_file(struct buffer_ext *be, unsigned long idx)
static void emit_string(struct buffer_ext *be, const char *s)
static struct debug_entry * debug_entry_next(struct debug_entry *ent)