diff options
author | Greg Clayton <gclayton@fb.com> | 2020-02-21 15:21:07 -0800 |
---|---|---|
committer | Greg Clayton <gclayton@fb.com> | 2020-02-24 14:17:43 -0800 |
commit | df8dda67ed03f7d7ba3d9475556ab01946386852 (patch) | |
tree | 46c1e32204fca2f2cc799dcdd74586fb95903d4a /llvm/lib/Support/DataExtractor.cpp | |
parent | 7f9f027c62623bff79730cd30d1a8a534e2ddb06 (diff) | |
download | llvm-df8dda67ed03f7d7ba3d9475556ab01946386852.zip llvm-df8dda67ed03f7d7ba3d9475556ab01946386852.tar.gz llvm-df8dda67ed03f7d7ba3d9475556ab01946386852.tar.bz2 |
Add methods to data extractor for extracting bytes and fixed length C strings.
Summary:
These modificaitons will be used in D74883.
Fixed length C strings can have trailing NULLs or sometimes spaces (BSD archive files), so the fixed length C string defaults to stripping trailing NULLs, but can have the arguments specify to remove one or more kinds of spaces if needed. This is used to extract fixed length C strings from ELF NOTEs in D74883.
Reviewers: labath, dblaikie, aprantl
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74991
Diffstat (limited to 'llvm/lib/Support/DataExtractor.cpp')
-rw-r--r-- | llvm/lib/Support/DataExtractor.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp index a98297c..3d19b4d 100644 --- a/llvm/lib/Support/DataExtractor.cpp +++ b/llvm/lib/Support/DataExtractor.cpp @@ -171,6 +171,21 @@ StringRef DataExtractor::getCStrRef(uint64_t *offset_ptr) const { return StringRef(); } +StringRef DataExtractor::getFixedLengthString(uint64_t *OffsetPtr, + uint64_t Length, + StringRef TrimChars) const { + StringRef Bytes(getBytes(OffsetPtr, Length)); + return Bytes.trim(TrimChars); +} + +StringRef DataExtractor::getBytes(uint64_t *OffsetPtr, uint64_t Length) const { + if (!isValidOffsetForDataOfSize(*OffsetPtr, Length)) + return StringRef(); + StringRef Result = Data.substr(*OffsetPtr, Length); + *OffsetPtr += Length; + return Result; +} + uint64_t DataExtractor::getULEB128(uint64_t *offset_ptr, llvm::Error *Err) const { assert(*offset_ptr <= Data.size()); |