- Timestamp:
- Sep 13, 2020 8:15:53 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCCommands.cpp
r86098 r86100 32 32 #include <iprt/ctype.h> 33 33 #include <iprt/dir.h> 34 #include <iprt/file.h> 34 35 #include <iprt/env.h> 35 36 #include <iprt/ldr.h> … … 77 78 static FNDBGCCMD dbgcCmdRunScript; 78 79 static FNDBGCCMD dbgcCmdWriteCore; 80 static FNDBGCCMD dbgcCmdWriteGstMem; 79 81 80 82 … … 261 263 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */ 262 264 { 1, 1, DBGCVAR_CAT_STRING, 0, "path", "Filename string." }, 265 }; 266 267 /** writegstmem arguments. */ 268 static const DBGCVARDESC g_aArgWriteGstMem[] = 269 { 270 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */ 271 { 1, 1, DBGCVAR_CAT_STRING, 0, "filename", "Filename string." }, 272 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "The guest address." } 263 273 }; 264 274 … … 310 320 { "unset", 1, ~0U, &g_aArgUnset[0], RT_ELEMENTS(g_aArgUnset), 0, dbgcCmdUnset, "<var1> [var1..[varN]]", "Unsets (delete) one or more global variables." }, 311 321 { "writecore", 1, 1, &g_aArgWriteCore[0], RT_ELEMENTS(g_aArgWriteCore), 0, dbgcCmdWriteCore, "<filename>", "Write core to file." }, 322 { "writegstmem", 2, 2, &g_aArgWriteGstMem[0], RT_ELEMENTS(g_aArgWriteGstMem), 0, dbgcCmdWriteGstMem, "<filename> <address>", "Load data from the given file and write it to guest memory at the given start address." }, 312 323 }; 313 324 /** The number of native commands. */ … … 1939 1950 } 1940 1951 1952 1953 /** 1954 * @callback_method_impl{FNDBGCCMD, The 'writegstmem' command.} 1955 */ 1956 static DECLCALLBACK(int) dbgcCmdWriteGstMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs) 1957 { 1958 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp); 1959 LogFunc(("\n")); 1960 1961 /* 1962 * Validate the parsing and make sense of the input. 1963 * This is a mess as usual because we don't trust the parser yet. 1964 */ 1965 AssertReturn( cArgs == 2 1966 && paArgs[0].enmType == DBGCVAR_TYPE_STRING 1967 && DBGCVAR_ISPOINTER(paArgs[1].enmType), 1968 VERR_DBGC_PARSE_INCORRECT_ARG_TYPE); 1969 1970 const char *pszFile = paArgs[0].u.pszString; 1971 if (!pszFile) 1972 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Missing file path.\n"); 1973 1974 DBGFADDRESS LoadAddress; 1975 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[1], &LoadAddress); 1976 if (RT_FAILURE(rc)) 1977 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "pfnVarToDbgfAddr: %Dv\n", &paArgs[1]); 1978 1979 RTFILE hFile = NIL_RTFILE; 1980 rc = RTFileOpen(&hFile, pszFile, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 1981 if (RT_SUCCESS(rc)) 1982 { 1983 uint64_t cbFile; 1984 rc = RTFileQuerySize(hFile, &cbFile); 1985 if (RT_SUCCESS(rc)) 1986 { 1987 void *pvBuf = RTMemTmpAlloc(_16K); 1988 if (RT_LIKELY(pvBuf)) 1989 { 1990 size_t cbLeft = cbFile; 1991 1992 while ( cbLeft 1993 && RT_SUCCESS(rc)) 1994 { 1995 uint64_t cbThisCopy = RT_MIN(cbFile, _16K); 1996 1997 rc = RTFileRead(hFile, pvBuf, cbThisCopy, NULL /*pcbRead*/); 1998 if (RT_SUCCESS(rc)) 1999 { 2000 rc = DBGFR3MemWrite(pUVM, pDbgc->idCpu, &LoadAddress, pvBuf, cbThisCopy); 2001 if (RT_SUCCESS(rc)) 2002 DBGFR3AddrAdd(&LoadAddress, cbThisCopy); 2003 else 2004 { 2005 DBGCVAR VarCur; 2006 rc = DBGCCmdHlpVarFromDbgfAddr(pCmdHlp, &LoadAddress, &VarCur); 2007 if (RT_SUCCESS(rc)) 2008 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3MemWrite(,,%DV,,%RX64) failed. rc=%Rrc\n", &VarCur, cbThisCopy, rc); 2009 else 2010 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGCCmdHlpVarFromDbgfAddr\n"); 2011 } 2012 } 2013 else 2014 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "RTFileRead() failed. rc=%Rrc\n", rc); 2015 2016 cbLeft -= cbThisCopy; 2017 } 2018 2019 if (RT_SUCCESS(rc)) 2020 DBGCCmdHlpPrintf(pCmdHlp, "Wrote 0x%RX64 (%RU64) bytes to %Dv\n", cbFile, cbFile, &paArgs[1]); 2021 2022 RTMemTmpFree(pvBuf); 2023 } 2024 else 2025 { 2026 rc = VERR_NO_MEMORY; 2027 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "RTMemTmpAlloc() failed. rc=%Rrc\n", rc); 2028 } 2029 } 2030 else 2031 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "RTFileQuerySize() failed. rc=%Rrc\n", rc); 2032 2033 RTFileClose(hFile); 2034 } 2035 else 2036 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "RTFileOpen(,%s,) failed. rc=%Rrc\n", pszFile, rc); 2037 2038 return rc; 2039 } 2040
Note:
See TracChangeset
for help on using the changeset viewer.