binutils-gdb/gdb/nat
Hannes Domani ac637ec30d Don't close thread handles provided by WaitForDebugEvent
I sometimes encountered a weird breakpoint failure when using start:

(gdb) start
Temporary breakpoint 2 at 0x40162d: file gdb-25911.c, line 4.
Starting program: C:\src\tests\gdb-25911.exe
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x401628

After trying a lot of combinations, I found a way to reproduce it:

(gdb) file gdb-25987.exe
Reading symbols from gdb-25987.exe...
(gdb) start
Temporary breakpoint 1 at 0x401638: file gdb-25987.cpp, line 13.
Starting program: C:\src\tests\gdb-25987.exe

Temporary breakpoint 1, main () at gdb-25987.cpp:13
13      int main() {
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
MyClass::call (this=0x3d20d0) at gdb-25987.cpp:8
8           *(char*)(nullptr) = 1;
(gdb) kill
Kill the program being debugged? (y or n) y
[Inferior 1 (process 1140) killed]
(gdb) file gdb-25911.exe
Load new symbol table from "gdb-25911.exe"? (y or n) y
Reading symbols from gdb-25911.exe...
(gdb) start
Temporary breakpoint 2 at 0x40162d: file gdb-25911.c, line 4.
Starting program: C:\src\tests\gdb-25911.exe
Warning:
Cannot insert breakpoint 2.
Cannot access memory at address 0x401628

Command aborted.

The actual failure was that ReadProcessMemory used a process handle that
was no longer valid.
And the underlying reason was that the windows_thread_info destructor
closes a thread handle that was provided earlier by WaitForDebugEvent.

But since this is not allowed (and it was actually already closed at this
point, and the handle value reused), this closed another still-needed handle.

gdb/ChangeLog:

2020-05-27  Hannes Domani  <ssbssa@yahoo.de>

	* nat/windows-nat.c (windows_thread_info::~windows_thread_info):
	Don't close thread handle.
2020-05-27 19:15:53 +02:00
..
aarch64-linux-hw-point.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
aarch64-linux-hw-point.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
aarch64-linux.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
aarch64-linux.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
aarch64-sve-linux-ptrace.c [AArch64] When unavailable, fetch VG from ptrace. 2020-03-19 12:51:31 -03:00
aarch64-sve-linux-ptrace.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
aarch64-sve-linux-sigcontext.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
amd64-linux-siginfo.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
amd64-linux-siginfo.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
fork-inferior.c gdb: fix darwin-nat.c build / adapt to multi-target 2020-01-23 14:55:50 -05:00
fork-inferior.h gdb: fix darwin-nat.c build / adapt to multi-target 2020-01-23 14:55:50 -05:00
gdb_ptrace.h gdb: remove HAVE_DECL_PTRACE 2020-03-20 11:57:49 -04:00
gdb_thread_db.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
glibc_thread_db.h Normalize include guards in gdb 2019-02-07 03:27:23 -07:00
linux-btrace.c Disable record btrace bts support for AMD processors 2020-05-14 17:56:33 -07:00
linux-btrace.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-namespaces.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-namespaces.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-nat.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-osdata.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-osdata.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-personality.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-personality.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-procfs.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-procfs.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-ptrace.c Remove use of <config.h> from gdb/nat/ 2020-01-14 16:25:04 -07:00
linux-ptrace.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-waitpid.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
linux-waitpid.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
mips-linux-watch.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
mips-linux-watch.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
ppc-linux.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
ppc-linux.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
riscv-linux-tdesc.c gdb/riscv: Update API for looking up target descriptions 2020-02-19 01:24:37 +00:00
riscv-linux-tdesc.h gdb/riscv: Update API for looking up target descriptions 2020-02-19 01:24:37 +00:00
windows-nat.c Don't close thread handles provided by WaitForDebugEvent 2020-05-27 19:15:53 +02:00
windows-nat.h Fix Windows debugging regression 2020-04-24 06:48:01 -06:00
x86-cpuid.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
x86-dregs.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
x86-dregs.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
x86-gcc-cpuid.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
x86-linux-dregs.c Remove use of <config.h> from gdb/nat/ 2020-01-14 16:25:04 -07:00
x86-linux-dregs.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
x86-linux.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
x86-linux.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00