Fix null pointer dereference in process_debug_info()
[binutils-gdb.git] / gdb / target / waitstatus.c
blob30c0621326fd7ccb0fedc1e871da0c2a696a49a9
1 /* Target waitstatus implementations.
3 Copyright (C) 1990-2024 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 #include "waitstatus.h"
22 /* See waitstatus.h. */
24 std::string
25 target_waitstatus::to_string () const
27 std::string str = string_printf
28 ("status->kind = %s", target_waitkind_str (this->kind ()));
30 /* Make sure the compiler warns if a new TARGET_WAITKIND enumerator is added
31 but not handled here. */
32 DIAGNOSTIC_PUSH
33 DIAGNOSTIC_ERROR_SWITCH
34 switch (this->kind ())
36 case TARGET_WAITKIND_EXITED:
37 case TARGET_WAITKIND_THREAD_EXITED:
38 return string_appendf (str, ", exit_status = %d", this->exit_status ());
40 case TARGET_WAITKIND_STOPPED:
41 case TARGET_WAITKIND_SIGNALLED:
42 return string_appendf (str, ", sig = %s",
43 gdb_signal_to_symbol_string (this->sig ()));
45 case TARGET_WAITKIND_FORKED:
46 case TARGET_WAITKIND_VFORKED:
47 case TARGET_WAITKIND_THREAD_CLONED:
48 return string_appendf (str, ", child_ptid = %s",
49 this->child_ptid ().to_string ().c_str ());
51 case TARGET_WAITKIND_EXECD:
52 return string_appendf (str, ", execd_pathname = %s",
53 this->execd_pathname ());
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;
66 DIAGNOSTIC_POP
68 gdb_assert_not_reached ("invalid target_waitkind value: %d",
69 (int) this->kind ());