Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- PlatformRemoteMacOSX.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 <memory>
10
#include <string>
11
#include <vector>
12
13
#include "PlatformRemoteMacOSX.h"
14
15
#include "lldb/Breakpoint/BreakpointLocation.h"
16
#include "lldb/Core/Module.h"
17
#include "lldb/Core/ModuleList.h"
18
#include "lldb/Core/ModuleSpec.h"
19
#include "lldb/Core/PluginManager.h"
20
#include "lldb/Host/Host.h"
21
#include "lldb/Host/HostInfo.h"
22
#include "lldb/Target/Process.h"
23
#include "lldb/Target/Target.h"
24
#include "lldb/Utility/ArchSpec.h"
25
#include "lldb/Utility/FileSpec.h"
26
#include "lldb/Utility/Log.h"
27
#include "lldb/Utility/StreamString.h"
28
29
using namespace lldb;
30
using namespace lldb_private;
31
32
/// Default Constructor
33
23
PlatformRemoteMacOSX::PlatformRemoteMacOSX() : PlatformRemoteDarwinDevice() {}
Unexecuted instantiation: PlatformRemoteMacOSX::PlatformRemoteMacOSX()
PlatformRemoteMacOSX::PlatformRemoteMacOSX()
Line
Count
Source
33
23
PlatformRemoteMacOSX::PlatformRemoteMacOSX() : PlatformRemoteDarwinDevice() {}
34
35
// Static Variables
36
static uint32_t g_initialize_count = 0;
37
38
// Static Functions
39
6.88k
void PlatformRemoteMacOSX::Initialize() {
40
6.88k
  PlatformDarwin::Initialize();
41
42
6.88k
  if (g_initialize_count++ == 0) {
43
3.44k
    PluginManager::RegisterPlugin(PlatformRemoteMacOSX::GetPluginNameStatic(),
44
3.44k
                                  PlatformRemoteMacOSX::GetDescriptionStatic(),
45
3.44k
                                  PlatformRemoteMacOSX::CreateInstance);
46
3.44k
  }
47
6.88k
}
48
49
0
void PlatformRemoteMacOSX::Terminate() {
50
0
  if (g_initialize_count > 0) {
51
0
    if (--g_initialize_count == 0) {
52
0
      PluginManager::UnregisterPlugin(PlatformRemoteMacOSX::CreateInstance);
53
0
    }
54
0
  }
55
56
0
  PlatformDarwin::Terminate();
57
0
}
58
59
PlatformSP PlatformRemoteMacOSX::CreateInstance(bool force,
60
98
                                                const ArchSpec *arch) {
61
98
  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
62
98
  if (log) {
63
0
    const char *arch_name;
64
0
    if (arch && arch->GetArchitectureName())
65
0
      arch_name = arch->GetArchitectureName();
66
0
    else
67
0
      arch_name = "<null>";
68
69
0
    const char *triple_cstr =
70
0
        arch ? arch->GetTriple().getTriple().c_str() : "<null>";
71
72
0
    LLDB_LOGF(log, "PlatformMacOSX::%s(force=%s, arch={%s,%s})", __FUNCTION__,
73
0
              force ? "true" : "false", arch_name, triple_cstr);
74
0
  }
75
76
98
  bool create = force;
77
98
  if (!create && 
arch92
&&
arch->IsValid()92
) {
78
92
    const llvm::Triple &triple = arch->GetTriple();
79
92
    switch (triple.getVendor()) {
80
14
    case llvm::Triple::Apple:
81
14
      create = true;
82
14
      break;
83
84
0
#if defined(__APPLE__)
85
    // Only accept "unknown" for vendor if the host is Apple and it "unknown"
86
    // wasn't specified (it was just returned because it was NOT specified)
87
54
    case llvm::Triple::UnknownVendor:
88
54
      create = !arch->TripleVendorWasSpecified();
89
54
      break;
90
0
#endif
91
24
    default:
92
24
      break;
93
92
    }
94
95
92
    if (create) {
96
40
      switch (triple.getOS()) {
97
0
      case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
98
                                 // historical reasons
99
5
      case llvm::Triple::MacOSX:
100
5
        break;
101
0
#if defined(__APPLE__)
102
      // Only accept "vendor" for vendor if the host is Apple and it "unknown"
103
      // wasn't specified (it was just returned because it was NOT specified)
104
12
      case llvm::Triple::UnknownOS:
105
12
        create = !arch->TripleOSWasSpecified();
106
12
        break;
107
0
#endif
108
23
      default:
109
23
        create = false;
110
23
        break;
111
40
      }
112
40
    }
113
92
  }
114
115
98
  if (create) {
116
23
    LLDB_LOGF(log, "PlatformRemoteMacOSX::%s() creating platform",
117
23
              __FUNCTION__);
118
23
    return std::make_shared<PlatformRemoteMacOSX>();
119
23
  }
120
121
75
  LLDB_LOGF(log, "PlatformRemoteMacOSX::%s() aborting creation of platform",
122
75
            __FUNCTION__);
123
124
75
  return PlatformSP();
125
98
}
126
127
64
std::vector<ArchSpec> PlatformRemoteMacOSX::GetSupportedArchitectures() {
128
  // macOS for ARM64 support both native and translated x86_64 processes
129
64
  std::vector<ArchSpec> result;
130
64
  ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);
