llvm-project/lldb/lit/Breakpoint/Inputs
Stefan Granitz f0ee69f75d [JITLoaderGDB] Set eTypeJIT for objects read from JIT descriptors
Summary:
First part of a fix for JITed code debugging. This has been a regression from 5.0 to 6.0 and it's is still reproducible on current master: https://bugs.llvm.org/show_bug.cgi?id=36209

The address of the breakpoint site is corrupt: the 0x4 value we end up with, looks like an offset on a zero base address. When we parse the ELF section headers from the JIT descriptor, the load address for the text section we find in `header.sh_addr` is correct.

The bug manifests in `VMAddressProvider::GetVMRange(const ELFSectionHeader &)` (follow it from `ObjectFileELF::CreateSections()`). Here we think the object type was `eTypeObjectFile` and unleash some extra logic [1] which essentially overwrites the address with a zero value.

The object type is deduced from the ELF header's `e_type` in `ObjectFileELF::CalculateType()`. It never returns `eTypeJIT`, because the ELF header has no representation for it [2]. Instead the in-memory ELF object states `ET_REL`, which leads to `eTypeObjectFile`. This is what we get from `lli` at least since 3.x. (Might it be better to write `ET_EXEC` on the JIT side instead? In fact, relocations were already applied at this point, so "Relocatable" is not quite exact.)

So, this patch proposes to set `eTypeJIT` explicitly whenever we read from a JIT descriptor. In `ObjectFileELF::CreateSections()` we can then call `GetType()`, which returns the explicit value or otherwise falls back to `CalculateType()`.

LLDB then sets the breakpoint successfully. Next step: debug info.
```
Process 1056 stopped
* thread #1, name = 'lli', stop reason = breakpoint 1.2
    frame #0: 0x00007ffff7ff7000 JIT(0x3ba2030)`jitbp()
JIT(0x3ba2030)`jitbp:
->  0x7ffff7ff7000 <+0>:  pushq  %rbp
    0x7ffff7ff7001 <+1>:  movq   %rsp, %rbp
    0x7ffff7ff7004 <+4>:  movabsq $0x7ffff7ff6000, %rdi     ; imm = 0x7FFFF7FF6000
    0x7ffff7ff700e <+14>: movabsq $0x7ffff6697e80, %rcx     ; imm = 0x7FFFF6697E80
```

[1] It was first introduced with https://reviews.llvm.org/D38142#change-lF6csxV8HdlL, which has also been the original breaking change. The code has changed a lot since then.

[2] ELF object types: https://github.com/llvm/llvm-project/blob/2d2277f5/llvm/include/llvm/BinaryFormat/ELF.h#L110

Reviewers: labath, JDevlieghere, bkoropoff, clayborg, espindola, alexshap, stella.stamenova

Reviewed By: labath, clayborg

Subscribers: probinson, emaste, aprantl, arichardson, MaskRay, AlexDenisov, yurydelendik, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D61611

llvm-svn: 360354
2019-05-09 16:40:57 +00:00
..
case-sensitive.c
debug_addrx.yaml [LLDB] - Add support for DW_FORM_addrx[1-4]? forms. 2018-10-31 10:14:03 +00:00
debug_rnglist_basic.yaml [LLDB] - Add basic support for .debug_rnglists section (DWARF5) 2018-10-10 08:11:15 +00:00
debug_rnglist_offset_pair.yaml Recommit r345127 "[LLDB] - Add support for DW_RLE_base_address and DW_RLE_offset_pair entries (.debug_rnglists)" 2018-10-25 10:25:45 +00:00
debug_rnglist_rlestartend.yaml [LLDB] - Add support for DW_RLE_start_end entries (.debug_rnglists) 2018-10-17 07:37:26 +00:00
debug_rnglistx_rlex.yaml [LLDB] - Add support for DW_FORM_rnglistx and relative DW_RLE_* entries. 2018-11-02 09:03:25 +00:00
implicit_const_form_support.yaml [LLDB] - Add support for DW_FORM_implicit_const. 2018-10-12 09:46:15 +00:00
jitbp.cpp [JITLoaderGDB] Set eTypeJIT for objects read from JIT descriptors 2019-05-09 16:40:57 +00:00
ppc64-localentry.s
single-file-split-dwarf.o.yaml [LLDB] - Recommit r346848 "[LLDB] - Support the single file split DWARF.". 2018-11-14 13:01:15 +00:00
single-file-split-dwarf.yaml [LLDB] - Recommit r346848 "[LLDB] - Support the single file split DWARF.". 2018-11-14 13:01:15 +00:00
split-dwarf-5-addrbase.dwo.yaml [LLDB] - Update the test cases after yaml2obj change. 2019-04-03 15:28:35 +00:00
split-dwarf-5-addrbase.yaml [LLDB] - Fix setting the breakpoints when -gsplit-dwarf and DWARF 5 were used for building the executable. 2018-11-29 08:16:07 +00:00
split-dwarf5-debug-stroffsets-file1.dwo.yaml [LLDB] - Update the test cases after yaml2obj change. 2019-04-03 15:28:35 +00:00
split-dwarf5-debug-stroffsets-file2.dwo.yaml [LLDB] - Update the test cases after yaml2obj change. 2019-04-03 15:28:35 +00:00
split-dwarf5-debug-stroffsets-main.yaml [LLDB] - Improve the support of .debug_str_offsets/.debug_str_offsets.dwo 2018-11-29 12:44:10 +00:00