From 53cc74af95b74bd4fb71611cc57d4d0dbf252a74 Mon Sep 17 00:00:00 2001 From: hu Date: Sun, 6 Feb 2022 11:19:31 -0800 Subject: [PATCH 1/2] keep going even some of the cores don't support tracing --- src/common.c | 4 ++-- src/config.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common.c b/src/common.c index 5113655..33e1093 100644 --- a/src/common.c +++ b/src/common.c @@ -489,12 +489,12 @@ static int enable_cs_trace(pid_t pid) /* Do not specify traced PID in forkserver mode */ if (configure_trace(board, &devices, map_info, range_count, pid) < 0) { fprintf(stderr, "configure_trace() failed\n"); - goto exit; + //goto exit; } /* Enable ETMs and trace sinks for the first time */ if (enable_trace(board, &devices) < 0) { fprintf(stderr, "enable_trace() failed\n"); - goto exit; + //goto exit; } is_first_trace = false; } else { diff --git a/src/config.c b/src/config.c index 17355f3..46495ae 100644 --- a/src/config.c +++ b/src/config.c @@ -202,9 +202,11 @@ int configure_trace(const struct board *board, struct cs_devices_t *devices, return -1; } if (cs_set_trace_source_id(devices->ptm[i], 0x10 + i) < 0) { - return -1; + fprintf(stderr, "Failed to set trace source id for CPU #%d\n", i); + continue; } if (init_etm(devices->ptm[i]) < 0) { + fprintf(stderr, "Failed to init etm for CPU #%d\n", i); return -1; } } From 58d839f0f632e7885b848cbd61a4760a2a5211d0 Mon Sep 17 00:00:00 2001 From: hu Date: Sun, 6 Feb 2022 22:34:38 -0800 Subject: [PATCH 2/2] dynamic alloc map_info --- include/utils.h | 2 +- src/common.c | 5 +++-- src/utils.c | 28 +++++++++++++++------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/utils.h b/include/utils.h index b15bf75..14e556b 100644 --- a/include/utils.h +++ b/include/utils.h @@ -39,7 +39,7 @@ struct mmap_params { void dump_buf(void *buf, size_t buf_size, const char *buf_path); void dump_maps(FILE *stream, pid_t pid); void dump_map_info(FILE *stream, struct map_info *map_info, int count); -int setup_map_info(pid_t pid, struct map_info *map_info, int info_count_max); +int setup_map_info(pid_t pid, struct map_info **map_info, int info_count_max); int export_decoder_args(int trace_id, const char *trace_path, const char *args_path, struct map_info *map_info, int count); diff --git a/src/common.c b/src/common.c index 33e1093..5fbbac7 100644 --- a/src/common.c +++ b/src/common.c @@ -78,7 +78,7 @@ bool export_config = false; unsigned long etr_ram_addr = 0; size_t etr_ram_size = 0; int range_count = 0; -struct map_info map_info[RANGE_MAX]; +struct map_info *map_info; struct libcsdec_memory_map *mem_map = NULL; struct libcsdec_memory_image *mem_img = NULL; cov_type_t cov_type = edge_cov; @@ -719,7 +719,8 @@ int init_trace(pid_t parent_pid, pid_t pid) goto exit; } - if ((range_count = setup_map_info(pid, map_info, RANGE_MAX)) < 0) { + map_info = (struct map_info*)malloc(sizeof(struct map_info)*RANGE_MAX); + if ((range_count = setup_map_info(pid, &map_info, RANGE_MAX)) < 0) { fprintf(stderr, "setup_map_info() failed\n"); goto exit; } diff --git a/src/utils.c b/src/utils.c index adff498..b8fd250 100644 --- a/src/utils.c +++ b/src/utils.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,7 @@ void dump_maps(FILE *stream, pid_t pid) return; } -int setup_map_info(pid_t pid, struct map_info *map_info, int info_count_max) +int setup_map_info(pid_t pid, struct map_info **map_info, int info_count_max) { FILE *fp; char maps_path[PATH_MAX]; @@ -136,20 +137,21 @@ int setup_map_info(pid_t pid, struct map_info *map_info, int info_count_max) /* Not an executable region */ continue; } - if (count >= info_count_max) { - fprintf(stderr, "INFO: [0x%lx-0x%lx] will not be traced\n", start, end); - continue; + while (count >= info_count_max) { + info_count_max *= 2; + assert (info_count_max > 0); + *map_info = realloc(*map_info, sizeof(struct map_info)*info_count_max); } /* Search absolute path */ path = strchr(line, '/'); if (!path) { continue; } - map_info[count].start = start; - map_info[count].end = end; - map_info[count].offset = offset; - map_info[count].buf = NULL; - strncpy(map_info[count].path, path, PATH_MAX - 1); + (*map_info)[count].start = start; + (*map_info)[count].end = end; + (*map_info)[count].offset = offset; + (*map_info)[count].buf = NULL; + strncpy((*map_info)[count].path, path, PATH_MAX - 1); count++; } @@ -159,18 +161,18 @@ int setup_map_info(pid_t pid, struct map_info *map_info, int info_count_max) fclose(fp); for (i = 0; i < count; i++) { - if ((fd = open(map_info[i].path, O_RDONLY | O_SYNC)) < -1) { + if ((fd = open((*map_info)[i].path, O_RDONLY | O_SYNC)) < -1) { perror("open"); return -1; } - buf_size = (size_t)ALIGN_UP(map_info[i].end - map_info[i].start, PAGE_SIZE); - buf = mmap(NULL, buf_size, PROT_READ, MAP_PRIVATE, fd, map_info[i].offset); + buf_size = (size_t)ALIGN_UP((*map_info)[i].end - (*map_info)[i].start, PAGE_SIZE); + buf = mmap(NULL, buf_size, PROT_READ, MAP_PRIVATE, fd, (*map_info)[i].offset); if (!buf) { perror("mmap"); close(fd); return -1; } - map_info[i].buf = buf; + (*map_info)[i].buf = buf; close(fd); }