131
132
  // We can't use x86GetSupportedArchitectures() because it uses
133
  // the system architecture for some of its return values and also
134
  // has a 32bits variant.
135
64
  result.push_back(ArchSpec("x86_64-apple-macosx"));
136
64
  result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
137
64
  result.push_back(ArchSpec("arm64-apple-ios"));
138
64
  result.push_back(ArchSpec("arm64e-apple-ios"));
139
64
  return result;
140
64
}
141
142
lldb_private::Status PlatformRemoteMacOSX::GetFileWithUUID(
143
    const lldb_private::FileSpec &platform_file,
144
41
    const lldb_private::UUID *uuid_ptr, lldb_private::FileSpec &local_file) {
145
41
  if (m_remote_platform_sp) {
146
39
    std::string local_os_build;
147
39
#if !defined(__linux__)
148
39
    local_os_build = HostInfo::GetOSBuildString().getValueOr("");
149
39
#endif
150
39
    llvm::Optional<std::string> remote_os_build =
151
39
        m_remote_platform_sp->GetOSBuildString();
152
39
    if (local_os_build == remote_os_build) {
153
      // same OS version: the local file is good enough
154
39
      local_file = platform_file;
155
39
      return Status();
156
39
    } else {
157
      // try to find the file in the cache
158
0
      std::string cache_path(GetLocalCacheDirectory());
159
0
      std::string module_path(platform_file.GetPath());
160
0
      cache_path.append(module_path);
161
0
      FileSpec module_cache_spec(cache_path);
162
0
      if (FileSystem::Instance().Exists(module_cache_spec)) {
163
0
        local_file = module_cache_spec;
164
0
        return Status();
165
0
      }
166
      // bring in the remote module file
167
0
      FileSpec module_cache_folder =
168
0
          module_cache_spec.CopyByRemovingLastPathComponent();
169
      // try to make the local directory first
170
0
      Status err(
171
0
          llvm::sys::fs::create_directory(module_cache_folder.GetPath()));
172
0
      if (err.Fail())
173
0
        return err;
174
0
      err = GetFile(platform_file, module_cache_spec);
175
0
      if (err.Fail())
176
0
        return err;
177
0
      if (FileSystem::Instance().Exists(module_cache_spec)) {
178
0
        local_file = module_cache_spec;
179
0
        return Status();
180
0
      } else
181
0
        return Status("unable to obtain valid module file");
182
0
    }
183
39
  }
184
2
  local_file = platform_file;
185
2
  return Status();
186
41
}
187
188
3.44k
llvm::StringRef PlatformRemoteMacOSX::GetDescriptionStatic() {
189
3.44k
  return "Remote Mac OS X user platform plug-in.";
190
3.44k
}
191
192
83
llvm::StringRef PlatformRemoteMacOSX::GetDeviceSupportDirectoryName() {
193
83
  return "macOS DeviceSupport";
194
83
}
195
196
83
llvm::StringRef PlatformRemoteMacOSX::GetPlatformName() {
197
83
  return "MacOSX.platform";
198
83
}