diff options
| author | 2023-10-22 21:16:38 -0400 | |
|---|---|---|
| committer | 2023-11-10 12:01:35 -0500 | |
| commit | 2a255b2d61a445fb2b83cc8af7632e3d720e1292 (patch) | |
| tree | 37f5c16ba52339d91e57c5b975639dc1eb60b9f7 /src/core/debugger/gdbstub.cpp | |
| parent | Merge pull request #11981 from lucasreis1/patch (diff) | |
| download | yuzu-2a255b2d61a445fb2b83cc8af7632e3d720e1292.tar.gz yuzu-2a255b2d61a445fb2b83cc8af7632e3d720e1292.tar.xz yuzu-2a255b2d61a445fb2b83cc8af7632e3d720e1292.zip | |
kernel: add KPageTableBase
Co-authored-by: Kelebek1 <eeeedddccc@hotmail.co.uk>
Diffstat (limited to 'src/core/debugger/gdbstub.cpp')
| -rw-r--r-- | src/core/debugger/gdbstub.cpp | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp index 6f5f5156b..e9bf57895 100644 --- a/src/core/debugger/gdbstub.cpp +++ b/src/core/debugger/gdbstub.cpp | |||
| @@ -727,29 +727,34 @@ static constexpr const char* GetMemoryPermissionString(const Kernel::Svc::Memory | |||
| 727 | } | 727 | } |
| 728 | } | 728 | } |
| 729 | 729 | ||
| 730 | static VAddr GetModuleEnd(Kernel::KPageTable& page_table, VAddr base) { | 730 | static VAddr GetModuleEnd(Kernel::KProcessPageTable& page_table, VAddr base) { |
| 731 | Kernel::Svc::MemoryInfo mem_info; | 731 | Kernel::KMemoryInfo mem_info; |
| 732 | Kernel::Svc::MemoryInfo svc_mem_info; | ||
| 733 | Kernel::Svc::PageInfo page_info; | ||
| 732 | VAddr cur_addr{base}; | 734 | VAddr cur_addr{base}; |
| 733 | 735 | ||
| 734 | // Expect: r-x Code (.text) | 736 | // Expect: r-x Code (.text) |
| 735 | mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo(); | 737 | R_ASSERT(page_table.QueryInfo(std::addressof(mem_info), std::addressof(page_info), cur_addr)); |
| 736 | cur_addr = mem_info.base_address + mem_info.size; | 738 | svc_mem_info = mem_info.GetSvcMemoryInfo(); |
| 737 | if (mem_info.state != Kernel::Svc::MemoryState::Code || | 739 | cur_addr = svc_mem_info.base_address + svc_mem_info.size; |
| 738 | mem_info.permission != Kernel::Svc::MemoryPermission::ReadExecute) { | 740 | if (svc_mem_info.state != Kernel::Svc::MemoryState::Code || |
| 741 | svc_mem_info.permission != Kernel::Svc::MemoryPermission::ReadExecute) { | ||
| 739 | return cur_addr - 1; | 742 | return cur_addr - 1; |
| 740 | } | 743 | } |
| 741 | 744 | ||
| 742 | // Expect: r-- Code (.rodata) | 745 | // Expect: r-- Code (.rodata) |
| 743 | mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo(); | 746 | R_ASSERT(page_table.QueryInfo(std::addressof(mem_info), std::addressof(page_info), cur_addr)); |
| 744 | cur_addr = mem_info.base_address + mem_info.size; | 747 | svc_mem_info = mem_info.GetSvcMemoryInfo(); |
| 745 | if (mem_info.state != Kernel::Svc::MemoryState::Code || | 748 | cur_addr = svc_mem_info.base_address + svc_mem_info.size; |
| 746 | mem_info.permission != Kernel::Svc::MemoryPermission::Read) { | 749 | if (svc_mem_info.state != Kernel::Svc::MemoryState::Code || |
| 750 | svc_mem_info.permission != Kernel::Svc::MemoryPermission::Read) { | ||
| 747 | return cur_addr - 1; | 751 | return cur_addr - 1; |
| 748 | } | 752 | } |
| 749 | 753 | ||
| 750 | // Expect: rw- CodeData (.data) | 754 | // Expect: rw- CodeData (.data) |
| 751 | mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo(); | 755 | R_ASSERT(page_table.QueryInfo(std::addressof(mem_info), std::addressof(page_info), cur_addr)); |
| 752 | cur_addr = mem_info.base_address + mem_info.size; | 756 | svc_mem_info = mem_info.GetSvcMemoryInfo(); |
| 757 | cur_addr = svc_mem_info.base_address + svc_mem_info.size; | ||
| 753 | return cur_addr - 1; | 758 | return cur_addr - 1; |
| 754 | } | 759 | } |
| 755 | 760 | ||
| @@ -767,7 +772,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) { | |||
| 767 | 772 | ||
| 768 | if (command_str == "get fastmem") { | 773 | if (command_str == "get fastmem") { |
| 769 | if (Settings::IsFastmemEnabled()) { | 774 | if (Settings::IsFastmemEnabled()) { |
| 770 | const auto& impl = page_table.PageTableImpl(); | 775 | const auto& impl = page_table.GetImpl(); |
| 771 | const auto region = reinterpret_cast<uintptr_t>(impl.fastmem_arena); | 776 | const auto region = reinterpret_cast<uintptr_t>(impl.fastmem_arena); |
| 772 | const auto region_bits = impl.current_address_space_width_in_bits; | 777 | const auto region_bits = impl.current_address_space_width_in_bits; |
| 773 | const auto region_size = 1ULL << region_bits; | 778 | const auto region_size = 1ULL << region_bits; |
| @@ -785,20 +790,22 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) { | |||
| 785 | reply = fmt::format("Process: {:#x} ({})\n" | 790 | reply = fmt::format("Process: {:#x} ({})\n" |
| 786 | "Program Id: {:#018x}\n", | 791 | "Program Id: {:#018x}\n", |
| 787 | process->GetProcessId(), process->GetName(), process->GetProgramId()); | 792 | process->GetProcessId(), process->GetName(), process->GetProgramId()); |
| 788 | reply += fmt::format("Layout:\n" | 793 | reply += fmt::format( |
| 789 | " Alias: {:#012x} - {:#012x}\n" | 794 | "Layout:\n" |
| 790 | " Heap: {:#012x} - {:#012x}\n" | 795 | " Alias: {:#012x} - {:#012x}\n" |
| 791 | " Aslr: {:#012x} - {:#012x}\n" | 796 | " Heap: {:#012x} - {:#012x}\n" |
| 792 | " Stack: {:#012x} - {:#012x}\n" | 797 | " Aslr: {:#012x} - {:#012x}\n" |
| 793 | "Modules:\n", | 798 | " Stack: {:#012x} - {:#012x}\n" |
| 794 | GetInteger(page_table.GetAliasRegionStart()), | 799 | "Modules:\n", |
| 795 | GetInteger(page_table.GetAliasRegionEnd()), | 800 | GetInteger(page_table.GetAliasRegionStart()), |
| 796 | GetInteger(page_table.GetHeapRegionStart()), | 801 | GetInteger(page_table.GetAliasRegionStart()) + page_table.GetAliasRegionSize() - 1, |
| 797 | GetInteger(page_table.GetHeapRegionEnd()), | 802 | GetInteger(page_table.GetHeapRegionStart()), |
| 798 | GetInteger(page_table.GetAliasCodeRegionStart()), | 803 | GetInteger(page_table.GetHeapRegionStart()) + page_table.GetHeapRegionSize() - 1, |
| 799 | GetInteger(page_table.GetAliasCodeRegionEnd()), | 804 | GetInteger(page_table.GetAliasCodeRegionStart()), |
| 800 | GetInteger(page_table.GetStackRegionStart()), | 805 | GetInteger(page_table.GetAliasCodeRegionStart()) + page_table.GetAliasCodeRegionSize() - |
| 801 | GetInteger(page_table.GetStackRegionEnd())); | 806 | 1, |
| 807 | GetInteger(page_table.GetStackRegionStart()), | ||
| 808 | GetInteger(page_table.GetStackRegionStart()) + page_table.GetStackRegionSize() - 1); | ||
| 802 | 809 | ||
| 803 | for (const auto& [vaddr, name] : modules) { | 810 | for (const auto& [vaddr, name] : modules) { |
| 804 | reply += fmt::format(" {:#012x} - {:#012x} {}\n", vaddr, | 811 | reply += fmt::format(" {:#012x} - {:#012x} {}\n", vaddr, |
| @@ -811,27 +818,34 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) { | |||
| 811 | while (true) { | 818 | while (true) { |
| 812 | using MemoryAttribute = Kernel::Svc::MemoryAttribute; | 819 | using MemoryAttribute = Kernel::Svc::MemoryAttribute; |
| 813 | 820 | ||
| 814 | auto mem_info = page_table.QueryInfo(cur_addr).GetSvcMemoryInfo(); | 821 | Kernel::KMemoryInfo mem_info{}; |
| 815 | 822 | Kernel::Svc::PageInfo page_info{}; | |
| 816 | if (mem_info.state != Kernel::Svc::MemoryState::Inaccessible || | 823 | R_ASSERT(page_table.QueryInfo(std::addressof(mem_info), std::addressof(page_info), |
| 817 | mem_info.base_address + mem_info.size - 1 != std::numeric_limits<u64>::max()) { | 824 | cur_addr)); |
| 818 | const char* state = GetMemoryStateName(mem_info.state); | 825 | auto svc_mem_info = mem_info.GetSvcMemoryInfo(); |
| 819 | const char* perm = GetMemoryPermissionString(mem_info); | 826 | |
| 820 | 827 | if (svc_mem_info.state != Kernel::Svc::MemoryState::Inaccessible || | |
| 821 | const char l = True(mem_info.attribute & MemoryAttribute::Locked) ? 'L' : '-'; | 828 | svc_mem_info.base_address + svc_mem_info.size - 1 != |
| 822 | const char i = True(mem_info.attribute & MemoryAttribute::IpcLocked) ? 'I' : '-'; | 829 | std::numeric_limits<u64>::max()) { |
| 823 | const char d = True(mem_info.attribute & MemoryAttribute::DeviceShared) ? 'D' : '-'; | 830 | const char* state = GetMemoryStateName(svc_mem_info.state); |
| 824 | const char u = True(mem_info.attribute & MemoryAttribute::Uncached) ? 'U' : '-'; | 831 | const char* perm = GetMemoryPermissionString(svc_mem_info); |
| 832 | |||
| 833 | const char l = True(svc_mem_info.attribute & MemoryAttribute::Locked) ? 'L' : '-'; | ||
| 834 | const char i = | ||
| 835 | True(svc_mem_info.attribute & MemoryAttribute::IpcLocked) ? 'I' : '-'; | ||
| 836 | const char d = | ||
| 837 | True(svc_mem_info.attribute & MemoryAttribute::DeviceShared) ? 'D' : '-'; | ||
| 838 | const char u = True(svc_mem_info.attribute & MemoryAttribute::Uncached) ? 'U' : '-'; | ||
| 825 | const char p = | 839 | const char p = |
| 826 | True(mem_info.attribute & MemoryAttribute::PermissionLocked) ? 'P' : '-'; | 840 | True(svc_mem_info.attribute & MemoryAttribute::PermissionLocked) ? 'P' : '-'; |
| 827 | 841 | ||
| 828 | reply += fmt::format(" {:#012x} - {:#012x} {} {} {}{}{}{}{} [{}, {}]\n", | 842 | reply += fmt::format( |
| 829 | mem_info.base_address, | 843 | " {:#012x} - {:#012x} {} {} {}{}{}{}{} [{}, {}]\n", svc_mem_info.base_address, |
| 830 | mem_info.base_address + mem_info.size - 1, perm, state, l, i, | 844 | svc_mem_info.base_address + svc_mem_info.size - 1, perm, state, l, i, d, u, p, |
| 831 | d, u, p, mem_info.ipc_count, mem_info.device_count); | 845 | svc_mem_info.ipc_count, svc_mem_info.device_count); |
| 832 | } | 846 | } |
| 833 | 847 | ||
| 834 | const uintptr_t next_address = mem_info.base_address + mem_info.size; | 848 | const uintptr_t next_address = svc_mem_info.base_address + svc_mem_info.size; |
| 835 | if (next_address <= cur_addr) { | 849 | if (next_address <= cur_addr) { |
| 836 | break; | 850 | break; |
| 837 | } | 851 | } |