<p dir="ltr">Can we have one seeing and share it? Dwarf debug could query the mc context?</p>
<p dir="ltr">Not sure if this would work. Just tossing it out there.</p>
<div class="gmail_quote">On Jun 18, 2014 8:31 PM, "Eric Christopher" <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p dir="ltr">Heh. Nice catch. Probably a rename to mc-dwarf-version would be best/easiest. </p>
<div class="gmail_quote">On Jun 18, 2014 8:25 PM, "Alp Toker" <<a href="mailto:alp@nuanti.com" target="_blank">alp@nuanti.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
On 01/05/2014 11:46, Oliver Stannard wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: olista01<br>
Date: Thu May  1 03:46:02 2014<br>
New Revision: 207739<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=207739&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=207739&view=rev</a><br>
Log:<br>
Record the DWARF version in MCContext<br>
<br>
Record the DWARF version in MCContext, and use it when<br>
emitting the dwarf version into the debug info.<br>
<br>
<br>
Modified:<br>
     llvm/trunk/include/llvm/MC/<u></u>MCContext.h<br>
     llvm/trunk/lib/MC/MCDwarf.cpp<br>
     llvm/trunk/test/MC/ELF/gen-<u></u>dwarf.s<br>
     llvm/trunk/tools/llvm-mc/llvm-<u></u>mc.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/<u></u>MCContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=207739&r1=207738&r2=207739&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/include/<u></u>llvm/MC/MCContext.h?rev=<u></u>207739&r1=207738&r2=207739&<u></u>view=diff</a><br>


==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/include/llvm/MC/<u></u>MCContext.h (original)<br>
+++ llvm/trunk/include/llvm/MC/<u></u>MCContext.h Thu May  1 03:46:02 2014<br>
@@ -147,6 +147,9 @@ namespace llvm {<br>
      /// non-empty.<br>
      StringRef DwarfDebugProducer;<br>
  +    /// The maximum version of dwarf that we should emit.<br>
+    uint16_t DwarfVersion;<br>
+<br>
      /// Honor temporary labels, this is useful for debugging semantic<br>
      /// differences between temporary and non-temporary labels (primarily on<br>
      /// Darwin).<br>
@@ -396,6 +399,9 @@ namespace llvm {<br>
      void setDwarfDebugProducer(<u></u>StringRef S) { DwarfDebugProducer = S; }<br>
      StringRef getDwarfDebugProducer() { return DwarfDebugProducer; }<br>
  +    void setDwarfVersion(uint16_t v) { DwarfVersion = v; }<br>
+    uint16_t getDwarfVersion() const { return DwarfVersion; }<br>
+<br>
      /// @}<br>
        char *getSecureLogFile() { return SecureLogFile; }<br>
<br>
Modified: llvm/trunk/lib/MC/MCDwarf.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=207739&r1=207738&r2=207739&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/MC/<u></u>MCDwarf.cpp?rev=207739&r1=<u></u>207738&r2=207739&view=diff</a><br>


==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCDwarf.cpp Thu May  1 03:46:02 2014<br>
@@ -645,8 +645,8 @@ static void EmitGenDwarfInfo(MCStreamer<br>
    const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4);<br>
    MCOS->EmitAbsValue(Length, 4);<br>
  -  // The 2 byte DWARF version, which is 2.<br>
-  MCOS->EmitIntValue(2, 2);<br>
+  // The 2 byte DWARF version.<br>
+  MCOS->EmitIntValue(context.<u></u>getDwarfVersion(), 2);<br>
      // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,<br>
    // it is at the start of that section so this is zero.<br>
<br>
Modified: llvm/trunk/test/MC/ELF/gen-<u></u>dwarf.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/gen-dwarf.s?rev=207739&r1=207738&r2=207739&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/test/MC/<u></u>ELF/gen-dwarf.s?rev=207739&r1=<u></u>207738&r2=207739&view=diff</a><br>


==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/test/MC/ELF/gen-<u></u>dwarf.s (original)<br>
+++ llvm/trunk/test/MC/ELF/gen-<u></u>dwarf.s Thu May  1 03:46:02 2014<br>
@@ -1,5 +1,9 @@<br>
-// RUN: llvm-mc -g -triple  i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r | FileCheck %s<br>
-// RUN: llvm-mc -g -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM %s<br>
+// RUN: llvm-mc -g -dwarf-version 2 -triple  i686-pc-linux-gnu %s -filetype=obj -o - | llvm-readobj -r | FileCheck %s<br>
+// RUN: not llvm-mc -g -dwarf-version 1  -triple  i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF1 %s<br>
+// RUN: llvm-mc -g -dwarf-version 2 -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF2 %s<br>
+// RUN: llvm-mc -g -dwarf-version 3 -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF3 %s<br>
+// RUN: llvm-mc -g -triple  i686-pc-linux-gnu %s -filetype=asm -o - | FileCheck --check-prefix=ASM --check-prefix=DWARF4 %s<br>
+// RUN: not llvm-mc -g -dwarf-version 5  -triple  i686-pc-linux-gnu %s -filetype=asm -o - 2>&1 | FileCheck --check-prefix=DWARF5 %s<br>
      // Test that on ELF:<br>
@@ -35,7 +39,9 @@ foo:<br>
  // Second instance of the section has the CU<br>
  // ASM: .section .debug_info<br>
  // Dwarf version<br>
-// ASM: .short 2<br>
+// DWARF2: .short 2<br>
+// DWARF3: .short 3<br>
+// DWARF4: .short 4<br>
  // ASM-NEXT: .long [[ABBREV_LABEL]]<br>
  // First .byte 1 is the abbreviation number for the compile_unit abbrev<br>
  // ASM: .byte 1<br>
@@ -44,3 +50,5 @@ foo:<br>
  // ASM: .section .debug_line<br>
  // ASM-NEXT: [[LINE_LABEL]]<br>
  +// DWARF1: Dwarf version 1 is not supported.<br>
+// DWARF5: Dwarf version 5 is not supported.<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/llvm-<u></u>mc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=207739&r1=207738&r2=207739&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/tools/llvm-<u></u>mc/llvm-mc.cpp?rev=207739&r1=<u></u>207738&r2=207739&view=diff</a><br>


==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/tools/llvm-mc/llvm-<u></u>mc.cpp (original)<br>
+++ llvm/trunk/tools/llvm-mc/llvm-<u></u>mc.cpp Thu May  1 03:46:02 2014<br>
@@ -154,6 +154,9 @@ static cl::opt<bool><br>
  GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly "<br>
                                    "source files"));<br>
  +static cl::opt<int><br>
