GNU Binutils with patches for OS216
修订版 | 50838d1be72ddd30e0b5f081933482424ae5a6b0 (tree) |
---|---|
时间 | 2020-06-19 07:17:01 |
作者 | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
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.
@@ -1,5 +1,25 @@ | ||
1 | 1 | 2020-06-18 Pedro Alves <palves@redhat.com> |
2 | 2 | |
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 | + | |
3 | 23 | * windows-nat.c (do_initial_windows_stuff): No longer set inferior_ptid. |
4 | 24 | |
5 | 25 | 2020-06-18 Pedro Alves <palves@redhat.com> |
@@ -36,7 +36,6 @@ DEBUG_EVENT current_event; | ||
36 | 36 | ContinueDebugEvent. */ |
37 | 37 | static DEBUG_EVENT last_wait_event; |
38 | 38 | |
39 | -windows_thread_info *current_windows_thread; | |
40 | 39 | DWORD desired_stop_thread_id = -1; |
41 | 40 | std::vector<pending_stop> pending_stops; |
42 | 41 | EXCEPTION_RECORD siginfo_er; |
@@ -180,9 +180,6 @@ extern enum gdb_signal last_sig; | ||
180 | 180 | stop. */ |
181 | 181 | extern DEBUG_EVENT current_event; |
182 | 182 | |
183 | -/* Info on currently selected thread */ | |
184 | -extern windows_thread_info *current_windows_thread; | |
185 | - | |
186 | 183 | /* The ID of the thread for which we anticipate a stop event. |
187 | 184 | Normally this is -1, meaning we'll accept an event in any |
188 | 185 | thread. */ |
@@ -317,7 +317,9 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target> | ||
317 | 317 | |
318 | 318 | bool stopped_by_sw_breakpoint () override |
319 | 319 | { |
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; | |
321 | 323 | } |
322 | 324 | |
323 | 325 | bool supports_stopped_by_sw_breakpoint () override |
@@ -356,6 +358,8 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target> | ||
356 | 358 | const char *thread_name (struct thread_info *) override; |
357 | 359 | |
358 | 360 | int get_windows_debug_event (int pid, struct target_waitstatus *ourstatus); |
361 | + | |
362 | + void do_initial_windows_stuff (DWORD pid, bool attaching); | |
359 | 363 | }; |
360 | 364 | |
361 | 365 | static windows_nat_target the_windows_nat_target; |
@@ -1131,11 +1135,15 @@ display_selector (HANDLE thread, DWORD sel) | ||
1131 | 1135 | static void |
1132 | 1136 | display_selectors (const char * args, int from_tty) |
1133 | 1137 | { |
1134 | - if (!current_windows_thread) | |
1138 | + if (inferior_ptid == null_ptid) | |
1135 | 1139 | { |
1136 | 1140 | puts_filtered ("Impossible to display selectors now.\n"); |
1137 | 1141 | return; |
1138 | 1142 | } |
1143 | + | |
1144 | + windows_thread_info *current_windows_thread | |
1145 | + = thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); | |
1146 | + | |
1139 | 1147 | if (!args) |
1140 | 1148 | { |
1141 | 1149 | #ifdef __x86_64__ |
@@ -1367,12 +1375,11 @@ fake_create_process (void) | ||
1367 | 1375 | (unsigned) GetLastError ()); |
1368 | 1376 | /* We can not debug anything in that case. */ |
1369 | 1377 | } |
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 */); | |
1376 | 1383 | return current_event.dwThreadId; |
1377 | 1384 | } |
1378 | 1385 |
@@ -1532,8 +1539,6 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1532 | 1539 | { |
1533 | 1540 | BOOL debug_event; |
1534 | 1541 | DWORD continue_status, event_code; |
1535 | - windows_thread_info *th; | |
1536 | - static windows_thread_info dummy_thread_info (0, 0, 0); | |
1537 | 1542 | DWORD thread_id = 0; |
1538 | 1543 | |
1539 | 1544 | /* 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, | ||
1545 | 1550 | thread_id = stop->thread_id; |
1546 | 1551 | *ourstatus = stop->status; |
1547 | 1552 | |
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; | |
1552 | 1556 | |
1553 | 1557 | return thread_id; |
1554 | 1558 | } |
@@ -1562,7 +1566,6 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1562 | 1566 | |
1563 | 1567 | event_code = current_event.dwDebugEventCode; |
1564 | 1568 | ourstatus->kind = TARGET_WAITKIND_SPURIOUS; |
1565 | - th = NULL; | |
1566 | 1569 | have_saved_context = 0; |
1567 | 1570 | |
1568 | 1571 | switch (event_code) |
@@ -1588,7 +1591,7 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1588 | 1591 | } |
1589 | 1592 | /* Record the existence of this thread. */ |
1590 | 1593 | thread_id = current_event.dwThreadId; |
1591 | - th = windows_add_thread | |
1594 | + windows_add_thread | |
1592 | 1595 | (ptid_t (current_event.dwProcessId, current_event.dwThreadId, 0), |
1593 | 1596 | current_event.u.CreateThread.hThread, |
1594 | 1597 | current_event.u.CreateThread.lpThreadLocalBase, |
@@ -1605,7 +1608,6 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1605 | 1608 | current_event.dwThreadId, 0), |
1606 | 1609 | current_event.u.ExitThread.dwExitCode, |
1607 | 1610 | false /* main_thread_p */); |
1608 | - th = &dummy_thread_info; | |
1609 | 1611 | break; |
1610 | 1612 | |
1611 | 1613 | case CREATE_PROCESS_DEBUG_EVENT: |
@@ -1619,7 +1621,7 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1619 | 1621 | |
1620 | 1622 | current_process_handle = current_event.u.CreateProcessInfo.hProcess; |
1621 | 1623 | /* Add the main thread. */ |
1622 | - th = windows_add_thread | |
1624 | + windows_add_thread | |
1623 | 1625 | (ptid_t (current_event.dwProcessId, |
1624 | 1626 | current_event.dwThreadId, 0), |
1625 | 1627 | current_event.u.CreateProcessInfo.hThread, |
@@ -1756,7 +1758,7 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1756 | 1758 | && windows_initialization_done) |
1757 | 1759 | { |
1758 | 1760 | 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); | |
1760 | 1762 | th->stopped_at_software_breakpoint = true; |
1761 | 1763 | th->pc_adjusted = false; |
1762 | 1764 | } |
@@ -1764,14 +1766,6 @@ windows_nat_target::get_windows_debug_event (int pid, | ||
1764 | 1766 | thread_id = 0; |
1765 | 1767 | CHECK (windows_continue (continue_status, desired_stop_thread_id, 0)); |
1766 | 1768 | } |
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 | - } | |
1775 | 1769 | |
1776 | 1770 | out: |
1777 | 1771 | return thread_id; |
@@ -1828,19 +1822,24 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, | ||
1828 | 1822 | { |
1829 | 1823 | ptid_t result = ptid_t (current_event.dwProcessId, retval, 0); |
1830 | 1824 | |
1831 | - if (current_windows_thread != nullptr) | |
1825 | + if (ourstatus->kind != TARGET_WAITKIND_EXITED | |
1826 | + && ourstatus->kind != TARGET_WAITKIND_SIGNALLED) | |
1832 | 1827 | { |
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) | |
1840 | 1831 | { |
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 | + } | |
1844 | 1843 | } |
1845 | 1844 | } |
1846 | 1845 |
@@ -1976,8 +1975,8 @@ windows_add_all_dlls (void) | ||
1976 | 1975 | } |
1977 | 1976 | } |
1978 | 1977 | |
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) | |
1981 | 1980 | { |
1982 | 1981 | int i; |
1983 | 1982 | struct inferior *inf; |
@@ -1993,8 +1992,8 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching) | ||
1993 | 1992 | #endif |
1994 | 1993 | current_event.dwProcessId = pid; |
1995 | 1994 | memset (¤t_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); | |
1998 | 1997 | disable_breakpoints_in_shlibs (); |
1999 | 1998 | windows_clear_solib (); |
2000 | 1999 | clear_proceed_status (0); |
@@ -2024,11 +2023,13 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching) | ||
2024 | 2023 | |
2025 | 2024 | windows_initialization_done = 0; |
2026 | 2025 | |
2026 | + ptid_t last_ptid; | |
2027 | + | |
2027 | 2028 | while (1) |
2028 | 2029 | { |
2029 | 2030 | struct target_waitstatus status; |
2030 | 2031 | |
2031 | - ops->wait (minus_one_ptid, &status, 0); | |
2032 | + last_ptid = this->wait (minus_one_ptid, &status, 0); | |
2032 | 2033 | |
2033 | 2034 | /* Note windows_wait returns TARGET_WAITKIND_SPURIOUS for thread |
2034 | 2035 | events. */ |
@@ -2036,9 +2037,11 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching) | ||
2036 | 2037 | && status.kind != TARGET_WAITKIND_SPURIOUS) |
2037 | 2038 | break; |
2038 | 2039 | |
2039 | - ops->resume (minus_one_ptid, 0, GDB_SIGNAL_0); | |
2040 | + this->resume (minus_one_ptid, 0, GDB_SIGNAL_0); | |
2040 | 2041 | } |
2041 | 2042 | |
2043 | + switch_to_thread (find_thread_ptid (this, last_ptid)); | |
2044 | + | |
2042 | 2045 | /* Now that the inferior has been started and all DLLs have been mapped, |
2043 | 2046 | we can iterate over all DLLs and load them in. |
2044 | 2047 |
@@ -2170,7 +2173,7 @@ windows_nat_target::attach (const char *args, int from_tty) | ||
2170 | 2173 | } |
2171 | 2174 | #endif |
2172 | 2175 | |
2173 | - do_initial_windows_stuff (this, pid, 1); | |
2176 | + do_initial_windows_stuff (pid, 1); | |
2174 | 2177 | target_terminal::ours (); |
2175 | 2178 | } |
2176 | 2179 |
@@ -2200,7 +2203,7 @@ windows_nat_target::detach (inferior *inf, int from_tty) | ||
2200 | 2203 | } |
2201 | 2204 | |
2202 | 2205 | x86_cleanup_dregs (); |
2203 | - inferior_ptid = null_ptid; | |
2206 | + switch_to_no_thread (); | |
2204 | 2207 | detach_inferior (inf); |
2205 | 2208 | |
2206 | 2209 | maybe_unpush_target (); |
@@ -3010,7 +3013,7 @@ windows_nat_target::create_inferior (const char *exec_file, | ||
3010 | 3013 | else |
3011 | 3014 | saw_create = 0; |
3012 | 3015 | |
3013 | - do_initial_windows_stuff (this, pi.dwProcessId, 0); | |
3016 | + do_initial_windows_stuff (pi.dwProcessId, 0); | |
3014 | 3017 | |
3015 | 3018 | /* windows_continue (DBG_CONTINUE, -1, 0); */ |
3016 | 3019 | } |