stringify.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* DWARF stringify code
  2. Copyright (C) 1994-2022 Free Software Foundation, Inc.
  3. Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
  4. Inc. with support from Florida State University (under contract
  5. with the Ada Joint Program Office), and Silicon Graphics, Inc.
  6. Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
  7. based on Fred Fish's (Cygnus Support) implementation of DWARF 1
  8. support.
  9. This file is part of GDB.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 3 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  20. #include "defs.h"
  21. #include "dwarf2.h"
  22. #include "dwarf2/stringify.h"
  23. /* A convenience function that returns an "unknown" DWARF name,
  24. including the value of V. STR is the name of the entity being
  25. printed, e.g., "TAG". */
  26. static const char *
  27. dwarf_unknown (const char *str, unsigned v)
  28. {
  29. char *cell = get_print_cell ();
  30. xsnprintf (cell, PRINT_CELL_SIZE, "DW_%s_<unknown: %u>", str, v);
  31. return cell;
  32. }
  33. /* See stringify.h. */
  34. const char *
  35. dwarf_tag_name (unsigned tag)
  36. {
  37. const char *name = get_DW_TAG_name (tag);
  38. if (name == NULL)
  39. return dwarf_unknown ("TAG", tag);
  40. return name;
  41. }
  42. /* See stringify.h. */
  43. const char *
  44. dwarf_attr_name (unsigned attr)
  45. {
  46. const char *name;
  47. #ifdef MIPS /* collides with DW_AT_HP_block_index */
  48. if (attr == DW_AT_MIPS_fde)
  49. return "DW_AT_MIPS_fde";
  50. #else
  51. if (attr == DW_AT_HP_block_index)
  52. return "DW_AT_HP_block_index";
  53. #endif
  54. name = get_DW_AT_name (attr);
  55. if (name == NULL)
  56. return dwarf_unknown ("AT", attr);
  57. return name;
  58. }
  59. /* See stringify.h. */
  60. const char *
  61. dwarf_form_name (unsigned form)
  62. {
  63. const char *name = get_DW_FORM_name (form);
  64. if (name == NULL)
  65. return dwarf_unknown ("FORM", form);
  66. return name;
  67. }
  68. /* See stringify.h. */
  69. const char *
  70. dwarf_bool_name (unsigned mybool)
  71. {
  72. if (mybool)
  73. return "TRUE";
  74. else
  75. return "FALSE";
  76. }
  77. /* See stringify.h. */
  78. const char *
  79. dwarf_type_encoding_name (unsigned enc)
  80. {
  81. const char *name = get_DW_ATE_name (enc);
  82. if (name == NULL)
  83. return dwarf_unknown ("ATE", enc);
  84. return name;
  85. }
  86. /* See stringify.h. */
  87. const char *
  88. dwarf_unit_type_name (int unit_type)
  89. {
  90. const char *name = get_DW_UT_name (unit_type);
  91. if (name == nullptr)
  92. return dwarf_unknown ("UT", unit_type);
  93. return name;
  94. }