diff options
author | Chang S. Bae <chang.seok.bae@intel.com> | 2017-04-26 12:13:08 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2017-04-27 20:03:53 -0700 |
commit | 961d8670bf99b627255c2c3111535bd319981cf9 (patch) | |
tree | 0aa6e7f60e3a92c1380425d5ef83f17fc9836486 | |
parent | 0e37f02bade16133ba54a05c42bc9cbc08b45b7f (diff) | |
download | nasm-961d8670bf99b627255c2c3111535bd319981cf9.tar.gz |
outmacho: add dir list
Separate dir info from the file list to align with dwarf format
in debug_line section
Signedoff-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | output/outmacho.c | 85 |
1 files changed, 65 insertions, 20 deletions
diff --git a/output/outmacho.c b/output/outmacho.c index c6774d11..5577cc33 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -323,11 +323,19 @@ static struct section *get_section_by_index(const int32_t index) return s; } +struct dir_list { + struct dir_list *next; + struct dir_list *last; + const char *dir_name; + uint32_t dir; +}; + struct file_list { struct file_list *next; struct file_list *last; - char *file_name; + const char *file_name; uint32_t file; + struct dir_list *dir; }; struct dw_sect_list { @@ -351,9 +359,10 @@ struct section_info { #define DW_MAX_LN (DW_LN_BASE + DW_LN_RANGE) #define DW_MAX_SP_OPCODE 256 -static struct file_list *dw_head_list = 0, *dw_cur_list = 0, *dw_last_list = 0; +static struct file_list *dw_head_file = 0, *dw_cur_file = 0, **dw_last_file_next = NULL; +static struct dir_list *dw_head_dir = 0, **dw_last_dir_next = NULL; static struct dw_sect_list *dw_head_sect = 0, *dw_cur_sect = 0, *dw_last_sect = 0; -static uint32_t cur_line = 0, dw_num_files = 0, dw_num_sects = 0; +static uint32_t cur_line = 0, dw_num_files = 0, dw_num_dirs = 0, dw_num_sects = 0; static bool dbg_immcall = false; static const char *module_name = NULL; @@ -2015,6 +2024,46 @@ static void macho_dbg_generate(void) } } +static void new_file_list (const char *file_name, const char *dir_name) +{ + struct dir_list *dir_list; + bool need_new_dir_list = true; + + nasm_new(dw_cur_file); + dw_cur_file->file = ++dw_num_files; + dw_cur_file->file_name = file_name; + if(!dw_head_file) { + dw_head_file = dw_cur_file; + } else { + *dw_last_file_next = dw_cur_file; + } + dw_last_file_next = &(dw_cur_file->next); + + if(dw_head_dir) { + list_for_each(dir_list, dw_head_dir) { + if(!(strcmp(dir_name, dir_list->dir_name))) { + dw_cur_file->dir = dir_list; + need_new_dir_list = false; + break; + } + } + } + + if(need_new_dir_list) + { + nasm_new(dir_list); + dir_list->dir = dw_num_dirs++; + dir_list->dir_name = dir_name; + if(!dw_head_dir) { + dw_head_dir = dir_list; + } else { + *dw_last_dir_next = dir_list; + } + dw_last_dir_next = &(dir_list->next); + dw_cur_file->dir = dir_list; + } +} + static void macho_dbg_init(void) { } @@ -2022,15 +2071,20 @@ static void macho_dbg_init(void) static void macho_dbg_linenum(const char *file_name, int32_t line_num, int32_t segto) { bool need_new_list = true; + const char *cur_file = nasm_basename(file_name); + const char *cur_dir = nasm_dirname(file_name); (void)segto; - if(!dw_cur_list || strcmp(file_name, dw_cur_list->file_name)) { - if(dw_head_list) { + if(!dw_cur_file || strcmp(cur_file, dw_cur_file->file_name) || + strcmp(cur_dir, dw_cur_file->dir->dir_name)) { + if(dw_head_file) { struct file_list *match; - list_for_each(match, dw_head_list) { - if(!(strcmp(file_name, match->file_name))) { - dw_cur_list = match; + list_for_each(match, dw_head_file) { + if(!(strcmp(cur_file, match->file_name)) && + !(strcmp(cur_dir, match->dir->dir_name))) { + dw_cur_file = match; + dw_cur_file->dir = match->dir; need_new_list = false; break; } @@ -2038,16 +2092,7 @@ static void macho_dbg_linenum(const char *file_name, int32_t line_num, int32_t s } if(need_new_list) { - nasm_new(dw_cur_list); - dw_cur_list->file = ++dw_num_files; - dw_cur_list->file_name = (char*) file_name; - - if(!dw_head_list) { - dw_head_list = dw_last_list = dw_cur_list; - } else { - dw_last_list->next = dw_cur_list; - dw_last_list = dw_cur_list; - } + new_file_list(cur_file, cur_dir); } } @@ -2109,7 +2154,7 @@ static void macho_dbg_output(int type, void *param) if(dbg_immcall == true) { int32_t line_delta = cur_line - dw_cur_sect->line; int32_t offset_delta = sinfo_param->size - dw_cur_sect->offset; - uint32_t cur_file = dw_cur_list->file; + uint32_t cur_file = dw_cur_file->file; p_linep = dw_cur_sect->psaa; if(cur_file != dw_cur_sect->file) { @@ -2150,7 +2195,7 @@ static void macho_dbg_cleanup(void) { struct dw_sect_list *p_sect = dw_head_sect; - struct file_list *p_file = dw_head_list; + struct file_list *p_file = dw_head_file; uint32_t idx = 0; for(; idx < dw_num_sects; idx++) { |