| 1028 | } |
| 1029 | |
| 1030 | BOOL StackWalker::LoadModules() |
| 1031 | { |
| 1032 | if (this->m_sw == NULL) |
| 1033 | { |
| 1034 | SetLastError(ERROR_DLL_INIT_FAILED); |
| 1035 | return FALSE; |
| 1036 | } |
| 1037 | if (m_modulesLoaded != FALSE) |
| 1038 | return TRUE; |
| 1039 | |
| 1040 | // Build the sym-path: |
| 1041 | char* szSymPath = NULL; |
| 1042 | if ((this->m_options & SymBuildPath) != 0) |
| 1043 | { |
| 1044 | const size_t nSymPathLen = 4096; |
| 1045 | szSymPath = (char*)malloc(nSymPathLen); |
| 1046 | if (szSymPath == NULL) |
| 1047 | { |
| 1048 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
| 1049 | return FALSE; |
| 1050 | } |
| 1051 | szSymPath[0] = 0; |
| 1052 | // Now first add the (optional) provided sympath: |
| 1053 | if (this->m_szSymPath != NULL) |
| 1054 | { |
| 1055 | strcat_s(szSymPath, nSymPathLen, this->m_szSymPath); |
| 1056 | strcat_s(szSymPath, nSymPathLen, ";"); |
| 1057 | } |
| 1058 | |
| 1059 | strcat_s(szSymPath, nSymPathLen, ".;"); |
| 1060 | |
| 1061 | const size_t nTempLen = 1024; |
| 1062 | char szTemp[nTempLen]; |
| 1063 | // Now add the current directory: |
| 1064 | if (GetCurrentDirectoryA(nTempLen, szTemp) > 0) |
| 1065 | { |
| 1066 | szTemp[nTempLen - 1] = 0; |
| 1067 | strcat_s(szSymPath, nSymPathLen, szTemp); |
| 1068 | strcat_s(szSymPath, nSymPathLen, ";"); |
| 1069 | } |
| 1070 | |
| 1071 | // Now add the path for the main-module: |
| 1072 | if (GetModuleFileNameA(NULL, szTemp, nTempLen) > 0) |
| 1073 | { |
| 1074 | szTemp[nTempLen - 1] = 0; |
| 1075 | for (char* p = (szTemp + strlen(szTemp) - 1); p >= szTemp; --p) |
| 1076 | { |
| 1077 | // locate the rightmost path separator |
| 1078 | if ((*p == '\\') || (*p == '/') || (*p == ':')) |
| 1079 | { |
| 1080 | *p = 0; |
| 1081 | break; |
| 1082 | } |
| 1083 | } // for (search for path separator...) |
| 1084 | if (strlen(szTemp) > 0) |
| 1085 | { |
| 1086 | strcat_s(szSymPath, nSymPathLen, szTemp); |
| 1087 | strcat_s(szSymPath, nSymPathLen, ";"); |
no test coverage detected