From: epetrich Date: Thu, 13 May 2004 21:51:54 +0000 (+0000) Subject: * src/hc08/gen.c (hc08_emitDebuggerSymbol), X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=5d609f8d1aef366db39770b8e9c26757b7e7622e;p=fw%2Fsdcc * src/hc08/gen.c (hc08_emitDebuggerSymbol), * src/hc08/main.c, * src/mcs51/gen.c (mcs51_emitDebuggerSymbol), * src/mcs51/main.c, * src/ds390/gen.c (ds390_emitDebuggerSymbol), * src/ds390/main.c, * src/z80/gen.c (z80_emitDebuggerSymbol), * src/z80/main.c, * src/pic/gen.c (pic14_emitDebuggerSymbol), * src/pic/main.c, * src/pic16/gen.c (pic14_emitDebuggerSymbol), * src/pic16/main.c, * src/avr/gen.c (avr_emitDebuggerSymbol), * src/avr/main.c, * src/xa51/gen.c (xa51_emitDebuggerSymbol), * src/xa51/main.c, * src/SDCCdebug.c (emitDebuggerSymbol), * src/SDCCdebug.h, * src/port.h: added a debugger struct to the port struct. Added a callback for defining debugger symbols * src/SDCCast.c (createLabel), * src/SDCC.y (labeled_statement): mark all compiler generated labels with isitmp = 1 * src/SDCCicode.h, * src/SDCCicode.c (geniCodeFunctionBody): added a link from the FUNCTION iCode back to the ast for the function * src/hc08/ralloc.c (hc08_assignRegisters), * src/hc08/ralloc.h: define a regs struct for the stack pointer. Removed unneeded fields from the regs struct. * src/hc08/gen.c (transferRegReg, genFunction, genEndFunction): use the pushReg() & pullReg() functions instead of emitcode() * src/hc08/gen.c (genLabel, genhc08Code), * src/SDCCdebug.h: Added additional debugger hooks needed for DWARF * src/cdbFile.c (cdbWriteLabel, cdbWriteScope): Added stubs for unneeded debugger hooks * src/hc08/gen.c (genEndFunction, genhc08Code), * src/hc08/gen.h, * src/mcs51/gen.c (genEndFunction, gen51Code), * src/mcs51/gen.h, * src/ds390/gen.c (genEndFunction, gen390Code), * src/ds390/gen.h, * src/z80/gen.c (genEndFunction, genZ80Code), * src/z80/gen.h, * src/z80/z80.h, * src/pic/gen.c (genEndFunction, genpic14Code), * src/pic/gen.h, * src/pic16/gen.c (genEndFunction, genpic16Code), * src/pic16/gen.h, * src/avr/gen.c (genEndFunction, genAVRCode), * src/avr/gen.h, * src/xa51/gen.c (genEndFunction, genXA51Code), * src/xa51/gen.h, * src/cdbFile.c (cdbWriteFunction, cdbWriteEndFunction): moved cdb specific code to cdbFile.c and out of the backend code generators * as/hc08/lkmain.c (main): removed OMF51 support from link-hc08 * as/hc08/lkarea.c (lnkarea): areas with NOLOAD attribute default starting address is now 0 * as/hc08/asm.h, * as/hc08/m08pst.c, * as/hc08/asmain.c (asmbl): implemented the .sleb128 and .uleb128 assembler directive for DWARF support * as/hc08/lkelf.c (elf): only increment address when rtflg[] set * src/src.dsp, * src/Makefile.in, * src/SDCCdwarf2.c: preliminary DWARF (ver 2) debugger data generator git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3304 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 1520e311..52320484 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,79 @@ +2004-05-13 Erik Petrich + + * src/hc08/gen.c (hc08_emitDebuggerSymbol), + * src/hc08/main.c, + * src/mcs51/gen.c (mcs51_emitDebuggerSymbol), + * src/mcs51/main.c, + * src/ds390/gen.c (ds390_emitDebuggerSymbol), + * src/ds390/main.c, + * src/z80/gen.c (z80_emitDebuggerSymbol), + * src/z80/main.c, + * src/pic/gen.c (pic14_emitDebuggerSymbol), + * src/pic/main.c, + * src/pic16/gen.c (pic14_emitDebuggerSymbol), + * src/pic16/main.c, + * src/avr/gen.c (avr_emitDebuggerSymbol), + * src/avr/main.c, + * src/xa51/gen.c (xa51_emitDebuggerSymbol), + * src/xa51/main.c, + * src/SDCCdebug.c (emitDebuggerSymbol), + * src/SDCCdebug.h, + * src/port.h: added a debugger struct to the port struct. Added a + callback for defining debugger symbols + + * src/SDCCast.c (createLabel), + * src/SDCC.y (labeled_statement): mark all compiler generated labels + with isitmp = 1 + * src/SDCCicode.h, + * src/SDCCicode.c (geniCodeFunctionBody): added a link from the FUNCTION + iCode back to the ast for the function + + * src/hc08/ralloc.c (hc08_assignRegisters), + * src/hc08/ralloc.h: define a regs struct for the stack pointer. Removed + unneeded fields from the regs struct. + * src/hc08/gen.c (transferRegReg, genFunction, genEndFunction): use the + pushReg() & pullReg() functions instead of emitcode() + + * src/hc08/gen.c (genLabel, genhc08Code), + * src/SDCCdebug.h: Added additional debugger hooks needed for DWARF + + * src/cdbFile.c (cdbWriteLabel, cdbWriteScope): Added stubs for unneeded + debugger hooks + + * src/hc08/gen.c (genEndFunction, genhc08Code), + * src/hc08/gen.h, + * src/mcs51/gen.c (genEndFunction, gen51Code), + * src/mcs51/gen.h, + * src/ds390/gen.c (genEndFunction, gen390Code), + * src/ds390/gen.h, + * src/z80/gen.c (genEndFunction, genZ80Code), + * src/z80/gen.h, + * src/z80/z80.h, + * src/pic/gen.c (genEndFunction, genpic14Code), + * src/pic/gen.h, + * src/pic16/gen.c (genEndFunction, genpic16Code), + * src/pic16/gen.h, + * src/avr/gen.c (genEndFunction, genAVRCode), + * src/avr/gen.h, + * src/xa51/gen.c (genEndFunction, genXA51Code), + * src/xa51/gen.h, + * src/cdbFile.c (cdbWriteFunction, cdbWriteEndFunction): moved cdb + specific code to cdbFile.c and out of the backend code generators + + * as/hc08/lkmain.c (main): removed OMF51 support from link-hc08 + * as/hc08/lkarea.c (lnkarea): areas with NOLOAD attribute default + starting address is now 0 + + * as/hc08/asm.h, + * as/hc08/m08pst.c, + * as/hc08/asmain.c (asmbl): implemented the .sleb128 and .uleb128 + assembler directive for DWARF support + * as/hc08/lkelf.c (elf): only increment address when rtflg[] set + + * src/src.dsp, + * src/Makefile.in, + * src/SDCCdwarf2.c: preliminary DWARF (ver 2) debugger data generator + 2004-05-04 Erik Petrich * src/hc08/gen.c (genJumpTab, emitcode, genhc08code): fixed stack error diff --git a/src/SDCCdebug.c b/src/SDCCdebug.c index b07aaf2e..8885d7ca 100644 --- a/src/SDCCdebug.c +++ b/src/SDCCdebug.c @@ -149,5 +149,13 @@ void dumpSymInfo(char *pcName, memmap *memItem) } - - +/*------------------------------------------------------------------*/ +/* emitDebuggerSymbol - call the port specific routine to associate */ +/* the current code location with a debugger symbol */ +/*------------------------------------------------------------------*/ +void +emitDebuggerSymbol (char * debugSym) +{ + if (port->debugger.emitDebuggerSymbol) + port->debugger.emitDebuggerSymbol (debugSym); +} diff --git a/src/SDCCdebug.h b/src/SDCCdebug.h index cd4b5bf9..24fb8263 100644 --- a/src/SDCCdebug.h +++ b/src/SDCCdebug.h @@ -7,12 +7,15 @@ typedef struct DebugFile int (*openFile)(char *file); int (*closeFile)(void); int (*writeModule)(char *name); - int (*writeFunction)(symbol *pSym); + int (*writeFunction)(symbol *pSym, iCode *ic); + int (*writeEndFunction)(symbol *pSym, iCode *ic, int offset); + int (*writeLabel)(symbol *pSym, iCode *ic); + int (*writeScope)(iCode *ic); int (*writeSymbol)(symbol *pSym); int (*writeType)(structdef *sdef, int block, int inStruct, char *tag); - int (*writeCLine)(char *module, int Line, int Level, int Block); + int (*writeCLine)(iCode *ic); int (*writeALine)(char *module, int Line); - + int (*writeFrameAddress)(char *variable, struct regs *reg, int offset); }DEBUGFILE; extern DEBUGFILE *debugFile; @@ -20,5 +23,6 @@ extern DEBUGFILE *debugFile; void outputDebugStackSymbols(void); void outputDebugSymbols(void); void dumpSymInfo(char *pcName, memmap *memItem); +void emitDebuggerSymbol (char * debugSym); #endif diff --git a/src/avr/gen.c b/src/avr/gen.c index 68eca463..5993a46c 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -261,6 +261,18 @@ emitcode (char *inst, char *fmt, ...) va_end (ap); } +/*-----------------------------------------------------------------*/ +/* avr_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +avr_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} + /*-----------------------------------------------------------------*/ /* hasInc - operand is incremented before any other use */ /*-----------------------------------------------------------------*/ @@ -1815,6 +1827,10 @@ genEndFunction (iCode * ic) if (IFFUNC_ISCRITICAL (sym->type)) emitcode ("sti", ""); + if (options.debug && currFunc) { + debugFile->writeEndFunction (currFunc, ic, 1); + } + if (IFFUNC_ISISR (sym->type)) { emitcode ("rti", ""); } @@ -5113,12 +5129,8 @@ genAVRCode (iCode * lic) if (allocInfo) printAllocInfo (currFunc, codeOutFile); /* if debug information required */ - /* if (options.debug && currFunc) { */ - if (currFunc) { - debugFile->writeFunction(currFunc); - _G.debugLine = 1; -/* emitcode ("", ".type %s,@function", currFunc->name); */ - _G.debugLine = 0; + if (options.debug && currFunc) { + debugFile->writeFunction (currFunc, lic); } /* stack pointer name */ spname = "sp"; @@ -5128,11 +5140,7 @@ genAVRCode (iCode * lic) if (cln != ic->lineno) { if (options.debug) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), - ic->lineno, ic->level, ic->block); - _G.debugLine = 0; + debugFile->writeCLine (ic); } emitcode (";", "%s %d", ic->filename, ic->lineno); cln = ic->lineno; diff --git a/src/avr/main.c b/src/avr/main.c index 8b98bae1..d0faac3c 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -227,6 +227,9 @@ PORT avr_port = { { 1, -1 }, + { + avr_emitDebuggerSymbol + }, "_", _avr_init, _avr_parseOptions, diff --git a/src/ds390/gen.c b/src/ds390/gen.c index e5670acc..0e077df1 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -187,6 +187,18 @@ emitcode (char *inst, char *fmt,...) va_end (ap); } +/*-----------------------------------------------------------------*/ +/* ds390_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +ds390_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} + // // Move the passed value into A unless it is already there. // @@ -3254,6 +3266,8 @@ genEndFunction (iCode * ic) if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); + if (options.debug && currFunc) + debugFile->writeEndFunction (currFunc, ic, 0); return; } @@ -3407,15 +3421,7 @@ genEndFunction (iCode * ic) /* if debug then send end of function */ if (options.debug && currFunc) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - if (IS_STATIC (currFunc->etype)) - emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "XG$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } emitcode ("reti", ""); @@ -3441,15 +3447,7 @@ genEndFunction (iCode * ic) /* if debug then send end of function */ if (options.debug && currFunc) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - if (IS_STATIC (currFunc->etype)) - emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "XG$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } emitcode ("ret", ""); @@ -13383,13 +13381,7 @@ gen390Code (iCode * lic) /* if debug information required */ if (options.debug && currFunc) { - debugFile->writeFunction(currFunc); - _G.debugLine = 1; - if (IS_STATIC (currFunc->etype)) - emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "G$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeFunction (currFunc, lic); } /* stack pointer name */ if (options.useXstack) @@ -13407,11 +13399,7 @@ gen390Code (iCode * lic) { if (options.debug) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), ic->lineno, - ic->level, ic->block); - _G.debugLine = 0; + debugFile->writeCLine (ic); } if (!options.noCcodeInAsm) { emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno, diff --git a/src/ds390/main.c b/src/ds390/main.c index 211e9dc1..2a9889e3 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -867,6 +867,9 @@ PORT ds390_port = { 2, -1 }, + { + ds390_emitDebuggerSymbol + }, "_", _ds390_init, _ds390_parseOptions, @@ -1166,6 +1169,9 @@ PORT tininative_port = { 2, -1 }, + { + ds390_emitDebuggerSymbol + }, "", _tininative_init, _ds390_parseOptions, @@ -1380,6 +1386,9 @@ PORT ds400_port = { 2, -1 }, + { + ds390_emitDebuggerSymbol + }, "_", _ds390_init, _ds390_parseOptions, diff --git a/src/hc08/gen.c b/src/hc08/gen.c index 68f5ec34..de90e142 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -45,6 +45,8 @@ char *aopLiteral (value * val, int offset); char *aopLiteralLong (value * val, int offset, int size); extern int allocInfo; +static int pushReg (regs *reg, bool freereg); +static void pullReg (regs *reg); static char *zero = "#0x00"; static char *one = "#0x01"; @@ -187,6 +189,17 @@ emitLabel (symbol *tlbl) emitcode ("", "%05d$:", (tlbl->key +100)); } +/*-----------------------------------------------------------------*/ +/* hc08_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +hc08_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} /*--------------------------------------------------------------------------*/ @@ -228,8 +241,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc) switch (srcidx) { case H_IDX: /* H to A */ - emitcode ("pshh", ""); - emitcode ("pula", ""); + pushReg (hc08_reg_h, FALSE); + pullReg (hc08_reg_a); break; case X_IDX: /* X to A */ emitcode ("txa", ""); @@ -242,12 +255,12 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc) switch (srcidx) { case A_IDX: /* A to H */ - emitcode ("psha", ""); - emitcode ("pulh", ""); + pushReg (hc08_reg_a, FALSE); + pullReg (hc08_reg_h); break; case X_IDX: /* X to H */ - emitcode ("pshx", ""); - emitcode ("pulh", ""); + pushReg (hc08_reg_x, FALSE); + pullReg (hc08_reg_h); break; default: error=1; @@ -260,8 +273,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc) emitcode ("tax", ""); break; case H_IDX: /* H to X */ - emitcode ("pshh", ""); - emitcode ("pulx", ""); + pushReg (hc08_reg_h, FALSE); + pullReg (hc08_reg_x); break; default: error=1; @@ -271,8 +284,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc) switch (srcidx) { case XA_IDX: /* XA to HX */ - emitcode ("pshx", ""); - emitcode ("pulh", ""); + pushReg (hc08_reg_x, FALSE); + pullReg (hc08_reg_h); emitcode ("tax", ""); break; default: @@ -284,8 +297,8 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc) { case HX_IDX: /* HX to XA */ emitcode ("txa", ""); - emitcode ("pshh", ""); - emitcode ("pulx", ""); + pushReg (hc08_reg_h, FALSE); + pullReg (hc08_reg_x); break; default: error=1; @@ -306,6 +319,21 @@ transferRegReg (regs *sreg, regs *dreg, bool freesrc) hc08_useReg(dreg); } +/*--------------------------------------------------------------------------*/ +/* updateCFA - update the debugger information to reflect the current */ +/* connonical frame address relative to the stack pointer */ +/*--------------------------------------------------------------------------*/ +static void +updateCFA(void) +{ + /* there is no frame unless there is a function */ + if (!currFunc) + return; + + debugFile->writeFrameAddress (NULL, hc08_reg_sp, + 1 + _G.stackOfs + _G.stackPushes); +} + /*--------------------------------------------------------------------------*/ /* pushReg - Push register reg onto the stack. If freereg is true, reg is */ /* marked free and available for reuse. */ @@ -320,24 +348,33 @@ pushReg (regs *reg, bool freereg) case A_IDX: emitcode ("psha", ""); _G.stackPushes++; + updateCFA(); break; case X_IDX: emitcode ("pshx", ""); _G.stackPushes++; + updateCFA(); break; case H_IDX: emitcode ("pshh", ""); _G.stackPushes++; + updateCFA(); break; case HX_IDX: emitcode ("pshx", ""); + _G.stackPushes++; + updateCFA(); emitcode ("pshh", ""); - _G.stackPushes += 2; + _G.stackPushes++; + updateCFA(); break; case XA_IDX: emitcode ("psha", ""); + updateCFA(); + _G.stackPushes++; emitcode ("pshx", ""); - _G.stackPushes += 2; + updateCFA(); + _G.stackPushes++; break; default: break; @@ -360,24 +397,33 @@ pullReg (regs *reg) case A_IDX: emitcode ("pula", ""); _G.stackPushes--; + updateCFA(); break; case X_IDX: emitcode ("pulx", ""); _G.stackPushes--; + updateCFA(); break; case H_IDX: emitcode ("pulh", ""); _G.stackPushes--; + updateCFA(); break; case HX_IDX: emitcode ("pulx", ""); + _G.stackPushes--; + updateCFA(); emitcode ("pulh", ""); - _G.stackPushes -= 2; + _G.stackPushes--; + updateCFA(); break; case XA_IDX: emitcode ("pula", ""); + _G.stackPushes--; + updateCFA(); emitcode ("pulx", ""); - _G.stackPushes -= 2; + _G.stackPushes--; + updateCFA(); break; default: break; @@ -396,6 +442,7 @@ pullNull (int n) { emitcode("ais","#%d",n); _G.stackPushes -= n; + updateCFA(); } } @@ -434,23 +481,28 @@ pullOrFreeReg (regs *reg, bool needpull) static void adjustStack (int n) { - _G.stackPushes -= n; while (n) { if (n>127) { emitcode ("ais","#127"); n -= 127; + _G.stackPushes -= 127; + updateCFA(); } else if (n<-128) { emitcode ("ais","#-128"); n += 128; + _G.stackPushes += 128; + updateCFA(); } else { emitcode ("ais", "#%d", n); + _G.stackPushes -= n; n = 0; + updateCFA(); } } } @@ -2798,6 +2850,10 @@ genFunction (iCode * ic) emitcode ("", "%s:", sym->rname); ftype = operandType (IC_LEFT (ic)); + + _G.stackOfs = 0; + _G.stackPushes = 0; + debugFile->writeFrameAddress (NULL, hc08_reg_sp, 0); if (IFFUNC_ISNAKED(ftype)) { @@ -2813,7 +2869,7 @@ genFunction (iCode * ic) { if (!inExcludeList ("h")) - emitcode ("pshh", ""); + pushReg (hc08_reg_h, FALSE); } else { @@ -2895,6 +2951,8 @@ genEndFunction (iCode * ic) if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); + if (options.debug && currFunc) + debugFile->writeEndFunction (currFunc, ic, 0); return; } @@ -2936,21 +2994,13 @@ genEndFunction (iCode * ic) { if (!inExcludeList ("h")) - emitcode ("pulh", ""); + pullReg (hc08_reg_h); /* if debug then send end of function */ if (options.debug && currFunc) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - if (IS_STATIC (currFunc->etype)) - emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "XG$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } emitcode ("rti", ""); @@ -2969,7 +3019,7 @@ genEndFunction (iCode * ic) { if (bitVectBitValue (sym->regsUsed, i) || (hc08_ptrRegReq && (i == HX_IDX || i == HX_IDX))) - emitcode ("pop", "%s", hc08_regWithIdx (i)->dname); + emitcode ("pop", "%s", hc08_regWithIdx (i)->name); } } @@ -2978,15 +3028,7 @@ genEndFunction (iCode * ic) /* if debug then send end of function */ if (options.debug && currFunc) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - if (IS_STATIC (currFunc->etype)) - emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "XG$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } emitcode ("rts", ""); @@ -3081,6 +3123,8 @@ genLabel (iCode * ic) /* special case never generate */ if (IC_LABEL (ic) == entryLabel) return; + + debugFile->writeLabel(IC_LABEL (ic), ic); emitcode ("", "%05d$:", (IC_LABEL (ic)->key + 100)); @@ -7554,6 +7598,7 @@ genEndCritical (iCode *ic) } + /*-----------------------------------------------------------------*/ /* genhc08Code - generate code for HC08 based controllers */ /*-----------------------------------------------------------------*/ @@ -7562,6 +7607,8 @@ genhc08Code (iCode * lic) { iCode *ic; int cln = 0; + int clevel = 0; + int cblock = 0; lineHead = lineCurr = NULL; @@ -7571,19 +7618,23 @@ genhc08Code (iCode * lic) /* if debug information required */ if (options.debug && currFunc) { - debugFile->writeFunction(currFunc); + debugFile->writeFunction (currFunc, lic); + #if 0 _G.debugLine = 1; if (IS_STATIC (currFunc->etype)) emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); else emitcode ("", "G$%s$0$0 ==.", currFunc->name); _G.debugLine = 0; + #endif } /* stack pointer name */ if (options.useXstack) spname = "_spx"; else spname = "sp"; + + debugFile->writeFrameAddress (NULL, NULL, 0); /* have no idea where frame is now */ hc08_aop_pass[0] = newAsmop (AOP_REG); hc08_aop_pass[0]->size=1; @@ -7600,17 +7651,31 @@ genhc08Code (iCode * lic) for (ic = lic; ic; ic = ic->next) { + _G.current_iCode = ic; + if (ic->level != clevel || ic->block != cblock) + { + if (options.debug) + { + debugFile->writeScope(ic); + } + clevel = ic->level; + cblock = ic->block; + } + if (ic->lineno && cln != ic->lineno) { if (options.debug) { + debugFile->writeCLine(ic); + #if 0 _G.debugLine = 1; emitcode ("", "C$%s$%d$%d$%d ==.", FileBaseName (ic->filename), ic->lineno, ic->level, ic->block); _G.debugLine = 0; + #endif } if (!options.noCcodeInAsm) { emitcode ("", ";%s:%d: %s", ic->filename, ic->lineno, @@ -7898,6 +7963,8 @@ genhc08Code (iCode * lic) D(emitcode("","; forgot to free xa")); } + debugFile->writeFrameAddress (NULL, NULL, 0); /* have no idea where frame is now */ + /* now we are ready to call the peep hole optimizer */ diff --git a/src/hc08/main.c b/src/hc08/main.c index 16761b6e..aa2cbb0c 100644 --- a/src/hc08/main.c +++ b/src/hc08/main.c @@ -12,6 +12,9 @@ void copyFile(FILE *dest, FILE *src); extern char * iComments2; +extern FILE * dwarf2FilePtr; +extern DEBUGFILE dwarf2DebugFile; +extern int dwarf2FinalizeFile(void); static char _defaultRules[] = { @@ -99,6 +102,7 @@ _hc08_parseOptions (int *pargc, char **argv, int *i) if (!strcmp (argv[*i], "--out-fmt-elf")) { options.out_fmt = 2; + debugFile = &dwarf2DebugFile; return TRUE; } @@ -231,6 +235,16 @@ _hc08_genAssemblerPreamble (FILE * of) } } +static void +_hc08_genAssemblerEnd (FILE * of) +{ + if (options.out_fmt == 2 && options.debug) + { + dwarf2FinalizeFile(); + copyFile(of, dwarf2FilePtr); + } +} + static void _hc08_genExtraAreas (FILE * asmFile, bool mainExists) { @@ -330,6 +344,26 @@ oclsExpense (struct memmap *oclass) } +/*----------------------------------------------------------------------*/ +/* hc08_dwarfRegNum - return the DWARF register number for a register. */ +/* These are defined for the HC08 in "Motorola 8- and 16-bit Embedded */ +/* Application Binary Interface (M8/16EABI)" */ +/*----------------------------------------------------------------------*/ +static int +hc08_dwarfRegNum (regs * reg) +{ + switch (reg->rIdx) + { + case A_IDX: return 0; + case H_IDX: return 1; + case X_IDX: return 2; + case CND_IDX: return 17; + case SP_IDX: return 15; + } + return -1; +} + + /** $1 is always the basename. $2 is always the output file. @@ -406,12 +440,30 @@ PORT hc08_port = { _hc08_genExtraAreas, NULL }, { - -1, 0, 4, 2, 0, 0 + -1, /* direction (-1 = stack grows down) */ + 0, /* bank_overhead (switch between register banks) */ + 4, /* isr_overhead */ + 2, /* call_overhead */ + 0, /* reent_overhead */ + 0 /* banked_overhead (switch between code banks) */ }, /* hc08 has an 8 bit mul */ { 1, -1 }, + { + hc08_emitDebuggerSymbol, + { + hc08_dwarfRegNum, + NULL, + NULL, + 4, /* addressSize */ + 14, /* regNumRet */ + 15, /* regNumSP */ + -1, /* regNumBP */ + 1, /* offsetSP */ + }, + }, "_", _hc08_init, _hc08_parseOptions, @@ -422,7 +474,7 @@ PORT hc08_port = _hc08_getRegName, _hc08_keywords, _hc08_genAssemblerPreamble, - NULL, /* no genAssemblerEnd */ + _hc08_genAssemblerEnd, /* no genAssemblerEnd */ _hc08_genIVT, _hc08_genXINIT, NULL, /* genInitStartup */ diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 0fb8581b..861f4fc7 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -150,6 +150,18 @@ emitcode (char *inst, const char *fmt,...) va_end (ap); } +/*-----------------------------------------------------------------*/ +/* mcs51_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +mcs51_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} + /*-----------------------------------------------------------------*/ /* mova - moves specified value into accumulator */ /*-----------------------------------------------------------------*/ @@ -2864,6 +2876,8 @@ genEndFunction (iCode * ic) if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); + if (options.debug && currFunc) + debugFile->writeEndFunction (currFunc, ic, 0); return; } @@ -2997,15 +3011,7 @@ genEndFunction (iCode * ic) /* if debug then send end of function */ if (options.debug && currFunc) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - if (IS_STATIC (currFunc->etype)) - emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "XG$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } emitcode ("reti", ""); @@ -3038,15 +3044,7 @@ genEndFunction (iCode * ic) /* if debug then send end of function */ if (options.debug && currFunc) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - if (IS_STATIC (currFunc->etype)) - emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "XG$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } emitcode ("ret", ""); @@ -9892,13 +9890,7 @@ gen51Code (iCode * lic) /* if debug information required */ if (options.debug && currFunc) { - debugFile->writeFunction(currFunc); - _G.debugLine = 1; - if (IS_STATIC (currFunc->etype)) - emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "G$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeFunction (currFunc, lic); } /* stack pointer name */ if (options.useXstack) @@ -9915,11 +9907,7 @@ gen51Code (iCode * lic) { if (options.debug) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), ic->lineno, - ic->level, ic->block); - _G.debugLine = 0; + debugFile->writeCLine(ic); } if (!options.noCcodeInAsm) { emitcode ("", ";%s:%d: %s", ic->filename, ic->lineno, diff --git a/src/mcs51/main.c b/src/mcs51/main.c index c0a49d15..d4849412 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -712,6 +712,9 @@ PORT mcs51_port = { 1, -1 }, + { + mcs51_emitDebuggerSymbol + }, "_", _mcs51_init, _mcs51_parseOptions, diff --git a/src/pic/gen.c b/src/pic/gen.c index 89e46791..fb1868b1 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -265,6 +265,18 @@ void pic14_emitcode (char *inst,char *fmt, ...) va_end(ap); } +/*-----------------------------------------------------------------*/ +/* pic14_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +pic14_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + pic14_emitcode ("", ";%s ==.", debugSym); + _G.debugLine = 0; +} + /*-----------------------------------------------------------------*/ /* getFreePtr - returns r0 or r1 whichever is free or can be pushed*/ @@ -2871,15 +2883,7 @@ registers :-) */ /* if debug then send end of function */ /* if (options.debug && currFunc) { */ if (currFunc) { - _G.debugLine = 1; - pic14_emitcode(";","C$%s$%d$%d$%d ==.", - FileBaseName(ic->filename),currFunc->lastLine, - ic->level,ic->block); - if (IS_STATIC(currFunc->etype)) - pic14_emitcode(";","XF%s$%s$0$0 ==.",moduleName,currFunc->name); - else - pic14_emitcode(";","XG$%s$0$0 ==.",currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } pic14_emitcode ("reti",""); @@ -2914,15 +2918,7 @@ registers :-) */ /* if debug then send end of function */ if (currFunc) { - _G.debugLine = 1; - pic14_emitcode(";","C$%s$%d$%d$%d ==.", - FileBaseName(ic->filename),currFunc->lastLine, - ic->level,ic->block); - if (IS_STATIC(currFunc->etype)) - pic14_emitcode(";","XF%s$%s$0$0 ==.",moduleName,currFunc->name); - else - pic14_emitcode(";","XG$%s$0$0 ==.",currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } pic14_emitcode ("return",""); @@ -9875,16 +9871,7 @@ void genpic14Code (iCode *lic) /* if debug information required */ if (options.debug && currFunc) { if (currFunc) { - debugFile->writeFunction(currFunc); - _G.debugLine = 1; - if (IS_STATIC(currFunc->etype)) { - pic14_emitcode("",";F%s$%s$0$0 %d",moduleName,currFunc->name,__LINE__); - //addpCode2pBlock(pb,newpCodeLabel(moduleName,currFunc->name)); - } else { - pic14_emitcode("",";G$%s$0$0 %d",currFunc->name,__LINE__); - //addpCode2pBlock(pb,newpCodeLabel(NULL,currFunc->name)); - } - _G.debugLine = 0; + debugFile->writeFunction (currFunc, lic); } } @@ -9894,11 +9881,7 @@ void genpic14Code (iCode *lic) DEBUGpic14_emitcode(";ic",""); if ( cln != ic->lineno ) { if ( options.debug ) { - _G.debugLine = 1; - pic14_emitcode("",";C$%s$%d$%d$%d ==.", - FileBaseName(ic->filename),ic->lineno, - ic->level,ic->block); - _G.debugLine = 0; + debugFile->writeCLine (ic); } /* pic14_emitcode("#CSRC","%s %d",FileBaseName(ic->filename),ic->lineno); diff --git a/src/pic/main.c b/src/pic/main.c index a84d1bc8..2d5fedb5 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -51,6 +51,10 @@ void pCodeInitRegisters(void); void pic14_assignRegisters (eBBlock ** ebbs, int count); +/* Also defined in gen.h, but the #include is commented out */ +/* for an unknowned reason. - EEP */ +void pic14_emitDebuggerSymbol (char *); + static int regParmFlg = 0; /* determine if we can register a parameter */ static void @@ -453,6 +457,9 @@ PORT pic_port = { 1, -1 }, + { + pic14_emitDebuggerSymbol + }, "_", _pic14_init, _pic14_parseOptions, diff --git a/src/pic16/gen.c b/src/pic16/gen.c index dc423a94..5ba54327 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -330,6 +330,17 @@ void pic16_emitcode (char *inst,char *fmt, ...) } #endif +/*-----------------------------------------------------------------*/ +/* pic16_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +pic16_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + pic16_emitcode (";", "%s ==.", debugSym); + _G.debugLine = 0; +} /*-----------------------------------------------------------------*/ /* getFreePtr - returns r0 or r1 whichever is free or can be pushed*/ @@ -3511,15 +3522,7 @@ static void genEndFunction (iCode *ic) /* if debug then send end of function */ /* if (options.debug && currFunc) */ if (currFunc) { - _G.debugLine = 1; - pic16_emitcode(";","C$%s$%d$%d$%d ==.", - FileBaseName(ic->filename),currFunc->lastLine, - ic->level,ic->block); - if (IS_STATIC(currFunc->etype)) - pic16_emitcode(";","XF%s$%s$0$0 ==.",moduleName,currFunc->name); - else - pic16_emitcode(";","XG$%s$0$0 ==.",currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } pic16_emitpcodeNULLop(POC_RETFIE); @@ -3556,15 +3559,7 @@ static void genEndFunction (iCode *ic) pic16_emitpcomment("%s: _G.nRegsSaved upon exit from function: %d\n", __FUNCTION__, _G.nRegsSaved); /* if debug then send end of function */ if (currFunc) { - _G.debugLine = 1; - pic16_emitcode(";","C$%s$%d$%d$%d ==.", - FileBaseName(ic->filename),currFunc->lastLine, - ic->level,ic->block); - if (IS_STATIC(currFunc->etype)) - pic16_emitcode(";","XF%s$%s$0$0 ==.",moduleName,currFunc->name); - else - pic16_emitcode(";","XG$%s$0$0 ==.",currFunc->name); - _G.debugLine = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } /* insert code to restore stack frame, if user enabled it @@ -11237,15 +11232,6 @@ void genpic16Code (iCode *lic) if (options.debug && currFunc) { if (currFunc) { cdbSymbol(currFunc,cdbFile,FALSE,TRUE); - _G.debugLine = 1; - if (IS_STATIC(currFunc->etype)) { - pic16_emitcode("",";F%s$%s$0$0 %d",moduleName,currFunc->name,__LINE__); - //pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(moduleName,currFunc->name)); - } else { - pic16_emitcode("",";G$%s$0$0 %d",currFunc->name,__LINE__); - //pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(NULL,currFunc->name)); - } - _G.debugLine = 0; } } #endif @@ -11255,11 +11241,7 @@ void genpic16Code (iCode *lic) DEBUGpic16_emitcode(";ic ", "\t%c 0x%x",ic->op, ic->op); if ( cln != ic->lineno ) { if ( options.debug ) { - _G.debugLine = 1; - pic16_emitcode("",";C$%s$%d$%d$%d ==.", - FileBaseName(ic->filename),ic->lineno, - ic->level,ic->block); - _G.debugLine = 0; + debugFile->writeCLine (ic); } if(!options.noCcodeInAsm) { diff --git a/src/pic16/main.c b/src/pic16/main.c index 6c98fb22..d295080d 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -82,6 +82,10 @@ static int regParmFlg = 0; /* determine if we can register a parameter */ pic16_options_t pic16_options; +/* Also defined in gen.h, but the #include is commented out */ +/* for an unknowned reason. - EEP */ +void pic16_emitDebuggerSymbol (char *); + static void _pic16_init (void) { @@ -806,6 +810,9 @@ PORT pic16_port = { 1, -1 }, + { + pic16_emitDebuggerSymbol + }, "_", _pic16_init, _pic16_parseOptions, diff --git a/src/port.h b/src/port.h index e3c08ae7..2005ddfd 100644 --- a/src/port.h +++ b/src/port.h @@ -195,6 +195,24 @@ typedef struct } support; + struct + { + void (*emitDebuggerSymbol) (char *); + struct + { + int (*regNum) (struct regs *); + bitVect * cfiSame; + bitVect * cfiUndef; + int addressSize; + int regNumRet; + int regNumSP; + int regNumBP; + int offsetSP; + } + dwarf; + } + debugger; + /** Prefix to add to a C function (eg "_") */ const char *fun_prefix; diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 8a5a2b16..f30aed63 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -124,6 +124,19 @@ static void emitcode (char *inst, char *fmt,...) { va_end (ap); } +/*-----------------------------------------------------------------*/ +/* xa51_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +xa51_emitDebuggerSymbol (char * debugSym) +{ + _G.debugLine = 1; + emitcode ("", "%s ==.", debugSym); + _G.debugLine = 0; +} + + char *getStackOffset(int stack) { static char gsoBuf[1024]; sprintf (gsoBuf, "r7+(%d%+d%+d)", stack, @@ -829,6 +842,8 @@ genEndFunction (iCode * ic) if (IFFUNC_ISNAKED(sym->type)) { emitcode(";", "naked function: no epilogue."); + if (options.debug && currFunc) + debugFile->writeEndFunction (currFunc, ic, 0); return; } @@ -837,6 +852,10 @@ genEndFunction (iCode * ic) emitcode ("add", "r7,#%d\t; release stack space for locals", sym->stack); } + if (options.debug && currFunc) { + debugFile->writeEndFunction (currFunc, ic, 1); + } + if (IFFUNC_ISISR(sym->type)) { emitcode ("reti", ""); } else { @@ -1912,23 +1931,13 @@ void genXA51Code (iCode * lic) { /* if debug information required */ if (options.debug && currFunc) { - debugFile->writeFunction(currFunc); - _G.debugLine = 1; - if (IS_STATIC (currFunc->etype)) - emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name); - else - emitcode ("", "G$%s$0$0 ==.", currFunc->name); - _G.debugLine = 0; + debugFile->writeFunction (currFunc, lic); } for (ic = lic; ic; ic = ic->next) { if (ic->lineno && cln != ic->lineno) { if (options.debug) { - _G.debugLine = 1; - emitcode ("", "C$%s$%d$%d$%d ==.", - FileBaseName (ic->filename), ic->lineno, - ic->level, ic->block); - _G.debugLine = 0; + debugFile->writeCLine (ic); } if (!options.noCcodeInAsm) { emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno, diff --git a/src/xa51/main.c b/src/xa51/main.c index 51bc27f5..99f2b902 100755 --- a/src/xa51/main.c +++ b/src/xa51/main.c @@ -301,6 +301,9 @@ PORT xa51_port = { 2, -2 }, + { + xa51_emitDebuggerSymbol + }, "_", _xa51_init, _xa51_parseOptions, diff --git a/src/z80/gen.c b/src/z80/gen.c index 281dc7ba..f61ad624 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -442,6 +442,19 @@ emitDebug (const char *szFormat,...) } } +/*-----------------------------------------------------------------*/ +/* z80_emitDebuggerSymbol - associate the current code location */ +/* with a debugger symbol */ +/*-----------------------------------------------------------------*/ +void +z80_emitDebuggerSymbol (char * debugSym) +{ + _G.lines.isDebug = 1; + emit2 ("%s !equ .", debugSym); + emit2 ("!global", debugSym); + _G.lines.isDebug = 0; +} + /*-----------------------------------------------------------------*/ /* emit2 - writes the code into a file : for now it is simple */ /*-----------------------------------------------------------------*/ @@ -3254,17 +3267,7 @@ genEndFunction (iCode * ic) if (options.debug && currFunc) { - _G.lines.isDebug = 1; - sprintf (buffer, "C$%s$%d$%d$%d", - FileBaseName (ic->filename), currFunc->lastLine, - ic->level, ic->block); - emit2 ("!labeldef", buffer); - if (IS_STATIC (currFunc->etype)) - sprintf (buffer, "XF%s$%s$0$0", moduleName, currFunc->name); - else - sprintf (buffer, "XG$%s$0$0", currFunc->name); - emit2 ("!labeldef", buffer); - _G.lines.isDebug = 0; + debugFile->writeEndFunction (currFunc, ic, 1); } /* Both banked and non-banked just ret */ @@ -7835,14 +7838,7 @@ genZ80Code (iCode * lic) /* if debug information required */ if (options.debug && currFunc) { - debugFile->writeFunction(currFunc); - _G.lines.isDebug = 1; - if (IS_STATIC (currFunc->etype)) - sprintf (buffer, "F%s$%s$0$0", moduleName, currFunc->name); - else - sprintf (buffer, "G$%s$0$0", currFunc->name); - emit2 ("!labeldef", buffer); - _G.lines.isDebug = 0; + debugFile->writeFunction (currFunc, lic); } for (ic = lic; ic; ic = ic->next) @@ -7853,13 +7849,7 @@ genZ80Code (iCode * lic) { if (options.debug) { - _G.lines.isDebug = 1; - sprintf (buffer, "C$%s$%d$%d$%d", - FileBaseName (ic->filename), ic->lineno, - ic->level, ic->block); - emit2 ("%s !equ .", buffer); - emit2 ("!global", buffer); - _G.lines.isDebug = 0; + debugFile->writeCLine (ic); } if (!options.noCcodeInAsm) { emit2 (";%s:%d: %s", ic->filename, ic->lineno, diff --git a/src/z80/main.c b/src/z80/main.c index d2a21845..55fb58d0 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -623,6 +623,9 @@ PORT z80_port = { 0, 2 }, + { + z80_emitDebuggerSymbol + }, "_", _z80_init, _parseOptions, @@ -724,6 +727,9 @@ PORT gbz80_port = { 0, 2 }, + { + z80_emitDebuggerSymbol + }, "_", _gbz80_init, _parseOptions,