forked from OSchip/llvm-project
Take care of special characters while creating named MDNode name to hold function specific local variable's info.
This fixes radar 8653152. I am checking in testcase as a separate check-in. llvm-svn: 118726
This commit is contained in:
parent
1801410fa8
commit
364bf04267
|
@ -33,6 +33,7 @@ namespace llvm {
|
||||||
class DbgDeclareInst;
|
class DbgDeclareInst;
|
||||||
class Instruction;
|
class Instruction;
|
||||||
class MDNode;
|
class MDNode;
|
||||||
|
class NamedMDNode;
|
||||||
class LLVMContext;
|
class LLVMContext;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
|
@ -835,6 +836,14 @@ namespace llvm {
|
||||||
/// getDICompositeType - Find underlying composite type.
|
/// getDICompositeType - Find underlying composite type.
|
||||||
DICompositeType getDICompositeType(DIType T);
|
DICompositeType getDICompositeType(DIType T);
|
||||||
|
|
||||||
|
/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
|
||||||
|
/// to hold function specific information.
|
||||||
|
NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, StringRef Name);
|
||||||
|
|
||||||
|
/// getFnSpecificMDNode - Return a NameMDNode, if available, that is
|
||||||
|
/// suitable to hold function specific information.
|
||||||
|
NamedMDNode *getFnSpecificMDNode(const Module &M, StringRef Name);
|
||||||
|
|
||||||
class DebugInfoFinder {
|
class DebugInfoFinder {
|
||||||
public:
|
public:
|
||||||
/// processModule - Process entire module and collect debug info
|
/// processModule - Process entire module and collect debug info
|
||||||
|
|
|
@ -1156,6 +1156,39 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, StringRef Name,
|
||||||
return DIGlobalVariable(Node);
|
return DIGlobalVariable(Node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// fixupObjcLikeName - Replace contains special characters used
|
||||||
|
/// in a typical Objective-C names with '.' in a given string.
|
||||||
|
static void fixupObjcLikeName(std::string &Str) {
|
||||||
|
for (size_t i = 0, e = Str.size(); i < e; ++i) {
|
||||||
|
char C = Str[i];
|
||||||
|
if (C == '[' || C == ']' || C == ' ' || C == ':')
|
||||||
|
Str[i] = '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
|
||||||
|
/// to hold function specific information.
|
||||||
|
NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, StringRef FuncName) {
|
||||||
|
SmallString<32> Out;
|
||||||
|
if (FuncName.find('[') == StringRef::npos)
|
||||||
|
return M.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", FuncName)
|
||||||
|
.toStringRef(Out));
|
||||||
|
std::string Name = FuncName;
|
||||||
|
fixupObjcLikeName(Name);
|
||||||
|
return M.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", Name)
|
||||||
|
.toStringRef(Out));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getFnSpecificMDNode - Return a NameMDNode, if available, that is
|
||||||
|
/// suitable to hold function specific information.
|
||||||
|
NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, StringRef FuncName) {
|
||||||
|
if (FuncName.find('[') == StringRef::npos)
|
||||||
|
return M.getNamedMetadata(Twine("llvm.dbg.lv.", FuncName));
|
||||||
|
std::string Name = FuncName;
|
||||||
|
fixupObjcLikeName(Name);
|
||||||
|
return M.getNamedMetadata(Twine("llvm.dbg.lv.", Name));
|
||||||
|
}
|
||||||
|
|
||||||
/// CreateVariable - Create a new descriptor for the specified variable.
|
/// CreateVariable - Create a new descriptor for the specified variable.
|
||||||
DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
|
DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
|
||||||
StringRef Name,
|
StringRef Name,
|
||||||
|
@ -1185,9 +1218,8 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
|
||||||
if (FName.startswith(StringRef(&One, 1)))
|
if (FName.startswith(StringRef(&One, 1)))
|
||||||
FName = FName.substr(1);
|
FName = FName.substr(1);
|
||||||
|
|
||||||
SmallString<32> Out;
|
|
||||||
NamedMDNode *FnLocals =
|
NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, FName);
|
||||||
M.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", FName).toStringRef(Out));
|
|
||||||
FnLocals->addOperand(Node);
|
FnLocals->addOperand(Node);
|
||||||
}
|
}
|
||||||
return DIVariable(Node);
|
return DIVariable(Node);
|
||||||
|
|
|
@ -2128,8 +2128,7 @@ void DwarfDebug::endModule() {
|
||||||
StringRef FName = SP.getLinkageName();
|
StringRef FName = SP.getLinkageName();
|
||||||
if (FName.empty())
|
if (FName.empty())
|
||||||
FName = SP.getName();
|
FName = SP.getName();
|
||||||
NamedMDNode *NMD =
|
NamedMDNode *NMD = getFnSpecificMDNode(*(MMI->getModule()), FName);
|
||||||
M->getNamedMetadata(Twine("llvm.dbg.lv.", getRealLinkageName(FName)));
|
|
||||||
if (!NMD) continue;
|
if (!NMD) continue;
|
||||||
unsigned E = NMD->getNumOperands();
|
unsigned E = NMD->getNumOperands();
|
||||||
if (!E) continue;
|
if (!E) continue;
|
||||||
|
@ -2422,10 +2421,7 @@ DwarfDebug::collectVariableInfo(const MachineFunction *MF,
|
||||||
|
|
||||||
// Collect info for variables that were optimized out.
|
// Collect info for variables that were optimized out.
|
||||||
const Function *F = MF->getFunction();
|
const Function *F = MF->getFunction();
|
||||||
const Module *M = F->getParent();
|
if (NamedMDNode *NMD = getFnSpecificMDNode(*(F->getParent()), F->getName())) {
|
||||||
if (NamedMDNode *NMD =
|
|
||||||
M->getNamedMetadata(Twine("llvm.dbg.lv.",
|
|
||||||
getRealLinkageName(F->getName())))) {
|
|
||||||
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
||||||
DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
|
DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
|
||||||
if (!DV || !Processed.insert(DV))
|
if (!DV || !Processed.insert(DV))
|
||||||
|
@ -2912,10 +2908,8 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
|
||||||
StringRef FName = SP.getLinkageName();
|
StringRef FName = SP.getLinkageName();
|
||||||
if (FName.empty())
|
if (FName.empty())
|
||||||
FName = SP.getName();
|
FName = SP.getName();
|
||||||
const Module *M = MF->getFunction()->getParent();
|
if (NamedMDNode *NMD =
|
||||||
if (NamedMDNode *NMD =
|
getFnSpecificMDNode(*(MF->getFunction()->getParent()), FName)) {
|
||||||
M->getNamedMetadata(Twine("llvm.dbg.lv.",
|
|
||||||
getRealLinkageName(FName)))) {
|
|
||||||
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
|
||||||
DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
|
DIVariable DV(cast<MDNode>(NMD->getOperand(i)));
|
||||||
if (!DV || !ProcessedVars.insert(DV))
|
if (!DV || !ProcessedVars.insert(DV))
|
||||||
|
|
Loading…
Reference in New Issue