[SOS] Use addresses without sign extension in lldb plugin (dotnet/coreclr#14009)
authorKonstantin Baladurin <k.baladurin@partner.samsung.com>
Tue, 3 Oct 2017 18:28:06 +0000 (21:28 +0300)
committerMike McLaughlin <mikem@microsoft.com>
Tue, 3 Oct 2017 18:28:06 +0000 (11:28 -0700)
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.

Commit migrated from https://github.com/dotnet/coreclr/commit/4ad0b6a18fe24864ff11760e9b313a0d6dbe9d3b

src/coreclr/src/ToolBox/SOS/lldbplugin/services.cpp

index e3eee4f..d0ea7bc 100644 (file)
@@ -8,6 +8,8 @@
 #include <string.h>
 #include <string>
 
+#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())
     {