• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版50838d1be72ddd30e0b5f081933482424ae5a6b0 (tree)
时间2020-06-19 07:17:01
作者Pedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

Don't write to inferior_ptid in windows-nat.c, part II

Writing to inferior_ptid in
windows_nat_target::get_windows_debug_event is just incorrect and not
necessary. We'll report the event to GDB's core, which then takes
care of switching inferior_ptid / current thread.

Related (see windows_nat_target::get_windows_debug_event), there's
also a "current_windows_thread" global that is just begging to get out
of sync with core GDB's current thread. This patch removes it.
gdbserver already does not have an equivalent global in win32-low.cc.

gdb/ChangeLog:
2020-06-18 Pedro Alves <palves@redhat.com>

* nat/windows-nat.c (current_windows_thread): Remove.
* nat/windows-nat.h (current_windows_thread): Remove.
* windows-nat.c (windows_nat_target::stopped_by_sw_breakpoint):
Adjust.
(display_selectors): Adjust to fetch the current
windows_thread_info based on inferior_ptid.
(fake_create_process): No longer write to current_windows_thread.
(windows_nat_target::get_windows_debug_event):
Don't set inferior_ptid or current_windows_thread.
(windows_nat_target::wait): Adjust to not rely on
current_windows_thread.
(do_initial_windows_stuff): Now a method of windows_nat_target.
Switch to the last_ptid thread.
(windows_nat_target::attach): Adjust.
(windows_nat_target::detach): Use switch_to_no_thread instead of
writing to inferior_ptid directly.
(windows_nat_target::create_inferior): Adjust.

更改概述

