summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeokYeon Hwang <syeon.hwang@samsung.com>2016-12-21 13:27:49 +0900
committerSeokYeon Hwang <syeon.hwang@samsung.com>2016-12-21 13:27:49 +0900
commit2c287e32dc138ff512db2a6fd10d5ac9173eeb30 (patch)
tree84cab26fd58eee0811e9376568c831459e6ea1e2
parente07e7bd4920899d250fa1b89e7974562dc464a72 (diff)
downloadqemu-2c287e32dc138ff512db2a6fd10d5ac9173eeb30.tar.gz
qemu-2c287e32dc138ff512db2a6fd10d5ac9173eeb30.tar.bz2
qemu-2c287e32dc138ff512db2a6fd10d5ac9173eeb30.zip
error_handler: unify stack walking logic
Change-Id: I5c82ecd08085af25b560f3c57b4abbc974f42e3d Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
-rw-r--r--tizen/src/util/error_handler.c72
1 files changed, 16 insertions, 56 deletions
diff --git a/tizen/src/util/error_handler.c b/tizen/src/util/error_handler.c
index 959594e83c..a6348ac54b 100644
--- a/tizen/src/util/error_handler.c
+++ b/tizen/src/util/error_handler.c
@@ -67,29 +67,9 @@ void enable_print_backtrace_at_normal_exit(void)
#ifdef CONFIG_WIN32
static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter;
-/* The MSDN says as followed in "Updated Platform Support" page,
- (https://msdn.microsoft.com/en-us/library/windows/desktop/
- ms681408(v=vs.85).aspx)
- "Where necessary, the DbgHelp library has been widened to support both 32-
- and 64-bit Windows. The original function and structure definitions are
- still in DbgHelp.h, but there are also updated versions of these
- definitions that are compatible with 64-bit Windows. If you use the updated
- functions in your code, it can be compiled for both 32- and 64-bit Windows.
- Your code will also be more efficient, since the original functions simply
- call the updated functions to perform the work."
- However, using the updated functinos does not work on the Windows 32-bit.
- IMHO, in the MinGW cross compile environment rather than the Visual Studio
- it does not compile correctly.
- Thus, use explicitly.
-*/
static void dump_backtrace(void *ptr)
{
-#ifdef _WIN64
STACKFRAME64 frame;
-#else
- STACKFRAME frame;
-#endif
- int i;
DWORD image;
CONTEXT context;
HANDLE hProcess = GetCurrentProcess();
@@ -105,8 +85,8 @@ static void dump_backtrace(void *ptr)
SymInitialize(hProcess, NULL, TRUE);
-#ifdef _WIN64
ZeroMemory(&frame, sizeof(STACKFRAME64));
+#ifdef _WIN64
image = IMAGE_FILE_MACHINE_AMD64;
frame.AddrPC.Offset = context.Rip;
frame.AddrPC.Mode = AddrModeFlat;
@@ -115,7 +95,6 @@ static void dump_backtrace(void *ptr)
frame.AddrStack.Offset = context.Rsp;
frame.AddrStack.Mode = AddrModeFlat;
#else
- ZeroMemory(&frame, sizeof(STACKFRAME));
image = IMAGE_FILE_MACHINE_I386;
frame.AddrPC.Offset = context.Eip;
frame.AddrPC.Mode = AddrModeFlat;
@@ -125,60 +104,41 @@ static void dump_backtrace(void *ptr)
frame.AddrStack.Mode = AddrModeFlat;
#endif
- i = 0;
- while (1) {
-#ifdef _WIN64
- BOOL result = StackWalk64(image, hProcess, hThread,
+ int i = 0;
+ BOOL result = FALSE;
+ while ((result = StackWalk64(image, hProcess, hThread,
&frame, &context, NULL,
SymFunctionTableAccess64,
- SymGetModuleBase64, NULL);
-#else
- BOOL result = StackWalk(image, hProcess, hThread,
- &frame, &context, NULL,
- SymFunctionTableAccess,
- SymGetModuleBase, NULL);
-#endif
- if (!result) {
- break;
- }
+ SymGetModuleBase64, NULL)) == TRUE) {
TCHAR buffer[sizeof(SYMBOL_INFO) + (MAX_SYM_NAME - 1) * sizeof(TCHAR)];
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;
DWORD64 displacement = 0;
TCHAR pFileName[MAX_PATH] = {0, };
-#ifdef _WIN64
DWORD64 dwBase = SymGetModuleBase64(hProcess, frame.AddrPC.Offset);
-#else
- DWORD dwBase = SymGetModuleBase(hProcess, frame.AddrPC.Offset);
-#endif
if (dwBase) {
- HMODULE hModule = (HMODULE)((DWORD_PTR)dwBase);
- if (!GetModuleFileNameA(hModule, pFileName, MAX_PATH)) {
+ if (!GetModuleFileNameA((HMODULE)(intptr_t)dwBase, pFileName,
+ MAX_PATH)) {
snprintf(pFileName, MAX_PATH, "Unknown Module");
}
}
/* TODO: take the symbols for the static functions
without import .pdb */
- if (SymFromAddr(hProcess,
- frame.AddrPC.Offset,
- &displacement, pSymbol)) {
-#ifdef _WIN64
- LOG_INFO("#%04d 0x%016I64x in %s from %s\n",
-#else
- LOG_INFO("#%04d 0x%08x in %s from %s\n",
-#endif
- i, frame.AddrPC.Offset, pSymbol->Name, pFileName);
- } else {
+ if (!SymFromAddr(hProcess,
+ frame.AddrPC.Offset,
+ &displacement, pSymbol)) {
+ g_strlcpy(pSymbol->Name, "????????", MAX_SYM_NAME);
+ }
#ifdef _WIN64
- LOG_INFO("#%04d 0x%016I64x in ???????? from %s\n",
+ LOG_INFO("#%04d 0x%016" PRIx64 " in %s from %s\n",
#else
- LOG_INFO("#%04d 0x%08x in ???????? from %s\n",
+ LOG_INFO("#%04d 0x%08" PRIx64 " in %s from %s\n",
#endif
- i, frame.AddrPC.Offset, pFileName);
- }
+ i, frame.AddrPC.Offset, pSymbol->Name, pFileName);
i++;
}
+
SymCleanup(hProcess);
}