@@ -246,8 +246,7 @@ static void esp_xtensa_dbgstubs_addr_check(struct target *target)
246
246
static void esp_xtensa_dbgstubs_info_update (struct target * target )
247
247
{
248
248
struct esp_xtensa_common * esp_xtensa = target_to_esp_xtensa (target );
249
- int table_start_id , desc_entry_id , gcov_entry_id ;
250
- int cap_entry_id , max_entry_id ;
249
+ int table_size , table_start_id , desc_entry_id , gcov_entry_id ;
251
250
uint32_t entries [ESP_DBG_STUB_ENTRY_MAX ];
252
251
253
252
LOG_DEBUG ("%s: Read debug stubs info %d / %d" , target_name (target ),
@@ -256,35 +255,46 @@ static void esp_xtensa_dbgstubs_info_update(struct target *target)
256
255
if (esp_xtensa -> dbg_stubs .base == 0 || esp_xtensa -> dbg_stubs .entries_count != 0 )
257
256
return ;
258
257
258
+ /* first read 2 entries to get magic num and table size */
259
259
int res = target_read_memory (target , esp_xtensa -> dbg_stubs .base , sizeof (uint32_t ),
260
- 1 ,
260
+ 2 ,
261
261
(uint8_t * )& entries [0 ]);
262
262
if (res != ERROR_OK ) {
263
263
LOG_ERROR ("%s: Failed to read first debug stub entry!" , target_name (target ));
264
264
return ;
265
265
}
266
266
if (entries [0 ] != ESP_DBG_STUB_MAGIC_NUM_VAL ) {
267
- /* old idf. check @esp_dbg_stub_id_v1 for ids*/
267
+ /* idf with the old table entry structure */
268
+ table_size = 2 ;
268
269
table_start_id = desc_entry_id = 0 ;
269
270
gcov_entry_id = 1 ;
270
- cap_entry_id = -1 ; /* none */
271
- max_entry_id = 2 ;
272
271
} else {
272
+ table_size = entries [1 ];
273
273
table_start_id = desc_entry_id = ESP_DBG_STUB_TABLE_START ;
274
274
gcov_entry_id = ESP_DBG_STUB_ENTRY_FIRST ;
275
- cap_entry_id = ESP_DBG_STUB_CAPABILITIES ;
276
- max_entry_id = ESP_DBG_STUB_ENTRY_MAX ;
277
- }
278
- res = target_read_memory (target , esp_xtensa -> dbg_stubs .base , sizeof (uint32_t ),
279
- max_entry_id ,
280
- (uint8_t * )& entries [0 ]);
281
- if (res != ERROR_OK ) {
282
- LOG_ERROR ("%s: Failed to read debug stubs info!" , target_name (target ));
283
- return ;
275
+
276
+ if (table_size < 2 ) {
277
+ LOG_ERROR ("Invalid stub table entry size (%x)" , table_size );
278
+ return ;
279
+ }
280
+ /* discard unsupported entries */
281
+ if (table_size > ESP_DBG_STUB_ENTRY_MAX )
282
+ table_size = ESP_DBG_STUB_ENTRY_MAX ;
283
+
284
+ /* now read the remaining entries */
285
+ res = target_read_memory (target ,
286
+ esp_xtensa -> dbg_stubs .base + 2 * sizeof (uint32_t ),
287
+ sizeof (uint32_t ),
288
+ table_size - 2 ,
289
+ (uint8_t * )& entries [2 ]);
290
+ if (res != ERROR_OK ) {
291
+ LOG_ERROR ("%s: Failed to read debug stubs info!" , target_name (target ));
292
+ return ;
293
+ }
294
+ esp_xtensa -> dbg_stubs .entries [ESP_DBG_STUB_CAPABILITIES ] =
295
+ entries [ESP_DBG_STUB_CAPABILITIES ];
284
296
}
285
297
286
- if (cap_entry_id > 0 )
287
- esp_xtensa -> dbg_stubs .entries [ESP_DBG_STUB_CAPABILITIES ] = entries [cap_entry_id ];
288
298
esp_xtensa -> dbg_stubs .entries [ESP_DBG_STUB_DESC ] = entries [desc_entry_id ];
289
299
esp_xtensa -> dbg_stubs .entries [ESP_DBG_STUB_ENTRY_GCOV ] = entries [gcov_entry_id ];
290
300
@@ -302,9 +312,9 @@ static void esp_xtensa_dbgstubs_info_update(struct target *target)
302
312
}
303
313
}
304
314
if (esp_xtensa -> dbg_stubs .entries_count <
305
- (uint32_t )(max_entry_id - table_start_id )) {
315
+ (uint32_t )(table_size - table_start_id )) {
306
316
LOG_WARNING ("Not full dbg stub table %d of %d" , esp_xtensa -> dbg_stubs .entries_count ,
307
- (max_entry_id - table_start_id ));
317
+ (table_size - table_start_id ));
308
318
}
309
319
if (esp_xtensa -> dbg_stubs .entries_count == 0 )
310
320
return ;
0 commit comments