Index: test/MC/ARM/dwarf-asm-multiple-sections.s =================================================================== --- test/MC/ARM/dwarf-asm-multiple-sections.s +++ test/MC/ARM/dwarf-asm-multiple-sections.s @@ -1,7 +1,9 @@ // RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -fdebug-compilation-dir=/tmp // RUN: llvm-dwarfdump %t | FileCheck -check-prefix DWARF %s // RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC %s -// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -gdwarf-2 2>&1 | FileCheck -check-prefix VERSION %s +// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 2 2>&1 | FileCheck -check-prefix VERSION %s +// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 1 2>&1 | FileCheck -check-prefix DWARF1 %s +// RUN: not llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 5 2>&1 | FileCheck -check-prefix DWARF5 %s .section .text, "ax" a: mov r0, r0 @@ -39,10 +41,10 @@ // DWARF: .debug_line contents: -// DWARF: 0x0000000000000000 7 0 1 0 0 is_stmt -// DWARF-NEXT: 0x0000000000000004 7 0 1 0 0 is_stmt end_sequence -// DWARF-NEXT: 0x0000000000000000 11 0 1 0 0 is_stmt -// DWARF-NEXT: 0x0000000000000004 11 0 1 0 0 is_stmt end_sequence +// DWARF: 0x0000000000000000 9 0 1 0 0 is_stmt +// DWARF-NEXT: 0x0000000000000004 9 0 1 0 0 is_stmt end_sequence +// DWARF-NEXT: 0x0000000000000000 13 0 1 0 0 is_stmt +// DWARF-NEXT: 0x0000000000000004 13 0 1 0 0 is_stmt end_sequence // DWARF: .debug_ranges contents: @@ -72,3 +74,6 @@ // VERSION: {{.*}} error: DWARF2 only supports one section per compilation unit + +// DWARF1: Dwarf version 1 is not supported. +// DWARF5: Dwarf version 5 is not supported. Index: tools/llvm-mc/llvm-mc.cpp =================================================================== --- tools/llvm-mc/llvm-mc.cpp +++ tools/llvm-mc/llvm-mc.cpp @@ -152,22 +152,8 @@ GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly " "source files")); -enum DwarfVersionNumber { - DWARF2 = 2, - DWARF3 = 3, - DWARF4 = 4 -}; - -static cl::opt -DwarfVersion(cl::desc("Dwarf version"), - cl::init(DWARF3), - cl::values(clEnumValN(DWARF2, "gdwarf-2", - "Dwarf version 2"), - clEnumValN(DWARF3, "gdwarf-3", - "Dwarf version 3"), - clEnumValN(DWARF4, "gdwarf-4", - "Dwarf version 4"), - clEnumValEnd)); +static cl::opt +DwarfVersion("dwarf-version", cl::desc("Dwarf version"), cl::init(3)); static cl::opt DebugCompilationDir("fdebug-compilation-dir", @@ -411,6 +397,11 @@ 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));