Skip to content

Commit 903f0f6

Browse files
author
git apple-llvm automerger
committed
Merge commit '360b8b91e435' from apple/master into swift/master-next
2 parents 7cb5b6a + 360b8b9 commit 903f0f6

File tree

7 files changed

+332
-3
lines changed

7 files changed

+332
-3
lines changed

lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump-new/linux-x86_64.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ Streams:
1414
Module Name: '/tmp/test/linux-x86_64'
1515
CodeView Record: 4C457042E35C283BC327C28762DB788BF5A4078BE2351448
1616
- Type: Exception
17-
Content: DD740000000000000B00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000D0040000F8310000
17+
Thread ID: 0x000074DD
18+
Exception Record:
19+
Exception Code: 0x0000000B
20+
Thread Context: 00000000
1821
- Type: SystemInfo
1922
Processor Arch: AMD64
2023
Processor Level: 6

llvm/include/llvm/ObjectYAML/MinidumpYAML.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace MinidumpYAML {
2626
/// from Types to Kinds is fixed and given by the static getKind function.
2727
struct Stream {
2828
enum class StreamKind {
29+
Exception,
2930
MemoryInfoList,
3031
MemoryList,
3132
ModuleList,
@@ -103,6 +104,25 @@ using ModuleListStream = detail::ListStream<detail::ParsedModule>;
103104
using ThreadListStream = detail::ListStream<detail::ParsedThread>;
104105
using MemoryListStream = detail::ListStream<detail::ParsedMemoryDescriptor>;
105106

107+
/// ExceptionStream minidump stream.
108+
struct ExceptionStream : public Stream {
109+
minidump::ExceptionStream MDExceptionStream;
110+
yaml::BinaryRef ThreadContext;
111+
112+
ExceptionStream()
113+
: Stream(StreamKind::Exception, minidump::StreamType::Exception),
114+
MDExceptionStream({}) {}
115+
116+
explicit ExceptionStream(const minidump::ExceptionStream &MDExceptionStream,
117+
ArrayRef<uint8_t> ThreadContext)
118+
: Stream(StreamKind::Exception, minidump::StreamType::Exception),
119+
MDExceptionStream(MDExceptionStream), ThreadContext(ThreadContext) {}
120+
121+
static bool classof(const Stream *S) {
122+
return S->Kind == StreamKind::Exception;
123+
}
124+
};
125+
106126
/// A structure containing the list of MemoryInfo entries comprising a
107127
/// MemoryInfoList stream.
108128
struct MemoryInfoListStream : public Stream {
@@ -239,6 +259,7 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::StreamType)
239259
LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::ArmInfo)
240260
LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::OtherInfo)
241261
LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::X86Info)
262+
LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::Exception)
242263
LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::MemoryInfo)
243264
LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::VSFixedFileInfo)
244265

llvm/lib/ObjectYAML/MinidumpEmitter.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ static LocationDescriptor layout(BlobAllocator &File, yaml::BinaryRef Data) {
118118
support::ulittle32_t(File.allocateBytes(Data))};
119119
}
120120

