diff options
Diffstat (limited to 'source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp')
-rw-r--r-- | source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp b/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp index 140d09ed43cf..fff44123539f 100644 --- a/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ b/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -6,9 +6,8 @@ // //===----------------------------------------------------------------------===// - -#include "llvm/Support/MathExtras.h" - +#include "JITLoaderGDB.h" +#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -26,8 +25,7 @@ #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" - -#include "JITLoaderGDB.h" +#include "llvm/Support/MathExtras.h" #include <memory> @@ -59,21 +57,33 @@ enum EnableJITLoaderGDB { eEnableJITLoaderGDBOff, }; -static constexpr OptionEnumValueElement g_enable_jit_loader_gdb_enumerators[] = { - {eEnableJITLoaderGDBDefault, "default", "Enable JIT compilation interface " - "for all platforms except macOS"}, - {eEnableJITLoaderGDBOn, "on", "Enable JIT compilation interface"}, - {eEnableJITLoaderGDBOff, "off", "Disable JIT compilation interface"} - }; +static constexpr OptionEnumValueElement g_enable_jit_loader_gdb_enumerators[] = + { + { + eEnableJITLoaderGDBDefault, + "default", + "Enable JIT compilation interface for all platforms except macOS", + }, + { + eEnableJITLoaderGDBOn, + "on", + "Enable JIT compilation interface", + }, + { + eEnableJITLoaderGDBOff, + "off", + "Disable JIT compilation interface", + }, +}; -static constexpr PropertyDefinition g_properties[] = { - {"enable", OptionValue::eTypeEnum, true, - eEnableJITLoaderGDBDefault, nullptr, - OptionEnumValues(g_enable_jit_loader_gdb_enumerators), - "Enable GDB's JIT compilation interface (default: enabled on " - "all platforms except macOS)"}}; +#define LLDB_PROPERTIES_jitloadergdb +#include "JITLoaderGDBProperties.inc" -enum { ePropertyEnable, ePropertyEnableJITBreakpoint }; +enum { +#define LLDB_PROPERTIES_jitloadergdb +#include "JITLoaderGDBPropertiesEnum.inc" + ePropertyEnableJITBreakpoint +}; class PluginProperties : public Properties { public: @@ -83,13 +93,13 @@ public: PluginProperties() { m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName()); - m_collection_sp->Initialize(g_properties); + m_collection_sp->Initialize(g_jitloadergdb_properties); } EnableJITLoaderGDB GetEnable() const { return (EnableJITLoaderGDB)m_collection_sp->GetPropertyAtIndexAsEnumeration( nullptr, ePropertyEnable, - g_properties[ePropertyEnable].default_uint_value); + g_jitloadergdb_properties[ePropertyEnable].default_uint_value); } }; @@ -177,8 +187,8 @@ void JITLoaderGDB::SetJITBreakpoint(lldb_private::ModuleList &module_list) { return; Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER)); - if (log) - log->Printf("JITLoaderGDB::%s looking for JIT register hook", __FUNCTION__); + LLDB_LOGF(log, "JITLoaderGDB::%s looking for JIT register hook", + __FUNCTION__); addr_t jit_addr = GetSymbolAddress( module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny); @@ -188,14 +198,12 @@ void JITLoaderGDB::SetJITBreakpoint(lldb_private::ModuleList &module_list) { m_jit_descriptor_addr = GetSymbolAddress( module_list, ConstString("__jit_debug_descriptor"), eSymbolTypeData); if (m_jit_descriptor_addr == LLDB_INVALID_ADDRESS) { - if (log) - log->Printf("JITLoaderGDB::%s failed to find JIT descriptor address", - __FUNCTION__); + LLDB_LOGF(log, "JITLoaderGDB::%s failed to find JIT descriptor address", + __FUNCTION__); return; } - if (log) - log->Printf("JITLoaderGDB::%s setting JIT breakpoint", __FUNCTION__); + LLDB_LOGF(log, "JITLoaderGDB::%s setting JIT breakpoint", __FUNCTION__); Breakpoint *bp = m_process->GetTarget().CreateBreakpoint(jit_addr, true, false).get(); @@ -211,8 +219,7 @@ bool JITLoaderGDB::JITDebugBreakpointHit(void *baton, user_id_t break_id, user_id_t break_loc_id) { Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER)); - if (log) - log->Printf("JITLoaderGDB::%s hit JIT breakpoint", __FUNCTION__); + LLDB_LOGF(log, "JITLoaderGDB::%s hit JIT breakpoint", __FUNCTION__); JITLoaderGDB *instance = static_cast<JITLoaderGDB *>(baton); return instance->ReadJITDescriptor(false); } @@ -285,9 +292,8 @@ bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) { size_t bytes_read = m_process->DoReadMemory(m_jit_descriptor_addr, &jit_desc, jit_desc_size, error); if (bytes_read != jit_desc_size || !error.Success()) { - if (log) - log->Printf("JITLoaderGDB::%s failed to read JIT descriptor", - __FUNCTION__); + LLDB_LOGF(log, "JITLoaderGDB::%s failed to read JIT descriptor", + __FUNCTION__); return false; } @@ -301,9 +307,8 @@ bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) { while (jit_relevant_entry != 0) { jit_code_entry<ptr_t> jit_entry; if (!ReadJITEntry(jit_relevant_entry, m_process, &jit_entry)) { - if (log) - log->Printf("JITLoaderGDB::%s failed to read JIT entry at 0x%" PRIx64, - __FUNCTION__, jit_relevant_entry); + LLDB_LOGF(log, "JITLoaderGDB::%s failed to read JIT entry at 0x%" PRIx64, + __FUNCTION__, jit_relevant_entry); return false; } @@ -312,10 +317,10 @@ bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) { ModuleSP module_sp; if (jit_action == JIT_REGISTER_FN) { - if (log) - log->Printf("JITLoaderGDB::%s registering JIT entry at 0x%" PRIx64 - " (%" PRIu64 " bytes)", - __FUNCTION__, symbolfile_addr, (uint64_t)symbolfile_size); + LLDB_LOGF(log, + "JITLoaderGDB::%s registering JIT entry at 0x%" PRIx64 + " (%" PRIu64 " bytes)", + __FUNCTION__, symbolfile_addr, (uint64_t)symbolfile_size); char jit_name[64]; snprintf(jit_name, 64, "JIT(0x%" PRIx64 ")", symbolfile_addr); @@ -331,20 +336,16 @@ bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) { module_sp->GetObjectFile()->GetSymtab(); m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp)); - if (module_sp->GetObjectFile()->GetPluginName() == - ConstString("mach-o")) { - ObjectFile *image_object_file = module_sp->GetObjectFile(); - if (image_object_file) { - const SectionList *section_list = - image_object_file->GetSectionList(); - if (section_list) { - uint64_t vmaddrheuristic = 0; - uint64_t lower = (uint64_t)-1; - uint64_t upper = 0; - updateSectionLoadAddress(*section_list, target, symbolfile_addr, - symbolfile_size, vmaddrheuristic, lower, - upper); - } + if (auto image_object_file = + llvm::dyn_cast<ObjectFileMachO>(module_sp->GetObjectFile())) { + const SectionList *section_list = image_object_file->GetSectionList(); + if (section_list) { + uint64_t vmaddrheuristic = 0; + uint64_t lower = (uint64_t)-1; + uint64_t upper = 0; + updateSectionLoadAddress(*section_list, target, symbolfile_addr, + symbolfile_size, vmaddrheuristic, lower, + upper); } } else { bool changed = false; @@ -357,15 +358,14 @@ bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) { module_list.Append(module_sp); target.ModulesDidLoad(module_list); } else { - if (log) - log->Printf("JITLoaderGDB::%s failed to load module for " - "JIT entry at 0x%" PRIx64, - __FUNCTION__, symbolfile_addr); + LLDB_LOGF(log, + "JITLoaderGDB::%s failed to load module for " + "JIT entry at 0x%" PRIx64, + __FUNCTION__, symbolfile_addr); } } else if (jit_action == JIT_UNREGISTER_FN) { - if (log) - log->Printf("JITLoaderGDB::%s unregistering JIT entry at 0x%" PRIx64, - __FUNCTION__, symbolfile_addr); + LLDB_LOGF(log, "JITLoaderGDB::%s unregistering JIT entry at 0x%" PRIx64, + __FUNCTION__, symbolfile_addr); JITObjectMap::iterator it = m_jit_objects.find(symbolfile_addr); if (it != m_jit_objects.end()) { @@ -458,8 +458,8 @@ addr_t JITLoaderGDB::GetSymbolAddress(ModuleList &module_list, SymbolContextList target_symbols; Target &target = m_process->GetTarget(); - if (!module_list.FindSymbolsWithNameAndType(name, symbol_type, - target_symbols)) + module_list.FindSymbolsWithNameAndType(name, symbol_type, target_symbols); + if (target_symbols.IsEmpty()) return LLDB_INVALID_ADDRESS; SymbolContext sym_ctx; |