Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ObjectFileMinidump.cpp --------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "ObjectFileMinidump.h"
10
11
#include "MinidumpFileBuilder.h"
12
13
#include "lldb/Core/ModuleSpec.h"
14
#include "lldb/Core/PluginManager.h"
15
#include "lldb/Core/Section.h"
16
#include "lldb/Target/Process.h"
17
18
#include "llvm/Support/FileSystem.h"
19
20
using namespace lldb;
21
using namespace lldb_private;
22
23
LLDB_PLUGIN_DEFINE(ObjectFileMinidump)
24
25
3.44k
void ObjectFileMinidump::Initialize() {
26
3.44k
  PluginManager::RegisterPlugin(
27
3.44k
      GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
28
3.44k
      CreateMemoryInstance, GetModuleSpecifications, SaveCore);
29
3.44k
}
30
31
3.43k
void ObjectFileMinidump::Terminate() {
32
3.43k
  PluginManager::UnregisterPlugin(CreateInstance);
33
3.43k
}
34
35
ObjectFile *ObjectFileMinidump::CreateInstance(
36
    const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
37
    lldb::offset_t data_offset, const lldb_private::FileSpec *file,
38
225
    lldb::offset_t offset, lldb::offset_t length) {
39
225
  return nullptr;
40
225
}
41
42
ObjectFile *ObjectFileMinidump::CreateMemoryInstance(
43
    const lldb::ModuleSP &module_sp, DataBufferSP &data_sp,
44
2
    const ProcessSP &process_sp, lldb::addr_t header_addr) {
45
2
  return nullptr;
46
2
}
47
48
size_t ObjectFileMinidump::GetModuleSpecifications(
49
    const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
50
    lldb::offset_t data_offset, lldb::offset_t file_offset,
51
2.70k
    lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
52
2.70k
  specs.Clear();
53
2.70k
  return 0;
54
2.70k
}
55
56
bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP &process_sp,
57
                                  const lldb_private::FileSpec &outfile,
58
                                  lldb::SaveCoreStyle &core_style,
59
0
                                  lldb_private::Status &error) {
60
0
  if (core_style != SaveCoreStyle::eSaveCoreStackOnly) {
61
0
    error.SetErrorString("Only stack minidumps supported yet.");
62
0
    return false;
63
0
  }
64
65
0
  if (!process_sp)
66
0
    return false;
67
68
0
  MinidumpFileBuilder builder;
69
70
0
  Target &target = process_sp->GetTarget();
71
72
0
  error = builder.AddSystemInfo(target.GetArchitecture().GetTriple());
73
0
  if (error.Fail())
74
0
    return false;
75
76
0
  error = builder.AddModuleList(target);
77
0
  if (error.Fail())
78
0
    return false;
79
80
0
  builder.AddMiscInfo(process_sp);
81
82
0
  if (target.GetArchitecture().GetMachine() == llvm::Triple::ArchType::x86_64) {
83
0
    error = builder.AddThreadList(process_sp);
84
0
    if (error.Fail())
85
0
      return false;
86
87
0
    error = builder.AddException(process_sp);
88
0
    if (error.Fail())
89
0
      return false;
90
91
0
    error = builder.AddMemoryList(process_sp);
92
0
    if (error.Fail())
93
0
      return false;
94
0
  }
95
96
0
  if (target.GetArchitecture().GetTriple().getOS() ==
97
0
      llvm::Triple::OSType::Linux) {
98
0
    builder.AddLinuxFileStreams(process_sp);
99
0
  }
100
101
0
  llvm::Expected<lldb::FileUP> maybe_core_file = FileSystem::Instance().Open(
102
0
      outfile, File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);
103
0
  if (!maybe_core_file) {
104
0
    error = maybe_core_file.takeError();
105
0
    return false;
106
0
  }
107
0
  lldb::FileUP core_file = std::move(maybe_core_file.get());
108
109
0
  error = builder.Dump(core_file);
110
0
  if (error.Fail())
111
0
    return false;
112
113
0
  return true;
114
0
}