Add comments to the ASM output to help understand the compact unwind and CIE tables.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134191 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2011-06-30 21:25:51 +00:00
parent cfe5254cd3
commit 3c163cfa60

View File

@ -526,6 +526,40 @@ namespace {
void EmitCFIInstruction(MCStreamer &Streamer, void EmitCFIInstruction(MCStreamer &Streamer,
const MCCFIInstruction &Instr); const MCCFIInstruction &Instr);
}; };
} // end anonymous namespace
static void EmitEncodingByte(MCStreamer &Streamer, unsigned Encoding,
StringRef Prefix) {
if (Streamer.isVerboseAsm()) {
const char *EncStr = 0;
switch (Encoding) {
default: EncStr = "<unknown encoding>";
case dwarf::DW_EH_PE_absptr: EncStr = "absptr";
case dwarf::DW_EH_PE_omit: EncStr = "omit";
case dwarf::DW_EH_PE_pcrel: EncStr = "pcrel";
case dwarf::DW_EH_PE_udata4: EncStr = "udata4";
case dwarf::DW_EH_PE_udata8: EncStr = "udata8";
case dwarf::DW_EH_PE_sdata4: EncStr = "sdata4";
case dwarf::DW_EH_PE_sdata8: EncStr = "sdata8";
case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4: EncStr = "pcrel udata4";
case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4: EncStr = "pcrel sdata4";
case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8: EncStr = "pcrel udata8";
case dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8: EncStr = "pcrel sdata8";
case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata4:
EncStr = "indirect pcrel udata4";
case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata4:
EncStr = "indirect pcrel sdata4";
case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata8:
EncStr = "indirect pcrel udata8";
case dwarf::DW_EH_PE_indirect |dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata8:
EncStr = "indirect pcrel sdata8";
}
Streamer.AddComment(Twine(Prefix) + " = " + EncStr);
}
Streamer.EmitIntValue(Encoding, 1);
} }
void FrameEmitterImpl::EmitCFIInstruction(MCStreamer &Streamer, void FrameEmitterImpl::EmitCFIInstruction(MCStreamer &Streamer,
@ -635,7 +669,7 @@ bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer,
#else #else
MCContext &Context = Streamer.getContext(); MCContext &Context = Streamer.getContext();
const TargetAsmInfo &TAI = Context.getTargetAsmInfo(); const TargetAsmInfo &TAI = Context.getTargetAsmInfo();
Streamer.SwitchSection(TAI.getCompactUnwindSection()); bool VerboseAsm = Streamer.isVerboseAsm();
// range-start range-length compact-unwind-enc personality-func lsda // range-start range-length compact-unwind-enc personality-func lsda
// _foo LfooEnd-_foo 0x00000023 0 0 // _foo LfooEnd-_foo 0x00000023 0 0
@ -659,25 +693,31 @@ bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer,
// .quad __gxx_personality // .quad __gxx_personality
// .quad except_tab1 // .quad except_tab1
Streamer.SwitchSection(TAI.getCompactUnwindSection());
// Range Start // Range Start
unsigned FDEEncoding = TAI.getFDEEncoding(UsingCFI); unsigned FDEEncoding = TAI.getFDEEncoding(UsingCFI);
unsigned Size = getSizeForEncoding(Streamer, FDEEncoding); unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
if (VerboseAsm) Streamer.AddComment("Range Start");
Streamer.EmitSymbolValue(Frame.Function, Size); Streamer.EmitSymbolValue(Frame.Function, Size);
// Range Length // Range Length
const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin, const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin,
*Frame.End, 0); *Frame.End, 0);
if (VerboseAsm) Streamer.AddComment("Range Length");
Streamer.EmitAbsValue(Range, 4); Streamer.EmitAbsValue(Range, 4);
// FIXME: // FIXME:
// Compact Encoding // Compact Encoding
const std::vector<MachineMove> &Moves = TAI.getInitialFrameState();
uint32_t Encoding = 0; uint32_t Encoding = 0;
Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4); Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4);
if (VerboseAsm) Streamer.AddComment("Compact Unwind Encoding");
Streamer.EmitIntValue(Encoding, Size); Streamer.EmitIntValue(Encoding, Size);
// Personality Function // Personality Function
Size = getSizeForEncoding(Streamer, Frame.PersonalityEncoding); Size = getSizeForEncoding(Streamer, Frame.PersonalityEncoding);
if (VerboseAsm) Streamer.AddComment("Personality Function");
if (Frame.Personality) if (Frame.Personality)
Streamer.EmitSymbolValue(Frame.Personality, Size); Streamer.EmitSymbolValue(Frame.Personality, Size);
else else
@ -685,6 +725,7 @@ bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer,
// LSDA // LSDA
Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding); Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding);
if (VerboseAsm) Streamer.AddComment("LSDA");
if (Frame.Lsda) if (Frame.Lsda)
Streamer.EmitSymbolValue(Frame.Lsda, Size); Streamer.EmitSymbolValue(Frame.Lsda, Size);
else else
@ -701,6 +742,7 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer,
unsigned lsdaEncoding) { unsigned lsdaEncoding) {
MCContext &context = streamer.getContext(); MCContext &context = streamer.getContext();
const TargetAsmInfo &asmInfo = context.getTargetAsmInfo(); const TargetAsmInfo &asmInfo = context.getTargetAsmInfo();
bool verboseAsm = streamer.isVerboseAsm();
MCSymbol *sectionStart; MCSymbol *sectionStart;
if (asmInfo.isFunctionEHFrameSymbolPrivate() || !IsEH) if (asmInfo.isFunctionEHFrameSymbolPrivate() || !IsEH)
@ -708,6 +750,7 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer,
else else
sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum)); sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum));
streamer.EmitLabel(sectionStart);
CIENum++; CIENum++;
MCSymbol *sectionEnd = streamer.getContext().CreateTempSymbol(); MCSymbol *sectionEnd = streamer.getContext().CreateTempSymbol();
@ -715,19 +758,22 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer,
// Length // Length
const MCExpr *Length = MakeStartMinusEndExpr(streamer, *sectionStart, const MCExpr *Length = MakeStartMinusEndExpr(streamer, *sectionStart,
*sectionEnd, 4); *sectionEnd, 4);
streamer.EmitLabel(sectionStart); if (verboseAsm) streamer.AddComment("CIE Length");
streamer.EmitAbsValue(Length, 4); streamer.EmitAbsValue(Length, 4);
// CIE ID // CIE ID
unsigned CIE_ID = IsEH ? 0 : -1; unsigned CIE_ID = IsEH ? 0 : -1;
if (verboseAsm) streamer.AddComment("CIE ID Tag");
streamer.EmitIntValue(CIE_ID, 4); streamer.EmitIntValue(CIE_ID, 4);
// Version // Version
if (verboseAsm) streamer.AddComment("DW_CIE_VERSION");
streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1); streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1);
// Augmentation String // Augmentation String
SmallString<8> Augmentation; SmallString<8> Augmentation;
if (IsEH) { if (IsEH) {
if (verboseAsm) streamer.AddComment("CIE Augmentation");
Augmentation += "z"; Augmentation += "z";
if (personality) if (personality)
Augmentation += "P"; Augmentation += "P";
@ -739,12 +785,15 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer,
streamer.EmitIntValue(0, 1); streamer.EmitIntValue(0, 1);
// Code Alignment Factor // Code Alignment Factor
if (verboseAsm) streamer.AddComment("CIE Code Alignment Factor");
streamer.EmitULEB128IntValue(1); streamer.EmitULEB128IntValue(1);
// Data Alignment Factor // Data Alignment Factor
if (verboseAsm) streamer.AddComment("CIE Data Alignment Factor");
streamer.EmitSLEB128IntValue(getDataAlignmentFactor(streamer)); streamer.EmitSLEB128IntValue(getDataAlignmentFactor(streamer));
// Return Address Register // Return Address Register
if (verboseAsm) streamer.AddComment("CIE Return Address Column");
streamer.EmitULEB128IntValue(asmInfo.getDwarfRARegNum(true)); streamer.EmitULEB128IntValue(asmInfo.getDwarfRARegNum(true));
// Augmentation Data Length (optional) // Augmentation Data Length (optional)
@ -762,19 +811,25 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer,
// Encoding of the FDE pointers // Encoding of the FDE pointers
augmentationLength += 1; augmentationLength += 1;
if (verboseAsm) streamer.AddComment("Augmentation Size");
streamer.EmitULEB128IntValue(augmentationLength); streamer.EmitULEB128IntValue(augmentationLength);
// Augmentation Data (optional) // Augmentation Data (optional)
if (personality) { if (personality) {
// Personality Encoding // Personality Encoding
streamer.EmitIntValue(personalityEncoding, 1); EmitEncodingByte(streamer, personalityEncoding,
"Personality Encoding");
// Personality // Personality
if (verboseAsm) streamer.AddComment("Personality");
EmitPersonality(streamer, *personality, personalityEncoding); EmitPersonality(streamer, *personality, personalityEncoding);
} }
if (lsda) if (lsda)
streamer.EmitIntValue(lsdaEncoding, 1); // LSDA Encoding EmitEncodingByte(streamer, lsdaEncoding, "LSDA Encoding");
// Encoding of the FDE pointers // Encoding of the FDE pointers
streamer.EmitIntValue(asmInfo.getFDEEncoding(UsingCFI), 1); EmitEncodingByte(streamer, asmInfo.getFDEEncoding(UsingCFI),
"FDE Encoding");
} }
// Initial Instructions // Initial Instructions