Find enclosing subprogram info.
authorDevang Patel <dpatel@apple.com>
Mon, 12 Oct 2009 23:11:24 +0000 (23:11 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 12 Oct 2009 23:11:24 +0000 (23:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83922 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

index f0579fe588afd31b7dd6c511ab785b9ea7114679..811bf65d9d02ea1c556ebd6c428aaf63548b06ba 100644 (file)
@@ -1894,6 +1894,24 @@ bool DwarfDebug::ExtractScopeInformation(MachineFunction *MF) {
   return !DbgScopeMap.empty();
 }
 
+static DISubprogram getDISubprogram(MDNode *N) {
+
+  DIDescriptor D(N);
+  if (D.isNull())
+    return DISubprogram();
+
+  if (D.isCompileUnit()) 
+    return DISubprogram();
+
+  if (D.isSubprogram())
+    return DISubprogram(N);
+
+  if (D.isLexicalBlock())
+    return getDISubprogram(DILexicalBlock(N).getContext().getNode());
+
+  assert (0 && "Unexpected Descriptor!");
+}
+
 /// BeginFunction - Gather pre-function debug information.  Assumes being
 /// emitted immediately after the function entry point.
 void DwarfDebug::BeginFunction(MachineFunction *MF) {
@@ -1923,7 +1941,7 @@ void DwarfDebug::BeginFunction(MachineFunction *MF) {
   if (!FDL.isUnknown()) {
     DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
     unsigned LabelID = 0;
-    DISubprogram SP(DLT.CompileUnit);
+    DISubprogram SP = getDISubprogram(DLT.CompileUnit);
     if (!SP.isNull())
       LabelID = RecordSourceLine(SP.getLineNumber(), 0, DLT.CompileUnit);
     else