compile-cplus-types.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. /* Convert types from GDB to GCC
  2. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  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. #include "defs.h"
  15. #include "gdbsupport/preprocessor.h"
  16. #include "gdbtypes.h"
  17. #include "compile-internal.h"
  18. #include "compile-cplus.h"
  19. #include "gdbsupport/gdb_assert.h"
  20. #include "symtab.h"
  21. #include "source.h"
  22. #include "cp-support.h"
  23. #include "cp-abi.h"
  24. #include "objfiles.h"
  25. #include "block.h"
  26. #include "gdbcmd.h"
  27. #include "c-lang.h"
  28. #include "compile-c.h"
  29. #include <algorithm>
  30. /* Default compile flags for C++. */
  31. const char *compile_cplus_instance::m_default_cflags = "-std=gnu++11";
  32. /* Flag to enable internal debugging. */
  33. static bool debug_compile_cplus_types = false;
  34. /* Flag to enable internal scope switching debugging. */
  35. static bool debug_compile_cplus_scopes = false;
  36. /* Forward declarations. */
  37. static gcc_type compile_cplus_convert_func (compile_cplus_instance *instance,
  38. struct type *type,
  39. bool strip_artificial);
  40. /* See description in compile-cplus.h. */
  41. gdb::unique_xmalloc_ptr<char>
  42. compile_cplus_instance::decl_name (const char *natural)
  43. {
  44. if (natural == nullptr)
  45. return nullptr;
  46. gdb::unique_xmalloc_ptr<char> name = cp_func_name (natural);
  47. if (name != nullptr)
  48. return name;
  49. return make_unique_xstrdup (natural);
  50. }
  51. /* Get the access flag for the NUM'th field of TYPE. */
  52. static enum gcc_cp_symbol_kind
  53. get_field_access_flag (const struct type *type, int num)
  54. {
  55. if (TYPE_FIELD_PROTECTED (type, num))
  56. return GCC_CP_ACCESS_PROTECTED;
  57. else if (TYPE_FIELD_PRIVATE (type, num))
  58. return GCC_CP_ACCESS_PRIVATE;
  59. /* GDB assumes everything else is public. */
  60. return GCC_CP_ACCESS_PUBLIC;
  61. }
  62. /* Get the access flag for the NUM'th method of TYPE's FNI'th
  63. fieldlist. */
  64. enum gcc_cp_symbol_kind
  65. get_method_access_flag (const struct type *type, int fni, int num)
  66. {
  67. gdb_assert (type->code () == TYPE_CODE_STRUCT);
  68. /* If this type was not declared a class, everything is public. */
  69. if (!type->is_declared_class ())
  70. return GCC_CP_ACCESS_PUBLIC;
  71. /* Otherwise, read accessibility from the fn_field. */
  72. const struct fn_field *methods = TYPE_FN_FIELDLIST1 (type, fni);
  73. if (TYPE_FN_FIELD_PROTECTED (methods, num))
  74. return GCC_CP_ACCESS_PROTECTED;
  75. else if (TYPE_FN_FIELD_PRIVATE (methods, num))
  76. return GCC_CP_ACCESS_PRIVATE;
  77. else
  78. return GCC_CP_ACCESS_PUBLIC;
  79. }
  80. /* A useful debugging function to output the scope SCOPE to stdout. */
  81. static void __attribute__ ((used))
  82. debug_print_scope (const compile_scope &scope)
  83. {
  84. for (const auto &comp: scope)
  85. {
  86. const char *symbol = (comp.bsymbol.symbol != nullptr
  87. ? comp.bsymbol.symbol->natural_name ()
  88. : "<none>");
  89. printf_unfiltered ("\tname = %s, symbol = %s\n", comp.name.c_str (),
  90. symbol);
  91. }
  92. }
  93. /* See description in compile-cplus.h. */
  94. compile_scope
  95. type_name_to_scope (const char *type_name, const struct block *block)
  96. {
  97. compile_scope scope;
  98. if (type_name == nullptr)
  99. {
  100. /* An anonymous type. We cannot really do much here. We simply cannot
  101. look up anonymous types easily/at all. */
  102. return scope;
  103. }
  104. const char *p = type_name;
  105. std::string lookup_name;
  106. while (*p != '\0')
  107. {
  108. /* Create a string token of the first component of TYPE_NAME. */
  109. int len = cp_find_first_component (p);
  110. std::string s (p, len);
  111. /* Advance past the last token. */
  112. p += len;
  113. /* Look up the symbol and decide when to stop. */
  114. if (!lookup_name.empty ())
  115. lookup_name += "::";
  116. lookup_name += s;
  117. /* Look up the resulting name. */
  118. struct block_symbol bsymbol
  119. = lookup_symbol (lookup_name.c_str (), block, VAR_DOMAIN, nullptr);
  120. if (bsymbol.symbol != nullptr)
  121. {
  122. scope_component comp = {s, bsymbol};
  123. scope.push_back (comp);
  124. if (bsymbol.symbol->type ()->code () != TYPE_CODE_NAMESPACE)
  125. {
  126. /* We're done. */
  127. break;
  128. }
  129. }
  130. if (*p == ':')
  131. {
  132. ++p;
  133. if (*p == ':')
  134. ++p;
  135. else
  136. {
  137. /* This shouldn't happen since we are not attempting to
  138. loop over user input. This name is generated by GDB
  139. from debug info. */
  140. internal_error (__FILE__, __LINE__,
  141. _("malformed TYPE_NAME during parsing"));
  142. }
  143. }
  144. }
  145. return scope;
  146. }
  147. /* Compare two scope_components for equality. These are equal if the names
  148. of the two components' are the same. */
  149. bool
  150. operator== (const scope_component &lhs, const scope_component &rhs)
  151. {
  152. return lhs.name == rhs.name;
  153. }
  154. /* Compare two scope_components for inequality. These are not equal if
  155. the two components' names are not equal. */
  156. bool
  157. operator!= (const scope_component &lhs, const scope_component &rhs)
  158. {
  159. return lhs.name != rhs.name;
  160. }
  161. /* Compare two compile_scopes for equality. These are equal if they are both
  162. contain the same number of components and each component is equal. */
  163. bool
  164. operator== (const compile_scope &lhs, const compile_scope &rhs)
  165. {
  166. if (lhs.size () != rhs.size ())
  167. return false;
  168. for (int i = 0; i < lhs.size (); ++i)
  169. {
  170. if (lhs[i] != rhs[i])
  171. return false;
  172. }
  173. return true;
  174. }
  175. /* Compare two compile_scopes for inequality. These are inequal if they
  176. contain unequal number of elements or if any of the components are not
  177. the same. */
  178. bool
  179. operator!= (const compile_scope &lhs, const compile_scope &rhs)
  180. {
  181. if (lhs.size () != rhs.size ())
  182. return true;
  183. for (int i = 0; i < lhs.size (); ++i)
  184. {
  185. if (lhs[i] != rhs[i])
  186. return true;
  187. }
  188. return false;
  189. }
  190. /* See description in compile-cplus.h. */
  191. void
  192. compile_cplus_instance::enter_scope (compile_scope &&new_scope)
  193. {
  194. bool must_push = m_scopes.empty () || m_scopes.back () != new_scope;
  195. new_scope.m_pushed = must_push;
  196. /* Save the new scope. */
  197. m_scopes.push_back (std::move (new_scope));
  198. if (must_push)
  199. {
  200. if (debug_compile_cplus_scopes)
  201. {
  202. gdb_printf (gdb_stdlog, "entering new scope %s\n",
  203. host_address_to_string (&m_scopes.back ()));
  204. }
  205. /* Push the global namespace. */
  206. plugin ().push_namespace ("");
  207. /* Push all other namespaces. Note that we do not push the last
  208. scope_component -- that's the actual type we are converting. */
  209. std::for_each
  210. (m_scopes.back ().begin (), m_scopes.back ().end () - 1,
  211. [this] (const scope_component &comp)
  212. {
  213. gdb_assert (comp.bsymbol.symbol->type ()->code ()
  214. == TYPE_CODE_NAMESPACE);
  215. const char *ns = (comp.name == CP_ANONYMOUS_NAMESPACE_STR ? nullptr
  216. : comp.name.c_str ());
  217. this->plugin ().push_namespace (ns);
  218. });
  219. }
  220. else
  221. {
  222. if (debug_compile_cplus_scopes)
  223. {
  224. gdb_printf (gdb_stdlog, "staying in current scope -- "
  225. "scopes are identical\n");
  226. }
  227. }
  228. }
  229. /* See description in compile-cplus.h. */
  230. void
  231. compile_cplus_instance::leave_scope ()
  232. {
  233. /* Get the current scope and remove it from the internal list of
  234. scopes. */
  235. compile_scope current = m_scopes.back ();
  236. m_scopes.pop_back ();
  237. if (current.m_pushed)
  238. {
  239. if (debug_compile_cplus_scopes)
  240. {
  241. gdb_printf (gdb_stdlog, "leaving scope %s\n",
  242. host_address_to_string (&current));
  243. }
  244. /* Pop namespaces. */
  245. std::for_each
  246. (current.begin (),current.end () - 1,
  247. [this] (const scope_component &comp) {
  248. gdb_assert (comp.bsymbol.symbol->type ()->code ()
  249. == TYPE_CODE_NAMESPACE);
  250. this->plugin ().pop_binding_level (comp.name.c_str ());
  251. });
  252. /* Pop global namespace. */
  253. plugin ().pop_binding_level ("");
  254. }
  255. else
  256. {
  257. if (debug_compile_cplus_scopes)
  258. gdb_printf (gdb_stdlog,
  259. "identical scopes -- not leaving scope\n");
  260. }
  261. }
  262. /* See description in compile-cplus.h. */
  263. compile_scope
  264. compile_cplus_instance::new_scope (const char *type_name, struct type *type)
  265. {
  266. /* Break the type name into components. If TYPE was defined in some
  267. superclass, we do not process TYPE but process the enclosing type
  268. instead. */
  269. compile_scope scope = type_name_to_scope (type_name, block ());
  270. if (!scope.empty ())
  271. {
  272. /* Get the name of the last component, which should be the
  273. unqualified name of the type to process. */
  274. scope_component &comp = scope.back ();
  275. if (!types_equal (type, comp.bsymbol.symbol->type ())
  276. && (m_scopes.empty ()
  277. || (m_scopes.back ().back ().bsymbol.symbol
  278. != comp.bsymbol.symbol)))
  279. {
  280. /* The type is defined inside another class(es). Convert that
  281. type instead of defining this type. */
  282. convert_type (comp.bsymbol.symbol->type ());
  283. /* If the original type (passed in to us) is defined in a nested
  284. class, the previous call will give us that type's gcc_type.
  285. Upper layers are expecting to get the original type's
  286. gcc_type! */
  287. get_cached_type (type, &scope.m_nested_type);
  288. return scope;
  289. }
  290. }
  291. else
  292. {
  293. if (type->name () == nullptr)
  294. {
  295. /* Anonymous type */
  296. /* We don't have a qualified name for this to look up, but
  297. we need a scope. We have to assume, then, that it is the same
  298. as the current scope, if any. */
  299. if (!m_scopes.empty ())
  300. {
  301. scope = m_scopes.back ();
  302. scope.m_pushed = false;
  303. }
  304. else
  305. scope.push_back (scope_component ());
  306. }
  307. else
  308. {
  309. scope_component comp
  310. = {
  311. decl_name (type->name ()).get (),
  312. lookup_symbol (type->name (), block (), VAR_DOMAIN, nullptr)
  313. };
  314. scope.push_back (comp);
  315. }
  316. }
  317. /* There must be at least one component in the compile_scope. */
  318. gdb_assert (scope.size () > 0);
  319. return scope;
  320. }
  321. /* See description in compile-cplus.h. */
  322. gcc_type
  323. compile_cplus_instance::convert_reference_base
  324. (gcc_type base, enum gcc_cp_ref_qualifiers rquals)
  325. {
  326. return this->plugin ().build_reference_type (base, rquals);
  327. }
  328. /* Convert a reference type to its gcc representation. */
  329. static gcc_type
  330. compile_cplus_convert_reference (compile_cplus_instance *instance,
  331. struct type *type)
  332. {
  333. gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (type));
  334. enum gcc_cp_ref_qualifiers quals = GCC_CP_REF_QUAL_NONE;
  335. switch (type->code ())
  336. {
  337. case TYPE_CODE_REF:
  338. quals = GCC_CP_REF_QUAL_LVALUE;
  339. break;
  340. case TYPE_CODE_RVALUE_REF:
  341. quals = GCC_CP_REF_QUAL_RVALUE;
  342. break;
  343. default:
  344. gdb_assert_not_reached ("unexpected type code for reference type");
  345. }
  346. return instance->convert_reference_base (target, quals);
  347. }
  348. /* See description in compile-cplus.h. */
  349. gcc_type
  350. compile_cplus_instance::convert_pointer_base(gcc_type target)
  351. {
  352. return plugin ().build_pointer_type (target);
  353. }
  354. /* Convert a pointer type to its gcc representation. */
  355. static gcc_type
  356. compile_cplus_convert_pointer (compile_cplus_instance *instance,
  357. struct type *type)
  358. {
  359. gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (type));
  360. return instance->convert_pointer_base (target);
  361. }
  362. /* Convert an array type to its gcc representation. */
  363. static gcc_type
  364. compile_cplus_convert_array (compile_cplus_instance *instance,
  365. struct type *type)
  366. {
  367. struct type *range = type->index_type ();
  368. gcc_type element_type = instance->convert_type (TYPE_TARGET_TYPE (type));
  369. if (range->bounds ()->low.kind () != PROP_CONST)
  370. {
  371. const char *s = _("array type with non-constant"
  372. " lower bound is not supported");
  373. return instance->plugin ().error (s);
  374. }
  375. if (range->bounds ()->low.const_val () != 0)
  376. {
  377. const char *s = _("cannot convert array type with "
  378. "non-zero lower bound to C");
  379. return instance->plugin ().error (s);
  380. }
  381. if (range->bounds ()->high.kind () == PROP_LOCEXPR
  382. || range->bounds ()->high.kind () == PROP_LOCLIST)
  383. {
  384. if (type->is_vector ())
  385. {
  386. const char *s = _("variably-sized vector type is not supported");
  387. return instance->plugin ().error (s);
  388. }
  389. std::string upper_bound
  390. = c_get_range_decl_name (&range->bounds ()->high);
  391. return instance->plugin ().build_vla_array_type (element_type,
  392. upper_bound.c_str ());
  393. }
  394. else
  395. {
  396. LONGEST low_bound, high_bound, count;
  397. if (!get_array_bounds (type, &low_bound, &high_bound))
  398. count = -1;
  399. else
  400. {
  401. gdb_assert (low_bound == 0); /* Ensured above. */
  402. count = high_bound + 1;
  403. }
  404. if (type->is_vector ())
  405. return instance->plugin ().build_vector_type (element_type, count);
  406. return instance->plugin ().build_array_type (element_type, count);
  407. }
  408. }
  409. /* Convert a typedef of TYPE. If not GCC_CP_ACCESS_NONE, NESTED_ACCESS
  410. will define the accessibility of the typedef definition in its
  411. containing class. */
  412. static gcc_type
  413. compile_cplus_convert_typedef (compile_cplus_instance *instance,
  414. struct type *type,
  415. enum gcc_cp_symbol_kind nested_access)
  416. {
  417. compile_scope scope = instance->new_scope (type->name (), type);
  418. if (scope.nested_type () != GCC_TYPE_NONE)
  419. return scope.nested_type ();
  420. gdb::unique_xmalloc_ptr<char> name
  421. = compile_cplus_instance::decl_name (type->name ());
  422. /* Make sure the scope for this type has been pushed. */
  423. instance->enter_scope (std::move (scope));
  424. /* Convert the typedef's real type. */
  425. gcc_type typedef_type = instance->convert_type (check_typedef (type));
  426. instance->plugin ().build_decl ("typedef", name.get (),
  427. GCC_CP_SYMBOL_TYPEDEF | nested_access,
  428. typedef_type, 0, 0, nullptr, 0);
  429. /* Completed this scope. */
  430. instance->leave_scope ();
  431. return typedef_type;
  432. }
  433. /* Convert types defined in TYPE. */
  434. static void
  435. compile_cplus_convert_type_defns (compile_cplus_instance *instance,
  436. struct type *type)
  437. {
  438. int i;
  439. enum gcc_cp_symbol_kind accessibility;
  440. /* Convert typedefs. */
  441. for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
  442. {
  443. if (TYPE_TYPEDEF_FIELD_PROTECTED (type, i))
  444. accessibility = GCC_CP_ACCESS_PROTECTED;
  445. else if (TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
  446. accessibility = GCC_CP_ACCESS_PRIVATE;
  447. else
  448. accessibility = GCC_CP_ACCESS_PUBLIC;
  449. instance->convert_type (TYPE_TYPEDEF_FIELD_TYPE (type, i), accessibility);
  450. }
  451. /* Convert nested types. */
  452. for (i = 0; i < TYPE_NESTED_TYPES_COUNT (type); ++i)
  453. {
  454. if (TYPE_NESTED_TYPES_FIELD_PROTECTED (type, i))
  455. accessibility = GCC_CP_ACCESS_PROTECTED;
  456. else if (TYPE_NESTED_TYPES_FIELD_PRIVATE (type, i))
  457. accessibility = GCC_CP_ACCESS_PRIVATE;
  458. else
  459. accessibility = GCC_CP_ACCESS_PUBLIC;
  460. instance->convert_type (TYPE_NESTED_TYPES_FIELD_TYPE (type, i),
  461. accessibility);
  462. }
  463. }
  464. /* Convert data members defined in TYPE, which should be struct/class/union
  465. with gcc_type COMP_TYPE. */
  466. static void
  467. compile_cplus_convert_struct_or_union_members
  468. (compile_cplus_instance *instance, struct type *type, gcc_type comp_type)
  469. {
  470. for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
  471. {
  472. const char *field_name = type->field (i).name ();
  473. if (TYPE_FIELD_IGNORE (type, i)
  474. || TYPE_FIELD_ARTIFICIAL (type, i))
  475. continue;
  476. /* GDB records unnamed/anonymous fields with empty string names. */
  477. if (*field_name == '\0')
  478. field_name = nullptr;
  479. gcc_type field_type
  480. = instance->convert_type (type->field (i).type ());
  481. if (field_is_static (&type->field (i)))
  482. {
  483. CORE_ADDR physaddr;
  484. switch (type->field (i).loc_kind ())
  485. {
  486. case FIELD_LOC_KIND_PHYSADDR:
  487. {
  488. physaddr = type->field (i).loc_physaddr ();
  489. instance->plugin ().build_decl
  490. ("field physaddr", field_name,
  491. (GCC_CP_SYMBOL_VARIABLE | get_field_access_flag (type, i)),
  492. field_type, nullptr, physaddr, nullptr, 0);
  493. }
  494. break;
  495. case FIELD_LOC_KIND_PHYSNAME:
  496. {
  497. const char *physname = type->field (i).loc_physname ();
  498. struct block_symbol sym
  499. = lookup_symbol (physname, instance->block (),
  500. VAR_DOMAIN, nullptr);
  501. if (sym.symbol == nullptr)
  502. {
  503. /* We didn't actually find the symbol. There's little
  504. we can do but ignore this member. */
  505. continue;
  506. }
  507. const char *filename = symbol_symtab (sym.symbol)->filename;
  508. unsigned int line = sym.symbol->line ();
  509. physaddr = SYMBOL_VALUE_ADDRESS (sym.symbol);
  510. instance->plugin ().build_decl
  511. ("field physname", field_name,
  512. (GCC_CP_SYMBOL_VARIABLE| get_field_access_flag (type, i)),
  513. field_type, nullptr, physaddr, filename, line);
  514. }
  515. break;
  516. default:
  517. gdb_assert_not_reached
  518. ("unexpected static field location kind");
  519. }
  520. }
  521. else
  522. {
  523. unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
  524. enum gcc_cp_symbol_kind field_flags = GCC_CP_SYMBOL_FIELD
  525. | get_field_access_flag (type, i);
  526. if (bitsize == 0)
  527. bitsize = 8 * TYPE_LENGTH (type->field (i).type ());
  528. instance->plugin ().build_field
  529. (field_name, field_type, field_flags, bitsize,
  530. type->field (i).loc_bitpos ());
  531. }
  532. }
  533. }
  534. /* Convert a method type to its gcc representation. */
  535. static gcc_type
  536. compile_cplus_convert_method (compile_cplus_instance *instance,
  537. struct type *parent_type,
  538. struct type *method_type)
  539. {
  540. /* Get the actual function type of the method, the corresponding class's
  541. type and corresponding qualifier flags. */
  542. gcc_type func_type = compile_cplus_convert_func (instance, method_type, true);
  543. gcc_type class_type = instance->convert_type (parent_type);
  544. gcc_cp_qualifiers_flags quals = 0;
  545. if (TYPE_CONST (method_type))
  546. quals |= GCC_CP_QUALIFIER_CONST;
  547. if (TYPE_VOLATILE (method_type))
  548. quals |= GCC_CP_QUALIFIER_VOLATILE;
  549. if (TYPE_RESTRICT (method_type))
  550. quals |= GCC_CP_QUALIFIER_RESTRICT;
  551. /* Not yet implemented. */
  552. gcc_cp_ref_qualifiers_flags rquals = GCC_CP_REF_QUAL_NONE;
  553. return instance->plugin ().build_method_type
  554. (class_type, func_type, quals.raw (), rquals.raw ());
  555. }
  556. /* Convert a member or method pointer represented by TYPE. */
  557. static gcc_type
  558. compile_cplus_convert_memberptr (compile_cplus_instance *instance,
  559. struct type *type)
  560. {
  561. struct type *containing_class = TYPE_SELF_TYPE (type);
  562. if (containing_class == nullptr)
  563. return GCC_TYPE_NONE;
  564. gcc_type class_type = instance->convert_type (containing_class);
  565. gcc_type member_type
  566. = instance->convert_type (TYPE_TARGET_TYPE (type));
  567. return instance->plugin ().build_pointer_to_member_type
  568. (class_type, member_type);
  569. }
  570. /* Convert all methods defined in TYPE, which should be a class/struct/union
  571. with gcc_type CLASS_TYPE. */
  572. static void
  573. compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance,
  574. struct type *type,
  575. gcc_type class_type)
  576. {
  577. for (int i = 0; i < TYPE_NFN_FIELDS (type); ++i)
  578. {
  579. struct fn_field *methods = TYPE_FN_FIELDLIST1 (type, i);
  580. gdb::unique_xmalloc_ptr<char> overloaded_name
  581. = compile_cplus_instance::decl_name (TYPE_FN_FIELDLIST_NAME (type, i));
  582. /* Loop through the fieldlist, adding decls to the compiler's
  583. representation of the class. */
  584. for (int j = 0; j < TYPE_FN_FIELDLIST_LENGTH (type, i); ++j)
  585. {
  586. /* Skip artificial methods. */
  587. if (TYPE_FN_FIELD_ARTIFICIAL (methods, j))
  588. continue;
  589. gcc_cp_symbol_kind_flags sym_kind = GCC_CP_SYMBOL_FUNCTION;
  590. gcc_type method_type;
  591. struct block_symbol sym
  592. = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (methods, j),
  593. instance->block (), VAR_DOMAIN, nullptr);
  594. if (sym.symbol == nullptr)
  595. {
  596. if (TYPE_FN_FIELD_VIRTUAL_P (methods, j))
  597. {
  598. /* This is beyond hacky, and is really only a workaround for
  599. detecting pure virtual methods. */
  600. method_type = compile_cplus_convert_method
  601. (instance, type, TYPE_FN_FIELD_TYPE (methods, j));
  602. instance->plugin ().build_decl
  603. ("pure virtual method", overloaded_name.get (),
  604. (sym_kind
  605. | get_method_access_flag (type, i, j)
  606. | GCC_CP_FLAG_VIRTUAL_FUNCTION
  607. | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION).raw (),
  608. method_type, nullptr, 0, nullptr, 0);
  609. continue;
  610. }
  611. /* This can happen if we have a DW_AT_declaration DIE
  612. for the method, but no "definition"-type DIE (with
  613. DW_AT_specification referencing the decl DIE), i.e.,
  614. the compiler has probably optimized the method away.
  615. In this case, all we can hope to do is issue a warning
  616. to the user letting him know. If the user has not actually
  617. requested using this method, things should still work. */
  618. warning (_("Method %s appears to be optimized out.\n"
  619. "All references to this method will be undefined."),
  620. TYPE_FN_FIELD_PHYSNAME (methods, j));
  621. continue;
  622. }
  623. const char *filename = symbol_symtab (sym.symbol)->filename;
  624. unsigned int line = sym.symbol->line ();
  625. CORE_ADDR address = BLOCK_START (SYMBOL_BLOCK_VALUE (sym.symbol));
  626. const char *kind;
  627. if (TYPE_FN_FIELD_STATIC_P (methods, j))
  628. {
  629. kind = "static method";
  630. method_type = compile_cplus_convert_func
  631. (instance, TYPE_FN_FIELD_TYPE (methods, j), true);
  632. }
  633. else
  634. {
  635. kind = "method";
  636. method_type = (compile_cplus_convert_method
  637. (instance, type, TYPE_FN_FIELD_TYPE (methods, j)));
  638. }
  639. if (TYPE_FN_FIELD_VIRTUAL_P (methods, j))
  640. sym_kind |= GCC_CP_FLAG_VIRTUAL_FUNCTION;
  641. instance->plugin ().build_decl
  642. (kind, overloaded_name.get (),
  643. (sym_kind | get_method_access_flag (type, i, j)).raw (),
  644. method_type, nullptr, address, filename, line);
  645. }
  646. }
  647. }
  648. /* Convert a struct or union type to its gcc representation. If this type
  649. was defined in another type, NESTED_ACCESS should indicate the
  650. accessibility of this type. */
  651. static gcc_type
  652. compile_cplus_convert_struct_or_union (compile_cplus_instance *instance,
  653. struct type *type,
  654. enum gcc_cp_symbol_kind nested_access)
  655. {
  656. const char *filename = nullptr;
  657. unsigned short line = 0;
  658. /* Get the decl name of this type. */
  659. gdb::unique_xmalloc_ptr<char> name
  660. = compile_cplus_instance::decl_name (type->name ());
  661. /* Create a new scope for TYPE. */
  662. compile_scope scope = instance->new_scope (type->name (), type);
  663. if (scope.nested_type () != GCC_TYPE_NONE)
  664. {
  665. /* The type requested was actually defined inside another type,
  666. such as a nested class definition. Return that type. */
  667. return scope.nested_type ();
  668. }
  669. /* Push all scopes. */
  670. instance->enter_scope (std::move (scope));
  671. /* First we create the resulting type and enter it into our hash
  672. table. This lets recursive types work. */
  673. gcc_decl resuld;
  674. if (type->code () == TYPE_CODE_STRUCT)
  675. {
  676. const char *what = type->is_declared_class () ? "class" : "struct";
  677. resuld = instance->plugin ().build_decl
  678. (what, name.get (), (GCC_CP_SYMBOL_CLASS | nested_access
  679. | (type->is_declared_class ()
  680. ? GCC_CP_FLAG_CLASS_NOFLAG
  681. : GCC_CP_FLAG_CLASS_IS_STRUCT)),
  682. 0, nullptr, 0, filename, line);
  683. }
  684. else
  685. {
  686. gdb_assert (type->code () == TYPE_CODE_UNION);
  687. resuld = instance->plugin ().build_decl
  688. ("union", name.get (), GCC_CP_SYMBOL_UNION | nested_access,
  689. 0, nullptr, 0, filename, line);
  690. }
  691. gcc_type result;
  692. if (type->code () == TYPE_CODE_STRUCT)
  693. {
  694. int num_baseclasses = TYPE_N_BASECLASSES (type);
  695. std::vector<gcc_type> elements (num_baseclasses);
  696. std::vector<enum gcc_cp_symbol_kind> flags (num_baseclasses);
  697. struct gcc_vbase_array bases {};
  698. bases.elements = elements.data ();
  699. bases.flags = flags.data ();
  700. bases.n_elements = num_baseclasses;
  701. for (int i = 0; i < num_baseclasses; ++i)
  702. {
  703. struct type *base_type = TYPE_BASECLASS (type, i);
  704. bases.flags[i] = (GCC_CP_SYMBOL_BASECLASS
  705. | get_field_access_flag (type, i)
  706. | (BASETYPE_VIA_VIRTUAL (type, i)
  707. ? GCC_CP_FLAG_BASECLASS_VIRTUAL
  708. : GCC_CP_FLAG_BASECLASS_NOFLAG));
  709. bases.elements[i] = instance->convert_type (base_type);
  710. }
  711. result = instance->plugin ().start_class_type
  712. (name.get (), resuld, &bases, filename, line);
  713. }
  714. else
  715. {
  716. gdb_assert (type->code () == TYPE_CODE_UNION);
  717. result = instance->plugin ().start_class_type
  718. (name.get (), resuld, nullptr, filename, line);
  719. }
  720. instance->insert_type (type, result);
  721. /* Add definitions. */
  722. compile_cplus_convert_type_defns (instance, type);
  723. /* Add methods. */
  724. compile_cplus_convert_struct_or_union_methods (instance, type, result);
  725. /* Add members. */
  726. compile_cplus_convert_struct_or_union_members (instance, type, result);
  727. /* All finished. */
  728. instance->plugin ().finish_class_type (name.get (), TYPE_LENGTH (type));
  729. /* Pop all scopes. */
  730. instance->leave_scope ();
  731. return result;
  732. }
  733. /* Convert an enum type to its gcc representation. If this type
  734. was defined in another type, NESTED_ACCESS should indicate the
  735. accessibility of this type.*/
  736. static gcc_type
  737. compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
  738. enum gcc_cp_symbol_kind nested_access)
  739. {
  740. bool scoped_enum_p = false;
  741. /* Create a new scope for this type. */
  742. compile_scope scope = instance->new_scope (type->name (), type);
  743. if (scope.nested_type () != GCC_TYPE_NONE)
  744. {
  745. /* The type requested was actually defined inside another type,
  746. such as a nested class definition. Return that type. */
  747. return scope.nested_type ();
  748. }
  749. gdb::unique_xmalloc_ptr<char> name
  750. = compile_cplus_instance::decl_name (type->name ());
  751. /* Push all scopes. */
  752. instance->enter_scope (std::move (scope));
  753. gcc_type int_type
  754. = instance->plugin ().get_int_type (type->is_unsigned (),
  755. TYPE_LENGTH (type), nullptr);
  756. gcc_type result
  757. = instance->plugin ().start_enum_type (name.get (), int_type,
  758. GCC_CP_SYMBOL_ENUM | nested_access
  759. | (scoped_enum_p
  760. ? GCC_CP_FLAG_ENUM_SCOPED
  761. : GCC_CP_FLAG_ENUM_NOFLAG),
  762. nullptr, 0);
  763. for (int i = 0; i < type->num_fields (); ++i)
  764. {
  765. gdb::unique_xmalloc_ptr<char> fname
  766. = compile_cplus_instance::decl_name (type->field (i).name ());
  767. if (type->field (i).loc_kind () != FIELD_LOC_KIND_ENUMVAL
  768. || fname == nullptr)
  769. continue;
  770. instance->plugin ().build_enum_constant (result, fname.get (),
  771. type->field (i).loc_enumval ());
  772. }
  773. /* Finish enum definition and pop scopes. */
  774. instance->plugin ().finish_enum_type (result);
  775. instance->leave_scope ();
  776. return result;
  777. }
  778. /* Convert a function type to its gcc representation. This function does
  779. not deal with function templates. */
  780. static gcc_type
  781. compile_cplus_convert_func (compile_cplus_instance *instance,
  782. struct type *type, bool strip_artificial)
  783. {
  784. int is_varargs = type->has_varargs ();
  785. struct type *target_type = TYPE_TARGET_TYPE (type);
  786. /* Functions with no debug info have no return type. Ideally we'd
  787. want to fallback to the type of the cast just before the
  788. function, like GDB's built-in expression parser, but we don't
  789. have access to that type here. For now, fallback to int, like
  790. GDB's parser used to do. */
  791. if (target_type == nullptr)
  792. {
  793. if (type->is_objfile_owned ())
  794. target_type = objfile_type (type->objfile_owner ())->builtin_int;
  795. else
  796. target_type = builtin_type (type->arch_owner ())->builtin_int;
  797. warning (_("function has unknown return type; assuming int"));
  798. }
  799. /* This approach means we can't make self-referential function
  800. types. Those are impossible in C, though. */
  801. gcc_type return_type = instance->convert_type (target_type);
  802. std::vector<gcc_type> elements (type->num_fields ());
  803. struct gcc_type_array array = { type->num_fields (), elements.data () };
  804. int artificials = 0;
  805. for (int i = 0; i < type->num_fields (); ++i)
  806. {
  807. if (strip_artificial && TYPE_FIELD_ARTIFICIAL (type, i))
  808. {
  809. --array.n_elements;
  810. ++artificials;
  811. }
  812. else
  813. {
  814. array.elements[i - artificials]
  815. = instance->convert_type (type->field (i).type ());
  816. }
  817. }
  818. /* We omit setting the argument types to `void' to be a little flexible
  819. with some minsyms like printf (compile-cplus.exp has examples). */
  820. gcc_type result = instance->plugin ().build_function_type
  821. (return_type, &array, is_varargs);
  822. return result;
  823. }
  824. /* Convert an integer type to its gcc representation. */
  825. static gcc_type
  826. compile_cplus_convert_int (compile_cplus_instance *instance, struct type *type)
  827. {
  828. if (type->has_no_signedness ())
  829. {
  830. gdb_assert (TYPE_LENGTH (type) == 1);
  831. return instance->plugin ().get_char_type ();
  832. }
  833. return instance->plugin ().get_int_type
  834. (type->is_unsigned (), TYPE_LENGTH (type), type->name ());
  835. }
  836. /* Convert a floating-point type to its gcc representation. */
  837. static gcc_type
  838. compile_cplus_convert_float (compile_cplus_instance *instance,
  839. struct type *type)
  840. {
  841. return instance->plugin ().get_float_type
  842. (TYPE_LENGTH (type), type->name ());
  843. }
  844. /* Convert the 'void' type to its gcc representation. */
  845. static gcc_type
  846. compile_cplus_convert_void (compile_cplus_instance *instance, struct type *type)
  847. {
  848. return instance->plugin ().get_void_type ();
  849. }
  850. /* Convert a boolean type to its gcc representation. */
  851. static gcc_type
  852. compile_cplus_convert_bool (compile_cplus_instance *instance, struct type *type)
  853. {
  854. return instance->plugin ().get_bool_type ();
  855. }
  856. /* See description in compile-cplus.h. */
  857. gcc_type
  858. compile_cplus_instance::convert_qualified_base (gcc_type base,
  859. gcc_cp_qualifiers_flags quals)
  860. {
  861. gcc_type result = base;
  862. if (quals != 0)
  863. result = plugin ().build_qualified_type (base, quals.raw ());
  864. return result;
  865. }
  866. /* See description in compile-cplus.h. */
  867. static gcc_type
  868. compile_cplus_convert_qualified (compile_cplus_instance *instance,
  869. struct type *type)
  870. {
  871. struct type *unqual = make_unqualified_type (type);
  872. gcc_cp_qualifiers_flags quals = (enum gcc_cp_qualifiers) 0;
  873. gcc_type unqual_converted = instance->convert_type (unqual);
  874. if (TYPE_CONST (type))
  875. quals |= GCC_CP_QUALIFIER_CONST;
  876. if (TYPE_VOLATILE (type))
  877. quals |= GCC_CP_QUALIFIER_VOLATILE;
  878. if (TYPE_RESTRICT (type))
  879. quals |= GCC_CP_QUALIFIER_RESTRICT;
  880. return instance->convert_qualified_base (unqual_converted, quals);
  881. }
  882. /* Convert a complex type to its gcc representation. */
  883. static gcc_type
  884. compile_cplus_convert_complex (compile_cplus_instance *instance,
  885. struct type *type)
  886. {
  887. gcc_type base = instance->convert_type (TYPE_TARGET_TYPE (type));
  888. return instance->plugin ().build_complex_type (base);
  889. }
  890. /* Convert a namespace of TYPE. */
  891. static gcc_type
  892. compile_cplus_convert_namespace (compile_cplus_instance *instance,
  893. struct type *type)
  894. {
  895. compile_scope scope = instance->new_scope (type->name (), type);
  896. gdb::unique_xmalloc_ptr<char> name
  897. = compile_cplus_instance::decl_name (type->name ());
  898. /* Push scope. */
  899. instance->enter_scope (std::move (scope));
  900. /* Convert this namespace. */
  901. instance->plugin ().push_namespace (name.get ());
  902. instance->plugin ().pop_binding_level (name.get ());
  903. /* Pop scope. */
  904. instance->leave_scope ();
  905. /* Namespaces are non-cacheable types. */
  906. return GCC_TYPE_NONE;
  907. }
  908. /* A helper function which knows how to convert most types from their
  909. gdb representation to the corresponding gcc form. This examines
  910. the TYPE and dispatches to the appropriate conversion function. It
  911. returns the gcc type.
  912. If the type was defined in another type, NESTED_ACCESS should indicate the
  913. accessibility of this type. */
  914. static gcc_type
  915. convert_type_cplus_basic (compile_cplus_instance *instance,
  916. struct type *type,
  917. enum gcc_cp_symbol_kind nested_access)
  918. {
  919. /* If we are converting a qualified type, first convert the
  920. unqualified type and then apply the qualifiers. */
  921. if ((type->instance_flags () & (TYPE_INSTANCE_FLAG_CONST
  922. | TYPE_INSTANCE_FLAG_VOLATILE
  923. | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
  924. return compile_cplus_convert_qualified (instance, type);
  925. switch (type->code ())
  926. {
  927. case TYPE_CODE_REF:
  928. case TYPE_CODE_RVALUE_REF:
  929. return compile_cplus_convert_reference (instance, type);
  930. case TYPE_CODE_PTR:
  931. return compile_cplus_convert_pointer (instance, type);
  932. case TYPE_CODE_ARRAY:
  933. return compile_cplus_convert_array (instance, type);
  934. case TYPE_CODE_STRUCT:
  935. case TYPE_CODE_UNION:
  936. return
  937. compile_cplus_convert_struct_or_union (instance, type, nested_access);
  938. case TYPE_CODE_ENUM:
  939. return compile_cplus_convert_enum (instance, type, nested_access);
  940. case TYPE_CODE_FUNC:
  941. return compile_cplus_convert_func (instance, type, false);
  942. case TYPE_CODE_METHOD:
  943. return
  944. compile_cplus_convert_method (instance, TYPE_SELF_TYPE (type), type);
  945. case TYPE_CODE_MEMBERPTR:
  946. case TYPE_CODE_METHODPTR:
  947. return compile_cplus_convert_memberptr (instance, type);
  948. break;
  949. case TYPE_CODE_INT:
  950. return compile_cplus_convert_int (instance, type);
  951. case TYPE_CODE_FLT:
  952. return compile_cplus_convert_float (instance, type);
  953. case TYPE_CODE_VOID:
  954. return compile_cplus_convert_void (instance, type);
  955. case TYPE_CODE_BOOL:
  956. return compile_cplus_convert_bool (instance, type);
  957. case TYPE_CODE_COMPLEX:
  958. return compile_cplus_convert_complex (instance, type);
  959. case TYPE_CODE_NAMESPACE:
  960. return compile_cplus_convert_namespace (instance, type);
  961. case TYPE_CODE_TYPEDEF:
  962. return compile_cplus_convert_typedef (instance, type, nested_access);
  963. default:
  964. break;
  965. }
  966. std::string s = string_printf (_("unhandled TYPE_CODE %d"),
  967. type->code ());
  968. return instance->plugin ().error (s.c_str ());
  969. }
  970. gcc_type
  971. compile_cplus_instance::convert_type (struct type *type,
  972. enum gcc_cp_symbol_kind nested_access)
  973. {
  974. /* Check if TYPE has already been converted. */
  975. gcc_type result;
  976. if (get_cached_type (type, &result))
  977. return result;
  978. /* It is the first time this type has been seen -- convert it
  979. and cache it, if appropriate.. */
  980. result = convert_type_cplus_basic (this, type, nested_access);
  981. if (result != GCC_TYPE_NONE)
  982. insert_type (type, result);
  983. return result;
  984. }
  985. void
  986. compile_cplus_instance::gcc_cplus_enter_scope
  987. (void *datum, struct gcc_cp_context *gcc_context)
  988. {
  989. }
  990. void
  991. compile_cplus_instance::gcc_cplus_leave_scope
  992. (void *datum, struct gcc_cp_context *gcc_context)
  993. {
  994. }
  995. /* Plug-in forwards. */
  996. /* C++ plug-in wrapper. */
  997. /* A result printer for plug-in calls that return a gcc_type or
  998. gcc_decl. */
  999. static void
  1000. compile_cplus_debug_output_1 (ULONGEST arg)
  1001. {
  1002. gdb_printf (gdb_stdlog, "%s", pulongest (arg));
  1003. }
  1004. static void
  1005. compile_cplus_debug_output_1 (const char *arg)
  1006. {
  1007. if (arg == nullptr)
  1008. gdb_puts ("NULL", gdb_stdlog);
  1009. else
  1010. gdb_puts (arg, gdb_stdlog);
  1011. }
  1012. static void
  1013. compile_cplus_debug_output ()
  1014. {
  1015. }
  1016. template <typename T>
  1017. static void
  1018. compile_cplus_debug_output_1 (const T *arg)
  1019. {
  1020. }
  1021. template <typename T, typename... Targs>
  1022. static void
  1023. compile_cplus_debug_output (T arg, Targs... Args)
  1024. {
  1025. compile_cplus_debug_output_1 (arg);
  1026. gdb_putc (' ', gdb_stdlog);
  1027. compile_cplus_debug_output (Args...);
  1028. }
  1029. #define FORWARD(OP,...) m_context->cp_ops->OP(m_context, ##__VA_ARGS__)
  1030. #define OUTPUT_DEBUG_RESULT(R) \
  1031. if (debug_compile_cplus_types) \
  1032. { \
  1033. gdb_puts (": ", gdb_stdlog); \
  1034. compile_cplus_debug_output (R); \
  1035. gdb_putc ('\n', gdb_stdlog); \
  1036. } \
  1037. #define GCC_METHOD0(R, N) \
  1038. R gcc_cp_plugin::N () const \
  1039. { \
  1040. if (debug_compile_cplus_types) \
  1041. compile_cplus_debug_output (STRINGIFY (N)); \
  1042. auto result = FORWARD (N); \
  1043. OUTPUT_DEBUG_RESULT (result); \
  1044. return result; \
  1045. }
  1046. #define GCC_METHOD1(R, N, A) \
  1047. R gcc_cp_plugin::N (A a) const \
  1048. { \
  1049. if (debug_compile_cplus_types) \
  1050. compile_cplus_debug_output (STRINGIFY (N), a); \
  1051. auto result = FORWARD (N, a); \
  1052. OUTPUT_DEBUG_RESULT (result); \
  1053. return result; \
  1054. }
  1055. #define GCC_METHOD2(R, N, A, B) \
  1056. R gcc_cp_plugin::N (A a, B b) const \
  1057. { \
  1058. if (debug_compile_cplus_types) \
  1059. compile_cplus_debug_output (STRINGIFY (N), a, b); \
  1060. auto result = FORWARD (N, a, b); \
  1061. OUTPUT_DEBUG_RESULT (result); \
  1062. return result; \
  1063. }
  1064. #define GCC_METHOD3(R, N, A, B, C) \
  1065. R gcc_cp_plugin::N (A a, B b, C c) const \
  1066. { \
  1067. if (debug_compile_cplus_types) \
  1068. compile_cplus_debug_output (STRINGIFY (N), a, b, c); \
  1069. auto result = FORWARD (N, a, b, c); \
  1070. OUTPUT_DEBUG_RESULT (result); \
  1071. return result; \
  1072. }
  1073. #define GCC_METHOD4(R, N, A, B, C, D) \
  1074. R gcc_cp_plugin::N (A a, B b, C c, D d) const \
  1075. { \
  1076. if (debug_compile_cplus_types) \
  1077. compile_cplus_debug_output (STRINGIFY (N), a, b, c, d); \
  1078. auto result = FORWARD (N, a, b, c, d); \
  1079. OUTPUT_DEBUG_RESULT (result); \
  1080. return result; \
  1081. }
  1082. #define GCC_METHOD5(R, N, A, B, C, D, E) \
  1083. R gcc_cp_plugin::N (A a, B b, C c, D d, E e) const \
  1084. { \
  1085. if (debug_compile_cplus_types) \
  1086. compile_cplus_debug_output (STRINGIFY (N), a, b, c, d, e); \
  1087. auto result = FORWARD (N, a, b, c, d, e); \
  1088. OUTPUT_DEBUG_RESULT (result); \
  1089. return result; \
  1090. }
  1091. #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
  1092. R gcc_cp_plugin::N (A a, B b, C c, D d, E e, F f, G g) const \
  1093. { \
  1094. if (debug_compile_cplus_types) \
  1095. compile_cplus_debug_output (STRINGIFY (N), a, b, c, d, e, f, g); \
  1096. auto result = FORWARD (N, a, b, c, d, e, f, g); \
  1097. OUTPUT_DEBUG_RESULT (result); \
  1098. return result; \
  1099. }
  1100. #include "gcc-cp-fe.def"
  1101. #undef GCC_METHOD0
  1102. #undef GCC_METHOD1
  1103. #undef GCC_METHOD2
  1104. #undef GCC_METHOD3
  1105. #undef GCC_METHOD4
  1106. #undef GCC_METHOD5
  1107. #undef GCC_METHOD7
  1108. #undef FORWARD
  1109. #undef OUTPUT_DEBUG_RESULT
  1110. gcc_expr
  1111. gcc_cp_plugin::build_decl (const char *debug_decltype, const char *name,
  1112. enum gcc_cp_symbol_kind sym_kind, gcc_type sym_type,
  1113. const char *substitution_name, gcc_address address,
  1114. const char *filename, unsigned int line_number)
  1115. {
  1116. if (debug_compile_cplus_types)
  1117. gdb_printf (gdb_stdlog, "<%s> ", debug_decltype);
  1118. return build_decl (name, sym_kind, sym_type, substitution_name,
  1119. address, filename, line_number);
  1120. }
  1121. gcc_type
  1122. gcc_cp_plugin::start_class_type (const char *debug_name, gcc_decl typedecl,
  1123. const struct gcc_vbase_array *base_classes,
  1124. const char *filename, unsigned int line_number)
  1125. {
  1126. if (debug_compile_cplus_types)
  1127. gdb_printf (gdb_stdlog, "<%s> ", debug_name);
  1128. return start_class_type (typedecl, base_classes, filename, line_number);
  1129. }
  1130. int
  1131. gcc_cp_plugin::finish_class_type (const char *debug_name,
  1132. unsigned long size_in_bytes)
  1133. {
  1134. if (debug_compile_cplus_types)
  1135. gdb_printf (gdb_stdlog, "<%s> ", debug_name);
  1136. return finish_class_type (size_in_bytes);
  1137. }
  1138. int
  1139. gcc_cp_plugin::pop_binding_level (const char *debug_name)
  1140. {
  1141. if (debug_compile_cplus_types)
  1142. gdb_printf (gdb_stdlog, "<%s> ", debug_name);
  1143. return pop_binding_level ();
  1144. }
  1145. void _initialize_compile_cplus_types ();
  1146. void
  1147. _initialize_compile_cplus_types ()
  1148. {
  1149. add_setshow_boolean_cmd ("compile-cplus-types", no_class,
  1150. &debug_compile_cplus_types, _("\
  1151. Set debugging of C++ compile type conversion."), _("\
  1152. Show debugging of C++ compile type conversion."), _("\
  1153. When enabled debugging messages are printed during C++ type conversion for\n\
  1154. the compile commands."),
  1155. nullptr,
  1156. nullptr,
  1157. &setdebuglist,
  1158. &showdebuglist);
  1159. add_setshow_boolean_cmd ("compile-cplus-scopes", no_class,
  1160. &debug_compile_cplus_scopes, _("\
  1161. Set debugging of C++ compile scopes."), _("\
  1162. Show debugging of C++ compile scopes."), _("\
  1163. When enabled debugging messages are printed about definition scopes during\n\
  1164. C++ type conversion for the compile commands."),
  1165. nullptr,
  1166. nullptr,
  1167. &setdebuglist,
  1168. &showdebuglist);
  1169. }