summaryrefslogtreecommitdiff
path: root/lib/Target/PIC16/PIC16DebugInfo.cpp
diff options
context:
space:
mode:
authorSanjiv Gupta <sanjiv.gupta@microchip.com>2009-05-28 18:24:11 +0000
committerSanjiv Gupta <sanjiv.gupta@microchip.com>2009-05-28 18:24:11 +0000
commitdd4694b519598993b3080103d16fdb9e17676f14 (patch)
tree43c00ef41f397f20fd567b004ed7d7cb5d9ed251 /lib/Target/PIC16/PIC16DebugInfo.cpp
parent43b41273f3e56f49449992436cc39b406c9a6350 (diff)
downloadllvm-dd4694b519598993b3080103d16fdb9e17676f14.tar.gz
llvm-dd4694b519598993b3080103d16fdb9e17676f14.tar.bz2
llvm-dd4694b519598993b3080103d16fdb9e17676f14.tar.xz
Emit debug info for locals with proper scope.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72531 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PIC16/PIC16DebugInfo.cpp')
-rw-r--r--lib/Target/PIC16/PIC16DebugInfo.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/lib/Target/PIC16/PIC16DebugInfo.cpp b/lib/Target/PIC16/PIC16DebugInfo.cpp
index 166d96e9f6..4d43811f24 100644
--- a/lib/Target/PIC16/PIC16DebugInfo.cpp
+++ b/lib/Target/PIC16/PIC16DebugInfo.cpp
@@ -14,9 +14,17 @@
#include "PIC16.h"
#include "PIC16DebugInfo.h"
#include "llvm/GlobalVariable.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+PIC16DbgInfo::~PIC16DbgInfo() {
+ for(std::map<std::string, DISubprogram *>::iterator i = FunctNameMap.begin();
+ i!=FunctNameMap.end(); i++)
+ delete i->second;
+ FunctNameMap.clear();
+}
+
void PIC16DbgInfo::PopulateDebugInfo(DIType Ty, unsigned short &TypeNo,
bool &HasAux, int Aux[],
std::string &TypeName) {
@@ -136,3 +144,127 @@ short PIC16DbgInfo::getClass(DIGlobalVariable DIGV) {
ClassNo = PIC16Dbg::C_EXT;
return ClassNo;
}
+
+void PIC16DbgInfo::PopulateFunctsDI(Module &M) {
+ GlobalVariable *Root = M.getGlobalVariable("llvm.dbg.subprograms");
+ if (!Root)
+ return;
+ Constant *RootC = cast<Constant>(*Root->use_begin());
+
+ for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end();
+ UI != UE; ++UI)
+ for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end();
+ UUI != UUE; ++UUI) {
+ GlobalVariable *GVSP = cast<GlobalVariable>(*UUI);
+ DISubprogram *SP = new DISubprogram(GVSP);
+ std::string Name;
+ SP->getLinkageName(Name);
+ FunctNameMap[Name] = SP;
+ }
+ return;
+}
+
+DISubprogram* PIC16DbgInfo::getFunctDI(std::string FunctName) {
+ return FunctNameMap[FunctName];
+}
+
+void PIC16DbgInfo::EmitFunctBeginDI(const Function *F) {
+ std::string FunctName = F->getName();
+ DISubprogram *SP = getFunctDI(FunctName);
+ if (SP) {
+ std::string FunctBeginSym = ".bf." + FunctName;
+ std::string BlockBeginSym = ".bb." + FunctName;
+
+ int FunctBeginLine = SP->getLineNumber();
+ int BFAux[PIC16Dbg::AuxSize] = {0};
+ BFAux[4] = FunctBeginLine;
+ BFAux[5] = FunctBeginLine >> 8;
+ // Emit debug directives for beginning of function.
+ EmitSymbol(FunctBeginSym, PIC16Dbg::C_FCN);
+ EmitAuxEntry(FunctBeginSym, BFAux, PIC16Dbg::AuxSize);
+ EmitSymbol(BlockBeginSym, PIC16Dbg::C_BLOCK);
+ EmitAuxEntry(BlockBeginSym, BFAux, PIC16Dbg::AuxSize);
+ }
+}
+
+void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
+ std::string FunctName = F->getName();
+ DISubprogram *SP = getFunctDI(FunctName);
+ if (SP) {
+ std::string FunctEndSym = ".ef." + FunctName;
+ std::string BlockEndSym = ".eb." + FunctName;
+
+ // Emit debug directives for end of function.
+ EmitSymbol(BlockEndSym, PIC16Dbg::C_BLOCK);
+ int EFAux[PIC16Dbg::AuxSize] = {0};
+ // 5th and 6th byte stand for line number.
+ EFAux[4] = Line;
+ EFAux[5] = Line >> 8;
+ EmitAuxEntry(BlockEndSym, EFAux, PIC16Dbg::AuxSize);
+ EmitSymbol(FunctEndSym, PIC16Dbg::C_FCN);
+ EmitAuxEntry(FunctEndSym, EFAux, PIC16Dbg::AuxSize);
+ }
+}
+
+/// EmitAuxEntry - Emit Auxiliary debug information.
+///
+void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int num) {
+ O << "\n\t.dim " << VarName << ", 1" ;
+ for (int i = 0; i<num; i++)
+ O << "," << Aux[i];
+}
+
+void PIC16DbgInfo::EmitSymbol(std::string Name, int Class) {
+ O << "\n\t" << ".def "<< Name << ", debug, class = " << Class;
+}
+
+void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
+ GlobalVariable *Root = M.getGlobalVariable("llvm.dbg.global_variables");
+ if (!Root)
+ return;
+
+ Constant *RootC = cast<Constant>(*Root->use_begin());
+ for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end();
+ UI != UE; ++UI) {
+ for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end();
+ UUI != UUE; ++UUI) {
+ DIGlobalVariable DIGV(cast<GlobalVariable>(*UUI));
+ DIType Ty = DIGV.getType();
+ unsigned short TypeNo = 0;
+ bool HasAux = false;
+ int Aux[PIC16Dbg::AuxSize] = { 0 };
+ std::string TypeName = "";
+ std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getName();
+ PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TypeName);
+ // Emit debug info only if type information is availaible.
+ if (TypeNo != PIC16Dbg::T_NULL) {
+ O << "\n\t.type " << VarName << ", " << TypeNo;
+ short ClassNo = getClass(DIGV);
+ O << "\n\t.class " << VarName << ", " << ClassNo;
+ if (HasAux) {
+ if (TypeName != "") {
+ // Emit debug info for structure and union objects after
+ // .dim directive supports structure/union tag name in aux entry.
+ /* O << "\n\t.dim " << VarName << ", 1," << TypeName;
+ for (int i = 0; i<PIC16Dbg::AuxSize; i++)
+ O << "," << Aux[i];*/
+ }
+ else {
+ EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize);
+ }
+ }
+ }
+ }
+ }
+ O << "\n";
+}
+
+void PIC16DbgInfo::EmitFileDirective(Module &M) {
+ GlobalVariable *CU = M.getNamedGlobal("llvm.dbg.compile_unit");
+ if (CU) {
+ DICompileUnit DIUnit(CU);
+ std::string Dir, FN;
+ O << "\n\t.file\t\"" << DIUnit.getDirectory(Dir) <<"/"
+ << DIUnit.getFilename(FN) << "\"" ;
+ }
+}