gdbstub.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef GDBSTUB_H
  2. #define GDBSTUB_H
  3. typedef struct GDBFeature {
  4. const char *xmlname;
  5. const char *xml;
  6. const char *name;
  7. const char * const *regs;
  8. int num_regs;
  9. } GDBFeature;
  10. typedef struct GDBFeatureBuilder {
  11. GDBFeature *feature;
  12. GPtrArray *xml;
  13. GPtrArray *regs;
  14. int base_reg;
  15. } GDBFeatureBuilder;
  16. /* Get or set a register. Returns the size of the register. */
  17. typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg);
  18. typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg);
  19. /**
  20. * gdb_init_cpu(): Initialize the CPU for gdbstub.
  21. * @cpu: The CPU to be initialized.
  22. */
  23. void gdb_init_cpu(CPUState *cpu);
  24. /**
  25. * gdb_register_coprocessor() - register a supplemental set of registers
  26. * @cpu - the CPU associated with registers
  27. * @get_reg - get function (gdb reading)
  28. * @set_reg - set function (gdb modifying)
  29. * @num_regs - number of registers in set
  30. * @xml - xml name of set
  31. * @gpos - non-zero to append to "general" register set at @gpos
  32. */
  33. void gdb_register_coprocessor(CPUState *cpu,
  34. gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
  35. const GDBFeature *feature, int g_pos);
  36. /**
  37. * gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
  38. * @cpu - the CPU associated with registers
  39. */
  40. void gdb_unregister_coprocessor_all(CPUState *cpu);
  41. /**
  42. * gdbserver_start: start the gdb server
  43. * @port_or_device: connection spec for gdb
  44. * @errp: error handle
  45. *
  46. * For CONFIG_USER this is either a tcp port or a path to a fifo. For
  47. * system emulation you can use a full chardev spec for your gdbserver
  48. * port.
  49. *
  50. * The error handle should be either &error_fatal (for start-up) or
  51. * &error_warn (for QMP/HMP initiated sessions).
  52. *
  53. * Returns true when server successfully started.
  54. */
  55. bool gdbserver_start(const char *port_or_device, Error **errp);
  56. /**
  57. * gdb_feature_builder_init() - Initialize GDBFeatureBuilder.
  58. * @builder: The builder to be initialized.
  59. * @feature: The feature to be filled.
  60. * @name: The name of the feature.
  61. * @xmlname: The name of the XML.
  62. * @base_reg: The base number of the register ID.
  63. */
  64. void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
  65. const char *name, const char *xmlname,
  66. int base_reg);
  67. /**
  68. * gdb_feature_builder_append_tag() - Append a tag.
  69. * @builder: The builder.
  70. * @format: The format of the tag.
  71. * @...: The values to be formatted.
  72. */
  73. void G_GNUC_PRINTF(2, 3)
  74. gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
  75. const char *format, ...);
  76. /**
  77. * gdb_feature_builder_append_reg() - Append a register.
  78. * @builder: The builder.
  79. * @name: The register's name; it must be unique within a CPU.
  80. * @bitsize: The register's size, in bits.
  81. * @regnum: The offset of the register's number in the feature.
  82. * @type: The type of the register.
  83. * @group: The register group to which this register belongs; it can be NULL.
  84. */
  85. void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,
  86. const char *name,
  87. int bitsize,
  88. int regnum,
  89. const char *type,
  90. const char *group);
  91. /**
  92. * gdb_feature_builder_end() - End building GDBFeature.
  93. * @builder: The builder.
  94. */
  95. void gdb_feature_builder_end(const GDBFeatureBuilder *builder);
  96. /**
  97. * gdb_find_static_feature() - Find a static feature.
  98. * @xmlname: The name of the XML.
  99. *
  100. * Return: The static feature.
  101. */
  102. const GDBFeature *gdb_find_static_feature(const char *xmlname);
  103. /**
  104. * gdb_read_register() - Read a register associated with a CPU.
  105. * @cpu: The CPU associated with the register.
  106. * @buf: The buffer that the read register will be appended to.
  107. * @reg: The register's number returned by gdb_find_feature_register().
  108. *
  109. * Return: The number of read bytes.
  110. */
  111. int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
  112. /**
  113. * typedef GDBRegDesc - a register description from gdbstub
  114. */
  115. typedef struct {
  116. int gdb_reg;
  117. const char *name;
  118. const char *feature_name;
  119. } GDBRegDesc;
  120. /**
  121. * gdb_get_register_list() - Return list of all registers for CPU
  122. * @cpu: The CPU being searched
  123. *
  124. * Returns a GArray of GDBRegDesc, caller frees array but not the
  125. * const strings.
  126. */
  127. GArray *gdb_get_register_list(CPUState *cpu);
  128. void gdb_set_stop_cpu(CPUState *cpu);
  129. /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
  130. extern const GDBFeature gdb_static_features[];
  131. #endif /* GDBSTUB_H */