📄 stabs-dbgfmt.c
字号:
strcpy(str, name); strcat(str, ":F1"); stabs_dbgfmt_append_stab(info, info->stab, stabs_dbgfmt_append_bcstr(info->stabstr, str), N_FUN, 0, sym, info->basebc, 0); yasm_xfree(str); break; }}static intstabs_dbgfmt_generate_bcs(yasm_bytecode *bc, void *d){ stabs_info *info = (stabs_info *)d; yasm_linemap_lookup(info->dbgfmt_stabs->linemap, bc->line, &info->curfile, &info->curline); /* check for new function */ stabs_dbgfmt_generate_n_fun(info, bc); if (info->lastfile != info->curfile) { info->lastline = 0; /* new file, so line changes */ /*stabs_dbgfmt_append_stab(info, info->stab, stabs_dbgfmt_append_bcstr(info->stabstr, info->curfile), N_SOL, 0, NULL, bc, 0);*/ } /* output new line stabs if there's a basebc (known function) */ if (info->basebc != NULL && info->curline != info->lastline) { info->lastline = bc->line; stabs_dbgfmt_append_stab(info, info->stab, NULL, N_SLINE, info->curline, NULL, NULL, bc->offset - info->basebc->offset); } info->lastline = info->curline; info->lastfile = info->curfile; return 0;}static intstabs_dbgfmt_generate_sections(yasm_section *sect, /*@null@*/ void *d){ stabs_info *info = (stabs_info *)d; const char *sectname=yasm_section_get_name(sect); /* each section has a different base symbol */ info->basebc = NULL; /* handle first (pseudo) bc separately */ stabs_dbgfmt_generate_n_fun(d, yasm_section_bcs_first(sect)); yasm_section_bcs_traverse(sect, d, stabs_dbgfmt_generate_bcs); if (yasm__strcasecmp(sectname, ".text")==0) { /* Close out last function by appending a null SO stab after last bc */ yasm_bytecode *bc = yasm_section_bcs_last(sect); yasm_symrec *sym = yasm_symtab_define_label2(".n_so", bc, 1, bc->line); stabs_dbgfmt_append_stab(info, info->stab, 0, N_SO, 0, sym, bc, 0); } return 1;}static voidstabs_dbgfmt_generate(yasm_dbgfmt *dbgfmt){ yasm_dbgfmt_stabs *dbgfmt_stabs = (yasm_dbgfmt_stabs *)dbgfmt; stabs_info info; int new; yasm_bytecode *dbgbc; stabs_bc_stab *dbgbc_stab; stabs_stab *stab; yasm_bytecode *filebc, *nullbc, *laststr, *firstbc; yasm_symrec *firstsym; yasm_section *stext; /* Stablen is determined by arch/machine */ if (yasm__strcasecmp(yasm_arch_keyword(dbgfmt_stabs->arch), "x86") == 0) { info.stablen = 12; } else /* unknown machine; generate nothing */ return; info.dbgfmt_stabs = dbgfmt_stabs; info.lastline = 0; info.stabcount = 0; info.stab = yasm_object_get_general(dbgfmt_stabs->object, ".stab", 0, 0, &new, 0); if (!new) { yasm_bytecode *last = yasm_section_bcs_last(info.stab); if (last == NULL) yasm__error(yasm_section_bcs_first(info.stab)->line, N_("stabs debugging conflicts with user-defined section .stab")); else yasm__warning(YASM_WARN_GENERAL, 0, N_("stabs debugging overrides empty section .stab")); } info.stabstr = yasm_object_get_general(dbgfmt_stabs->object, ".stabstr", 0, 0, &new, 0); if (!new) { yasm_bytecode *last = yasm_section_bcs_last(info.stabstr); if (last == NULL) yasm__error(yasm_section_bcs_first(info.stabstr)->line, N_("stabs debugging conflicts with user-defined section .stabstr")); else yasm__warning(YASM_WARN_GENERAL, 0, N_("stabs debugging overrides empty section .stabstr")); } /* initial pseudo-stab */ stab = yasm_xmalloc(sizeof(stabs_stab)); dbgbc = yasm_bc_create_common(&stabs_bc_stab_callback, sizeof(stabs_bc_stab), 0); dbgbc_stab = (stabs_bc_stab *)dbgbc; dbgbc->len = info.stablen; dbgbc_stab->stab = stab; yasm_section_bcs_append(info.stab, dbgbc); /* initial strtab bytecodes */ nullbc = stabs_dbgfmt_append_bcstr(info.stabstr, ""); filebc = stabs_dbgfmt_append_bcstr(info.stabstr, dbgfmt_stabs->filename); stext = yasm_object_find_general(dbgfmt_stabs->object, ".text"); firstsym = yasm_symtab_use(dbgfmt_stabs->symtab, ".text", 0); firstbc = yasm_section_bcs_first(stext); /* N_SO file stab */ stabs_dbgfmt_append_stab(&info, info.stab, filebc, N_SO, 0, firstsym, firstbc, 0); yasm_object_sections_traverse(dbgfmt_stabs->object, (void *)&info, stabs_dbgfmt_generate_sections); /* fill initial pseudo-stab's fields */ laststr = yasm_section_bcs_last(info.stabstr); if (laststr == NULL) yasm_internal_error(".stabstr has no entries"); stab->bcvalue = NULL; stab->symvalue = NULL; stab->value = laststr->offset + laststr->len; stab->bcstr = filebc; stab->type = N_UNDF; stab->other = 0; stab->desc = info.stabcount;}static intstabs_bc_stab_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_expr_func output_expr, yasm_output_reloc_func output_reloc){ /* This entire function, essentially the core of rendering stabs to a file, * needs to become endian aware. Size appears not to be an issue, as known * 64-bit systems use truncated values in 32-bit fields. */ stabs_bc_stab *bc_stab = (stabs_bc_stab *)bc; unsigned char *buf = *bufp; const stabs_stab *stab = bc_stab->stab; YASM_WRITE_32_L(buf, stab->bcstr ? stab->bcstr->offset : 0); YASM_WRITE_8(buf, stab->type); YASM_WRITE_8(buf, stab->other); YASM_WRITE_16_L(buf, stab->desc); if (stab->symvalue != NULL) { bc->offset += 8; output_reloc(stab->symvalue, bc, buf, 4, 32, 0, d); bc->offset -= 8; buf += 4; } else if (stab->bcvalue != NULL) { YASM_WRITE_32_L(buf, stab->bcvalue->offset); } else { YASM_WRITE_32_L(buf, stab->value); } *bufp = buf; return 0;}static intstabs_bc_str_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_output_expr_func output_expr, yasm_output_reloc_func output_reloc){ stabs_bc_str *bc_str = (stabs_bc_str *)bc; unsigned char *buf = *bufp; const char *str = bc_str->str; strcpy((char *)buf, str); buf += strlen(str)+1; *bufp = buf; return 0;}static voidstabs_bc_stab_destroy(yasm_bytecode *bc){ stabs_bc_stab *bc_stab = (stabs_bc_stab *)bc; yasm_xfree(bc_stab->stab);}static voidstabs_bc_str_destroy(yasm_bytecode *bc){ stabs_bc_str *bc_str = (stabs_bc_str *)bc; yasm_xfree(bc_str->str);}static voidstabs_bc_stab_print(const yasm_bytecode *bc, FILE *f, int indent_level){ const stabs_bc_stab *bc_stab = (const stabs_bc_stab *)bc; const stabs_stab *stab = bc_stab->stab; const char *str = ""; fprintf(f, "%*s.stabs \"%s\", 0x%x, 0x%x, 0x%x, 0x%lx\n", indent_level, "", str, stab->type, stab->other, stab->desc, stab->bcvalue ? stab->bcvalue->offset : stab->value);}static voidstabs_bc_str_print(const yasm_bytecode *bc, FILE *f, int indent_level){ const stabs_bc_str *bc_str = (const stabs_bc_str *)bc; fprintf(f, "%*s\"%s\"\n", indent_level, "", bc_str->str);}static yasm_bc_resolve_flagsstabs_bc_stab_resolve(yasm_bytecode *bc, int save, yasm_calc_bc_dist_func calc_bc_dist){ yasm_internal_error(N_("tried to resolve a stabs stab bytecode")); /*@notreached@*/ return YASM_BC_RESOLVE_MIN_LEN;}static yasm_bc_resolve_flagsstabs_bc_str_resolve(yasm_bytecode *bc, int save, yasm_calc_bc_dist_func calc_bc_dist){ yasm_internal_error(N_("tried to resolve a stabs str bytecode")); /*@notreached@*/ return YASM_BC_RESOLVE_MIN_LEN;}static intstabs_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name, yasm_valparamhead *valparams, unsigned long line){ return 1;}/* Define dbgfmt structure -- see dbgfmt.h for details */yasm_dbgfmt_module yasm_stabs_LTX_dbgfmt = { YASM_DBGFMT_VERSION, "Stabs debugging format", "stabs", stabs_dbgfmt_create, stabs_dbgfmt_destroy, stabs_dbgfmt_directive, stabs_dbgfmt_generate};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -