- Timestamp:
- Aug 27, 2010 12:48:09 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/DBGFCoreWrite.cpp
r32006 r32050 22 22 #define LOG_GROUP LOG_GROUP_DBGF 23 23 #include <iprt/param.h> 24 #include <iprt/file.h> 24 25 #include <VBox/dbgf.h> 25 26 #include "DBGFInternal.h" … … 28 29 #include <VBox/log.h> 29 30 31 #include "../Runtime/include/internal/ldrELF64.h" 32 33 /* 34 * VBox VMCore Format: 35 * [ ELF 64 Header] -- Only 1 36 * 37 * [ PT_NOTE ] -- Only 1 38 * - Offset into list of Notes (Note Hdr + data) of VBox CPUs. 39 * - (Any Additional custom Note sections) 40 * 41 * [ PT_LOAD ] -- One for each contiguous memory chunk 42 * - Memory offset 43 * - File offset 44 * 45 * Per-CPU register dump 46 * - CPU 1 Note Hdr + Data 47 * - CPU 2 Note Hdr + Data 48 * ... 49 * (Additional custom notes Hdr+data) 50 * - VBox 1 Note Hdr + Data 51 * - VBox 2 Note Hdr + Data 52 * ... 53 * Memory dump 54 * 55 */ 56 57 /** 58 * ELF function to write 64-bit ELF header. 59 * 60 * @param hFile The file to write to. 61 * @param cProgHdrs Number of program headers. 62 * @param cSecHdrs Number of section headers. 63 * @param pcbElfHdr Where to store the size of written header to file, 64 * can be NULL. 65 * 66 * @return IPRT status code. 67 */ 68 static int Elf64WriteElfHdr(RTFILE hFile, uint16_t cProgHdrs, uint16_t cSecHdrs, size_t *pcbElfHdr) 69 { 70 Elf64_Ehdr ElfHdr; 71 RT_ZERO(ElfHdr); 72 ElfHdr.e_ident[EI_MAG0] = ELFMAG0; 73 ElfHdr.e_ident[EI_MAG1] = ELFMAG1; 74 ElfHdr.e_ident[EI_MAG2] = ELFMAG2; 75 ElfHdr.e_ident[EI_MAG3] = ELFMAG3; 76 ElfHdr.e_ident[EI_DATA] = ELFDATA2LSB; 77 ElfHdr.e_type = ET_CORE; 78 ElfHdr.e_version = EV_CURRENT; 79 ElfHdr.e_ident[EI_CLASS] = ELFCLASS64; 80 /* 32-bit VMs will produce cores with e_machine EM_386. */ 81 #ifdef RT_ARCH_AMD64 82 ElfHdr.e_machine = EM_X86_64; 83 #else 84 ElfHdr.e_machine = EM_386; 85 #endif 86 ElfHdr.e_phnum = cProgHdrs; 87 ElfHdr.e_shnum = cSecHdrs; 88 ElfHdr.e_ehsize = sizeof(ElfHdr); 89 ElfHdr.e_phoff = sizeof(ElfHdr); 90 ElfHdr.e_phentsize = sizeof(Elf64_Phdr); 91 ElfHdr.e_shentsize = sizeof(Elf64_Shdr); 92 93 int rc = RTFileWrite(hFile, &ElfHdr, sizeof(ElfHdr), NULL /* full write */); 94 if (RT_SUCCESS(rc) && pcbElfHdr) 95 *pcbElfHdr = sizeof(ElfHdr); 96 return rc; 97 } 98 99 100 /** 101 * ELF function to write 64-bit program header. 102 * 103 * @param hFile The file to write to. 104 * @param Type Type of program header (PT_*). 105 * @param fFlags Flags (access permissions). 106 * @param offFileData File offset of contents. 107 * @param cbFileData Size of contents in the file. 108 * @param cbMemData Size of contents in memory. 109 * @param pcbProgHdr Where to store the size of written header to file, 110 * can be NULL. 111 * 112 * @return IPRT status code. 113 */ 114 static int Elf64WriteProgHdr(RTFILE hFile, uint32_t Type, uint32_t fFlags, RTFOFF offFileData, size_t cbFileData, size_t cbMemData, 115 size_t *pcbProgHdr) 116 { 117 Elf64_Phdr ProgHdr; 118 RT_ZERO(ProgHdr); 119 ProgHdr.p_type = Type; 120 ProgHdr.p_flags = fFlags; 121 ProgHdr.p_offset = offFileData; 122 ProgHdr.p_filesz = cbFileData; 123 ProgHdr.p_memsz = cbMemData; 124 125 int rc = RTFileWrite(hFile, &ProgHdr, sizeof(ProgHdr), NULL /* full write */); 126 if (RT_SUCCESS(rc) && pcbProgHdr) 127 *pcbProgHdr = sizeof(ProgHdr); 128 return rc; 129 } 130 131 132 /** 133 * Count the number of memory blobs that go into the core file. 134 * 135 * We cannot do a page-by-page dump of the entire guest memory as there will be 136 * way too many entries. Also we don't want to dump MMIO regions which means we 137 * cannot have a 1:1 mapping between core file offset and memory offset. Instead 138 * we dump the memory in blobs. A memory blob is a contiguous memory area 139 * suitable for dumping to a core file. 140 * 141 * @param pVM The VM handle. 142 * @oaram idCpu The target CPU ID. 143 * 144 * @return Number of memory blobs. 145 */ 146 static int dbgfR3CountMemoryBlobs(PVM pVM, VMCPUID idCpu) 147 { 148 /* @todo */ 149 return 0; 150 } 151 30 152 31 153 /** … … 46 168 AssertReturn(pszDumpPath, VERR_INVALID_POINTER); 47 169 48 /* @todo */ 49 50 return VINF_SUCCESS; 170 /* 171 * Halt the VM if it is not already halted. 172 */ 173 int rc = VINF_SUCCESS; 174 if (!DBGFR3IsHalted(pVM)) 175 { 176 rc = DBGFR3Halt(pVM); 177 if (RT_FAILURE(rc)) 178 return rc; 179 } 180 181 /* 182 * Collect core information. 183 */ 184 uint16_t cMemBlobs = dbgfR3CountMemoryBlobs(pVM, idCpu); 185 uint16_t cProgHdrs = cMemBlobs + 1; /* One PT_NOTE Program header */ 186 187 /* 188 * Write the core file. 189 */ 190 RTFILE hFile = NIL_RTFILE; 191 rc = RTFileOpen(&hFile, pszDumpPath, RTFILE_O_CREATE | RTFILE_O_READWRITE); 192 if (RT_SUCCESS(rc)) 193 { 194 size_t cbElfHdr = 0; 195 rc = Elf64WriteElfHdr(hFile, 0, 0 /* cSecHdrs */, &cbElfHdr); 196 if (RT_SUCCESS(rc)) 197 { 198 199 } 200 201 RTFileClose(hFile); 202 } 203 204 /* 205 * Resume the VM. 206 */ 207 DBGFR3Resume(pVM); 208 209 return rc; 51 210 } 52 211
Note:
See TracChangeset
for help on using the changeset viewer.