xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/target/waitstatus.c (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1 /* Target waitstatus implementations.
2 
3    Copyright (C) 1990-2023 Free Software Foundation, Inc.
4 
5    This file is part of GDB.
6 
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.
11 
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.
16 
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/>.  */
19 
20 #include "gdbsupport/common-defs.h"
21 #include "waitstatus.h"
22 
23 /* See waitstatus.h.  */
24 
25 std::string
26 target_waitstatus::to_string () const
27 {
28   std::string str = string_printf
29     ("status->kind = %s", target_waitkind_str (this->kind ()));
30 
31 /* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
32    but not handled here.  */
33 DIAGNOSTIC_PUSH
34 DIAGNOSTIC_ERROR_SWITCH
35   switch (this->kind ())
36     {
37     case TARGET_WAITKIND_EXITED:
38     case TARGET_WAITKIND_THREAD_EXITED:
39       return string_appendf (str, ", exit_status = %d", this->exit_status ());
40 
41     case TARGET_WAITKIND_STOPPED:
42     case TARGET_WAITKIND_SIGNALLED:
43       return string_appendf (str, ", sig = %s",
44 			     gdb_signal_to_symbol_string (this->sig ()));
45 
46     case TARGET_WAITKIND_FORKED:
47     case TARGET_WAITKIND_VFORKED:
48       return string_appendf (str, ", child_ptid = %s",
49 			     this->child_ptid ().to_string ().c_str ());
50 
51     case TARGET_WAITKIND_EXECD:
52       return string_appendf (str, ", execd_pathname = %s",
53 			     this->execd_pathname ());
54 
55     case TARGET_WAITKIND_LOADED:
56     case TARGET_WAITKIND_VFORK_DONE:
57     case TARGET_WAITKIND_SPURIOUS:
58     case TARGET_WAITKIND_SYSCALL_ENTRY:
59     case TARGET_WAITKIND_SYSCALL_RETURN:
60     case TARGET_WAITKIND_IGNORE:
61     case TARGET_WAITKIND_NO_HISTORY:
62     case TARGET_WAITKIND_NO_RESUMED:
63     case TARGET_WAITKIND_THREAD_CREATED:
64       return str;
65     }
66 DIAGNOSTIC_POP
67 
68   gdb_assert_not_reached ("invalid target_waitkind value: %d",
69 			  (int) this->kind ());
70 }
71