amd-dbgapi-target.h revision 1.1 1 1.1 christos /* Target used to communicate with the AMD Debugger API.
2 1.1 christos
3 1.1 christos Copyright (C) 2019-2024 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #ifndef AMD_DBGAPI_TARGET_H
21 1.1 christos #define AMD_DBGAPI_TARGET_H 1
22 1.1 christos
23 1.1 christos #include "gdbsupport/observable.h"
24 1.1 christos
25 1.1 christos #include <amd-dbgapi/amd-dbgapi.h>
26 1.1 christos
27 1.1 christos struct inferior;
28 1.1 christos
29 1.1 christos namespace detail
30 1.1 christos {
31 1.1 christos
32 1.1 christos template <typename T>
33 1.1 christos using is_amd_dbgapi_handle
34 1.1 christos = gdb::Or<std::is_same<T, amd_dbgapi_address_class_id_t>,
35 1.1 christos std::is_same<T, amd_dbgapi_address_space_id_t>,
36 1.1 christos std::is_same<T, amd_dbgapi_architecture_id_t>,
37 1.1 christos std::is_same<T, amd_dbgapi_agent_id_t>,
38 1.1 christos std::is_same<T, amd_dbgapi_breakpoint_id_t>,
39 1.1 christos std::is_same<T, amd_dbgapi_code_object_id_t>,
40 1.1 christos std::is_same<T, amd_dbgapi_dispatch_id_t>,
41 1.1 christos std::is_same<T, amd_dbgapi_displaced_stepping_id_t>,
42 1.1 christos std::is_same<T, amd_dbgapi_event_id_t>,
43 1.1 christos std::is_same<T, amd_dbgapi_process_id_t>,
44 1.1 christos std::is_same<T, amd_dbgapi_queue_id_t>,
45 1.1 christos std::is_same<T, amd_dbgapi_register_class_id_t>,
46 1.1 christos std::is_same<T, amd_dbgapi_register_id_t>,
47 1.1 christos std::is_same<T, amd_dbgapi_watchpoint_id_t>,
48 1.1 christos std::is_same<T, amd_dbgapi_wave_id_t>>;
49 1.1 christos
50 1.1 christos } /* namespace detail */
51 1.1 christos
52 1.1 christos /* Get the token of amd-dbgapi's inferior_created observer. */
53 1.1 christos
54 1.1 christos const gdb::observers::token &
55 1.1 christos get_amd_dbgapi_target_inferior_created_observer_token ();
56 1.1 christos
57 1.1 christos /* Comparison operators for amd-dbgapi handle types. */
58 1.1 christos
59 1.1 christos template <typename T,
60 1.1 christos typename = gdb::Requires<detail::is_amd_dbgapi_handle<T>>>
61 1.1 christos bool
62 1.1 christos operator== (const T &lhs, const T &rhs)
63 1.1 christos {
64 1.1 christos return lhs.handle == rhs.handle;
65 1.1 christos }
66 1.1 christos
67 1.1 christos template <typename T,
68 1.1 christos typename = gdb::Requires<detail::is_amd_dbgapi_handle<T>>>
69 1.1 christos bool
70 1.1 christos operator!= (const T &lhs, const T &rhs)
71 1.1 christos {
72 1.1 christos return !(lhs == rhs);
73 1.1 christos }
74 1.1 christos
75 1.1 christos /* Return true if the given ptid is a GPU thread (wave) ptid. */
76 1.1 christos
77 1.1 christos static inline bool
78 1.1 christos ptid_is_gpu (ptid_t ptid)
79 1.1 christos {
80 1.1 christos /* FIXME: Currently using values that are known not to conflict with other
81 1.1 christos processes to indicate if it is a GPU thread. ptid.pid 1 is the init
82 1.1 christos process and is the only process that could have a ptid.lwp of 1. The init
83 1.1 christos process cannot have a GPU. No other process can have a ptid.lwp of 1.
84 1.1 christos The GPU wave ID is stored in the ptid.tid. */
85 1.1 christos return ptid.pid () != 1 && ptid.lwp () == 1;
86 1.1 christos }
87 1.1 christos
88 1.1 christos /* Return INF's amd_dbgapi process id. */
89 1.1 christos
90 1.1 christos amd_dbgapi_process_id_t get_amd_dbgapi_process_id (inferior *inf);
91 1.1 christos
92 1.1 christos /* Get the amd-dbgapi wave id for PTID. */
93 1.1 christos
94 1.1 christos static inline amd_dbgapi_wave_id_t
95 1.1 christos get_amd_dbgapi_wave_id (ptid_t ptid)
96 1.1 christos {
97 1.1 christos gdb_assert (ptid_is_gpu (ptid));
98 1.1 christos return amd_dbgapi_wave_id_t {
99 1.1 christos static_cast<decltype (amd_dbgapi_wave_id_t::handle)> (ptid.tid ())
100 1.1 christos };
101 1.1 christos }
102 1.1 christos
103 1.1 christos /* Get the textual version of STATUS.
104 1.1 christos
105 1.1 christos Always returns non-nullptr, and asserts that STATUS has a valid value. */
106 1.1 christos
107 1.1 christos static inline const char *
108 1.1 christos get_status_string (amd_dbgapi_status_t status)
109 1.1 christos {
110 1.1 christos const char *ret;
111 1.1 christos status = amd_dbgapi_get_status_string (status, &ret);
112 1.1 christos gdb_assert (status == AMD_DBGAPI_STATUS_SUCCESS);
113 1.1 christos return ret;
114 1.1 christos }
115 1.1 christos
116 1.1 christos #endif /* AMD_DBGAPI_TARGET_H */
117