<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">For context, here are the relevant LLVM discussions:<div class=""><a href="http://reviews.llvm.org/D16569" style="font-family: Menlo-Regular;" class="">http://reviews.llvm.org/D16569</a> (<font face="Helvetica Neue" class="">D16569: Emit line 0 line information for interesting 'orphan’ instructions)</font></div><div class=""><a href="http://reviews.llvm.org/D9887" style="font-family: Menlo-Regular;" class="">http://reviews.llvm.org/D9887</a> <span style="font-family: 'Helvetica Neue';" class="">[DebugInfo][FastISel] Prevent using debug location from previous block for local values</span></div><div class=""><span style="font-family: 'Helvetica Neue';" class=""><br class=""></span></div><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 3, 2016, at 12:56 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">(Also, if clang is not generating code like this currently, maybe it's not a priority, but seems worth mentioning the technique anyway, since it could have a lot of use for these types of scenarios)</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Feb 3, 2016 at 12:54 PM Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">I asked around a little bit, and it seems like you do this by hand-writing some LLVM IR (limiting yourself to a subset that is sufficiently platform independent) and having clang link that in alongside a regular executable.  Then call your LLVM IR function from C++ and step over it.  Would that work?</div></blockquote></div></div></blockquote><div><br class=""></div><div>LLVM IR is nowhere near platform independent enough for this to be portable. Of course having a test for a single target is probably still better than having no test. I’m not sure if the effort of maintaining textual IR (which tends to change a lot) in the LLDB testsuite is worth it. Another option (not any less messy) would be to compile the test to assembler with -S insert a .loc 0 before assembling the file.</div><div><br class=""></div><div>-- adrian</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><br class=""></div><div class="">You'd probably need to talk to one of the LLVM guys to figure out how to do that, but it seems like it should work.</div><div class=""><br class=""></div><div class="">Assuming it does, this technique would also open the door to writing a lot of test cases that have historically been very difficult to write (such as unwinder tests that need frames to be constructed a specific way, etc).</div></div><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Feb 2, 2016 at 5:31 PM Jim Ingham <<a href="mailto:jingham@apple.com" target="_blank" class="">jingham@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I don't think Clang does this right now, but Adrian says they are considering doing it to solve some problems they have with keeping track of nested inlines.<br class="">
<br class="">
Swift does it, but the compiler makes no guarantees as to when this will happen.  It isn't controlled by some pragma, builtin or whatever.  So I know some places where it will happen today, but there's no guarantee it will continue to happen in the future.  So I'll have to write a test that works with the current compiler, and fails if the compiler changes so the relevant function no longer has line number 0 code right after the prologue.  Yuck!<br class="">
<br class="">
I don't think it will be any different with clang when/if it starts doing this.<br class="">
<br class="">
Jim<br class="">
<br class="">
<br class="">
> On Feb 2, 2016, at 4:14 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank" class="">zturner@google.com</a>> wrote:<br class="">
><br class="">
> Shouldn't it be possible to force clang to generate code like this?  If so couldn't you write a test for this by stepping over a function call which has this kind of code in it?<br class="">
><br class="">
> On Tue, Feb 2, 2016 at 4:11 PM Jim Ingham via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank" class="">lldb-commits@lists.llvm.org</a>> wrote:<br class="">
> Author: jingham<br class="">
> Date: Tue Feb  2 18:07:23 2016<br class="">
> New Revision: 259611<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259611&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=259611&view=rev</a><br class="">
> Log:<br class="">
> The compiler may use "line number 0" to indicate compiler generated goo that it can't<br class="">
> track a source for.  When we are pushing breakpoints and stepping past function prologues,<br class="">
> also push past code from line 0 immediately following the prologue end.<br class="">
><br class="">
> <<a href="rdar://problem/23730696" class="">rdar://problem/23730696</a>><br class="">
><br class="">
> Modified:<br class="">
>     lldb/trunk/include/lldb/Symbol/Function.h<br class="">
>     lldb/trunk/source/Symbol/Function.cpp<br class="">
><br class="">
> Modified: lldb/trunk/include/lldb/Symbol/Function.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=259611&r1=259610&r2=259611&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=259611&r1=259610&r2=259611&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- lldb/trunk/include/lldb/Symbol/Function.h (original)<br class="">
> +++ lldb/trunk/include/lldb/Symbol/Function.h Tue Feb  2 18:07:23 2016<br class="">
> @@ -574,6 +574,14 @@ public:<br class="">
>      CompilerType<br class="">
>      GetCompilerType ();<br class="">
><br class="">
> +    //------------------------------------------------------------------<br class="">
> +    /// Get the size of the prologue instructions for this function.  The "prologue"<br class="">
> +    /// instructions include any instructions given line number 0 immediately following<br class="">
> +    /// the prologue end.<br class="">
> +    ///<br class="">
> +    /// @return<br class="">
> +    ///     The size of the prologue.<br class="">
> +    //------------------------------------------------------------------<br class="">
>      uint32_t<br class="">
>      GetPrologueByteSize ();<br class="">
><br class="">
><br class="">
> Modified: lldb/trunk/source/Symbol/Function.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=259611&r1=259610&r2=259611&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Function.cpp?rev=259611&r1=259610&r2=259611&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- lldb/trunk/source/Symbol/Function.cpp (original)<br class="">
> +++ lldb/trunk/source/Symbol/Function.cpp Tue Feb  2 18:07:23 2016<br class="">
> @@ -570,6 +570,8 @@ Function::GetPrologueByteSize ()<br class="">
>      {<br class="">
>          m_flags.Set(flagsCalculatedPrologueSize);<br class="">
>          LineTable* line_table = m_comp_unit->GetLineTable ();<br class="">
> +        uint32_t prologue_end_line_idx = 0;<br class="">
> +<br class="">
>          if (line_table)<br class="">
>          {<br class="">
>              LineEntry first_line_entry;<br class="">
> @@ -578,9 +580,12 @@ Function::GetPrologueByteSize ()<br class="">
>              {<br class="">
>                  // Make sure the first line entry isn't already the end of the prologue<br class="">
>                  addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;<br class="">
> +                addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;<br class="">
> +<br class="">
>                  if (first_line_entry.is_prologue_end)<br class="">
>                  {<br class="">
>                      prologue_end_file_addr = first_line_entry.range.GetBaseAddress().GetFileAddress();<br class="">
> +                    prologue_end_line_idx = first_line_entry_idx;<br class="">
>                  }<br class="">
>                  else<br class="">
>                  {<br class="">
> @@ -595,6 +600,7 @@ Function::GetPrologueByteSize ()<br class="">
>                              if (line_entry.is_prologue_end)<br class="">
>                              {<br class="">
>                                  prologue_end_file_addr = line_entry.range.GetBaseAddress().GetFileAddress();<br class="">
> +                                prologue_end_line_idx = idx;<br class="">
>                                  break;<br class="">
>                              }<br class="">
>                          }<br class="">
> @@ -607,7 +613,7 @@ Function::GetPrologueByteSize ()<br class="">
>                  {<br class="">
>                      // Check the first few instructions and look for one that has<br class="">
>                      // a line number that's different than the first entry.<br class="">
> -                    const uint32_t last_line_entry_idx = first_line_entry_idx + 6;<br class="">
> +                    uint32_t last_line_entry_idx = first_line_entry_idx + 6;<br class="">
>                      for (uint32_t idx = first_line_entry_idx + 1; idx < last_line_entry_idx; ++idx)<br class="">
>                      {<br class="">
>                          LineEntry line_entry;<br class="">
> @@ -616,6 +622,7 @@ Function::GetPrologueByteSize ()<br class="">
>                              if (line_entry.line != first_line_entry.line)<br class="">
>                              {<br class="">
>                                  prologue_end_file_addr = line_entry.range.GetBaseAddress().GetFileAddress();<br class="">
> +                                prologue_end_line_idx = idx;<br class="">
>                                  break;<br class="">
>                              }<br class="">
>                          }<br class="">
> @@ -624,10 +631,37 @@ Function::GetPrologueByteSize ()<br class="">
>                      if (prologue_end_file_addr == LLDB_INVALID_ADDRESS)<br class="">
>                      {<br class="">
>                          prologue_end_file_addr = first_line_entry.range.GetBaseAddress().GetFileAddress() + first_line_entry.range.GetByteSize();<br class="">
> +                        prologue_end_line_idx = first_line_entry_idx;<br class="">
>                      }<br class="">
>                  }<br class="">
> +<br class="">
>                  const addr_t func_start_file_addr = m_range.GetBaseAddress().GetFileAddress();<br class="">
>                  const addr_t func_end_file_addr = func_start_file_addr + m_range.GetByteSize();<br class="">
> +<br class="">
> +                // Now calculate the offset to pass the subsequent line 0 entries.<br class="">
> +                uint32_t first_non_zero_line = prologue_end_line_idx;<br class="">
> +                while (1)<br class="">
> +                {<br class="">
> +                    LineEntry line_entry;<br class="">
> +                    if (line_table->GetLineEntryAtIndex(first_non_zero_line, line_entry))<br class="">
> +                    {<br class="">
> +                        if (line_entry.line != 0)<br class="">
> +                            break;<br class="">
> +                    }<br class="">
> +                    if (line_entry.range.GetBaseAddress().GetFileAddress() >= func_end_file_addr)<br class="">
> +                        break;<br class="">
> +<br class="">
> +                    first_non_zero_line++;<br class="">
> +                }<br class="">
> +<br class="">
> +                if (first_non_zero_line > prologue_end_line_idx)<br class="">
> +                {<br class="">
> +                    LineEntry first_non_zero_entry;<br class="">
> +                    if (line_table->GetLineEntryAtIndex(first_non_zero_line, first_non_zero_entry))<br class="">
> +                    {<br class="">
> +                        line_zero_end_file_addr = first_non_zero_entry.range.GetBaseAddress().GetFileAddress();<br class="">
> +                    }<br class="">
> +                }<br class="">
><br class="">
>                  // Verify that this prologue end file address in the function's<br class="">
>                  // address range just to be sure<br class="">
> @@ -635,10 +669,16 @@ Function::GetPrologueByteSize ()<br class="">
>                  {<br class="">
>                      m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;<br class="">
>                  }<br class="">
> +<br class="">
> +                if (prologue_end_file_addr < line_zero_end_file_addr && line_zero_end_file_addr < func_end_file_addr)<br class="">
> +                {<br class="">
> +                    m_prologue_byte_size += line_zero_end_file_addr - prologue_end_file_addr;<br class="">
> +                }<br class="">
>              }<br class="">
>          }<br class="">
>      }<br class="">
> -    return m_prologue_byte_size;<br class="">
> +<br class="">
> +        return m_prologue_byte_size;<br class="">
>  }<br class="">
><br class="">
>  lldb::LanguageType<br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> lldb-commits mailing list<br class="">
> <a href="mailto:lldb-commits@lists.llvm.org" target="_blank" class="">lldb-commits@lists.llvm.org</a><br class="">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="">
<br class="">
</blockquote></div></div></div></blockquote></div>
</div></blockquote></div><br class=""></div></body></html>