差异

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,25 @@
11 2020-06-18 Pedro Alves <palves@redhat.com>
22
3+ * nat/windows-nat.c (current_windows_thread): Remove.
4+ * nat/windows-nat.h (current_windows_thread): Remove.
5+ * windows-nat.c (windows_nat_target::stopped_by_sw_breakpoint):
6+ Adjust.
7+ (display_selectors): Adjust to fetch the current
8+ windows_thread_info based on inferior_ptid.
9+ (fake_create_process): No longer write to current_windows_thread.
10+ (windows_nat_target::get_windows_debug_event):
11+ Don't set inferior_ptid or current_windows_thread.
12+ (windows_nat_target::wait): Adjust to not rely on
13+ current_windows_thread.
14+ (do_initial_windows_stuff): Now a method of windows_nat_target.
15+ Switch to the last_ptid thread.
16+ (windows_nat_target::attach): Adjust.
17+ (windows_nat_target::detach): Use switch_to_no_thread instead of
18+ writing to inferior_ptid directly.
19+ (windows_nat_target::create_inferior): Adjust.
20+
21+2020-06-18 Pedro Alves <palves@redhat.com>
22+
323 * windows-nat.c (do_initial_windows_stuff): No longer set inferior_ptid.
424
525 2020-06-18 Pedro Alves <palves@redhat.com>
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -36,7 +36,6 @@ DEBUG_EVENT current_event;
3636 ContinueDebugEvent. */
3737 static DEBUG_EVENT last_wait_event;
3838
39-windows_thread_info *current_windows_thread;
4039 DWORD desired_stop_thread_id = -1;
4140 std::vector<pending_stop> pending_stops;
4241 EXCEPTION_RECORD siginfo_er;
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -180,9 +180,6 @@ extern enum gdb_signal last_sig;
180180 stop. */
181181 extern DEBUG_EVENT current_event;
182182
183-/* Info on currently selected thread */
184-extern windows_thread_info *current_windows_thread;
185-
186183 /* The ID of the thread for which we anticipate a stop event.
187184 Normally this is -1, meaning we'll accept an event in any
188185 thread. */
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -317,7 +317,9 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
317317
318318 bool stopped_by_sw_breakpoint () override
319319 {
320- return current_windows_thread->stopped_at_software_breakpoint;
320+ windows_thread_info *th
321+ = thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT);
322+ return th->stopped_at_software_breakpoint;
321323 }
322324
323325 bool supports_stopped_by_sw_breakpoint () override
@@ -356,6 +358,8 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
356358 const char *thread_name (struct thread_info *) override;
357359
358360 int get_windows_debug_event (int pid, struct target_waitstatus *ourstatus);
361+
362+ void do_initial_windows_stuff (DWORD pid, bool attaching);
359363 };
360364
361365 static windows_nat_target the_windows_nat_target;
@@ -1131,11 +1135,15 @@ display_selector (HANDLE thread, DWORD sel)
11311135 static void
11321136 display_selectors (const char * args, int from_tty)
11331137 {
1134- if (!current_windows_thread)
1138+ if (inferior_ptid == null_ptid)
11351139 {
11361140 puts_filtered ("Impossible to display selectors now.\n");
11371141 return;
11381142 }
1143+
1144+ windows_thread_info *current_windows_thread
1145+ = thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT);
1146+
11391147 if (!args)
11401148 {
11411149 #ifdef __x86_64__
@@ -1367,12 +1375,11 @@ fake_create_process (void)
13671375 (unsigned) GetLastError ());
13681376 /* We can not debug anything in that case. */
13691377 }
1370- current_windows_thread
1371- = windows_add_thread (ptid_t (current_event.dwProcessId,
1372- current_event.dwThreadId, 0),
1373- current_event.u.CreateThread.hThread,
1374- current_event.u.CreateThread.lpThreadLocalBase,
1375- true /* main_thread_p */);
1378+ windows_add_thread (ptid_t (current_event.dwProcessId, 0,
1379+ current_event.dwThreadId),
1380+ current_event.u.CreateThread.hThread,
1381+ current_event.u.CreateThread.lpThreadLocalBase,
1382+ true /* main_thread_p */);
13761383 return current_event.dwThreadId;
13771384 }
13781385
@@ -1532,8 +1539,6 @@ windows_nat_target::get_windows_debug_event (int pid,
15321539 {
15331540 BOOL debug_event;
15341541 DWORD continue_status, event_code;
1535- windows_thread_info *th;
1536- static windows_thread_info dummy_thread_info (0, 0, 0);
15371542 DWORD thread_id = 0;
15381543
15391544 /* If there is a relevant pending stop, report it now. See the
@@ -1545,10 +1550,9 @@ windows_nat_target::get_windows_debug_event (int pid,
15451550 thread_id = stop->thread_id;
15461551 *ourstatus = stop->status;
15471552
1548- inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
1549- current_windows_thread = thread_rec (inferior_ptid,
1550- INVALIDATE_CONTEXT);
1551- current_windows_thread->reload_context = 1;
1553+ ptid_t ptid (current_event.dwProcessId, thread_id);
1554+ windows_thread_info *th = thread_rec (ptid, INVALIDATE_CONTEXT);
1555+ th->reload_context = 1;
15521556
15531557 return thread_id;
15541558 }
@@ -1562,7 +1566,6 @@ windows_nat_target::get_windows_debug_event (int pid,
15621566
15631567 event_code = current_event.dwDebugEventCode;
15641568 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
1565- th = NULL;
15661569 have_saved_context = 0;
15671570
15681571 switch (event_code)
@@ -1588,7 +1591,7 @@ windows_nat_target::get_windows_debug_event (int pid,
15881591 }
15891592 /* Record the existence of this thread. */
15901593 thread_id = current_event.dwThreadId;
1591- th = windows_add_thread
1594+ windows_add_thread
15921595 (ptid_t (current_event.dwProcessId, current_event.dwThreadId, 0),
15931596 current_event.u.CreateThread.hThread,
15941597 current_event.u.CreateThread.lpThreadLocalBase,
@@ -1605,7 +1608,6 @@ windows_nat_target::get_windows_debug_event (int pid,
16051608 current_event.dwThreadId, 0),
16061609 current_event.u.ExitThread.dwExitCode,
16071610 false /* main_thread_p */);
1608- th = &dummy_thread_info;
16091611 break;
16101612
16111613 case CREATE_PROCESS_DEBUG_EVENT:
@@ -1619,7 +1621,7 @@ windows_nat_target::get_windows_debug_event (int pid,
16191621
16201622 current_process_handle = current_event.u.CreateProcessInfo.hProcess;
16211623 /* Add the main thread. */
1622- th = windows_add_thread
1624+ windows_add_thread
16231625 (ptid_t (current_event.dwProcessId,
16241626 current_event.dwThreadId, 0),
16251627 current_event.u.CreateProcessInfo.hThread,
@@ -1756,7 +1758,7 @@ windows_nat_target::get_windows_debug_event (int pid,
17561758 && windows_initialization_done)
17571759 {
17581760 ptid_t ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
1759- th = thread_rec (ptid, INVALIDATE_CONTEXT);
1761+ windows_thread_info *th = thread_rec (ptid, INVALIDATE_CONTEXT);
17601762 th->stopped_at_software_breakpoint = true;
17611763 th->pc_adjusted = false;
17621764 }
@@ -1764,14 +1766,6 @@ windows_nat_target::get_windows_debug_event (int pid,
17641766 thread_id = 0;
17651767 CHECK (windows_continue (continue_status, desired_stop_thread_id, 0));
17661768 }
1767- else
1768- {
1769- inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
1770- current_windows_thread = th;
1771- if (!current_windows_thread)
1772- current_windows_thread = thread_rec (inferior_ptid,
1773- INVALIDATE_CONTEXT);
1774- }
17751769
17761770 out:
17771771 return thread_id;
@@ -1828,19 +1822,24 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
18281822 {
18291823 ptid_t result = ptid_t (current_event.dwProcessId, retval, 0);
18301824
1831- if (current_windows_thread != nullptr)
1825+ if (ourstatus->kind != TARGET_WAITKIND_EXITED
1826+ && ourstatus->kind != TARGET_WAITKIND_SIGNALLED)
18321827 {
1833- current_windows_thread->stopped_at_software_breakpoint = false;
1834- if (current_event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT
1835- && ((current_event.u.Exception.ExceptionRecord.ExceptionCode
1836- == EXCEPTION_BREAKPOINT)
1837- || (current_event.u.Exception.ExceptionRecord.ExceptionCode
1838- == STATUS_WX86_BREAKPOINT))
1839- && windows_initialization_done)
1828+ windows_thread_info *th = thread_rec (result, INVALIDATE_CONTEXT);
1829+
1830+ if (th != nullptr)
18401831 {
1841- current_windows_thread->stopped_at_software_breakpoint
1842- = true;
1843- current_windows_thread->pc_adjusted = false;
1832+ th->stopped_at_software_breakpoint = false;
1833+ if (current_event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT
1834+ && ((current_event.u.Exception.ExceptionRecord.ExceptionCode
1835+ == EXCEPTION_BREAKPOINT)
1836+ || (current_event.u.Exception.ExceptionRecord.ExceptionCode
1837+ == STATUS_WX86_BREAKPOINT))
1838+ && windows_initialization_done)
1839+ {
1840+ th->stopped_at_software_breakpoint = true;
1841+ th->pc_adjusted = false;
1842+ }
18441843 }
18451844 }
18461845
@@ -1976,8 +1975,8 @@ windows_add_all_dlls (void)
19761975 }
19771976 }
19781977
1979-static void
1980-do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
1978+void
1979+windows_nat_target::do_initial_windows_stuff (DWORD pid, bool attaching)
19811980 {
19821981 int i;
19831982 struct inferior *inf;
@@ -1993,8 +1992,8 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
19931992 #endif
19941993 current_event.dwProcessId = pid;
19951994 memset (&current_event, 0, sizeof (current_event));
1996- if (!target_is_pushed (ops))
1997- push_target (ops);
1995+ if (!target_is_pushed (this))
1996+ push_target (this);
19981997 disable_breakpoints_in_shlibs ();
19991998 windows_clear_solib ();
20001999 clear_proceed_status (0);
@@ -2024,11 +2023,13 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
20242023
20252024 windows_initialization_done = 0;
20262025
2026+ ptid_t last_ptid;
2027+
20272028 while (1)
20282029 {
20292030 struct target_waitstatus status;
20302031
2031- ops->wait (minus_one_ptid, &status, 0);
2032+ last_ptid = this->wait (minus_one_ptid, &status, 0);
20322033
20332034 /* Note windows_wait returns TARGET_WAITKIND_SPURIOUS for thread
20342035 events. */
@@ -2036,9 +2037,11 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
20362037 && status.kind != TARGET_WAITKIND_SPURIOUS)
20372038 break;
20382039
2039- ops->resume (minus_one_ptid, 0, GDB_SIGNAL_0);
2040+ this->resume (minus_one_ptid, 0, GDB_SIGNAL_0);
20402041 }
20412042
2043+ switch_to_thread (find_thread_ptid (this, last_ptid));
2044+
20422045 /* Now that the inferior has been started and all DLLs have been mapped,
20432046 we can iterate over all DLLs and load them in.
20442047
@@ -2170,7 +2173,7 @@ windows_nat_target::attach (const char *args, int from_tty)
21702173 }
21712174 #endif
21722175
2173- do_initial_windows_stuff (this, pid, 1);
2176+ do_initial_windows_stuff (pid, 1);
21742177 target_terminal::ours ();
21752178 }
21762179
@@ -2200,7 +2203,7 @@ windows_nat_target::detach (inferior *inf, int from_tty)
22002203 }
22012204
22022205 x86_cleanup_dregs ();
2203- inferior_ptid = null_ptid;
2206+ switch_to_no_thread ();
22042207 detach_inferior (inf);
22052208
22062209 maybe_unpush_target ();
@@ -3010,7 +3013,7 @@ windows_nat_target::create_inferior (const char *exec_file,
30103013 else
30113014 saw_create = 0;
30123015
3013- do_initial_windows_stuff (this, pi.dwProcessId, 0);
3016+ do_initial_windows_stuff (pi.dwProcessId, 0);
30143017
30153018 /* windows_continue (DBG_CONTINUE, -1, 0); */
30163019 }