#include <dlfcn.h>
#include <string>
#include "coreclr_host.h"
+#include "log.h"
#include "utils.h"
static const char* CLR_PATH = "/usr/share/dotnet.tizen/netcoreapp";
static const char* TOOL_PATH = "/home/owner/share/.dotnet/tools";
void DisplayUsage() {
- fprintf(stdout,
+ _SOUT(
"Execute a .NET application or command.\n\n"
"Usage: dotnet [options] [path-to-executable] [arguments]\n"
"Usage: dotnet [command] [arguments]\n\n"
"counters monitor or collect performance counters\n"
"dump capture or analyze a coredump\n"
"gcdump capture a heapdump\n"
- "trace collect or convert a diagnostic event trace\n\n");
+ "trace collect or convert a diagnostic event trace\n"
+ "stack reports the managed stacks\n");
}
int main(int argc, const char* argv[]) {
}
std::string clrFilesPath(CLR_PATH);
- std::string toolDllsPath(TOOL_PATH);
+ std::string toolDllsPath(clrFilesPath + "/SOS");
std::string managedAssemblyPath;
std::string additionalProbingPath;
argc--;
argv++;
} else if (arg == "--additionalprobingpath" && argc > 1) {
- additionalProbingPath = absolutePath(argv[1]);
+ additionalProbingPath = getAbsolutePath(argv[1]);
argc--;
argv++;
} else if (arg == "--globalizationinvariant") {
argc--;
argv++;
} else if (arg.at(0) == '-') {
- fprintf(stderr, "Unknown option %s.\n", argv[0]);
+ _SERR("Unknown option %s.", argv[0]);
DisplayUsage();
return -1;
} else if (isManagedAssembly(arg) || isNativeImage(arg)) {
- if (!isFileExist(arg)) {
- fprintf(stderr, "The specified file does not exist.\n");
+ if (!isFile(arg)) {
+ _SERR("The specified file does not exist.");
return -1;
}
managedAssemblyPath = arg;
} else if (arg == "exec") {
// 'dotnet' and 'dotnet exec' can be alternatively used.
} else if (arg == "tool") {
- fprintf(stderr, "This command is not currently supported.\n");
+ _SERR("This command is not currently supported.");
return -1;
} else {
- managedAssemblyPath = toolDllsPath + "/dotnet-" + arg + ".dll";
-
- if (!isFileExist(managedAssemblyPath)) {
- fprintf(stderr,
+ std::string toolDll = "/dotnet-" + arg + ".dll";
+ std::string searchToolPath1 = toolDllsPath + toolDll;
+ std::string searchToolPath2 = std::string(TOOL_PATH) + toolDll;
+ if (isFile(searchToolPath1)) {
+ managedAssemblyPath = searchToolPath1;
+ } else if (isFile(searchToolPath2)) {
+ managedAssemblyPath = searchToolPath2;
+ } else {
+ _SERR(
"Could not execute because dotnet-%s does not exist.\n"
- "Go to https://developer.samsung.com/tizen to learn how to install tools.\n\n", argv[0]);
+ "Go to https://developer.samsung.com/tizen to learn how to install tools.\n", argv[0]);
return -1;
}
argv++;
}
- std::string currentExeAbsolutePath = absolutePath("/proc/self/exe");
+ std::string currentExeAbsolutePath = getAbsolutePath("/proc/self/exe");
if (currentExeAbsolutePath.empty()) {
- fprintf(stderr, "Failed to get the current executable's absolute path.\n");
+ _SERR("Failed to get the current executable's absolute path.");
return -1;
}
- std::string clrFilesAbsolutePath = absolutePath(clrFilesPath);
+ std::string clrFilesAbsolutePath = getAbsolutePath(clrFilesPath);
if (clrFilesAbsolutePath.empty()) {
- fprintf(stderr, "Failed to resolve the full path to the CLR files.\n");
+ _SERR("Failed to resolve the full path to the CLR files.");
return -1;
}
- std::string managedAssemblyAbsolutePath = absolutePath(managedAssemblyPath);
+ std::string managedAssemblyAbsolutePath = getAbsolutePath(managedAssemblyPath);
if (managedAssemblyAbsolutePath.empty()) {
- fprintf(stderr, "Failed to get the managed assembly's absolute path.\n");
+ _SERR("Failed to get the managed assembly's absolute path.");
return -1;
}
std::string coreclrLibPath(clrFilesAbsolutePath + "/libcoreclr.so");
- std::string appPath = baseName(managedAssemblyAbsolutePath);
+ std::string appPath = getBaseName(managedAssemblyAbsolutePath);
std::string nativeDllSearchDirs(appPath);
nativeDllSearchDirs += ":" + additionalProbingPath;
nativeDllSearchDirs += ":" + clrFilesAbsolutePath;
void* coreclrLib = dlopen(coreclrLibPath.c_str(), RTLD_NOW | RTLD_LOCAL);
if (coreclrLib == nullptr) {
const char* error = dlerror();
- fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error);
+ _SERR("dlopen failed to open the libcoreclr.so with error %s", error);
return -1;
}
coreclr_shutdown_ptr shutdownCoreCLR = (coreclr_shutdown_ptr)dlsym(coreclrLib, "coreclr_shutdown");
if (initializeCoreCLR == nullptr) {
- fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n");
+ _SERR("Function coreclr_initialize not found in the libcoreclr.so");
return -1;
} else if (executeAssembly == nullptr) {
- fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n");
+ _SERR("Function coreclr_execute_assembly not found in the libcoreclr.so");
return -1;
} else if (shutdownCoreCLR == nullptr) {
- fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n");
+ _SERR("Function coreclr_shutdown not found in the libcoreclr.so");
return -1;
}
+ bool ncdbStartupHook = isNCDBStartupHookProvided();
+
const char* propertyKeys[] = {
"TRUSTED_PLATFORM_ASSEMBLIES",
"APP_PATHS",
"APP_NI_PATHS",
"NATIVE_DLL_SEARCH_DIRECTORIES",
"System.Globalization.Invariant",
+ ncdbStartupHook ? "STARTUP_HOOKS" : "" // must be the last one
};
const char* propertyValues[] = {
tpaList.c_str(),
appPath.c_str(),
nativeDllSearchDirs.c_str(),
globalizationInvariant ? "true" : "false",
+ ncdbStartupHook ? getNCDBStartupHook() : "" // must be the last one
};
void* hostHandle;
int st = initializeCoreCLR(
currentExeAbsolutePath.c_str(),
"dotnet",
- sizeof(propertyKeys) / sizeof(propertyKeys[0]),
+ sizeof(propertyKeys) / sizeof(propertyKeys[0]) - (ncdbStartupHook ? 0 : 1),
propertyKeys,
propertyValues,
&hostHandle,
&domainId);
if (st < 0) {
- fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st);
+ _SERR("coreclr_initialize failed - status: 0x%08x", st);
return -1;
}
(unsigned int*)&exitCode);
if (st < 0) {
- fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st);
+ _SERR("coreclr_execute_assembly failed - status: 0x%08x", st);
exitCode = -1;
}
st = shutdownCoreCLR(hostHandle, domainId);
if (st < 0) {
- fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st);
+ _SERR("coreclr_shutdown failed - status: 0x%08x", st);
return -1;
}