if (docPath == fileName)
{
MemoryStream ms = GetEmbeddedSource(mdReader, handle, out docSize);
+
+ // PDB loaded, but don't contain source file lines.
+ // This is not an error, but also no data to return.
+ if (docSize == 0)
+ return RetCode.OK;
+
data = Marshal.AllocCoTaskMem(docSize);
Marshal.Copy(ms.ToArray(), 0, data, docSize);
length = docSize;
{
for (int i = 0; i < lines; i++, line++)
{
- char* toPrint = m_sources->getLine(m_sourcePath, line);
+ const char* errMessage = nullptr;
+ char* toPrint = m_sources->getLine(m_sourcePath, line, &errMessage);
+ if (errMessage)
+ {
+ printf("Source code file: %s\n%s\n", m_sourcePath.c_str(), errMessage);
+ }
if (toPrint)
{
if(line == m_stoppedAt)
}
}
- char* SourceStorage::getLine(std::string& file, int linenum)
+ char* SourceStorage::getLine(std::string& file, int linenum, const char **errMessage)
{
if(files.empty() || files.front()->filePath != file)
{
if (notFound)
{
// file is not in the list -- try to load it from pdb
- if (loadFile(file) != S_OK)
+ if (loadFile(file, errMessage) != S_OK)
return NULL;
}
}
return NULL;
}
- HRESULT SourceStorage::loadFile(std::string& file)
+ HRESULT SourceStorage::loadFile(std::string& file, const char **errMessage)
{
char* fileBuff = NULL;
int fileLen = 0;
HRESULT Status = S_OK;
- IfFailRet(m_dbg->GetSourceFile(file, &fileBuff, &fileLen));
+ if (FAILED(Status = m_dbg->GetSourceFile(file, &fileBuff, &fileLen)))
+ {
+ *errMessage = "Debug information (PDB file) cannot be opened. Check that PDB file exists and is correct.";
+ return Status;
+ }
+ if (fileLen == 0)
+ {
+ *errMessage = "Debug information (PDB file) doesn't contain source code. Make sure csproj file has <EmbedAllSources>true</EmbedAllSources> line.";
+ return E_FAIL;
+ }
+
SourceFile *sf = new SourceFile();
sf->filePath = file;
sf->size = fileLen;
int totalLen;
private:
- HRESULT loadFile(std::string& file);
+ HRESULT loadFile(std::string& file, const char **errMessage);
public:
SourceStorage(IDebugger* d)
}
~SourceStorage();
- char* getLine(std::string& file, int linenum);
+ char* getLine(std::string& file, int linenum, const char **errMessage);
}; // class sourcestorage
} // namespace
\ No newline at end of file