varobj.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /* GDB variable objects API.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef VAROBJ_H
  14. #define VAROBJ_H 1
  15. #include "symtab.h"
  16. #include "gdbtypes.h"
  17. #include "value.h"
  18. /* Enumeration for the format types */
  19. enum varobj_display_formats
  20. {
  21. FORMAT_NATURAL, /* What gdb actually calls 'natural' */
  22. FORMAT_BINARY, /* Binary display */
  23. FORMAT_DECIMAL, /* Decimal display */
  24. FORMAT_HEXADECIMAL, /* Hex display */
  25. FORMAT_OCTAL, /* Octal display */
  26. FORMAT_ZHEXADECIMAL /* Zero padded hexadecimal */
  27. };
  28. enum varobj_type
  29. {
  30. USE_SPECIFIED_FRAME, /* Use the frame passed to varobj_create. */
  31. USE_CURRENT_FRAME, /* Use the current frame. */
  32. USE_SELECTED_FRAME /* Always reevaluate in selected frame. */
  33. };
  34. /* Enumerator describing if a variable object is in scope. */
  35. enum varobj_scope_status
  36. {
  37. VAROBJ_IN_SCOPE = 0, /* Varobj is scope, value available. */
  38. VAROBJ_NOT_IN_SCOPE = 1, /* Varobj is not in scope, value not
  39. available, but varobj can become in
  40. scope later. */
  41. VAROBJ_INVALID = 2, /* Varobj no longer has any value, and never
  42. will. */
  43. };
  44. /* String representations of gdb's format codes (defined in varobj.c). */
  45. extern const char *varobj_format_string[];
  46. /* Struct that describes a variable object instance. */
  47. struct varobj;
  48. struct varobj_update_result
  49. {
  50. varobj_update_result (struct varobj *varobj_,
  51. varobj_scope_status status_ = VAROBJ_IN_SCOPE)
  52. : varobj (varobj_), status (status_)
  53. {}
  54. varobj_update_result (varobj_update_result &&other) = default;
  55. DISABLE_COPY_AND_ASSIGN (varobj_update_result);
  56. struct varobj *varobj;
  57. bool type_changed = false;
  58. bool children_changed = false;
  59. bool changed = false;
  60. enum varobj_scope_status status;
  61. /* This variable is used internally by varobj_update to indicate if the
  62. new value of varobj is already computed and installed, or has to
  63. be yet installed. Don't use this outside varobj.c. */
  64. bool value_installed = false;
  65. /* This will be non-NULL when new children were added to the varobj.
  66. It lists the new children (which must necessarily come at the end
  67. of the child list) added during an update. The caller is
  68. responsible for freeing this vector. */
  69. std::vector<struct varobj *> newobj;
  70. };
  71. struct varobj_root;
  72. struct varobj_dynamic;
  73. /* Every variable in the system has a structure of this type defined
  74. for it. This structure holds all information necessary to manipulate
  75. a particular object variable. */
  76. struct varobj
  77. {
  78. explicit varobj (varobj_root *root_);
  79. ~varobj ();
  80. /* Name of the variable for this object. If this variable is a
  81. child, then this name will be the child's source name.
  82. (bar, not foo.bar). */
  83. /* NOTE: This is the "expression". */
  84. std::string name;
  85. /* Expression for this child. Can be used to create a root variable
  86. corresponding to this child. */
  87. std::string path_expr;
  88. /* The name for this variable's object. This is here for
  89. convenience when constructing this object's children. */
  90. std::string obj_name;
  91. /* Index of this variable in its parent or -1. */
  92. int index = -1;
  93. /* The type of this variable. This can be NULL
  94. for artificial variable objects -- currently, the "accessibility"
  95. variable objects in C++. */
  96. struct type *type = NULL;
  97. /* The value of this expression or subexpression. A NULL value
  98. indicates there was an error getting this value.
  99. Invariant: if varobj_value_is_changeable_p (this) is non-zero,
  100. the value is either NULL, or not lazy. */
  101. value_ref_ptr value;
  102. /* The number of (immediate) children this variable has. */
  103. int num_children = -1;
  104. /* If this object is a child, this points to its immediate parent. */
  105. struct varobj *parent = NULL;
  106. /* Children of this object. */
  107. std::vector<varobj *> children;
  108. /* Description of the root variable. Points to root variable for
  109. children. */
  110. struct varobj_root *root;
  111. /* The format of the output for this object. */
  112. enum varobj_display_formats format = FORMAT_NATURAL;
  113. /* Was this variable updated via a varobj_set_value operation. */
  114. bool updated = false;
  115. /* Last print value. */
  116. std::string print_value;
  117. /* Is this variable frozen. Frozen variables are never implicitly
  118. updated by -var-update *
  119. or -var-update <direct-or-indirect-parent>. */
  120. bool frozen = false;
  121. /* Is the value of this variable intentionally not fetched? It is
  122. not fetched if either the variable is frozen, or any parents is
  123. frozen. */
  124. bool not_fetched = false;
  125. /* Sub-range of children which the MI consumer has requested. If
  126. FROM < 0 or TO < 0, means that all children have been
  127. requested. */
  128. int from = -1;
  129. int to = -1;
  130. /* Dynamic part of varobj. */
  131. struct varobj_dynamic *dynamic;
  132. };
  133. /* Is the variable X one of our "fake" children? */
  134. #define CPLUS_FAKE_CHILD(x) \
  135. ((x) != NULL && (x)->type == NULL && (x)->value == NULL)
  136. /* The language specific vector */
  137. struct lang_varobj_ops
  138. {
  139. /* The number of children of PARENT. */
  140. int (*number_of_children) (const struct varobj *parent);
  141. /* The name (expression) of a root varobj. */
  142. std::string (*name_of_variable) (const struct varobj *parent);
  143. /* The name of the INDEX'th child of PARENT. */
  144. std::string (*name_of_child) (const struct varobj *parent, int index);
  145. /* Returns the rooted expression of CHILD, which is a variable
  146. obtain that has some parent. */
  147. std::string (*path_expr_of_child) (const struct varobj *child);
  148. /* The ``struct value *'' of the INDEX'th child of PARENT. */
  149. struct value *(*value_of_child) (const struct varobj *parent, int index);
  150. /* The type of the INDEX'th child of PARENT. */
  151. struct type *(*type_of_child) (const struct varobj *parent, int index);
  152. /* The current value of VAR. */
  153. std::string (*value_of_variable) (const struct varobj *var,
  154. enum varobj_display_formats format);
  155. /* Return true if changes in value of VAR must be detected and
  156. reported by -var-update. Return false if -var-update should never
  157. report changes of such values. This makes sense for structures
  158. (since the changes in children values will be reported separately),
  159. or for artificial objects (like 'public' pseudo-field in C++).
  160. Return value of false means that gdb need not call value_fetch_lazy
  161. for the value of this variable object. */
  162. bool (*value_is_changeable_p) (const struct varobj *var);
  163. /* Return true if the type of VAR has mutated.
  164. VAR's value is still the varobj's previous value, while NEW_VALUE
  165. is VAR's new value and NEW_TYPE is the var's new type. NEW_VALUE
  166. may be NULL indicating that there is no value available (the varobj
  167. may be out of scope, of may be the child of a null pointer, for
  168. instance). NEW_TYPE, on the other hand, must never be NULL.
  169. This function should also be able to assume that var's number of
  170. children is set (not < 0).
  171. Languages where types do not mutate can set this to NULL. */
  172. bool (*value_has_mutated) (const struct varobj *var, struct value *new_value,
  173. struct type *new_type);
  174. /* Return true if VAR is a suitable path expression parent.
  175. For C like languages with anonymous structures and unions an anonymous
  176. structure or union is not a suitable parent. */
  177. bool (*is_path_expr_parent) (const struct varobj *var);
  178. };
  179. extern const struct lang_varobj_ops c_varobj_ops;
  180. extern const struct lang_varobj_ops cplus_varobj_ops;
  181. extern const struct lang_varobj_ops ada_varobj_ops;
  182. /* Non-zero if we want to see trace of varobj level stuff. */
  183. extern unsigned int varobjdebug;
  184. /* API functions */
  185. extern struct varobj *varobj_create (const char *objname,
  186. const char *expression, CORE_ADDR frame,
  187. enum varobj_type type);
  188. extern std::string varobj_gen_name (void);
  189. extern struct varobj *varobj_get_handle (const char *name);
  190. extern const char *varobj_get_objname (const struct varobj *var);
  191. extern std::string varobj_get_expression (const struct varobj *var);
  192. /* Delete a varobj and all its children if only_children is false, otherwise
  193. delete only the children. Return the number of deleted variables. */
  194. extern int varobj_delete (struct varobj *var, bool only_children);
  195. extern enum varobj_display_formats varobj_set_display_format (
  196. struct varobj *var,
  197. enum varobj_display_formats format);
  198. extern enum varobj_display_formats varobj_get_display_format (
  199. const struct varobj *var);
  200. extern int varobj_get_thread_id (const struct varobj *var);
  201. extern void varobj_set_frozen (struct varobj *var, bool frozen);
  202. extern bool varobj_get_frozen (const struct varobj *var);
  203. extern void varobj_get_child_range (const struct varobj *var, int *from,
  204. int *to);
  205. extern void varobj_set_child_range (struct varobj *var, int from, int to);
  206. extern gdb::unique_xmalloc_ptr<char>
  207. varobj_get_display_hint (const struct varobj *var);
  208. extern int varobj_get_num_children (struct varobj *var);
  209. /* Return the list of children of VAR. The returned vector should not
  210. be modified in any way. FROM and TO are in/out parameters
  211. indicating the range of children to return. If either *FROM or *TO
  212. is less than zero on entry, then all children will be returned. On
  213. return, *FROM and *TO will be updated to indicate the real range
  214. that was returned. The resulting vector will contain at least the
  215. children from *FROM to just before *TO; it might contain more
  216. children, depending on whether any more were available. */
  217. extern const std::vector<varobj *> &
  218. varobj_list_children (struct varobj *var, int *from, int *to);
  219. extern std::string varobj_get_type (struct varobj *var);
  220. extern struct type *varobj_get_gdb_type (const struct varobj *var);
  221. extern const char *varobj_get_path_expr (const struct varobj *var);
  222. extern const struct language_defn *
  223. varobj_get_language (const struct varobj *var);
  224. extern int varobj_get_attributes (const struct varobj *var);
  225. extern std::string
  226. varobj_get_formatted_value (struct varobj *var,
  227. enum varobj_display_formats format);
  228. extern std::string varobj_get_value (struct varobj *var);
  229. extern bool varobj_set_value (struct varobj *var, const char *expression);
  230. extern void all_root_varobjs (gdb::function_view<void (struct varobj *var)>);
  231. extern std::vector<varobj_update_result>
  232. varobj_update (struct varobj **varp, bool is_explicit);
  233. extern void varobj_invalidate (void);
  234. extern bool varobj_editable_p (const struct varobj *var);
  235. extern bool varobj_floating_p (const struct varobj *var);
  236. extern void varobj_set_visualizer (struct varobj *var,
  237. const char *visualizer);
  238. extern void varobj_enable_pretty_printing (void);
  239. extern bool varobj_has_more (const struct varobj *var, int to);
  240. extern bool varobj_is_dynamic_p (const struct varobj *var);
  241. extern bool varobj_default_value_is_changeable_p (const struct varobj *var);
  242. extern bool varobj_value_is_changeable_p (const struct varobj *var);
  243. extern struct type *varobj_get_value_type (const struct varobj *var);
  244. extern bool varobj_is_anonymous_child (const struct varobj *child);
  245. extern const struct varobj *
  246. varobj_get_path_expr_parent (const struct varobj *var);
  247. extern std::string
  248. varobj_value_get_print_value (struct value *value,
  249. enum varobj_display_formats format,
  250. const struct varobj *var);
  251. extern void varobj_formatted_print_options (struct value_print_options *opts,
  252. enum varobj_display_formats format);
  253. extern void varobj_restrict_range (const std::vector<varobj *> &children,
  254. int *from, int *to);
  255. extern bool varobj_default_is_path_expr_parent (const struct varobj *var);
  256. #endif /* VAROBJ_H */