// Distributed under the MIT License.
// See the LICENSE file in the project root for more information.
+#include <string>
+#include <locale>
+#include <codecvt>
+
+static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
+
static inline std::string to_utf8(const WCHAR *wstr, int len = -1)
{
if (len == -1)
- len = _wcslen(wstr);
+ return convert.to_bytes(wstr);
if (len == 0)
return std::string();
- int size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, len, NULL, 0, NULL, NULL);
- std::string strTo(size_needed, 0);
- WideCharToMultiByte(CP_UTF8, 0, wstr, len, &strTo[0], size_needed, NULL, NULL);
- return strTo;
+ return convert.to_bytes(wstr, wstr + len);
}
#include <list>
#include <iomanip>
+#include "cputil.h"
+
#include "manageddebugger.h"
#include "typeprinter.h"
#include "valueprint.h"
static mdTypeDef GetTypeTokenForName(IMetaDataImport *pMD, mdTypeDef tkEnclosingClass, const std::string &name)
{
- HRESULT Status;
-
- std::unique_ptr<WCHAR[]> wname(new WCHAR[name.size() + 1]);
-
- MultiByteToWideChar(CP_UTF8, 0, name.c_str(), name.size() + 1, &wname[0], name.size() + 1);
-
mdTypeDef typeToken = mdTypeDefNil;
- pMD->FindTypeDefByName(&wname[0], tkEnclosingClass, &typeToken);
+ pMD->FindTypeDefByName(convert.from_bytes(name).c_str(), tkEnclosingClass, &typeToken);
return typeToken;
}
ss << " \"" << EscapeShellArg(arg) << "\"";
}
std::string cmdString = ss.str();
- std::unique_ptr<WCHAR[]> cmd(new WCHAR[cmdString.size() + 1]);
-
- MultiByteToWideChar(CP_UTF8, 0, cmdString.c_str(), cmdString.size() + 1, &cmd[0], cmdString.size() + 1);
m_startupReady = false;
m_clrPath.clear();
LPVOID lpEnvironment = nullptr; // as current
LPCWSTR lpCurrentDirectory = nullptr; // as current
HANDLE resumeHandle;
- IfFailRet(CreateProcessForLaunch(&cmd[0], bSuspendProcess, lpEnvironment, lpCurrentDirectory, &m_processId, &resumeHandle));
+ IfFailRet(CreateProcessForLaunch(const_cast<LPWSTR>(convert.from_bytes(cmdString).c_str()), bSuspendProcess, lpEnvironment, lpCurrentDirectory, &m_processId, &resumeHandle));
IfFailRet(RegisterForRuntimeStartup(m_processId, ManagedDebugger::StartupCallback, this, &m_unregisterToken));
if (m_clrPath.empty())
return E_INVALIDARG; // Unable to find libcoreclr.so
- WCHAR szModuleName[MAX_LONGPATH];
- MultiByteToWideChar(CP_UTF8, 0, m_clrPath.c_str(), m_clrPath.size() + 1, szModuleName, MAX_LONGPATH);
-
WCHAR pBuffer[100];
DWORD dwLength;
IfFailRet(CreateVersionStringFromModule(
pid,
- szModuleName,
+ convert.from_bytes(m_clrPath).c_str(),
pBuffer,
_countof(pBuffer),
&dwLength));
{
HRESULT Status;
- WCHAR nameBuffer[MAX_LONGPATH];
-
- Status = MultiByteToWideChar(CP_UTF8, 0, filename.c_str(), filename.size() + 1, nameBuffer, MAX_LONGPATH);
-
std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
for (auto &info_pair : m_modulesInfo)
CORDB_ADDRESS modAddress;
IfFailRet(mdInfo.module->GetBaseAddress(&modAddress));
- if (FAILED(mdInfo.symbols->ResolveSequencePoint(nameBuffer, linenum, modAddress, &methodToken, &ilOffset)))
+ if (FAILED(mdInfo.symbols->ResolveSequencePoint(filename.c_str(), linenum, modAddress, &methodToken, &ilOffset)))
continue;
WCHAR wFilename[MAX_LONGPATH];
{
HRESULT Status;
- WCHAR nameBuffer[MAX_LONGPATH];
-
- Status = MultiByteToWideChar(CP_UTF8, 0, filename.c_str(), filename.size() + 1, nameBuffer, MAX_LONGPATH);
-
CORDB_ADDRESS modAddress;
IfFailRet(pModule->GetBaseAddress(&modAddress));
return E_FAIL;
}
- IfFailRet(info_pair->second.symbols->ResolveSequencePoint(nameBuffer, linenum, modAddress, &methodToken, &ilOffset));
+ IfFailRet(info_pair->second.symbols->ResolveSequencePoint(filename.c_str(), linenum, modAddress, &methodToken, &ilOffset));
WCHAR wFilename[MAX_LONGPATH];
ULONG resolvedLinenum;
#include <string>
#include <vector>
+#include "cputil.h"
#include "symbolreader.h"
#include "platform.h"
}
// The module name needs to be null for in-memory PE's.
- ArrayHolder<char> szModuleName = nullptr;
+ const char *szModuleName = nullptr;
+ std::string moduleName;
if (!isInMemory && pModuleName != nullptr)
{
- szModuleName = new char[MAX_LONGPATH];
- if (WideCharToMultiByte(CP_ACP, 0, pModuleName, (int)(_wcslen(pModuleName) + 1), szModuleName, MAX_LONGPATH, NULL, NULL) == 0)
- {
- return E_FAIL;
- }
+ moduleName = convert.to_bytes(pModuleName);
+ szModuleName = moduleName.c_str();
}
m_symbolReaderHandle = loadSymbolsForModuleDelegate(szModuleName, isFileLayout, peAddress,
attemptedSymbolReaderPreparation = true;
- WCHAR wszCoreClrPath[MAX_LONGPATH];
- MultiByteToWideChar(CP_UTF8, 0, coreClrPath.c_str(), coreClrPath.size() + 1, wszCoreClrPath, MAX_LONGPATH);
-
std::string clrDir = coreClrPath.substr(0, coreClrPath.rfind(DIRECTORY_SEPARATOR_STR_A));
HRESULT Status;
- HMODULE coreclrLib = LoadLibraryW(wszCoreClrPath);
+ HMODULE coreclrLib = LoadLibraryW(convert.from_bytes(coreClrPath).c_str());
if (coreclrLib == nullptr)
{
fprintf(stderr, "Error: Failed to load coreclr\n");
return Status;
}
-HRESULT SymbolReader::ResolveSequencePoint(WCHAR* pFilename, ULONG32 lineNumber, TADDR mod, mdMethodDef* pToken, ULONG32* pIlOffset)
+HRESULT SymbolReader::ResolveSequencePoint(const char *filename, ULONG32 lineNumber, TADDR mod, mdMethodDef* pToken, ULONG32* pIlOffset)
{
HRESULT Status = S_OK;
{
_ASSERTE(resolveSequencePointDelegate != nullptr);
- char szName[mdNameLen];
- if (WideCharToMultiByte(CP_ACP, 0, pFilename, (int)(_wcslen(pFilename) + 1), szName, mdNameLen, NULL, NULL) == 0)
- {
- return E_FAIL;
- }
- if (resolveSequencePointDelegate(m_symbolReaderHandle, szName, lineNumber, pToken, pIlOffset) == FALSE)
+ if (resolveSequencePointDelegate(m_symbolReaderHandle, filename, lineNumber, pToken, pIlOffset) == FALSE)
{
return E_FAIL;
}
HRESULT LoadSymbols(IMetaDataImport* pMD, ICorDebugModule* pModule);
HRESULT GetLineByILOffset(mdMethodDef MethodToken, ULONG64 IlOffset, ULONG *pLinenum, WCHAR* pwszFileName, ULONG cchFileName);
HRESULT GetNamedLocalVariableAndScope(ICorDebugILFrame * pILFrame, mdMethodDef methodToken, ULONG localIndex, WCHAR* paramName, ULONG paramNameLen, ICorDebugValue **ppValue, ULONG32* pIlStart, ULONG32* pIlEnd);
- HRESULT ResolveSequencePoint(WCHAR* pFilename, ULONG32 lineNumber, TADDR mod, mdMethodDef* pToken, ULONG32* pIlOffset);
+ HRESULT ResolveSequencePoint(const char *filename, ULONG32 lineNumber, TADDR mod, mdMethodDef* pToken, ULONG32* pIlOffset);
HRESULT GetStepRangesFromIP(ULONG64 ip, mdMethodDef MethodToken, ULONG32 *ilStartOffset, ULONG32 *ilEndOffset);
HRESULT GetSequencePoints(mdMethodDef methodToken, std::vector<SequencePoint> &points);
};
{
ULONG paramNameLen = 0;
mdParamDef paramDef;
- WCHAR wParamName[mdNameLen] = W("\0");
+ std::string paramName;
bool thisParam = i == 0 && (methodAttr & mdStatic) == 0;
if (thisParam)
- swprintf_s(wParamName, mdNameLen, W("this\0"));
+ paramName = "this";
else
{
int idx = ((methodAttr & mdStatic) == 0)? i : (i + 1);
if(SUCCEEDED(pMD->GetParamForMethodIndex(methodDef, idx, ¶mDef)))
+ {
+ WCHAR wParamName[mdNameLen] = W("\0");
pMD->GetParamProps(paramDef, NULL, NULL, wParamName, mdNameLen, ¶mNameLen, NULL, NULL, NULL, NULL);
+ paramName = convert.to_bytes(wParamName);
+ }
+ }
+ if(paramName.empty())
+ {
+ std::stringstream ss;
+ ss << "param_" << i;
+ paramName = ss.str();
}
- if(_wcslen(wParamName) == 0)
- swprintf_s(wParamName, mdNameLen, W("param_%d\0"), i);
ToRelease<ICorDebugValue> pValue;
ULONG cArgsFetched;
if (Status == S_FALSE)
break;
- std::string paramName = to_utf8(wParamName/*, paramNameLen*/);
-
if (thisParam)
{
IfFailRet(HandleSpecialThisParam(pValue, pILFrame, locals, cb));
}
else
{
- WCHAR msgBuffer[1024] = {0};
- HRESULT msgStatus = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, Status, 0, msgBuffer, 1024, nullptr);
std::stringstream ss;
ss << "Failed command '" << command << "' : "
- << "0x" << std::setw(8) << std::setfill('0') << std::hex << Status << " " << to_utf8(msgBuffer);
+ << "0x" << std::setw(8) << std::setfill('0') << std::hex << Status;
response["success"] = false;
response["message"] = ss.str();
}