gcc-c-interface.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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_C_INTERFACE_H
  15. #define GCC_C_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_c_context;
  24. /*
  25. * Definitions and declarations for the C front end.
  26. */
  27. /* Defined versions of the C front-end API. */
  28. enum gcc_c_api_version
  29. {
  30. GCC_C_FE_VERSION_0 = 0,
  31. /* Added char_type. Added new version of int_type and float_type,
  32. deprecated int_type_v0 and float_type_v0. */
  33. GCC_C_FE_VERSION_1 = 1
  34. };
  35. /* Qualifiers. */
  36. enum gcc_qualifiers
  37. {
  38. GCC_QUALIFIER_CONST = 1,
  39. GCC_QUALIFIER_VOLATILE = 2,
  40. GCC_QUALIFIER_RESTRICT = 4
  41. };
  42. /* This enumerates the kinds of decls that GDB can create. */
  43. enum gcc_c_symbol_kind
  44. {
  45. /* A function. */
  46. GCC_C_SYMBOL_FUNCTION,
  47. /* A variable. */
  48. GCC_C_SYMBOL_VARIABLE,
  49. /* A typedef. */
  50. GCC_C_SYMBOL_TYPEDEF,
  51. /* A label. */
  52. GCC_C_SYMBOL_LABEL
  53. };
  54. /* This enumerates the types of symbols that GCC might request from
  55. GDB. */
  56. enum gcc_c_oracle_request
  57. {
  58. /* An ordinary symbol -- a variable, function, typedef, or enum
  59. constant. */
  60. GCC_C_ORACLE_SYMBOL,
  61. /* A struct, union, or enum tag. */
  62. GCC_C_ORACLE_TAG,
  63. /* A label. */
  64. GCC_C_ORACLE_LABEL
  65. };
  66. /* The type of the function called by GCC to ask GDB for a symbol's
  67. definition. DATUM is an arbitrary value supplied when the oracle
  68. function is registered. CONTEXT is the GCC context in which the
  69. request is being made. REQUEST specifies what sort of symbol is
  70. being requested, and IDENTIFIER is the name of the symbol. */
  71. typedef void gcc_c_oracle_function (void *datum,
  72. struct gcc_c_context *context,
  73. enum gcc_c_oracle_request request,
  74. const char *identifier);
  75. /* The type of the function called by GCC to ask GDB for a symbol's
  76. address. This should return 0 if the address is not known. */
  77. typedef gcc_address gcc_c_symbol_address_function (void *datum,
  78. struct gcc_c_context *ctxt,
  79. const char *identifier);
  80. /* The vtable used by the C front end. */
  81. struct gcc_c_fe_vtable
  82. {
  83. /* The version of the C interface. The value is one of the
  84. gcc_c_api_version constants. */
  85. unsigned int c_version;
  86. /* Set the callbacks for this context.
  87. The binding oracle is called whenever the C parser needs to look
  88. up a symbol. This gives the caller a chance to lazily
  89. instantiate symbols using other parts of the gcc_c_fe_interface
  90. API.
  91. The address oracle is called whenever the C parser needs to look
  92. up a symbol. This is only called for symbols not provided by the
  93. symbol oracle -- that is, just built-in functions where GCC
  94. provides the declaration.
  95. DATUM is an arbitrary piece of data that is passed back verbatim
  96. to the callbacks in requests. */
  97. void (*set_callbacks) (struct gcc_c_context *self,
  98. gcc_c_oracle_function *binding_oracle,
  99. gcc_c_symbol_address_function *address_oracle,
  100. void *datum);
  101. #define GCC_METHOD0(R, N) \
  102. R (*N) (struct gcc_c_context *);
  103. #define GCC_METHOD1(R, N, A) \
  104. R (*N) (struct gcc_c_context *, A);
  105. #define GCC_METHOD2(R, N, A, B) \
  106. R (*N) (struct gcc_c_context *, A, B);
  107. #define GCC_METHOD3(R, N, A, B, C) \
  108. R (*N) (struct gcc_c_context *, A, B, C);
  109. #define GCC_METHOD4(R, N, A, B, C, D) \
  110. R (*N) (struct gcc_c_context *, A, B, C, D);
  111. #define GCC_METHOD5(R, N, A, B, C, D, E) \
  112. R (*N) (struct gcc_c_context *, A, B, C, D, E);
  113. #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
  114. R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G);
  115. #include "gcc-c-fe.def"
  116. #undef GCC_METHOD0
  117. #undef GCC_METHOD1
  118. #undef GCC_METHOD2
  119. #undef GCC_METHOD3
  120. #undef GCC_METHOD4
  121. #undef GCC_METHOD5
  122. #undef GCC_METHOD7
  123. };
  124. /* The C front end object. */
  125. struct gcc_c_context
  126. {
  127. /* Base class. */
  128. struct gcc_base_context base;
  129. /* Our vtable. This is a separate field because this is simpler
  130. than implementing a vtable inheritance scheme in C. */
  131. const struct gcc_c_fe_vtable *c_ops;
  132. };
  133. /* The name of the .so that the compiler builds. We dlopen this
  134. later. */
  135. #define GCC_C_FE_LIBCC libcc1.so
  136. /* The compiler exports a single initialization function. This macro
  137. holds its name as a symbol. */
  138. #define GCC_C_FE_CONTEXT gcc_c_fe_context
  139. /* The type of the initialization function. The caller passes in the
  140. desired base version and desired C-specific version. If the
  141. request can be satisfied, a compatible gcc_context object will be
  142. returned. Otherwise, the function returns NULL. */
  143. typedef struct gcc_c_context *gcc_c_fe_context_function
  144. (enum gcc_base_api_version,
  145. enum gcc_c_api_version);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* GCC_C_INTERFACE_H */