Add `set print repeats' tests for C/C++ arrays
[binutils-gdb.git] / gdb / dwarf2 / file-and-dir.h
1 /* DWARF file and directory
2
3 Copyright (C) 1994-2022 Free Software Foundation, Inc.
4
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
10 support.
11
12 This file is part of GDB.
13
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.
18
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.
23
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/>. */
26
27 #ifndef GDB_DWARF2_FILE_AND_DIR_H
28 #define GDB_DWARF2_FILE_AND_DIR_H
29
30 #include "objfiles.h"
31 #include <string>
32
33 /* The return type of find_file_and_directory. Note, the enclosed
34 string pointers are only valid while this object is valid. */
35
36 struct file_and_directory
37 {
38 file_and_directory (const char *name, const char *dir)
39 : m_name (name),
40 m_comp_dir (dir)
41 {
42 }
43
44 /* Return true if the file name is unknown. */
45 bool is_unknown () const
46 {
47 return m_name == nullptr;
48 }
49
50 /* Set the compilation directory. */
51 void set_comp_dir (std::string &&dir)
52 {
53 m_comp_dir_storage = std::move (dir);
54 m_comp_dir = nullptr;
55 }
56
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
62 {
63 if (!m_comp_dir_storage.empty ())
64 return m_comp_dir_storage.c_str ();
65 return m_comp_dir;
66 }
67
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)
71 {
72 if (!m_comp_dir_storage.empty ())
73 {
74 m_comp_dir = objfile->intern (m_comp_dir_storage);
75 m_comp_dir_storage.clear ();
76 }
77 return m_comp_dir;
78 }
79
80 /* Fetch the filename. This never returns NULL. */
81 const char *get_name () const
82 {
83 return m_name == nullptr ? "<unknown>" : m_name;
84 }
85
86 /* Set the filename. */
87 void set_name (gdb::unique_xmalloc_ptr<char> name)
88 {
89 m_name_storage = std::move (name);
90 m_name = m_name_storage.get ();
91 }
92
93 private:
94
95 /* The filename. */
96 const char *m_name;
97
98 /* Storage for the filename, if needed. */
99 gdb::unique_xmalloc_ptr<char> m_name_storage;
100
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;
106
107 /* The compilation directory, if it needed to be allocated. */
108 std::string m_comp_dir_storage;
109 };
110
111 #endif /* GDB_DWARF2_FILE_AND_DIR_H */