Do not leak all of the SourceLineInfo objects. Do not bother mallocing each
authorChris Lattner <sabre@nondot.org>
Tue, 17 Oct 2006 22:06:46 +0000 (22:06 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Oct 2006 22:06:46 +0000 (22:06 +0000)
one separately.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31022 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/DwarfWriter.h
include/llvm/CodeGen/MachineDebugInfo.h
lib/CodeGen/DwarfWriter.cpp
lib/CodeGen/MachineDebugInfo.cpp

index bd95fe24d051a0ad36b1a516fa45aa6904f99ecf..1cb785c73fd064b85590b6d7a28c6b70a4bcdaa8 100644 (file)
@@ -151,7 +151,7 @@ private:
   
   /// SectionSourceLines - Tracks line numbers per text section.
   ///
-  std::vector<std::vector<SourceLineInfo *> > SectionSourceLines;
+  std::vector<std::vector<SourceLineInfo> > SectionSourceLines;
 
 
 public:
index c559b6b66d7b2081777be6b1bc609a4029c4b195..a031ad0c6f6378eec2713d3a431ffefb315ecd7c 100644 (file)
@@ -967,7 +967,7 @@ private:
   UniqueVector<SourceFileInfo> SourceFiles;
 
   // Lines - List of of source line correspondence.
-  std::vector<SourceLineInfo *> Lines;
+  std::vector<SourceLineInfo> Lines;
   
   // LabelID - Current number assigned to unique label numbers.
   unsigned LabelID;
@@ -1049,10 +1049,15 @@ public:
   
   /// getSourceLines - Return a vector of source lines.
   ///
-  std::vector<SourceLineInfo *> &getSourceLines() {
+  const std::vector<SourceLineInfo> &getSourceLines() const {
     return Lines;
   }
   
+  // FIXME: nuke this.
+  void ClearLineInfo() {
+    Lines.clear();
+  }
+  
   /// SetupCompileUnits - Set up the unique vector of compile units.
   ///
   void SetupCompileUnits(Module &M);
index 1d08d07a8a351629e4ea0c667507ad5657cadfb8..dc59b8106826443e373a6905861a0f6239d4e294 100644 (file)
@@ -2178,7 +2178,7 @@ void DwarfWriter::EmitDebugLines() const {
   // A sequence for each text section.
   for (unsigned j = 0, M = SectionSourceLines.size(); j < M; ++j) {
     // Isolate current sections line info.
-    const std::vector<SourceLineInfo *> &LineInfos = SectionSourceLines[j];
+    const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
     
     if (DwarfVerbose) {
       O << "\t"
@@ -2193,40 +2193,40 @@ void DwarfWriter::EmitDebugLines() const {
     
     // Construct rows of the address, source, line, column matrix.
     for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
-      SourceLineInfo *LineInfo = LineInfos[i];
+      const SourceLineInfo &LineInfo = LineInfos[i];
       
       if (DwarfVerbose) {
-        unsigned SourceID = LineInfo->getSourceID();
+        unsigned SourceID = LineInfo.getSourceID();
         const SourceFileInfo &SourceFile = SourceFiles[SourceID];
         unsigned DirectoryID = SourceFile.getDirectoryID();
         O << "\t"
           << TAI->getCommentString() << " "
           << Directories[DirectoryID]
           << SourceFile.getName() << ":"
-          << LineInfo->getLine() << "\n"; 
+          << LineInfo.getLine() << "\n"; 
       }
 
       // Define the line address.
       EmitInt8(0); EOL("Extended Op");
       EmitInt8(4 + 1); EOL("Op size");
       EmitInt8(DW_LNE_set_address); EOL("DW_LNE_set_address");
-      EmitReference("loc",  LineInfo->getLabelID()); EOL("Location label");
+      EmitReference("loc",  LineInfo.getLabelID()); EOL("Location label");
       
       // If change of source, then switch to the new source.
-      if (Source != LineInfo->getSourceID()) {
-        Source = LineInfo->getSourceID();
+      if (Source != LineInfo.getSourceID()) {
+        Source = LineInfo.getSourceID();
         EmitInt8(DW_LNS_set_file); EOL("DW_LNS_set_file");
         EmitULEB128Bytes(Source); EOL("New Source");
       }
       
       // If change of line.
-      if (Line != LineInfo->getLine()) {
+      if (Line != LineInfo.getLine()) {
         // Determine offset.
-        int Offset = LineInfo->getLine() - Line;
+        int Offset = LineInfo.getLine() - Line;
         int Delta = Offset - MinLineDelta;
         
         // Update line.
-        Line = LineInfo->getLine();
+        Line = LineInfo.getLine();
         
         // If delta is small enough and in range...
         if (Delta >= 0 && Delta < (MaxLineDelta - 1)) {
@@ -2635,13 +2635,13 @@ void DwarfWriter::EndFunction() {
   EmitLabel("func_end", SubprogramCount);
     
   // Get function line info.
-  std::vector<SourceLineInfo *> &LineInfos = DebugInfo->getSourceLines();
+  const std::vector<SourceLineInfo> &LineInfos = DebugInfo->getSourceLines();
 
   if (!LineInfos.empty()) {
     // Get section line info.
     unsigned ID = SectionMap.insert(Asm->CurrentSection);
     if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
-    std::vector<SourceLineInfo *> &SectionLineInfos =SectionSourceLines[ID-1];
+    std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
     // Append the function info to section info.
     SectionLineInfos.insert(SectionLineInfos.end(),
                             LineInfos.begin(), LineInfos.end());
@@ -2654,7 +2654,8 @@ void DwarfWriter::EndFunction() {
   EmitFunctionDebugFrame();
   
   // Reset the line numbers for the next function.
-  LineInfos.clear();
+  // FIXME: move this to release memory of the debuginfo object.
+  DebugInfo->ClearLineInfo();
 
   // Clear function debug information.
   DebugInfo->EndFunction();
index c87928f44a42eb52b98e8afe663c4fed3f5f7b8e..a227589e1e87b06bdd9e9252994f8325b824f371 100644 (file)
@@ -1538,7 +1538,7 @@ MachineDebugInfo::getGlobalVariablesUsing(Module &M,
 unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column,
                                        unsigned Source) {
   unsigned ID = NextLabelID();
-  Lines.push_back(new SourceLineInfo(Line, Column, Source, ID));
+  Lines.push_back(SourceLineInfo(Line, Column, Source, ID));
   return ID;
 }