17d62b00eSchristos /* DWARF stringify code 27d62b00eSchristos 3*6881a400Schristos Copyright (C) 1994-2023 Free Software Foundation, Inc. 47d62b00eSchristos 57d62b00eSchristos Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, 67d62b00eSchristos Inc. with support from Florida State University (under contract 77d62b00eSchristos with the Ada Joint Program Office), and Silicon Graphics, Inc. 87d62b00eSchristos Initial contribution by Brent Benson, Harris Computer Systems, Inc., 97d62b00eSchristos based on Fred Fish's (Cygnus Support) implementation of DWARF 1 107d62b00eSchristos support. 117d62b00eSchristos 127d62b00eSchristos This file is part of GDB. 137d62b00eSchristos 147d62b00eSchristos This program is free software; you can redistribute it and/or modify 157d62b00eSchristos it under the terms of the GNU General Public License as published by 167d62b00eSchristos the Free Software Foundation; either version 3 of the License, or 177d62b00eSchristos (at your option) any later version. 187d62b00eSchristos 197d62b00eSchristos This program is distributed in the hope that it will be useful, 207d62b00eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 217d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 227d62b00eSchristos GNU General Public License for more details. 237d62b00eSchristos 247d62b00eSchristos You should have received a copy of the GNU General Public License 257d62b00eSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 267d62b00eSchristos 277d62b00eSchristos #include "defs.h" 287d62b00eSchristos #include "dwarf2.h" 297d62b00eSchristos #include "dwarf2/stringify.h" 307d62b00eSchristos 317d62b00eSchristos /* A convenience function that returns an "unknown" DWARF name, 327d62b00eSchristos including the value of V. STR is the name of the entity being 337d62b00eSchristos printed, e.g., "TAG". */ 347d62b00eSchristos 357d62b00eSchristos static const char * 367d62b00eSchristos dwarf_unknown (const char *str, unsigned v) 377d62b00eSchristos { 387d62b00eSchristos char *cell = get_print_cell (); 397d62b00eSchristos xsnprintf (cell, PRINT_CELL_SIZE, "DW_%s_<unknown: %u>", str, v); 407d62b00eSchristos return cell; 417d62b00eSchristos } 427d62b00eSchristos 437d62b00eSchristos /* See stringify.h. */ 447d62b00eSchristos 457d62b00eSchristos const char * 467d62b00eSchristos dwarf_tag_name (unsigned tag) 477d62b00eSchristos { 487d62b00eSchristos const char *name = get_DW_TAG_name (tag); 497d62b00eSchristos 507d62b00eSchristos if (name == NULL) 517d62b00eSchristos return dwarf_unknown ("TAG", tag); 527d62b00eSchristos 537d62b00eSchristos return name; 547d62b00eSchristos } 557d62b00eSchristos 567d62b00eSchristos /* See stringify.h. */ 577d62b00eSchristos 587d62b00eSchristos const char * 597d62b00eSchristos dwarf_attr_name (unsigned attr) 607d62b00eSchristos { 617d62b00eSchristos const char *name; 627d62b00eSchristos 637d62b00eSchristos #ifdef MIPS /* collides with DW_AT_HP_block_index */ 647d62b00eSchristos if (attr == DW_AT_MIPS_fde) 657d62b00eSchristos return "DW_AT_MIPS_fde"; 667d62b00eSchristos #else 677d62b00eSchristos if (attr == DW_AT_HP_block_index) 687d62b00eSchristos return "DW_AT_HP_block_index"; 697d62b00eSchristos #endif 707d62b00eSchristos 717d62b00eSchristos name = get_DW_AT_name (attr); 727d62b00eSchristos 737d62b00eSchristos if (name == NULL) 747d62b00eSchristos return dwarf_unknown ("AT", attr); 757d62b00eSchristos 767d62b00eSchristos return name; 777d62b00eSchristos } 787d62b00eSchristos 797d62b00eSchristos /* See stringify.h. */ 807d62b00eSchristos 817d62b00eSchristos const char * 827d62b00eSchristos dwarf_form_name (unsigned form) 837d62b00eSchristos { 847d62b00eSchristos const char *name = get_DW_FORM_name (form); 857d62b00eSchristos 867d62b00eSchristos if (name == NULL) 877d62b00eSchristos return dwarf_unknown ("FORM", form); 887d62b00eSchristos 897d62b00eSchristos return name; 907d62b00eSchristos } 917d62b00eSchristos 927d62b00eSchristos /* See stringify.h. */ 937d62b00eSchristos 947d62b00eSchristos const char * 957d62b00eSchristos dwarf_bool_name (unsigned mybool) 967d62b00eSchristos { 977d62b00eSchristos if (mybool) 987d62b00eSchristos return "TRUE"; 997d62b00eSchristos else 1007d62b00eSchristos return "FALSE"; 1017d62b00eSchristos } 1027d62b00eSchristos 1037d62b00eSchristos /* See stringify.h. */ 1047d62b00eSchristos 1057d62b00eSchristos const char * 1067d62b00eSchristos dwarf_type_encoding_name (unsigned enc) 1077d62b00eSchristos { 1087d62b00eSchristos const char *name = get_DW_ATE_name (enc); 1097d62b00eSchristos 1107d62b00eSchristos if (name == NULL) 1117d62b00eSchristos return dwarf_unknown ("ATE", enc); 1127d62b00eSchristos 1137d62b00eSchristos return name; 1147d62b00eSchristos } 115*6881a400Schristos 116*6881a400Schristos /* See stringify.h. */ 117*6881a400Schristos 118*6881a400Schristos const char * 119*6881a400Schristos dwarf_unit_type_name (int unit_type) 120*6881a400Schristos { 121*6881a400Schristos const char *name = get_DW_UT_name (unit_type); 122*6881a400Schristos 123*6881a400Schristos if (name == nullptr) 124*6881a400Schristos return dwarf_unknown ("UT", unit_type); 125*6881a400Schristos 126*6881a400Schristos return name; 127*6881a400Schristos } 128