121+
static size_t layout(BlobAllocator &File, MinidumpYAML::ExceptionStream &S) {
122+
File.allocateObject(S.MDExceptionStream);
123+
124+
size_t DataEnd = File.tell();
125+
126+
// Lay out the thread context data, (which is not a part of the stream).
127+
// TODO: This usually (always?) matches the thread context of the
128+
// corresponding thread, and may overlap memory regions as well. We could
129+
// add a level of indirection to the MinidumpYAML format (like an array of
130+
// Blobs that the LocationDescriptors index into) to be able to distinguish
131+
// the cases where location descriptions overlap vs happen to reference
132+
// identical data.
133+
S.MDExceptionStream.ThreadContext = layout(File, S.ThreadContext);
134+
135+
return DataEnd;
136+
}
137+
121138
static void layout(BlobAllocator &File, MemoryListStream::entry_type &Range) {
122139
Range.Entry.Memory = layout(File, Range.Content);
123140
}
@@ -158,6 +175,9 @@ static Directory layout(BlobAllocator &File, Stream &S) {
158175
Result.Location.RVA = File.tell();
159176
Optional<size_t> DataEnd;
160177
switch (S.Kind) {
178+
case Stream::StreamKind::Exception:
179+
DataEnd = layout(File, cast<MinidumpYAML::ExceptionStream>(S));
180+
break;
161181
case Stream::StreamKind::MemoryInfoList: {
162182
MemoryInfoListStream &InfoList = cast<MemoryInfoListStream>(S);
163183
File.allocateNewObject<minidump::MemoryInfoListHeader>(

llvm/lib/ObjectYAML/MinidumpYAML.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Stream::~Stream() = default;
6969

7070
Stream::StreamKind Stream::getKind(StreamType Type) {
7171
switch (Type) {
72+
case StreamType::Exception:
73+
return StreamKind::Exception;
7274
case StreamType::MemoryInfoList:
7375
return StreamKind::MemoryInfoList;
7476
case StreamType::MemoryList:
@@ -95,6 +97,8 @@ Stream::StreamKind Stream::getKind(StreamType Type) {
9597
std::unique_ptr<Stream> Stream::create(StreamType Type) {
9698
StreamKind Kind = getKind(Type);
9799
switch (Kind) {
100+
case StreamKind::Exception:
101+
return std::make_unique<ExceptionStream>();
98102
case StreamKind::MemoryInfoList:
99103
return std::make_unique<MemoryInfoListStream>();
100104
case StreamKind::MemoryList:
@@ -274,8 +278,7 @@ void yaml::MappingTraits<ModuleListStream::entry_type>::mapping(
274278
mapRequiredHex(IO, "Base of Image", M.Entry.BaseOfImage);
275279
mapRequiredHex(IO, "Size of Image", M.Entry.SizeOfImage);
276280
mapOptionalHex(IO, "Checksum", M.Entry.Checksum, 0);
277-
IO.mapOptional("Time Date Stamp", M.Entry.TimeDateStamp,
278-
support::ulittle32_t(0));
281+
mapOptional(IO, "Time Date Stamp", M.Entry.TimeDateStamp, 0);
279282
IO.mapRequired("Module Name", M.Name);
280283
IO.mapOptional("Version Info", M.Entry.VersionInfo, VSFixedFileInfo());
281284
IO.mapRequired("CodeView Record", M.CvRecord);
@@ -367,6 +370,32 @@ static void streamMapping(yaml::IO &IO, ThreadListStream &Stream) {
367370
IO.mapRequired("Threads", Stream.Entries);
368371
}
369372

373+
static void streamMapping(yaml::IO &IO, MinidumpYAML::ExceptionStream &Stream) {
374+
mapRequiredHex(IO, "Thread ID", Stream.MDExceptionStream.ThreadId);
375+
IO.mapRequired("Exception Record", Stream.MDExceptionStream.ExceptionRecord);
376+
IO.mapRequired("Thread Context", Stream.ThreadContext);
377+
}
378+
379+
void yaml::MappingTraits<minidump::Exception>::mapping(
380+
yaml::IO &IO, minidump::Exception &Exception) {
381+
mapRequiredHex(IO, "Exception Code", Exception.ExceptionCode);
382+
mapOptionalHex(IO, "Exception Flags", Exception.ExceptionFlags, 0);
383+
mapOptionalHex(IO, "Exception Record", Exception.ExceptionRecord, 0);
384+
mapOptionalHex(IO, "Exception Address", Exception.ExceptionAddress, 0);
385+
mapOptional(IO, "Number of Parameters", Exception.NumberParameters, 0);
386+
387+
for (size_t Index = 0; Index < Exception.MaxParameters; ++Index) {
388+
SmallString<16> Name("Parameter ");
389+
Twine(Index).toVector(Name);
390+
support::ulittle64_t &Field = Exception.ExceptionInformation[Index];
391+
392+
if (Index < Exception.NumberParameters)
393+
mapRequiredHex(IO, Name.c_str(), Field);
394+
else
395+
mapOptionalHex(IO, Name.c_str(), Field, 0);
396+
}
397+
}
398+
370399
void yaml::MappingTraits<std::unique_ptr<Stream>>::mapping(
371400
yaml::IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S) {
372401
StreamType Type;
@@ -377,6 +406,9 @@ void yaml::MappingTraits<std::unique_ptr<Stream>>::mapping(
377406
if (!IO.outputting())
378407
S = MinidumpYAML::Stream::create(Type);
379408
switch (S->Kind) {
409+
case MinidumpYAML::Stream::StreamKind::Exception:
410+
streamMapping(IO, llvm::cast<MinidumpYAML::ExceptionStream>(*S));
411+
break;
380412
case MinidumpYAML::Stream::StreamKind::MemoryInfoList:
381413
streamMapping(IO, llvm::cast<MemoryInfoListStream>(*S));
382414
break;
@@ -406,6 +438,7 @@ StringRef yaml::MappingTraits<std::unique_ptr<Stream>>::validate(
406438
switch (S->Kind) {
407439
case MinidumpYAML::Stream::StreamKind::RawContent:
408440
return streamValidate(cast<RawContentStream>(*S));
441+
case MinidumpYAML::Stream::StreamKind::Exception:
409442
case MinidumpYAML::Stream::StreamKind::MemoryInfoList:
410443
case MinidumpYAML::Stream::StreamKind::MemoryList:
411444
case MinidumpYAML::Stream::StreamKind::ModuleList:
@@ -429,6 +462,18 @@ Expected<std::unique_ptr<Stream>>
429462
Stream::create(const Directory &StreamDesc, const object::MinidumpFile &File) {
430463
StreamKind Kind = getKind(StreamDesc.Type);
431464
switch (Kind) {
465+
case StreamKind::Exception: {
466+
Expected<const minidump::ExceptionStream &> ExpectedExceptionStream =
467+
File.getExceptionStream();
468+
if (!ExpectedExceptionStream)
469+
return ExpectedExceptionStream.takeError();
470+
Expected<ArrayRef<uint8_t>> ExpectedThreadContext =
471+
File.getRawData(ExpectedExceptionStream->ThreadContext);
472+
if (!ExpectedThreadContext)
473+
return ExpectedThreadContext.takeError();
474+
return std::make_unique<ExceptionStream>(*ExpectedExceptionStream,
475+
*ExpectedThreadContext);
476+
}
432477
case StreamKind::MemoryInfoList: {
433478
if (auto ExpectedList = File.getMemoryInfoList())
434479
return std::make_unique<MemoryInfoListStream>(*ExpectedList);

llvm/test/tools/obj2yaml/basic-minidump.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ Streams:
5151
Stack:
5252
Start of Memory Range: 0x6C6D6E6F70717273
5353
Content: '7475767778797A7B'
54+
- Type: Exception
55+
Thread ID: 0x7
56+
Exception Record:
57+
Exception Code: 0x10
58+
Exception Flags: 0x5
59+
Exception Record: 0x0102030405060708
60+
Exception Address: 0x0A0B0C0D0E0F1011
61+
Number of Parameters: 2
62+
Parameter 0: 0x22
63+
Parameter 1: 0x24
64+
Thread Context: '8182838485868788'
5465
- Type: MemoryList
5566
Memory Ranges:
5667
- Start of Memory Range: 0x7C7D7E7F80818283
@@ -129,6 +140,17 @@ Streams:
129140
# CHECK-NEXT: Stack:
130141
# CHECK-NEXT: Start of Memory Range: 0x6C6D6E6F70717273
131142
# CHECK-NEXT: Content: 7475767778797A7B
143+
# CHECK-NEXT: - Type: Exception
144+
# CHECK-NEXT: Thread ID: 0x00000007
145+
# CHECK-NEXT: Exception Record:
146+
# CHECK-NEXT: Exception Code: 0x00000010
147+
# CHECK-NEXT: Exception Flags: 0x00000005
148+
# CHECK-NEXT: Exception Record: 0x0102030405060708
149+
# CHECK-NEXT: Exception Address: 0x0A0B0C0D0E0F1011
150+
# CHECK-NEXT: Number of Parameters: 2
151+
# CHECK-NEXT: Parameter 0: 0x0000000000000022
152+
# CHECK-NEXT: Parameter 1: 0x0000000000000024
153+
# CHECK-NEXT: Thread Context: '8182838485868788'
132154
# CHECK-NEXT: - Type: MemoryList
133155
# CHECK-NEXT: Memory Ranges:
134156
# CHECK-NEXT: - Start of Memory Range: 0x7C7D7E7F80818283
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# RUN: not yaml2obj %s -o /dev/null 2>&1 | FileCheck %s
2+
3+
## Test that we report an error for an ExceptionStream where the specified
4+
## number of parameters is greater than the number of ExceptionInformation
5+
## elements listed.
6+
7+
--- !minidump
8+
Streams:
9+
- Type: Exception
10+
Thread ID: 0x7
11+
Exception Record:
12+
Exception Code: 0x23
13+
Exception Flags: 0x5
14+
Exception Record: 0x0102030405060708
15+
Exception Address: 0x0a0b0c0d0e0f1011
16+
Number of Parameters: 4
17+
Parameter 0: 0x99
18+
Parameter 1: 0x23
19+
Parameter 2: 0x42
20+
# CHECK: error: missing required key 'Parameter 3'
21+
Thread Context: 3DeadBeefDefacedABadCafe)");

0 commit comments

Comments
 (0)