| 546 | return true; |
| 547 | } |
| 548 | void read_mdebug(N64Recomp::Context& context, ELFIO::section* mdebug_section, std::unordered_map<uint16_t, std::vector<N64Recomp::DataSymbol>>& data_syms) { |
| 549 | if (mdebug_section == nullptr) { |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | ELFIO::Elf64_Off base_offset = mdebug_section->get_offset(); |
| 554 | const char *mdata = mdebug_section->get_data(); |
| 555 | |
| 556 | // Read, byteswap and relocate the symbolic header. Relocation here means convert file-relative offsets to section-relative offsets. |
| 557 | |
| 558 | MDebug::HDRR hdrr; |
| 559 | std::memcpy(&hdrr, mdata, sizeof(MDebug::HDRR)); |
| 560 | hdrr.swap(); |
| 561 | hdrr.relocate(base_offset); |
| 562 | |
| 563 | // Check the magic value and version number are what we expect. |
| 564 | |
| 565 | if (hdrr.magic != MDebug::MAGIC || hdrr.vstamp != 0) { |
| 566 | fmt::print(stderr, "Warning: Found an mdebug section with bad magic value or version (magic={} version={}). Skipping.\n", hdrr.magic, hdrr.vstamp); |
| 567 | return; |
| 568 | } |
| 569 | |
| 570 | // Read the various records that are relevant for collecting static symbols and where they are declared. |
| 571 | |
| 572 | std::vector<MDebug::FDR> fdrs = hdrr.read_fdrs(mdata); |
| 573 | std::vector<MDebug::AUX> all_auxs = hdrr.read_auxs(mdata); |
| 574 | std::vector<MDebug::PDR> all_pdrs = hdrr.read_pdrs(mdata); |
| 575 | std::vector<MDebug::SYMR> all_symrs = hdrr.read_symrs(mdata); |
| 576 | |
| 577 | // For each file descriptor |
| 578 | for (MDebug::FDR& fdr : fdrs) { |
| 579 | const char* fdr_name = fdr.get_name(mdata + hdrr.cbSsOffset); |
| 580 | |
| 581 | printf("%s @ 0x%08X:\n", fdr_name, fdr.adr); |
| 582 | printf(" Procedures:\n"); |
| 583 | |
| 584 | bool at_function = false; |
| 585 | |
| 586 | |
| 587 | // For every symbol record in the file descriptor record. |
| 588 | for (auto symr : fdr.get_symrs(all_symrs)) { |
| 589 | MDebug::ST type = symr.get_st(); |
| 590 | if (type == MDebug::ST_PROC || type == MDebug::ST_STATICPROC) { |
| 591 | at_function = true; |
| 592 | const char* name = fdr.get_string(mdata + hdrr.cbSsOffset, symr.iss); |
| 593 | printf(" %s @ 0x%08X\n", name, symr.value); |
| 594 | auto find_it = context.functions_by_name.find(name); |
| 595 | if (find_it != context.functions_by_name.end()) { |
| 596 | printf(" in map: 0x%08lX\n", context.functions[find_it->second].vram); |
| 597 | } |
| 598 | } |
| 599 | else if (type == MDebug::ST_END) { |
| 600 | printf(" size: 0x%08lX\n", symr.value); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | printf(" Globals:\n"); |
| 605 |
nothing calls this directly
no test coverage detected