-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[PDB][NativeSession] Use better error code for invalid format #167885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-platform-windows Author: Mirko (MuellerMP) ChangesReplaces the default "Success" std::error_code with a more meaningful one if Full diff: https://github.com/llvm/llvm-project/pull/167885.diff 1 Files Affected:
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
index 8967a2eb1749e..982153beb32b4 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
@@ -99,9 +99,12 @@ loadPdbFile(StringRef PdbPath, std::unique_ptr<BumpPtrAllocator> &Allocator) {
PdbPath = Buffer->getBufferIdentifier();
file_magic Magic;
auto EC = identify_magic(PdbPath, Magic);
- if (EC || Magic != file_magic::pdb)
+ if (EC)
return make_error<RawError>(EC);
+ if (Magic != file_magic::pdb)
+ return make_error<RawError>(raw_error_code::invalid_format);
+
auto Stream = std::make_unique<MemoryBufferByteStream>(
std::move(Buffer), llvm::endianness::little);
@@ -154,9 +157,12 @@ Error NativeSession::createFromExe(StringRef ExePath,
file_magic Magic;
auto EC = identify_magic(PdbPath.get(), Magic);
- if (EC || Magic != file_magic::pdb)
+ if (EC)
return make_error<RawError>(EC);
+ if (Magic != file_magic::pdb)
+ return make_error<RawError>(raw_error_code::invalid_format);
+
auto Allocator = std::make_unique<BumpPtrAllocator>();
auto File = loadPdbFile(PdbPath.get(), Allocator);
if (!File)
|
|
This fixes the case where |
Yes, please add a test. |
08eae4d to
c9790ff
Compare
done -> also improved the error message and reduced the original code duplication a bit |
c4566d9 to
24debcb
Compare
|
Hey @aganea - would you perhaps have time to review this? |
aganea
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a nit:
|
|
||
| static Error validatePdbMagic(StringRef PdbPath) { | ||
| file_magic Magic; | ||
| auto EC = identify_magic(PdbPath, Magic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write if (auto EC = ... ) to make it shorter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks - made it shorter
sorry for the amount of commit updates - i messed up my local git config
81d4e19 to
a00f0be
Compare
Replaces the default "Success" std::error_code with a more meaningful one.
a00f0be to
712b6fd
Compare
|
@aganea thanks for the review! |
…67885) Replaces the default "Success" std::error_code with a more meaningful one if `Magic != file_magic::pdb`.
Replaces the default "Success" std::error_code with a more meaningful one if
Magic != file_magic::pdb.