X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCdwarf2.c;h=0e1d1c325a698d79d6851b9ae5b38fb96af92892;hb=eae1bd2f705a2c61e143c539f8c4d1e9c2b4efe6;hp=5a9c22c80c2a0b234ca4d624e85e6d5a84f7734b;hpb=48ba82a9755eae5da6e24d1381ea3bcf72ebb9ef;p=fw%2Fsdcc diff --git a/src/SDCCdwarf2.c b/src/SDCCdwarf2.c index 5a9c22c8..0e1d1c32 100644 --- a/src/SDCCdwarf2.c +++ b/src/SDCCdwarf2.c @@ -98,7 +98,7 @@ dwNewDebugSymbol () { char debugSym[SDCC_NAME_MAX]; - sprintf (debugSym, "S%s$%s$%d", moduleName, currFunc->name, dwDebugSymbol); + sprintf (debugSym, "S%s$%s$%d", dwModuleName, currFunc->name, dwDebugSymbol); dwDebugSymbol++; return Safe_strdup (debugSym); } @@ -990,7 +990,7 @@ dwWriteAttr (dwattr * ap) break; case DW_AT_location: case DW_AT_frame_base: - dwWriteWord (NULL, ap->val.loclist->baseOffset, NULL); + dwWriteWord ("Ldebug_loc_start", ap->val.loclist->baseOffset, NULL); break; default: dwWriteWord (NULL, ap->val.data, NULL); @@ -1575,7 +1575,7 @@ dwFindFileIndex (char * filename) if (!strncmp (includeDir, filename, strlen (includeDir)) && strlen (filename) > strlen (includeDir)) { - if (*(filename+strlen (includeDir)) == DIR_SEPARATOR_CHAR) + if (IS_DIR_SEPARATOR(filename[strlen (includeDir)])) break; } } @@ -1641,7 +1641,7 @@ dwWriteLineNumber (dwline * lp) curOffset = lp->offset; dwWriteByte (NULL, DW_LNS_advance_line, NULL); - dwWriteULEB128 (NULL, lp->line - 1, NULL); + dwWriteSLEB128 (NULL, lp->line - 1, NULL); curLine = lp->line; dwWriteByte (NULL, DW_LNS_copy, NULL); @@ -1713,7 +1713,7 @@ dwWriteLineNumber (dwline * lp) curOffset = lp->offset; dwWriteByte (NULL, DW_LNS_advance_line, NULL); - dwWriteULEB128 (NULL, deltaLine, NULL); + dwWriteSLEB128 (NULL, deltaLine, NULL); curLine = lp->line; dwWriteByte (NULL, DW_LNS_copy, NULL); @@ -2107,6 +2107,9 @@ dwMatchTypes (const void * type1v, const void * type2v) { if (SPEC_NOUN (type1) != SPEC_NOUN (type2)) return 0; + if (SPEC_NOUN (type1) == V_STRUCT + && SPEC_STRUCT (type1) != SPEC_STRUCT (type2)) + return 0; if (SPEC_CONST (type1) != SPEC_CONST (type2)) return 0; if (SPEC_VOLATILE (type1) != SPEC_VOLATILE (type2)) @@ -2163,6 +2166,7 @@ dwTagFromType (sym_link * type, dwtag * parent) dwtag * modtp; dwtag * subtp; int key; + int tableUpdated = 0; key = dwHashType (type) % dwTypeTagTable->size; oldtp = hTabFindByKey (dwTypeTagTable, key, type, dwMatchTypes); @@ -2257,20 +2261,57 @@ dwTagFromType (sym_link * type, dwtag * parent) /* is a complete type */ dwAddTagAttr (tp, dwNewAttrConst (DW_AT_byte_size, getSize (type))); + + /* Must add this before processing the struct fields */ + /* in case there is a recursive definition. */ + hTabAddItemLong (&dwTypeTagTable, key, type, tp); + tableUpdated = 1; + field = sdp->fields; while (field) { dwtag * memtp; dwloc * lp; - + + if (IS_BITFIELD (field->type) && !SPEC_BLEN(field->type)) + { + field = field->next; + continue; + } + memtp = dwNewTag (DW_TAG_member); if (*(field->name)) dwAddTagAttr (memtp, dwNewAttrString (DW_AT_name, field->name)); - subtp = dwTagFromType (field->type, tp); - dwAddTagAttr (memtp, dwNewAttrTagRef (DW_AT_type, subtp)); - if (!subtp->parent) - dwAddTagChild (parent, subtp); + if (IS_BITFIELD (field->type)) + { + int blen = SPEC_BLEN (field->type); + int bstr = SPEC_BSTR (field->type); + sym_link * type; + + dwAddTagAttr (memtp, + dwNewAttrConst (DW_AT_byte_size, + (blen+7)/8)); + dwAddTagAttr (memtp, + dwNewAttrConst (DW_AT_bit_size, blen)); + dwAddTagAttr (memtp, + dwNewAttrConst (DW_AT_bit_offset, + ((blen+7) & ~7) + - (blen+bstr))); + if (blen < 8) + type = typeFromStr ("uc"); + else + type = typeFromStr ("ui"); + subtp = dwTagFromType (type, tp); + dwAddTagAttr (memtp, dwNewAttrTagRef (DW_AT_type, subtp)); + } + else + { + subtp = dwTagFromType (field->type, tp); + dwAddTagAttr (memtp, dwNewAttrTagRef (DW_AT_type, subtp)); + if (!subtp->parent) + dwAddTagChild (parent, subtp); + } lp = dwNewLoc (DW_OP_plus_uconst, NULL, field->offset); dwAddTagAttr (memtp, @@ -2343,6 +2384,16 @@ dwTagFromType (sym_link * type, dwtag * parent) getSize (type))); dwAddTagChild (dwRootTag, tp); break; + + case V_FIXED16X16: + tp = dwNewTag (DW_TAG_base_type); + dwAddTagAttr (tp, dwNewAttrConst (DW_AT_encoding, + DW_ATE_float)); + dwAddTagAttr (tp, dwNewAttrString (DW_AT_name, "fixed16x16")); + dwAddTagAttr (tp, dwNewAttrConst (DW_AT_byte_size, + getSize (type))); + dwAddTagChild (dwRootTag, tp); + break; case V_CHAR: tp = dwNewTag (DW_TAG_base_type); @@ -2381,35 +2432,32 @@ dwTagFromType (sym_link * type, dwtag * parent) } } - hTabAddItemLong (&dwTypeTagTable, key, type, tp); + if (!tableUpdated) + hTabAddItemLong (&dwTypeTagTable, key, type, tp); + if (!tp->parent) + dwAddTagChild (parent, tp); return tp; } /*------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/ -/* dwOpenFile - opens a temporary file for debugging information */ +/* dwOpenFile - open the debugging file (just initialize, since all */ +/* DWARF data goes into the assembly output file) */ /*-----------------------------------------------------------------------*/ int dwOpenFile(char *file) { - dwarf2FilePtr = tempfile(); - if(!dwarf2FilePtr) return 0; - dwTypeTagTable = newHashTable (128); return 1; } /*-----------------------------------------------------------------------*/ -/* dwCloseFile - close (and deletes) the temporary file for debugging */ -/* information */ +/* dwCloseFile - close the debugging file (do nothing, since all DWARF */ +/* data goes into the assembly output file) */ /*-----------------------------------------------------------------------*/ int dwCloseFile(void) { - if(!dwarf2FilePtr) return 0; - - fclose(dwarf2FilePtr); - return 1; } @@ -2503,7 +2551,7 @@ dwWriteSymbolInternal (symbol *sym) dwattr * funcap; int inregs = 0; - if (!sym->level) + if (!sym->level || IS_EXTERN (sym->etype)) scopetp = dwRootTag; else { @@ -2595,12 +2643,15 @@ dwWriteSymbolInternal (symbol *sym) else if (symloc->onStack) { /* stack allocation */ - lp = dwNewLoc (DW_OP_fbreg, NULL, sym->stack); + lp = dwNewLoc (DW_OP_fbreg, NULL, symloc->stack); } else { /* global allocation */ - lp = dwNewLoc (DW_OP_addr, sym->rname, 0); + if (sym->level && !sym->allocreq) + lp = NULL; + else + lp = dwNewLoc (DW_OP_addr, symloc->rname, 0); } /* Only create the DW_AT_location if a known location exists. */ @@ -2633,8 +2684,6 @@ int dwWriteFunction(symbol *sym, iCode *ic) dwtag * tp; value * args; - if(!dwarf2FilePtr) return 0; - dwFuncTag = tp = dwNewTag (DW_TAG_subprogram); dwAddTagAttr (dwFuncTag, dwNewAttrString (DW_AT_name, sym->name)); @@ -2690,7 +2739,7 @@ int dwWriteFunction(symbol *sym, iCode *ic) /*-----------------------------------------------------------------------*/ int dwWriteEndFunction(symbol *sym, iCode *ic, int offset) { - char debugSym[SDCC_NAME_MAX]; + char debugSym[SDCC_NAME_MAX + 1]; if (ic) { @@ -2700,7 +2749,7 @@ int dwWriteEndFunction(symbol *sym, iCode *ic, int offset) } if (IS_STATIC (sym->etype)) - sprintf (debugSym, "XF%s$%s$0$0", moduleName, sym->name); + sprintf (debugSym, "XF%s$%s$0$0", dwModuleName, sym->name); else sprintf (debugSym, "XG$%s$0$0", sym->name); emitDebuggerSymbol (debugSym); @@ -2728,14 +2777,14 @@ int dwWriteEndFunction(symbol *sym, iCode *ic, int offset) /*-----------------------------------------------------------------------*/ int dwWriteLabel(symbol *sym, iCode *ic) { - char debugSym[SDCC_NAME_MAX]; + char debugSym[SDCC_NAME_MAX + 1]; dwtag * tp; /* ignore the compiler generated labels */ if (sym->isitmp) return 1; - sprintf (debugSym, "L%s$%s$%s", moduleName, currFunc->name, sym->name); + sprintf (debugSym, "L%s$%s$%s", dwModuleName, currFunc->name, sym->name); emitDebuggerSymbol (debugSym); tp = dwNewTag (DW_TAG_label); @@ -2827,12 +2876,15 @@ int dwWriteType(structdef *sdef, int block, int inStruct, char *tag) int dwWriteModule(char *name) { dwtag * tp; + char verid[125]; - if(!dwarf2FilePtr) return 0; + dwModuleName = Safe_strdup (name); + sprintf(verid, "SDCC version %s #%s", SDCC_VERSION_STR, getBuildNumber()); + tp = dwNewTag (DW_TAG_compile_unit); - dwAddTagAttr (tp, dwNewAttrString (DW_AT_producer, "SDCC version " - SDCC_VERSION_STR)); + dwAddTagAttr (tp, dwNewAttrString (DW_AT_producer, verid)); + dwAddTagAttr (tp, dwNewAttrConst (DW_AT_language, DW_LANG_C89)); dwAddTagAttr (tp, dwNewAttrString (DW_AT_name, fullSrcFileName)); @@ -2855,8 +2907,6 @@ int dwWriteCLine(iCode *ic) dwline * lp; char * debugSym; - if(!dwarf2FilePtr) return 0; - lp = Safe_alloc (sizeof (dwline)); lp->line = ic->lineno; @@ -2893,8 +2943,6 @@ dwWriteFrameAddress(char *variable, struct regs *reg, int offset) dwloc * lp; int regNum; - if(!dwarf2FilePtr) return 0; - /* If there was a region open, close it */ if (dwFrameLastLoc) { @@ -2970,8 +3018,6 @@ dwWriteFrameAddress(char *variable, struct regs *reg, int offset) /*-----------------------------------------------------------------------*/ int dwWriteALine(char *module, int Line) { - if(!dwarf2FilePtr) return 0; - return 1; } @@ -2983,14 +3029,14 @@ int dwWriteALine(char *module, int Line) /* debug file */ /*-----------------------------------------------------------------------*/ int -dwarf2FinalizeFile(void) +dwarf2FinalizeFile(FILE *of) { int tagAddress = 11; int abbrevNum = 0; int attr; - - if(!dwarf2FilePtr) return 1; + dwarf2FilePtr = of; + /* Write the .debug_line section */ dwWriteLineNumbers ();