This patch tries to improve memory-read from core files (in order to improve disassembly functionality).
I am using RHEL 7.7 (linux kernel 3.10) and for a lot of cases, I was not able to disassemble some functions from backtrace when debugging crashes from core files. It outputs some dummy code as following:
(lldb) disassemble example`fn: 0x55deb51866b0 <+0>: addb %al, (%rax) 0x55deb51866b2 <+2>: addb %al, (%rax) 0x55deb51866b4 <+4>: addb %al, (%rax) 0x55deb51866b6 <+6>: addb %al, (%rax) ....
The cause of the problem was the fact we are returning all the zeros from ProcessElfCore::ReadMemory() that is being called within Disassembler::ParseInstructions() and it disassembles some dummy opcodes from the buffer returned. If we are about to fill the buffer with all zeros, I guess it is safe to just return zero, and to proceed with reading from file itself. Therefore, we are removing zero bytes filling (padding) completely.
Before this patch (simple example that has been attached into the test):
$ lldb lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64-for-disassemble.out -c lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64-for-disassemble.core (lldb) f 4 frame #4: 0x00007f1d2f862545 libc.so.6`__libc_start_main + 245 libc.so.6`__libc_start_main: -> 0x7f1d2f862545 <+245>: addb %al, (%rax) 0x7f1d2f862547 <+247>: addb %al, (%rax) 0x7f1d2f862549 <+249>: addb %al, (%rax) 0x7f1d2f86254b <+251>: addb %al, (%rax)
After this patch applied:
(lldb) f 4 frame #4: 0x00007f1d2f862545 libc.so.6`__libc_start_main + 245 libc.so.6`__libc_start_main: -> 0x7f1d2f862545 <+245>: movl %eax, %edi 0x7f1d2f862547 <+247>: callq 0x39d10 ; exit 0x7f1d2f86254c <+252>: xorl %edx, %edx 0x7f1d2f86254e <+254>: jmp 0x22489 ; <+57>
GDB was able to disassemble all the functions from core file.