Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep going even some of the cores don't support tracing #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
28 changes: 15 additions & 13 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <fcntl.h>
#include <ctype.h>
#include <pthread.h>
#include <assert.h>

#include <sys/mman.h>
#include <sys/ptrace.h>
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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++;
}

Expand All @@ -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);
}

Expand Down