1 /* Target waitstatus definitions and prototypes.
3 Copyright (C) 1990-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef TARGET_WAITSTATUS_H
21 #define TARGET_WAITSTATUS_H
23 #include "diagnostics.h"
24 #include "gdbsupport/gdb_signals.h"
26 /* Stuff for target_wait. */
28 /* Generally, what has the program done? */
31 /* The program has exited. The exit status is in value.integer. */
32 TARGET_WAITKIND_EXITED
,
34 /* The program has stopped with a signal. Which signal is in
36 TARGET_WAITKIND_STOPPED
,
38 /* The program has terminated with a signal. Which signal is in
40 TARGET_WAITKIND_SIGNALLED
,
42 /* The program is letting us know that it dynamically loaded
43 something (e.g. it called load(2) on AIX). */
44 TARGET_WAITKIND_LOADED
,
46 /* The program has forked. A "related" process' PTID is in
47 value.related_pid. I.e., if the child forks, value.related_pid
48 is the parent's ID. */
49 TARGET_WAITKIND_FORKED
,
51 /* The program has vforked. A "related" process's PTID is in
53 TARGET_WAITKIND_VFORKED
,
55 /* The program has exec'ed a new executable file. The new file's
56 pathname is pointed to by value.execd_pathname. */
57 TARGET_WAITKIND_EXECD
,
59 /* The program had previously vforked, and now the child is done
60 with the shared memory region, because it exec'ed or exited.
61 Note that the event is reported to the vfork parent. This is
62 only used if GDB did not stay attached to the vfork child,
63 otherwise, a TARGET_WAITKIND_EXECD or
64 TARGET_WAITKIND_EXIT|SIGNALLED event associated with the child
65 has the same effect. */
66 TARGET_WAITKIND_VFORK_DONE
,
68 /* The program has entered or returned from a system call. On
69 HP-UX, this is used in the hardware watchpoint implementation.
70 The syscall's unique integer ID number is in
72 TARGET_WAITKIND_SYSCALL_ENTRY
,
73 TARGET_WAITKIND_SYSCALL_RETURN
,
75 /* Nothing happened, but we stopped anyway. This perhaps should
76 be handled within target_wait, but I'm not sure target_wait
77 should be resuming the inferior. */
78 TARGET_WAITKIND_SPURIOUS
,
80 /* An event has occured, but we should wait again.
81 Remote_async_wait() returns this when there is an event
82 on the inferior, but the rest of the world is not interested in
83 it. The inferior has not stopped, but has just sent some output
84 to the console, for instance. In this case, we want to go back
85 to the event loop and wait there for another event from the
86 inferior, rather than being stuck in the remote_async_wait()
87 function. This way the event loop is responsive to other events,
88 like for instance the user typing. */
89 TARGET_WAITKIND_IGNORE
,
91 /* The target has run out of history information,
92 and cannot run backward any further. */
93 TARGET_WAITKIND_NO_HISTORY
,
95 /* There are no resumed children left in the program. */
96 TARGET_WAITKIND_NO_RESUMED
,
98 /* The thread was created. */
99 TARGET_WAITKIND_THREAD_CREATED
,
101 /* The thread has exited. The exit status is in value.integer. */
102 TARGET_WAITKIND_THREAD_EXITED
,
105 /* Return KIND as a string. */
107 static inline const char *
108 target_waitkind_str (target_waitkind kind
)
110 /* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
111 but not handled here. */
113 DIAGNOSTIC_ERROR_SWITCH
116 case TARGET_WAITKIND_EXITED
:
118 case TARGET_WAITKIND_STOPPED
:
120 case TARGET_WAITKIND_SIGNALLED
:
122 case TARGET_WAITKIND_LOADED
:
124 case TARGET_WAITKIND_FORKED
:
126 case TARGET_WAITKIND_VFORKED
:
128 case TARGET_WAITKIND_EXECD
:
130 case TARGET_WAITKIND_VFORK_DONE
:
132 case TARGET_WAITKIND_SYSCALL_ENTRY
:
133 return "SYSCALL_ENTRY";
134 case TARGET_WAITKIND_SYSCALL_RETURN
:
135 return "SYSCALL_RETURN";
136 case TARGET_WAITKIND_SPURIOUS
:
138 case TARGET_WAITKIND_IGNORE
:
140 case TARGET_WAITKIND_NO_HISTORY
:
142 case TARGET_WAITKIND_NO_RESUMED
:
144 case TARGET_WAITKIND_THREAD_CREATED
:
145 return "THREAD_CREATED";
146 case TARGET_WAITKIND_THREAD_EXITED
:
147 return "THREAD_EXITED";
151 gdb_assert_not_reached ("invalid target_waitkind value: %d\n", (int) kind
);
154 struct target_waitstatus
156 /* Default constructor. */
157 target_waitstatus () = default;
159 /* Copy constructor. */
161 target_waitstatus (const target_waitstatus
&other
)
163 m_kind
= other
.m_kind
;
164 m_value
= other
.m_value
;
166 if (m_kind
== TARGET_WAITKIND_EXECD
)
167 m_value
.execd_pathname
= xstrdup (m_value
.execd_pathname
);
170 /* Move constructor. */
172 target_waitstatus (target_waitstatus
&&other
)
174 m_kind
= other
.m_kind
;
175 m_value
= other
.m_value
;
177 if (m_kind
== TARGET_WAITKIND_EXECD
)
178 other
.m_value
.execd_pathname
= nullptr;
183 /* Copy assignment operator. */
185 target_waitstatus
&operator= (const target_waitstatus
&rhs
)
189 m_value
= rhs
.m_value
;
191 if (m_kind
== TARGET_WAITKIND_EXECD
)
192 m_value
.execd_pathname
= xstrdup (m_value
.execd_pathname
);
197 /* Move assignment operator. */
199 target_waitstatus
&operator= (target_waitstatus
&&rhs
)
203 m_value
= rhs
.m_value
;
205 if (m_kind
== TARGET_WAITKIND_EXECD
)
206 rhs
.m_value
.execd_pathname
= nullptr;
215 ~target_waitstatus ()
220 /* Setters: set the wait status kind plus any associated data. */
222 target_waitstatus
&set_exited (int exit_status
)
225 m_kind
= TARGET_WAITKIND_EXITED
;
226 m_value
.exit_status
= exit_status
;
230 target_waitstatus
&set_stopped (gdb_signal sig
)
233 m_kind
= TARGET_WAITKIND_STOPPED
;
238 target_waitstatus
&set_signalled (gdb_signal sig
)
241 m_kind
= TARGET_WAITKIND_SIGNALLED
;
246 target_waitstatus
&set_loaded ()
249 m_kind
= TARGET_WAITKIND_LOADED
;
253 target_waitstatus
&set_forked (ptid_t child_ptid
)
256 m_kind
= TARGET_WAITKIND_FORKED
;
257 m_value
.child_ptid
= child_ptid
;
261 target_waitstatus
&set_vforked (ptid_t child_ptid
)
264 m_kind
= TARGET_WAITKIND_VFORKED
;
265 m_value
.child_ptid
= child_ptid
;
269 target_waitstatus
&set_execd (gdb::unique_xmalloc_ptr
<char> execd_pathname
)
272 m_kind
= TARGET_WAITKIND_EXECD
;
273 m_value
.execd_pathname
= execd_pathname
.release ();
277 target_waitstatus
&set_vfork_done ()
280 m_kind
= TARGET_WAITKIND_VFORK_DONE
;
284 target_waitstatus
&set_syscall_entry (int syscall_number
)
287 m_kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
288 m_value
.syscall_number
= syscall_number
;
292 target_waitstatus
&set_syscall_return (int syscall_number
)
295 m_kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
296 m_value
.syscall_number
= syscall_number
;
300 target_waitstatus
&set_spurious ()
303 m_kind
= TARGET_WAITKIND_SPURIOUS
;
307 target_waitstatus
&set_ignore ()
310 m_kind
= TARGET_WAITKIND_IGNORE
;
314 target_waitstatus
&set_no_history ()
317 m_kind
= TARGET_WAITKIND_NO_HISTORY
;
321 target_waitstatus
&set_no_resumed ()
324 m_kind
= TARGET_WAITKIND_NO_RESUMED
;
328 target_waitstatus
&set_thread_created ()
331 m_kind
= TARGET_WAITKIND_THREAD_CREATED
;
335 target_waitstatus
&set_thread_exited (int exit_status
)
338 m_kind
= TARGET_WAITKIND_THREAD_EXITED
;
339 m_value
.exit_status
= exit_status
;
343 /* Get the kind of this wait status. */
345 target_waitkind
kind () const
350 /* Getters for the associated data.
352 Getters can only be used if the wait status is of the appropriate kind.
353 See the setters above or the assertions below to know which data is
354 associated to which kind. */
356 int exit_status () const
358 gdb_assert (m_kind
== TARGET_WAITKIND_EXITED
359 || m_kind
== TARGET_WAITKIND_THREAD_EXITED
);
360 return m_value
.exit_status
;
363 gdb_signal
sig () const
365 gdb_assert (m_kind
== TARGET_WAITKIND_STOPPED
366 || m_kind
== TARGET_WAITKIND_SIGNALLED
);
370 ptid_t
child_ptid () const
372 gdb_assert (m_kind
== TARGET_WAITKIND_FORKED
373 || m_kind
== TARGET_WAITKIND_VFORKED
);
374 return m_value
.child_ptid
;
377 const char *execd_pathname () const
379 gdb_assert (m_kind
== TARGET_WAITKIND_EXECD
);
380 return m_value
.execd_pathname
;
383 int syscall_number () const
385 gdb_assert (m_kind
== TARGET_WAITKIND_SYSCALL_ENTRY
386 || m_kind
== TARGET_WAITKIND_SYSCALL_RETURN
);
387 return m_value
.syscall_number
;
390 /* Return a pretty printed form of target_waitstatus.
392 This is only meant to be used in debug messages, not for user-visible
394 std::string
to_string () const;
397 /* Reset the wait status to its original state. */
400 if (m_kind
== TARGET_WAITKIND_EXECD
)
401 xfree (m_value
.execd_pathname
);
403 m_kind
= TARGET_WAITKIND_IGNORE
;
406 target_waitkind m_kind
= TARGET_WAITKIND_IGNORE
;
408 /* Additional information about the event. */
415 /* Forked child pid */
418 char *execd_pathname
;
424 /* Extended reasons that can explain why a target/thread stopped for a
427 enum target_stop_reason
429 /* Either not stopped, or stopped for a reason that doesn't require
431 TARGET_STOPPED_BY_NO_REASON
,
433 /* Stopped by a software breakpoint. */
434 TARGET_STOPPED_BY_SW_BREAKPOINT
,
436 /* Stopped by a hardware breakpoint. */
437 TARGET_STOPPED_BY_HW_BREAKPOINT
,
439 /* Stopped by a watchpoint. */
440 TARGET_STOPPED_BY_WATCHPOINT
,
442 /* Stopped by a single step finishing. */
443 TARGET_STOPPED_BY_SINGLE_STEP
446 #endif /* TARGET_WAITSTATUS_H */