Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/platform-win32.cc

Issue 23703013: remove OS::StackWalk (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-solaris.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 if (!LoadDbgHelpAndTlHelp32()) return; 1201 if (!LoadDbgHelpAndTlHelp32()) return;
1202 HANDLE process_handle = GetCurrentProcess(); 1202 HANDLE process_handle = GetCurrentProcess();
1203 LoadSymbols(isolate, process_handle); 1203 LoadSymbols(isolate, process_handle);
1204 } 1204 }
1205 1205
1206 1206
1207 void OS::SignalCodeMovingGC() { 1207 void OS::SignalCodeMovingGC() {
1208 } 1208 }
1209 1209
1210 1210
1211 // Walk the stack using the facilities in dbghelp.dll and tlhelp32.dll
1212
1213 // Switch off warning 4748 (/GS can not protect parameters and local variables
1214 // from local buffer overrun because optimizations are disabled in function) as
1215 // it is triggered by the use of inline assembler.
1216 #pragma warning(push)
1217 #pragma warning(disable : 4748)
1218 int OS::StackWalk(Vector<OS::StackFrame> frames) {
1219 BOOL ok;
1220
1221 // Load the required functions from DLL's.
1222 if (!LoadDbgHelpAndTlHelp32()) return kStackWalkError;
1223
1224 // Get the process and thread handles.
1225 HANDLE process_handle = GetCurrentProcess();
1226 HANDLE thread_handle = GetCurrentThread();
1227
1228 // Read the symbols.
1229 if (!LoadSymbols(Isolate::Current(), process_handle)) return kStackWalkError;
1230
1231 // Capture current context.
1232 CONTEXT context;
1233 RtlCaptureContext(&context);
1234
1235 // Initialize the stack walking
1236 STACKFRAME64 stack_frame;
1237 memset(&stack_frame, 0, sizeof(stack_frame));
1238 #ifdef _WIN64
1239 stack_frame.AddrPC.Offset = context.Rip;
1240 stack_frame.AddrFrame.Offset = context.Rbp;
1241 stack_frame.AddrStack.Offset = context.Rsp;
1242 #else
1243 stack_frame.AddrPC.Offset = context.Eip;
1244 stack_frame.AddrFrame.Offset = context.Ebp;
1245 stack_frame.AddrStack.Offset = context.Esp;
1246 #endif
1247 stack_frame.AddrPC.Mode = AddrModeFlat;
1248 stack_frame.AddrFrame.Mode = AddrModeFlat;
1249 stack_frame.AddrStack.Mode = AddrModeFlat;
1250 int frames_count = 0;
1251
1252 // Collect stack frames.
1253 int frames_size = frames.length();
1254 while (frames_count < frames_size) {
1255 ok = _StackWalk64(
1256 IMAGE_FILE_MACHINE_I386, // MachineType
1257 process_handle, // hProcess
1258 thread_handle, // hThread
1259 &stack_frame, // StackFrame
1260 &context, // ContextRecord
1261 NULL, // ReadMemoryRoutine
1262 _SymFunctionTableAccess64, // FunctionTableAccessRoutine
1263 _SymGetModuleBase64, // GetModuleBaseRoutine
1264 NULL); // TranslateAddress
1265 if (!ok) break;
1266
1267 // Store the address.
1268 ASSERT((stack_frame.AddrPC.Offset >> 32) == 0); // 32-bit address.
1269 frames[frames_count].address =
1270 reinterpret_cast<void*>(stack_frame.AddrPC.Offset);
1271
1272 // Try to locate a symbol for this frame.
1273 DWORD64 symbol_displacement;
1274 SmartArrayPointer<IMAGEHLP_SYMBOL64> symbol(
1275 NewArray<IMAGEHLP_SYMBOL64>(kStackWalkMaxNameLen));
1276 if (symbol.is_empty()) return kStackWalkError; // Out of memory.
1277 memset(*symbol, 0, sizeof(IMAGEHLP_SYMBOL64) + kStackWalkMaxNameLen);
1278 (*symbol)->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
1279 (*symbol)->MaxNameLength = kStackWalkMaxNameLen;
1280 ok = _SymGetSymFromAddr64(process_handle, // hProcess
1281 stack_frame.AddrPC.Offset, // Address
1282 &symbol_displacement, // Displacement
1283 *symbol); // Symbol
1284 if (ok) {
1285 // Try to locate more source information for the symbol.
1286 IMAGEHLP_LINE64 Line;
1287 memset(&Line, 0, sizeof(Line));
1288 Line.SizeOfStruct = sizeof(Line);
1289 DWORD line_displacement;
1290 ok = _SymGetLineFromAddr64(
1291 process_handle, // hProcess
1292 stack_frame.AddrPC.Offset, // dwAddr
1293 &line_displacement, // pdwDisplacement
1294 &Line); // Line
1295 // Format a text representation of the frame based on the information
1296 // available.
1297 if (ok) {
1298 SNPrintF(MutableCStrVector(frames[frames_count].text,
1299 kStackWalkMaxTextLen),
1300 "%s %s:%d:%d",
1301 (*symbol)->Name, Line.FileName, Line.LineNumber,
1302 line_displacement);
1303 } else {
1304 SNPrintF(MutableCStrVector(frames[frames_count].text,
1305 kStackWalkMaxTextLen),
1306 "%s",
1307 (*symbol)->Name);
1308 }
1309 // Make sure line termination is in place.
1310 frames[frames_count].text[kStackWalkMaxTextLen - 1] = '\0';
1311 } else {
1312 // No text representation of this frame
1313 frames[frames_count].text[0] = '\0';
1314
1315 // Continue if we are just missing a module (for non C/C++ frames a
1316 // module will never be found).
1317 int err = GetLastError();
1318 if (err != ERROR_MOD_NOT_FOUND) {
1319 break;
1320 }
1321 }
1322
1323 frames_count++;
1324 }
1325
1326 // Return the number of frames filled in.
1327 return frames_count;
1328 }
1329
1330
1331 // Restore warnings to previous settings.
1332 #pragma warning(pop)
1333
1334 #else // __MINGW32__ 1211 #else // __MINGW32__
1335 void OS::LogSharedLibraryAddresses(Isolate* isolate) { } 1212 void OS::LogSharedLibraryAddresses(Isolate* isolate) { }
1336 void OS::SignalCodeMovingGC() { } 1213 void OS::SignalCodeMovingGC() { }
1337 int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; }
1338 #endif // __MINGW32__ 1214 #endif // __MINGW32__
1339 1215
1340 1216
1341 uint64_t OS::CpuFeaturesImpliedByPlatform() { 1217 uint64_t OS::CpuFeaturesImpliedByPlatform() {
1342 return 0; // Windows runs on anything. 1218 return 0; // Windows runs on anything.
1343 } 1219 }
1344 1220
1345 1221
1346 double OS::nan_value() { 1222 double OS::nan_value() {
1347 #ifdef _MSC_VER 1223 #ifdef _MSC_VER
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 ASSERT(result); 1445 ASSERT(result);
1570 } 1446 }
1571 1447
1572 1448
1573 1449
1574 void Thread::YieldCPU() { 1450 void Thread::YieldCPU() {
1575 Sleep(0); 1451 Sleep(0);
1576 } 1452 }
1577 1453
1578 } } // namespace v8::internal 1454 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698