Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- PlatformRemoteAppleWatch.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 <string>
10
#include <vector>
11
12
#include "PlatformRemoteAppleWatch.h"
13
14
#include "lldb/Breakpoint/BreakpointLocation.h"
15
#include "lldb/Core/Module.h"
16
#include "lldb/Core/ModuleList.h"
17
#include "lldb/Core/ModuleSpec.h"
18
#include "lldb/Core/PluginManager.h"
19
#include "lldb/Host/Host.h"
20
#include "lldb/Target/Process.h"
21
#include "lldb/Target/Target.h"
22
#include "lldb/Utility/ArchSpec.h"
23
#include "lldb/Utility/FileSpec.h"
24
#include "lldb/Utility/Log.h"
25
#include "lldb/Utility/Status.h"
26
#include "lldb/Utility/StreamString.h"
27
28
using namespace lldb;
29
using namespace lldb_private;
30
31
// Static Variables
32
static uint32_t g_initialize_count = 0;
33
34
// Static Functions
35
3.44k
void PlatformRemoteAppleWatch::Initialize() {
36
3.44k
  PlatformDarwin::Initialize();
37
38
3.44k
  if (g_initialize_count++ == 0) {
39
3.44k
    PluginManager::RegisterPlugin(
40
3.44k
        PlatformRemoteAppleWatch::GetPluginNameStatic(),
41
3.44k
        PlatformRemoteAppleWatch::GetDescriptionStatic(),
42
3.44k
        PlatformRemoteAppleWatch::CreateInstance);
43
3.44k
  }
44
3.44k
}
45
46
3.43k
void PlatformRemoteAppleWatch::Terminate() {
47
3.43k
  if (g_initialize_count > 0) {
48
3.43k
    if (--g_initialize_count == 0) {
49
3.43k
      PluginManager::UnregisterPlugin(PlatformRemoteAppleWatch::CreateInstance);
50
3.43k
    }
51
3.43k
  }
52
53
3.43k
  PlatformDarwin::Terminate();
54
3.43k
}
55
56
PlatformSP PlatformRemoteAppleWatch::CreateInstance(bool force,
57
78
                                                    const ArchSpec *arch) {
58
78
  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
59
78
  if (log) {
60
0
    const char *arch_name;
61
0
    if (arch && arch->GetArchitectureName())
62
0
      arch_name = arch->GetArchitectureName();
63
0
    else
64
0
      arch_name = "<null>";
65
66
0
    const char *triple_cstr =
67
0
        arch ? arch->GetTriple().getTriple().c_str() : "<null>";
68
69
0
    LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s(force=%s, arch={%s,%s})",
70
0
              __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
71
0
  }
72
73
78
  bool create = force;
74
78
  if (!create && arch && arch->IsValid()) {
75
78
    switch (arch->GetMachine()) {
76
12
    case llvm::Triple::arm:
77
29
    case llvm::Triple::aarch64:
78
30
    case llvm::Triple::aarch64_32:
79
30
    case llvm::Triple::thumb: {
80
30
      const llvm::Triple &triple = arch->GetTriple();
81
30
      llvm::Triple::VendorType vendor = triple.getVendor();
82
30
      switch (vendor) {
83
1
      case llvm::Triple::Apple:
84
1
        create = true;
85
1
        break;
86
87
0
#if defined(__APPLE__)
88
      // Only accept "unknown" for the vendor if the host is Apple and
89
      // "unknown" wasn't specified (it was just returned because it was NOT
90
      // specified)
91
23
      case llvm::Triple::UnknownVendor:
92
23
        create = !arch->TripleVendorWasSpecified();
93
23
        break;
94
95
0
#endif
96
6
      default:
97
6
        break;
98
30
      }
99
30
      if (create) {
100
18
        switch (triple.getOS()) {
101
1
        case llvm::Triple::WatchOS: // This is the right triple value for Apple
102
                                    // Watch debugging
103
1
          break;
104
105
17
        default:
106
17
          create = false;
107
17
          break;
108
18
        }
109
18
      }
110
30
    } break;
111
48
    default:
112
48
      break;
113
78
    }
114
78
  }
115
116
#if defined(__APPLE__) &&                                                      \
117
    (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
118
  // If lldb is running on a watch, this isn't a RemoteWatch environment; it's
119
  // a local system environment.
120
  if (force == false) {
121
    create = false;
122
  }
123
#endif
124
125
78
  if (create) {
126
1
    LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() creating platform",
127
1
              __FUNCTION__);
128
129
1
    return lldb::PlatformSP(new PlatformRemoteAppleWatch());
130
1
  }
131
132
77
  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() aborting creation of platform",
133
77
            __FUNCTION__);
