Changeset 32253 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Sep 6, 2010 3:14:24 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 65580
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/DBGFCoreWrite.cpp
r32248 r32253 57 57 #include <VBox/log.h> 58 58 #include <VBox/mm.h> 59 #include <VBox/version.h> 59 60 60 61 #include "../Runtime/include/internal/ldrELF64.h" … … 67 68 # define Log LogRel 68 69 #endif 69 #define DBGFLOG_NAME "D GBFCoreWrite"70 #define DBGFLOG_NAME "DBGFCoreWrite" 70 71 71 72 /* … … 74 75 static const int s_NoteAlign = 4; /* @todo see #5211 comment 3 */ 75 76 static const int s_cbNoteName = 16; 76 static const char *s_pcszCoreVBoxCpu = "VBOXCPU"; 77 static const char *s_pcszCoreVBoxCore = "VBOXCORE"; 78 static const char *s_pcszCoreVBoxCpu = "VBOXCPU"; 77 79 78 80 /** … … 83 85 const char *pszDumpPath; /* File path to dump the core into. */ 84 86 } DBGFCOREDATA, *PDBGFCOREDATA; 85 86 87 87 88 /** … … 307 308 uint16_t cProgHdrs = cMemRanges + 1; 308 309 309 /* 310 * Compute size of the note section. 311 */ 312 uint64_t cbNoteSection = pVM->cCpus * Elf64NoteSectionSize(s_pcszCoreVBoxCpu, sizeof(CPUMCTX)); 310 DBGFCOREDESCRIPTOR CoreDescriptor; 311 RT_ZERO(CoreDescriptor); 312 CoreDescriptor.u32Magic = DBGFCORE_MAGIC; 313 CoreDescriptor.VBoxVersion = VBOX_FULL_VERSION; 314 CoreDescriptor.VBoxRevision = VBOX_SVN_REV; 315 CoreDescriptor.cCpus = pVM->cCpus; 316 317 LogRel((DBGFLOG_NAME ":CoreDescriptor Version=%u Revision=%u\n", CoreDescriptor.VBoxVersion, CoreDescriptor.VBoxRevision)); 318 319 /* 320 * Compute total size of the note section. 321 */ 322 uint64_t cbNoteSection = Elf64NoteSectionSize(s_pcszCoreVBoxCore, sizeof(CoreDescriptor)) 323 + pVM->cCpus * Elf64NoteSectionSize(s_pcszCoreVBoxCpu, sizeof(CPUMCTX)); 313 324 uint64_t off = 0; 314 325 … … 318 329 RTFILE hFile = NIL_RTFILE; 319 330 int rc = RTFileOpen(&hFile, pDbgfData->pszDumpPath, RTFILE_O_CREATE_REPLACE | RTFILE_O_READWRITE); 320 if (RT_SUCCESS(rc)) 321 { 331 if (RT_FAILURE(rc)) 332 { 333 LogRel((DBGFLOG_NAME ":RTFileOpen failed for '%s' rc=%Rrc\n", pDbgfData->pszDumpPath, rc)); 334 return rc; 335 } 336 337 /* 338 * Write ELF header. 339 */ 340 uint64_t cbElfHdr = 0; 341 uint64_t cbProgHdr = 0; 342 rc = Elf64WriteElfHdr(hFile, cProgHdrs, 0 /* cSecHdrs */, &cbElfHdr); 343 off += cbElfHdr; 344 if (RT_FAILURE(rc)) 345 { 346 LogRel((DBGFLOG_NAME ":Elf64WriteElfHdr failed. rc=%Rrc\n", rc)); 347 goto CoreWriteDone; 348 } 349 350 /* 351 * Write PT_NOTE program header. 352 */ 353 rc = Elf64WriteProgHdr(hFile, PT_NOTE, PF_R, 354 cbElfHdr + cProgHdrs * sizeof(Elf64_Phdr), /* file offset to contents */ 355 cbNoteSection, /* size in core file */ 356 cbNoteSection, /* size in memory */ 357 0, /* physical address */ 358 &cbProgHdr); 359 Assert(cbProgHdr == sizeof(Elf64_Phdr)); 360 off += cbProgHdr; 361 362 if (RT_FAILURE(rc)) 363 { 364 LogRel((DBGFLOG_NAME ":Elf64WritreProgHdr failed for PT_NOTE. rc=%Rrc\n", rc)); 365 goto CoreWriteDone; 366 } 367 368 /* 369 * Write PT_LOAD program header for each memory range. 370 */ 371 uint64_t offMemRange = off + cbNoteSection; 372 for (uint16_t iRange = 0; iRange < cMemRanges; iRange++) 373 { 374 RTGCPHYS GCPhysStart; 375 RTGCPHYS GCPhysEnd; 376 377 bool fIsMmio; 378 rc = PGMR3PhysGetRange(pVM, iRange, &GCPhysStart, &GCPhysEnd, NULL /* pszDesc */, &fIsMmio); 379 if (RT_FAILURE(rc)) 380 { 381 LogRel((DBGFLOG_NAME ": PGMR3PhysGetRange failed for iRange(%u) rc=%Rrc\n", iRange, rc)); 382 goto CoreWriteDone; 383 } 384 385 uint64_t cbMemRange = GCPhysEnd - GCPhysStart + 1; 386 uint64_t cbFileRange = fIsMmio ? 0 : cbMemRange; 387 388 LogRel((DBGFLOG_NAME ": PGMR3PhysGetRange iRange=%u GCPhysStart=%#x GCPhysEnd=%#x cbMemRange=%u\n", 389 iRange, GCPhysStart, GCPhysEnd, cbMemRange)); 390 391 rc = Elf64WriteProgHdr(hFile, PT_LOAD, PF_R, 392 offMemRange, /* file offset to contents */ 393 cbFileRange, /* size in core file */ 394 cbMemRange, /* size in memory */ 395 GCPhysStart, /* physical address */ 396 &cbProgHdr); 397 Assert(cbProgHdr == sizeof(Elf64_Phdr)); 398 if (RT_FAILURE(rc)) 399 { 400 LogRel((DBGFLOG_NAME ":Elf64WriteProgHdr failed for memory range(%u) cbFileRange=%u cbMemRange=%u rc=%Rrc\n", iRange, 401 cbFileRange, cbMemRange, rc)); 402 goto CoreWriteDone; 403 } 404 405 offMemRange += cbFileRange; 406 } 407 408 /* 409 * Write the Core descriptor note header and data. 410 */ 411 rc = Elf64WriteNoteHdr(hFile, NT_VBOXCORE, s_pcszCoreVBoxCore, &CoreDescriptor, sizeof(CoreDescriptor), 412 NULL /* pcbNoteHdr */); 413 if (RT_FAILURE(rc)) 414 { 415 LogRel((DBGFLOG_NAME ":Elf64WriteNoteHdr failed for Note '%s' rc=%Rrc\n", s_pcszCoreVBoxCore, rc)); 416 goto CoreWriteDone; 417 } 418 419 /* 420 * Write the CPU context note headers and data. 421 */ 422 for (uint32_t iCpu = 0; iCpu < pVM->cCpus; iCpu++) 423 { 424 PCPUMCTX pCpuCtx = &pVM->aCpus[iCpu].cpum.s.Guest; 425 rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, s_pcszCoreVBoxCpu, pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */); 426 if (RT_FAILURE(rc)) 427 { 428 LogRel((DBGFLOG_NAME ":Elf64WriteNoteHdr failed for vCPU[%u] rc=%Rrc\n", iCpu, rc)); 429 goto CoreWriteDone; 430 } 431 } 432 433 /* 434 * Write memory ranges. 435 */ 436 for (uint16_t iRange = 0; iRange < cMemRanges; iRange++) 437 { 438 RTGCPHYS GCPhysStart; 439 RTGCPHYS GCPhysEnd; 440 bool fIsMmio; 441 rc = PGMR3PhysGetRange(pVM, iRange, &GCPhysStart, &GCPhysEnd, NULL /* pszDesc */, &fIsMmio); 442 if (RT_FAILURE(rc)) 443 { 444 LogRel((DBGFLOG_NAME ":PGMR3PhysGetRange(2) failed for iRange(%u) rc=%Rrc\n", iRange, rc)); 445 goto CoreWriteDone; 446 } 447 448 if (fIsMmio) 449 continue; 450 322 451 /* 323 * Write ELF header.452 * Write page-by-page of this memory range. 324 453 */ 325 uint64_t cbElfHdr = 0; 326 rc = Elf64WriteElfHdr(hFile, cProgHdrs, 0 /* cSecHdrs */, &cbElfHdr); 327 off += cbElfHdr; 328 if (RT_SUCCESS(rc)) 454 uint64_t cbMemRange = GCPhysEnd - GCPhysStart + 1; 455 uint64_t cPages = cbMemRange >> PAGE_SHIFT; 456 for (uint64_t iPage = 0; iPage < cPages; iPage++) 329 457 { 330 /* 331 * Write PT_NOTE program header. 332 */ 333 uint64_t cbProgHdr = 0; 334 rc = Elf64WriteProgHdr(hFile, PT_NOTE, PF_R, 335 cbElfHdr + cProgHdrs * sizeof(Elf64_Phdr), /* file offset to contents */ 336 cbNoteSection, /* size in core file */ 337 cbNoteSection, /* size in memory */ 338 0, /* physical address */ 339 &cbProgHdr); 340 Assert(cbProgHdr == sizeof(Elf64_Phdr)); 341 off += cbProgHdr; 342 if (RT_SUCCESS(rc)) 458 const int cbBuf = PAGE_SIZE; 459 void *pvBuf = MMR3HeapAlloc(pVM, MM_TAG_DBGF_CORE_WRITE, cbBuf); 460 if (RT_UNLIKELY(!pvBuf)) 461 { 462 LogRel((DBGFLOG_NAME ":MMR3HeapAlloc failed. iRange=%u iPage=%u\n", iRange, iPage)); 463 goto CoreWriteDone; 464 } 465 466 rc = PGMPhysRead(pVM, GCPhysStart, pvBuf, cbBuf); 467 if (RT_FAILURE(rc)) 343 468 { 344 469 /* 345 * Write PT_LOAD program header for each memory range.470 * For some reason this failed, write out a zero page instead. 346 471 */ 347 uint64_t offMemRange = off + cbNoteSection; 348 for (uint16_t iRange = 0; iRange < cMemRanges; iRange++) 349 { 350 RTGCPHYS GCPhysStart; 351 RTGCPHYS GCPhysEnd; 352 353 bool fIsMmio; 354 rc = PGMR3PhysGetRange(pVM, iRange, &GCPhysStart, &GCPhysEnd, NULL /* pszDesc */, &fIsMmio); 355 if (RT_FAILURE(rc)) 356 { 357 LogRel((DBGFLOG_NAME ": PGMR3PhysGetRange failed for iRange(%u) rc=%Rrc\n", iRange, rc)); 358 break; 359 } 360 361 uint64_t cbMemRange = GCPhysEnd - GCPhysStart + 1; 362 uint64_t cbFileRange = fIsMmio ? 0 : cbMemRange; 363 364 LogRel((DBGFLOG_NAME ": PGMR3PhysGetRange iRange=%u GCPhysStart=%#x GCPhysEnd=%#x cbMemRange=%u\n", 365 iRange, GCPhysStart, GCPhysEnd, cbMemRange)); 366 367 rc = Elf64WriteProgHdr(hFile, PT_LOAD, PF_R, 368 offMemRange, /* file offset to contents */ 369 cbFileRange, /* size in core file */ 370 cbMemRange, /* size in memory */ 371 GCPhysStart, /* physical address */ 372 &cbProgHdr); 373 Assert(cbProgHdr == sizeof(Elf64_Phdr)); 374 if (RT_FAILURE(rc)) 375 { 376 LogRel((DBGFLOG_NAME ":Elf64WriteProgHdr failed for memory range(%u) cbFileRange=%u cbMemRange=%u rc=%Rrc\n", iRange, 377 cbFileRange, cbMemRange, rc)); 378 break; 379 } 380 381 offMemRange += cbFileRange; 382 } 383 384 /* 385 * Write the CPU context note headers and data. 386 */ 387 if (RT_SUCCESS(rc)) 388 { 389 for (uint32_t iCpu = 0; iCpu < pVM->cCpus; iCpu++) 390 { 391 PCPUMCTX pCpuCtx = &pVM->aCpus[iCpu].cpum.s.Guest; 392 rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, s_pcszCoreVBoxCpu, pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */); 393 if (RT_FAILURE(rc)) 394 { 395 LogRel((DBGFLOG_NAME ":Elf64WriteNoteHdr failed for vCPU[%u] rc=%Rrc\n", iCpu, rc)); 396 break; 397 } 398 } 399 } 400 401 /* 402 * Write memory ranges. 403 */ 404 if (RT_SUCCESS(rc)) 405 { 406 for (uint16_t iRange = 0; iRange < cMemRanges; iRange++) 407 { 408 RTGCPHYS GCPhysStart; 409 RTGCPHYS GCPhysEnd; 410 bool fIsMmio; 411 rc = PGMR3PhysGetRange(pVM, iRange, &GCPhysStart, &GCPhysEnd, NULL /* pszDesc */, &fIsMmio); 412 if (RT_FAILURE(rc)) 413 { 414 LogRel((DBGFLOG_NAME ":PGMR3PhysGetRange(2) failed for iRange(%u) rc=%Rrc\n", iRange, rc)); 415 break; 416 } 417 418 if (fIsMmio) 419 continue; 420 421 /* 422 * Write page-by-page of this memory range. 423 */ 424 uint64_t cbMemRange = GCPhysEnd - GCPhysStart + 1; 425 uint64_t cPages = cbMemRange >> PAGE_SHIFT; 426 for (uint64_t iPage = 0; iPage < cPages; iPage++) 427 { 428 const int cbBuf = PAGE_SIZE; 429 void *pvBuf = MMR3HeapAlloc(pVM, MM_TAG_DBGF_CORE_WRITE, cbBuf); 430 if (RT_UNLIKELY(!pvBuf)) 431 { 432 LogRel((DBGFLOG_NAME ":MMR3HeapAlloc failed. iRange=%u iPage=%u\n", iRange, iPage)); 433 break; 434 } 435 436 rc = PGMPhysRead(pVM, GCPhysStart, pvBuf, cbBuf); 437 if (RT_FAILURE(rc)) 438 { 439 /* 440 * For some reason this failed, write out a zero page instead. 441 */ 442 LogRel((DBGFLOG_NAME ":PGMPhysRead failed for iRange=%u iPage=%u. rc=%Rrc. Ignoring...\n", iRange, 443 iPage, rc)); 444 memset(pvBuf, 0, cbBuf); 445 } 446 447 rc = RTFileWrite(hFile, pvBuf, cbBuf, NULL /* all */); 448 if (RT_FAILURE(rc)) 449 { 450 LogRel((DBGFLOG_NAME ":RTFileWrite failed. iRange=%u iPage=%u rc=%Rrc\n", iRange, iPage, rc)); 451 MMR3HeapFree(pvBuf); 452 break; 453 } 454 455 MMR3HeapFree(pvBuf); 456 } 457 458 if (RT_FAILURE(rc)) 459 break; 460 } 461 } 472 LogRel((DBGFLOG_NAME ":PGMPhysRead failed for iRange=%u iPage=%u. rc=%Rrc. Ignoring...\n", iRange, 473 iPage, rc)); 474 memset(pvBuf, 0, cbBuf); 462 475 } 463 476 477 rc = RTFileWrite(hFile, pvBuf, cbBuf, NULL /* all */); 478 if (RT_FAILURE(rc)) 479 { 480 LogRel((DBGFLOG_NAME ":RTFileWrite failed. iRange=%u iPage=%u rc=%Rrc\n", iRange, iPage, rc)); 481 MMR3HeapFree(pvBuf); 482 goto CoreWriteDone; 483 } 484 485 MMR3HeapFree(pvBuf); 464 486 } 465 466 RTFileClose(hFile); 467 } 487 } 488 489 CoreWriteDone: 490 RTFileClose(hFile); 468 491 469 492 return rc; -
trunk/src/VBox/VMM/DBGFInternal.h
r30072 r32253 311 311 312 312 313 /** DBGCORECOREDESCRIPTOR::u32Magic. */ 314 #define DBGFCORE_MAGIC 0xc01ac0de 315 316 /** 317 * The DBGF Core descriptor. 318 */ 319 typedef struct DBGFCOREDESCRIPTOR 320 { 321 /** The core file magic (DBGFCORE_MAGIC) */ 322 uint32_t u32Magic; 323 /** VirtualBox version. */ 324 uint64_t VBoxVersion; 325 /** VirtualBox revision. */ 326 uint64_t VBoxRevision; 327 /** Number of CPUs. */ 328 uint32_t cCpus; 329 } DBGFCOREDESCRIPTOR; 330 /** Pointer to DBGFCOREDESCRIPTOR data. */ 331 typedef DBGFCOREDESCRIPTOR *PDBGFCOREDESCRIPTOR; 332 333 313 334 int dbgfR3AsInit(PVM pVM); 314 335 void dbgfR3AsTerm(PVM pVM); -
trunk/src/VBox/VMM/Makefile.kmk
r32006 r32253 49 49 VMMR3_TEMPLATE = VBoxR3Dll 50 50 51 VMMR3_DEFS = IN_VMM_R3 IN_DIS IN_GMM_R3 IN_DBG $(VMM_COMMON_DEFS) 51 VMMR3_DEFS = IN_VMM_R3 IN_DIS IN_GMM_R3 IN_DBG $(VMM_COMMON_DEFS) VBOX_SVN_REV=$(VBOX_SVN_REV) 52 52 ## @todo eliminate IN_GMM_R3 53 53 ifdef VBOX_WITH_PREALLOC_RAM_BY_DEFAULT
Note:
See TracChangeset
for help on using the changeset viewer.