Skip to content

Commit 344ce95

Browse files
committed
esp/apptrace: added table size entry to the stub entry table
1 parent f053db4 commit 344ce95

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/target/esp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*/
3939
enum esp_dbg_stub_id {
4040
ESP_DBG_STUB_ENTRY_MAGIC_NUM,
41+
ESP_DBG_STUB_TABLE_SIZE,
4142
ESP_DBG_STUB_TABLE_START,
4243
ESP_DBG_STUB_DESC = ESP_DBG_STUB_TABLE_START, /*< Stubs descriptor ID */
4344
ESP_DBG_STUB_ENTRY_FIRST,

src/target/esp_xtensa.c

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ static void esp_xtensa_dbgstubs_addr_check(struct target *target)
246246
static void esp_xtensa_dbgstubs_info_update(struct target *target)
247247
{
248248
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;
251250
uint32_t entries[ESP_DBG_STUB_ENTRY_MAX];
252251

253252
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)
256255
if (esp_xtensa->dbg_stubs.base == 0 || esp_xtensa->dbg_stubs.entries_count != 0)
257256
return;
258257

258+
/* first read 2 entries to get magic num and table size */
259259
int res = target_read_memory(target, esp_xtensa->dbg_stubs.base, sizeof(uint32_t),
260-
1,
260+
2,
261261
(uint8_t *)&entries[0]);
262262
if (res != ERROR_OK) {
263263
LOG_ERROR("%s: Failed to read first debug stub entry!", target_name(target));
264264
return;
265265
}
266266
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;
268269
table_start_id = desc_entry_id = 0;
269270
gcov_entry_id = 1;
270-
cap_entry_id = -1; /* none */
271-
max_entry_id = 2;
272271
} else {
272+
table_size = entries[1];
273273
table_start_id = desc_entry_id = ESP_DBG_STUB_TABLE_START;
274274
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];
284296
}
285297

286-
if (cap_entry_id > 0)
287-
esp_xtensa->dbg_stubs.entries[ESP_DBG_STUB_CAPABILITIES] = entries[cap_entry_id];
288298
esp_xtensa->dbg_stubs.entries[ESP_DBG_STUB_DESC] = entries[desc_entry_id];
289299
esp_xtensa->dbg_stubs.entries[ESP_DBG_STUB_ENTRY_GCOV] = entries[gcov_entry_id];
290300

@@ -302,9 +312,9 @@ static void esp_xtensa_dbgstubs_info_update(struct target *target)
302312
}
303313
}
304314
if (esp_xtensa->dbg_stubs.entries_count <
305-
(uint32_t)(max_entry_id-table_start_id)) {
315+
(uint32_t)(table_size - table_start_id)) {
306316
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));
308318
}
309319
if (esp_xtensa->dbg_stubs.entries_count == 0)
310320
return;

0 commit comments

Comments
 (0)