@@ -88,18 +88,11 @@ index_cache::disable ()
88
88
89
89
/* See index-cache.h. */
90
90
91
- index_cache_store_context ::index_cache_store_context (const index_cache & ic )
91
+ index_cache_store_context ::index_cache_store_context (const index_cache & ic ,
92
+ dwarf2_per_bfd * per_bfd )
92
93
: m_enabled (ic .enabled ())
93
94
{
94
- }
95
-
96
- /* See dwarf-index-cache.h. */
97
-
98
- void
99
- index_cache ::store (dwarf2_per_bfd * per_bfd ,
100
- const index_cache_store_context & ctx )
101
- {
102
- if (!ctx .m_enabled )
95
+ if (!m_enabled )
103
96
return ;
104
97
105
98
/* Get build id of objfile. */
@@ -108,15 +101,13 @@ index_cache::store (dwarf2_per_bfd *per_bfd,
108
101
{
109
102
index_cache_debug ("objfile %s has no build id" ,
110
103
bfd_get_filename (per_bfd -> obfd ));
104
+ m_enabled = false;
111
105
return ;
112
106
}
113
-
114
- std ::string build_id_str = build_id_to_string (build_id );
107
+ build_id_str = build_id_to_string (build_id );
115
108
116
109
/* Get build id of dwz file, if present. */
117
- gdb ::optional < std ::string > dwz_build_id_str ;
118
110
const dwz_file * dwz = dwarf2_get_dwz_file (per_bfd );
119
- const char * dwz_build_id_ptr = NULL ;
120
111
121
112
if (dwz != nullptr )
122
113
{
@@ -126,36 +117,61 @@ index_cache::store (dwarf2_per_bfd *per_bfd,
126
117
{
127
118
index_cache_debug ("dwz objfile %s has no build id" ,
128
119
dwz -> filename ());
120
+ m_enabled = false;
129
121
return ;
130
122
}
131
123
132
124
dwz_build_id_str = build_id_to_string (dwz_build_id );
133
- dwz_build_id_ptr = dwz_build_id_str -> c_str ();
134
125
}
135
126
136
- if (m_dir .empty ())
127
+ if (ic . m_dir .empty ())
137
128
{
138
129
warning (_ ("The index cache directory name is empty, skipping store." ));
130
+ m_enabled = false;
139
131
return ;
140
132
}
141
133
142
134
try
143
135
{
144
136
/* Try to create the containing directory. */
145
- if (!mkdir_recursive (m_dir .c_str ()))
137
+ if (!mkdir_recursive (ic . m_dir .c_str ()))
146
138
{
147
139
warning (_ ("index cache: could not make cache directory: %s" ),
148
140
safe_strerror (errno ));
141
+ m_enabled = false;
149
142
return ;
150
143
}
144
+ }
145
+ catch (const gdb_exception_error & except )
146
+ {
147
+ index_cache_debug ("couldn't store index cache for objfile %s: %s" ,
148
+ bfd_get_filename (per_bfd -> obfd ), except .what ());
149
+ m_enabled = false;
150
+ }
151
+ }
152
+
153
+ /* See dwarf-index-cache.h. */
151
154
155
+ void
156
+ index_cache ::store (dwarf2_per_bfd * per_bfd ,
157
+ const index_cache_store_context & ctx )
158
+ {
159
+ if (!ctx .m_enabled )
160
+ return ;
161
+
162
+ const char * dwz_build_id_ptr = (ctx .dwz_build_id_str .has_value ()
163
+ ? ctx .dwz_build_id_str -> c_str ()
164
+ : nullptr );
165
+
166
+ try
167
+ {
152
168
index_cache_debug ("writing index cache for objfile %s" ,
153
169
bfd_get_filename (per_bfd -> obfd ));
154
170
155
171
/* Write the index itself to the directory, using the build id as the
156
172
filename. */
157
173
write_dwarf_index (per_bfd , m_dir .c_str (),
158
- build_id_str .c_str (), dwz_build_id_ptr ,
174
+ ctx . build_id_str .c_str (), dwz_build_id_ptr ,
159
175
dw_index_kind ::GDB_INDEX );
160
176
}
161
177
catch (const gdb_exception_error & except )
0 commit comments