Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifdef SK_BUILD_FOR_WIN32 | |
| 9 | |
| 10 #include "win_dbghelp.h" | |
| 11 #include <process.h> | |
| 12 #include <string.h> | |
| 13 #include <stdlib.h> | |
| 14 | |
| 15 #define CDB_PRINT_CALLSTACK_CURRENT_THREAD "k" | |
| 16 | |
| 17 char debug_app_name[MAX_PATH] = ""; | |
| 18 void setAppName(const char* app_name) { | |
| 19 if (app_name == NULL) { | |
| 20 app_name = ""; | |
| 21 } | |
| 22 strcpy(debug_app_name, app_name); | |
| 23 } | |
| 24 | |
| 25 const char* getAppName() { | |
| 26 return debug_app_name; | |
| 27 } | |
| 28 | |
| 29 char debug_binaries_path[MAX_PATH] = ""; | |
| 30 void setBinariesPath(const char* binaries_path) { | |
| 31 if (binaries_path == NULL) { | |
| 32 binaries_path = ""; | |
| 33 } | |
| 34 strcpy(debug_binaries_path, binaries_path); | |
| 35 } | |
| 36 | |
| 37 const char* getBinariesPath() { | |
| 38 return debug_binaries_path; | |
| 39 } | |
| 40 | |
| 41 char debug_app_version[100] = ""; | |
| 42 void setAppVersion(const char* version) { | |
| 43 if (version == NULL) { | |
| 44 version = ""; | |
| 45 } | |
| 46 strcpy(debug_app_version, version); | |
| 47 } | |
| 48 | |
| 49 const char* getAppVersion() { | |
| 50 return debug_app_version; | |
| 51 } | |
| 52 | |
| 53 char debug_cdb_path[MAX_PATH] = ""; | |
| 54 void setCdbPath(const char* path) { | |
| 55 if (path == NULL) { | |
| 56 path = ""; | |
| 57 } | |
| 58 strcpy(debug_cdb_path, path); | |
| 59 } | |
| 60 | |
| 61 const char* getCdbPath() { | |
| 62 return debug_cdb_path; | |
| 63 } | |
| 64 | |
| 65 int GenerateDumpAndPrintCallstack(EXCEPTION_POINTERS* pExceptionPointers) { | |
| 66 BOOL bMiniDumpSuccessful; | |
| 67 char szPath[MAX_PATH]; | |
| 68 char szFileName[MAX_PATH]; | |
| 69 char* szAppName = getAppName(); | |
| 70 char* szVersion = getAppVersion(); | |
| 71 DWORD dwBufferSize = MAX_PATH; | |
| 72 HANDLE hDumpFile; | |
| 73 SYSTEMTIME stLocalTime; | |
| 74 MINIDUMP_EXCEPTION_INFORMATION ExpParam; | |
| 75 | |
| 76 GetLocalTime( &stLocalTime ); | |
| 77 GetTempPath( dwBufferSize, szPath ); | |
| 78 | |
| 79 sprintf( szFileName, "%s%s", szPath, szAppName ); | |
| 80 CreateDirectory( szFileName, NULL ); | |
| 81 | |
| 82 sprintf( szFileName, "%s%s\\%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp", | |
| 83 szPath, szAppName, szVersion, | |
| 84 stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, | |
| 85 stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond, | |
| 86 GetCurrentProcessId(), GetCurrentThreadId()); | |
| 87 | |
| 88 SkDebugf("Minidump saved to %s.\n", szFileName); | |
| 89 | |
| 90 hDumpFile = CreateFile(szFileName, | |
| 91 GENERIC_READ|GENERIC_WRITE, | |
| 92 FILE_SHARE_WRITE|FILE_SHARE_READ, | |
| 93 0, | |
| 94 CREATE_ALWAYS, | |
| 95 0, | |
| 96 0); | |
| 97 | |
| 98 ExpParam.ThreadId = GetCurrentThreadId(); | |
| 99 ExpParam.ExceptionPointers = pExceptionPointers; | |
| 100 ExpParam.ClientPointers = TRUE; | |
| 101 | |
| 102 bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), | |
| 103 GetCurrentProcessId(), | |
| 104 hDumpFile, | |
| 105 MiniDumpWithDataSegs, | |
| 106 &ExpParam, | |
| 107 NULL, | |
| 108 NULL); | |
| 109 | |
| 110 const char* cdbExePath = getCdbPath(); | |
| 111 | |
| 112 if (cdbExePath && *cdbExePath != '\0') { | |
| 113 char exePath[MAX_PATH]; | |
| 114 sprintf(exePath, "%s\\%s.exe", getBinariesPath(), getAppName()); | |
| 115 | |
| 116 char pdbPath[MAX_PATH]; | |
| 117 sprintf(pdbPath, "%s\\%s.pdb", getBinariesPath(), getAppName()); | |
| 118 | |
| 119 _execl(cdbExePath, | |
| 120 "-y", pdbPath, | |
| 121 "-i", exePath, | |
| 122 "-z", szFileName, | |
| 123 "-c", CDB_PRINT_CALLSTACK_CURRENT_THREAD); | |
| 124 } else { | |
| 125 SkDebugf("Warning: CDB path not not set up.\n"); | |
| 126 } | |
| 127 | |
| 128 return EXCEPTION_EXECUTE_HANDLER; | |
| 129 } | |
| 130 | |
| 131 void setUpDebuggingFromArgs(const char* vargs0) { | |
| 132 // remove .exe | |
| 133 int i = strlen(vargs0); | |
| 134 | |
| 135 i--; | |
| 136 if (i < 0 || (vargs0[i] != 'E' && vargs0[i] != 'e')) { | |
| 137 return; | |
| 138 } | |
| 139 | |
| 140 i--; | |
| 141 if (i < 0 || (vargs0[i] != 'X' && vargs0[i] != 'x')) { | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 i--; | |
| 146 if (i < 0 || (vargs0[i] != 'E' && vargs0[i] != 'e')) { | |
| 147 return; | |
| 148 } | |
| 149 | |
| 150 i--; | |
| 151 if (i < 0 || vargs0[i] != '.') { | |
| 152 return; | |
| 153 } | |
| 154 | |
| 155 int pos_period = i; | |
| 156 | |
| 157 // Find last \ in path - this is Windows! | |
| 158 while (i >= 0 && vargs0[i] != '\\') { | |
| 159 i--; | |
| 160 } | |
| 161 | |
| 162 if (i < 0) { | |
| 163 return; | |
| 164 } | |
| 165 | |
| 166 int pos_last_slash = i; | |
| 167 | |
| 168 char app_name[MAX_PATH]; | |
| 169 strncpy(vargs0 + pos_last_slash + 1, app_name, pos_period - pos_last_slash - 1); | |
| 170 app_name[pos_period - pos_last_slash] = '\0'; | |
| 171 setAppName(app_name); | |
| 172 | |
| 173 char binaries_path[MAX_PATH]; | |
| 174 strncpy(vargs0, binaries_path, pos_last_slash - 1); | |
| 175 binaries_path[pos_last_slash] = '\0'; | |
| 176 setBinariesPath(binaries_path); | |
| 177 | |
| 178 setAppVersion("1.0"); // Dummy for now, but use revision instead if we use | |
| 179 // the minidump for anything else other than | |
| 180 // collecting the callstack. | |
| 181 #ifdef _WIN64 | |
|
edisonn
2013/02/28 16:56:23
is there a better way to get the path to an exe pa
borenet
2013/02/28 20:28:19
I think an environment variable would be okay. I
| |
| 182 setCdbPath(getenv("CDB_PATH_X64")); | |
| 183 #else | |
| 184 setCdbPath(getenv("CDB_PATH")); | |
| 185 #endif | |
| 186 } | |
| 187 | |
| 188 #endif // SK_BUILD_FOR_WIN32 | |
| OLD | NEW |