target-debug.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* GDB target debugging macros
  2. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef TARGET_DEBUG_H
  15. #define TARGET_DEBUG_H
  16. /* Printers for the debug target. Each prints an object of a given
  17. type to a string that needn't be freed. Most printers are macros,
  18. for brevity, but a few are static functions where more complicated
  19. behavior is needed.
  20. References to these printers are automatically generated by
  21. make-target-delegates. See the generated file target-delegates.c.
  22. In a couple cases, a special printing function is defined and then
  23. used via the TARGET_DEBUG_PRINTER macro. See target.h.
  24. A few methods still have some explicit targetdebug code in
  25. target.c. In most cases this is because target delegation hasn't
  26. been done for the method; but individual cases vary. For instance,
  27. target_store_registers does some special register printing that is
  28. more simply done there, and target_xfer_partial additionally
  29. bypasses the debug target. */
  30. /* Helper macro. */
  31. #define target_debug_do_print(E) \
  32. gdb_puts ((E), gdb_stdlog);
  33. #define target_debug_print_enum_target_object(X) \
  34. target_debug_do_print (plongest (X))
  35. #define target_debug_print_CORE_ADDR(X) \
  36. target_debug_do_print (core_addr_to_string (X))
  37. #define target_debug_print_const_char_p(X) \
  38. target_debug_do_print (((X) ? (X) : "(null)"))
  39. #define target_debug_print_char_p(X) \
  40. target_debug_do_print (((X) ? (X) : "(null)"))
  41. #define target_debug_print_int(X) \
  42. target_debug_do_print (plongest (X))
  43. #define target_debug_print_bool(X) \
  44. target_debug_do_print ((X) ? "true" : "false")
  45. #define target_debug_print_long(X) \
  46. target_debug_do_print (plongest (X))
  47. #define target_debug_print_enum_target_xfer_status(X) \
  48. target_debug_do_print (plongest (X))
  49. #define target_debug_print_enum_exec_direction_kind(X) \
  50. target_debug_do_print (plongest (X))
  51. #define target_debug_print_enum_trace_find_type(X) \
  52. target_debug_do_print (plongest (X))
  53. #define target_debug_print_enum_btrace_read_type(X) \
  54. target_debug_do_print (plongest (X))
  55. #define target_debug_print_enum_btrace_error(X) \
  56. target_debug_do_print (plongest (X))
  57. #define target_debug_print_ptid_t(X) \
  58. target_debug_do_print (plongest (X.pid ()))
  59. #define target_debug_print_struct_gdbarch_p(X) \
  60. target_debug_do_print (gdbarch_bfd_arch_info (X)->printable_name)
  61. #define target_debug_print_const_gdb_byte_p(X) \
  62. target_debug_do_print (host_address_to_string (X))
  63. #define target_debug_print_gdb_byte_p(X) \
  64. target_debug_do_print (host_address_to_string (X))
  65. #define target_debug_print_gdb_byte_pp(X) \
  66. target_debug_do_print (host_address_to_string (*(X)))
  67. #define target_debug_print_enum_gdb_signal(X) \
  68. target_debug_do_print (gdb_signal_to_name (X))
  69. #define target_debug_print_ULONGEST(X) \
  70. target_debug_do_print (hex_string (X))
  71. #define target_debug_print_ULONGEST_p(X) \
  72. target_debug_do_print (hex_string (*(X)))
  73. #define target_debug_print_LONGEST(X) \
  74. target_debug_do_print (phex (X, 0))
  75. #define target_debug_print_LONGEST_p(X) \
  76. target_debug_do_print (phex (*(X), 0))
  77. #define target_debug_print_struct_address_space_p(X) \
  78. target_debug_do_print (plongest (address_space_num (X)))
  79. #define target_debug_print_struct_bp_target_info_p(X) \
  80. target_debug_do_print (core_addr_to_string ((X)->placed_address))
  81. #define target_debug_print_struct_expression_p(X) \
  82. target_debug_do_print (host_address_to_string (X))
  83. #define target_debug_print_CORE_ADDR_p(X) \
  84. target_debug_do_print (core_addr_to_string (*(X)))
  85. #define target_debug_print_int_p(X) \
  86. target_debug_do_print (plongest (*(X)))
  87. #define target_debug_print_struct_regcache_p(X) \
  88. target_debug_do_print (host_address_to_string (X))
  89. #define target_debug_print_struct_thread_info_p(X) \
  90. target_debug_do_print (host_address_to_string (X))
  91. #define target_debug_print_struct_ui_file_p(X) \
  92. target_debug_do_print (host_address_to_string (X))
  93. #define target_debug_print_const_target_section_table_p(X) \
  94. target_debug_do_print (host_address_to_string (X))
  95. #define target_debug_print_void_p(X) \
  96. target_debug_do_print (host_address_to_string (X))
  97. #define target_debug_print_find_memory_region_ftype(X) \
  98. target_debug_do_print (host_address_to_string (X))
  99. #define target_debug_print_bfd_p(X) \
  100. target_debug_do_print (host_address_to_string (X))
  101. #define target_debug_print_std_vector_mem_region(X) \
  102. target_debug_do_print (host_address_to_string (X.data ()))
  103. #define target_debug_print_std_vector_static_tracepoint_marker(X) \
  104. target_debug_do_print (host_address_to_string (X.data ()))
  105. #define target_debug_print_const_struct_target_desc_p(X) \
  106. target_debug_do_print (host_address_to_string (X))
  107. #define target_debug_print_struct_bp_location_p(X) \
  108. target_debug_do_print (host_address_to_string (X))
  109. #define target_debug_print_const_trace_state_variable_r(X) \
  110. target_debug_do_print (host_address_to_string (&X))
  111. #define target_debug_print_struct_trace_status_p(X) \
  112. target_debug_do_print (host_address_to_string (X))
  113. #define target_debug_print_struct_breakpoint_p(X) \
  114. target_debug_do_print (host_address_to_string (X))
  115. #define target_debug_print_struct_uploaded_tp_p(X) \
  116. target_debug_do_print (host_address_to_string (X))
  117. #define target_debug_print_struct_uploaded_tp_pp(X) \
  118. target_debug_do_print (host_address_to_string (X))
  119. #define target_debug_print_struct_uploaded_tsv_pp(X) \
  120. target_debug_do_print (host_address_to_string (X))
  121. #define target_debug_print_static_tracepoint_marker_p(X) \
  122. target_debug_do_print (host_address_to_string (X))
  123. #define target_debug_print_struct_btrace_target_info_p(X) \
  124. target_debug_do_print (host_address_to_string (X))
  125. #define target_debug_print_const_struct_frame_unwind_p(X) \
  126. target_debug_do_print (host_address_to_string (X))
  127. #define target_debug_print_struct_btrace_data_p(X) \
  128. target_debug_do_print (host_address_to_string (X))
  129. #define target_debug_print_enum_record_method(X) \
  130. target_debug_do_print (plongest (X))
  131. #define target_debug_print_const_struct_btrace_config_p(X) \
  132. target_debug_do_print (host_address_to_string (X))
  133. #define target_debug_print_const_struct_btrace_target_info_p(X) \
  134. target_debug_do_print (host_address_to_string (X))
  135. #define target_debug_print_enum_target_hw_bp_type(X) \
  136. target_debug_do_print (plongest (X))
  137. #define target_debug_print_enum_bptype(X) \
  138. target_debug_do_print (plongest (X))
  139. #define target_debug_print_struct_inferior_p(X) \
  140. target_debug_do_print (host_address_to_string (X))
  141. #define target_debug_print_enum_remove_bp_reason(X) \
  142. target_debug_do_print (plongest (X))
  143. #define target_debug_print_gdb_disassembly_flags(X) \
  144. target_debug_do_print (plongest (X))
  145. #define target_debug_print_traceframe_info_up(X) \
  146. target_debug_do_print (host_address_to_string (X.get ()))
  147. #define target_debug_print_gdb_array_view_const_int(X) \
  148. target_debug_do_print (host_address_to_string (X.data ()))
  149. #define target_debug_print_inferior_p(inf) \
  150. target_debug_do_print (host_address_to_string (inf))
  151. #define target_debug_print_record_print_flags(X) \
  152. target_debug_do_print (plongest (X))
  153. #define target_debug_print_thread_control_capabilities(X) \
  154. target_debug_do_print (plongest (X))
  155. #define target_debug_print_thread_info_p(X) \
  156. target_debug_do_print (host_address_to_string (X))
  157. #define target_debug_print_std_string(X) \
  158. target_debug_do_print ((X).c_str ())
  159. #define target_debug_print_gdb_byte_vector(X) \
  160. target_debug_do_print (host_address_to_string (X.data ()))
  161. #define target_debug_print_gdb_unique_xmalloc_ptr_char(X) \
  162. target_debug_do_print (X.get ())
  163. #define target_debug_print_target_waitkind(X) \
  164. target_debug_do_print (pulongest (X))
  165. static void
  166. target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
  167. {
  168. gdb_puts (status->to_string ().c_str (), gdb_stdlog);
  169. }
  170. /* Macros or functions that are used via TARGET_DEBUG_PRINTER. */
  171. #define target_debug_print_step(X) \
  172. target_debug_do_print ((X) ? "step" : "continue")
  173. static void
  174. target_debug_print_target_wait_flags (target_wait_flags options)
  175. {
  176. std::string str = target_options_to_string (options);
  177. gdb_puts (str.c_str (), gdb_stdlog);
  178. }
  179. static void
  180. target_debug_print_signals (gdb::array_view<const unsigned char> sigs)
  181. {
  182. gdb_puts ("{", gdb_stdlog);
  183. for (size_t i = 0; i < sigs.size (); i++)
  184. if (sigs[i] != 0)
  185. {
  186. gdb_printf (gdb_stdlog, " %s",
  187. gdb_signal_to_name ((enum gdb_signal) i));
  188. }
  189. gdb_puts (" }", gdb_stdlog);
  190. }
  191. static void
  192. target_debug_print_size_t (size_t size)
  193. {
  194. gdb_printf (gdb_stdlog, "%s", pulongest (size));
  195. }
  196. static void
  197. target_debug_print_const_gdb_byte_vector_r (const gdb::byte_vector &vector)
  198. {
  199. gdb_puts ("{", gdb_stdlog);
  200. for (size_t i = 0; i < vector.size (); i++)
  201. {
  202. gdb_printf (gdb_stdlog, " %s",
  203. phex_nz (vector[i], 1));
  204. }
  205. gdb_puts (" }", gdb_stdlog);
  206. }
  207. static void
  208. target_debug_print_gdb_byte_vector_r (gdb::byte_vector &vector)
  209. {
  210. target_debug_print_const_gdb_byte_vector_r (vector);
  211. }
  212. #endif /* TARGET_DEBUG_H */