Index: source/Plugins/JITLoader/GDB/JITLoaderGDB.h =================================================================== --- source/Plugins/JITLoader/GDB/JITLoaderGDB.h +++ source/Plugins/JITLoader/GDB/JITLoaderGDB.h @@ -83,7 +83,7 @@ bool ReadJITDescriptor(bool all_entries); - template + template bool ReadJITDescriptorImpl(bool all_entries); Index: source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp =================================================================== --- source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -28,6 +28,34 @@ using namespace lldb; using namespace lldb_private; +//------------------------------------------------------------------ +// Debug Interface Structures +//------------------------------------------------------------------ +typedef enum +{ + JIT_NOACTION = 0, + JIT_REGISTER_FN, + JIT_UNREGISTER_FN +} jit_actions_t; + +template +struct jit_code_entry +{ + ptr_t next_entry; // pointer + ptr_t prev_entry; // pointer + ptr_t symfile_addr; // pointer + uint64_t symfile_size; +}; + +template +struct jit_descriptor +{ + uint32_t version; + uint32_t action_flag; // Values are jit_action_t + ptr_t relevant_entry; // pointer + ptr_t first_entry; // pointer +}; + namespace { PropertyDefinition @@ -78,44 +106,42 @@ return g_settings_sp; } -} // anonymous namespace end - -//------------------------------------------------------------------ -// Debug Interface Structures -//------------------------------------------------------------------ -typedef enum -{ - JIT_NOACTION = 0, - JIT_REGISTER_FN, - JIT_UNREGISTER_FN -} jit_actions_t; - -template -struct jit_code_entry -{ - ptr_t next_entry; // pointer - ptr_t prev_entry; // pointer - ptr_t symfile_addr; // pointer - uint64_t symfile_size __attribute__ ((aligned (8))); -}; - -template -struct jit_code_entry -{ - ptr_t next_entry; // pointer - ptr_t prev_entry; // pointer - ptr_t symfile_addr; // pointer - uint64_t symfile_size __attribute__ ((packed)); -}; + template + bool ReadJITEntry(const addr_t &from_addr, Process *process, jit_code_entry *entry) + { + addr_t addr = from_addr; + Error error; + size_t bytes_read = 0; + + bytes_read = process->DoReadMemory(addr, &entry->next_entry, sizeof(ptr_t), error); + if (bytes_read != sizeof(ptr_t) || !error.Success()) + return false; + addr += sizeof(ptr_t); + + bytes_read = process->DoReadMemory(addr, &entry->prev_entry, sizeof(ptr_t), error); + if (bytes_read != sizeof(ptr_t) || !error.Success()) + return false; + addr += sizeof(ptr_t); + + bytes_read = process->DoReadMemory(addr, &entry->symfile_addr, sizeof(ptr_t), error); + if (bytes_read != sizeof(ptr_t) || !error.Success()) + return false; + addr += sizeof(ptr_t); + + ArchSpec::Core core = process->GetTarget().GetArchitecture().GetCore(); + if (ArchSpec::kCore_x86_32_first <= core && core <= ArchSpec::kCore_x86_32_last) + addr += addr % 4; + else + addr += addr % 8; + + bytes_read = process->DoReadMemory(addr, &entry->symfile_size, 8, error); + if (bytes_read != 8 || !error.Success()) + return false; + + return true; + } -template -struct jit_descriptor -{ - uint32_t version; - uint32_t action_flag; // Values are jit_action_t - ptr_t relevant_entry; // pointer - ptr_t first_entry; // pointer -}; +} // anonymous namespace end JITLoaderGDB::JITLoaderGDB (lldb_private::Process *process) : JITLoader(process), @@ -278,21 +304,13 @@ bool JITLoaderGDB::ReadJITDescriptor(bool all_entries) { - Target &target = m_process->GetTarget(); - const ArchSpec &arch_spec = target.GetArchitecture(); - if (arch_spec.GetAddressByteSize() == 8) - return ReadJITDescriptorImpl(all_entries); + if (m_process->GetTarget().GetArchitecture().GetAddressByteSize() == 8) + return ReadJITDescriptorImpl(all_entries); else - { - ArchSpec::Core core = arch_spec.GetCore(); - if (ArchSpec::kCore_x86_32_first <= core && core <= ArchSpec::kCore_x86_32_last) - return ReadJITDescriptorImpl(all_entries); - else - return ReadJITDescriptorImpl(all_entries); - } + return ReadJITDescriptorImpl(all_entries); } -template +template bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) { @@ -326,10 +344,8 @@ while (jit_relevant_entry != 0) { - jit_code_entry jit_entry; - const size_t jit_entry_size = sizeof(jit_entry); - bytes_read = m_process->DoReadMemory(jit_relevant_entry, &jit_entry, jit_entry_size, error); - if (bytes_read != jit_entry_size || !error.Success()) + jit_code_entry jit_entry; + if (!ReadJITEntry(jit_relevant_entry, m_process, &jit_entry)) { if (log) log->Printf(