在gdb下加载DLL时出现奇怪的SEGFAULT

时间:2014-02-21 15:08:22

标签: c dll gdb segmentation-fault

我有一个小的C程序,它加载一个自定义DLL并使用一些函数。我可以从控制台运行该程序,它按预期工作。 (我在Windows XP上使用MinGW进行编译)

但是如果我从gdb运行它,当它加载DLL时,我得到:

56              ldll = LoadLibrary("gsp810.dll");
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x7c929af2 in ntdll!RtlpWaitForCriticalSection () from C:\WINDOWS\system32\ntdll.dll

奇怪的是,如果我在这一点上做了一个回溯,我会得到一个奇怪的Windows函数堆栈,它甚至不包含我自己的程序堆栈(见下文)。但是,如果我继续运行,它最终将返回到我的main()函数,一切似乎都恢复正常。该程序按预期工作,可以调用DLL中的函数。

(gdb) backtrace
#0  0x7c929af2 in ntdll!RtlpWaitForCriticalSection () from C:\WINDOWS\system32\ntdll.dll
#1  0x7c911046 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\system32\ntdll.dll
#2  0x00e161a0 in ?? ()
#3  0x77da6cf8 in RegCloseKey () from C:\WINDOWS\system32\advapi32.dll
#4  0x77da78e4 in RegOpenKeyExA () from C:\WINDOWS\system32\advapi32.dll
#5  0x77f44fcd in SHLWAPI!PathMakeSystemFolderW () from C:\WINDOWS\system32\shlwapi.dll
#6  0x77f452e8 in SHLWAPI!PathMakeSystemFolderW () from C:\WINDOWS\system32\shlwapi.dll
#7  0x77f45252 in SHLWAPI!PathMakeSystemFolderW () from C:\WINDOWS\system32\shlwapi.dll
#8  0x7c91118a in ntdll!LdrInitializeThunk () from C:\WINDOWS\system32\ntdll.dll
#9  0x77f40000 in ?? ()
#10 0x7c92b5d2 in ntdll!LdrFindResourceDirectory_U () from C:\WINDOWS\system32\ntdll.dll
#11 0x7c9262db in ntdll!RtlValidateUnicodeString () from C:\WINDOWS\system32\ntdll.dll
#12 0x7c92643d in ntdll!LdrLoadDll () from C:\WINDOWS\system32\ntdll.dll
#13 0x00000000 in ?? ()

这个SEGFAULT是正常的,还是表明DLL存在潜在问题?

编辑:好的,看起来问题出在DLL本身。我不明白的是gdb正在显示的回溯,因为它不包含我的应用程序中的函数。然后,在某个时刻,它以某种方式“切换”到我的堆栈,程序继续运行,好像什么也没发生。

Windows是否可能以某种方式“处理”分段错误,并将控制权返回给应用程序?

0 个答案:

没有答案