Page MenuHomePhabricator

[LLDB] Switch to assembly view if source is moved

Authored by mohit.bhakkad on Sep 14 2015, 11:55 PM.

Diff Detail


Event Timeline

mohit.bhakkad retitled this revision from to [LLDB] Switch to assembly view if source is moved.
mohit.bhakkad updated this object.
mohit.bhakkad added a reviewer: clayborg.
mohit.bhakkad set the repository for this revision to rL LLVM.
mohit.bhakkad added subscribers: jaydeep, bhushan, slthakur and 2 others.
jingham requested changes to this revision.Sep 15 2015, 10:03 AM
jingham added a reviewer: jingham.
jingham added a subscriber: jingham.

This change means that the two cases "no debug info" and "couldn't find your sources" end up looking very similar. I think it is fine to show the assembly but it would be better to also arrange a warning that we couldn't find this source file.

This revision now requires changes to proceed.Sep 15 2015, 10:03 AM
clayborg accepted this revision.Sep 15 2015, 2:27 PM
clayborg edited edge metadata.

I would rather not see a warning. If you don't have sources I don't really want to see:

warning: couldn't find foo.c
0x1000: add r1, r2, r3

Maybe we can enable mixed mode display where it intersperses the source file and line in the disassembly when/if there is source info, but no source file?

clayborg requested changes to this revision.Sep 15 2015, 3:37 PM
clayborg edited edge metadata.

Ok, so Jim and I agreed verbally on the solution. If we have source, but we don't have the source file itself, then we should print the line table entry out. This can be done with:

if (num_lines == 0)
    const bool show_fullpaths = true;
    m_sc.line_entry.DumpStopContext(&strm, show_fullpaths) const
    have_source = false;

So the output will now be

0x1000: add r1, r2, r3

No need for a warning, just print the line entry.

sas edited edge metadata.Sep 15 2015, 4:20 PM
sas added a subscriber: sas.

Maybe I'm an outlier here -- but I don't think we should show assembly code, unless specifically requested by the user, when we can't find a source file (but we have source-level debug information).

lldb used to behave the other way - when a source file could not be found, we would show assembly before the prompt. There were many complaints from users about this behavior; users who are thinking at a source level and using source commands like "step" and "next", did not want to see assembly, it was meaningless to them. If they stepi into an assembly routine or put a breakpoint on it - where we have no debug information, then presenting the assembly makes sense.

IIRC, gdb behaves the same way that lldb does today. e.g.

clang -g a.c
rm a.c
lldb a.out
(lldb) br s -n main
(lldb) r

  • thread #1: tid = 0x5e8d52, 0x0000000100000ed7 a.out`main(argc=1, argv=0x00007fff5fbff958) + 39 at a.c:10, queue = '', stop reason = breakpoint 1.1 frame #0: 0x0000000100000ed7 a.out`main(argc=1, argv=0x00007fff5fbff958) + 39 at a.c:10

(lldb) n
Process 38732 stopped

  • thread #1: tid = 0x5e8d52, 0x0000000100000eea a.out`main(argc=1, argv=0x00007fff5fbff958) + 58 at a.c:11, queue = '', stop reason = step over frame #0: 0x0000000100000eea a.out`main(argc=1, argv=0x00007fff5fbff958) + 58 at a.c:11


I feel pretty strongly that this behavior should not be changed. Seeing mixed source and assembly is meaningful to me and I may personally like to see that -- but the vast majority of our users do not interact with their programs at that level.

I chatted with Jim and Greg about this today. We have a "stop-disassembly-display" setting right now. It can be one of three values:

never: never show assembly
no-source: show assembly when we have no debug information
always: always show assembly

"no-source" is a poor name. What this really means is "no-debuginfo". I think we should have four values for stop-disassembly-display:

never: never show assembly
no-debuginfo: show assembly when we have no debug info
no-source: show assembly when we have no source file
always: always show assembly

and I think the default for stop-disassembly-display should be no-debuginfo. This preserves the existing behavior but if users would prefer to see assembly when a source file is missing, they can set it to be "no-source" and they will get that behavior.

Mohit, what do you think about this approach?

Jim raised the point that it would be nice if lldb would print the full path of the missing source file when it can't print the source file. That way, if the user knows the source is available at a different file path, they can add a target.source-map remapping and lldb can show the source code. There is a mechanism for printing a warning one time in Process already, see Process::PrintWarningOptimization. This warning is printed once per Module - you can see that it passes the Module pointer to PrintWarning. We'd want to add a Process::PrintWarningSourceFileMissing method and issue it once per source file in a similar way. Don't feel obligated to do this - it's just something that we should do, unrelated to the changes you're looking at here. With this change, the first time a user steps into a context where we have debug info but cannot find the source, the user will get a message like

warning: Could not find source file at '/builder/project/subir_a/MySources.cpp'

and the user can be like "Oh yes, of course, it's actually on /archivedbuilds/project/subdir_a on this computer" and do the file remap.

Hi Jason, thanks for your suggestions. Yes, this approach looks good and one time warning should be helpful from users view, I will implement it get back with a patch soon.

mohit.bhakkad edited edge metadata.

Changes in this revision:

  • changed no-source to no-debuginfo and made it default
  • now no-source means display assembly if source file is missing, even if debug-info is present.
clayborg accepted this revision.Nov 2 2015, 10:53 AM
clayborg edited edge metadata.

Yep, Greg said the patch is good to commit.

This revision was automatically updated to reflect the committed changes.