Skip to content

Commit 72d6a16

Browse files
committed
Impliment good feedback on making code more concise, and fix callback to pad 0's if datasize exceeds content
1 parent 63ca9e1 commit 72d6a16

File tree

6 files changed

+28
-52
lines changed

6 files changed

+28
-52
lines changed

llvm/include/llvm/Object/Minidump.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ class MinidumpFile : public Binary {
189189
Storage = Storage.drop_front(Descriptor.DataSize);
190190
Descriptors = Descriptors.drop_front();
191191

192-
if (Descriptors.empty())
193-
IsEnd = true;
194192
return Error::success();
195193
}
196194

llvm/lib/Object/Minidump.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,21 @@ MinidumpFile::create(MemoryBufferRef Source) {
156156
new MinidumpFile(Source, Hdr, *ExpectedStreams, std::move(StreamMap)));
157157
}
158158

159-
static iterator_range<MinidumpFile::FallibleMemory64Iterator>
160-
makeEmptyRange(Error &Err) {
161-
return make_range(
162-
llvm::object::MinidumpFile::FallibleMemory64Iterator::itr(
163-
llvm::object::MinidumpFile::Memory64Iterator::end(), Err),
164-
llvm::object::MinidumpFile::FallibleMemory64Iterator::end(
165-
llvm::object::MinidumpFile::Memory64Iterator::end()));
166-
}
167-
168159
iterator_range<MinidumpFile::FallibleMemory64Iterator>
169160
MinidumpFile::getMemory64List(Error &Err) const {
161+
ErrorAsOutParameter ErrAsOutParam(&Err);
162+
auto end = FallibleMemory64Iterator::end(Memory64Iterator::end());
170163
Expected<minidump::Memory64ListHeader> ListHeader = getMemoryList64Header();
171164
if (!ListHeader) {
172165
Err = ListHeader.takeError();
173-
return makeEmptyRange(Err);
166+
return make_range(end, end);
174167
}
175168

176169
std::optional<ArrayRef<uint8_t>> Stream =
177170
getRawStream(StreamType::Memory64List);
178171
if (!Stream) {
179172
Err = createError("No such stream");
180-
return makeEmptyRange(Err);
173+
return make_range(end, end);
181174
}
182175

183176
Expected<ArrayRef<minidump::MemoryDescriptor_64>> Descriptors =
@@ -187,13 +180,13 @@ MinidumpFile::getMemory64List(Error &Err) const {
187180

188181
if (!Descriptors) {
189182
Err = Descriptors.takeError();
190-
return makeEmptyRange(Err);
183+
return make_range(end, end);
191184
}
192185

193186
if (!Descriptors->empty() &&
194187
ListHeader->BaseRVA + Descriptors->front().DataSize > getData().size()) {
195188
Err = createError("Memory64List header RVA out of range");
196-
return makeEmptyRange(Err);
189+
return make_range(end, end);
197190
}
198191

199192
return make_range(FallibleMemory64Iterator::itr(

llvm/lib/ObjectYAML/MinidumpEmitter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,15 @@ static size_t layout(BlobAllocator &File, MinidumpYAML::Memory64ListStream &S) {
147147

148148
// Save the new offset for the stream size.
149149
size_t DataEnd = File.tell();
150-
for (auto &E : S.Entries)
150+
for (auto &E : S.Entries) {
151151
File.allocateBytes(E.Content);
152+
if (E.Entry.DataSize > E.Content.binary_size()) {
153+
size_t Padding = E.Entry.DataSize - E.Content.binary_size();
154+
File.allocateCallback(Padding, [Padding](raw_ostream &OS) {
155+
OS << std::string(Padding, '\0');
156+
});
157+
}
158+
}
152159

153160
return DataEnd;
154161
}

llvm/lib/ObjectYAML/MinidumpYAML.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,14 @@ Stream::create(const Directory &StreamDesc, const object::MinidumpFile &File) {
531531
case StreamKind::Memory64List: {
532532
Error Err = Error::success();
533533
auto Memory64List = File.getMemory64List(Err);
534-
if (Err)
535-
return Err;
536534
std::vector<Memory64ListStream::entry_type> Ranges;
537535
for (const auto &Pair : Memory64List) {
538536
Ranges.push_back({Pair.first, Pair.second});
539537
}
540538

541-
// If we don't have an error, or if any of the reads succeed, return ranges
542-
// this would also work if we have no descriptors.
543-
if (!Err || Ranges.size() > 0)
544-
return std::make_unique<Memory64ListStream>(std::move(Ranges));
545-
546-
return Err;
539+
if (Err)
540+
return Err;
541+
return std::make_unique<Memory64ListStream>(std::move(Ranges));
547542
}
548543
case StreamKind::ModuleList: {
549544
auto ExpectedList = File.getModuleList();

llvm/test/tools/obj2yaml/Minidump/basic.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Streams:
7474
Memory Ranges:
7575
- Start of Memory Range: 0x7FFFFFCF08180283
7676
Content: '68656c6c6f776f726c64'
77+
- Start of Memory Range: 0x7FFAFFCF08180283
78+
Data Size: 8
79+
Content: '8008'
7780
- Type: MemoryInfoList
7881
Memory Ranges:
7982
- Base Address: 0x0000000000000000
@@ -167,6 +170,8 @@ Streams:
167170
# CHECK-NEXT: Memory Ranges:
168171
# CHECK-NEXT: - Start of Memory Range: 0x7FFFFFCF08180283
169172
# CHECK-NEXT: Content: 68656C6C6F776F726C64
173+
# CHECK-NEXT: - Start of Memory Range: 0x7FFAFFCF08180283
174+
# CHECK-NEXT: Content: '8008000000000000'
170175
# CHECK-NEXT: - Type: MemoryInfoList
171176
# CHECK-NEXT: Memory Ranges:
172177
# CHECK-NEXT: - Base Address: 0x0

llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -356,37 +356,32 @@ TEST(MinidumpYAML, MemoryRegion_64bit) {
356356
ASSERT_THAT(File.streams().size(), 1u);
357357

358358
Error Err = Error::success();
359-
// Explicit Err check
360-
ASSERT_FALSE(Err);
361-
Expected<iterator_range<object::MinidumpFile::FallibleMemory64Iterator>>
362-
ExpectedMemoryList = File.getMemory64List(Err);
363-
364-
ASSERT_THAT_EXPECTED(ExpectedMemoryList, Succeeded());
365-
366359
iterator_range<object::MinidumpFile::FallibleMemory64Iterator> MemoryList =
367-
*ExpectedMemoryList;
360+
File.getMemory64List(Err);
361+
362+
ASSERT_THAT_ERROR(std::move(Err), Succeeded());
368363
auto Iterator = MemoryList.begin();
369364

370365
auto DescOnePair = *Iterator;
371366
const minidump::MemoryDescriptor_64 &DescOne = DescOnePair.first;
372367
ASSERT_THAT(DescOne.StartOfMemoryRange, 0x7FFFFFCF0818283u);
373368
ASSERT_THAT(DescOne.DataSize, 5u);
374369
++Iterator;
375-
ASSERT_FALSE(Err);
370+
ASSERT_THAT_ERROR(std::move(Err), Succeeded());
376371

377372
auto DescTwoPair = *Iterator;
378373
const minidump::MemoryDescriptor_64 &DescTwo = DescTwoPair.first;
379374
ASSERT_THAT(DescTwo.StartOfMemoryRange, 0x7FFFFFFF0818283u);
380375
ASSERT_THAT(DescTwo.DataSize, 5u);
381376
++Iterator;
382-
ASSERT_FALSE(Err);
377+
ASSERT_THAT_ERROR(std::move(Err), Succeeded());
383378

384379
const std::optional<ArrayRef<uint8_t>> ExpectedContent =
385380
File.getRawStream(StreamType::Memory64List);
386381
ASSERT_TRUE(ExpectedContent);
387382
const size_t ExpectedStreamSize =
388383
sizeof(Memory64ListHeader) + (sizeof(MemoryDescriptor_64) * 2);
389-
ASSERT_THAT(ExpectedStreamSize, ExpectedContent->size());
384+
ASSERT_THAT(ExpectedContent->size(), ExpectedStreamSize);
390385

391386
Expected<minidump::Memory64ListHeader> ExpectedHeader =
392387
File.getMemoryList64Header();
@@ -404,20 +399,3 @@ TEST(MinidumpYAML, MemoryRegion_64bit) {
404399

405400
ASSERT_EQ(Iterator, MemoryList.end());
406401
}
407-
408-
TEST(MinidumpYAML, MemoryRegion_DataSize_TooSmall) {
409-
SmallString<0> Storage;
410-
auto ExpectedFile = toBinary(Storage, R"(
411-
--- !minidump
412-
Streams:
413-
- Type: Memory64List
414-
Memory Ranges:
415-
- Start of Memory Range: 0x7FFFFFCF0818283
416-
Data Size: 1
417-
Content: '68656c6c6f'
418-
- Start of Memory Range: 0x7FFFFFFF0818283
419-
Content: '776f726c64'
420-
)");
421-
422-
ASSERT_THAT_EXPECTED(ExpectedFile, Failed());
423-
}

0 commit comments

Comments
 (0)