1 /* DWARF file and directory
3 Copyright (C) 1994-2022 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
33 /* The return type of find_file_and_directory. Note, the enclosed
34 string pointers are only valid while this object is valid. */
36 struct file_and_directory
38 file_and_directory (const char *name
, const char *dir
)
44 /* Return true if the file name is unknown. */
45 bool is_unknown () const
47 return m_name
== nullptr;
50 /* Set the compilation directory. */
51 void set_comp_dir (std::string
&&dir
)
53 m_comp_dir_storage
= std::move (dir
);
57 /* Fetch the compilation directory. This may return NULL in some
58 circumstances. Note that the return value here is not stable --
59 it may change if this object is moved. To get a stable pointer,
60 you should call intern_comp_dir. */
61 const char *get_comp_dir () const
63 if (!m_comp_dir_storage
.empty ())
64 return m_comp_dir_storage
.c_str ();
68 /* If necessary, intern the compilation directory using OBJFILE's
69 string cache. Returns the compilation directory. */
70 const char *intern_comp_dir (struct objfile
*objfile
)
72 if (!m_comp_dir_storage
.empty ())
74 m_comp_dir
= objfile
->intern (m_comp_dir_storage
);
75 m_comp_dir_storage
.clear ();
80 /* Fetch the filename. This never returns NULL. */
81 const char *get_name () const
83 return m_name
== nullptr ? "<unknown>" : m_name
;
86 /* Set the filename. */
87 void set_name (gdb::unique_xmalloc_ptr
<char> name
)
89 m_name_storage
= std::move (name
);
90 m_name
= m_name_storage
.get ();
98 /* Storage for the filename, if needed. */
99 gdb::unique_xmalloc_ptr
<char> m_name_storage
;
101 /* The compilation directory. NULL if not known. If we needed to
102 compute a new string, it will be stored in the comp_dir_storage
103 member, and this will be NULL. Otherwise, points directly to the
104 DW_AT_comp_dir string attribute. */
105 const char *m_comp_dir
;
107 /* The compilation directory, if it needed to be allocated. */
108 std::string m_comp_dir_storage
;
111 #endif /* GDB_DWARF2_FILE_AND_DIR_H */