disassemble w/ source

When I explicitly run the “disassemble -m -n printf” command I don’t get source even though we’ve obviously got source and I’m stepping through it. Example is way down below.

I was hoping someone might be able to explain the the SourceManager class a bit. It looks like this function is being called to display the source:

// Disassembler::PrintInstructions()

443+> debugger.GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.line_entry.file,
444| sc.line_entry.line,
445| num_mixed_context_lines,
446| num_mixed_context_lines,
447| ((inst_is_at_pc && (options & eOptionMarkPCSourceLine)) ? “->” : “”)
448| &strm);

SourceManager.cpp, SourceManager::File::File() is not resolving the filename because there is no target set:

if (!m_mod_time.IsValid())
if (target)
m_source_map_mod_id = target->GetSourcePathMap().GetModificationID();

if (!file_spec.GetDirectory() && file_spec.GetFilename())

The SourceManager class has two constructors, and the debugger one doesn’t appear to set the target:

// SourceManager constructor
SourceManager::SourceManager(const TargetSP &target_sp) :
m_last_file_sp (),
m_last_line (0),
m_last_count (0),
m_target_wp (target_sp),

SourceManager::SourceManager(const DebuggerSP &debugger_sp) :
m_last_file_sp (),
m_last_line (0),
m_last_count (0),
m_target_wp (),
m_debugger_wp (debugger_sp)

Thoughts on how best to fix this?


mikesart@mikesart-rad:~/data/src/blah2/build$ lldb – blah
Current executable set to ‘blah’ (x86_64).
(lldb) b __printf
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) r
Process 14039 launched: ‘/home/mikesart/data/src/blah2/build/blah’ (x86_64)
1 location added to breakpoint 1
Process 14039 stopped

  • thread #1: tid = 0x36d7, 0x00007fe484b5b89b libc.so.6__printf(format=0x0000000000401fc6) + 91 at printf.c:34, stop reason = breakpoint 1.1 frame #0: 0x00007fe484b5b89b libc.so.6__printf(format=0x0000000000401fc6) + 91 at printf.c:34
    31 va_list arg;
    32 int done;
    → 34 va_start (arg, format);
    35 done = vfprintf (stdout, format, arg);
    36 va_end (arg);
    (lldb) n
    Process 14039 stopped
  • thread #1: tid = 0x36d7, 0x00007fe484b5b8a3 libc.so.6__printf(format=0x0000000000401fc6) + 99 at printf.c:30, stop reason = step over frame #0: 0x00007fe484b5b8a3 libc.so.6__printf(format=0x0000000000401fc6) + 99 at printf.c:30
    27 /* VARARGS1 */
    28 int
    29 __printf (const char *format, …)
    → 30 {
    31 va_list arg;
    32 int done;
    (lldb) disassemble -m
    libc.so.6__printf at printf.c:30 0x7fe484b5b840: subq $216, %rsp 0x7fe484b5b847: testb %al, %al 0x7fe484b5b849: movq %rsi, 40(%rsp) 0x7fe484b5b84e: movq %rdx, 48(%rsp) 0x7fe484b5b853: movq %rcx, 56(%rsp) 0x7fe484b5b858: movq %r8, 64(%rsp) 0x7fe484b5b85d: movq %r9, 72(%rsp) 0x7fe484b5b862: je 0x7fe484b5b89b ; __printf + 91 at printf.c:34 libc.so.6__printf + 36 at printf.c:30
    0x7fe484b5b864: movaps %xmm0, 80(%rsp)
    0x7fe484b5b869: movaps %xmm1, 96(%rsp)
    0x7fe484b5b86e: movaps %xmm2, 112(%rsp)
    0x7fe484b5b873: movaps %xmm3, 128(%rsp)
    0x7fe484b5b87b: movaps %xmm4, 144(%rsp)
    0x7fe484b5b883: movaps %xmm5, 160(%rsp)
    0x7fe484b5b88b: movaps %xmm6, 176(%rsp)
    0x7fe484b5b893: movaps %xmm7, 192(%rsp)
    libc.so.6__printf + 91 at printf.c:34 0x7fe484b5b89b: leaq 224(%rsp), %rax libc.so.6__printf + 99 at printf.c:30
    → 0x7fe484b5b8a3: movq %rdi, %rsi
    libc.so.6__printf + 102 at printf.c:35 0x7fe484b5b8a6: leaq 8(%rsp), %rdx libc.so.6__printf + 107 at printf.c:34
    0x7fe484b5b8ab: movl $8, 8(%rsp)
    0x7fe484b5b8b3: movl $48, 12(%rsp)
    0x7fe484b5b8bb: movq %rax, 16(%rsp)
    0x7fe484b5b8c0: leaq 32(%rsp), %rax
    0x7fe484b5b8c5: movq %rax, 24(%rsp)
    libc.so.6__printf + 138 at printf.c:35 0x7fe484b5b8ca: movq 3556935(%rip), %rax 0x7fe484b5b8d1: movq (%rax), %rdi 0x7fe484b5b8d4: callq 0x7fe484b509c0 ; _IO_vfprintf_internal at vfprintf.c:211 libc.so.6__printf + 153 at printf.c:39
    0x7fe484b5b8d9: addq $216, %rsp
    0x7fe484b5b8e0: ret

This patch fixes the issue and I believe is similar to what DisplaySourceLinesWithLineNumbers() in SBSourceManager.cpp does.

Please let me know if this is ok to check in (or not…) Thanks.

mikesart@mikesart-rad:~/data/src/llvm.svn/llvm/tools/lldb$ svn diff source/Core/Disassembler.cpp
Index: source/Core/Disassembler.cpp

That is the correct fix. Looks good.