+DwarfVersion("dwarf-version", cl::desc("Dwarf version"), cl::init(4));<br>
+<br>
</blockquote>
<br>
Hi Oliver,<br>
<br>
It looks like this "dwarf-version" option introduced to llvm-mc.cpp conflicts with an existing one in lib/CodeGen/AsmPrinter/<u></u>DwarfDebug.cpp:<br>
<br>
$ bin/llvm-mc<br>
<premain>: CommandLine Error: Argument 'dwarf-version' defined more than once!<br>
<br>
Due to a bug in CommandLine registration the errors got reported on stderr but didn't trigger any test failures so the issue went unnoticed.<br>
<br>
Could you coordinate with DwarfDebug.cpp to either share a single option definition, rename one of the two flags, or adjust link dependencies to eliminate the conflict?<br>
<br>
Once that's done I'll land the necessary CommandLine checks to make sure conflicting registrations get detected in future.<br>
<br>
Alp.<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  static cl::opt<std::string><br>
  DebugCompilationDir("fdebug-<u></u>compilation-dir",<br>
                      cl::desc("Specifies the debug info's compilation dir"));<br>
@@ -406,6 +409,12 @@ int main(int argc, char **argv) {<br>
      Ctx.setAllowTemporaryLabels(<u></u>false);<br>
      Ctx.setGenDwarfForAssembly(<u></u>GenDwarfForAssembly);<br>
+  if (DwarfVersion < 2 || DwarfVersion > 4) {<br>
+    errs() << ProgName << ": Dwarf version " << DwarfVersion<br>
+           << " is not supported." << '\n';<br>
+    return 1;<br>
+  }<br>
+  Ctx.setDwarfVersion(<u></u>DwarfVersion);<br>
    if (!DwarfDebugFlags.empty())<br>
      Ctx.setDwarfDebugFlags(<u></u>StringRef(DwarfDebugFlags));<br>
    if (!DwarfDebugProducer.empty())<br>
<br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</blockquote>
<br>
-- <br>
<a href="http://www.nuanti.com" target="_blank">http://www.nuanti.com</a><br>
the browser experts<br>
<br>
</blockquote></div>
</blockquote></div>