Add runtineOnly option to LoadNativeSymbols to use to get DAC/DBI module name.
Use LoadNativeSymbols(true) to get the DAC/DBI modules when don't exist locally.
/// </summary>
/// <param name="moduleFileName">module file name</param>
/// <param name="symbolFileName">symbol file name and path</param>
- internal delegate void SymbolFileCallback(
- IntPtr parameter,
- [MarshalAs(UnmanagedType.LPStr)] string moduleFileName,
- [MarshalAs(UnmanagedType.LPStr)] string symbolFileName);
+ public delegate void SymbolFileCallback(IntPtr parameter, [MarshalAs(UnmanagedType.LPStr)] string moduleFileName, [MarshalAs(UnmanagedType.LPStr)] string symbolFileName);
static SymbolStore s_symbolStore = null;
static bool s_symbolCacheAdded = false;
/// </summary>
/// <param name="callback">called back for each symbol file loaded</param>
/// <param name="parameter">callback parameter</param>
- /// <param name="moduleDirectory">module path</param>
- /// <param name="moduleFileName">module file name</param>
+ /// <param name="moduleFilePath">module path</param>
/// <param name="address">module base address</param>
/// <param name="size">module size</param>
/// <param name="readMemory">read memory callback delegate</param>
- internal static void LoadNativeSymbols(SymbolFileCallback callback, IntPtr parameter, string tempDirectory, string moduleDirectory, string moduleFileName,
- ulong address, int size, ReadMemoryDelegate readMemory)
+ public static void LoadNativeSymbols(SymbolFileCallback callback, IntPtr parameter, string tempDirectory, string moduleFilePath, ulong address, int size, ReadMemoryDelegate readMemory)
{
if (s_symbolStore != null)
{
Debug.Assert(s_tracer != null);
- string path = Path.Combine(moduleDirectory, moduleFileName);
Stream stream = new TargetStream(address, size, readMemory);
KeyTypeFlags flags = KeyTypeFlags.SymbolKey | KeyTypeFlags.ClrKeys;
KeyGenerator generator = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var elfFile = new ELFFile(new StreamAddressSpace(stream), 0, true);
- generator = new ELFFileKeyGenerator(s_tracer, elfFile, path);
+ generator = new ELFFileKeyGenerator(s_tracer, elfFile, moduleFilePath);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var machOFile = new MachOFile(new StreamAddressSpace(stream), 0, true);
- generator = new MachOFileKeyGenerator(s_tracer, machOFile, path);
+ generator = new MachOFileKeyGenerator(s_tracer, machOFile, moduleFilePath);
}
else
{
IEnumerable<SymbolStoreKey> keys = generator.GetKeys(flags);
foreach (SymbolStoreKey key in keys)
{
- string symbolFileName = Path.GetFileName(key.FullPathName);
+ string moduleFileName = Path.GetFileName(key.FullPathName);
s_tracer.Verbose("{0} {1}", key.FullPathName, key.Index);
// Don't download the sos binaries that come with the runtime
- if (symbolFileName != "SOS.NETCore.dll" && !symbolFileName.StartsWith("libsos."))
+ if (moduleFileName != "SOS.NETCore.dll" && !moduleFileName.StartsWith("libsos."))
{
using (SymbolStoreFile file = GetSymbolStoreFile(key))
{
{
try
{
- string downloadFileName = file.FileName;
+ string downloadFilePath = file.FileName;
// If the downloaded doesn't already exists on disk in the cache, then write it to a temporary location.
- if (!File.Exists(downloadFileName))
+ if (!File.Exists(downloadFilePath))
{
- downloadFileName = Path.Combine(tempDirectory, symbolFileName);
+ downloadFilePath = Path.Combine(tempDirectory, moduleFileName);
- using (Stream destinationStream = File.OpenWrite(downloadFileName)) {
+ using (Stream destinationStream = File.OpenWrite(downloadFilePath)) {
file.Stream.CopyTo(destinationStream);
}
s_tracer.WriteLine("Downloaded symbol file {0}", key.FullPathName);
}
- s_tracer.Information("{0}: {1}", symbolFileName, downloadFileName);
- callback(parameter, symbolFileName, downloadFileName);
+ s_tracer.Information("{0}: {1}", moduleFileName, downloadFilePath);
+ callback(parameter, moduleFileName, downloadFilePath);
}
catch (Exception ex) when (ex is UnauthorizedAccessException || ex is DirectoryNotFoundException)
{
}
catch (Exception ex) when (ex is BadInputFormatException || ex is InvalidVirtualAddressException)
{
- s_tracer.Error("Exception: {0}/{1}: {2:X16}", moduleDirectory, moduleFileName, address);
+ s_tracer.Error("Exception: {0}/{1}: {2:X16}", moduleFilePath, address);
}
}
}
}
if (!GetAbsolutePath(directory, coreClrDirectory))
{
- ExtErr("Error: Failed to get coreclr absolute path\n");
return E_FAIL;
}
#else
strcat_s(tmpPath, MAX_LONGPATH, DIRECTORY_SEPARATOR_STR_A);
}
char pidstr[128];
- sprintf_s(pidstr, _countof(pidstr), "%d", GetCurrentProcessId());
+ sprintf_s(pidstr, _countof(pidstr), "sos%d", GetCurrentProcessId());
strcat_s(tmpPath, MAX_LONGPATH, pidstr);
strcat_s(tmpPath, MAX_LONGPATH, DIRECTORY_SEPARATOR_STR_A);
g_dacFilePath = _strdup(dacModulePath.c_str());
}
}
+
+ if (g_dacFilePath == nullptr)
+ {
+ // Attempt to only load the DAC/DBI modules
+ LoadNativeSymbols(true);
+ }
}
return g_dacFilePath;
}
// if DBI file exists
if (access(dbiModulePath.c_str(), F_OK) == 0)
#endif
+ {
g_dbiFilePath = _strdup(dbiModulePath.c_str());
+ }
+ }
+
+ if (g_dbiFilePath == nullptr)
+ {
+ // Attempt to only load the DAC/DBI modules
+ LoadNativeSymbols(true);
}
}
return g_dbiFilePath;
//
// Symbol downloader callback
//
-static void SymbolFileCallback(void* param, const char* moduleFileName, const char* symbolFileName)
+static void SymbolFileCallback(void* param, const char* moduleFileName, const char* symbolFilePath)
{
if (strcmp(moduleFileName, MAIN_CLR_DLL_NAME_A) == 0) {
return;
}
if (strcmp(moduleFileName, MAKEDLLNAME_A("mscordaccore")) == 0) {
if (g_dacFilePath == nullptr) {
- g_dacFilePath = _strdup(symbolFileName);
+ g_dacFilePath = _strdup(symbolFilePath);
}
return;
}
if (strcmp(moduleFileName, MAKEDLLNAME_A("mscordbi")) == 0) {
if (g_dbiFilePath == nullptr) {
- g_dbiFilePath = _strdup(symbolFileName);
+ g_dbiFilePath = _strdup(symbolFilePath);
}
return;
}
HRESULT Status = g_ExtServices->QueryInterface(__uuidof(ILLDBServices2), (void**)&services2);
if (SUCCEEDED(Status))
{
- services2->AddModuleSymbol(param, symbolFileName);
+ services2->AddModuleSymbol(param, symbolFilePath);
}
}
//
// Enumerate native module callback
//
-static void LoadNativeSymbolsCallback(void* param, const char* moduleDirectory, const char* moduleFileName, ULONG64 moduleAddress, int moduleSize)
+static void LoadNativeSymbolsCallback(void* param, const char* moduleFilePath, ULONG64 moduleAddress, int moduleSize)
{
_ASSERTE(g_hostingInitialized);
_ASSERTE(g_SOSNetCoreCallbacks.LoadNativeSymbolsDelegate != nullptr);
- g_SOSNetCoreCallbacks.LoadNativeSymbolsDelegate(SymbolFileCallback, param, GetTempDirectory(), moduleDirectory, moduleFileName, moduleAddress, moduleSize, ReadMemoryForSymbols);
+ g_SOSNetCoreCallbacks.LoadNativeSymbolsDelegate(SymbolFileCallback, param, GetTempDirectory(), moduleFilePath, moduleAddress, moduleSize, ReadMemoryForSymbols);
}
#endif
* for them. Depends on the lldb callback to enumerate modules. Not
* necessary on dbgeng because it already downloads native symbols.
\**********************************************************************/
-HRESULT LoadNativeSymbols()
+HRESULT LoadNativeSymbols(bool runtimeOnly)
{
HRESULT Status = S_OK;
#ifdef FEATURE_PAL
Status = g_ExtServices->QueryInterface(__uuidof(ILLDBServices2), (void**)&services2);
if (SUCCEEDED(Status))
{
- Status = services2->LoadNativeSymbols(LoadNativeSymbolsCallback);
+ Status = services2->LoadNativeSymbols(runtimeOnly, LoadNativeSymbolsCallback);
}
}
#endif
extern BOOL IsHostingInitialized();
extern HRESULT InitializeHosting();
extern HRESULT InitializeSymbolStore(BOOL logging, BOOL msdl, BOOL symweb, const char* symbolServer, const char* cacheDirectory);
-extern HRESULT LoadNativeSymbols();
+extern HRESULT LoadNativeSymbols(bool runtimeOnly = false);
extern void DisplaySymbolStore();
extern void DisableSymbolStore();
PULONG64 offset) = 0;
};
-typedef void (*PFN_MODULE_LOAD_CALLBACK)(void* param, const char* moduleName, const char* moduleDirectory, ULONG64 moduleAddress, int moduleSize);
+typedef void (*PFN_MODULE_LOAD_CALLBACK)(void* param, const char* moduleFilePath, ULONG64 moduleAddress, int moduleSize);
MIDL_INTERFACE("012F32F0-33BA-4E8E-BC01-037D382D8A5E")
ILLDBServices2: public IUnknown
//----------------------------------------------------------------------------
virtual HRESULT LoadNativeSymbols(
+ bool runtimeOnly,
PFN_MODULE_LOAD_CALLBACK callback) = 0;
virtual HRESULT AddModuleSymbol(
void* param,
- const char* symbolFileName) = 0;
+ const char* symbolFilePath) = 0;
};
#ifdef __cplusplus
// ILLDBServices2
//----------------------------------------------------------------------------
+void
+LLDBServices::LoadNativeSymbols(
+ lldb::SBTarget target,
+ lldb::SBModule module,
+ PFN_MODULE_LOAD_CALLBACK callback)
+{
+ if (module.IsValid())
+ {
+ const char* directory = nullptr;
+ const char* filename = nullptr;
+
+ lldb::SBFileSpec symbolFileSpec = module.GetSymbolFileSpec();
+ if (symbolFileSpec.IsValid())
+ {
+ directory = symbolFileSpec.GetDirectory();
+ filename = symbolFileSpec.GetFilename();
+ }
+ else {
+ lldb::SBFileSpec fileSpec = module.GetFileSpec();
+ if (fileSpec.IsValid())
+ {
+ directory = fileSpec.GetDirectory();
+ filename = fileSpec.GetFilename();
+ }
+ }
+
+ if (directory != nullptr && filename != nullptr)
+ {
+ ULONG64 moduleAddress = GetModuleBase(target, module);
+ int moduleSize = INT32_MAX;
+ if (moduleAddress != UINT64_MAX)
+ {
+ std::string path(directory);
+ path.append("/");
+ path.append(filename);
+
+ callback(&module, path.c_str(), moduleAddress, moduleSize);
+ }
+ }
+ }
+}
+
HRESULT
LLDBServices::LoadNativeSymbols(
+ bool runtimeOnly,
PFN_MODULE_LOAD_CALLBACK callback)
{
- uint32_t numTargets = m_debugger.GetNumTargets();
- for (int ti = 0; ti < numTargets; ti++)
+ if (runtimeOnly)
{
- lldb::SBTarget target = m_debugger.GetTargetAtIndex(ti);
+ lldb::SBTarget target = m_debugger.GetSelectedTarget();
if (target.IsValid())
{
- uint32_t numModules = target.GetNumModules();
- for (int mi = 0; mi < numModules; mi++)
+ const char *coreclrModule = MAKEDLLNAME_A("coreclr");
+ lldb::SBFileSpec fileSpec;
+ fileSpec.SetFilename(coreclrModule);
+
+ lldb::SBModule module = target.FindModule(fileSpec);
+ LoadNativeSymbols(target, module, callback);
+ }
+ }
+ else
+ {
+ uint32_t numTargets = m_debugger.GetNumTargets();
+ for (int ti = 0; ti < numTargets; ti++)
+ {
+ lldb::SBTarget target = m_debugger.GetTargetAtIndex(ti);
+ if (target.IsValid())
{
- lldb::SBModule module = target.GetModuleAtIndex(mi);
- if (module.IsValid())
+ uint32_t numModules = target.GetNumModules();
+ for (int mi = 0; mi < numModules; mi++)
{
- const char* directory = nullptr;
- const char* filename = nullptr;
-
- lldb::SBFileSpec symbolFileSpec = module.GetSymbolFileSpec();
- if (symbolFileSpec.IsValid())
- {
- directory = symbolFileSpec.GetDirectory();
- filename = symbolFileSpec.GetFilename();
- }
- else {
- lldb::SBFileSpec fileSpec = module.GetFileSpec();
- if (fileSpec.IsValid())
- {
- directory = fileSpec.GetDirectory();
- filename = fileSpec.GetFilename();
- }
- }
-
- if (directory != nullptr && filename != nullptr)
- {
- ULONG64 moduleAddress = GetModuleBase(target, module);
- int moduleSize = INT32_MAX;
- if (moduleAddress != UINT64_MAX)
- {
- callback(&module, directory, filename, moduleAddress, moduleSize);
- }
- }
+ lldb::SBModule module = target.GetModuleAtIndex(mi);
+ LoadNativeSymbols(target, module, callback);
}
}
}
//----------------------------------------------------------------------------
HRESULT LoadNativeSymbols(
+ bool runtimeOnly,
PFN_MODULE_LOAD_CALLBACK callback);
HRESULT AddModuleSymbol(
PCSTR GetModuleDirectory(
PCSTR name);
+ void LoadNativeSymbols(
+ lldb::SBTarget target,
+ lldb::SBModule module,
+ PFN_MODULE_LOAD_CALLBACK callback);
PCSTR GetPluginModuleDirectory();
-
- int StartListenerThread();
};