summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rwxr-xr-xcpp/config/Make.rules.msvc27
-rw-r--r--cpp/src/IceUtil/Exception.cpp72
-rw-r--r--cpp/src/IceUtil/Makefile.mak4
3 files changed, 77 insertions, 26 deletions
diff --git a/cpp/config/Make.rules.msvc b/cpp/config/Make.rules.msvc
index 644ea78bcb5..eaf4c1a08a3 100755
--- a/cpp/config/Make.rules.msvc
+++ b/cpp/config/Make.rules.msvc
@@ -49,7 +49,7 @@ CPPFLAGS = $(CPPFLAGS) -MP
CPPFLAGS = $(CPPFLAGS) -O2 -DNDEBUG -MD
!if "$(RELEASEPDBS)" == "yes"
-CPPFLAGS = $(CPPFLAGS) -Zi
+CPPFLAGS = $(CPPFLAGS) -Zi -Oy-
!endif
ARFLAGS = $(ARFLAGS) /LTCG
@@ -69,35 +69,20 @@ LDFLAGS = $(LDFLAGS) /nologo
!if "$(WINRT)" == "yes"
LDFLAGS = $(LDFLAGS) /NXCOMPAT /MANIFEST:NO /APPCONTAINER /NOLOGO
-
-!if "$(OPTIMIZE)" != "yes"
-LDFLAGS = $(LDFLAGS) /debug
-!else
-LDFLAGS = $(LDFLAGS) /OPT:REF
-!if "$(GENERATE_PDB)" != "yes"
-LDFLAGS = $(LDFLAGS) /pdb:none
-!else
-LDFLAGS = $(LDFLAGS) /debug
-!endif
-!endif
-
!else
LDFLAGS = $(LDFLAGS) /FIXED:no
-!if "$(OPTIMIZE)" != "yes"
-
-LDFLAGS = $(LDFLAGS) /debug
-
-!else
+!endif
+!if "$(OPTIMIZE)" == "yes"
LDFLAGS = $(LDFLAGS) /OPT:REF
+!endif
+
!if "$(GENERATE_PDB)" != "yes"
LDFLAGS = $(LDFLAGS) /pdb:none
!else
-LDFLAGS = $(LDFLAGS) /debug
+LDFLAGS = $(LDFLAGS) /debug /incremental:no
!endif
-!endif
-!endif
LD_DLLFLAGS = $(LDFLAGS) /dll
LD_EXEFLAGS = $(LDFLAGS)
diff --git a/cpp/src/IceUtil/Exception.cpp b/cpp/src/IceUtil/Exception.cpp
index c90b6bb9879..e17088973d7 100644
--- a/cpp/src/IceUtil/Exception.cpp
+++ b/cpp/src/IceUtil/Exception.cpp
@@ -15,6 +15,9 @@
# ifndef UNICODE
# define UNICODE
# endif
+# ifndef _UNICODE
+# define _UNICODE
+# endif
#endif
#include <IceUtil/Exception.h>
@@ -33,14 +36,14 @@
# define ICE_GCC_STACK_TRACES
#endif
-#if defined(_WIN32) && !defined(__MINGW32__) && !defined(ICE_OS_WINRT)
+#ifdef ICE_WIN32_STACK_TRACES
# if defined(_MSC_VER) && _MSC_VER >= 1700
# define DBGHELP_TRANSLATE_TCHAR
# include <IceUtil/Unicode.h>
# endif
# include <DbgHelp.h>
+# include <tchar.h>
# define ICE_STACK_TRACES
-# define ICE_WIN32_STACK_TRACES
#endif
using namespace std;
@@ -105,10 +108,65 @@ getStackTrace()
IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(globalMutex);
if(process == 0)
{
+
+ //
+ // Compute Search path (best effort)
+ // consists of the current working directory, this DLL (or exe) directory and %_NT_SYMBOL_PATH%
+ //
+ basic_string<TCHAR> searchPath;
+ const TCHAR pathSeparator = _T('\\');
+ const TCHAR searchPathSeparator = _T(';');
+
+ TCHAR cwd[MAX_PATH];
+ if(GetCurrentDirectory(MAX_PATH, cwd) != 0)
+ {
+ searchPath = cwd;
+ }
+
+ HMODULE myModule = 0;
+ GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ "startHook",
+ &myModule);
+ //
+ // If GetModuleHandleEx fails, myModule is NULL, i.e. we'll locate the current exe's directory.
+ //
+
+ TCHAR myFilename[MAX_PATH];
+ DWORD len = GetModuleFileName(myModule, myFilename, MAX_PATH);
+ if(len != 0 && len < MAX_PATH)
+ {
+ assert(myFilename[len] == 0);
+
+ basic_string<TCHAR> myPath = myFilename;
+ size_t pos = myPath.find_last_of(pathSeparator);
+ if(pos != basic_string<TCHAR>::npos)
+ {
+ myPath = myPath.substr(0, pos);
+
+ if(!searchPath.empty())
+ {
+ searchPath += searchPathSeparator;
+ }
+ searchPath += myPath;
+ }
+ }
+
+ const DWORD size = 1024;
+ TCHAR symbolPath[size];
+ len = GetEnvironmentVariable(_T("_NT_SYMBOL_PATH"), symbolPath, size);
+ if(len > 0 && len < size)
+ {
+ if(!searchPath.empty())
+ {
+ searchPath += searchPathSeparator;
+ }
+ searchPath += symbolPath;
+ }
+
process = GetCurrentProcess();
- SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME);
- BOOL ok = SymInitialize(process, 0, TRUE);
- if(!ok)
+
+ SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS | SYMOPT_UNDNAME);
+ if(SymInitialize(process, searchPath.c_str(), TRUE) == 0)
{
process = 0;
return "No stack trace: SymInitialize failed with " + IceUtilInternal::errorToString(GetLastError());
@@ -146,6 +204,9 @@ getStackTrace()
DWORD displacement = 0;
lock.acquire();
+
+ // TODO: call SymRefreshModuleList here? (not available on XP)
+
for(int i = 0; i < frames; i++)
{
if(!stackTrace.empty())
@@ -295,6 +356,7 @@ getStackTrace()
free(stackStrings);
# endif
+
return stackTrace;
}
#endif
diff --git a/cpp/src/IceUtil/Makefile.mak b/cpp/src/IceUtil/Makefile.mak
index 7e8d5ef31dc..4e62b1607d5 100644
--- a/cpp/src/IceUtil/Makefile.mak
+++ b/cpp/src/IceUtil/Makefile.mak
@@ -44,6 +44,10 @@ CPPFLAGS = $(CPPFLAGS) -DICE_UTIL_API_EXPORTS -I.. -DWIN32_LEAN_AND_MEAN
!if "$(GENERATE_PDB)" == "yes"
PDBFLAGS = /pdb:$(DLLNAME:.dll=.pdb)
+
+!if "$(WINRT)" != "yes"
+CPPFLAGS = $(CPPFLAGS) -DICE_WIN32_STACK_TRACES
+!endif
!endif
RES_FILE = IceUtil.res