This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
gdb fails to resume after "DebugBreak" (SigTrap)
- From: Martin <lazarus at mfriebe dot de>
- To: gdb at sourceware dot org
- Date: Wed, 21 Mar 2012 15:54:35 +0000
- Subject: gdb fails to resume after "DebugBreak" (SigTrap)
Here is an issue I discovered with GDB. Unfortunately, I have no exact
steps for reproduction. (I have an app using Lazarus and FreePascal,
that can reproduce it, but that is too big)
The problem is, if an app, receives a "pause request" while already
paused. GDB will then fail to resume.
I believe this is a windows problem. (All GDB I use are from the mingw site)
It appears that the issue may have been fixed in 7.0.50 (was still
present in 7.0.0) and been re-introduced in 7.3. At least I have not yet
been able to get it with any of the versions in between. (But it might
just have been luck)
Anyway here is what I have.
1)
In order to interrupt a debugged app on windows, the following functions
are used. (pascal, but should be similar in other languages)
DebugBreakAddr := GetProcAddress(GetModuleHandle(kernel32),
'DebugBreak');
CreatRThread :=
GetProcAddress(GetModuleHandle(kernel32)'CreateRemoteThread');
Then the proccess is opened:
OpenProcess(PROCESS_CREATE_THREAD or PROCESS_QUERY_INFORMATION or
PROCESS_VM_OPERATION or PROCESS_VM_WRITE or PROCESS_VM_READ, False,
TargetPID);
hThread := CreatRThread (hProcess, nil, 0, DebugBreakAddr, nil, 0,
FPauseRequestInThreadID);
AFAIK This will lead to a SigTrap being sent to the app, and gdb will
interrupt the app.
2)
if the app has reached a breakpoint, and is in paused state, then if the
above signal is sent it will be seen by gdb, as soon as gdb continues
the app.
gdb will correctly stop, in response to the SigTrap:
*stopped,reason="signal-received",signal-name="SIGTRAP",signal-meaning="Trace/breakpoint
trap",frame={addr="0x77b5884f",func="ntdll!DbgUiConvertStateChangeStructure",args=[],from="C:\\Windows\\system32\\ntdll.dll"},thread-id="2",stopped-threads="all"
Trying to continue the app, sometimes result in this error:
-exec-continue
^running
*running,thread-id="all"
(gdb)
&"warning: SuspendThread failed. (winerr 5)\n"
^error,msg="PC register is not available"
(gdb)
Earlier version (6.x) of gdb, would just return the app "exited
normally" (despite it certainly didn't exit "normally", as it did not
finish)