<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 14, 2014 at 7:37 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We really shouldn't be mixing debug information *in* the .s and debug<br>
information generated *for* a .s.<br>
<br>
It might be that dwarfdump has a bug and needs more information to<br>
work. In which case that information should be in the .s or we should<br>
fix dwarfdump.<br></blockquote><div><br></div><div>It sort of does. I poked around with this yesterday.<br><br>llvm-dwarfdump can't/won't dump debug_line tables if there's no compile unit that refers to that debug_lines section.<br>
<br>One reason is that you can't actually parse the debug_line tables if you don't know the size of an address for the compile unit. So llvm-dwarfdump just reads all the compile units and prints out their respective line tables.<br>
<br>This is both redundant (it'll print multiple line tables even if all the compile units share a single one, I think) and needlessly confusing/incorrect (even if we can't print the guts of the line table, we should still be able to read the length of the table (maybe print the whole table header - but I think it has one address field, which can vary depending on the CU) and skip over its contents).<br>
<br>So what would be nice to see would be: parse all the CUs, sort their debug_line offsets, then walk the debug_types section in order, printing a terse summary ("length, unknown data") for each entry/table/thing we didn't have a CU/address size for, and printing the full dump for each one we do have the CU/address size for.<br>
<br>The short answer here, without fixing/improving llvm-dwarfdump, would be to just include a minimal debug_info section with a single compile_unit with the necessary DW_AT_stmt_list entry that points to the debug_lines section, then dumping will print it out.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Give me a sec. I am applying you patch and will debug it a bit to see<br>
what is the issue.<br>
<div class="HOEnZb"><div class="h5"><br>
On 14 February 2014 10:28, Diego Novillo <<a href="mailto:dnovillo@google.com">dnovillo@google.com</a>> wrote:<br>
> I still haven't woken up. I need -g in *both* cases:<br>
><br>
> 1- llvm-dwarfdump needs a -g .o or it will not generate its report.<br>
> 2- If I do not use -g, I need to write a .file directive so .loc won't<br>
> get confused.<br>
> 3- I cannot write a .file directive if I'm using -g.<br>
><br>
> So, the only way to get both tests here is to always run llvm-mc with<br>
> -g.<br>
><br>
> Hi echristo,<br>
><br>
> <a href="http://llvm-reviews.chandlerc.com/D2794" target="_blank">http://llvm-reviews.chandlerc.com/D2794</a><br>
><br>
> CHANGE SINCE LAST DIFF<br>
> <a href="http://llvm-reviews.chandlerc.com/D2794?vs=7129&id=7131#toc" target="_blank">http://llvm-reviews.chandlerc.com/D2794?vs=7129&id=7131#toc</a><br>
><br>
> Files:<br>
> lib/DebugInfo/DWARFDebugLine.cpp<br>
> lib/DebugInfo/DWARFDebugLine.h<br>
> lib/MC/MCDwarf.cpp<br>
> test/DebugInfo/X86/ending-run.ll<br>
> test/DebugInfo/X86/line-info.ll<br>
> test/MC/ELF/discriminator.s<br>
> test/MC/MachO/gen-dwarf-cpp.s<br>
> test/MC/MachO/gen-dwarf.s<br>
><br>
> Index: lib/DebugInfo/DWARFDebugLine.cpp<br>
> ===================================================================<br>
> --- lib/DebugInfo/DWARFDebugLine.cpp<br>
> +++ lib/DebugInfo/DWARFDebugLine.cpp<br>
> @@ -62,6 +62,7 @@<br>
> Column = 0;<br>
> File = 1;<br>
> Isa = 0;<br>
> + Discriminator = 0;<br>
> IsStmt = default_is_stmt;<br>
> BasicBlock = false;<br>
> EndSequence = false;<br>
> @@ -71,7 +72,7 @@<br>
><br>
> void DWARFDebugLine::Row::dump(raw_ostream &OS) const {<br>
> OS << format("0x%16.16" PRIx64 " %6u %6u", Address, Line, Column)<br>
> - << format(" %6u %3u ", File, Isa)<br>
> + << format(" %6u %3u %13u ", File, Isa, Discriminator)<br>
> << (IsStmt ? " is_stmt" : "")<br>
> << (BasicBlock ? " basic_block" : "")<br>
> << (PrologueEnd ? " prologue_end" : "")<br>
> @@ -85,8 +86,9 @@<br>
> OS << '\n';<br>
><br>
> if (!Rows.empty()) {<br>
> - OS << "Address Line Column File ISA Flags\n"<br>
> - << "------------------ ------ ------ ------ --- -------------\n";<br>
> + OS << "Address Line Column File ISA Discriminator Flags\n"<br>
> + << "------------------ ------ ------ ------ --- ------------- "<br>
> + "-------------\n";<br>
> for (std::vector<Row>::const_iterator pos = Rows.begin(),<br>
> end = Rows.end(); pos != end; ++pos)<br>
> pos->dump(OS);<br>
> @@ -311,6 +313,10 @@<br>
> }<br>
> break;<br>
><br>
> + case DW_LNE_set_discriminator:<br>
> + state.Discriminator = debug_line_data.getULEB128(offset_ptr);<br>
> + break;<br>
> +<br>
> default:<br>
> // Length doesn't include the zero opcode byte or the length itself, but<br>
> // it does include the sub_opcode, so we have to adjust for that below<br>
> Index: lib/DebugInfo/DWARFDebugLine.h<br>
> ===================================================================<br>
> --- lib/DebugInfo/DWARFDebugLine.h<br>
> +++ lib/DebugInfo/DWARFDebugLine.h<br>
> @@ -112,6 +112,9 @@<br>
> // An unsigned integer whose value encodes the applicable instruction set<br>
> // architecture for the current instruction.<br>
> uint8_t Isa;<br>
> + // An unsigned integer representing the DWARF path discriminator value<br>
> + // for this location.<br>
> + uint32_t Discriminator;<br>
> // A boolean indicating that the current instruction is the beginning of a<br>
> // statement.<br>
> uint8_t IsStmt:1,<br>
> Index: lib/MC/MCDwarf.cpp<br>
> ===================================================================<br>
> --- lib/MC/MCDwarf.cpp<br>
> +++ lib/MC/MCDwarf.cpp<br>
> @@ -137,6 +137,7 @@<br>
> unsigned Column = 0;<br>
> unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;<br>
> unsigned Isa = 0;<br>
> + unsigned Discriminator = 0;<br>
> MCSymbol *LastLabel = NULL;<br>
><br>
> // Loop through each MCLineEntry and encode the dwarf line number table.<br>
> @@ -154,6 +155,15 @@<br>
> MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1);<br>
> MCOS->EmitULEB128IntValue(Column);<br>
> }<br>
> + if (Discriminator != it->getDiscriminator()) {<br>
> + Discriminator = it->getDiscriminator();<br>
> + unsigned Size =<br>
> + MCOS->getContext().getAsmInfo()->getULEB128Size(Discriminator);<br>
> + MCOS->EmitIntValue(dwarf::DW_LNS_extended_op, 1);<br>
> + MCOS->EmitULEB128IntValue(Size + 1);<br>
> + MCOS->EmitIntValue(dwarf::DW_LNE_set_discriminator, 1);<br>
> + MCOS->EmitULEB128IntValue(Discriminator);<br>
> + }<br>
> if (Isa != it->getIsa()) {<br>
> Isa = it->getIsa();<br>
> MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1);<br>
> Index: test/DebugInfo/X86/ending-run.ll<br>
> ===================================================================<br>
> --- test/DebugInfo/X86/ending-run.ll<br>
> +++ test/DebugInfo/X86/ending-run.ll<br>
> @@ -4,9 +4,9 @@<br>
> ; Check that the line table starts at 7, not 4, but that the first<br>
> ; statement isn't until line 8.<br>
><br>
> -; CHECK-NOT: 0x0000000000000000 7 0 1 0 is_stmt<br>
> +; CHECK-NOT: 0x0000000000000000 7 0 1 0 0 is_stmt<br>
> ; CHECK: 0x0000000000000000 7 0 1 0<br>
> -; CHECK: 0x0000000000000004 8 18 1 0 is_stmt prologue_end<br>
> +; CHECK: 0x0000000000000004 8 18 1 0 0 is_stmt prologue_end<br>
><br>
> define i32 @callee(i32 %x) nounwind uwtable ssp {<br>
> entry:<br>
> Index: test/DebugInfo/X86/line-info.ll<br>
> ===================================================================<br>
> --- test/DebugInfo/X86/line-info.ll<br>
> +++ test/DebugInfo/X86/line-info.ll<br>
> @@ -2,7 +2,7 @@<br>
> ; RUN: llvm-dwarfdump %t | FileCheck %s<br>
><br>
> ; CHECK: [[FILEID:[0-9]+]]]{{.*}}list0.h<br>
> -; CHECK: [[FILEID]] 0 1 0 is_stmt{{$}}<br>
> +; CHECK: [[FILEID]] 0 1 0 0 is_stmt{{$}}<br>
><br>
> ; IR generated from clang -g -emit-llvm with the following source:<br>
> ; list0.h:<br>
> Index: test/MC/ELF/discriminator.s<br>
> ===================================================================<br>
> --- /dev/null<br>
> +++ test/MC/ELF/discriminator.s<br>
> @@ -0,0 +1,20 @@<br>
> +# RUN: llvm-mc -g -triple i386-unknown-unknown %s -filetype=obj -o - | llvm-readobj -r | FileCheck %s<br>
> +# RUN: llvm-mc -g -triple i386-unknown-unknown %s -filetype=obj -o - | llvm-dwarfdump -debug-dump=line - | FileCheck %s -check-prefix=DWARF-DUMP<br>
> +<br>
> + .text<br>
> + .globl foo<br>
> + .type foo, @function<br>
> + .align 4<br>
> +foo:<br>
> + .loc 1 2 discriminator 1<br>
> + ret<br>
> + .size foo, .-foo<br>
> +<br>
> +# CHECK: Relocations [<br>
> +# CHECK: Section ({{[^ ]+}}) .rel.debug_line {<br>
> +# CHECK-NEXT: 0x5B R_386_32 .text 0x0<br>
> +# CHECK-NEXT: }<br>
> +<br>
> +# DWARF-DUMP: Address Line Column File ISA Discriminator Flags<br>
> +# DWARF-DUMP: ------------------ ------ ------ ------ --- ------------- -------------<br>
> +# DWARF-DUMP: 0x0000000000000000 2 0 1 0 1 is_stmt<br>
> Index: test/MC/MachO/gen-dwarf-cpp.s<br>
> ===================================================================<br>
> --- test/MC/MachO/gen-dwarf-cpp.s<br>
> +++ test/MC/MachO/gen-dwarf-cpp.s<br>
> @@ -17,6 +17,6 @@<br>
> // CHECK: file_names[ 2] 0 0x00000000 0x00000000 t.s<br>
><br>
> // We check that the source line number 100 is picked up before the "movl"<br>
> -// CHECK: Address Line Column File ISA Flags<br>
> -// CHECK: ------------------ ------ ------ ------ --- -------------<br>
> -// CHECK: 0x0000000000000000 102 0 2 0 is_stmt<br>
> +// CHECK: Address Line Column File ISA Discriminator Flags<br>
> +// CHECK: ------------------ ------ ------ ------ --- ------------- -------------<br>
> +// CHECK: 0x0000000000000000 102 0 2 0 0 is_stmt<br>
> Index: test/MC/MachO/gen-dwarf.s<br>
> ===================================================================<br>
> --- test/MC/MachO/gen-dwarf.s<br>
> +++ test/MC/MachO/gen-dwarf.s<br>
> @@ -113,10 +113,10 @@<br>
> // CHECK: ---- ---------- ---------- ---------------------------<br>
> // CHECK: file_names[ 1] 1 0x00000000 0x00000000 gen-dwarf.s<br>
><br>
> -// CHECK: Address Line Column File ISA Flags<br>
> -// CHECK: ------------------ ------ ------ ------ --- -------------<br>
> -// CHECK: 0x0000000000000000 6 0 1 0 is_stmt<br>
> -// CHECK: 0x0000000000000005 7 0 1 0 is_stmt<br>
> -// CHECK: 0x0000000000000006 8 0 1 0 is_stmt<br>
> -// CHECK: 0x0000000000000007 11 0 1 0 is_stmt<br>
> -// CHECK: 0x0000000000000008 11 0 1 0 is_stmt end_sequence<br>
> +// CHECK: Address Line Column File ISA Discriminator Flags<br>
> +// CHECK: ------------------ ------ ------ ------ --- ------------- -------------<br>
> +// CHECK: 0x0000000000000000 6 0 1 0 0 is_stmt<br>
> +// CHECK: 0x0000000000000005 7 0 1 0 0 is_stmt<br>
> +// CHECK: 0x0000000000000006 8 0 1 0 0 is_stmt<br>
> +// CHECK: 0x0000000000000007 11 0 1 0 0 is_stmt<br>
> +// CHECK: 0x0000000000000008 11 0 1 0 0 is_stmt end_sequence<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">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/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div></div>