summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike McLaughlin <mikem@microsoft.com>2015-08-04 12:01:04 -0700
committerMike McLaughlin <mikem@microsoft.com>2015-08-04 12:01:04 -0700
commit9fd41c57e01a26cae2451336d22231854988e1e0 (patch)
treeff447006c6ffe1e62d3e7974342ad25efad96b2a
parent885c6f8ed0c545f24c8d730fe261cbbcc2bc8b52 (diff)
parentb356f950b2e560a5b77d182dd46d2c99441a084a (diff)
downloadcoreclr-9fd41c57e01a26cae2451336d22231854988e1e0.tar.gz
coreclr-9fd41c57e01a26cae2451336d22231854988e1e0.tar.bz2
coreclr-9fd41c57e01a26cae2451336d22231854988e1e0.zip
Merge pull request #1327 from mikem8361/settid
Add work around a bug in lldb on a core dump
-rw-r--r--src/ToolBox/SOS/Strike/strike.cpp2
-rw-r--r--src/ToolBox/SOS/lldbplugin/CMakeLists.txt4
-rw-r--r--src/ToolBox/SOS/lldbplugin/debugclient.cpp56
-rw-r--r--src/ToolBox/SOS/lldbplugin/debugclient.h9
-rw-r--r--src/ToolBox/SOS/lldbplugin/setclrpathcommand.cpp52
-rw-r--r--src/ToolBox/SOS/lldbplugin/setsostidcommand.cpp53
-rw-r--r--src/ToolBox/SOS/lldbplugin/soscommand.cpp27
-rw-r--r--src/ToolBox/SOS/lldbplugin/sosplugin.cpp2
-rw-r--r--src/ToolBox/SOS/lldbplugin/sosplugin.h12
9 files changed, 190 insertions, 27 deletions
diff --git a/src/ToolBox/SOS/Strike/strike.cpp b/src/ToolBox/SOS/Strike/strike.cpp
index 0c2f97f625..a6b1834373 100644
--- a/src/ToolBox/SOS/Strike/strike.cpp
+++ b/src/ToolBox/SOS/Strike/strike.cpp
@@ -14019,4 +14019,4 @@ Help(PDEBUG_CLIENT Client, PCSTR Args)
return S_OK;
}
-#endif // !FEATURE_PAL
+#endif // FEATURE_PAL
diff --git a/src/ToolBox/SOS/lldbplugin/CMakeLists.txt b/src/ToolBox/SOS/lldbplugin/CMakeLists.txt
index ce279e9a1c..6eb30054ca 100644
--- a/src/ToolBox/SOS/lldbplugin/CMakeLists.txt
+++ b/src/ToolBox/SOS/lldbplugin/CMakeLists.txt
@@ -28,7 +28,7 @@ if(NOT ENABLE_LLDBPLUGIN)
endif()
# Check for LLDB library
-find_library(LLDB NAMES lldb-3.6 lldb-3.5 LLDB lldb PATHS "${WITH_LLDB_LIBS}" PATH_SUFFIXES llvm)
+find_library(LLDB NAMES LLDB lldb lldb-3.6 lldb-3.5 PATHS "${WITH_LLDB_LIBS}" PATH_SUFFIXES llvm)
if(LLDB STREQUAL LLDB-NOTFOUND)
if(REQUIRE_LLDBPLUGIN)
message(FATAL_ERROR "Cannot find lldb-3.5 or lldb-3.6. Try installing lldb-3.6-dev (or the appropriate package for your platform)")
@@ -70,6 +70,8 @@ include_directories(${CLR_DIR}/src/coreclr/hosts/unixcoreruncommon)
set(SOURCES
sosplugin.cpp
soscommand.cpp
+ setclrpathcommand.cpp
+ setsostidcommand.cpp
coreruncommand.cpp
debugclient.cpp
${CLR_DIR}/src/coreclr/hosts/unixcorerun/corerun.cpp
diff --git a/src/ToolBox/SOS/lldbplugin/debugclient.cpp b/src/ToolBox/SOS/lldbplugin/debugclient.cpp
index f2a690b73b..51d61baca0 100644
--- a/src/ToolBox/SOS/lldbplugin/debugclient.cpp
+++ b/src/ToolBox/SOS/lldbplugin/debugclient.cpp
@@ -10,10 +10,13 @@
#include <dbgtargetcontext.h>
#include <string>
-DebugClient::DebugClient(lldb::SBDebugger &debugger, lldb::SBCommandReturnObject &returnObject, char *coreclrDirectory) :
+ULONG g_currentThreadIndex = -1;
+ULONG g_currentThreadSystemId = -1;
+char *g_coreclrDirectory;
+
+DebugClient::DebugClient(lldb::SBDebugger &debugger, lldb::SBCommandReturnObject &returnObject) :
m_debugger(debugger),
- m_returnObject(returnObject),
- m_coreclrDirectory(coreclrDirectory)
+ m_returnObject(returnObject)
{
returnObject.SetStatus(lldb::eReturnStatusSuccessFinishResult);
}
@@ -741,6 +744,14 @@ DebugClient::GetCurrentThreadId(
return E_FAIL;
}
+ // This is allow the a valid current TID to be returned to
+ // workaround a bug in lldb on core dumps.
+ if (g_currentThreadIndex != -1)
+ {
+ *id = g_currentThreadIndex;
+ return S_OK;
+ }
+
*id = thread.GetIndexID();
return S_OK;
}
@@ -774,6 +785,14 @@ DebugClient::GetCurrentThreadSystemId(
return E_FAIL;
}
+ // This is allow the a valid current TID to be returned to
+ // workaround a bug in lldb on core dumps.
+ if (g_currentThreadSystemId != -1)
+ {
+ *sysId = g_currentThreadSystemId;
+ return S_OK;
+ }
+
*sysId = thread.GetThreadID();
return S_OK;
}
@@ -795,13 +814,22 @@ DebugClient::GetThreadIdBySystemId(
goto exit;
}
- thread = process.GetThreadByID(sysId);
- if (!thread.IsValid())
+ // If we have a "fake" thread OS (system) id and a fake thread index,
+ // we need to return fake thread index.
+ if (g_currentThreadSystemId == sysId && g_currentThreadIndex != -1)
{
- goto exit;
+ id = g_currentThreadIndex;
}
+ else
+ {
+ thread = process.GetThreadByID(sysId);
+ if (!thread.IsValid())
+ {
+ goto exit;
+ }
- id = thread.GetIndexID();
+ id = thread.GetIndexID();
+ }
hr = S_OK;
exit:
@@ -834,7 +862,17 @@ DebugClient::GetThreadContextById(
goto exit;
}
- thread = process.GetThreadByID(threadID);
+ // If we have a "fake" thread OS (system) id and a fake thread index,
+ // use the fake thread index to get the context.
+ if (g_currentThreadSystemId == threadID && g_currentThreadIndex != -1)
+ {
+ thread = process.GetThreadByIndexID(g_currentThreadIndex);
+ }
+ else
+ {
+ thread = process.GetThreadByID(threadID);
+ }
+
if (!thread.IsValid())
{
goto exit;
@@ -1001,7 +1039,7 @@ DebugClient::GetFrameOffset(
PCSTR
DebugClient::GetCoreClrDirectory()
{
- return m_coreclrDirectory;
+ return g_coreclrDirectory;
}
DWORD_PTR
diff --git a/src/ToolBox/SOS/lldbplugin/debugclient.h b/src/ToolBox/SOS/lldbplugin/debugclient.h
index 3081189fa1..cb2d089d0e 100644
--- a/src/ToolBox/SOS/lldbplugin/debugclient.h
+++ b/src/ToolBox/SOS/lldbplugin/debugclient.h
@@ -8,7 +8,6 @@ class DebugClient : public IDebugClient
private:
lldb::SBDebugger &m_debugger;
lldb::SBCommandReturnObject &m_returnObject;
- char *m_coreclrDirectory;
void OutputString(ULONG mask, PCSTR str);
lldb::SBProcess GetCurrentProcess();
@@ -19,7 +18,7 @@ private:
DWORD_PTR GetRegister(lldb::SBFrame frame, const char *name);
public:
- DebugClient(lldb::SBDebugger &debugger, lldb::SBCommandReturnObject &returnObject, char *coreclrDirectory);
+ DebugClient(lldb::SBDebugger &debugger, lldb::SBCommandReturnObject &returnObject);
~DebugClient();
//----------------------------------------------------------------------------
@@ -139,6 +138,9 @@ public:
ULONG loadedImageNameBufferSize,
PULONG loadedImageNameSize);
+ PCSTR GetModuleDirectory(
+ PCSTR name);
+
//----------------------------------------------------------------------------
// IDebugSystemObjects
//----------------------------------------------------------------------------
@@ -187,7 +189,4 @@ public:
DWORD_PTR GetExpression(
PCSTR exp);
-
- PCSTR GetModuleDirectory(
- PCSTR name);
};
diff --git a/src/ToolBox/SOS/lldbplugin/setclrpathcommand.cpp b/src/ToolBox/SOS/lldbplugin/setclrpathcommand.cpp
new file mode 100644
index 0000000000..2810ff402c
--- /dev/null
+++ b/src/ToolBox/SOS/lldbplugin/setclrpathcommand.cpp
@@ -0,0 +1,52 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+#include "sosplugin.h"
+#include <dlfcn.h>
+#include <string.h>
+#include <string>
+
+class setclrpathCommand : public lldb::SBCommandPluginInterface
+{
+public:
+ setclrpathCommand()
+ {
+ }
+
+ virtual bool
+ DoExecute (lldb::SBDebugger debugger,
+ char** arguments,
+ lldb::SBCommandReturnObject &result)
+ {
+ if (arguments[0] == NULL)
+ {
+ result.Printf("setclrpath error - no path\n");
+ return false;
+ }
+
+ if (g_coreclrDirectory != NULL)
+ {
+ free(g_coreclrDirectory);
+ }
+
+ std::string path(arguments[0]);
+ if (path[path.length() - 1] != '/')
+ {
+ path.append("/");
+ }
+
+ g_coreclrDirectory = strdup(path.c_str());
+ result.Printf("Set load path for sos/dac/dbi to %s\n", g_coreclrDirectory);
+ return result.Succeeded();
+ }
+};
+
+bool
+setclrpathCommandInitialize(lldb::SBDebugger debugger)
+{
+ lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
+ lldb::SBCommand command = interpreter.AddCommand("setclrpath", new setclrpathCommand(), "Set the path to load coreclr sos/dac/dbi files. setclrpath <path>");
+ return true;
+}
diff --git a/src/ToolBox/SOS/lldbplugin/setsostidcommand.cpp b/src/ToolBox/SOS/lldbplugin/setsostidcommand.cpp
new file mode 100644
index 0000000000..c1366e3eb4
--- /dev/null
+++ b/src/ToolBox/SOS/lldbplugin/setsostidcommand.cpp
@@ -0,0 +1,53 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+#include "sosplugin.h"
+#include <dlfcn.h>
+#include <string.h>
+#include <string>
+
+class setsostidCommand : public lldb::SBCommandPluginInterface
+{
+public:
+ setsostidCommand()
+ {
+ }
+
+ virtual bool
+ DoExecute(lldb::SBDebugger debugger,
+ char** arguments,
+ lldb::SBCommandReturnObject &result)
+ {
+ if (arguments[0] == NULL)
+ {
+ result.Printf("Clearing sos thread os id/index\n");
+ g_currentThreadIndex = -1;
+ g_currentThreadSystemId = -1;
+ }
+ else if (arguments[1] == NULL)
+ {
+ result.Printf("Need thread index parameter that maps to the os id\n");
+ }
+ else
+ {
+ ULONG tid = strtoul(arguments[0], NULL, 16);
+ g_currentThreadSystemId = tid;
+
+ ULONG index = strtoul(arguments[1], NULL, 16);
+ g_currentThreadIndex = index;
+
+ result.Printf("Set sos thread os id to 0x%x which maps to lldb thread index %d\n", tid, index);
+ }
+ return result.Succeeded();
+ }
+};
+
+bool
+setsostidCommandInitialize(lldb::SBDebugger debugger)
+{
+ lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
+ lldb::SBCommand command = interpreter.AddCommand("setsostid", new setsostidCommand(), "Set the current os tid/thread index instead of using the one lldb provides. setsostid <tid> <index>");
+ return true;
+}
diff --git a/src/ToolBox/SOS/lldbplugin/soscommand.cpp b/src/ToolBox/SOS/lldbplugin/soscommand.cpp
index be0ef9b4b4..660295d456 100644
--- a/src/ToolBox/SOS/lldbplugin/soscommand.cpp
+++ b/src/ToolBox/SOS/lldbplugin/soscommand.cpp
@@ -11,7 +11,6 @@
class sosCommand : public lldb::SBCommandPluginInterface
{
void *m_sosHandle;
- char m_coreclrDirectory[MAX_PATH];
public:
sosCommand()
@@ -24,7 +23,7 @@ public:
char** arguments,
lldb::SBCommandReturnObject &result)
{
- DebugClient* client = new DebugClient(debugger, result, m_coreclrDirectory);
+ DebugClient* client = new DebugClient(debugger, result);
if (arguments)
{
LoadSos(client);
@@ -65,16 +64,24 @@ public:
{
if (m_sosHandle == NULL)
{
- const char *coreclrModule = MAKEDLLNAME_A("coreclr");
- const char *directory = client->GetModuleDirectory(coreclrModule);
- if (directory == NULL)
+ if (g_coreclrDirectory == NULL)
{
- client->Output(DEBUG_OUTPUT_WARNING, "The %s module is not loaded yet in the target process\n", coreclrModule);
+ const char *coreclrModule = MAKEDLLNAME_A("coreclr");
+ const char *directory = client->GetModuleDirectory(coreclrModule);
+ if (directory != NULL)
+ {
+ std::string path(directory);
+ path.append("/");
+ g_coreclrDirectory = strdup(path.c_str());
+ }
+ else
+ {
+ client->Output(DEBUG_OUTPUT_WARNING, "The %s module is not loaded yet in the target process\n", coreclrModule);
+ }
}
- else
+
+ if (g_coreclrDirectory != NULL)
{
- strcpy(m_coreclrDirectory, directory);
- strcat(m_coreclrDirectory, "/");
// Load the DAC module first explicitly because SOS and DBI
// have implicit references to the DAC's PAL.
@@ -88,7 +95,7 @@ public:
void *
LoadModule(DebugClient *client, const char *moduleName)
{
- std::string modulePath(m_coreclrDirectory);
+ std::string modulePath(g_coreclrDirectory);
modulePath.append(moduleName);
void *moduleHandle = dlopen(modulePath.c_str(), RTLD_NOW);
diff --git a/src/ToolBox/SOS/lldbplugin/sosplugin.cpp b/src/ToolBox/SOS/lldbplugin/sosplugin.cpp
index a6111b6186..024e42c475 100644
--- a/src/ToolBox/SOS/lldbplugin/sosplugin.cpp
+++ b/src/ToolBox/SOS/lldbplugin/sosplugin.cpp
@@ -14,5 +14,7 @@ lldb::PluginInitialize (lldb::SBDebugger debugger)
{
corerunCommandInitialize(debugger);
sosCommandInitialize(debugger);
+ setclrpathCommandInitialize(debugger);
+ setsostidCommandInitialize(debugger);
return true;
} \ No newline at end of file
diff --git a/src/ToolBox/SOS/lldbplugin/sosplugin.h b/src/ToolBox/SOS/lldbplugin/sosplugin.h
index 412955c9bb..54a7aee491 100644
--- a/src/ToolBox/SOS/lldbplugin/sosplugin.h
+++ b/src/ToolBox/SOS/lldbplugin/sosplugin.h
@@ -11,8 +11,18 @@
typedef HRESULT (*CommandFunc)(PDEBUG_CLIENT client, const char *args);
+extern char *g_coreclrDirectory;
+extern ULONG g_currentThreadIndex;
+extern ULONG g_currentThreadSystemId;
+
bool
sosCommandInitialize(lldb::SBDebugger debugger);
bool
-corerunCommandInitialize(lldb::SBDebugger debugger); \ No newline at end of file
+setsostidCommandInitialize(lldb::SBDebugger debugger);
+
+bool
+setclrpathCommandInitialize(lldb::SBDebugger debugger);
+
+bool
+corerunCommandInitialize(lldb::SBDebugger debugger);