Changeset 38509 in vbox
- Timestamp:
- Aug 23, 2011 3:07:55 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/errorprint.h
r36536 r38509 36 36 // shared prototypes; these are defined in shared glue code and are 37 37 // compiled only once for all front-ends 38 void GluePrintErrorInfo(co m::ErrorInfo &info);38 void GluePrintErrorInfo(const com::ErrorInfo &info); 39 39 void GluePrintErrorContext(const char *pcszContext, const char *pcszSourceFile, uint32_t ulLine); 40 40 void GluePrintRCMessage(HRESULT rc); 41 void GlueHandleComError(ComPtr<IUnknown> iface, const char *pcszContext, HRESULT rc, const char *pcszSourceFile, uint32_t ulLine); 41 void GlueHandleComError(ComPtr<IUnknown> iface, 42 const char *pcszContext, 43 HRESULT rc, 44 const char *pcszSourceFile, 45 uint32_t ulLine); 46 void GlueHandleComErrorProgress(ComPtr<IProgress> progress, 47 const char *pcszContext, 48 HRESULT rc, 49 const char *pcszSourceFile, 50 uint32_t ulLine); 42 51 43 52 /** … … 153 162 } while (0) 154 163 164 165 /** 166 * Check the progress object for an error and if there is one print out the 167 * extended error information. 168 */ 169 #define CHECK_PROGRESS_ERROR(progress) \ 170 do { \ 171 LONG iRc; \ 172 rc = progress->COMGETTER(ResultCode)(&iRc); \ 173 if (FAILED(iRc)) \ 174 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, iRc, __FILE__, __LINE__); \ 175 } while (0) 176 177 /** 178 * Does the same as CHECK_PROGRESS_ERROR(), but executes the |return ret| statement on 179 * failure. 180 */ 181 #define CHECK_PROGRESS_ERROR_RET(progress, ret) \ 182 do { \ 183 LONG iRc; \ 184 rc = progress->COMGETTER(ResultCode)(&iRc); \ 185 if (FAILED(iRc)) \ 186 { \ 187 com::GlueHandleComErrorProgress(progress, __PRETTY_FUNCTION__, iRc, __FILE__, __LINE__); \ 188 return (ret); \ 189 } \ 190 } while (0) 191 155 192 /** 156 193 * Asserts the given expression is true. When the expression is false, prints -
trunk/src/VBox/Main/glue/errorprint.cpp
r32718 r38509 30 30 { 31 31 32 void GluePrintErrorInfo(co m::ErrorInfo &info)32 void GluePrintErrorInfo(const com::ErrorInfo &info) 33 33 { 34 Utf8Str str = Utf8StrFmt("%ls\n" 35 "Details: code %Rhrc (0x%RX32), component %ls, interface %ls, callee %ls\n" 36 , 37 info.getText().raw(), 38 info.getResultCode(), 39 info.getResultCode(), 40 info.getComponent().raw(), 41 info.getInterfaceName().raw(), 42 info.getCalleeName().raw()); 34 bool haveResultCode = false; 35 #if defined (RT_OS_WIN) 36 haveResultCode = info.isFullAvailable(); 37 bool haveComponent = true; 38 bool haveInterfaceID = true; 39 #else /* defined (RT_OS_WIN) */ 40 haveResultCode = true; 41 bool haveComponent = info.isFullAvailable(); 42 bool haveInterfaceID = info.isFullAvailable(); 43 #endif 44 45 Utf8Str str; 46 RTCList<Utf8Str> comp; 47 48 Bstr bstrDetailsText = info.getText(); 49 if (!bstrDetailsText.isEmpty()) 50 str = Utf8StrFmt("%ls\n", 51 bstrDetailsText.raw()); 52 if (haveResultCode) 53 comp.append(Utf8StrFmt("code %Rhrc (0x%RX32)", 54 info.getResultCode(), 55 info.getResultCode())); 56 if (haveComponent) 57 comp.append(Utf8StrFmt("component %ls", 58 info.getComponent().raw())); 59 if (haveInterfaceID) 60 comp.append(Utf8StrFmt("interface %ls", 61 info.getInterfaceName().raw())); 62 if (!info.getCalleeName().isEmpty()) 63 comp.append(Utf8StrFmt("callee %ls", 64 info.getCalleeName().raw())); 65 66 if (comp.size() > 0) 67 { 68 str += "Details: "; 69 for (size_t i = 0; i < comp.size() - 1; ++i) 70 str += comp.at(i) + ", "; 71 str += comp.last(); 72 str += "\n"; 73 } 74 43 75 // print and log 44 76 RTMsgError("%s", str.c_str()); … … 52 84 Utf8Str strFilename(RTPathFilename(pcszSourceFile)); 53 85 Utf8Str str = Utf8StrFmt("Context: \"%s\" at line %d of file %s\n", 54 55 56 86 pcszContext, 87 ulLine, 88 strFilename.c_str()); 57 89 // print and log 58 RT StrmPrintf(g_pStdErr,"%s", str.c_str());90 RTMsgError("%s", str.c_str()); 59 91 Log(("%s", str.c_str())); 60 92 } … … 68 100 } 69 101 102 static void glueHandleComErrorInternal(com::ErrorInfo &info, 103 const char *pcszContext, 104 HRESULT rc, 105 const char *pcszSourceFile, 106 uint32_t ulLine) 107 { 108 const com::ErrorInfo *pInfo = &info; 109 do 110 { 111 if (pInfo->isFullAvailable() || pInfo->isBasicAvailable()) 112 GluePrintErrorInfo(*pInfo); 113 else 114 #if defined (RT_OS_WIN) 115 GluePrintRCMessage(rc); 116 #else /* defined (RT_OS_WIN) */ 117 GluePrintRCMessage(pInfo->getResultCode()); 118 #endif 119 pInfo = pInfo->getNext(); 120 /* If there is more than one error, separate them visually. */ 121 if (pInfo) 122 RTMsgError("--------\n"); 123 } 124 while(pInfo); 125 126 GluePrintErrorContext(pcszContext, pcszSourceFile, ulLine); 127 } 128 70 129 void GlueHandleComError(ComPtr<IUnknown> iface, 71 130 const char *pcszContext, … … 74 133 uint32_t ulLine) 75 134 { 76 // if we have full error info, print something nice, and start with the actual error message 135 /* If we have full error info, print something nice, and start with the 136 * actual error message. */ 77 137 com::ErrorInfo info(iface, COM_IIDOF(IUnknown)); 78 if (info.isFullAvailable() || info.isBasicAvailable()) 79 GluePrintErrorInfo(info); 80 else 81 GluePrintRCMessage(rc); 82 GluePrintErrorContext(pcszContext, pcszSourceFile, ulLine); 138 139 glueHandleComErrorInternal(info, 140 pcszContext, 141 rc, 142 pcszSourceFile, 143 ulLine); 144 83 145 } 84 146 147 void GlueHandleComErrorProgress(ComPtr<IProgress> progress, 148 const char *pcszContext, 149 HRESULT rc, 150 const char *pcszSourceFile, 151 uint32_t ulLine) 152 { 153 /* Get the error info out of the progress object. */ 154 ProgressErrorInfo ei(progress); 155 156 glueHandleComErrorInternal(ei, 157 pcszContext, 158 rc, 159 pcszSourceFile, 160 ulLine); 161 } 85 162 86 163 } /* namespace com */
Note:
See TracChangeset
for help on using the changeset viewer.