[lldb-dev] Debugging ELF relocatable files using LLDB

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Thu Feb 16 08:56:58 PST 2017


> On Feb 16, 2017, at 3:51 AM, Ramana via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> It looks like LLDB doesn't like ELF relocatable files for debugging
> and asserts with the following message when tried
> 
>     <path to>/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2228:
> unsigned int ObjectFileELF::RelocateSection(.....):  Assertion `false
> && "unexpected relocation type"' failed.
> 
> Are we not supposed to debug ELF relocatable files on LLDB or am I
> missing something?
> 
> If we cannot debug the relocatable files, is it _simply_ because those
> files lack program headers (program memory map) and relocations are
> yet to be processed (for debug info) or there are other reasons?
> 
> For our target, the assembler output itself is a self contained ELF
> and hence will not have external references (both code and data). I am
> wondering if I can debug these ELF files on LLDB with minimal changes
> which does not require a full (or proper) linking step and would
> appreciate any pointers on that.
> 
> Thanks,
> Ramana

Looks like you just need to add support for the 32 bit relocations:


    if (hdr->Is32Bit()) {
      switch (reloc_type(rel)) {
      case R_386_32:
      case R_386_PC32:
      default:
        assert(false && "unexpected relocation type");
      }
    } else {
      switch (reloc_type(rel)) {
      case R_X86_64_64: {
        symbol = symtab->FindSymbolByID(reloc_symbol(rel));
        if (symbol) {
          addr_t value = symbol->GetAddressRef().GetFileAddress();
          DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
          uint64_t *dst = reinterpret_cast<uint64_t *>(
              data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
              ELFRelocation::RelocOffset64(rel));
          *dst = value + ELFRelocation::RelocAddend64(rel);
        }
        break;
      }
      case R_X86_64_32:
      case R_X86_64_32S: {
        symbol = symtab->FindSymbolByID(reloc_symbol(rel));
        if (symbol) {
          addr_t value = symbol->GetAddressRef().GetFileAddress();
          value += ELFRelocation::RelocAddend32(rel);
          assert(
              (reloc_type(rel) == R_X86_64_32 && (value <= UINT32_MAX)) ||
              (reloc_type(rel) == R_X86_64_32S &&
               ((int64_t)value <= INT32_MAX && (int64_t)value >= INT32_MIN)));
          uint32_t truncated_addr = (value & 0xFFFFFFFF);
          DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
          uint32_t *dst = reinterpret_cast<uint32_t *>(
              data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
              ELFRelocation::RelocOffset32(rel));
          *dst = truncated_addr;
        }
        break;
      }
      case R_X86_64_PC32:
      default:
        assert(false && "unexpected relocation type");
      }
    }


I am guessing you will do something similar to the x86-64 stuff.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20170216/c94730cf/attachment.html>


More information about the lldb-dev mailing list