[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
|
|
|
//===-- TargetList.cpp ----------------------------------------------------===//
|
2010-06-09 00:52:24 +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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-07 02:34:25 +08:00
|
|
|
#include "lldb/Target/TargetList.h"
|
2011-03-19 09:12:21 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2013-04-25 06:29:28 +08:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-11-22 09:42:44 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2012-03-21 02:34:04 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2011-09-24 08:52:29 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupPlatform.h"
|
2013-04-25 06:29:28 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2011-03-09 06:40:15 +08:00
|
|
|
#include "lldb/Target/Platform.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Broadcaster.h"
|
|
|
|
#include "lldb/Utility/Event.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2017-03-23 01:33:23 +08:00
|
|
|
#include "lldb/Utility/TildeExpressionResolver.h"
|
2017-06-29 22:32:17 +08:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2017-01-23 23:56:45 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2012-02-16 14:50:00 +08:00
|
|
|
ConstString &TargetList::GetStaticBroadcasterClass() {
|
|
|
|
static ConstString class_name("lldb.targetList");
|
|
|
|
return class_name;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// TargetList constructor
|
2016-05-18 09:59:10 +08:00
|
|
|
TargetList::TargetList(Debugger &debugger)
|
|
|
|
: Broadcaster(debugger.GetBroadcasterManager(),
|
|
|
|
TargetList::GetStaticBroadcasterClass().AsCString()),
|
|
|
|
m_target_list(), m_target_list_mutex(), m_selected_target_idx(0) {
|
2012-02-16 14:50:00 +08:00
|
|
|
CheckInWithManager();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status TargetList::CreateTarget(Debugger &debugger,
|
|
|
|
llvm::StringRef user_exe_path,
|
|
|
|
llvm::StringRef triple_str,
|
2018-09-20 17:09:05 +08:00
|
|
|
LoadDependentFiles load_dependent_files,
|
2017-05-12 12:51:55 +08:00
|
|
|
const OptionGroupPlatform *platform_options,
|
|
|
|
TargetSP &target_sp) {
|
2021-05-25 01:16:40 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-11 16:09:39 +08:00
|
|
|
auto result = TargetList::CreateTargetInternal(
|
|
|
|
debugger, user_exe_path, triple_str, load_dependent_files,
|
|
|
|
platform_options, target_sp);
|
|
|
|
|
|
|
|
if (target_sp && result.Success())
|
|
|
|
AddTargetInternal(target_sp, /*do_select*/ true);
|
|
|
|
return result;
|
2014-11-22 09:42:44 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status TargetList::CreateTarget(Debugger &debugger,
|
|
|
|
llvm::StringRef user_exe_path,
|
|
|
|
const ArchSpec &specified_arch,
|
2018-09-20 17:09:05 +08:00
|
|
|
LoadDependentFiles load_dependent_files,
|
2017-05-12 12:51:55 +08:00
|
|
|
PlatformSP &platform_sp, TargetSP &target_sp) {
|
2021-05-25 01:16:40 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-11 16:09:39 +08:00
|
|
|
auto result = TargetList::CreateTargetInternal(
|
|
|
|
debugger, user_exe_path, specified_arch, load_dependent_files,
|
|
|
|
platform_sp, target_sp);
|
|
|
|
|
|
|
|
if (target_sp && result.Success())
|
|
|
|
AddTargetInternal(target_sp, /*do_select*/ true);
|
|
|
|
return result;
|
2014-11-22 09:42:44 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status TargetList::CreateTargetInternal(
|
2016-11-19 04:44:46 +08:00
|
|
|
Debugger &debugger, llvm::StringRef user_exe_path,
|
2018-09-20 17:09:05 +08:00
|
|
|
llvm::StringRef triple_str, LoadDependentFiles load_dependent_files,
|
2020-11-06 03:38:50 +08:00
|
|
|
const OptionGroupPlatform *platform_options, TargetSP &target_sp) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-02-25 21:47:27 +08:00
|
|
|
PlatformList &platform_list = debugger.GetPlatformList();
|
2020-07-29 23:59:57 +08:00
|
|
|
// Let's start by looking at the selected platform.
|
2022-02-25 21:47:27 +08:00
|
|
|
PlatformSP platform_sp = platform_list.GetSelectedPlatform();
|
2020-07-29 23:59:57 +08:00
|
|
|
|
|
|
|
// This variable corresponds to the architecture specified by the triple
|
|
|
|
// string. If that string was empty the currently selected platform will
|
|
|
|
// determine the architecture.
|
2016-11-19 04:44:46 +08:00
|
|
|
const ArchSpec arch(triple_str);
|
2020-07-29 23:59:57 +08:00
|
|
|
if (!triple_str.empty() && !arch.IsValid()) {
|
|
|
|
error.SetErrorStringWithFormat("invalid triple '%s'",
|
|
|
|
triple_str.str().c_str());
|
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-25 06:29:28 +08:00
|
|
|
|
2014-07-11 07:33:37 +08:00
|
|
|
ArchSpec platform_arch(arch);
|
2015-01-22 06:42:49 +08:00
|
|
|
|
2020-07-29 23:59:57 +08:00
|
|
|
// Create a new platform if a platform was specified in the platform options
|
|
|
|
// and doesn't match the selected platform.
|
|
|
|
if (platform_options && platform_options->PlatformWasSpecified() &&
|
|
|
|
!platform_options->PlatformMatches(platform_sp)) {
|
|
|
|
const bool select_platform = true;
|
|
|
|
platform_sp = platform_options->CreatePlatformWithOptions(
|
|
|
|
debugger.GetCommandInterpreter(), arch, select_platform, error,
|
|
|
|
platform_arch);
|
|
|
|
if (!platform_sp)
|
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-07-29 23:59:57 +08:00
|
|
|
bool prefer_platform_arch = false;
|
2020-08-07 01:52:16 +08:00
|
|
|
auto update_platform_arch = [&](const ArchSpec &module_arch) {
|
|
|
|
// If the OS or vendor weren't specified, then adopt the module's
|
|
|
|
// architecture so that the platform matching can be more accurate.
|
|
|
|
if (!platform_arch.TripleOSWasSpecified() ||
|
|
|
|
!platform_arch.TripleVendorWasSpecified()) {
|
|
|
|
prefer_platform_arch = true;
|
|
|
|
platform_arch = module_arch;
|
|
|
|
}
|
|
|
|
};
|
2020-07-29 23:59:57 +08:00
|
|
|
|
2016-11-19 04:44:46 +08:00
|
|
|
if (!user_exe_path.empty()) {
|
2020-07-29 23:59:57 +08:00
|
|
|
ModuleSpec module_spec(FileSpec(user_exe_path, FileSpec::Style::native));
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSystem::Instance().Resolve(module_spec.GetFileSpec());
|
2014-07-30 05:27:21 +08:00
|
|
|
// Resolve the executable in case we are given a path to a application
|
2020-07-29 23:59:57 +08:00
|
|
|
// bundle like a .app bundle on MacOSX.
|
2014-07-30 05:27:21 +08:00
|
|
|
Host::ResolveExecutableInBundle(module_spec.GetFileSpec());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-25 06:29:28 +08:00
|
|
|
lldb::offset_t file_offset = 0;
|
2013-07-13 06:07:46 +08:00
|
|
|
lldb::offset_t file_size = 0;
|
2020-07-29 23:59:57 +08:00
|
|
|
ModuleSpecList module_specs;
|
2013-07-13 06:07:46 +08:00
|
|
|
const size_t num_specs = ObjectFile::GetModuleSpecifications(
|
|
|
|
module_spec.GetFileSpec(), file_offset, file_size, module_specs);
|
2020-07-29 23:59:57 +08:00
|
|
|
|
2013-04-25 06:29:28 +08:00
|
|
|
if (num_specs > 0) {
|
|
|
|
ModuleSpec matching_module_spec;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-25 06:29:28 +08:00
|
|
|
if (num_specs == 1) {
|
|
|
|
if (module_specs.GetModuleSpecAtIndex(0, matching_module_spec)) {
|
|
|
|
if (platform_arch.IsValid()) {
|
2014-07-11 07:33:37 +08:00
|
|
|
if (platform_arch.IsCompatibleMatch(
|
|
|
|
matching_module_spec.GetArchitecture())) {
|
|
|
|
// If the OS or vendor weren't specified, then adopt the module's
|
2018-05-01 00:49:04 +08:00
|
|
|
// architecture so that the platform matching can be more
|
2020-07-29 23:59:57 +08:00
|
|
|
// accurate.
|
2020-08-07 01:52:16 +08:00
|
|
|
update_platform_arch(matching_module_spec.GetArchitecture());
|
2014-07-11 07:33:37 +08:00
|
|
|
} else {
|
2015-10-14 07:41:19 +08:00
|
|
|
StreamString platform_arch_strm;
|
|
|
|
StreamString module_arch_strm;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-12-04 15:27:43 +08:00
|
|
|
platform_arch.DumpTriple(platform_arch_strm.AsRawOstream());
|
2015-10-14 07:41:19 +08:00
|
|
|
matching_module_spec.GetArchitecture().DumpTriple(
|
2019-12-04 15:27:43 +08:00
|
|
|
module_arch_strm.AsRawOstream());
|
2013-04-30 01:25:54 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"the specified architecture '%s' is not compatible with '%s' "
|
|
|
|
"in '%s'",
|
2016-11-17 05:15:24 +08:00
|
|
|
platform_arch_strm.GetData(), module_arch_strm.GetData(),
|
2013-04-30 01:25:54 +08:00
|
|
|
module_spec.GetFileSpec().GetPath().c_str());
|
2013-04-25 06:29:28 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
} else {
|
2020-07-29 23:59:57 +08:00
|
|
|
// Only one arch and none was specified.
|
2014-07-11 07:33:37 +08:00
|
|
|
prefer_platform_arch = true;
|
2013-04-25 06:29:28 +08:00
|
|
|
platform_arch = matching_module_spec.GetArchitecture();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2020-07-29 23:59:57 +08:00
|
|
|
} else if (arch.IsValid()) {
|
2020-08-07 01:52:16 +08:00
|
|
|
// Fat binary. A (valid) architecture was specified.
|
2020-07-29 23:59:57 +08:00
|
|
|
module_spec.GetArchitecture() = arch;
|
|
|
|
if (module_specs.FindMatchingModuleSpec(module_spec,
|
2020-08-07 01:52:16 +08:00
|
|
|
matching_module_spec))
|
|
|
|
update_platform_arch(matching_module_spec.GetArchitecture());
|
2013-04-25 06:29:28 +08:00
|
|
|
} else {
|
2020-08-07 01:52:16 +08:00
|
|
|
// Fat binary. No architecture specified, check if there is
|
|
|
|
// only one platform for all of the architectures.
|
2022-03-31 01:36:18 +08:00
|
|
|
std::vector<PlatformSP> candidates;
|
|
|
|
std::vector<ArchSpec> archs;
|
|
|
|
for (const ModuleSpec &spec : module_specs.ModuleSpecs())
|
|
|
|
archs.push_back(spec.GetArchitecture());
|
|
|
|
if (PlatformSP platform_for_archs_sp =
|
2022-02-25 21:47:27 +08:00
|
|
|
platform_list.GetOrCreate(archs, {}, candidates)) {
|
2022-03-31 01:36:18 +08:00
|
|
|
platform_sp = platform_for_archs_sp;
|
|
|
|
} else if (candidates.empty()) {
|
2020-07-29 23:59:57 +08:00
|
|
|
error.SetErrorString("no matching platforms found for this file");
|
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
// More than one platform claims to support this file.
|
|
|
|
StreamString error_strm;
|
2022-03-31 01:36:18 +08:00
|
|
|
std::set<llvm::StringRef> platform_set;
|
2020-07-29 23:59:57 +08:00
|
|
|
error_strm.Printf(
|
|
|
|
"more than one platform supports this executable (");
|
2022-03-31 01:36:18 +08:00
|
|
|
for (const auto &candidate : candidates) {
|
|
|
|
llvm::StringRef platform_name = candidate->GetName();
|
|
|
|
if (platform_set.count(platform_name))
|
|
|
|
continue;
|
|
|
|
if (!platform_set.empty())
|
|
|
|
error_strm.PutCString(", ");
|
|
|
|
error_strm.PutCString(platform_name);
|
|
|
|
platform_set.insert(platform_name);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-07-29 23:59:57 +08:00
|
|
|
error_strm.Printf("), specify an architecture to disambiguate");
|
|
|
|
error.SetErrorString(error_strm.GetString());
|
|
|
|
return error;
|
2013-04-25 06:29:28 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-25 06:29:28 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-05-12 05:23:31 +08:00
|
|
|
// If we have a valid architecture, make sure the current platform is
|
2020-07-29 23:59:57 +08:00
|
|
|
// compatible with that architecture.
|
2015-05-12 05:23:31 +08:00
|
|
|
if (!prefer_platform_arch && arch.IsValid()) {
|
2022-03-15 03:14:16 +08:00
|
|
|
if (!platform_sp->IsCompatibleArchitecture(arch, {}, false, nullptr)) {
|
2022-02-25 21:47:27 +08:00
|
|
|
platform_sp = platform_list.GetOrCreate(arch, {}, &platform_arch);
|
2020-11-06 03:38:50 +08:00
|
|
|
if (platform_sp)
|
2022-02-25 21:47:27 +08:00
|
|
|
platform_list.SetSelectedPlatform(platform_sp);
|
2015-05-12 05:23:31 +08:00
|
|
|
}
|
|
|
|
} else if (platform_arch.IsValid()) {
|
2020-07-29 23:59:57 +08:00
|
|
|
// If "arch" isn't valid, yet "platform_arch" is, it means we have an
|
|
|
|
// executable file with a single architecture which should be used.
|
2015-05-12 05:23:31 +08:00
|
|
|
ArchSpec fixed_platform_arch;
|
2022-02-25 21:47:27 +08:00
|
|
|
if (!platform_sp->IsCompatibleArchitecture(platform_arch, {}, false, nullptr)) {
|
|
|
|
platform_sp =
|
|
|
|
platform_list.GetOrCreate(platform_arch, {}, &fixed_platform_arch);
|
2020-11-06 03:38:50 +08:00
|
|
|
if (platform_sp)
|
2022-02-25 21:47:27 +08:00
|
|
|
platform_list.SetSelectedPlatform(platform_sp);
|
2011-09-24 08:52:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 09:42:44 +08:00
|
|
|
if (!platform_arch.IsValid())
|
|
|
|
platform_arch = arch;
|
|
|
|
|
2020-11-06 03:38:50 +08:00
|
|
|
return TargetList::CreateTargetInternal(debugger, user_exe_path,
|
|
|
|
platform_arch, load_dependent_files,
|
|
|
|
platform_sp, target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-05-08 09:45:38 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status TargetList::CreateTargetInternal(Debugger &debugger,
|
|
|
|
llvm::StringRef user_exe_path,
|
|
|
|
const ArchSpec &specified_arch,
|
2018-09-20 17:09:05 +08:00
|
|
|
LoadDependentFiles load_dependent_files,
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb::PlatformSP &platform_sp,
|
2020-11-06 03:38:50 +08:00
|
|
|
lldb::TargetSP &target_sp) {
|
2020-12-22 05:41:57 +08:00
|
|
|
LLDB_SCOPED_TIMERF("TargetList::CreateTarget (file = '%s', arch = '%s')",
|
|
|
|
user_exe_path.str().c_str(),
|
|
|
|
specified_arch.GetArchitectureName());
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2020-11-06 03:38:50 +08:00
|
|
|
const bool is_dummy_target = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-05-08 09:45:38 +08:00
|
|
|
ArchSpec arch(specified_arch);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-06 05:17:09 +08:00
|
|
|
if (arch.IsValid()) {
|
|
|
|
if (!platform_sp ||
|
2022-03-15 03:14:16 +08:00
|
|
|
!platform_sp->IsCompatibleArchitecture(arch, {}, false, nullptr))
|
|
|
|
platform_sp =
|
2022-02-25 21:47:27 +08:00
|
|
|
debugger.GetPlatformList().GetOrCreate(specified_arch, {}, &arch);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-08-08 01:33:36 +08:00
|
|
|
if (!platform_sp)
|
|
|
|
platform_sp = debugger.GetPlatformList().GetSelectedPlatform();
|
2013-08-01 07:27:46 +08:00
|
|
|
|
2015-06-10 01:54:27 +08:00
|
|
|
if (!arch.IsValid())
|
2013-04-04 08:15:09 +08:00
|
|
|
arch = specified_arch;
|
2012-10-19 00:33:33 +08:00
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec file(user_exe_path);
|
2018-11-02 01:09:25 +08:00
|
|
|
if (!FileSystem::Instance().Exists(file) && user_exe_path.startswith("~")) {
|
2015-12-15 09:33:19 +08:00
|
|
|
// we want to expand the tilde but we don't want to resolve any symbolic
|
2017-03-23 01:33:23 +08:00
|
|
|
// links so we can't use the FileSpec constructor's resolve flag
|
|
|
|
llvm::SmallString<64> unglobbed_path;
|
2018-11-09 09:59:28 +08:00
|
|
|
StandardTildeExpressionResolver Resolver;
|
|
|
|
Resolver.ResolveFullPath(user_exe_path, unglobbed_path);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-09 06:40:15 +08:00
|
|
|
if (unglobbed_path.empty())
|
2018-11-02 05:05:36 +08:00
|
|
|
file = FileSpec(user_exe_path);
|
2011-03-09 06:40:15 +08:00
|
|
|
else
|
2018-11-02 05:05:36 +08:00
|
|
|
file = FileSpec(unglobbed_path.c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-10-26 06:45:35 +08:00
|
|
|
bool user_exe_path_is_bundle = false;
|
2015-12-15 09:33:19 +08:00
|
|
|
char resolved_bundle_exe_path[PATH_MAX];
|
2012-10-26 06:45:35 +08:00
|
|
|
resolved_bundle_exe_path[0] = '\0';
|
2011-03-09 06:40:15 +08:00
|
|
|
if (file) {
|
2018-11-08 08:14:50 +08:00
|
|
|
if (FileSystem::Instance().IsDirectory(file))
|
2012-10-26 06:45:35 +08:00
|
|
|
user_exe_path_is_bundle = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-11-19 04:44:46 +08:00
|
|
|
if (file.IsRelative() && !user_exe_path.empty()) {
|
2018-05-07 22:21:04 +08:00
|
|
|
llvm::SmallString<64> cwd;
|
|
|
|
if (! llvm::sys::fs::current_path(cwd)) {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec cwd_file(cwd.c_str());
|
2018-05-07 22:21:04 +08:00
|
|
|
cwd_file.AppendPathComponent(file);
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(cwd_file))
|
2018-05-07 22:21:04 +08:00
|
|
|
file = cwd_file;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-08-10 07:31:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-09 06:40:15 +08:00
|
|
|
ModuleSP exe_module_sp;
|
|
|
|
if (platform_sp) {
|
|
|
|
FileSpecList executable_search_paths(
|
2014-11-22 09:42:44 +08:00
|
|
|
Target::GetDefaultExecutableSearchPaths());
|
|
|
|
ModuleSpec module_spec(file, arch);
|
|
|
|
error = platform_sp->ResolveExecutable(module_spec, exe_module_sp,
|
|
|
|
executable_search_paths.GetSize()
|
2012-10-19 00:33:33 +08:00
|
|
|
? &executable_search_paths
|
2015-11-21 12:00:43 +08:00
|
|
|
: nullptr);
|
2011-03-09 06:40:15 +08:00
|
|
|
}
|
2010-09-27 08:30:10 +08:00
|
|
|
|
2012-10-26 06:45:35 +08:00
|
|
|
if (error.Success() && exe_module_sp) {
|
|
|
|
if (exe_module_sp->GetObjectFile() == nullptr) {
|
|
|
|
if (arch.IsValid()) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"\"%s\" doesn't contain architecture %s", file.GetPath().c_str(),
|
|
|
|
arch.GetArchitectureName());
|
|
|
|
} else {
|
2013-08-01 07:27:46 +08:00
|
|
|
error.SetErrorStringWithFormat("unsupported file type \"%s\"",
|
|
|
|
file.GetPath().c_str());
|
2012-10-19 00:33:33 +08:00
|
|
|
}
|
2011-09-24 08:52:29 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-11-22 09:42:44 +08:00
|
|
|
target_sp.reset(new Target(debugger, arch, platform_sp, is_dummy_target));
|
2018-09-20 17:09:05 +08:00
|
|
|
target_sp->SetExecutableModule(exe_module_sp, load_dependent_files);
|
2012-10-26 06:45:35 +08:00
|
|
|
if (user_exe_path_is_bundle)
|
2011-08-11 10:48:45 +08:00
|
|
|
exe_module_sp->GetFileSpec().GetPath(resolved_bundle_exe_path,
|
2012-10-26 06:45:35 +08:00
|
|
|
sizeof(resolved_bundle_exe_path));
|
2020-05-14 22:05:40 +08:00
|
|
|
if (target_sp->GetPreloadSymbols())
|
|
|
|
exe_module_sp->PreloadSymbols();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// No file was specified, just create an empty target with any arch if a
|
|
|
|
// valid arch was specified
|
2014-11-22 09:42:44 +08:00
|
|
|
target_sp.reset(new Target(debugger, arch, platform_sp, is_dummy_target));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-08-01 04:30:59 +08:00
|
|
|
if (!target_sp)
|
|
|
|
return error;
|
2014-11-22 09:42:44 +08:00
|
|
|
|
2020-08-01 04:30:59 +08:00
|
|
|
// Set argv0 with what the user typed, unless the user specified a
|
|
|
|
// directory. If the user specified a directory, then it is probably a
|
|
|
|
// bundle that was resolved and we need to use the resolved bundle path
|
|
|
|
if (!user_exe_path.empty()) {
|
|
|
|
// Use exactly what the user typed as the first argument when we exec or
|
|
|
|
// posix_spawn
|
|
|
|
if (user_exe_path_is_bundle && resolved_bundle_exe_path[0]) {
|
|
|
|
target_sp->SetArg0(resolved_bundle_exe_path);
|
2014-11-22 09:42:44 +08:00
|
|
|
} else {
|
2020-08-01 04:30:59 +08:00
|
|
|
// Use resolved path
|
|
|
|
target_sp->SetArg0(file.GetPath().c_str());
|
2010-08-10 07:31:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-08-01 04:30:59 +08:00
|
|
|
if (file.GetDirectory()) {
|
|
|
|
FileSpec file_dir;
|
|
|
|
file_dir.GetDirectory() = file.GetDirectory();
|
|
|
|
target_sp->AppendExecutableSearchPaths(file_dir);
|
|
|
|
}
|
|
|
|
|
2020-11-06 03:38:50 +08:00
|
|
|
// Now prime this from the dummy target:
|
|
|
|
target_sp->PrimeFromDummyTarget(debugger.GetDummyTarget());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetList::DeleteTarget(TargetSP &target_sp) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-02 23:52:50 +08:00
|
|
|
auto it = std::find(m_target_list.begin(), m_target_list.end(), target_sp);
|
|
|
|
if (it == m_target_list.end())
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-12-02 23:52:50 +08:00
|
|
|
m_target_list.erase(it);
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 09:33:19 +08:00
|
|
|
TargetSP TargetList::FindTargetWithExecutableAndArchitecture(
|
|
|
|
const FileSpec &exe_file_spec, const ArchSpec *exe_arch_ptr) const {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-02 23:52:50 +08:00
|
|
|
auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
|
|
|
|
[&exe_file_spec, exe_arch_ptr](const TargetSP &item) {
|
|
|
|
Module *exe_module = item->GetExecutableModulePointer();
|
|
|
|
if (!exe_module ||
|
|
|
|
!FileSpec::Match(exe_file_spec, exe_module->GetFileSpec()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !exe_arch_ptr ||
|
|
|
|
exe_arch_ptr->IsCompatibleMatch(exe_module->GetArchitecture());
|
|
|
|
});
|
|
|
|
|
|
|
|
if (it != m_target_list.end())
|
|
|
|
return *it;
|
|
|
|
|
|
|
|
return TargetSP();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetSP TargetList::FindTargetWithProcessID(lldb::pid_t pid) const {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-02 23:52:50 +08:00
|
|
|
auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
|
|
|
|
[pid](const TargetSP &item) {
|
|
|
|
auto *process_ptr = item->GetProcessSP().get();
|
|
|
|
return process_ptr && (process_ptr->GetID() == pid);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (it != m_target_list.end())
|
|
|
|
return *it;
|
|
|
|
|
|
|
|
return TargetSP();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetSP TargetList::FindTargetWithProcess(Process *process) const {
|
|
|
|
TargetSP target_sp;
|
2020-12-02 23:52:50 +08:00
|
|
|
if (!process)
|
|
|
|
return target_sp;
|
|
|
|
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
|
|
|
auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
|
|
|
|
[process](const TargetSP &item) {
|
|
|
|
return item->GetProcessSP().get() == process;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (it != m_target_list.end())
|
|
|
|
target_sp = *it;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return target_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetSP TargetList::GetTargetSP(Target *target) const {
|
|
|
|
TargetSP target_sp;
|
2020-12-02 23:52:50 +08:00
|
|
|
if (!target)
|
|
|
|
return target_sp;
|
|
|
|
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
|
|
|
auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
|
|
|
|
[target](const TargetSP &item) { return item.get() == target; });
|
|
|
|
if (it != m_target_list.end())
|
|
|
|
target_sp = *it;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return target_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TargetList::SendAsyncInterrupt(lldb::pid_t pid) {
|
|
|
|
uint32_t num_async_interrupts_sent = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (pid != LLDB_INVALID_PROCESS_ID) {
|
|
|
|
TargetSP target_sp(FindTargetWithProcessID(pid));
|
2015-12-15 09:33:19 +08:00
|
|
|
if (target_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
Process *process = target_sp->GetProcessSP().get();
|
|
|
|
if (process) {
|
2012-07-28 07:57:19 +08:00
|
|
|
process->SendAsyncInterrupt();
|
2010-06-09 00:52:24 +08:00
|
|
|
++num_async_interrupts_sent;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
// We don't have a valid pid to broadcast to, so broadcast to the target
|
|
|
|
// list's async broadcaster...
|
2015-12-15 09:33:19 +08:00
|
|
|
BroadcastEvent(Process::eBroadcastBitInterrupt, nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return num_async_interrupts_sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TargetList::SignalIfRunning(lldb::pid_t pid, int signo) {
|
|
|
|
uint32_t num_signals_sent = 0;
|
2015-12-15 09:33:19 +08:00
|
|
|
Process *process = nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (pid == LLDB_INVALID_PROCESS_ID) {
|
|
|
|
// Signal all processes with signal
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-02 23:52:50 +08:00
|
|
|
for (const auto &target_sp : m_target_list) {
|
|
|
|
process = target_sp->GetProcessSP().get();
|
|
|
|
if (process && process->IsAlive()) {
|
|
|
|
++num_signals_sent;
|
|
|
|
process->Signal(signo);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Signal a specific process with signal
|
|
|
|
TargetSP target_sp(FindTargetWithProcessID(pid));
|
2015-12-15 09:33:19 +08:00
|
|
|
if (target_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
process = target_sp->GetProcessSP().get();
|
2020-12-02 23:52:50 +08:00
|
|
|
if (process && process->IsAlive()) {
|
|
|
|
++num_signals_sent;
|
|
|
|
process->Signal(signo);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return num_signals_sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TargetList::GetNumTargets() const {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_target_list.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::TargetSP TargetList::GetTargetAtIndex(uint32_t idx) const {
|
|
|
|
TargetSP target_sp;
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_target_list.size())
|
|
|
|
target_sp = m_target_list[idx];
|
|
|
|
return target_sp;
|
|
|
|
}
|
|
|
|
|
2012-05-09 07:06:07 +08:00
|
|
|
uint32_t TargetList::GetIndexOfTarget(lldb::TargetSP target_sp) const {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-02 23:52:50 +08:00
|
|
|
auto it = std::find(m_target_list.begin(), m_target_list.end(), target_sp);
|
|
|
|
if (it != m_target_list.end())
|
|
|
|
return std::distance(m_target_list.begin(), it);
|
2012-05-09 07:06:07 +08:00
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:09:39 +08:00
|
|
|
void TargetList::AddTargetInternal(TargetSP target_sp, bool do_select) {
|
|
|
|
lldbassert(std::find(m_target_list.begin(), m_target_list.end(), target_sp) ==
|
|
|
|
m_target_list.end() &&
|
|
|
|
"target already exists it the list");
|
|
|
|
m_target_list.push_back(std::move(target_sp));
|
|
|
|
if (do_select)
|
|
|
|
SetSelectedTargetInternal(m_target_list.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TargetList::SetSelectedTargetInternal(uint32_t index) {
|
|
|
|
lldbassert(!m_target_list.empty());
|
|
|
|
m_selected_target_idx = index < m_target_list.size() ? index : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TargetList::SetSelectedTarget(uint32_t index) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2020-12-11 16:09:39 +08:00
|
|
|
SetSelectedTargetInternal(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TargetList::SetSelectedTarget(const TargetSP &target_sp) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
|
|
|
auto it = std::find(m_target_list.begin(), m_target_list.end(), target_sp);
|
|
|
|
SetSelectedTargetInternal(std::distance(m_target_list.begin(), it));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
lldb::TargetSP TargetList::GetSelectedTarget() {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_target_list_mutex);
|
2010-08-27 05:32:51 +08:00
|
|
|
if (m_selected_target_idx >= m_target_list.size())
|
|
|
|
m_selected_target_idx = 0;
|
|
|
|
return GetTargetAtIndex(m_selected_target_idx);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|