2018-10-09 01:42:28 -04:00
|
|
|
#include "dwarf.h"
|
|
|
|
|
#include "console.h"
|
|
|
|
|
#include "elf.h"
|
|
|
|
|
#include "kmalloc.h"
|
|
|
|
|
|
2018-09-30 14:56:07 -04:00
|
|
|
#include <stdio.h>
|
2018-10-01 00:41:19 -04:00
|
|
|
#include <errno.h>
|
2018-09-29 19:38:42 -04:00
|
|
|
|
2018-09-30 14:56:07 -04:00
|
|
|
void dwarf_find_file(uintptr_t address) {
|
2018-10-06 19:28:56 -04:00
|
|
|
// FILE *file;
|
2018-09-30 14:56:07 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-01 00:41:19 -04:00
|
|
|
void *dwarf_find_debug_info() {
|
2018-09-30 14:56:07 -04:00
|
|
|
void *debug_line_ptr = NULL;
|
2018-10-06 19:28:56 -04:00
|
|
|
// uint32_t read = 0;
|
2018-09-29 19:38:42 -04:00
|
|
|
|
2018-10-02 13:32:18 -04:00
|
|
|
elf_file_t *elf_file;
|
|
|
|
|
if ((elf_file = elf_open("kernel.bin")) == NULL) goto fail;
|
|
|
|
|
elf_print_sections(elf_file);
|
2018-09-30 14:56:07 -04:00
|
|
|
|
2018-10-02 13:32:18 -04:00
|
|
|
elf_section_header_t *debug_line_section = elf_find_section(elf_file, ".debug_line");
|
2018-10-01 20:51:57 -04:00
|
|
|
if (debug_line_section == NULL || debug_line_section->size > UINT16_MAX) goto fail;
|
2018-09-30 14:56:07 -04:00
|
|
|
|
2018-10-01 00:41:19 -04:00
|
|
|
// ret = f_lseek(&file, debug_line_section->offset);
|
|
|
|
|
// if (ret != FR_OK) goto fail;
|
|
|
|
|
//
|
|
|
|
|
// uint16_t debug_line_section_size = (uint16_t) debug_line_section->size;
|
|
|
|
|
// kprint("debug_line_section_size = "); kprint_uint16(debug_line_section_size); kprint_char('\n');
|
|
|
|
|
// debug_line_ptr = malloc(debug_line_section_size);
|
|
|
|
|
// if (debug_line_ptr == NULL) goto fail;
|
|
|
|
|
//
|
|
|
|
|
// ret = f_read(&file, debug_line_ptr, debug_line_section_size, &read);
|
|
|
|
|
// if (ret != FR_OK || read != debug_line_section_size) goto fail;
|
|
|
|
|
//
|
|
|
|
|
// dwarf_debug_line_header_t *debug_line_header = debug_line_ptr;
|
|
|
|
|
// kprint_uint32(debug_line_header->length);
|
|
|
|
|
// kprint_char('\n');
|
2018-09-29 19:38:42 -04:00
|
|
|
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
fail:
|
2018-10-01 00:41:19 -04:00
|
|
|
printf("Failed to read DWARF info: %d\n", errno);
|
2018-09-29 19:38:42 -04:00
|
|
|
|
|
|
|
|
end:
|
2018-10-02 13:32:18 -04:00
|
|
|
elf_close(elf_file);
|
2018-10-09 01:42:28 -04:00
|
|
|
kfree(debug_line_ptr);
|
2018-09-29 19:38:42 -04:00
|
|
|
return NULL;
|
|
|
|
|
}
|