MCPcopy Create free account
hub / github.com/cuberite/cuberite / ShowCallstack

Method ShowCallstack

src/StackWalker.cpp:1006–1239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1004static LPVOID s_readMemoryFunction_UserData = NULL;
1005
1006BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadProcessMemoryRoutine readMemoryFunction, LPVOID pUserData)
1007{
1008 CONTEXT c;
1009 CallstackEntry csEntry;
1010 IMAGEHLP_SYMBOL64 *pSym = NULL;
1011 StackWalkerInternal::IMAGEHLP_MODULE64_V2 Module;
1012 IMAGEHLP_LINE64 Line;
1013 int frameNum;
1014 bool bLastEntryCalled = true;
1015 int curRecursionCount = 0;
1016
1017 if (m_modulesLoaded == FALSE)
1018 this->LoadModules(); // ignore the result...
1019
1020 if (this->m_sw->m_hDbhHelp == NULL)
1021 {
1022 SetLastError(ERROR_DLL_INIT_FAILED);
1023 return FALSE;
1024 }
1025
1026 s_readMemoryFunction = readMemoryFunction;
1027 s_readMemoryFunction_UserData = pUserData;
1028
1029 if (context == NULL)
1030 {
1031 // If no context is provided, capture the context
1032 if (hThread == GetCurrentThread())
1033 {
1034 GET_CURRENT_CONTEXT(c, USED_CONTEXT_FLAGS);
1035 }
1036 else
1037 {
1038 SuspendThread(hThread);
1039 memset(&c, 0, sizeof(CONTEXT));
1040 c.ContextFlags = USED_CONTEXT_FLAGS;
1041 if (GetThreadContext(hThread, &c) == FALSE)
1042 {
1043 ResumeThread(hThread);
1044 return FALSE;
1045 }
1046 }
1047 }
1048 else
1049 c = *context;
1050
1051 // init STACKFRAME for first call
1052 STACKFRAME64 s; // in/out stackframe
1053 memset(&s, 0, sizeof(s));
1054 DWORD imageType;
1055#ifdef _M_IX86
1056 // normally, call ImageNtHeader() and use machine info from PE header
1057 imageType = IMAGE_FILE_MACHINE_I386;
1058 s.AddrPC.Offset = c.Eip;
1059 s.AddrPC.Mode = AddrModeFlat;
1060 s.AddrFrame.Offset = c.Ebp;
1061 s.AddrFrame.Mode = AddrModeFlat;
1062 s.AddrStack.Offset = c.Esp;
1063 s.AddrStack.Mode = AddrModeFlat;

Callers 1

ShowLeaksMethod · 0.80

Calls 5

LoadModulesMethod · 0.95
OnDbgHelpErrMethod · 0.95
OnCallstackEntryMethod · 0.95
MyStrCpyFunction · 0.85
GetModuleInfoMethod · 0.80

Tested by

no test coverage detected