[PATCH] Record the DWARF version in MCContext
Oliver Stannard
oliver.stannard at arm.com
Wed Apr 16 09:16:53 PDT 2014
Expand test/MC/ELF/gen-dwarf.s to check that the correct dwarf version is emitted.
http://reviews.llvm.org/D3399
CHANGE SINCE LAST DIFF
http://reviews.llvm.org/D3399?vs=8569&id=8577#toc
Files:
include/llvm/MC/MCContext.h
lib/MC/MCDwarf.cpp
test/MC/ELF/gen-dwarf.s
tools/llvm-mc/llvm-mc.cpp
Index: include/llvm/MC/MCContext.h
===================================================================
--- include/llvm/MC/MCContext.h
+++ include/llvm/MC/MCContext.h
@@ -147,6 +147,9 @@
/// non-empty.
StringRef DwarfDebugProducer;
+ /// The maximum version of dwarf that we should emit.
+ unsigned DwarfVersion;
+
/// Honor temporary labels, this is useful for debugging semantic
/// differences between temporary and non-temporary labels (primarily on
/// Darwin).
@@ -396,6 +399,9 @@
void setDwarfDebugProducer(StringRef S) { DwarfDebugProducer = S; }
StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }
+ void setDwarfVersion(unsigned v) { DwarfVersion = v; }
+ unsigned getDwarfVersion() const { return DwarfVersion; }
+
/// @}
char *getSecureLogFile() { return SecureLogFile; }
Index: lib/MC/MCDwarf.cpp
===================================================================
--- lib/MC/MCDwarf.cpp
+++ lib/MC/MCDwarf.cpp
@@ -645,8 +645,8 @@
const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4);
MCOS->EmitAbsValue(Length, 4);
- // The 2 byte DWARF version, which is 2.
- MCOS->EmitIntValue(2, 2);
+ // The 2 byte DWARF version.
+ MCOS->EmitIntValue(context.getDwarfVersion(), 2);
// The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
// it is at the start of that section so this is zero.
Index: test/MC/ELF/gen-dwarf.s
===================================================================
--- test/MC/ELF/gen-dwarf.s
+++ test/MC/ELF/gen-dwarf.s
@@ -1,5 +1,7 @@
-// RUN: llvm-mc -g -triple i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r | FileCheck %s
+// RUN: llvm-mc -g -dwarf-version 2 -triple i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r | FileCheck %s
// RUN: llvm-mc -g -triple i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM %s
+// RUN: llvm-mc -g -dwarf-version 2 -triple i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM2 %s
+// RUN: llvm-mc -g -dwarf-version 3 -triple i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM3 %s
// Test that on ELF:
@@ -34,8 +36,12 @@
// Second instance of the section has the CU
// ASM: .section .debug_info
+// ASM2: .section .debug_info
+// ASM3: .section .debug_info
// Dwarf version
-// ASM: .short 2
+// ASM2: .short 2
+// ASM3: .short 3
+// ASM: .short 4
// ASM-NEXT: .long [[ABBREV_LABEL]]
// First .byte 1 is the abbreviation number for the compile_unit abbrev
// ASM: .byte 1
Index: tools/llvm-mc/llvm-mc.cpp
===================================================================
--- tools/llvm-mc/llvm-mc.cpp
+++ tools/llvm-mc/llvm-mc.cpp
@@ -153,6 +153,9 @@
GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly "
"source files"));
+static cl::opt<int>
+DwarfVersion("dwarf-version", cl::desc("Dwarf version"), cl::init(4));
+
static cl::opt<std::string>
DebugCompilationDir("fdebug-compilation-dir",
cl::desc("Specifies the debug info's compilation dir"));
@@ -403,6 +406,12 @@
Ctx.setAllowTemporaryLabels(false);
Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
+ if (DwarfVersion < 2 || DwarfVersion > 4) {
+ errs() << ProgName << ": Dwarf version " << DwarfVersion
+ << " is not supported." << '\n';
+ return 1;
+ }
+ Ctx.setDwarfVersion(DwarfVersion);
if (!DwarfDebugFlags.empty())
Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags));
if (!DwarfDebugProducer.empty())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3399.2.patch
Type: text/x-patch
Size: 3598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140416/2b2261b2/attachment.bin>
More information about the llvm-commits
mailing list