mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-24 10:38:24 +02:00
* fixes for locals in inlined procedures
fix for bug797 + stabs generation for inlined paras and locals
This commit is contained in:
parent
35d59eeb52
commit
16638c8b65
@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
}
|
}
|
||||||
|
{$ifdef FPC}
|
||||||
|
{$goto on}
|
||||||
|
{$endif FPC}
|
||||||
unit cg386cal;
|
unit cg386cal;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -41,7 +44,7 @@ implementation
|
|||||||
cobjects,verbose,globals,
|
cobjects,verbose,globals,
|
||||||
symconst,aasm,types,
|
symconst,aasm,types,
|
||||||
{$ifdef GDB}
|
{$ifdef GDB}
|
||||||
gdb,
|
strings,gdb,
|
||||||
{$endif GDB}
|
{$endif GDB}
|
||||||
hcodegen,temp_gen,pass_2,
|
hcodegen,temp_gen,pass_2,
|
||||||
cpubase,cpuasm,
|
cpubase,cpuasm,
|
||||||
@ -1285,6 +1288,11 @@ implementation
|
|||||||
proc_names : tstringcontainer;
|
proc_names : tstringcontainer;
|
||||||
inlineentrycode,inlineexitcode : paasmoutput;
|
inlineentrycode,inlineexitcode : paasmoutput;
|
||||||
oldexitlabel,oldexit2label,oldquickexitlabel:Pasmlabel;
|
oldexitlabel,oldexit2label,oldquickexitlabel:Pasmlabel;
|
||||||
|
{$ifdef GDB}
|
||||||
|
startlabel,endlabel : pasmlabel;
|
||||||
|
pp : pchar;
|
||||||
|
mangled_length : longint;
|
||||||
|
{$endif GDB}
|
||||||
begin
|
begin
|
||||||
oldinlining_procedure:=inlining_procedure;
|
oldinlining_procedure:=inlining_procedure;
|
||||||
oldexitlabel:=aktexitlabel;
|
oldexitlabel:=aktexitlabel;
|
||||||
@ -1293,11 +1301,11 @@ implementation
|
|||||||
getlabel(aktexitlabel);
|
getlabel(aktexitlabel);
|
||||||
getlabel(aktexit2label);
|
getlabel(aktexit2label);
|
||||||
oldprocsym:=aktprocsym;
|
oldprocsym:=aktprocsym;
|
||||||
|
{ we're inlining a procedure }
|
||||||
|
inlining_procedure:=true;
|
||||||
{ save old procinfo }
|
{ save old procinfo }
|
||||||
getmem(oldprocinfo,sizeof(tprocinfo));
|
getmem(oldprocinfo,sizeof(tprocinfo));
|
||||||
move(procinfo^,oldprocinfo^,sizeof(tprocinfo));
|
move(procinfo^,oldprocinfo^,sizeof(tprocinfo));
|
||||||
{ we're inlining a procedure }
|
|
||||||
inlining_procedure:=true;
|
|
||||||
{ set the return value }
|
{ set the return value }
|
||||||
aktprocsym:=p^.inlineprocsym;
|
aktprocsym:=p^.inlineprocsym;
|
||||||
procinfo^.returntype:=aktprocsym^.definition^.rettype;
|
procinfo^.returntype:=aktprocsym^.definition^.rettype;
|
||||||
@ -1309,16 +1317,44 @@ implementation
|
|||||||
st^.symtablelevel:=oldprocsym^.definition^.localst^.symtablelevel;
|
st^.symtablelevel:=oldprocsym^.definition^.localst^.symtablelevel;
|
||||||
if st^.datasize>0 then
|
if st^.datasize>0 then
|
||||||
begin
|
begin
|
||||||
st^.address_fixup:=gettempofsizepersistant(st^.datasize);
|
st^.address_fixup:=gettempofsizepersistant(st^.datasize)+st^.datasize;
|
||||||
{$ifdef extdebug}
|
{$ifdef extdebug}
|
||||||
Comment(V_debug,'local symtable is at offset '+tostr(st^.address_fixup));
|
Comment(V_debug,'local symtable is at offset '+tostr(st^.address_fixup));
|
||||||
exprasmlist^.concat(new(pai_asm_comment,init(strpnew(
|
exprasmlist^.concat(new(pai_asm_comment,init(strpnew(
|
||||||
'local symtable is at offset '+tostr(st^.address_fixup)))));
|
'local symtable is at offset '+tostr(st^.address_fixup)))));
|
||||||
{$endif extdebug}
|
{$endif extdebug}
|
||||||
end;
|
end;
|
||||||
|
exprasmlist^.concat(new(Pai_Marker, Init(InlineStart)));
|
||||||
{$ifdef extdebug}
|
{$ifdef extdebug}
|
||||||
exprasmlist^.concat(new(pai_asm_comment,init(strpnew('Start of inlined proc'))));
|
exprasmlist^.concat(new(pai_asm_comment,init(strpnew('Start of inlined proc'))));
|
||||||
{$endif extdebug}
|
{$endif extdebug}
|
||||||
|
{$ifdef GDB}
|
||||||
|
if (cs_debuginfo in aktmoduleswitches) then
|
||||||
|
begin
|
||||||
|
getlabel(startlabel);
|
||||||
|
getlabel(endlabel);
|
||||||
|
emitlab(startlabel);
|
||||||
|
p^.inlineprocsym^.definition^.localst^.symtabletype:=inlinelocalsymtable;
|
||||||
|
p^.inlineprocsym^.definition^.parast^.symtabletype:=inlineparasymtable;
|
||||||
|
|
||||||
|
{ Here we must include the para and local symtable info }
|
||||||
|
p^.inlineprocsym^.concatstabto(withdebuglist);
|
||||||
|
|
||||||
|
{ set it back for savety }
|
||||||
|
p^.inlineprocsym^.definition^.localst^.symtabletype:=localsymtable;
|
||||||
|
p^.inlineprocsym^.definition^.parast^.symtabletype:=parasymtable;
|
||||||
|
|
||||||
|
mangled_length:=length(oldprocsym^.definition^.mangledname);
|
||||||
|
getmem(pp,mangled_length+50);
|
||||||
|
strpcopy(pp,'192,0,0,'+startlabel^.name);
|
||||||
|
if (target_os.use_function_relative_addresses) then
|
||||||
|
begin
|
||||||
|
strpcopy(strend(pp),'-');
|
||||||
|
strpcopy(strend(pp),oldprocsym^.definition^.mangledname);
|
||||||
|
end;
|
||||||
|
withdebuglist^.concat(new(pai_stabn,init(strnew(pp))));
|
||||||
|
end;
|
||||||
|
{$endif GDB}
|
||||||
{ takes care of local data initialization }
|
{ takes care of local data initialization }
|
||||||
inlineentrycode:=new(paasmoutput,init);
|
inlineentrycode:=new(paasmoutput,init);
|
||||||
inlineexitcode:=new(paasmoutput,init);
|
inlineexitcode:=new(paasmoutput,init);
|
||||||
@ -1333,15 +1369,31 @@ implementation
|
|||||||
{$ifdef extdebug}
|
{$ifdef extdebug}
|
||||||
exprasmlist^.concat(new(pai_asm_comment,init(strpnew('End of inlined proc'))));
|
exprasmlist^.concat(new(pai_asm_comment,init(strpnew('End of inlined proc'))));
|
||||||
{$endif extdebug}
|
{$endif extdebug}
|
||||||
|
exprasmlist^.concat(new(Pai_Marker, Init(InlineEnd)));
|
||||||
|
|
||||||
{we can free the local data now, reset also the fixup address }
|
{we can free the local data now, reset also the fixup address }
|
||||||
if st^.datasize>0 then
|
if st^.datasize>0 then
|
||||||
begin
|
begin
|
||||||
ungetpersistanttemp(st^.address_fixup);
|
ungetpersistanttemp(st^.address_fixup-st^.datasize);
|
||||||
st^.address_fixup:=0;
|
st^.address_fixup:=0;
|
||||||
end;
|
end;
|
||||||
{ restore procinfo }
|
{ restore procinfo }
|
||||||
move(oldprocinfo^,procinfo^,sizeof(tprocinfo));
|
move(oldprocinfo^,procinfo^,sizeof(tprocinfo));
|
||||||
freemem(oldprocinfo,sizeof(tprocinfo));
|
freemem(oldprocinfo,sizeof(tprocinfo));
|
||||||
|
{$ifdef GDB}
|
||||||
|
if (cs_debuginfo in aktmoduleswitches) then
|
||||||
|
begin
|
||||||
|
emitlab(endlabel);
|
||||||
|
strpcopy(pp,'224,0,0,'+endlabel^.name);
|
||||||
|
if (target_os.use_function_relative_addresses) then
|
||||||
|
begin
|
||||||
|
strpcopy(strend(pp),'-');
|
||||||
|
strpcopy(strend(pp),oldprocsym^.definition^.mangledname);
|
||||||
|
end;
|
||||||
|
withdebuglist^.concat(new(pai_stabn,init(strnew(pp))));
|
||||||
|
freemem(pp,mangled_length+50);
|
||||||
|
end;
|
||||||
|
{$endif GDB}
|
||||||
{ restore }
|
{ restore }
|
||||||
aktprocsym:=oldprocsym;
|
aktprocsym:=oldprocsym;
|
||||||
aktexitlabel:=oldexitlabel;
|
aktexitlabel:=oldexitlabel;
|
||||||
@ -1355,7 +1407,12 @@ implementation
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.126 2000-02-09 18:08:33 jonas
|
Revision 1.127 2000-03-01 00:03:11 pierre
|
||||||
|
* fixes for locals in inlined procedures
|
||||||
|
fix for bug797
|
||||||
|
+ stabs generation for inlined paras and locals
|
||||||
|
|
||||||
|
Revision 1.126 2000/02/09 18:08:33 jonas
|
||||||
* added regallocs for esi
|
* added regallocs for esi
|
||||||
|
|
||||||
Revision 1.125 2000/02/09 13:22:45 peter
|
Revision 1.125 2000/02/09 13:22:45 peter
|
||||||
|
@ -166,6 +166,10 @@ implementation
|
|||||||
inlineparasymtable,localsymtable]) then
|
inlineparasymtable,localsymtable]) then
|
||||||
begin
|
begin
|
||||||
p^.location.reference.base:=procinfo^.framepointer;
|
p^.location.reference.base:=procinfo^.framepointer;
|
||||||
|
if (symtabletype in [inlinelocalsymtable,
|
||||||
|
localsymtable]) then
|
||||||
|
p^.location.reference.offset:=pvarsym(p^.symtableentry)^.address-p^.symtable^.address_fixup
|
||||||
|
else
|
||||||
p^.location.reference.offset:=pvarsym(p^.symtableentry)^.address+p^.symtable^.address_fixup;
|
p^.location.reference.offset:=pvarsym(p^.symtableentry)^.address+p^.symtable^.address_fixup;
|
||||||
|
|
||||||
if (symtabletype in [localsymtable,inlinelocalsymtable]) then
|
if (symtabletype in [localsymtable,inlinelocalsymtable]) then
|
||||||
@ -1005,7 +1009,12 @@ implementation
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.100 2000-02-09 18:08:33 jonas
|
Revision 1.101 2000-03-01 00:03:11 pierre
|
||||||
|
* fixes for locals in inlined procedures
|
||||||
|
fix for bug797
|
||||||
|
+ stabs generation for inlined paras and locals
|
||||||
|
|
||||||
|
Revision 1.100 2000/02/09 18:08:33 jonas
|
||||||
* added regallocs for esi
|
* added regallocs for esi
|
||||||
|
|
||||||
Revision 1.99 2000/02/09 13:22:47 peter
|
Revision 1.99 2000/02/09 13:22:47 peter
|
||||||
@ -1093,4 +1102,3 @@ end.
|
|||||||
* resources are working again
|
* resources are working again
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2729,10 +2729,10 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
|
|||||||
begin
|
begin
|
||||||
procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
|
procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
|
||||||
reset_reference(hr);
|
reset_reference(hr);
|
||||||
if psym(p)^.owner^.symtabletype=localsymtable then
|
if psym(p)^.owner^.symtabletype in [localsymtable,inlinelocalsymtable] then
|
||||||
begin
|
begin
|
||||||
hr.base:=procinfo^.framepointer;
|
hr.base:=procinfo^.framepointer;
|
||||||
hr.offset:=-pvarsym(p)^.address;
|
hr.offset:=-pvarsym(p)^.address+pvarsym(p)^.owner^.address_fixup;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -2794,12 +2794,12 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
|
|||||||
procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
|
procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
|
||||||
reset_reference(hr);
|
reset_reference(hr);
|
||||||
case psym(p)^.owner^.symtabletype of
|
case psym(p)^.owner^.symtabletype of
|
||||||
localsymtable:
|
localsymtable,inlinelocalsymtable:
|
||||||
begin
|
begin
|
||||||
hr.base:=procinfo^.framepointer;
|
hr.base:=procinfo^.framepointer;
|
||||||
hr.offset:=-pvarsym(p)^.address;
|
hr.offset:=-pvarsym(p)^.address+pvarsym(p)^.owner^.address_fixup;
|
||||||
end;
|
end;
|
||||||
parasymtable:
|
parasymtable,inlineparasymtable:
|
||||||
begin
|
begin
|
||||||
hr.base:=procinfo^.framepointer;
|
hr.base:=procinfo^.framepointer;
|
||||||
hr.offset:=pvarsym(p)^.address+procinfo^.para_offset;
|
hr.offset:=pvarsym(p)^.address+procinfo^.para_offset;
|
||||||
@ -2972,7 +2972,7 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
|
|||||||
href1.offset:=pvarsym(p)^.address+procinfo^.para_offset;
|
href1.offset:=pvarsym(p)^.address+procinfo^.para_offset;
|
||||||
reset_reference(href2);
|
reset_reference(href2);
|
||||||
href2.base:=procinfo^.framepointer;
|
href2.base:=procinfo^.framepointer;
|
||||||
href2.offset:=-pvarsym(p)^.localvarsym^.address;
|
href2.offset:=-pvarsym(p)^.localvarsym^.address+pvarsym(p)^.localvarsym^.owner^.address_fixup;
|
||||||
copyshortstring(href2,href1,pstringdef(pvarsym(p)^.vartype.def)^.len,true);
|
copyshortstring(href2,href1,pstringdef(pvarsym(p)^.vartype.def)^.len,true);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -2982,7 +2982,7 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
|
|||||||
href1.offset:=pvarsym(p)^.address+procinfo^.para_offset;
|
href1.offset:=pvarsym(p)^.address+procinfo^.para_offset;
|
||||||
reset_reference(href2);
|
reset_reference(href2);
|
||||||
href2.base:=procinfo^.framepointer;
|
href2.base:=procinfo^.framepointer;
|
||||||
href2.offset:=-pvarsym(p)^.localvarsym^.address;
|
href2.offset:=-pvarsym(p)^.localvarsym^.address+pvarsym(p)^.localvarsym^.owner^.address_fixup;
|
||||||
concatcopy(href1,href2,pvarsym(p)^.vartype.def^.size,true,true);
|
concatcopy(href1,href2,pvarsym(p)^.vartype.def^.size,true,true);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -3781,7 +3781,12 @@ procedure mov_reg_to_dest(p : ptree; s : topsize; reg : tregister);
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.83 2000-02-18 21:25:48 florian
|
Revision 1.84 2000-03-01 00:03:12 pierre
|
||||||
|
* fixes for locals in inlined procedures
|
||||||
|
fix for bug797
|
||||||
|
+ stabs generation for inlined paras and locals
|
||||||
|
|
||||||
|
Revision 1.83 2000/02/18 21:25:48 florian
|
||||||
* fixed a bug in int64/qword handling was a quite ugly one
|
* fixed a bug in int64/qword handling was a quite ugly one
|
||||||
|
|
||||||
Revision 1.82 2000/02/18 20:53:14 pierre
|
Revision 1.82 2000/02/18 20:53:14 pierre
|
||||||
|
@ -1403,7 +1403,7 @@
|
|||||||
+vartype.def^.numberstring+'",'+
|
+vartype.def^.numberstring+'",'+
|
||||||
tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
|
tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
|
||||||
end
|
end
|
||||||
else if (owner^.symtabletype=parasymtable) then
|
else if (owner^.symtabletype in [parasymtable,inlineparasymtable]) then
|
||||||
begin
|
begin
|
||||||
case varspez of
|
case varspez of
|
||||||
vs_var : st := 'v'+st;
|
vs_var : st := 'v'+st;
|
||||||
@ -1420,7 +1420,7 @@
|
|||||||
{offset to ebp => will not work if the framepointer is esp
|
{offset to ebp => will not work if the framepointer is esp
|
||||||
so some optimizing will make things harder to debug }
|
so some optimizing will make things harder to debug }
|
||||||
end
|
end
|
||||||
else if (owner^.symtabletype=localsymtable) then
|
else if (owner^.symtabletype in [localsymtable,inlinelocalsymtable]) then
|
||||||
{$ifdef i386}
|
{$ifdef i386}
|
||||||
if reg<>R_NO then
|
if reg<>R_NO then
|
||||||
begin
|
begin
|
||||||
@ -1441,7 +1441,7 @@
|
|||||||
else
|
else
|
||||||
stabstring := strpnew('"'+name+':'+st
|
stabstring := strpnew('"'+name+':'+st
|
||||||
+vartype.def^.numberstring+'",'+
|
+vartype.def^.numberstring+'",'+
|
||||||
tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address))
|
tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner^.address_fixup))
|
||||||
else
|
else
|
||||||
stabstring := inherited stabstring;
|
stabstring := inherited stabstring;
|
||||||
end;
|
end;
|
||||||
@ -2125,7 +2125,12 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.139 2000-02-11 13:53:49 pierre
|
Revision 1.140 2000-03-01 00:03:10 pierre
|
||||||
|
* fixes for locals in inlined procedures
|
||||||
|
fix for bug797
|
||||||
|
+ stabs generation for inlined paras and locals
|
||||||
|
|
||||||
|
Revision 1.139 2000/02/11 13:53:49 pierre
|
||||||
* avoid stack overflow in tref.done (bug 846)
|
* avoid stack overflow in tref.done (bug 846)
|
||||||
|
|
||||||
Revision 1.138 2000/02/09 13:23:05 peter
|
Revision 1.138 2000/02/09 13:23:05 peter
|
||||||
|
@ -1185,6 +1185,12 @@ implementation
|
|||||||
psym(p)^.concatstabto(asmoutput);
|
psym(p)^.concatstabto(asmoutput);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure resetstab(p : pnamedindexobject);
|
||||||
|
begin
|
||||||
|
if psym(p)^.typ <> procsym then
|
||||||
|
psym(p)^.isstabwritten:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure concattypestab(p : pnamedindexobject);
|
procedure concattypestab(p : pnamedindexobject);
|
||||||
begin
|
begin
|
||||||
if psym(p)^.typ = typesym then
|
if psym(p)^.typ = typesym then
|
||||||
@ -2123,6 +2129,9 @@ implementation
|
|||||||
procedure tsymtable.concatstabto(asmlist : paasmoutput);
|
procedure tsymtable.concatstabto(asmlist : paasmoutput);
|
||||||
begin
|
begin
|
||||||
asmoutput:=asmlist;
|
asmoutput:=asmlist;
|
||||||
|
if symtabletype in [inlineparasymtable,inlinelocalsymtable] then
|
||||||
|
foreach({$ifndef TP}@{$endif}resetstab);
|
||||||
|
|
||||||
foreach({$ifndef TP}@{$endif}concatstab);
|
foreach({$ifndef TP}@{$endif}concatstab);
|
||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
@ -2784,7 +2793,12 @@ implementation
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.78 2000-02-20 20:49:45 florian
|
Revision 1.79 2000-03-01 00:03:10 pierre
|
||||||
|
* fixes for locals in inlined procedures
|
||||||
|
fix for bug797
|
||||||
|
+ stabs generation for inlined paras and locals
|
||||||
|
|
||||||
|
Revision 1.78 2000/02/20 20:49:45 florian
|
||||||
* newcg is compiling
|
* newcg is compiling
|
||||||
* fixed the dup id problem reported by Paul Y.
|
* fixed the dup id problem reported by Paul Y.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user