gcc-c-interface.h 5.5 KB

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