Browse Source

* Avoid having current_debuginfo pointing to freed memory

git-svn-id: trunk@20549 -
pierre 13 years ago
parent
commit
813ebf08e3
2 changed files with 23 additions and 8 deletions
  1. 17 4
      compiler/dbgbase.pas
  2. 6 4
      compiler/fmodule.pas

+ 17 - 4
compiler/dbgbase.pas

@@ -94,8 +94,8 @@ interface
       CDebugInfo : array[tdbg] of TDebugInfoClass;
       CDebugInfo : array[tdbg] of TDebugInfoClass;
       current_debuginfo : tdebuginfo;
       current_debuginfo : tdebuginfo;
 
 
-    procedure InitDebugInfo(hp:tmodule);
-    procedure DoneDebugInfo(hp:tmodule);
+    procedure InitDebugInfo(hp:tmodule; restore_current_debuginfo : boolean);
+    procedure DoneDebugInfo(hp:tmodule;var current_debuginfo_reset : boolean);
     procedure RegisterDebugInfo(const r:tdbginfo;c:TDebugInfoClass);
     procedure RegisterDebugInfo(const r:tdbginfo;c:TDebugInfoClass);
 
 
 
 
@@ -579,7 +579,7 @@ implementation
                            Init / Done
                            Init / Done
 ****************************************************************************}
 ****************************************************************************}
 
 
-    procedure InitDebugInfo(hp:tmodule);
+    procedure InitDebugInfo(hp:tmodule; restore_current_debuginfo : boolean);
       begin
       begin
         if not assigned(CDebugInfo[target_dbg.id]) then
         if not assigned(CDebugInfo[target_dbg.id]) then
           begin
           begin
@@ -587,13 +587,26 @@ implementation
             exit;
             exit;
           end;
           end;
         hp.DebugInfo:=CDebugInfo[target_dbg.id].Create;
         hp.DebugInfo:=CDebugInfo[target_dbg.id].Create;
+        if restore_current_debuginfo then
+          begin
+            if current_debuginfo=nil then
+              current_debuginfo:=tdebuginfo(hp.DebugInfo)
+            else
+              internalerror(2012032101);
+          end;
       end;
       end;
 
 
 
 
-    procedure DoneDebugInfo(hp:tmodule);
+    procedure DoneDebugInfo(hp:tmodule;var current_debuginfo_reset : boolean);
       begin
       begin
+        current_debuginfo_reset:=false;
         if assigned(hp.DebugInfo) then
         if assigned(hp.DebugInfo) then
           begin
           begin
+            if hp.DebugInfo=current_debuginfo then
+              begin
+                current_debuginfo:=nil;
+                current_debuginfo_reset:=true;
+              end;
             hp.DebugInfo.Free;
             hp.DebugInfo.Free;
             hp.DebugInfo:=nil;
             hp.DebugInfo:=nil;
           end;
           end;

+ 6 - 4
compiler/fmodule.pas

@@ -552,13 +552,14 @@ implementation
         _exports:=TLinkedList.Create;
         _exports:=TLinkedList.Create;
         dllscannerinputlist:=TFPHashList.Create;
         dllscannerinputlist:=TFPHashList.Create;
         asmdata:=TAsmData.create(realmodulename^);
         asmdata:=TAsmData.create(realmodulename^);
-        InitDebugInfo(self);
+        InitDebugInfo(self,false);
       end;
       end;
 
 
 
 
     destructor tmodule.Destroy;
     destructor tmodule.Destroy;
       var
       var
         i : longint;
         i : longint;
+        current_debuginfo_reset : boolean;
       begin
       begin
         if assigned(unitmap) then
         if assigned(unitmap) then
           freemem(unitmap);
           freemem(unitmap);
@@ -598,7 +599,7 @@ implementation
             { release procinfo tree }
             { release procinfo tree }
             tprocinfo(procinfo).destroy_tree;
             tprocinfo(procinfo).destroy_tree;
           end;
           end;
-        DoneDebugInfo(self);
+        DoneDebugInfo(self,current_debuginfo_reset);
         used_units.free;
         used_units.free;
         dependent_units.free;
         dependent_units.free;
         resourcefiles.Free;
         resourcefiles.Free;
@@ -654,6 +655,7 @@ implementation
     procedure tmodule.reset;
     procedure tmodule.reset;
       var
       var
         i   : longint;
         i   : longint;
+        current_debuginfo_reset : boolean;
       begin
       begin
         if assigned(scanner) then
         if assigned(scanner) then
           begin
           begin
@@ -683,7 +685,7 @@ implementation
             asmdata.free;
             asmdata.free;
             asmdata:=nil;
             asmdata:=nil;
           end;
           end;
-        DoneDebugInfo(self);
+        DoneDebugInfo(self,current_debuginfo_reset);
         globalsymtable.free;
         globalsymtable.free;
         globalsymtable:=nil;
         globalsymtable:=nil;
         localsymtable.free;
         localsymtable.free;
@@ -721,7 +723,7 @@ implementation
         sourcefiles.free;
         sourcefiles.free;
         sourcefiles:=tinputfilemanager.create;
         sourcefiles:=tinputfilemanager.create;
         asmdata:=TAsmData.create(realmodulename^);
         asmdata:=TAsmData.create(realmodulename^);
-        InitDebugInfo(self);
+        InitDebugInfo(self,current_debuginfo_reset);
         _exports.free;
         _exports.free;
         _exports:=tlinkedlist.create;
         _exports:=tlinkedlist.create;
         dllscannerinputlist.free;
         dllscannerinputlist.free;