f-valprint.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /* Support for printing Fortran values for GDB, the GNU debugger.
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. Contributed by Motorola. Adapted from the C definitions by Farooq Butt
  4. (fmbutt@engage.sps.mot.com), additionally worked over by Stan Shebs.
  5. This file is part of GDB.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include "defs.h"
  17. #include "annotate.h"
  18. #include "symtab.h"
  19. #include "gdbtypes.h"
  20. #include "expression.h"
  21. #include "value.h"
  22. #include "valprint.h"
  23. #include "language.h"
  24. #include "f-lang.h"
  25. #include "frame.h"
  26. #include "gdbcore.h"
  27. #include "command.h"
  28. #include "block.h"
  29. #include "dictionary.h"
  30. #include "cli/cli-style.h"
  31. #include "gdbarch.h"
  32. #include "f-array-walker.h"
  33. static void f77_get_dynamic_length_of_aggregate (struct type *);
  34. LONGEST
  35. f77_get_lowerbound (struct type *type)
  36. {
  37. if (type->bounds ()->low.kind () != PROP_CONST)
  38. error (_("Lower bound may not be '*' in F77"));
  39. return type->bounds ()->low.const_val ();
  40. }
  41. LONGEST
  42. f77_get_upperbound (struct type *type)
  43. {
  44. if (type->bounds ()->high.kind () != PROP_CONST)
  45. {
  46. /* We have an assumed size array on our hands. Assume that
  47. upper_bound == lower_bound so that we show at least 1 element.
  48. If the user wants to see more elements, let him manually ask for 'em
  49. and we'll subscript the array and show him. */
  50. return f77_get_lowerbound (type);
  51. }
  52. return type->bounds ()->high.const_val ();
  53. }
  54. /* Obtain F77 adjustable array dimensions. */
  55. static void
  56. f77_get_dynamic_length_of_aggregate (struct type *type)
  57. {
  58. int upper_bound = -1;
  59. int lower_bound = 1;
  60. /* Recursively go all the way down into a possibly multi-dimensional
  61. F77 array and get the bounds. For simple arrays, this is pretty
  62. easy but when the bounds are dynamic, we must be very careful
  63. to add up all the lengths correctly. Not doing this right
  64. will lead to horrendous-looking arrays in parameter lists.
  65. This function also works for strings which behave very
  66. similarly to arrays. */
  67. if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ARRAY
  68. || TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_STRING)
  69. f77_get_dynamic_length_of_aggregate (TYPE_TARGET_TYPE (type));
  70. /* Recursion ends here, start setting up lengths. */
  71. lower_bound = f77_get_lowerbound (type);
  72. upper_bound = f77_get_upperbound (type);
  73. /* Patch in a valid length value. */
  74. TYPE_LENGTH (type) =
  75. (upper_bound - lower_bound + 1)
  76. * TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type)));
  77. }
  78. /* Per-dimension statistics. */
  79. struct dimension_stats
  80. {
  81. /* The type of the index used to address elements in the dimension. */
  82. struct type *index_type;
  83. /* Total number of elements in the dimension, counted as we go. */
  84. int nelts;
  85. };
  86. /* A class used by FORTRAN_PRINT_ARRAY as a specialisation of the array
  87. walking template. This specialisation prints Fortran arrays. */
  88. class fortran_array_printer_impl : public fortran_array_walker_base_impl
  89. {
  90. public:
  91. /* Constructor. TYPE is the array type being printed, ADDRESS is the
  92. address in target memory for the object of TYPE being printed. VAL is
  93. the GDB value (of TYPE) being printed. STREAM is where to print to,
  94. RECOURSE is passed through (and prevents infinite recursion), and
  95. OPTIONS are the printing control options. */
  96. explicit fortran_array_printer_impl (struct type *type,
  97. CORE_ADDR address,
  98. struct value *val,
  99. struct ui_file *stream,
  100. int recurse,
  101. const struct value_print_options *options)
  102. : m_elts (0),
  103. m_val (val),
  104. m_stream (stream),
  105. m_recurse (recurse),
  106. m_options (options),
  107. m_dimension (0),
  108. m_nrepeats (0),
  109. m_stats (0)
  110. { /* Nothing. */ }
  111. /* Called while iterating over the array bounds. When SHOULD_CONTINUE is
  112. false then we must return false, as we have reached the end of the
  113. array bounds for this dimension. However, we also return false if we
  114. have printed too many elements (after printing '...'). In all other
  115. cases, return true. */
  116. bool continue_walking (bool should_continue)
  117. {
  118. bool cont = should_continue && (m_elts < m_options->print_max);
  119. if (!cont && should_continue)
  120. gdb_puts ("...", m_stream);
  121. return cont;
  122. }
  123. /* Called when we start iterating over a dimension. If it's not the
  124. inner most dimension then print an opening '(' character. */
  125. void start_dimension (struct type *index_type, LONGEST nelts, bool inner_p)
  126. {
  127. size_t dim_indx = m_dimension++;
  128. m_elt_type_prev = nullptr;
  129. if (m_stats.size () < m_dimension)
  130. {
  131. m_stats.resize (m_dimension);
  132. m_stats[dim_indx].index_type = index_type;
  133. m_stats[dim_indx].nelts = nelts;
  134. }
  135. gdb_puts ("(", m_stream);
  136. }
  137. /* Called when we finish processing a batch of items within a dimension
  138. of the array. Depending on whether this is the inner most dimension
  139. or not we print different things, but this is all about adding
  140. separators between elements, and dimensions of the array. */
  141. void finish_dimension (bool inner_p, bool last_p)
  142. {
  143. gdb_puts (")", m_stream);
  144. if (!last_p)
  145. gdb_puts (" ", m_stream);
  146. m_dimension--;
  147. }
  148. /* Called when processing dimensions of the array other than the
  149. innermost one. WALK_1 is the walker to normally call, ELT_TYPE is
  150. the type of the element being extracted, and ELT_OFF is the offset
  151. of the element from the start of array being walked, INDEX_TYPE
  152. and INDEX is the type and the value respectively of the element's
  153. index in the dimension currently being walked and LAST_P is true
  154. only when this is the last element that will be processed in this
  155. dimension. */
  156. void process_dimension (gdb::function_view<void (struct type *,
  157. int, bool)> walk_1,
  158. struct type *elt_type, LONGEST elt_off,
  159. LONGEST index, bool last_p)
  160. {
  161. size_t dim_indx = m_dimension - 1;
  162. struct type *elt_type_prev = m_elt_type_prev;
  163. LONGEST elt_off_prev = m_elt_off_prev;
  164. bool repeated = (m_options->repeat_count_threshold < UINT_MAX
  165. && elt_type_prev != nullptr
  166. && (m_elts + ((m_nrepeats + 1)
  167. * m_stats[dim_indx + 1].nelts)
  168. <= m_options->print_max)
  169. && dimension_contents_eq (m_val, elt_type,
  170. elt_off_prev, elt_off));
  171. if (repeated)
  172. m_nrepeats++;
  173. if (!repeated || last_p)
  174. {
  175. LONGEST nrepeats = m_nrepeats;
  176. m_nrepeats = 0;
  177. if (nrepeats >= m_options->repeat_count_threshold)
  178. {
  179. annotate_elt_rep (nrepeats + 1);
  180. gdb_printf (m_stream, "%p[<repeats %s times>%p]",
  181. metadata_style.style ().ptr (),
  182. plongest (nrepeats + 1),
  183. nullptr);
  184. annotate_elt_rep_end ();
  185. if (!repeated)
  186. gdb_puts (" ", m_stream);
  187. m_elts += nrepeats * m_stats[dim_indx + 1].nelts;
  188. }
  189. else
  190. for (LONGEST i = nrepeats; i > 0; i--)
  191. {
  192. maybe_print_array_index (m_stats[dim_indx].index_type,
  193. index - nrepeats + repeated,
  194. m_stream, m_options);
  195. walk_1 (elt_type_prev, elt_off_prev, repeated && i == 1);
  196. }
  197. if (!repeated)
  198. {
  199. /* We need to specially handle the case of hitting `print_max'
  200. exactly as recursing would cause lone `(...)' to be printed.
  201. And we need to print `...' by hand if the skipped element
  202. would be the last one processed, because the subsequent call
  203. to `continue_walking' from our caller won't do that. */
  204. if (m_elts < m_options->print_max)
  205. {
  206. maybe_print_array_index (m_stats[dim_indx].index_type, index,
  207. m_stream, m_options);
  208. walk_1 (elt_type, elt_off, last_p);
  209. nrepeats++;
  210. }
  211. else if (last_p)
  212. gdb_puts ("...", m_stream);
  213. }
  214. }
  215. m_elt_type_prev = elt_type;
  216. m_elt_off_prev = elt_off;
  217. }
  218. /* Called to process an element of ELT_TYPE at offset ELT_OFF from the
  219. start of the parent object, where INDEX is the value of the element's
  220. index in the dimension currently being walked and LAST_P is true only
  221. when this is the last element to be processed in this dimension. */
  222. void process_element (struct type *elt_type, LONGEST elt_off,
  223. LONGEST index, bool last_p)
  224. {
  225. size_t dim_indx = m_dimension - 1;
  226. struct type *elt_type_prev = m_elt_type_prev;
  227. LONGEST elt_off_prev = m_elt_off_prev;
  228. bool repeated = (m_options->repeat_count_threshold < UINT_MAX
  229. && elt_type_prev != nullptr
  230. && value_contents_eq (m_val, elt_off_prev, m_val, elt_off,
  231. TYPE_LENGTH (elt_type)));
  232. if (repeated)
  233. m_nrepeats++;
  234. if (!repeated || last_p || m_elts + 1 == m_options->print_max)
  235. {
  236. LONGEST nrepeats = m_nrepeats;
  237. bool printed = false;
  238. if (nrepeats != 0)
  239. {
  240. m_nrepeats = 0;
  241. if (nrepeats >= m_options->repeat_count_threshold)
  242. {
  243. annotate_elt_rep (nrepeats + 1);
  244. gdb_printf (m_stream, "%p[<repeats %s times>%p]",
  245. metadata_style.style ().ptr (),
  246. plongest (nrepeats + 1),
  247. nullptr);
  248. annotate_elt_rep_end ();
  249. }
  250. else
  251. {
  252. /* Extract the element value from the parent value. */
  253. struct value *e_val
  254. = value_from_component (m_val, elt_type, elt_off_prev);
  255. for (LONGEST i = nrepeats; i > 0; i--)
  256. {
  257. maybe_print_array_index (m_stats[dim_indx].index_type,
  258. index - i + 1,
  259. m_stream, m_options);
  260. common_val_print (e_val, m_stream, m_recurse, m_options,
  261. current_language);
  262. if (i > 1)
  263. gdb_puts (", ", m_stream);
  264. }
  265. }
  266. printed = true;
  267. }
  268. if (!repeated)
  269. {
  270. /* Extract the element value from the parent value. */
  271. struct value *e_val
  272. = value_from_component (m_val, elt_type, elt_off);
  273. if (printed)
  274. gdb_puts (", ", m_stream);
  275. maybe_print_array_index (m_stats[dim_indx].index_type, index,
  276. m_stream, m_options);
  277. common_val_print (e_val, m_stream, m_recurse, m_options,
  278. current_language);
  279. }
  280. if (!last_p)
  281. gdb_puts (", ", m_stream);
  282. }
  283. m_elt_type_prev = elt_type;
  284. m_elt_off_prev = elt_off;
  285. ++m_elts;
  286. }
  287. private:
  288. /* Called to compare two VAL elements of ELT_TYPE at offsets OFFSET1
  289. and OFFSET2 each. Handle subarrays recursively, because they may
  290. have been sliced and we do not want to compare any memory contents
  291. present between the slices requested. */
  292. bool
  293. dimension_contents_eq (const struct value *val, struct type *type,
  294. LONGEST offset1, LONGEST offset2)
  295. {
  296. if (type->code () == TYPE_CODE_ARRAY
  297. && TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_CHAR)
  298. {
  299. /* Extract the range, and get lower and upper bounds. */
  300. struct type *range_type = check_typedef (type)->index_type ();
  301. LONGEST lowerbound, upperbound;
  302. if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
  303. error ("failed to get range bounds");
  304. /* CALC is used to calculate the offsets for each element. */
  305. fortran_array_offset_calculator calc (type);
  306. struct type *subarray_type = check_typedef (TYPE_TARGET_TYPE (type));
  307. for (LONGEST i = lowerbound; i < upperbound + 1; i++)
  308. {
  309. /* Use the index and the stride to work out a new offset. */
  310. LONGEST index_offset = calc.index_offset (i);
  311. if (!dimension_contents_eq (val, subarray_type,
  312. offset1 + index_offset,
  313. offset2 + index_offset))
  314. return false;
  315. }
  316. return true;
  317. }
  318. else
  319. return value_contents_eq (val, offset1, val, offset2,
  320. TYPE_LENGTH (type));
  321. }
  322. /* The number of elements printed so far. */
  323. int m_elts;
  324. /* The value from which we are printing elements. */
  325. struct value *m_val;
  326. /* The stream we should print too. */
  327. struct ui_file *m_stream;
  328. /* The recursion counter, passed through when we print each element. */
  329. int m_recurse;
  330. /* The print control options. Gives us the maximum number of elements to
  331. print, and is passed through to each element that we print. */
  332. const struct value_print_options *m_options = nullptr;
  333. /* The number of the current dimension being handled. */
  334. LONGEST m_dimension;
  335. /* The number of element repetitions in the current series. */
  336. LONGEST m_nrepeats;
  337. /* The type and offset from M_VAL of the element handled in the previous
  338. iteration over the current dimension. */
  339. struct type *m_elt_type_prev;
  340. LONGEST m_elt_off_prev;
  341. /* Per-dimension stats. */
  342. std::vector<struct dimension_stats> m_stats;
  343. };
  344. /* This function gets called to print a Fortran array. */
  345. static void
  346. fortran_print_array (struct type *type, CORE_ADDR address,
  347. struct ui_file *stream, int recurse,
  348. const struct value *val,
  349. const struct value_print_options *options)
  350. {
  351. fortran_array_walker<fortran_array_printer_impl> p
  352. (type, address, (struct value *) val, stream, recurse, options);
  353. p.walk ();
  354. }
  355. /* Decorations for Fortran. */
  356. static const struct generic_val_print_decorations f_decorations =
  357. {
  358. "(",
  359. ",",
  360. ")",
  361. ".TRUE.",
  362. ".FALSE.",
  363. "void",
  364. "{",
  365. "}"
  366. };
  367. /* See f-lang.h. */
  368. void
  369. f_language::value_print_inner (struct value *val, struct ui_file *stream,
  370. int recurse,
  371. const struct value_print_options *options) const
  372. {
  373. struct type *type = check_typedef (value_type (val));
  374. struct gdbarch *gdbarch = type->arch ();
  375. int printed_field = 0; /* Number of fields printed. */
  376. struct type *elttype;
  377. CORE_ADDR addr;
  378. int index;
  379. const gdb_byte *valaddr = value_contents_for_printing (val).data ();
  380. const CORE_ADDR address = value_address (val);
  381. switch (type->code ())
  382. {
  383. case TYPE_CODE_STRING:
  384. f77_get_dynamic_length_of_aggregate (type);
  385. printstr (stream, builtin_type (gdbarch)->builtin_char, valaddr,
  386. TYPE_LENGTH (type), NULL, 0, options);
  387. break;
  388. case TYPE_CODE_ARRAY:
  389. if (TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_CHAR)
  390. fortran_print_array (type, address, stream, recurse, val, options);
  391. else
  392. {
  393. struct type *ch_type = TYPE_TARGET_TYPE (type);
  394. f77_get_dynamic_length_of_aggregate (type);
  395. printstr (stream, ch_type, valaddr,
  396. TYPE_LENGTH (type) / TYPE_LENGTH (ch_type), NULL, 0,
  397. options);
  398. }
  399. break;
  400. case TYPE_CODE_PTR:
  401. if (options->format && options->format != 's')
  402. {
  403. value_print_scalar_formatted (val, options, 0, stream);
  404. break;
  405. }
  406. else
  407. {
  408. int want_space = 0;
  409. addr = unpack_pointer (type, valaddr);
  410. elttype = check_typedef (TYPE_TARGET_TYPE (type));
  411. if (elttype->code () == TYPE_CODE_FUNC)
  412. {
  413. /* Try to print what function it points to. */
  414. print_function_pointer_address (options, gdbarch, addr, stream);
  415. return;
  416. }
  417. if (options->symbol_print)
  418. want_space = print_address_demangle (options, gdbarch, addr,
  419. stream, demangle);
  420. else if (options->addressprint && options->format != 's')
  421. {
  422. gdb_puts (paddress (gdbarch, addr), stream);
  423. want_space = 1;
  424. }
  425. /* For a pointer to char or unsigned char, also print the string
  426. pointed to, unless pointer is null. */
  427. if (TYPE_LENGTH (elttype) == 1
  428. && elttype->code () == TYPE_CODE_INT
  429. && (options->format == 0 || options->format == 's')
  430. && addr != 0)
  431. {
  432. if (want_space)
  433. gdb_puts (" ", stream);
  434. val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1,
  435. stream, options);
  436. }
  437. return;
  438. }
  439. break;
  440. case TYPE_CODE_STRUCT:
  441. case TYPE_CODE_UNION:
  442. case TYPE_CODE_NAMELIST:
  443. /* Starting from the Fortran 90 standard, Fortran supports derived
  444. types. */
  445. gdb_printf (stream, "( ");
  446. for (index = 0; index < type->num_fields (); index++)
  447. {
  448. struct type *field_type
  449. = check_typedef (type->field (index).type ());
  450. if (field_type->code () != TYPE_CODE_FUNC)
  451. {
  452. const char *field_name = type->field (index).name ();
  453. struct value *field;
  454. if (type->code () == TYPE_CODE_NAMELIST)
  455. {
  456. /* While printing namelist items, fetch the appropriate
  457. value field before printing its value. */
  458. struct block_symbol sym
  459. = lookup_symbol (field_name, get_selected_block (nullptr),
  460. VAR_DOMAIN, nullptr);
  461. if (sym.symbol == nullptr)
  462. error (_("failed to find symbol for name list component %s"),
  463. field_name);
  464. field = value_of_variable (sym.symbol, sym.block);
  465. }
  466. else
  467. field = value_field (val, index);
  468. if (printed_field > 0)
  469. gdb_puts (", ", stream);
  470. if (field_name != NULL)
  471. {
  472. fputs_styled (field_name, variable_name_style.style (),
  473. stream);
  474. gdb_puts (" = ", stream);
  475. }
  476. common_val_print (field, stream, recurse + 1,
  477. options, current_language);
  478. ++printed_field;
  479. }
  480. }
  481. gdb_printf (stream, " )");
  482. break;
  483. case TYPE_CODE_BOOL:
  484. if (options->format || options->output_format)
  485. {
  486. struct value_print_options opts = *options;
  487. opts.format = (options->format ? options->format
  488. : options->output_format);
  489. value_print_scalar_formatted (val, &opts, 0, stream);
  490. }
  491. else
  492. {
  493. LONGEST longval = value_as_long (val);
  494. /* The Fortran standard doesn't specify how logical types are
  495. represented. Different compilers use different non zero
  496. values to represent logical true. */
  497. if (longval == 0)
  498. gdb_puts (f_decorations.false_name, stream);
  499. else
  500. gdb_puts (f_decorations.true_name, stream);
  501. }
  502. break;
  503. case TYPE_CODE_INT:
  504. case TYPE_CODE_REF:
  505. case TYPE_CODE_FUNC:
  506. case TYPE_CODE_FLAGS:
  507. case TYPE_CODE_FLT:
  508. case TYPE_CODE_VOID:
  509. case TYPE_CODE_ERROR:
  510. case TYPE_CODE_RANGE:
  511. case TYPE_CODE_UNDEF:
  512. case TYPE_CODE_COMPLEX:
  513. case TYPE_CODE_CHAR:
  514. default:
  515. generic_value_print (val, stream, recurse, options, &f_decorations);
  516. break;
  517. }
  518. }
  519. static void
  520. info_common_command_for_block (const struct block *block, const char *comname,
  521. int *any_printed)
  522. {
  523. struct block_iterator iter;
  524. struct symbol *sym;
  525. struct value_print_options opts;
  526. get_user_print_options (&opts);
  527. ALL_BLOCK_SYMBOLS (block, iter, sym)
  528. if (sym->domain () == COMMON_BLOCK_DOMAIN)
  529. {
  530. const struct common_block *common = SYMBOL_VALUE_COMMON_BLOCK (sym);
  531. size_t index;
  532. gdb_assert (sym->aclass () == LOC_COMMON_BLOCK);
  533. if (comname && (!sym->linkage_name ()
  534. || strcmp (comname, sym->linkage_name ()) != 0))
  535. continue;
  536. if (*any_printed)
  537. gdb_putc ('\n');
  538. else
  539. *any_printed = 1;
  540. if (sym->print_name ())
  541. gdb_printf (_("Contents of F77 COMMON block '%s':\n"),
  542. sym->print_name ());
  543. else
  544. gdb_printf (_("Contents of blank COMMON block:\n"));
  545. for (index = 0; index < common->n_entries; index++)
  546. {
  547. struct value *val = NULL;
  548. gdb_printf ("%s = ",
  549. common->contents[index]->print_name ());
  550. try
  551. {
  552. val = value_of_variable (common->contents[index], block);
  553. value_print (val, gdb_stdout, &opts);
  554. }
  555. catch (const gdb_exception_error &except)
  556. {
  557. fprintf_styled (gdb_stdout, metadata_style.style (),
  558. "<error reading variable: %s>",
  559. except.what ());
  560. }
  561. gdb_putc ('\n');
  562. }
  563. }
  564. }
  565. /* This function is used to print out the values in a given COMMON
  566. block. It will always use the most local common block of the
  567. given name. */
  568. static void
  569. info_common_command (const char *comname, int from_tty)
  570. {
  571. struct frame_info *fi;
  572. const struct block *block;
  573. int values_printed = 0;
  574. /* We have been told to display the contents of F77 COMMON
  575. block supposedly visible in this function. Let us
  576. first make sure that it is visible and if so, let
  577. us display its contents. */
  578. fi = get_selected_frame (_("No frame selected"));
  579. /* The following is generally ripped off from stack.c's routine
  580. print_frame_info(). */
  581. block = get_frame_block (fi, 0);
  582. if (block == NULL)
  583. {
  584. gdb_printf (_("No symbol table info available.\n"));
  585. return;
  586. }
  587. while (block)
  588. {
  589. info_common_command_for_block (block, comname, &values_printed);
  590. /* After handling the function's top-level block, stop. Don't
  591. continue to its superblock, the block of per-file symbols. */
  592. if (BLOCK_FUNCTION (block))
  593. break;
  594. block = BLOCK_SUPERBLOCK (block);
  595. }
  596. if (!values_printed)
  597. {
  598. if (comname)
  599. gdb_printf (_("No common block '%s'.\n"), comname);
  600. else
  601. gdb_printf (_("No common blocks.\n"));
  602. }
  603. }
  604. void _initialize_f_valprint ();
  605. void
  606. _initialize_f_valprint ()
  607. {
  608. add_info ("common", info_common_command,
  609. _("Print out the values contained in a Fortran COMMON block."));
  610. }