From fdbb5a7a91b00d1e4a9a16fee96763917a411fff Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 14 Apr 2021 16:34:04 -0700 Subject: [PATCH] [lldb] Add code and data address mask to Process Add a code and data address mask to Process with respective getters and setters and a setting that allows the user to specify the mast as a number of addressable bits. The masks will be used by FixCodeAddress and FixDataAddress respectively in the ABI classes. Differential revision: https://reviews.llvm.org/D100515 --- lldb/include/lldb/Target/Process.h | 20 ++++++++++++++++++++ lldb/source/Target/Process.cpp | 30 ++++++++++++++++++++++++++++++ lldb/source/Target/TargetProperties.td | 3 +++ 3 files changed, 53 insertions(+) diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index abd0d39..0a2a6f6 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -77,6 +77,8 @@ public: Args GetExtraStartupCommands() const; void SetExtraStartupCommands(const Args &args); FileSpec GetPythonOSPluginPath() const; + uint32_t GetVirtualAddressableBits() const; + void SetVirtualAddressableBits(uint32_t bits); void SetPythonOSPluginPath(const FileSpec &file); bool GetIgnoreBreakpointsInExpressions() const; void SetIgnoreBreakpointsInExpressions(bool ignore); @@ -1330,6 +1332,17 @@ public: virtual void DidExit() {} + lldb::addr_t GetCodeAddressMask(); + lldb::addr_t GetDataAddressMask(); + + void SetCodeAddressMask(lldb::addr_t code_address_mask) { + m_code_address_mask = code_address_mask; + } + + void SetDataAddressMask(lldb::addr_t data_address_mask) { + m_data_address_mask = data_address_mask; + } + /// Get the Modification ID of the process. /// /// \return @@ -2878,6 +2891,13 @@ protected: /// from looking up or creating things during or after a finalize call. std::atomic m_finalizing; + /// Mask for code an data addresses. The default value (0) means no mask is + /// set. + /// @{ + lldb::addr_t m_code_address_mask = 0; + lldb::addr_t m_data_address_mask = 0; + /// @} + bool m_clear_thread_plans_on_stop; bool m_force_next_event_delivery; lldb::StateType m_last_broadcast_state; /// This helps with the Public event diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 986df94..9f39e78 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -200,6 +200,16 @@ FileSpec ProcessProperties::GetPythonOSPluginPath() const { return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx); } +uint32_t ProcessProperties::GetVirtualAddressableBits() const { + const uint32_t idx = ePropertyVirtualAddressableBits; + return m_collection_sp->GetPropertyAtIndexAsUInt64( + nullptr, idx, g_process_properties[idx].default_uint_value); +} + +void ProcessProperties::SetVirtualAddressableBits(uint32_t bits) { + const uint32_t idx = ePropertyVirtualAddressableBits; + m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, bits); +} void ProcessProperties::SetPythonOSPluginPath(const FileSpec &file) { const uint32_t idx = ePropertyPythonOSPluginPath; m_collection_sp->SetPropertyAtIndexAsFileSpec(nullptr, idx, file); @@ -5547,6 +5557,26 @@ void Process::Flush() { m_queue_list_stop_id = 0; } +lldb::addr_t Process::GetCodeAddressMask() { + if (m_code_address_mask == 0) { + if (uint32_t number_of_addressable_bits = GetVirtualAddressableBits()) { + lldb::addr_t address_mask = ~((1ULL << number_of_addressable_bits) - 1); + SetCodeAddressMask(address_mask); + } + } + return m_code_address_mask; +} + +lldb::addr_t Process::GetDataAddressMask() { + if (m_data_address_mask == 0) { + if (uint32_t number_of_addressable_bits = GetVirtualAddressableBits()) { + lldb::addr_t address_mask = ~((1ULL << number_of_addressable_bits) - 1); + SetDataAddressMask(address_mask); + } + } + return m_data_address_mask; +} + void Process::DidExec() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); LLDB_LOGF(log, "Process::%s()", __FUNCTION__); diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index e22f940..a3634a0 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -233,6 +233,9 @@ let Definition = "process" in { def SteppingRunsAllThreads: Property<"run-all-threads", "Boolean">, DefaultFalse, Desc<"If true, stepping operations will run all threads. This is equivalent to setting the run-mode option to 'all-threads'.">; + def VirtualAddressableBits: Property<"virtual-addressable-bits", "UInt64">, + DefaultUnsignedValue<0>, + Desc<"The number of bits used for addressing. If the value is 39, then bits 0..38 are used for addressing. The default value of 0 means unspecified.">; } let Definition = "platform" in { -- 2.7.4