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