[gdb/testsuite] Fix gdb.python/py-inferior.exp with -fsanitize=thread
[binutils-gdb.git] / gdb / target-debug.h
blob4a4e72e4bb9a469da6761b66263d717cac60ff4b
1 /* GDB target debugging macros
3 Copyright (C) 2014-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 #ifndef TARGET_DEBUG_H
21 #define TARGET_DEBUG_H
23 /* Printers for the debug target. Each prints an object of a given
24 type to a string that needn't be freed. Most printers are macros,
25 for brevity, but a few are static functions where more complicated
26 behavior is needed.
28 References to these printers are automatically generated by
29 make-target-delegates. See the generated file target-delegates-gen.c.
31 In a couple cases, a special printing function is defined and then
32 used via the TARGET_DEBUG_PRINTER macro. See target.h.
34 A few methods still have some explicit targetdebug code in
35 target.c. In most cases this is because target delegation hasn't
36 been done for the method; but individual cases vary. For instance,
37 target_store_registers does some special register printing that is
38 more simply done there, and target_xfer_partial additionally
39 bypasses the debug target. */
41 #include "gdbarch.h"
42 #include "gdbsupport/x86-xstate.h"
43 #include "progspace.h"
44 #include "target.h"
45 #include "target/wait.h"
46 #include "target/waitstatus.h"
48 /* The functions defined in this header file are not marked "inline", such
49 that any function not used by target-delegates-gen.c (the only user of this
50 file) will be flagged as unused. */
52 static std::string
53 target_debug_print_target_object (target_object object)
54 { return plongest (object); }
56 static std::string
57 target_debug_print_CORE_ADDR (CORE_ADDR addr)
58 { return core_addr_to_string (addr); }
60 static std::string
61 target_debug_print_const_char_p (const char *s)
62 { return s != nullptr ? s : "(null)"; }
64 static std::string
65 target_debug_print_int (int v)
66 { return plongest (v); }
68 static std::string
69 target_debug_print_bool (bool v)
70 { return v ? "true" : "false"; }
72 static std::string
73 target_debug_print_long (long v)
74 { return plongest (v); }
76 static std::string
77 target_debug_print_target_xfer_status (target_xfer_status status)
78 { return plongest (status); }
80 static std::string
81 target_debug_print_exec_direction_kind (exec_direction_kind kind)
82 { return plongest (kind); }
84 static std::string
85 target_debug_print_trace_find_type (trace_find_type type)
86 { return plongest (type); }
88 static std::string
89 target_debug_print_btrace_read_type (btrace_read_type type)
90 { return plongest (type); }
92 static std::string
93 target_debug_print_btrace_error (btrace_error error)
94 { return plongest (error); }
96 static std::string
97 target_debug_print_ptid_t (ptid_t ptid)
98 { return plongest (ptid.pid ()); }
100 static std::string
101 target_debug_print_gdbarch_p (gdbarch *arch)
102 { return gdbarch_bfd_arch_info (arch)->printable_name; }
104 static std::string
105 target_debug_print_const_gdb_byte_p (const gdb_byte *p)
106 { return host_address_to_string (p); }
108 static std::string
109 target_debug_print_gdb_byte_p (gdb_byte *p)
110 { return host_address_to_string (p); }
112 static std::string
113 target_debug_print_const_gdb_byte_pp (const gdb_byte **p)
114 { return host_address_to_string (*p); }
116 static std::string
117 target_debug_print_gdb_signal (gdb_signal sig)
118 { return gdb_signal_to_name (sig); }
120 static std::string
121 target_debug_print_ULONGEST (ULONGEST v)
122 { return hex_string (v); }
124 static std::string
125 target_debug_print_ULONGEST_p (ULONGEST *p)
126 { return hex_string (*p); }
128 static std::string
129 target_debug_print_LONGEST (LONGEST v)
130 { return phex (v, 0); }
132 static std::string
133 target_debug_print_LONGEST_p (LONGEST *p)
134 { return phex (*p, 0); }
136 static std::string
137 target_debug_print_bp_target_info_p (bp_target_info *bp)
138 { return core_addr_to_string (bp->placed_address); }
140 static std::string
141 target_debug_print_expression_p (expression *exp)
142 { return host_address_to_string (exp); }
144 static std::string
145 target_debug_print_CORE_ADDR_p (CORE_ADDR *p)
146 { return core_addr_to_string (*p); }
148 static std::string
149 target_debug_print_int_p (int *p)
150 { return plongest (*p); }
152 static std::string
153 target_debug_print_regcache_p (regcache *regcache)
154 { return host_address_to_string (regcache); }
156 static std::string
157 target_debug_print_thread_info_p (thread_info *thread)
158 { return host_address_to_string (thread); }
160 static std::string
161 target_debug_print_ui_file_p (ui_file *file)
162 { return host_address_to_string (file); }
164 static std::string
165 target_debug_print_const_std_vector_target_section_p
166 (const std::vector<target_section> *vec)
167 { return host_address_to_string (vec->data ()); }
169 static std::string
170 target_debug_print_void_p (void *p)
171 { return host_address_to_string (p); }
173 static std::string
174 target_debug_print_find_memory_region_ftype (find_memory_region_ftype func)
175 { return host_address_to_string (func); }
177 static std::string
178 target_debug_print_bfd_p (bfd *bfd)
179 { return host_address_to_string (bfd); }
181 static std::string
182 target_debug_print_std_vector_mem_region (const std::vector<mem_region> &vec)
183 { return host_address_to_string (vec.data ()); }
185 static std::string
186 target_debug_print_std_vector_static_tracepoint_marker
187 (const std::vector<static_tracepoint_marker> &vec)
188 { return host_address_to_string (vec.data ()); }
190 static std::string
191 target_debug_print_const_target_desc_p (const target_desc *tdesc)
192 { return host_address_to_string (tdesc); }
194 static std::string
195 target_debug_print_bp_location_p (bp_location *loc)
196 { return host_address_to_string (loc); }
198 static std::string
199 target_debug_print_const_trace_state_variable_r
200 (const trace_state_variable &tsv)
201 { return host_address_to_string (&tsv); }
203 static std::string
204 target_debug_print_trace_status_p (trace_status *status)
205 { return host_address_to_string (status); }
207 static std::string
208 target_debug_print_tracepoint_p (tracepoint *tp)
209 { return host_address_to_string (tp); }
211 static std::string
212 target_debug_print_uploaded_tp_p (uploaded_tp *tp)
213 { return host_address_to_string (tp); }
215 static std::string
216 target_debug_print_uploaded_tp_pp (uploaded_tp **v)
217 { return host_address_to_string (*v); }
219 static std::string
220 target_debug_print_uploaded_tsv_pp (uploaded_tsv **tsv)
221 { return host_address_to_string (tsv); }
223 static std::string
224 target_debug_print_static_tracepoint_marker_p (static_tracepoint_marker *marker)
225 { return host_address_to_string (marker); }
227 static std::string
228 target_debug_print_btrace_target_info_p (btrace_target_info *info)
229 { return host_address_to_string (info); }
231 static std::string
232 target_debug_print_const_frame_unwind_p (const frame_unwind *fu)
233 { return host_address_to_string (fu); }
235 static std::string
236 target_debug_print_btrace_data_p (btrace_data *data)
237 { return host_address_to_string (data); }
239 static std::string
240 target_debug_print_record_method (record_method method)
241 { return plongest (method); }
243 static std::string
244 target_debug_print_const_btrace_config_p (const btrace_config *config)
245 { return host_address_to_string (config); }
247 static std::string
248 target_debug_print_const_btrace_target_info_p (const btrace_target_info *info)
249 { return host_address_to_string (info); }
251 static std::string
252 target_debug_print_target_hw_bp_type (target_hw_bp_type type)
253 { return plongest (type); }
255 static std::string
256 target_debug_print_bptype (bptype type)
257 { return plongest (type); }
259 static std::string
260 target_debug_print_inferior_p (inferior *inf)
261 { return host_address_to_string (inf); }
263 static std::string
264 target_debug_print_remove_bp_reason (remove_bp_reason reason)
265 { return plongest (reason); }
267 static std::string
268 target_debug_print_gdb_disassembly_flags (gdb_disassembly_flags flags)
269 { return plongest (flags); }
271 static std::string
272 target_debug_print_traceframe_info_up (std::unique_ptr<traceframe_info> &info)
273 { return host_address_to_string (info.get ()); }
275 static std::string
276 target_debug_print_gdb_array_view_const_int
277 (const gdb::array_view<const int> &view)
278 { return host_address_to_string (view.data ()); }
280 static std::string
281 target_debug_print_record_print_flags (record_print_flags flags)
282 { return plongest (flags); }
284 static std::string
285 target_debug_print_thread_control_capabilities (thread_control_capabilities cap)
286 { return plongest (cap); }
288 static std::string
289 target_debug_print_std_string (const std::string &str)
290 { return str.c_str (); }
292 static std::string
293 target_debug_print_gdb_unique_xmalloc_ptr_char
294 (const gdb::unique_xmalloc_ptr<char> &p)
295 { return p.get (); }
297 static std::string
298 target_debug_print_target_waitkind (target_waitkind kind)
299 { return pulongest (kind); }
301 static std::string
302 target_debug_print_gdb_thread_options (gdb_thread_options options)
303 { return to_string (options); }
305 static std::string
306 target_debug_print_target_waitstatus_p (struct target_waitstatus *status)
307 { return status->to_string (); }
309 /* Functions that are used via TARGET_DEBUG_PRINTER. */
311 static std::string
312 target_debug_print_step (int step)
313 { return step ? "step" : "continue"; }
315 static std::string
316 target_debug_print_target_wait_flags (target_wait_flags options)
317 { return target_options_to_string (options); }
319 static std::string
320 target_debug_print_signals (gdb::array_view<const unsigned char> sigs)
322 std::string s = "{";
324 for (size_t i = 0; i < sigs.size (); i++)
325 if (sigs[i] != 0)
326 string_appendf (s, " %s",
327 gdb_signal_to_name (static_cast<gdb_signal>(i)));
329 s += " }";
331 return s;
334 static std::string
335 target_debug_print_size_t (size_t size)
337 return pulongest (size);
340 static std::string
341 target_debug_print_gdb_array_view_const_gdb_byte (gdb::array_view<const gdb_byte> vector)
343 std::string s = "{";
345 for (const auto b : vector)
346 string_appendf (s, " %s", phex_nz (b, 1));
348 s += " }";
350 return s;
353 static std::string
354 target_debug_print_const_gdb_byte_vector_r (const gdb::byte_vector &vector)
355 { return target_debug_print_gdb_array_view_const_gdb_byte (vector); }
357 static std::string
358 target_debug_print_gdb_byte_vector_r (gdb::byte_vector &vector)
359 { return target_debug_print_const_gdb_byte_vector_r (vector); }
361 static std::string
362 target_debug_print_x86_xsave_layout (const x86_xsave_layout &layout)
364 std::string s = string_printf ("{ sizeof_xsave=%d", layout.sizeof_xsave);
366 #define POFFS(region) \
367 if (layout.region##_offset != 0) \
368 string_appendf (s, ", " #region "_offset=%d", layout.region##_offset);
370 POFFS(avx);
371 POFFS(k);
372 POFFS(zmm_h);
373 POFFS(zmm);
374 POFFS(pkru);
376 #undef POFFS
378 s += " }";
380 return s;
382 #endif /* TARGET_DEBUG_H */