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 GDB_TARGET_DEBUG_H
21 #define GDB_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
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. */
42 #include "gdbsupport/x86-xstate.h"
43 #include "progspace.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. */
53 target_debug_print_target_object (target_object object
)
54 { return plongest (object
); }
57 target_debug_print_CORE_ADDR (CORE_ADDR addr
)
58 { return core_addr_to_string (addr
); }
61 target_debug_print_const_char_p (const char *s
)
62 { return s
!= nullptr ? s
: "(null)"; }
65 target_debug_print_int (int v
)
66 { return plongest (v
); }
69 target_debug_print_bool (bool v
)
70 { return v
? "true" : "false"; }
73 target_debug_print_long (long v
)
74 { return plongest (v
); }
77 target_debug_print_target_xfer_status (target_xfer_status status
)
78 { return plongest (status
); }
81 target_debug_print_exec_direction_kind (exec_direction_kind kind
)
82 { return plongest (kind
); }
85 target_debug_print_trace_find_type (trace_find_type type
)
86 { return plongest (type
); }
89 target_debug_print_btrace_read_type (btrace_read_type type
)
90 { return plongest (type
); }
93 target_debug_print_btrace_error (btrace_error error
)
94 { return plongest (error
); }
97 target_debug_print_ptid_t (ptid_t ptid
)
98 { return plongest (ptid
.pid ()); }
101 target_debug_print_gdbarch_p (gdbarch
*arch
)
102 { return gdbarch_bfd_arch_info (arch
)->printable_name
; }
105 target_debug_print_const_gdb_byte_p (const gdb_byte
*p
)
106 { return host_address_to_string (p
); }
109 target_debug_print_gdb_byte_p (gdb_byte
*p
)
110 { return host_address_to_string (p
); }
113 target_debug_print_const_gdb_byte_pp (const gdb_byte
**p
)
114 { return host_address_to_string (*p
); }
117 target_debug_print_gdb_signal (gdb_signal sig
)
118 { return gdb_signal_to_name (sig
); }
121 target_debug_print_ULONGEST (ULONGEST v
)
122 { return hex_string (v
); }
125 target_debug_print_ULONGEST_p (ULONGEST
*p
)
126 { return hex_string (*p
); }
129 target_debug_print_LONGEST (LONGEST v
)
130 { return phex (v
, 0); }
133 target_debug_print_LONGEST_p (LONGEST
*p
)
134 { return phex (*p
, 0); }
137 target_debug_print_bp_target_info_p (bp_target_info
*bp
)
138 { return core_addr_to_string (bp
->placed_address
); }
141 target_debug_print_expression_p (expression
*exp
)
142 { return host_address_to_string (exp
); }
145 target_debug_print_CORE_ADDR_p (CORE_ADDR
*p
)
146 { return core_addr_to_string (*p
); }
149 target_debug_print_int_p (int *p
)
150 { return plongest (*p
); }
153 target_debug_print_regcache_p (regcache
*regcache
)
154 { return host_address_to_string (regcache
); }
157 target_debug_print_thread_info_p (thread_info
*thread
)
158 { return host_address_to_string (thread
); }
161 target_debug_print_ui_file_p (ui_file
*file
)
162 { return host_address_to_string (file
); }
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 ()); }
170 target_debug_print_void_p (void *p
)
171 { return host_address_to_string (p
); }
174 target_debug_print_find_memory_region_ftype (find_memory_region_ftype func
)
175 { return host_address_to_string (func
); }
178 target_debug_print_bfd_p (bfd
*bfd
)
179 { return host_address_to_string (bfd
); }
182 target_debug_print_std_vector_mem_region (const std::vector
<mem_region
> &vec
)
183 { return host_address_to_string (vec
.data ()); }
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 ()); }
191 target_debug_print_const_target_desc_p (const target_desc
*tdesc
)
192 { return host_address_to_string (tdesc
); }
195 target_debug_print_bp_location_p (bp_location
*loc
)
196 { return host_address_to_string (loc
); }
199 target_debug_print_const_trace_state_variable_r
200 (const trace_state_variable
&tsv
)
201 { return host_address_to_string (&tsv
); }
204 target_debug_print_trace_status_p (trace_status
*status
)
205 { return host_address_to_string (status
); }
208 target_debug_print_tracepoint_p (tracepoint
*tp
)
209 { return host_address_to_string (tp
); }
212 target_debug_print_uploaded_tp_p (uploaded_tp
*tp
)
213 { return host_address_to_string (tp
); }
216 target_debug_print_uploaded_tp_pp (uploaded_tp
**v
)
217 { return host_address_to_string (*v
); }
220 target_debug_print_uploaded_tsv_pp (uploaded_tsv
**tsv
)
221 { return host_address_to_string (tsv
); }
224 target_debug_print_static_tracepoint_marker_p (static_tracepoint_marker
*marker
)
225 { return host_address_to_string (marker
); }
228 target_debug_print_btrace_target_info_p (btrace_target_info
*info
)
229 { return host_address_to_string (info
); }
232 target_debug_print_const_frame_unwind_p (const frame_unwind
*fu
)
233 { return host_address_to_string (fu
); }
236 target_debug_print_btrace_data_p (btrace_data
*data
)
237 { return host_address_to_string (data
); }
240 target_debug_print_record_method (record_method method
)
241 { return plongest (method
); }
244 target_debug_print_const_btrace_config_p (const btrace_config
*config
)
245 { return host_address_to_string (config
); }
248 target_debug_print_const_btrace_target_info_p (const btrace_target_info
*info
)
249 { return host_address_to_string (info
); }
252 target_debug_print_target_hw_bp_type (target_hw_bp_type type
)
253 { return plongest (type
); }
256 target_debug_print_bptype (bptype type
)
257 { return plongest (type
); }
260 target_debug_print_inferior_p (inferior
*inf
)
261 { return host_address_to_string (inf
); }
264 target_debug_print_remove_bp_reason (remove_bp_reason reason
)
265 { return plongest (reason
); }
268 target_debug_print_gdb_disassembly_flags (gdb_disassembly_flags flags
)
269 { return plongest (flags
); }
272 target_debug_print_traceframe_info_up (std::unique_ptr
<traceframe_info
> &info
)
273 { return host_address_to_string (info
.get ()); }
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 ()); }
281 target_debug_print_record_print_flags (record_print_flags flags
)
282 { return plongest (flags
); }
285 target_debug_print_thread_control_capabilities (thread_control_capabilities cap
)
286 { return plongest (cap
); }
289 target_debug_print_std_string (const std::string
&str
)
290 { return str
.c_str (); }
293 target_debug_print_gdb_unique_xmalloc_ptr_char
294 (const gdb::unique_xmalloc_ptr
<char> &p
)
298 target_debug_print_target_waitkind (target_waitkind kind
)
299 { return pulongest (kind
); }
302 target_debug_print_gdb_thread_options (gdb_thread_options options
)
303 { return to_string (options
); }
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. */
312 target_debug_print_step (int step
)
313 { return step
? "step" : "continue"; }
316 target_debug_print_target_wait_flags (target_wait_flags options
)
317 { return target_options_to_string (options
); }
320 target_debug_print_signals (gdb::array_view
<const unsigned char> sigs
)
324 for (size_t i
= 0; i
< sigs
.size (); i
++)
326 string_appendf (s
, " %s",
327 gdb_signal_to_name (static_cast<gdb_signal
>(i
)));
335 target_debug_print_size_t (size_t size
)
337 return pulongest (size
);
341 target_debug_print_gdb_array_view_const_gdb_byte (gdb::array_view
<const gdb_byte
> vector
)
345 for (const auto b
: vector
)
346 string_appendf (s
, " %s", phex_nz (b
, 1));
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
); }
358 target_debug_print_gdb_byte_vector_r (gdb::byte_vector
&vector
)
359 { return target_debug_print_const_gdb_byte_vector_r (vector
); }
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);
382 #endif /* GDB_TARGET_DEBUG_H */