134
135
77
  return lldb::PlatformSP();
136
78
}
137
138
3.44k
llvm::StringRef PlatformRemoteAppleWatch::GetDescriptionStatic() {
139
3.44k
  return "Remote Apple Watch platform plug-in.";
140
3.44k
}
141
142
/// Default Constructor
143
PlatformRemoteAppleWatch::PlatformRemoteAppleWatch()
144
1
    : PlatformRemoteDarwinDevice() {}
145
146
2
std::vector<ArchSpec> PlatformRemoteAppleWatch::GetSupportedArchitectures() {
147
2
  ArchSpec system_arch(GetSystemArchitecture());
148
149
2
  const ArchSpec::Core system_core = system_arch.GetCore();
150
2
  switch (system_core) {
151
2
  default:
152
2
  case ArchSpec::eCore_arm_arm64:
153
2
    return {
154
2
        ArchSpec("arm64-apple-watchos"),    ArchSpec("armv7k-apple-watchos"),
155
2
        ArchSpec("armv7s-apple-watchos"),   ArchSpec("armv7-apple-watchos"),
156
2
        ArchSpec("thumbv7k-apple-watchos"), ArchSpec("thumbv7-apple-watchos"),
157
2
        ArchSpec("thumbv7s-apple-watchos"), ArchSpec("arm64_32-apple-watchos")};
158
159
0
  case ArchSpec::eCore_arm_armv7k:
160
0
    return {
161
0
        ArchSpec("armv7k-apple-watchos"),  ArchSpec("armv7s-apple-watchos"),
162
0
        ArchSpec("armv7-apple-watchos"),   ArchSpec("thumbv7k-apple-watchos"),
163
0
        ArchSpec("thumbv7-apple-watchos"), ArchSpec("thumbv7s-apple-watchos"),
164
0
        ArchSpec("arm64_32-apple-watchos")};
165
166
0
  case ArchSpec::eCore_arm_armv7s:
167
0
    return {
168
0
        ArchSpec("armv7s-apple-watchos"),  ArchSpec("armv7k-apple-watchos"),
169
0
        ArchSpec("armv7-apple-watchos"),   ArchSpec("thumbv7k-apple-watchos"),
170
0
        ArchSpec("thumbv7-apple-watchos"), ArchSpec("thumbv7s-apple-watchos"),
171
0
        ArchSpec("arm64_32-apple-watchos")};
172
173
0
  case ArchSpec::eCore_arm_armv7:
174
0
    return {ArchSpec("armv7-apple-watchos"), ArchSpec("armv7k-apple-watchos"),
175
0
            ArchSpec("thumbv7k-apple-watchos"),
176
0
            ArchSpec("thumbv7-apple-watchos"),
177
0
            ArchSpec("arm64_32-apple-watchos")};
178
2
  }
179
2
}
180
181
4
llvm::StringRef PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName() {
182
4
  return "watchOS DeviceSupport";
183
4
}
184
185
4
llvm::StringRef PlatformRemoteAppleWatch::GetPlatformName() {
186
4
  return "WatchOS.platform";
187
4
}