Browse Source

dump: Set correct vaddr for ELF dump

vaddr needs to be equal to the paddr since the dump file represents the
physical memory image.

Without setting vaddr correctly, GDB would load all the different memory
regions on top of each other to vaddr 0, thus making GDB showing the wrong
memory data for a given address.

Signed-off-by: Jon Doron <arilou@gmail.com>
Message-Id: <2019010908.27142-1-arilou@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
tags/v4.0.0-rc0
Jon Doron 5 months ago
parent
commit
e17bebd049
2 changed files with 4 additions and 2 deletions
  1. 3
    2
      dump.c
  2. 1
    0
      scripts/dump-guest-memory.py

+ 3
- 2
dump.c View File

@@ -192,7 +192,7 @@ static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
192 192
     phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
193 193
     phdr.p_filesz = cpu_to_dump64(s, filesz);
194 194
     phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
195
-    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
195
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr) ?: phdr.p_paddr;
196 196
 
197 197
     assert(memory_mapping->length >= filesz);
198 198
 
@@ -216,7 +216,8 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
216 216
     phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
217 217
     phdr.p_filesz = cpu_to_dump32(s, filesz);
218 218
     phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
219
-    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
219
+    phdr.p_vaddr =
220
+        cpu_to_dump32(s, memory_mapping->virt_addr) ?: phdr.p_paddr;
220 221
 
221 222
     assert(memory_mapping->length >= filesz);
222 223
 

+ 1
- 0
scripts/dump-guest-memory.py View File

@@ -163,6 +163,7 @@ class ELF(object):
163 163
         phdr = get_arch_phdr(self.endianness, self.elfclass)
164 164
         phdr.p_type = p_type
165 165
         phdr.p_paddr = p_paddr
166
+        phdr.p_vaddr = p_paddr
166 167
         phdr.p_filesz = p_size
167 168
         phdr.p_memsz = p_size
168 169
         self.segments.append(phdr)

Loading…
Cancel
Save