Skip to content

Commit

Permalink
Add DW_AT_comp_dir to elf files.
Browse files Browse the repository at this point in the history
This commit adds the compilation directory debug information for ELF files.
This feature helps debuggers locate the source file when debugging.
The feature is already present for Mach-O files.

Signed-off-by: Marco Vanotti <mvanotti@dc.uba.ar>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
  • Loading branch information
mvanotti authored and cyrillos committed May 8, 2021
1 parent a9faae3 commit f2a6eb4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions output/outelf.c
Expand Up @@ -84,6 +84,7 @@ static struct hash_table section_by_name;
static struct elf_symbol *fwds;

static char elf_module[FILENAME_MAX];
static char elf_dir[FILENAME_MAX];

extern const struct ofmt of_elf32;
extern const struct ofmt of_elf64;
Expand Down Expand Up @@ -552,8 +553,10 @@ static void elf_init(void)
".shstrtab", ".strtab", ".symtab", ".symtab_shndx", NULL
};
const char * const *p;
const char * cur_path = nasm_realpath(inname);

strlcpy(elf_module, inname, sizeof(elf_module));
strlcpy(elf_dir, nasm_dirname(cur_path), sizeof(elf_dir));
sects = NULL;
nsects = sectlen = 0;
syms = saa_init((int32_t)sizeof(struct elf_symbol));
Expand Down Expand Up @@ -3307,7 +3310,8 @@ static void dwarf_generate(void)
saa_write32(pinforel, (dwarf_linesym << 8) + R_386_32); /* reloc to line */
saa_write32(pinforel, 0);
saa_write32(pinfo,0); /* DW_AT_stmt_list */
saa_wbytes(pinfo, elf_module, strlen(elf_module)+1);
saa_wbytes(pinfo, elf_module, strlen(elf_module)+1); /* DW_AT_name */
saa_wbytes(pinfo, elf_dir, strlen(elf_dir)+1); /* DW_AT_comp_dir */
saa_wbytes(pinfo, nasm_signature(), nasm_signature_len()+1);
saa_write16(pinfo,DW_LANG_Mips_Assembler);
saa_write8(pinfo,2); /* abbrviation number LEB128u */
Expand Down Expand Up @@ -3346,7 +3350,8 @@ static void dwarf_generate(void)
saa_write32(pinforel, (dwarf_linesym << 8) + R_X86_64_32); /* reloc to line */
saa_write32(pinforel, 0);
saa_write32(pinfo,0); /* DW_AT_stmt_list */
saa_wbytes(pinfo, elf_module, strlen(elf_module)+1);
saa_wbytes(pinfo, elf_module, strlen(elf_module)+1); /* DW_AT_name */
saa_wbytes(pinfo, elf_dir, strlen(elf_dir)+1); /* DW_AT_comp_dir */
saa_wbytes(pinfo, nasm_signature(), nasm_signature_len()+1);
saa_write16(pinfo,DW_LANG_Mips_Assembler);
saa_write8(pinfo,2); /* abbrviation number LEB128u */
Expand Down Expand Up @@ -3386,7 +3391,8 @@ static void dwarf_generate(void)
saa_write64(pinforel, (dwarf_linesym << 32) + R_X86_64_32); /* reloc to line */
saa_write64(pinforel, 0);
saa_write32(pinfo,0); /* DW_AT_stmt_list */
saa_wbytes(pinfo, elf_module, strlen(elf_module)+1);
saa_wbytes(pinfo, elf_module, strlen(elf_module)+1); /* DW_AT_name */
saa_wbytes(pinfo, elf_dir, strlen(elf_dir)+1); /* DW_AT_comp_dir */
saa_wbytes(pinfo, nasm_signature(), nasm_signature_len()+1);
saa_write16(pinfo,DW_LANG_Mips_Assembler);
saa_write8(pinfo,2); /* abbrviation number LEB128u */
Expand Down Expand Up @@ -3424,6 +3430,8 @@ static void dwarf_generate(void)
saa_write8(pabbrev,DW_FORM_data4);
saa_write8(pabbrev,DW_AT_name);
saa_write8(pabbrev,DW_FORM_string);
saa_write8(pabbrev,DW_AT_comp_dir);
saa_write8(pabbrev,DW_FORM_string);
saa_write8(pabbrev,DW_AT_producer);
saa_write8(pabbrev,DW_FORM_string);
saa_write8(pabbrev,DW_AT_language);
Expand Down

0 comments on commit f2a6eb4

Please sign in to comment.