|
|
|
@ -22,15 +22,44 @@ print_word_at_address(int child, u64 address)
@@ -22,15 +22,44 @@ print_word_at_address(int child, u64 address)
|
|
|
|
|
printf("word at %#018lx: {%x %x %x %x}\n", address, nb[0], nb[1], nb[2], nb[3]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static struct mi_buffer |
|
|
|
|
read_file_mmap(char *path) |
|
|
|
|
{ |
|
|
|
|
struct mi_buffer result = { 0 }; |
|
|
|
|
|
|
|
|
|
struct stat s; |
|
|
|
|
int fd = open(path, O_RDONLY); |
|
|
|
|
assert(fd != -1); |
|
|
|
|
fstat(fd, &s); |
|
|
|
|
|
|
|
|
|
result.data = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
|
|
|
|
result.size = s.st_size; |
|
|
|
|
|
|
|
|
|
printf("mmap()-ed %ld bytes (%s)\n", result.size, path); |
|
|
|
|
|
|
|
|
|
close(fd); |
|
|
|
|
|
|
|
|
|
return(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
print_current_line(struct mi_process proc, u64 line) |
|
|
|
|
print_sourcepoint(struct mi_process proc, struct mi_sourcepoint *sp) |
|
|
|
|
{ |
|
|
|
|
char *source = proc.source; |
|
|
|
|
u64 size = proc.source_size; |
|
|
|
|
u64 current_line = 1; |
|
|
|
|
// NOTE: sourcepoint file indices are 1-based
|
|
|
|
|
if (proc.source_files[sp->file - 1].data == 0) { |
|
|
|
|
char *path = proc.source_file_names[sp->file - 1]; |
|
|
|
|
struct mi_buffer file = read_file_mmap(path); |
|
|
|
|
proc.source_files[sp->file - 1] = file; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct mi_buffer file = proc.source_files[sp->file - 1]; |
|
|
|
|
|
|
|
|
|
char *source = (char *) file.data; |
|
|
|
|
u64 size = file.size; |
|
|
|
|
int current_line = 1; |
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < size; ++i) { |
|
|
|
|
if (current_line == line) { |
|
|
|
|
if (current_line == sp->line) { |
|
|
|
|
int len = 0; |
|
|
|
|
int start = 0; |
|
|
|
|
int leading = 1; |
|
|
|
@ -84,35 +113,10 @@ process_create(char *path)
@@ -84,35 +113,10 @@ process_create(char *path)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
u64 source_size; |
|
|
|
|
u64 elf_size; |
|
|
|
|
u8 *elf; |
|
|
|
|
char *source; |
|
|
|
|
struct stat s; |
|
|
|
|
int fd; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
fd = open(path, O_RDONLY); |
|
|
|
|
assert(fd != -1); |
|
|
|
|
fstat(fd, &s); |
|
|
|
|
elf_size = s.st_size; |
|
|
|
|
elf = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
|
|
|
|
close(fd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
fd = open("/code/trace-test/traceme.c", O_RDONLY); // TODO
|
|
|
|
|
assert(fd != -1); |
|
|
|
|
fstat(fd, &s); |
|
|
|
|
source_size = s.st_size; |
|
|
|
|
source = mmap(0, source_size, PROT_READ, MAP_PRIVATE, fd, 0); |
|
|
|
|
close(fd); |
|
|
|
|
} |
|
|
|
|
struct mi_buffer file = read_file_mmap(path); |
|
|
|
|
|
|
|
|
|
result.elf = elf; |
|
|
|
|
result.elf_size = elf_size; |
|
|
|
|
result.source = source; |
|
|
|
|
result.source_size = source_size; |
|
|
|
|
result.elf = file.data; |
|
|
|
|
result.elf_size = file.size; |
|
|
|
|
result.pid = pid; |
|
|
|
|
|
|
|
|
|
return(result); |
|
|
|
|