1 1.1 christos /* DWARF file and directory 2 1.1 christos 3 1.1.1.2 christos Copyright (C) 1994-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos Adapted by Gary Funck (gary (at) intrepid.com), Intrepid Technology, 6 1.1 christos Inc. with support from Florida State University (under contract 7 1.1 christos with the Ada Joint Program Office), and Silicon Graphics, Inc. 8 1.1 christos Initial contribution by Brent Benson, Harris Computer Systems, Inc., 9 1.1 christos based on Fred Fish's (Cygnus Support) implementation of DWARF 1 10 1.1 christos support. 11 1.1 christos 12 1.1 christos This file is part of GDB. 13 1.1 christos 14 1.1 christos This program is free software; you can redistribute it and/or modify 15 1.1 christos it under the terms of the GNU General Public License as published by 16 1.1 christos the Free Software Foundation; either version 3 of the License, or 17 1.1 christos (at your option) any later version. 18 1.1 christos 19 1.1 christos This program is distributed in the hope that it will be useful, 20 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 21 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 1.1 christos GNU General Public License for more details. 23 1.1 christos 24 1.1 christos You should have received a copy of the GNU General Public License 25 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 26 1.1 christos 27 1.1 christos #ifndef GDB_DWARF2_FILE_AND_DIR_H 28 1.1 christos #define GDB_DWARF2_FILE_AND_DIR_H 29 1.1 christos 30 1.1 christos #include "objfiles.h" 31 1.1 christos #include "source.h" 32 1.1 christos #include <string> 33 1.1 christos 34 1.1 christos /* The return type of find_file_and_directory. Note, the enclosed 35 1.1 christos string pointers are only valid while this object is valid. */ 36 1.1 christos 37 1.1 christos struct file_and_directory 38 1.1 christos { 39 1.1 christos file_and_directory (const char *name, const char *dir) 40 1.1 christos : m_name (name), 41 1.1 christos m_comp_dir (dir) 42 1.1 christos { 43 1.1 christos } 44 1.1 christos 45 1.1 christos /* Return true if the file name is unknown. */ 46 1.1 christos bool is_unknown () const 47 1.1 christos { 48 1.1 christos return m_name == nullptr; 49 1.1 christos } 50 1.1 christos 51 1.1 christos /* Set the compilation directory. */ 52 1.1 christos void set_comp_dir (std::string &&dir) 53 1.1 christos { 54 1.1 christos m_comp_dir_storage = std::move (dir); 55 1.1 christos m_comp_dir = nullptr; 56 1.1 christos } 57 1.1 christos 58 1.1 christos /* Fetch the compilation directory. This may return NULL in some 59 1.1 christos circumstances. Note that the return value here is not stable -- 60 1.1 christos it may change if this object is moved. To get a stable pointer, 61 1.1 christos you should call intern_comp_dir. */ 62 1.1 christos const char *get_comp_dir () const 63 1.1 christos { 64 1.1 christos if (!m_comp_dir_storage.empty ()) 65 1.1 christos return m_comp_dir_storage.c_str (); 66 1.1 christos return m_comp_dir; 67 1.1 christos } 68 1.1 christos 69 1.1 christos /* If necessary, intern the compilation directory using OBJFILE's 70 1.1 christos string cache. Returns the compilation directory. */ 71 1.1 christos const char *intern_comp_dir (struct objfile *objfile) 72 1.1 christos { 73 1.1 christos if (!m_comp_dir_storage.empty ()) 74 1.1 christos { 75 1.1 christos m_comp_dir = objfile->intern (m_comp_dir_storage); 76 1.1 christos m_comp_dir_storage.clear (); 77 1.1 christos } 78 1.1 christos return m_comp_dir; 79 1.1 christos } 80 1.1 christos 81 1.1 christos /* Fetch the filename. This never returns NULL. */ 82 1.1 christos const char *get_name () const 83 1.1 christos { 84 1.1 christos return m_name == nullptr ? "<unknown>" : m_name; 85 1.1 christos } 86 1.1 christos 87 1.1 christos /* Set the filename. */ 88 1.1 christos void set_name (gdb::unique_xmalloc_ptr<char> name) 89 1.1 christos { 90 1.1 christos m_name_storage = std::move (name); 91 1.1 christos m_name = m_name_storage.get (); 92 1.1 christos } 93 1.1 christos 94 1.1 christos /* Return the full name, computing it if necessary. */ 95 1.1 christos const char *get_fullname () 96 1.1 christos { 97 1.1 christos if (m_fullname == nullptr) 98 1.1 christos m_fullname = find_source_or_rewrite (get_name (), get_comp_dir ()); 99 1.1 christos return m_fullname.get (); 100 1.1 christos } 101 1.1 christos 102 1.1 christos /* Forget the full name. */ 103 1.1 christos void forget_fullname () 104 1.1 christos { 105 1.1 christos m_fullname.reset (); 106 1.1 christos } 107 1.1 christos 108 1.1 christos private: 109 1.1 christos 110 1.1 christos /* The filename. */ 111 1.1 christos const char *m_name; 112 1.1 christos 113 1.1 christos /* Storage for the filename, if needed. */ 114 1.1 christos gdb::unique_xmalloc_ptr<char> m_name_storage; 115 1.1 christos 116 1.1 christos /* The compilation directory. NULL if not known. If we needed to 117 1.1 christos compute a new string, it will be stored in the comp_dir_storage 118 1.1 christos member, and this will be NULL. Otherwise, points directly to the 119 1.1 christos DW_AT_comp_dir string attribute. */ 120 1.1 christos const char *m_comp_dir; 121 1.1 christos 122 1.1 christos /* The compilation directory, if it needed to be allocated. */ 123 1.1 christos std::string m_comp_dir_storage; 124 1.1 christos 125 1.1 christos /* The full name. */ 126 1.1 christos gdb::unique_xmalloc_ptr<char> m_fullname; 127 1.1 christos }; 128 1.1 christos 129 1.1 christos #endif /* GDB_DWARF2_FILE_AND_DIR_H */ 130