Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Log internal errors |
| 3 | * |
| 4 | * Copyright 1997 Andrew Taylor |
| 5 | */ |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | |
| 11 | #include "windows.h" |
| 12 | #include "stddebug.h" |
| 13 | #include "debug.h" |
| 14 | |
| 15 | #ifdef DEBUG_RUNTIME |
| 16 | |
| 17 | #define ErrorString(manifest) { manifest, # manifest } |
| 18 | |
| 19 | const struct { |
| 20 | int constant; |
| 21 | const char *name; |
| 22 | } ErrorStrings[] = { |
| 23 | |
| 24 | ErrorString(ERR_GALLOC), |
| 25 | ErrorString(ERR_GREALLOC), |
| 26 | ErrorString(ERR_GLOCK), |
| 27 | ErrorString(ERR_LALLOC), |
| 28 | ErrorString(ERR_LREALLOC), |
| 29 | ErrorString(ERR_LLOCK), |
| 30 | ErrorString(ERR_ALLOCRES), |
| 31 | ErrorString(ERR_LOCKRES), |
| 32 | ErrorString(ERR_LOADMODULE), |
| 33 | ErrorString(ERR_CREATEDLG), |
| 34 | ErrorString(ERR_CREATEDLG2), |
| 35 | ErrorString(ERR_REGISTERCLASS), |
| 36 | ErrorString(ERR_DCBUSY), |
| 37 | ErrorString(ERR_CREATEWND), |
| 38 | ErrorString(ERR_STRUCEXTRA), |
| 39 | ErrorString(ERR_LOADSTR), |
| 40 | ErrorString(ERR_LOADMENU), |
| 41 | ErrorString(ERR_NESTEDBEGINPAINT), |
| 42 | ErrorString(ERR_BADINDEX), |
| 43 | ErrorString(ERR_CREATEMENU), |
| 44 | ErrorString(ERR_CREATEDC), |
| 45 | ErrorString(ERR_CREATEMETA), |
| 46 | ErrorString(ERR_DELOBJSELECTED), |
| 47 | ErrorString(ERR_SELBITMAP) |
| 48 | }; |
| 49 | |
| 50 | #define ErrorStringCount (sizeof(ErrorStrings) / sizeof(ErrorStrings[0])) |
| 51 | |
| 52 | const struct { |
| 53 | int constant; |
| 54 | const char *name; |
| 55 | } ParamErrorStrings[] = { |
| 56 | |
| 57 | ErrorString(ERR_BAD_VALUE), |
| 58 | ErrorString(ERR_BAD_FLAGS), |
| 59 | ErrorString(ERR_BAD_INDEX), |
| 60 | ErrorString(ERR_BAD_DVALUE), |
| 61 | ErrorString(ERR_BAD_DFLAGS), |
| 62 | ErrorString(ERR_BAD_DINDEX), |
| 63 | ErrorString(ERR_BAD_PTR), |
| 64 | ErrorString(ERR_BAD_FUNC_PTR), |
| 65 | ErrorString(ERR_BAD_SELECTOR), |
| 66 | ErrorString(ERR_BAD_STRING_PTR), |
| 67 | ErrorString(ERR_BAD_HANDLE), |
| 68 | ErrorString(ERR_BAD_HINSTANCE), |
| 69 | ErrorString(ERR_BAD_HMODULE), |
| 70 | ErrorString(ERR_BAD_GLOBAL_HANDLE), |
| 71 | ErrorString(ERR_BAD_LOCAL_HANDLE), |
| 72 | ErrorString(ERR_BAD_ATOM), |
| 73 | ErrorString(ERR_BAD_HFILE), |
| 74 | ErrorString(ERR_BAD_HWND), |
| 75 | ErrorString(ERR_BAD_HMENU), |
| 76 | ErrorString(ERR_BAD_HCURSOR), |
| 77 | ErrorString(ERR_BAD_HICON), |
| 78 | ErrorString(ERR_BAD_HDWP), |
| 79 | ErrorString(ERR_BAD_CID), |
| 80 | ErrorString(ERR_BAD_HDRVR), |
| 81 | ErrorString(ERR_BAD_COORDS), |
| 82 | ErrorString(ERR_BAD_GDI_OBJECT), |
| 83 | ErrorString(ERR_BAD_HDC), |
| 84 | ErrorString(ERR_BAD_HPEN), |
| 85 | ErrorString(ERR_BAD_HFONT), |
| 86 | ErrorString(ERR_BAD_HBRUSH), |
| 87 | ErrorString(ERR_BAD_HBITMAP), |
| 88 | ErrorString(ERR_BAD_HRGN), |
| 89 | ErrorString(ERR_BAD_HPALETTE), |
| 90 | ErrorString(ERR_BAD_HMETAFILE) |
| 91 | }; |
| 92 | |
| 93 | #define ParamErrorStringCount (sizeof(ParamErrorStrings) / sizeof(ParamErrorStrings[0])) |
| 94 | |
| 95 | #endif /* DEBUG_RUNTIME */ |
| 96 | |
| 97 | /*********************************************************************** |
| 98 | * GetErrorString (internal) |
| 99 | */ |
| 100 | static const char *GetErrorString(UINT16 uErr) { |
| 101 | static char buffer[80]; |
| 102 | |
| 103 | #ifdef DEBUG_RUNTIME |
| 104 | int i; |
| 105 | |
| 106 | for (i = 0; i < ErrorStringCount; i++) { |
| 107 | if (uErr == ErrorStrings[i].constant) |
| 108 | return ErrorStrings[i].name; |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | sprintf(buffer, "%x", uErr); |
| 113 | return buffer; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /*********************************************************************** |
| 118 | * GetParamErrorString (internal) |
| 119 | */ |
| 120 | static const char *GetParamErrorString(UINT16 uErr) { |
| 121 | static char buffer[80]; |
| 122 | |
| 123 | if (uErr & ERR_WARNING) { |
| 124 | strcpy(buffer, "ERR_WARNING | "); |
| 125 | uErr &= ~ERR_WARNING; |
| 126 | } else |
| 127 | buffer[0] = '\0'; |
| 128 | |
| 129 | #ifdef DEBUG_RUNTIME |
| 130 | { |
| 131 | int i; |
| 132 | |
| 133 | for (i = 0; i < ParamErrorStringCount; i++) { |
| 134 | if (uErr == ParamErrorStrings[i].constant) { |
| 135 | strcat(buffer, ParamErrorStrings[i].name); |
| 136 | return buffer; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | #endif |
| 141 | |
| 142 | sprintf(buffer + strlen(buffer), "%x", uErr); |
| 143 | return buffer; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | /*********************************************************************** |
| 148 | * LogError (KERNEL.324) |
| 149 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 150 | VOID WINAPI LogError(UINT16 uErr, LPVOID lpvInfo) |
| 151 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 152 | fprintf(stddeb, "LogError(%s, %p)\n", |
| 153 | GetErrorString(uErr), lpvInfo); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | /*********************************************************************** |
| 158 | * LogParamError (KERNEL.325) |
| 159 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 160 | void WINAPI LogParamError(UINT16 uErr, FARPROC16 lpfn, LPVOID lpvParam) |
| 161 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 162 | /* FIXME: is it possible to get the module name/function |
| 163 | * from the lpfn param? |
| 164 | */ |
| 165 | fprintf(stddeb, "LogParamError(%s, %p, %p)\n", |
| 166 | GetParamErrorString(uErr), lpfn, lpvParam); |
| 167 | } |