#ifndef LLVM_DEBUGINFO_PDB_DIA_DIAERROR_H
#define LLVM_DEBUGINFO_PDB_DIA_DIAERROR_H
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
-#include <string>
-
namespace llvm {
namespace pdb {
enum class dia_error_code {
public:
static char ID;
DIAError(dia_error_code C);
- DIAError(const std::string &Context);
- DIAError(dia_error_code C, const std::string &Context);
+ DIAError(StringRef Context);
+ DIAError(dia_error_code C, StringRef Context);
void log(raw_ostream &OS) const override;
- const std::string &getErrorMessage() const;
+ StringRef getErrorMessage() const;
std::error_code convertToErrorCode() const override;
private:
#ifndef LLVM_DEBUGINFO_PDB_ERROR_H
#define LLVM_DEBUGINFO_PDB_ERROR_H
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
namespace llvm {
public:
static char ID;
GenericError(generic_error_code C);
- GenericError(const std::string &Context);
- GenericError(generic_error_code C, const std::string &Context);
+ GenericError(StringRef Context);
+ GenericError(generic_error_code C, StringRef Context);
void log(raw_ostream &OS) const override;
- const std::string &getErrorMessage() const;
+ StringRef getErrorMessage() const;
std::error_code convertToErrorCode() const override;
private:
DIAError::DIAError(dia_error_code C) : DIAError(C, "") {}
-DIAError::DIAError(const std::string &Context)
+DIAError::DIAError(StringRef Context)
: DIAError(dia_error_code::unspecified, Context) {}
-DIAError::DIAError(dia_error_code C, const std::string &Context) : Code(C) {
+DIAError::DIAError(dia_error_code C, StringRef Context) : Code(C) {
ErrMsg = "DIA Error: ";
std::error_code EC = convertToErrorCode();
- if (Code != dia_error_code::unspecified)
- ErrMsg += EC.message() + " ";
+ ErrMsg += EC.message() + " ";
if (!Context.empty())
ErrMsg += Context;
}
void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-const std::string &DIAError::getErrorMessage() const { return ErrMsg; }
+StringRef DIAError::getErrorMessage() const { return ErrMsg; }
std::error_code DIAError::convertToErrorCode() const {
return std::error_code(static_cast<int>(Code), *Category);
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::pdb;
-static Error ErrorFromHResult(HRESULT Result) {
+static Error ErrorFromHResult(HRESULT Result, StringRef Context) {
switch (Result) {
case E_PDB_NOT_FOUND:
- return make_error<GenericError>(generic_error_code::invalid_path);
+ return make_error<GenericError>(generic_error_code::invalid_path, Context);
case E_PDB_FORMAT:
- return make_error<DIAError>(dia_error_code::invalid_file_format);
+ return make_error<DIAError>(dia_error_code::invalid_file_format, Context);
case E_INVALIDARG:
- return make_error<DIAError>(dia_error_code::invalid_parameter);
+ return make_error<DIAError>(dia_error_code::invalid_parameter, Context);
case E_UNEXPECTED:
- return make_error<DIAError>(dia_error_code::already_loaded);
+ return make_error<DIAError>(dia_error_code::already_loaded, Context);
case E_PDB_INVALID_SIG:
case E_PDB_INVALID_AGE:
- return make_error<DIAError>(dia_error_code::debug_info_mismatch);
- default:
- return make_error<DIAError>(dia_error_code::unspecified);
+ return make_error<DIAError>(dia_error_code::debug_info_mismatch, Context);
+ default: {
+ std::string S;
+ raw_string_ostream OS(S);
+ OS << "HRESULT: " << format_hex(static_cast<DWORD>(Result), 10, true)
+ << ": " << Context;
+ return make_error<DIAError>(dia_error_code::unspecified, OS.str());
+ }
}
}
HRESULT HR;
if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
reinterpret_cast<LPVOID *>(&DiaDataSource))))
- return ErrorFromHResult(HR);
+ return ErrorFromHResult(HR, "Calling NoRegCoCreate");
return Error::success();
#endif
}
const wchar_t *Path16Str = reinterpret_cast<const wchar_t*>(Path16.data());
HRESULT HR;
if (FAILED(HR = DiaDataSource->loadDataFromPdb(Path16Str)))
- return ErrorFromHResult(HR);
+ return ErrorFromHResult(HR, "Calling loadDataFromPdb");
if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
- return ErrorFromHResult(HR);
+ return ErrorFromHResult(HR, "Calling openSession");
Session.reset(new DIASession(DiaSession));
return Error::success();
const wchar_t *Path16Str = reinterpret_cast<const wchar_t *>(Path16.data());
HRESULT HR;
if (FAILED(HR = DiaDataSource->loadDataForExe(Path16Str, nullptr, nullptr)))
- return ErrorFromHResult(HR);
+ return ErrorFromHResult(HR, "Calling loadDataForExe");
if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
- return ErrorFromHResult(HR);
+ return ErrorFromHResult(HR, "Calling openSession");
Session.reset(new DIASession(DiaSession));
return Error::success();
GenericError::GenericError(generic_error_code C) : GenericError(C, "") {}
-GenericError::GenericError(const std::string &Context)
+GenericError::GenericError(StringRef Context)
: GenericError(generic_error_code::unspecified, Context) {}
-GenericError::GenericError(generic_error_code C, const std::string &Context)
- : Code(C) {
+GenericError::GenericError(generic_error_code C, StringRef Context) : Code(C) {
ErrMsg = "PDB Error: ";
std::error_code EC = convertToErrorCode();
if (Code != generic_error_code::unspecified)
void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-const std::string &GenericError::getErrorMessage() const { return ErrMsg; }
+StringRef GenericError::getErrorMessage() const { return ErrMsg; }
std::error_code GenericError::convertToErrorCode() const {
return std::error_code(static_cast<int>(Code), *Category);