From 388e7b4e98367cbdf03858817da7d756ea4247a3 Mon Sep 17 00:00:00 2001 From: Konstantin Baladurin Date: Tue, 3 Oct 2017 21:28:06 +0300 Subject: [PATCH] Use addresses without sign extension in lldb plugin (#14009) lldb doesn't expect sign-extended addresses so we need to convert them before using with lldb API. This patch allows to use SOS plugin for core files in lldb on 32-bit platforms and also fixes output of the 'clrstack -f' command. --- src/ToolBox/SOS/lldbplugin/services.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ToolBox/SOS/lldbplugin/services.cpp b/src/ToolBox/SOS/lldbplugin/services.cpp index 262f814..3186920 100644 --- a/src/ToolBox/SOS/lldbplugin/services.cpp +++ b/src/ToolBox/SOS/lldbplugin/services.cpp @@ -8,6 +8,8 @@ #include #include +#define CONVERT_FROM_SIGN_EXTENDED(offset) ((ULONG_PTR)(offset)) + ULONG g_currentThreadIndex = -1; ULONG g_currentThreadSystemId = -1; char *g_coreclrDirectory; @@ -545,6 +547,9 @@ LLDBServices::Disassemble( uint8_t byte; int cch; + // lldb doesn't expect sign-extended address + offset = CONVERT_FROM_SIGN_EXTENDED(offset); + if (buffer == NULL) { hr = E_INVALIDARG; @@ -750,6 +755,9 @@ LLDBServices::ReadVirtual( lldb::SBError error; size_t read = 0; + // lldb doesn't expect sign-extended address + offset = CONVERT_FROM_SIGN_EXTENDED(offset); + lldb::SBProcess process = GetCurrentProcess(); if (!process.IsValid()) { @@ -776,6 +784,9 @@ LLDBServices::WriteVirtual( lldb::SBError error; size_t written = 0; + // lldb doesn't expect sign-extended address + offset = CONVERT_FROM_SIGN_EXTENDED(offset); + lldb::SBProcess process = GetCurrentProcess(); if (!process.IsValid()) { @@ -822,6 +833,9 @@ LLDBServices::GetNameByOffset( lldb::SBSymbol symbol; std::string str; + // lldb doesn't expect sign-extended address + offset = CONVERT_FROM_SIGN_EXTENDED(offset); + target = m_debugger.GetSelectedTarget(); if (!target.IsValid()) { @@ -1012,6 +1026,9 @@ LLDBServices::GetModuleByOffset( lldb::SBTarget target; int numModules; + // lldb doesn't expect sign-extended address + offset = CONVERT_FROM_SIGN_EXTENDED(offset); + target = m_debugger.GetSelectedTarget(); if (!target.IsValid()) { @@ -1076,6 +1093,9 @@ LLDBServices::GetModuleNames( lldb::SBFileSpec fileSpec; HRESULT hr = S_OK; + // lldb doesn't expect sign-extended address + base = CONVERT_FROM_SIGN_EXTENDED(base); + target = m_debugger.GetSelectedTarget(); if (!target.IsValid()) { @@ -1167,6 +1187,9 @@ LLDBServices::GetLineByOffset( lldb::SBLineEntry lineEntry; std::string str; + // lldb doesn't expect sign-extended address + offset = CONVERT_FROM_SIGN_EXTENDED(offset); + target = m_debugger.GetSelectedTarget(); if (!target.IsValid()) { -- 2.7.4