Changeset 5685 in vbox
- Timestamp:
- Nov 11, 2007 11:11:40 AM (17 years ago)
- Location:
- trunk/src/VBox/Debugger
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/DBGCInternal.h
r5676 r5685 328 328 * Internal Functions * 329 329 *******************************************************************************/ 330 int dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags); 331 int dbgcRun(PDBGC pDbgc); 332 void dbgcDestroy(PDBGC pDbgc); 333 330 334 int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd); 331 335 int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd); -
trunk/src/VBox/Debugger/DBGConsole.cpp
r5679 r5685 1820 1820 1821 1821 /** 1822 * Make a console instance. 1823 * 1824 * This will not return until either an 'exit' command is issued or a error code 1825 * indicating connection loss is encountered. 1826 * 1827 * @returns VINF_SUCCESS if console termination caused by the 'exit' command. 1828 * @returns The VBox status code causing the console termination. 1829 * 1830 * @param pVM VM Handle. 1831 * @param pBack Pointer to the backend structure. This must contain 1832 * a full set of function pointers to service the console. 1833 * @param fFlags Reserved, must be zero. 1834 * @remark A forced termination of the console is easiest done by forcing the 1835 * callbacks to return fatal failures. 1836 */ 1837 DBGDECL(int) DBGCCreate(PVM pVM, PDBGCBACK pBack, unsigned fFlags) 1822 * Run the debugger console. 1823 * 1824 * @returns VBox status. 1825 * @param pDbgc Pointer to the debugger console instance data. 1826 */ 1827 int dbgcRun(PDBGC pDbgc) 1828 { 1829 /* 1830 * Main Debugger Loop. 1831 * 1832 * This loop will either block on waiting for input or on waiting on 1833 * debug events. If we're forwarding the log we cannot wait for long 1834 * before we must flush the log. 1835 */ 1836 int rc = VINF_SUCCESS; 1837 for (;;) 1838 { 1839 if (pDbgc->pVM && DBGFR3CanWait(pDbgc->pVM)) 1840 { 1841 /* 1842 * Wait for a debug event. 1843 */ 1844 PCDBGFEVENT pEvent; 1845 rc = DBGFR3EventWait(pDbgc->pVM, pDbgc->fLog ? 1 : 32, &pEvent); 1846 if (VBOX_SUCCESS(rc)) 1847 { 1848 rc = dbgcProcessEvent(pDbgc, pEvent); 1849 if (VBOX_FAILURE(rc)) 1850 break; 1851 } 1852 else if (rc != VERR_TIMEOUT) 1853 break; 1854 1855 /* 1856 * Check for input. 1857 */ 1858 if (pDbgc->pBack->pfnInput(pDbgc->pBack, 0)) 1859 { 1860 rc = dbgcProcessInput(pDbgc); 1861 if (VBOX_FAILURE(rc)) 1862 break; 1863 } 1864 } 1865 else 1866 { 1867 /* 1868 * Wait for input. If Logging is enabled we'll only wait very briefly. 1869 */ 1870 if (pDbgc->pBack->pfnInput(pDbgc->pBack, pDbgc->fLog ? 1 : 1000)) 1871 { 1872 rc = dbgcProcessInput(pDbgc); 1873 if (VBOX_FAILURE(rc)) 1874 break; 1875 } 1876 } 1877 1878 /* 1879 * Forward log output. 1880 */ 1881 if (pDbgc->fLog) 1882 { 1883 rc = dbgcProcessLog(pDbgc); 1884 if (VBOX_FAILURE(rc)) 1885 break; 1886 } 1887 } 1888 1889 return rc; 1890 } 1891 1892 1893 /** 1894 * Creates a a new instance. 1895 * 1896 * @returns VBox status code. 1897 * @param ppDbgc Where to store the pointer to the instance data. 1898 * @param pBack Pointer to the backend. 1899 * @param fFlags The flags. 1900 */ 1901 int dbgcCreate(PDBGC *ppDbgc, PDBGCBACK pBack, unsigned fFlags) 1838 1902 { 1839 1903 /* 1840 1904 * Validate input. 1841 1905 */ 1842 AssertReturn(VALID_PTR(pVM), VERR_INVALID_PARAMETER); 1843 AssertReturn(VALID_PTR(pBack), VERR_INVALID_PARAMETER); 1906 AssertPtrReturn(pBack, VERR_INVALID_POINTER); 1844 1907 AssertMsgReturn(!fFlags, ("%#x", fFlags), VERR_INVALID_PARAMETER); 1845 1908 1846 1909 /* 1847 * Allocate and initialize instance data1848 */ 1849 PDBGC 1910 * Allocate and initialize. 1911 */ 1912 PDBGC pDbgc = (PDBGC)RTMemAllocZ(sizeof(*pDbgc)); 1850 1913 if (!pDbgc) 1851 1914 return VERR_NO_MEMORY; … … 1879 1942 dbgcInitOpCharBitMap(); 1880 1943 1881 /* 1882 * Print welcome message. 1883 */ 1884 int rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, 1885 "Welcome to the VirtualBox Debugger!\n"); 1886 if (VBOX_FAILURE(rc)) 1887 goto l_failure; 1888 1889 /* 1890 * Attach to the VM. 1891 */ 1892 rc = DBGFR3Attach(pVM); 1893 if (VBOX_FAILURE(rc)) 1894 { 1895 rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to attach to VM %p\n", pDbgc->pVM); 1896 goto l_failure; 1897 } 1898 pDbgc->pVM = pVM; 1899 1900 /* 1901 * Print commandline and auto select result. 1902 */ 1903 rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, 1904 "Current VM is %08x\n" /** @todo get and print the VM name! */ 1905 "VBoxDbg> ", 1906 pDbgc->pVM); 1907 if (VBOX_FAILURE(rc)) 1908 goto l_failure; 1909 1910 /* 1911 * Main Debugger Loop. 1912 * 1913 * This loop will either block on waiting for input or on waiting on 1914 * debug events. If we're forwarding the log we cannot wait for long 1915 * before we must flush the log. 1916 */ 1917 for (rc = 0;;) 1918 { 1919 if (pDbgc->pVM && DBGFR3CanWait(pDbgc->pVM)) 1920 { 1921 /* 1922 * Wait for a debug event. 1923 */ 1924 PCDBGFEVENT pEvent; 1925 rc = DBGFR3EventWait(pDbgc->pVM, pDbgc->fLog ? 1 : 32, &pEvent); 1926 if (VBOX_SUCCESS(rc)) 1927 { 1928 rc = dbgcProcessEvent(pDbgc, pEvent); 1929 if (VBOX_FAILURE(rc)) 1930 break; 1931 } 1932 else if (rc != VERR_TIMEOUT) 1933 break; 1934 1935 /* 1936 * Check for input. 1937 */ 1938 if (pBack->pfnInput(pDbgc->pBack, 0)) 1939 { 1940 rc = dbgcProcessInput(pDbgc); 1941 if (VBOX_FAILURE(rc)) 1942 break; 1943 } 1944 } 1945 else 1946 { 1947 /* 1948 * Wait for input. If Logging is enabled we'll only wait very briefly. 1949 */ 1950 if (pBack->pfnInput(pDbgc->pBack, pDbgc->fLog ? 1 : 1000)) 1951 { 1952 rc = dbgcProcessInput(pDbgc); 1953 if (VBOX_FAILURE(rc)) 1954 break; 1955 } 1956 } 1957 1958 /* 1959 * Forward log output. 1960 */ 1961 if (pDbgc->fLog) 1962 { 1963 rc = dbgcProcessLog(pDbgc); 1964 if (VBOX_FAILURE(rc)) 1965 break; 1966 } 1967 } 1968 1969 1970 l_failure: 1971 /* 1972 * Cleanup console debugger session. 1973 */ 1944 *ppDbgc = pDbgc; 1945 return VINF_SUCCESS; 1946 } 1947 1948 /** 1949 * Destroys a DBGC instance created by dbgcCreate. 1950 * 1951 * @param pDbgc Pointer to the debugger console instance data. 1952 */ 1953 void dbgcDestroy(PDBGC pDbgc) 1954 { 1955 AssertPtr(pDbgc); 1956 1974 1957 /* Disable log hook. */ 1975 1958 if (pDbgc->fLog) … … 1984 1967 /* finally, free the instance memory. */ 1985 1968 RTMemFree(pDbgc); 1986 1969 } 1970 1971 1972 /** 1973 * Make a console instance. 1974 * 1975 * This will not return until either an 'exit' command is issued or a error code 1976 * indicating connection loss is encountered. 1977 * 1978 * @returns VINF_SUCCESS if console termination caused by the 'exit' command. 1979 * @returns The VBox status code causing the console termination. 1980 * 1981 * @param pVM VM Handle. 1982 * @param pBack Pointer to the backend structure. This must contain 1983 * a full set of function pointers to service the console. 1984 * @param fFlags Reserved, must be zero. 1985 * @remark A forced termination of the console is easiest done by forcing the 1986 * callbacks to return fatal failures. 1987 */ 1988 DBGDECL(int) DBGCCreate(PVM pVM, PDBGCBACK pBack, unsigned fFlags) 1989 { 1990 /* 1991 * Validate input. 1992 */ 1993 AssertPtrNullReturn(pVM, VERR_INVALID_POINTER); 1994 1995 /* 1996 * Allocate and initialize instance data 1997 */ 1998 PDBGC pDbgc; 1999 int rc = dbgcCreate(&pDbgc, pBack, fFlags); 2000 if (RT_FAILURE(rc)) 2001 return rc; 2002 2003 /* 2004 * Print welcome message. 2005 */ 2006 rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, 2007 "Welcome to the VirtualBox Debugger!\n"); 2008 2009 /* 2010 * Attach to the specified VM. 2011 */ 2012 if (RT_SUCCESS(rc) && pVM) 2013 { 2014 rc = DBGFR3Attach(pVM); 2015 if (RT_SUCCESS(rc)) 2016 { 2017 pDbgc->pVM = pVM; 2018 rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, 2019 "Current VM is %08x\n" /** @todo get and print the VM name! */ 2020 "VBoxDbg> ", 2021 pDbgc->pVM); 2022 } 2023 else 2024 rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to attach to VM %p\n", pDbgc->pVM); 2025 } 2026 else 2027 rc = pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, 2028 "VBoxDbg> "); 2029 2030 /* 2031 * Run the main loop. 2032 */ 2033 if (RT_SUCCESS(rc)) 2034 rc = dbgcRun(pDbgc); 2035 2036 /* 2037 * Cleanup console debugger session. 2038 */ 2039 dbgcDestroy(pDbgc); 1987 2040 return rc; 1988 2041 } -
trunk/src/VBox/Debugger/Makefile.kmk
r5680 r5685 59 59 # This stubs all the VBoxVMM APIs. 60 60 # 61 tstDBGCParser_TEMPLATE = VBOXR3EXE 61 tstDBGCParser_TEMPLATE = VBOXR3TSTEXE 62 tstDBGCParser_DEFS = IN_DBGF_R3 IN_CPUM_R3 IN_MM_R3 IN_PGM_R3 IN_SELM_R3 62 63 tstDBGCParser_SOURCES = \ 63 testcase/tstDBGCParser.cpp 64 testcase/tstDBGCParser.cpp \ 65 testcase/tstDBGCStubs.cpp 64 66 tstDBGCParser_LIBS = \ 65 67 $(TARGET_Debugger) \ … … 73 75 VBoxDbg_DEFS = IN_DBG_R3 74 76 VBoxDbg_CXXFLAGS.linux = $(TEMPLATE_VBOXQTGUI_CXXFLAGS.linux) -O2 75 VBoxDbg_CXXFLAGS.win = -wd424476 77 VBoxDbg_INCS = \ 77 78 . \ -
trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp
r5681 r5685 29 29 30 30 /******************************************************************************* 31 * Internal Functions * 32 *******************************************************************************/ 33 static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies); 34 static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead); 35 static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten); 36 37 38 /******************************************************************************* 31 39 * Global Variables * 32 40 *******************************************************************************/ 33 41 /** Global error counter. */ 34 42 static unsigned g_cErrors = 0; 43 /** The DBGC backend structure for use in this testcase. */ 44 static DBGCBACK g_tstBack = 45 { 46 tstDBGCBackInput, 47 tstDBGCBackRead, 48 tstDBGCBackWrite 49 }; 50 /** For keeping track of output prefixing. */ 51 static bool g_fPendingPrefix = true; 52 53 54 /** 55 * Checks if there is input. 56 * 57 * @returns true if there is input ready. 58 * @returns false if there not input ready. 59 * @param pBack Pointer to the backend structure supplied by 60 * the backend. The backend can use this to find 61 * it's instance data. 62 * @param cMillies Number of milliseconds to wait on input data. 63 */ 64 static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies) 65 { 66 RTPrintf("tstDBGCParser: tstDBGCBackInput was called!\n"); 67 g_cErrors++; 68 return false; 69 } 70 71 72 /** 73 * Read input. 74 * 75 * @returns VBox status code. 76 * @param pBack Pointer to the backend structure supplied by 77 * the backend. The backend can use this to find 78 * it's instance data. 79 * @param pvBuf Where to put the bytes we read. 80 * @param cbBuf Maximum nymber of bytes to read. 81 * @param pcbRead Where to store the number of bytes actually read. 82 * If NULL the entire buffer must be filled for a 83 * successful return. 84 */ 85 static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead) 86 { 87 RTPrintf("tstDBGCParser: tstDBGCBackRead was called!\n"); 88 g_cErrors++; 89 return VERR_INTERNAL_ERROR; 90 } 91 92 93 /** 94 * Write (output). 95 * 96 * @returns VBox status code. 97 * @param pBack Pointer to the backend structure supplied by 98 * the backend. The backend can use this to find 99 * it's instance data. 100 * @param pvBuf What to write. 101 * @param cbBuf Number of bytes to write. 102 * @param pcbWritten Where to store the number of bytes actually written. 103 * If NULL the entire buffer must be successfully written. 104 */ 105 static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten) 106 { 107 const char *pch = (const char *)pvBuf; 108 *pcbWritten = cbBuf; 109 while (cbBuf-- > 0) 110 { 111 if (g_fPendingPrefix) 112 { 113 RTPrintf("tstDBGCParser: OUTPUT: "); 114 g_fPendingPrefix = false; 115 } 116 if (*pch == '\n') 117 g_fPendingPrefix = true; 118 RTPrintf("%c", *pch); 119 pch++; 120 } 121 return VINF_SUCCESS; 122 } 123 124 125 /** 126 * Completes the output, making sure that we're in 127 * the 1 position of a new line. 128 */ 129 static void tstCompleteOutput(void) 130 { 131 if (!g_fPendingPrefix) 132 RTPrintf("\n"); 133 g_fPendingPrefix = true; 134 } 135 35 136 36 137 … … 45 146 46 147 /* 47 * 148 * Create a DBGC instance. 48 149 */ 150 PDBGC pDbgc; 151 int rc = dbgcCreate(&pDbgc, &g_tstBack, 0); 152 if (RT_SUCCESS(rc)) 153 { 154 155 dbgcDestroy(pDbgc); 156 } 49 157 50 158
Note:
See TracChangeset
for help on using the changeset viewer.