diff options
author | Zachary Turner <zturner@google.com> | 2017-06-23 19:54:44 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-06-23 19:54:44 +0000 |
commit | 6b124f29e727da3f3d27112b7ded82b404a68b2f (patch) | |
tree | 114ef7bf288195112e97ded242f269477dd82eb4 /llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp | |
parent | 717021772bc8b4b1ee01c340daa0a718aa0059fb (diff) | |
download | bcm5719-llvm-6b124f29e727da3f3d27112b7ded82b404a68b2f.tar.gz bcm5719-llvm-6b124f29e727da3f3d27112b7ded82b404a68b2f.zip |
[llvm-pdbutil] Add the ability to dump raw bytes from the file.
Normally we can only make sense of the content of a PDB in terms
of streams and blocks, but in some cases it may be useful to dump
bytes at a specific absolute file offset. For example, if you
know that some interesting data is at a particular location and
you want to see some surrounding data.
llvm-svn: 306146
Diffstat (limited to 'llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp')
-rw-r--r-- | llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp b/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp index 123c55d2072..9761987f076 100644 --- a/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp +++ b/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp @@ -96,6 +96,22 @@ Error BytesOutputStyle::dump() { P.NewLine(); } + if (opts::bytes::DumpByteRange.hasValue()) { + auto &R = *opts::bytes::DumpByteRange; + uint32_t Max = R.Max.getValueOr(File.getFileSize()); + + if (Max < R.Min) + return make_error<StringError>("Invalid byte range specified. Max < Min", + inconvertibleErrorCode()); + if (Max >= File.getFileSize()) + return make_error<StringError>( + "Invalid byte range specified. Requested byte larger than file size", + inconvertibleErrorCode()); + + dumpByteRanges(R.Min, Max); + P.NewLine(); + } + if (!opts::bytes::DumpStreamData.empty()) { dumpStreamBytes(); P.NewLine(); @@ -122,6 +138,21 @@ void BytesOutputStyle::dumpBlockRanges(uint32_t Min, uint32_t Max) { } } +void BytesOutputStyle::dumpByteRanges(uint32_t Min, uint32_t Max) { + printHeader(P, "MSF Bytes"); + + AutoIndent Indent(P); + + BinaryStreamReader Reader(File.getMsfBuffer()); + ArrayRef<uint8_t> Data; + consumeError(Reader.skip(Min)); + uint32_t Size = Max - Min + 1; + auto EC = Reader.readBytes(Data, Size); + assert(!EC); + consumeError(std::move(EC)); + P.formatBinary("Bytes", Data, Min); +} + void BytesOutputStyle::dumpStreamBytes() { if (StreamPurposes.empty()) discoverStreamPurposes(File, StreamPurposes); |