gcc-cp-interface.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /* Interface between GCC C++ FE and GDB
  2. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  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 GCC_CP_INTERFACE_H
  15. #define GCC_CP_INTERFACE_H
  16. #include "gcc-interface.h"
  17. /* This header defines the interface to the GCC API. It must be both
  18. valid C and valid C++, because it is included by both programs. */
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /* Forward declaration. */
  23. struct gcc_cp_context;
  24. /*
  25. * Definitions and declarations for the C++ front end.
  26. */
  27. /* Defined versions of the C++ front-end API. */
  28. enum gcc_cp_api_version
  29. {
  30. GCC_CP_FE_VERSION_0 = 0
  31. };
  32. /* Qualifiers. */
  33. enum gcc_cp_qualifiers
  34. {
  35. GCC_CP_QUALIFIER_CONST = 1,
  36. GCC_CP_QUALIFIER_VOLATILE = 2,
  37. GCC_CP_QUALIFIER_RESTRICT = 4
  38. };
  39. /* Ref qualifiers. */
  40. enum gcc_cp_ref_qualifiers {
  41. GCC_CP_REF_QUAL_NONE = 0,
  42. GCC_CP_REF_QUAL_LVALUE = 1,
  43. GCC_CP_REF_QUAL_RVALUE = 2
  44. };
  45. /* Opaque typedef for unbound class templates. They are used for
  46. template arguments, and defaults for template template
  47. parameters. */
  48. typedef unsigned long long gcc_utempl;
  49. /* Opaque typedef for expressions. They are used for template
  50. arguments, defaults for non-type template parameters, and defaults
  51. for function arguments. */
  52. typedef unsigned long long gcc_expr;
  53. typedef enum
  54. { GCC_CP_TPARG_VALUE, GCC_CP_TPARG_CLASS,
  55. GCC_CP_TPARG_TEMPL, GCC_CP_TPARG_PACK }
  56. gcc_cp_template_arg_kind;
  57. typedef union
  58. { gcc_expr value; gcc_type type; gcc_utempl templ; gcc_type pack; }
  59. gcc_cp_template_arg;
  60. /* An array of template arguments. */
  61. struct gcc_cp_template_args
  62. {
  63. /* Number of elements. */
  64. int n_elements;
  65. /* kind[i] indicates what kind of template argument type[i] is. */
  66. char /* gcc_cp_template_arg_kind */ *kinds;
  67. /* The template arguments. */
  68. gcc_cp_template_arg *elements;
  69. };
  70. /* An array of (default) function arguments. */
  71. struct gcc_cp_function_args
  72. {
  73. /* Number of elements. */
  74. int n_elements;
  75. /* The (default) values for each argument. */
  76. gcc_expr *elements;
  77. };
  78. /* This enumerates the kinds of decls that GDB can create. */
  79. enum gcc_cp_symbol_kind
  80. {
  81. /* A function. */
  82. GCC_CP_SYMBOL_FUNCTION,
  83. /* A variable. */
  84. GCC_CP_SYMBOL_VARIABLE,
  85. /* A typedef, or an alias declaration (including template ones). */
  86. GCC_CP_SYMBOL_TYPEDEF,
  87. /* A label. */
  88. GCC_CP_SYMBOL_LABEL,
  89. /* A class, forward declared in build_decl (to be later defined in
  90. start_class_definition), or, in a template parameter list scope,
  91. a declaration of a template class, closing the parameter
  92. list. */
  93. GCC_CP_SYMBOL_CLASS,
  94. /* A union, forward declared in build_decl (to be later defined in
  95. start_class_definition). */
  96. GCC_CP_SYMBOL_UNION,
  97. /* An enumeration type being introduced with start_new_enum_type. */
  98. GCC_CP_SYMBOL_ENUM,
  99. /* A nonstatic data member being introduced with new_field. */
  100. GCC_CP_SYMBOL_FIELD,
  101. /* A base class in a gcc_vbase_array. */
  102. GCC_CP_SYMBOL_BASECLASS,
  103. /* A using declaration in new_using_decl. */
  104. GCC_CP_SYMBOL_USING,
  105. /* A (lambda) closure class type. In many regards this is just like
  106. a regular class, but it's not supposed to have base classes, some
  107. of the member functions that are usually implicitly-defined are
  108. deleted, and it should have an operator() member function that
  109. holds the lambda body. We can't instantiate objects of lambda
  110. types from the snippet, but we can interact with them in such
  111. ways as passing them to functions that take their types, and
  112. calling their body. */
  113. GCC_CP_SYMBOL_LAMBDA_CLOSURE,
  114. /* Marker to check that we haven't exceeded GCC_CP_SYMBOL_MASK. */
  115. GCC_CP_SYMBOL_END,
  116. GCC_CP_SYMBOL_MASK = 15,
  117. /* When defining a class member, at least one of the
  118. GCC_CP_ACCESS_MASK bits must be set; when defining a namespace-
  119. or union-scoped symbol, none of them must be set. */
  120. GCC_CP_ACCESS_PRIVATE,
  121. GCC_CP_ACCESS_PUBLIC = GCC_CP_ACCESS_PRIVATE << 1,
  122. GCC_CP_ACCESS_MASK = (GCC_CP_ACCESS_PUBLIC
  123. | GCC_CP_ACCESS_PRIVATE),
  124. GCC_CP_ACCESS_PROTECTED = GCC_CP_ACCESS_MASK,
  125. GCC_CP_ACCESS_NONE = 0,
  126. GCC_CP_FLAG_BASE = GCC_CP_ACCESS_PRIVATE << 2,
  127. /* Flags to be used along with GCC_CP_SYMBOL_FUNCTION: */
  128. /* This flag should be set for constructors, destructors and
  129. operators. */
  130. GCC_CP_FLAG_SPECIAL_FUNCTION = GCC_CP_FLAG_BASE,
  131. /* We intentionally cannot express inline, constexpr, or virtual
  132. override for functions. We can't inline or constexpr-replace
  133. without a source-level body. The override keyword is only
  134. meaningful within the definition of the containing class. */
  135. /* This indicates a "virtual" member function, explicitly or
  136. implicitly (due to a virtual function with the same name and
  137. prototype in a base class) declared as such. */
  138. GCC_CP_FLAG_VIRTUAL_FUNCTION = GCC_CP_FLAG_BASE << 1,
  139. /* The following two flags should only be set when the flag above is
  140. set. */
  141. /* This indicates a pure virtual member function, i.e., one that is
  142. declared with "= 0", even if a body is provided in the
  143. definition. */
  144. GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION = GCC_CP_FLAG_BASE << 2,
  145. /* This indicates a "final" virtual member function. */
  146. GCC_CP_FLAG_FINAL_VIRTUAL_FUNCTION = GCC_CP_FLAG_BASE << 3,
  147. /* This indicates a special member function should have its default
  148. implementation. This either means the function declaration
  149. contains the "= default" tokens, or that the member function was
  150. implicitly generated by the compiler, although the latter use is
  151. discouraged: just let the compiler implicitly introduce it.
  152. A member function defaulted after its first declaration has
  153. slightly different ABI implications from one implicitly generated
  154. or explicitly defaulted at the declaration (and definition)
  155. point. To avoid silent (possibly harmless) violation of the one
  156. definition rule, it is recommended that this flag not be used for
  157. such functions, and that the address of the definition be
  158. supplied instead. */
  159. GCC_CP_FLAG_DEFAULTED_FUNCTION = GCC_CP_FLAG_BASE << 4,
  160. /* This indicates a deleted member function, i.e., one that has been
  161. defined as "= delete" at its declaration point, or one that has
  162. been implicitly defined as deleted (with or without an explicit
  163. "= default" definition).
  164. This should not be used for implicitly-declared member functions
  165. that resolve to deleted definitions, as it may affect the
  166. implicit declaration of other member functions. */
  167. GCC_CP_FLAG_DELETED_FUNCTION = GCC_CP_FLAG_BASE << 5,
  168. /* This indicates a constructor or type-conversion operator declared
  169. as "explicit". */
  170. GCC_CP_FLAG_EXPLICIT_FUNCTION = GCC_CP_FLAG_BASE << 6,
  171. GCC_CP_FLAG_END_FUNCTION,
  172. GCC_CP_FLAG_MASK_FUNCTION = (((GCC_CP_FLAG_END_FUNCTION - 1) << 1)
  173. - GCC_CP_FLAG_BASE),
  174. /* Flags to be used along with GCC_CP_SYMBOL_VARIABLE: */
  175. /* This indicates a variable declared as "constexpr". */
  176. GCC_CP_FLAG_CONSTEXPR_VARIABLE = GCC_CP_FLAG_BASE,
  177. /* This indicates a variable declared as "thread_local". ??? What
  178. should the ADDRESS be? */
  179. GCC_CP_FLAG_THREAD_LOCAL_VARIABLE = GCC_CP_FLAG_BASE << 1,
  180. GCC_CP_FLAG_END_VARIABLE,
  181. GCC_CP_FLAG_MASK_VARIABLE = (((GCC_CP_FLAG_END_VARIABLE - 1) << 1)
  182. - GCC_CP_FLAG_BASE),
  183. /* Flags to be used when defining nonstatic data members of classes
  184. with new_field. */
  185. /* Use this when no flags are present. */
  186. GCC_CP_FLAG_FIELD_NOFLAG = 0,
  187. /* This indicates the field is declared as mutable. */
  188. GCC_CP_FLAG_FIELD_MUTABLE = GCC_CP_FLAG_BASE,
  189. GCC_CP_FLAG_END_FIELD,
  190. GCC_CP_FLAG_MASK_FIELD = (((GCC_CP_FLAG_END_FIELD - 1) << 1)
  191. - GCC_CP_FLAG_BASE),
  192. /* Flags to be used when defining an enum with
  193. start_new_enum_type. */
  194. /* This indicates an enum type without any flags. */
  195. GCC_CP_FLAG_ENUM_NOFLAG = 0,
  196. /* This indicates a scoped enum type. */
  197. GCC_CP_FLAG_ENUM_SCOPED = GCC_CP_FLAG_BASE,
  198. GCC_CP_FLAG_END_ENUM,
  199. GCC_CP_FLAG_MASK_ENUM = (((GCC_CP_FLAG_END_ENUM - 1) << 1)
  200. - GCC_CP_FLAG_BASE),
  201. /* Flags to be used when introducing a class or a class template
  202. with build_decl. */
  203. /* This indicates an enum type without any flags. */
  204. GCC_CP_FLAG_CLASS_NOFLAG = 0,
  205. /* This indicates the class is actually a struct. This has no
  206. effect whatsoever on access control in this interface, since all
  207. class members must have explicit access control bits set, but it
  208. may affect error messages. */
  209. GCC_CP_FLAG_CLASS_IS_STRUCT = GCC_CP_FLAG_BASE,
  210. GCC_CP_FLAG_END_CLASS,
  211. GCC_CP_FLAG_MASK_CLASS = (((GCC_CP_FLAG_END_CLASS - 1) << 1)
  212. - GCC_CP_FLAG_BASE),
  213. /* Flags to be used when introducing a virtual base class in a
  214. gcc_vbase_array. */
  215. /* This indicates an enum type without any flags. */
  216. GCC_CP_FLAG_BASECLASS_NOFLAG = 0,
  217. /* This indicates the class is actually a struct. This has no
  218. effect whatsoever on access control in this interface, since all
  219. class members must have explicit access control bits set, but it
  220. may affect error messages. */
  221. GCC_CP_FLAG_BASECLASS_VIRTUAL = GCC_CP_FLAG_BASE,
  222. GCC_CP_FLAG_END_BASECLASS,
  223. GCC_CP_FLAG_MASK_BASECLASS = (((GCC_CP_FLAG_END_BASECLASS - 1) << 1)
  224. - GCC_CP_FLAG_BASE),
  225. GCC_CP_FLAG_MASK = (GCC_CP_FLAG_MASK_FUNCTION
  226. | GCC_CP_FLAG_MASK_VARIABLE
  227. | GCC_CP_FLAG_MASK_FIELD
  228. | GCC_CP_FLAG_MASK_ENUM
  229. | GCC_CP_FLAG_MASK_CLASS
  230. | GCC_CP_FLAG_MASK_BASECLASS
  231. )
  232. };
  233. /* An array of types used for creating lists of base classes. */
  234. struct gcc_vbase_array
  235. {
  236. /* Number of elements. */
  237. int n_elements;
  238. /* The base classes. */
  239. gcc_type *elements;
  240. /* Flags for each base class. Used to indicate access control and
  241. virtualness. */
  242. enum gcc_cp_symbol_kind *flags;
  243. };
  244. /* This enumerates the types of symbols that GCC might request from
  245. GDB. */
  246. enum gcc_cp_oracle_request
  247. {
  248. /* An identifier in namespace scope -- type, variable, function,
  249. namespace, template. All namespace-scoped symbols with the
  250. requested name, in any namespace (including the global
  251. namespace), should be defined in response to this request. */
  252. GCC_CP_ORACLE_IDENTIFIER
  253. };
  254. /* The type of the function called by GCC to ask GDB for a symbol's
  255. definition. DATUM is an arbitrary value supplied when the oracle
  256. function is registered. CONTEXT is the GCC context in which the
  257. request is being made. REQUEST specifies what sort of symbol is
  258. being requested, and IDENTIFIER is the name of the symbol. */
  259. typedef void gcc_cp_oracle_function (void *datum,
  260. struct gcc_cp_context *context,
  261. enum gcc_cp_oracle_request request,
  262. const char *identifier);
  263. /* The type of the function called by GCC to ask GDB for a symbol's
  264. address. This should return 0 if the address is not known. */
  265. typedef gcc_address gcc_cp_symbol_address_function (void *datum,
  266. struct gcc_cp_context *ctxt,
  267. const char *identifier);
  268. /* The type of the function called by GCC to ask GDB to enter or leave
  269. the user expression scope. */
  270. typedef void gcc_cp_enter_leave_user_expr_scope_function (void *datum,
  271. struct gcc_cp_context
  272. *context);
  273. /* The vtable used by the C front end. */
  274. struct gcc_cp_fe_vtable
  275. {
  276. /* The version of the C interface. The value is one of the
  277. gcc_cp_api_version constants. */
  278. unsigned int cp_version;
  279. /* Set the callbacks for this context.
  280. The binding oracle is called whenever the C++ parser needs to
  281. look up a symbol. This gives the caller a chance to lazily
  282. instantiate symbols using other parts of the gcc_cp_fe_interface
  283. API. The symbol is looked up without a scope, and the oracle
  284. must supply a definition for ALL namespace-scoped definitions
  285. bound to the symbol.
  286. The address oracle is called whenever the C++ parser needs to
  287. look up a symbol. This may be called for symbols not provided by
  288. the symbol oracle, such as built-in functions where GCC provides
  289. the declaration; other internal symbols, such as those related
  290. with thunks, rtti, and virtual tables are likely to be queried
  291. through this interface too. The identifier is a mangled symbol
  292. name.
  293. DATUM is an arbitrary piece of data that is passed back verbatim
  294. to the callbacks in requests. */
  295. void (*set_callbacks) (struct gcc_cp_context *self,
  296. gcc_cp_oracle_function *binding_oracle,
  297. gcc_cp_symbol_address_function *address_oracle,
  298. gcc_cp_enter_leave_user_expr_scope_function *enter_scope,
  299. gcc_cp_enter_leave_user_expr_scope_function *leave_scope,
  300. void *datum);
  301. #define GCC_METHOD0(R, N) \
  302. R (*N) (struct gcc_cp_context *);
  303. #define GCC_METHOD1(R, N, A) \
  304. R (*N) (struct gcc_cp_context *, A);
  305. #define GCC_METHOD2(R, N, A, B) \
  306. R (*N) (struct gcc_cp_context *, A, B);
  307. #define GCC_METHOD3(R, N, A, B, C) \
  308. R (*N) (struct gcc_cp_context *, A, B, C);
  309. #define GCC_METHOD4(R, N, A, B, C, D) \
  310. R (*N) (struct gcc_cp_context *, A, B, C, D);
  311. #define GCC_METHOD5(R, N, A, B, C, D, E) \
  312. R (*N) (struct gcc_cp_context *, A, B, C, D, E);
  313. #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
  314. R (*N) (struct gcc_cp_context *, A, B, C, D, E, F, G);
  315. #include "gcc-cp-fe.def"
  316. #undef GCC_METHOD0
  317. #undef GCC_METHOD1
  318. #undef GCC_METHOD2
  319. #undef GCC_METHOD3
  320. #undef GCC_METHOD4
  321. #undef GCC_METHOD5
  322. #undef GCC_METHOD7
  323. };
  324. /* The C front end object. */
  325. struct gcc_cp_context
  326. {
  327. /* Base class. */
  328. struct gcc_base_context base;
  329. /* Our vtable. This is a separate field because this is simpler
  330. than implementing a vtable inheritance scheme in C. */
  331. const struct gcc_cp_fe_vtable *cp_ops;
  332. };
  333. /* The name of the .so that the compiler builds. We dlopen this
  334. later. */
  335. #define GCC_CP_FE_LIBCC libcc1.so
  336. /* The compiler exports a single initialization function. This macro
  337. holds its name as a symbol. */
  338. #define GCC_CP_FE_CONTEXT gcc_cp_fe_context
  339. /* The type of the initialization function. The caller passes in the
  340. desired base version and desired C-specific version. If the
  341. request can be satisfied, a compatible gcc_context object will be
  342. returned. Otherwise, the function returns NULL. */
  343. typedef struct gcc_cp_context *gcc_cp_fe_context_function
  344. (enum gcc_base_api_version,
  345. enum gcc_cp_api_version);
  346. #ifdef __cplusplus
  347. }
  348. #endif
  349. #endif /* GCC_CP_INTERFACE_H */