@@ -88,18 +88,11 @@ index_cache::disable ()
8888
8989 /* See index-cache.h. */
9090
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 )
9293 : m_enabled (ic .enabled ())
9394{
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 )
10396 return ;
10497
10598 /* Get build id of objfile. */
@@ -108,15 +101,13 @@ index_cache::store (dwarf2_per_bfd *per_bfd,
108101 {
109102 index_cache_debug ("objfile %s has no build id" ,
110103 bfd_get_filename (per_bfd -> obfd ));
104+ m_enabled = false;
111105 return ;
112106 }
113-
114- std ::string build_id_str = build_id_to_string (build_id );
107+ build_id_str = build_id_to_string (build_id );
115108
116109 /* Get build id of dwz file, if present. */
117- gdb ::optional < std ::string > dwz_build_id_str ;
118110 const dwz_file * dwz = dwarf2_get_dwz_file (per_bfd );
119- const char * dwz_build_id_ptr = NULL ;
120111
121112 if (dwz != nullptr )
122113 {
@@ -126,36 +117,61 @@ index_cache::store (dwarf2_per_bfd *per_bfd,
126117 {
127118 index_cache_debug ("dwz objfile %s has no build id" ,
128119 dwz -> filename ());
120+ m_enabled = false;
129121 return ;
130122 }
131123
132124 dwz_build_id_str = build_id_to_string (dwz_build_id );
133- dwz_build_id_ptr = dwz_build_id_str -> c_str ();
134125 }
135126
136- if (m_dir .empty ())
127+ if (ic . m_dir .empty ())
137128 {
138129 warning (_ ("The index cache directory name is empty, skipping store." ));
130+ m_enabled = false;
139131 return ;
140132 }
141133
142134 try
143135 {
144136 /* Try to create the containing directory. */
145- if (!mkdir_recursive (m_dir .c_str ()))
137+ if (!mkdir_recursive (ic . m_dir .c_str ()))
146138 {
147139 warning (_ ("index cache: could not make cache directory: %s" ),
148140 safe_strerror (errno ));
141+ m_enabled = false;
149142 return ;
150143 }
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. */
151154
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+ {
152168 index_cache_debug ("writing index cache for objfile %s" ,
153169 bfd_get_filename (per_bfd -> obfd ));
154170
155171 /* Write the index itself to the directory, using the build id as the
156172 filename. */
157173 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 ,
159175 dw_index_kind ::GDB_INDEX );
160176 }
161177 catch (const gdb_exception_error & except )
0 commit comments