[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- PlatformWindows.cpp -----------------------------------------------===//
|
2013-10-15 20:32:12 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2013-10-15 20:32:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "PlatformWindows.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#if defined(_WIN32)
|
2014-03-13 19:39:01 +08:00
|
|
|
#include "lldb/Host/windows/windows.h"
|
2013-10-15 20:32:12 +08:00
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
2015-03-05 01:43:00 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointSite.h"
|
2013-10-15 20:32:12 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
2014-08-20 01:18:29 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2015-03-05 01:43:00 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2013-10-15 20:32:12 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-02-08 06:58:18 +08:00
|
|
|
LLDB_PLUGIN(PlatformWindows);
|
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
static uint32_t g_initialize_count = 0;
|
|
|
|
|
2014-07-29 00:44:49 +08:00
|
|
|
namespace {
|
|
|
|
class SupportedArchList {
|
|
|
|
public:
|
|
|
|
SupportedArchList() {
|
|
|
|
AddArch(ArchSpec("i686-pc-windows"));
|
2014-08-21 00:42:51 +08:00
|
|
|
AddArch(HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
|
|
|
|
AddArch(HostInfo::GetArchitecture(HostInfo::eArchKind32));
|
|
|
|
AddArch(HostInfo::GetArchitecture(HostInfo::eArchKind64));
|
2014-07-29 00:44:49 +08:00
|
|
|
AddArch(ArchSpec("i386-pc-windows"));
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-29 00:44:49 +08:00
|
|
|
size_t Count() const { return m_archs.size(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-29 00:44:49 +08:00
|
|
|
const ArchSpec &operator[](int idx) { return m_archs[idx]; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-29 00:44:49 +08:00
|
|
|
private:
|
|
|
|
void AddArch(const ArchSpec &spec) {
|
|
|
|
auto iter = std::find_if(
|
|
|
|
m_archs.begin(), m_archs.end(),
|
|
|
|
[spec](const ArchSpec &rhs) { return spec.IsExactMatch(rhs); });
|
|
|
|
if (iter != m_archs.end())
|
|
|
|
return;
|
|
|
|
if (spec.IsValid())
|
|
|
|
m_archs.push_back(spec);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-29 00:44:49 +08:00
|
|
|
std::vector<ArchSpec> m_archs;
|
|
|
|
};
|
2015-10-27 08:45:06 +08:00
|
|
|
} // anonymous namespace
|
2014-07-29 00:44:49 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
PlatformSP PlatformWindows::CreateInstance(bool force,
|
|
|
|
const lldb_private::ArchSpec *arch) {
|
|
|
|
// The only time we create an instance is when we are creating a remote
|
|
|
|
// windows platform
|
|
|
|
const bool is_host = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
bool create = force;
|
2018-12-15 08:15:33 +08:00
|
|
|
if (!create && arch && arch->IsValid()) {
|
2013-10-15 20:32:12 +08:00
|
|
|
const llvm::Triple &triple = arch->GetTriple();
|
|
|
|
switch (triple.getVendor()) {
|
|
|
|
case llvm::Triple::PC:
|
|
|
|
create = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2018-08-01 07:53:23 +08:00
|
|
|
case llvm::Triple::UnknownVendor:
|
2013-10-15 20:32:12 +08:00
|
|
|
create = !arch->TripleVendorWasSpecified();
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-10-15 20:32:12 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-10-15 20:32:12 +08:00
|
|
|
|
|
|
|
if (create) {
|
|
|
|
switch (triple.getOS()) {
|
|
|
|
case llvm::Triple::Win32:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case llvm::Triple::UnknownOS:
|
|
|
|
create = arch->TripleOSWasSpecified();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
create = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-10-15 20:32:12 +08:00
|
|
|
if (create)
|
2014-09-20 04:11:50 +08:00
|
|
|
return PlatformSP(new PlatformWindows(is_host));
|
|
|
|
return PlatformSP();
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::ConstString PlatformWindows::GetPluginNameStatic(bool is_host) {
|
|
|
|
if (is_host) {
|
|
|
|
static ConstString g_host_name(Platform::GetHostPlatformName());
|
|
|
|
return g_host_name;
|
|
|
|
} else {
|
|
|
|
static ConstString g_remote_name("remote-windows");
|
|
|
|
return g_remote_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *PlatformWindows::GetPluginDescriptionStatic(bool is_host) {
|
|
|
|
return is_host ? "Local Windows user platform plug-in."
|
|
|
|
: "Remote Windows user platform plug-in.";
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:45:06 +08:00
|
|
|
lldb_private::ConstString PlatformWindows::GetPluginName() {
|
2013-10-15 20:32:12 +08:00
|
|
|
return GetPluginNameStatic(IsHost());
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:45:06 +08:00
|
|
|
void PlatformWindows::Initialize() {
|
2015-02-13 02:18:27 +08:00
|
|
|
Platform::Initialize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
if (g_initialize_count++ == 0) {
|
|
|
|
#if defined(_WIN32)
|
|
|
|
// Force a host flag to true for the default platform object.
|
|
|
|
PlatformSP default_platform_sp(new PlatformWindows(true));
|
2014-08-21 00:42:51 +08:00
|
|
|
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
|
2014-09-20 04:11:50 +08:00
|
|
|
Platform::SetHostPlatform(default_platform_sp);
|
2013-10-15 20:32:12 +08:00
|
|
|
#endif
|
|
|
|
PluginManager::RegisterPlugin(
|
|
|
|
PlatformWindows::GetPluginNameStatic(false),
|
|
|
|
PlatformWindows::GetPluginDescriptionStatic(false),
|
|
|
|
PlatformWindows::CreateInstance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 12:57:18 +08:00
|
|
|
void PlatformWindows::Terminate() {
|
2013-10-15 20:32:12 +08:00
|
|
|
if (g_initialize_count > 0) {
|
|
|
|
if (--g_initialize_count == 0) {
|
|
|
|
PluginManager::UnregisterPlugin(PlatformWindows::CreateInstance);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-02-13 02:18:27 +08:00
|
|
|
|
|
|
|
Platform::Terminate();
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Default Constructor
|
Extract common PlatformPOSIX/Windows code into a separate class
Summary:
The two classes contained a lot of duplicated code, but there wasn't a
good place to factor it to. It couldn't be the base Platform class,
since we also have platforms which are only remote (such as
PlatformGDBRemoteServer), and so it did not make sense for those to have
an m_remote_platform member.
This patch creates a new class, RemoteAwarePlatform, which can serve as
a base class for platforms which can both serve as a host, and forward
actions to a remote system. It is motivated partly by D56232 (which was
about to add a bunch of additional duplicated methods), and partly by my
own need to modify a function which happens to be implemented in both
places identically.
The patch moves the methods which are trivially identical in the two
classes into the common base class, there were one or two more methods
which could probably be merged into one, but this wasn't completely
trivial, so I did not attempt to do that now.
Reviewers: jingham, zturner, clayborg, asmith
Subscribers: emaste, mgorny, Hui, lldb-commits
Differential Revision: https://reviews.llvm.org/D58052
llvm-svn: 353812
2019-02-12 17:27:24 +08:00
|
|
|
PlatformWindows::PlatformWindows(bool is_host) : RemoteAwarePlatform(is_host) {}
|
2013-10-15 20:32:12 +08:00
|
|
|
|
|
|
|
/// Destructor.
|
|
|
|
///
|
|
|
|
/// The destructor is virtual since this class is designed to be
|
|
|
|
/// inherited from by the plug-in instance.
|
2015-10-27 08:45:06 +08:00
|
|
|
PlatformWindows::~PlatformWindows() = default;
|
2013-10-15 20:32:12 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status PlatformWindows::ResolveExecutable(
|
2013-10-15 20:32:12 +08:00
|
|
|
const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp,
|
|
|
|
const FileSpecList *module_search_paths_ptr) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2013-10-15 20:32:12 +08:00
|
|
|
// Nothing special to do here, just use the actual file and architecture
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
char exe_path[PATH_MAX];
|
2014-11-18 03:39:20 +08:00
|
|
|
ModuleSpec resolved_module_spec(ms);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
if (IsHost()) {
|
|
|
|
// if we cant resolve the executable loation based on the current path
|
|
|
|
// variables
|
2018-11-02 01:09:25 +08:00
|
|
|
if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
|
2014-11-18 03:39:20 +08:00
|
|
|
resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
|
2018-11-02 05:05:36 +08:00
|
|
|
resolved_module_spec.GetFileSpec().SetFile(exe_path,
|
2018-06-14 06:08:14 +08:00
|
|
|
FileSpec::Style::native);
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSystem::Instance().Resolve(resolved_module_spec.GetFileSpec());
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
|
|
|
|
2018-11-02 01:09:25 +08:00
|
|
|
if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
|
2018-11-02 01:09:22 +08:00
|
|
|
FileSystem::Instance().ResolveExecutableLocation(
|
|
|
|
resolved_module_spec.GetFileSpec());
|
2013-10-15 20:32:12 +08:00
|
|
|
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
|
2013-10-15 20:32:12 +08:00
|
|
|
error.Clear();
|
|
|
|
else {
|
2014-11-18 03:39:20 +08:00
|
|
|
ms.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
|
2013-10-15 20:32:12 +08:00
|
|
|
error.SetErrorStringWithFormat("unable to find executable for '%s'",
|
|
|
|
exe_path);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_remote_platform_sp) {
|
2019-02-14 13:34:46 +08:00
|
|
|
error =
|
|
|
|
GetCachedExecutable(resolved_module_spec, exe_module_sp,
|
|
|
|
module_search_paths_ptr, *m_remote_platform_sp);
|
2013-10-15 20:32:12 +08:00
|
|
|
} else {
|
|
|
|
// We may connect to a process and use the provided executable (Don't use
|
|
|
|
// local $PATH).
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
|
2013-10-15 20:32:12 +08:00
|
|
|
error.Clear();
|
|
|
|
else
|
|
|
|
error.SetErrorStringWithFormat("the platform is not currently "
|
|
|
|
"connected, and '%s' doesn't exist in "
|
|
|
|
"the system root.",
|
|
|
|
exe_path);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
if (error.Success()) {
|
2014-11-18 03:39:20 +08:00
|
|
|
if (resolved_module_spec.GetArchitecture().IsValid()) {
|
2015-10-27 08:45:06 +08:00
|
|
|
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
|
|
|
|
nullptr, nullptr, nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-27 08:45:06 +08:00
|
|
|
if (!exe_module_sp || exe_module_sp->GetObjectFile() == nullptr) {
|
2013-10-15 20:32:12 +08:00
|
|
|
exe_module_sp.reset();
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"'%s' doesn't contain the architecture %s",
|
2014-11-18 03:39:20 +08:00
|
|
|
resolved_module_spec.GetFileSpec().GetPath().c_str(),
|
|
|
|
resolved_module_spec.GetArchitecture().GetArchitectureName());
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// No valid architecture was specified, ask the platform for the
|
|
|
|
// architectures that we should be using (in the correct order) and see
|
|
|
|
// if we can find a match that way
|
2013-10-15 20:32:12 +08:00
|
|
|
StreamString arch_names;
|
2014-11-18 03:39:20 +08:00
|
|
|
for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
|
|
|
|
idx, resolved_module_spec.GetArchitecture());
|
2016-09-07 04:57:50 +08:00
|
|
|
++idx) {
|
2015-10-27 08:45:06 +08:00
|
|
|
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
|
2019-02-14 13:34:46 +08:00
|
|
|
module_search_paths_ptr, nullptr,
|
|
|
|
nullptr);
|
2013-10-15 20:32:12 +08:00
|
|
|
// Did we find an executable using one of the
|
|
|
|
if (error.Success()) {
|
|
|
|
if (exe_module_sp && exe_module_sp->GetObjectFile())
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
else
|
2013-10-15 20:32:12 +08:00
|
|
|
error.SetErrorToGenericError();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
if (idx > 0)
|
|
|
|
arch_names.PutCString(", ");
|
|
|
|
arch_names.PutCString(
|
2014-11-18 03:39:20 +08:00
|
|
|
resolved_module_spec.GetArchitecture().GetArchitectureName());
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
if (error.Fail() || !exe_module_sp) {
|
2018-11-01 23:47:33 +08:00
|
|
|
if (FileSystem::Instance().Readable(
|
|
|
|
resolved_module_spec.GetFileSpec())) {
|
2014-08-16 02:03:30 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"'%s' doesn't contain any '%s' platform architectures: %s",
|
2014-11-18 03:39:20 +08:00
|
|
|
resolved_module_spec.GetFileSpec().GetPath().c_str(),
|
2016-11-17 05:15:24 +08:00
|
|
|
GetPluginName().GetCString(), arch_names.GetData());
|
2014-08-16 02:03:30 +08:00
|
|
|
} else {
|
2014-11-18 03:39:20 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"'%s' is not readable",
|
|
|
|
resolved_module_spec.GetFileSpec().GetPath().c_str());
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-10-15 20:32:12 +08:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status PlatformWindows::ConnectRemote(Args &args) {
|
|
|
|
Status error;
|
2013-10-15 20:32:12 +08:00
|
|
|
if (IsHost()) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"can't connect to the host platform '%s', always connected",
|
|
|
|
GetPluginName().AsCString());
|
|
|
|
} else {
|
|
|
|
if (!m_remote_platform_sp)
|
2014-09-20 04:11:50 +08:00
|
|
|
m_remote_platform_sp =
|
|
|
|
Platform::Create(ConstString("remote-gdb-server"), error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
if (m_remote_platform_sp) {
|
|
|
|
if (error.Success()) {
|
|
|
|
if (m_remote_platform_sp) {
|
|
|
|
error = m_remote_platform_sp->ConnectRemote(args);
|
|
|
|
} else {
|
|
|
|
error.SetErrorString(
|
|
|
|
"\"platform connect\" takes a single argument: <connect-url>");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-10-15 20:32:12 +08:00
|
|
|
} else
|
|
|
|
error.SetErrorString("failed to create a 'remote-gdb-server' platform");
|
|
|
|
|
|
|
|
if (error.Fail())
|
|
|
|
m_remote_platform_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status PlatformWindows::DisconnectRemote() {
|
|
|
|
Status error;
|
2013-10-15 20:32:12 +08:00
|
|
|
|
|
|
|
if (IsHost()) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"can't disconnect from the host platform '%s', always connected",
|
|
|
|
GetPluginName().AsCString());
|
|
|
|
} else {
|
|
|
|
if (m_remote_platform_sp)
|
|
|
|
error = m_remote_platform_sp->DisconnectRemote();
|
|
|
|
else
|
|
|
|
error.SetErrorString("the platform is not currently connected");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-05-21 02:31:17 +08:00
|
|
|
ProcessSP PlatformWindows::DebugProcess(ProcessLaunchInfo &launch_info,
|
|
|
|
Debugger &debugger, Target *target,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2015-05-21 02:31:17 +08:00
|
|
|
// Windows has special considerations that must be followed when launching or
|
2018-05-01 00:49:04 +08:00
|
|
|
// attaching to a process. The key requirement is that when launching or
|
|
|
|
// attaching to a process, you must do it from the same the thread that will
|
|
|
|
// go into a permanent loop which will then receive debug events from the
|
|
|
|
// process. In particular, this means we can't use any of LLDB's generic
|
|
|
|
// mechanisms to do it for us, because it doesn't have the special knowledge
|
|
|
|
// required for setting up the background thread or passing the right flags.
|
2015-05-21 02:31:17 +08:00
|
|
|
//
|
|
|
|
// Another problem is that that LLDB's standard model for debugging a process
|
2018-05-01 00:49:04 +08:00
|
|
|
// is to first launch it, have it stop at the entry point, and then attach to
|
|
|
|
// it. In Windows this doesn't quite work, you have to specify as an
|
|
|
|
// argument to CreateProcess() that you're going to debug the process. So we
|
|
|
|
// override DebugProcess here to handle this. Launch operations go directly
|
|
|
|
// to the process plugin, and attach operations almost go directly to the
|
|
|
|
// process plugin (but we hijack the events first). In essence, we
|
|
|
|
// encapsulate all the logic of Launching and Attaching in the process
|
|
|
|
// plugin, and PlatformWindows::DebugProcess is just a pass-through to get to
|
|
|
|
// the process plugin.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-14 13:34:46 +08:00
|
|
|
if (IsRemote()) {
|
|
|
|
if (m_remote_platform_sp)
|
|
|
|
return m_remote_platform_sp->DebugProcess(launch_info, debugger, target,
|
|
|
|
error);
|
|
|
|
else
|
|
|
|
error.SetErrorString("the platform is not currently connected");
|
|
|
|
}
|
|
|
|
|
2015-05-21 02:31:17 +08:00
|
|
|
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
|
|
|
|
// This is a process attach. Don't need to launch anything.
|
|
|
|
ProcessAttachInfo attach_info(launch_info);
|
|
|
|
return Attach(attach_info, debugger, target, error);
|
|
|
|
} else {
|
2019-01-07 18:59:57 +08:00
|
|
|
ProcessSP process_sp = target->CreateProcess(
|
|
|
|
launch_info.GetListener(), launch_info.GetProcessPluginName(), nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-21 02:31:17 +08:00
|
|
|
// We need to launch and attach to the process.
|
|
|
|
launch_info.GetFlags().Set(eLaunchFlagDebug);
|
|
|
|
if (process_sp)
|
|
|
|
error = process_sp->Launch(launch_info);
|
|
|
|
|
|
|
|
return process_sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo &attach_info,
|
|
|
|
Debugger &debugger, Target *target,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2015-05-21 02:31:17 +08:00
|
|
|
error.Clear();
|
2013-10-15 20:32:12 +08:00
|
|
|
lldb::ProcessSP process_sp;
|
2015-05-21 02:31:17 +08:00
|
|
|
if (!IsHost()) {
|
2013-10-15 20:32:12 +08:00
|
|
|
if (m_remote_platform_sp)
|
2014-11-18 03:39:20 +08:00
|
|
|
process_sp =
|
|
|
|
m_remote_platform_sp->Attach(attach_info, debugger, target, error);
|
2013-10-15 20:32:12 +08:00
|
|
|
else
|
|
|
|
error.SetErrorString("the platform is not currently connected");
|
2015-05-21 02:31:17 +08:00
|
|
|
return process_sp;
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
2015-05-21 02:31:17 +08:00
|
|
|
|
2015-10-27 08:45:06 +08:00
|
|
|
if (target == nullptr) {
|
2015-05-21 02:31:17 +08:00
|
|
|
TargetSP new_target_sp;
|
|
|
|
FileSpec emptyFileSpec;
|
|
|
|
ArchSpec emptyArchSpec;
|
|
|
|
|
2018-09-20 17:09:05 +08:00
|
|
|
error = debugger.GetTargetList().CreateTarget(
|
|
|
|
debugger, "", "", eLoadDependentsNo, nullptr, new_target_sp);
|
2015-05-21 02:31:17 +08:00
|
|
|
target = new_target_sp.get();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-05-21 02:31:17 +08:00
|
|
|
|
|
|
|
if (!target || error.Fail())
|
|
|
|
return process_sp;
|
|
|
|
|
2015-10-27 08:45:06 +08:00
|
|
|
debugger.GetTargetList().SetSelectedTarget(target);
|
2015-05-21 02:31:17 +08:00
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
const char *plugin_name = attach_info.GetProcessPluginName();
|
|
|
|
process_sp = target->CreateProcess(
|
|
|
|
attach_info.GetListenerForProcess(debugger), plugin_name, nullptr);
|
2015-05-21 02:31:17 +08:00
|
|
|
|
2013-10-15 20:32:12 +08:00
|
|
|
process_sp->HijackProcessEvents(attach_info.GetHijackListener());
|
2015-05-21 02:31:17 +08:00
|
|
|
if (process_sp)
|
|
|
|
error = process_sp->Attach(attach_info);
|
2013-10-15 20:32:12 +08:00
|
|
|
|
|
|
|
return process_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlatformWindows::GetSupportedArchitectureAtIndex(uint32_t idx,
|
|
|
|
ArchSpec &arch) {
|
2014-07-29 00:44:49 +08:00
|
|
|
static SupportedArchList architectures;
|
|
|
|
|
|
|
|
if (idx >= architectures.Count())
|
|
|
|
return false;
|
|
|
|
arch = architectures[idx];
|
|
|
|
return true;
|
2013-10-15 20:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlatformWindows::GetStatus(Stream &strm) {
|
|
|
|
Platform::GetStatus(strm);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2018-06-18 23:44:36 +08:00
|
|
|
llvm::VersionTuple version = HostInfo::GetOSVersion();
|
2019-02-14 13:34:46 +08:00
|
|
|
strm << " Host: Windows " << version.getAsString() << '\n';
|
2013-10-15 20:32:12 +08:00
|
|
|
#endif
|
|
|
|
}
|
2015-05-21 02:31:17 +08:00
|
|
|
|
|
|
|
bool PlatformWindows::CanDebugProcess() { return true; }
|
2015-05-23 03:34:17 +08:00
|
|
|
|
2015-08-27 08:53:57 +08:00
|
|
|
ConstString PlatformWindows::GetFullNameForDylib(ConstString basename) {
|
|
|
|
if (basename.IsEmpty())
|
|
|
|
return basename;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-08-27 08:53:57 +08:00
|
|
|
StreamString stream;
|
|
|
|
stream.Printf("%s.dll", basename.GetCString());
|
2016-11-17 05:15:24 +08:00
|
|
|
return ConstString(stream.GetString());
|
2015-08-27 08:53:57 +08:00
|
|
|
}
|