2016-06-27 21:53:53 +02:00
|
|
|
//===- ObjectYAML.cpp - YAML utilities for object files -------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-06-27 21:53:53 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a wrapper class for handling tagged YAML input
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ObjectYAML/ObjectYAML.h"
|
2017-07-01 03:35:55 +02:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/Support/YAMLParser.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
#include <string>
|
2016-06-27 21:53:53 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace yaml;
|
|
|
|
|
|
|
|
void MappingTraits<YamlObjectFile>::mapping(IO &IO,
|
|
|
|
YamlObjectFile &ObjectFile) {
|
|
|
|
if (IO.outputting()) {
|
|
|
|
if (ObjectFile.Elf)
|
|
|
|
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
|
|
|
|
if (ObjectFile.Coff)
|
|
|
|
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
|
|
|
|
if (ObjectFile.MachO)
|
|
|
|
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
|
|
|
|
if (ObjectFile.FatMachO)
|
|
|
|
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
|
|
|
|
*ObjectFile.FatMachO);
|
|
|
|
} else {
|
2019-04-25 11:59:55 +02:00
|
|
|
Input &In = (Input &)IO;
|
2020-10-20 14:12:28 +02:00
|
|
|
if (IO.mapTag("!Arch")) {
|
|
|
|
ObjectFile.Arch.reset(new ArchYAML::Archive());
|
|
|
|
MappingTraits<ArchYAML::Archive>::mapping(IO, *ObjectFile.Arch);
|
|
|
|
std::string Err =
|
|
|
|
MappingTraits<ArchYAML::Archive>::validate(IO, *ObjectFile.Arch);
|
|
|
|
if (!Err.empty())
|
|
|
|
IO.setError(Err);
|
|
|
|
} else if (IO.mapTag("!ELF")) {
|
2016-06-27 21:53:53 +02:00
|
|
|
ObjectFile.Elf.reset(new ELFYAML::Object());
|
|
|
|
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
|
|
|
|
} else if (IO.mapTag("!COFF")) {
|
|
|
|
ObjectFile.Coff.reset(new COFFYAML::Object());
|
|
|
|
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
|
|
|
|
} else if (IO.mapTag("!mach-o")) {
|
|
|
|
ObjectFile.MachO.reset(new MachOYAML::Object());
|
|
|
|
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
|
|
|
|
} else if (IO.mapTag("!fat-mach-o")) {
|
|
|
|
ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary());
|
|
|
|
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
|
|
|
|
*ObjectFile.FatMachO);
|
[ObjectYAML] Add basic minidump generation support
Summary:
This patch adds the ability to read a yaml form of a minidump file and
write it out as binary. Apart from the minidump header and the stream
directory, only three basic stream kinds are supported:
- Text: This kind is used for streams which contain textual data. This
is typically the contents of a /proc file on linux (e.g.
/proc/PID/maps). In this case, we just put the raw stream contents
into the yaml.
- SystemInfo: This stream contains various bits of information about the
host system in binary form. We expose the data in a structured form.
- Raw: This kind is used as a fallback when we don't have any special
knowledge about the stream. In this case, we just print the stream
contents in hex.
For this code to be really useful, more stream kinds will need to be
added (particularly for things like lists of memory regions and loaded
modules). However, these can be added incrementally.
Reviewers: jhenderson, zturner, clayborg, aprantl
Subscribers: mgorny, lemo, llvm-commits, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59482
llvm-svn: 356753
2019-03-22 15:47:26 +01:00
|
|
|
} else if (IO.mapTag("!minidump")) {
|
|
|
|
ObjectFile.Minidump.reset(new MinidumpYAML::Object());
|
|
|
|
MappingTraits<MinidumpYAML::Object>::mapping(IO, *ObjectFile.Minidump);
|
2017-03-30 21:44:09 +02:00
|
|
|
} else if (IO.mapTag("!WASM")) {
|
|
|
|
ObjectFile.Wasm.reset(new WasmYAML::Object());
|
|
|
|
MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm);
|
2021-06-07 06:14:44 +02:00
|
|
|
} else if (IO.mapTag("!XCOFF")) {
|
|
|
|
ObjectFile.Xcoff.reset(new XCOFFYAML::Object());
|
|
|
|
MappingTraits<XCOFFYAML::Object>::mapping(IO, *ObjectFile.Xcoff);
|
2019-04-25 11:59:55 +02:00
|
|
|
} else if (const Node *N = In.getCurrentNode()) {
|
|
|
|
if (N->getRawTag().empty())
|
2016-06-27 21:53:53 +02:00
|
|
|
IO.setError("YAML Object File missing document type tag!");
|
|
|
|
else
|
2019-04-25 11:59:55 +02:00
|
|
|
IO.setError("YAML Object File unsupported document type tag '" +
|
|
|
|
N->getRawTag() + "'!");
|
2016-06-27 21:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|