[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
|
|
|
//===-- ProcessKDP.cpp ----------------------------------------------------===//
|
2011-07-15 11:27: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
|
2011-07-15 11:27:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdlib>
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <memory>
|
2015-04-03 18:55:00 +08:00
|
|
|
#include <mutex>
|
|
|
|
|
2011-07-20 11:41:06 +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"
|
2012-09-29 12:02:01 +08:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2011-07-15 11:27:12 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
2014-10-07 05:22:36 +08:00
|
|
|
#include "lldb/Host/ConnectionFileDescriptor.h"
|
2011-07-15 11:27:12 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/ThreadLauncher.h"
|
2015-10-16 07:54:09 +08:00
|
|
|
#include "lldb/Host/common/TCPSocket.h"
|
2012-10-20 06:22:57 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandObject.h"
|
|
|
|
#include "lldb/Interpreter/CommandObjectMultiword.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
#include "lldb/Interpreter/OptionGroupString.h"
|
|
|
|
#include "lldb/Interpreter/OptionGroupUInt64.h"
|
2015-03-04 20:05:24 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueProperties.h"
|
Move Host/Symbols.cpp to Symbols/LocateSymbolFile.cpp
Given that we have a target named Symbols, one wonders why a
file named Symbols.cpp is not in this target. To be clear,
the functions exposed from this file are really focused on
*locating* a symbol file on a given host, which is where the
ambiguity comes in. However, it makes more sense conceptually
to be in the Symbols target. While some of the specific places
to search for symbol files might change depending on the Host,
this is not inherently true in the same way that, for example,
"accessing the file system" or "starting threads" is
fundamentally dependent on the Host.
PDBs, for example, recently became a reality on non-Windows platforms,
and it's theoretically possible that DSYMs could become a thing on non
MacOSX platforms (maybe in a remote debugging scenario). Other types of
symbol files, such as DWO, DWP, etc have never been tied to any Host
platform anyway.
After this patch, there is only one remaining dependency from
Host to Target.
Differential Revision: https://reviews.llvm.org/D58730
llvm-svn: 355032
2019-02-28 05:42:10 +08:00
|
|
|
#include "lldb/Symbol/LocateSymbolFile.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/Symbol/ObjectFile.h"
|
2012-09-22 00:31:20 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2011-07-16 00:31:38 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2011-07-19 11:57:15 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2019-07-06 01:42:08 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2015-07-08 07:59:01 +08:00
|
|
|
#include "lldb/Utility/StringExtractor.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/UUID.h"
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2017-02-07 01:55:02 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
|
|
|
|
2013-08-27 13:04:57 +08:00
|
|
|
#define USEC_PER_SEC 1000000
|
|
|
|
|
2012-10-03 09:29:34 +08:00
|
|
|
#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
|
2012-10-25 08:25:13 +08:00
|
|
|
#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
|
2011-07-15 11:27:12 +08:00
|
|
|
#include "ProcessKDP.h"
|
|
|
|
#include "ProcessKDPLog.h"
|
2011-07-19 11:57:15 +08:00
|
|
|
#include "ThreadKDP.h"
|
2011-07-15 11:27:12 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-02-18 11:59:03 +08:00
|
|
|
LLDB_PLUGIN_DEFINE_ADV(ProcessKDP, ProcessMacOSXKernel)
|
2020-02-08 06:58:18 +08:00
|
|
|
|
2013-07-16 06:54:20 +08:00
|
|
|
namespace {
|
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
#define LLDB_PROPERTIES_processkdp
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "ProcessKDPProperties.inc"
|
2013-07-16 06:54:20 +08:00
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
enum {
|
|
|
|
#define LLDB_PROPERTIES_processkdp
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "ProcessKDPPropertiesEnum.inc"
|
2019-07-26 05:36:37 +08:00
|
|
|
};
|
2013-07-16 06:54:20 +08:00
|
|
|
|
|
|
|
class PluginProperties : public Properties {
|
2016-09-07 04:57:50 +08:00
|
|
|
public:
|
2013-05-11 05:47:16 +08:00
|
|
|
static ConstString GetSettingName() {
|
2021-10-23 01:53:43 +08:00
|
|
|
return ConstString(ProcessKDP::GetPluginNameStatic());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-16 06:54:20 +08:00
|
|
|
PluginProperties() : Properties() {
|
2019-02-12 07:13:08 +08:00
|
|
|
m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
|
2019-07-30 00:41:30 +08:00
|
|
|
m_collection_sp->Initialize(g_processkdp_properties);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-23 04:28:59 +08:00
|
|
|
~PluginProperties() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-16 06:54:20 +08:00
|
|
|
uint64_t GetPacketTimeout() {
|
2019-07-26 05:36:37 +08:00
|
|
|
const uint32_t idx = ePropertyKDPPacketTimeout;
|
2013-07-16 06:54:20 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
2019-07-30 00:41:30 +08:00
|
|
|
NULL, idx, g_processkdp_properties[idx].default_uint_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-07 21:44:47 +08:00
|
|
|
static PluginProperties &GetGlobalPluginProperties() {
|
|
|
|
static PluginProperties g_settings;
|
|
|
|
return g_settings;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-07-16 06:54:20 +08:00
|
|
|
|
|
|
|
} // anonymous namespace end
|
|
|
|
|
2013-05-08 02:35:34 +08:00
|
|
|
static const lldb::tid_t g_kernel_tid = 1;
|
|
|
|
|
2021-10-23 01:53:43 +08:00
|
|
|
llvm::StringRef ProcessKDP::GetPluginDescriptionStatic() {
|
2011-07-15 11:27:12 +08:00
|
|
|
return "KDP Remote protocol based debugging plug-in for darwin kernel "
|
|
|
|
"debugging.";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessKDP::Terminate() {
|
|
|
|
PluginManager::UnregisterPlugin(ProcessKDP::CreateInstance);
|
|
|
|
}
|
|
|
|
|
2015-09-02 06:56:59 +08:00
|
|
|
lldb::ProcessSP ProcessKDP::CreateInstance(TargetSP target_sp,
|
2016-03-08 05:50:25 +08:00
|
|
|
ListenerSP listener_sp,
|
2020-11-21 00:12:22 +08:00
|
|
|
const FileSpec *crash_file_path,
|
|
|
|
bool can_connect) {
|
2012-02-09 14:16:32 +08:00
|
|
|
lldb::ProcessSP process_sp;
|
|
|
|
if (crash_file_path == NULL)
|
2019-02-12 07:13:08 +08:00
|
|
|
process_sp = std::make_shared<ProcessKDP>(target_sp, listener_sp);
|
2012-02-09 14:16:32 +08:00
|
|
|
return process_sp;
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
2015-09-02 06:56:59 +08:00
|
|
|
bool ProcessKDP::CanDebug(TargetSP target_sp, bool plugin_specified_by_name) {
|
2011-10-22 05:41:45 +08:00
|
|
|
if (plugin_specified_by_name)
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
// For now we are just making sure the file exists for a given module
|
2015-09-02 06:56:59 +08:00
|
|
|
Module *exe_module = target_sp->GetExecutableModulePointer();
|
2011-08-11 10:48:45 +08:00
|
|
|
if (exe_module) {
|
2015-09-02 06:56:59 +08:00
|
|
|
const llvm::Triple &triple_ref = target_sp->GetArchitecture().GetTriple();
|
2012-05-08 09:45:38 +08:00
|
|
|
switch (triple_ref.getOS()) {
|
|
|
|
case llvm::Triple::Darwin: // Should use "macosx" for desktop and "ios" for
|
|
|
|
// iOS, but accept darwin just in case
|
|
|
|
case llvm::Triple::MacOSX: // For desktop targets
|
|
|
|
case llvm::Triple::IOS: // For arm targets
|
2015-11-06 07:03:44 +08:00
|
|
|
case llvm::Triple::TvOS:
|
|
|
|
case llvm::Triple::WatchOS:
|
2012-05-08 09:45:38 +08:00
|
|
|
if (triple_ref.getVendor() == llvm::Triple::Apple) {
|
|
|
|
ObjectFile *exe_objfile = exe_module->GetObjectFile();
|
|
|
|
if (exe_objfile->GetType() == ObjectFile::eTypeExecutable &&
|
|
|
|
exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-05-08 09:45:38 +08:00
|
|
|
default:
|
|
|
|
break;
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-10-22 05:41:45 +08:00
|
|
|
return false;
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProcessKDP constructor
|
2016-03-08 05:50:25 +08:00
|
|
|
ProcessKDP::ProcessKDP(TargetSP target_sp, ListenerSP listener_sp)
|
|
|
|
: Process(target_sp, listener_sp),
|
2011-07-15 11:27:12 +08:00
|
|
|
m_comm("lldb.process.kdp-remote.communication"),
|
2012-02-16 14:50:00 +08:00
|
|
|
m_async_broadcaster(NULL, "lldb.process.kdp-remote.async-broadcaster"),
|
2021-10-21 19:32:42 +08:00
|
|
|
m_kernel_load_addr(LLDB_INVALID_ADDRESS), m_command_sp(),
|
|
|
|
m_kernel_thread_wp() {
|
2012-09-22 00:31:20 +08:00
|
|
|
m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadShouldExit,
|
|
|
|
"async thread should exit");
|
|
|
|
m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue,
|
|
|
|
"async thread continue");
|
2013-07-16 06:54:20 +08:00
|
|
|
const uint64_t timeout_seconds =
|
2021-10-07 21:44:47 +08:00
|
|
|
GetGlobalPluginProperties().GetPacketTimeout();
|
2013-07-16 06:54:20 +08:00
|
|
|
if (timeout_seconds > 0)
|
2016-11-02 18:13:54 +08:00
|
|
|
m_comm.SetPacketTimeout(std::chrono::seconds(timeout_seconds));
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
ProcessKDP::~ProcessKDP() {
|
|
|
|
Clear();
|
2018-05-01 00:49:04 +08:00
|
|
|
// We need to call finalize on the process before destroying ourselves to
|
|
|
|
// make sure all of the broadcaster cleanup goes as planned. If we destruct
|
|
|
|
// this class, then Process::~Process() might have problems trying to fully
|
|
|
|
// destroy the broadcaster.
|
2011-11-17 12:46:02 +08:00
|
|
|
Finalize();
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
2022-09-13 23:30:07 +08:00
|
|
|
Status ProcessKDP::DoWillLaunch(Module *module) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString("launching not supported in kdp-remote plug-in");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2022-09-13 23:30:07 +08:00
|
|
|
Status ProcessKDP::DoWillAttachToProcessWithID(lldb::pid_t pid) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
|
|
|
"attaching to a by process ID not supported in kdp-remote plug-in");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2022-09-13 23:30:07 +08:00
|
|
|
Status ProcessKDP::DoWillAttachToProcessWithName(const char *process_name,
|
|
|
|
bool wait_for_launch) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
|
|
|
"attaching to a by process name not supported in kdp-remote plug-in");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-10-29 07:26:59 +08:00
|
|
|
bool ProcessKDP::GetHostArchitecture(ArchSpec &arch) {
|
|
|
|
uint32_t cpu = m_comm.GetCPUType();
|
|
|
|
if (cpu) {
|
|
|
|
uint32_t sub = m_comm.GetCPUSubtype();
|
|
|
|
arch.SetArchitecture(eArchTypeMachO, cpu, sub);
|
|
|
|
// Leave architecture vendor as unspecified unknown
|
|
|
|
arch.GetTriple().setVendor(llvm::Triple::UnknownVendor);
|
|
|
|
arch.GetTriple().setVendorName(llvm::StringRef());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
arch.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-14 04:44:01 +08:00
|
|
|
Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2012-09-22 00:31:20 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Don't let any JIT happen when doing KDP as we can't allocate memory and we
|
|
|
|
// don't want to be mucking with threads that might already be handling
|
|
|
|
// exceptions
|
2012-09-22 00:31:20 +08:00
|
|
|
SetCanJIT(false);
|
2011-07-18 04:36:25 +08:00
|
|
|
|
2016-12-08 07:51:49 +08:00
|
|
|
if (remote_url.empty()) {
|
|
|
|
error.SetErrorStringWithFormat("empty connection URL");
|
2012-09-22 00:31:20 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
std::unique_ptr<ConnectionFileDescriptor> conn_up(
|
2013-04-19 06:45:39 +08:00
|
|
|
new ConnectionFileDescriptor());
|
2019-02-13 14:25:41 +08:00
|
|
|
if (conn_up) {
|
2011-07-18 04:36:25 +08:00
|
|
|
// Only try once for now.
|
|
|
|
// TODO: check if we should be retrying?
|
|
|
|
const uint32_t max_retry_count = 1;
|
|
|
|
for (uint32_t retry_count = 0; retry_count < max_retry_count;
|
|
|
|
++retry_count) {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (conn_up->Connect(remote_url, &error) == eConnectionStatusSuccess)
|
2011-07-18 04:36:25 +08:00
|
|
|
break;
|
|
|
|
usleep(100000);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (conn_up->IsConnected()) {
|
2015-10-16 07:54:09 +08:00
|
|
|
const TCPSocket &socket =
|
2019-02-13 14:25:41 +08:00
|
|
|
static_cast<const TCPSocket &>(*conn_up->GetReadObject());
|
2015-01-16 08:47:08 +08:00
|
|
|
const uint16_t reply_port = socket.GetLocalPortNumber();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-18 04:36:25 +08:00
|
|
|
if (reply_port != 0) {
|
2020-04-02 20:40:59 +08:00
|
|
|
m_comm.SetConnection(std::move(conn_up));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-18 04:36:25 +08:00
|
|
|
if (m_comm.SendRequestReattach(reply_port)) {
|
|
|
|
if (m_comm.SendRequestConnect(reply_port, reply_port,
|
|
|
|
"Greetings from LLDB...")) {
|
|
|
|
m_comm.GetVersion();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-29 07:26:59 +08:00
|
|
|
Target &target = GetTarget();
|
|
|
|
ArchSpec kernel_arch;
|
|
|
|
// The host architecture
|
|
|
|
GetHostArchitecture(kernel_arch);
|
2012-09-29 12:02:01 +08:00
|
|
|
ArchSpec target_arch = target.GetArchitecture();
|
2014-07-17 05:16:27 +08:00
|
|
|
// Merge in any unspecified stuff into the target architecture in
|
|
|
|
// case the target arch isn't set at all or incompletely.
|
|
|
|
target_arch.MergeFrom(kernel_arch);
|
2015-09-02 06:56:59 +08:00
|
|
|
target.SetArchitecture(target_arch);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-17 05:16:27 +08:00
|
|
|
/* Get the kernel's UUID and load address via KDP_KERNELVERSION
|
|
|
|
* packet. */
|
|
|
|
/* An EFI kdp session has neither UUID nor load address. */
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-29 12:02:01 +08:00
|
|
|
UUID kernel_uuid = m_comm.GetUUID();
|
2014-07-17 05:16:27 +08:00
|
|
|
addr_t kernel_load_addr = m_comm.GetLoadAddress();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-17 05:16:27 +08:00
|
|
|
if (m_comm.RemoteIsEFI()) {
|
|
|
|
// Select an invalid plugin name for the dynamic loader so one
|
2018-05-01 00:49:04 +08:00
|
|
|
// doesn't get used since EFI does its own manual loading via
|
|
|
|
// python scripting
|
2021-10-21 19:32:42 +08:00
|
|
|
m_dyld_plugin_name = "none";
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-07 07:02:03 +08:00
|
|
|
if (kernel_uuid.IsValid()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If EFI passed in a UUID= try to lookup UUID The slide will not
|
|
|
|
// be provided. But the UUID lookup will be used to launch EFI
|
|
|
|
// debug scripts from the dSYM, that can load all of the symbols.
|
2014-07-17 05:16:27 +08:00
|
|
|
ModuleSpec module_spec;
|
2012-09-25 10:40:06 +08:00
|
|
|
module_spec.GetUUID() = kernel_uuid;
|
2015-09-02 06:56:59 +08:00
|
|
|
module_spec.GetArchitecture() = target.GetArchitecture();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-02 06:56:59 +08:00
|
|
|
// Lookup UUID locally, before attempting dsymForUUID like action
|
2019-03-07 02:44:27 +08:00
|
|
|
FileSpecList search_paths =
|
|
|
|
Target::GetDefaultDebugFileSearchPaths();
|
2015-09-02 06:56:59 +08:00
|
|
|
module_spec.GetSymbolFileSpec() =
|
2019-03-07 02:44:27 +08:00
|
|
|
Symbols::LocateExecutableSymbolFile(module_spec,
|
|
|
|
search_paths);
|
2011-07-21 09:12:01 +08:00
|
|
|
if (module_spec.GetSymbolFileSpec()) {
|
|
|
|
ModuleSpec executable_module_spec =
|
|
|
|
Symbols::LocateExecutableObjectFile(module_spec);
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(
|
|
|
|
executable_module_spec.GetFileSpec())) {
|
2011-07-21 09:12:01 +08:00
|
|
|
module_spec.GetFileSpec() =
|
|
|
|
executable_module_spec.GetFileSpec();
|
2011-07-18 04:36:25 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-07-17 05:16:27 +08:00
|
|
|
if (!module_spec.GetSymbolFileSpec() ||
|
2022-04-15 07:52:38 +08:00
|
|
|
!module_spec.GetSymbolFileSpec()) {
|
|
|
|
Status symbl_error;
|
|
|
|
Symbols::DownloadObjectAndSymbolFile(module_spec, symbl_error,
|
|
|
|
true);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
|
2015-10-29 07:26:59 +08:00
|
|
|
ModuleSP module_sp(new Module(module_spec));
|
2012-09-25 10:40:06 +08:00
|
|
|
if (module_sp.get() && module_sp->GetObjectFile()) {
|
|
|
|
// Get the current target executable
|
2015-09-02 06:56:59 +08:00
|
|
|
ModuleSP exe_module_sp(target.GetExecutableModule());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
// Make sure you don't already have the right module loaded
|
|
|
|
// and they will be uniqued
|
2014-07-17 05:16:27 +08:00
|
|
|
if (exe_module_sp.get() != module_sp.get())
|
2018-09-20 17:09:05 +08:00
|
|
|
target.SetExecutableModule(module_sp, eLoadDependentsNo);
|
2012-09-25 10:40:06 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-18 04:36:25 +08:00
|
|
|
}
|
|
|
|
} else if (m_comm.RemoteIsDarwinKernel()) {
|
2014-07-17 05:16:27 +08:00
|
|
|
m_dyld_plugin_name =
|
2012-09-25 10:40:06 +08:00
|
|
|
DynamicLoaderDarwinKernel::GetPluginNameStatic();
|
|
|
|
if (kernel_load_addr != LLDB_INVALID_ADDRESS) {
|
2013-05-07 07:02:03 +08:00
|
|
|
m_kernel_load_addr = kernel_load_addr;
|
2011-07-18 04:36:25 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-22 00:31:20 +08:00
|
|
|
// Set the thread ID
|
2012-09-25 10:40:06 +08:00
|
|
|
UpdateThreadListIfNeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
SetID(1);
|
2011-08-22 10:49:39 +08:00
|
|
|
GetThreadList();
|
2011-07-19 11:57:15 +08:00
|
|
|
SetPrivateState(eStateStopped);
|
2015-09-02 06:56:59 +08:00
|
|
|
StreamSP async_strm_sp(target.GetDebugger().GetAsyncOutputStream());
|
2011-07-20 11:41:06 +08:00
|
|
|
if (async_strm_sp) {
|
2011-07-21 09:12:01 +08:00
|
|
|
const char *cstr;
|
|
|
|
if ((cstr = m_comm.GetKernelVersion()) != NULL) {
|
|
|
|
async_strm_sp->Printf("Version: %s\n", cstr);
|
2011-07-20 11:41:06 +08:00
|
|
|
async_strm_sp->Flush();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-21 09:12:01 +08:00
|
|
|
// if ((cstr = m_comm.GetImagePath ()) != NULL)
|
2016-09-07 04:57:50 +08:00
|
|
|
// {
|
2011-07-21 09:12:01 +08:00
|
|
|
// async_strm_sp->Printf ("Image Path:
|
|
|
|
// %s\n", cstr);
|
|
|
|
// async_strm_sp->Flush();
|
2016-09-07 04:57:50 +08:00
|
|
|
// }
|
|
|
|
}
|
|
|
|
} else {
|
2011-07-21 09:12:01 +08:00
|
|
|
error.SetErrorString("KDP_REATTACH failed");
|
2011-07-18 04:36:25 +08:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-21 09:12:01 +08:00
|
|
|
error.SetErrorString("KDP_REATTACH failed");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-18 04:36:25 +08:00
|
|
|
} else {
|
|
|
|
error.SetErrorString("invalid reply port from UDP connection");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-07-18 04:36:25 +08:00
|
|
|
if (error.Success())
|
2016-12-08 07:51:49 +08:00
|
|
|
error.SetErrorStringWithFormat("failed to connect to '%s'",
|
|
|
|
remote_url.str().c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-18 04:36:25 +08:00
|
|
|
if (error.Fail())
|
|
|
|
m_comm.Disconnect();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process Control
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoLaunch(Module *exe_module,
|
|
|
|
ProcessLaunchInfo &launch_info) {
|
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString("launching not supported in kdp-remote plug-in");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status
|
|
|
|
ProcessKDP::DoAttachToProcessWithID(lldb::pid_t attach_pid,
|
|
|
|
const ProcessAttachInfo &attach_info) {
|
|
|
|
Status error;
|
2012-02-25 09:07:38 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"attach to process by ID is not supported in kdp remote debugging");
|
2012-02-25 09:07:38 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status
|
|
|
|
ProcessKDP::DoAttachToProcessWithName(const char *process_name,
|
|
|
|
const ProcessAttachInfo &attach_info) {
|
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"attach to process by name is not supported in kdp remote debugging");
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2014-08-02 08:33:35 +08:00
|
|
|
void ProcessKDP::DidAttach(ArchSpec &process_arch) {
|
|
|
|
Process::DidAttach(process_arch);
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Process);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::DidAttach()");
|
2011-07-15 11:27:12 +08:00
|
|
|
if (GetID() != LLDB_INVALID_PROCESS_ID) {
|
2015-10-29 07:26:59 +08:00
|
|
|
GetHostArchitecture(process_arch);
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 09:29:34 +08:00
|
|
|
addr_t ProcessKDP::GetImageInfoAddress() { return m_kernel_load_addr; }
|
|
|
|
|
|
|
|
lldb_private::DynamicLoader *ProcessKDP::GetDynamicLoader() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_dyld_up.get() == NULL)
|
2021-10-21 19:32:42 +08:00
|
|
|
m_dyld_up.reset(DynamicLoader::FindPlugin(this, m_dyld_plugin_name));
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_dyld_up.get();
|
2012-10-03 09:29:34 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::WillResume() { return Status(); }
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoResume() {
|
|
|
|
Status error;
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Process);
|
2013-04-03 04:32:37 +08:00
|
|
|
// Only start the async thread if we try to do any process control
|
|
|
|
if (!m_async_thread.IsJoinable())
|
2013-05-09 09:55:29 +08:00
|
|
|
StartAsyncThread();
|
2012-09-25 10:40:06 +08:00
|
|
|
|
|
|
|
bool resume = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
// With KDP there is only one thread we can tell what to do
|
2012-09-22 00:31:20 +08:00
|
|
|
ThreadSP kernel_thread_sp(m_thread_list.FindThreadByProtocolID(g_kernel_tid));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 00:31:20 +08:00
|
|
|
if (kernel_thread_sp) {
|
|
|
|
const StateType thread_resume_state =
|
|
|
|
kernel_thread_sp->GetTemporaryResumeState();
|
2012-09-25 10:40:06 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::DoResume() thread_resume_state = %s",
|
|
|
|
StateAsCString(thread_resume_state));
|
2012-09-25 10:40:06 +08:00
|
|
|
switch (thread_resume_state) {
|
2012-09-22 00:31:20 +08:00
|
|
|
case eStateSuspended:
|
2018-05-01 00:49:04 +08:00
|
|
|
// Nothing to do here when a thread will stay suspended we just leave the
|
|
|
|
// CPU mask bit set to zero for the thread
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::DoResume() = suspended???");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-09-21 09:55:30 +08:00
|
|
|
case eStateStepping: {
|
2013-04-03 04:32:37 +08:00
|
|
|
lldb::RegisterContextSP reg_ctx_sp(
|
|
|
|
kernel_thread_sp->GetRegisterContext());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-03 04:32:37 +08:00
|
|
|
if (reg_ctx_sp) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(
|
|
|
|
log,
|
|
|
|
"ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep (true);");
|
2013-05-09 09:55:29 +08:00
|
|
|
reg_ctx_sp->HardwareSingleStep(true);
|
2013-04-03 04:32:37 +08:00
|
|
|
resume = true;
|
2012-09-25 10:40:06 +08:00
|
|
|
} else {
|
2013-05-09 09:55:29 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"KDP thread 0x%llx has no register context",
|
2013-04-03 04:32:37 +08:00
|
|
|
kernel_thread_sp->GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
case eStateRunning: {
|
2013-04-03 04:32:37 +08:00
|
|
|
lldb::RegisterContextSP reg_ctx_sp(
|
|
|
|
kernel_thread_sp->GetRegisterContext());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
if (reg_ctx_sp) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep "
|
|
|
|
"(false);");
|
2012-09-22 00:31:20 +08:00
|
|
|
reg_ctx_sp->HardwareSingleStep(false);
|
|
|
|
resume = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-09-22 00:31:20 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2012-09-25 10:40:06 +08:00
|
|
|
"KDP thread 0x%llx has no register context",
|
|
|
|
kernel_thread_sp->GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
default:
|
|
|
|
// The only valid thread resume states are listed above
|
2017-01-06 08:38:06 +08:00
|
|
|
llvm_unreachable("invalid thread resume state");
|
2012-09-22 00:31:20 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
if (resume) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::DoResume () sending resume");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
if (m_comm.SendRequestResume()) {
|
|
|
|
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue);
|
2012-09-22 00:31:20 +08:00
|
|
|
SetPrivateState(eStateRunning);
|
2012-09-25 10:40:06 +08:00
|
|
|
} else
|
|
|
|
error.SetErrorString("KDP resume failed");
|
2013-05-08 02:35:34 +08:00
|
|
|
} else {
|
|
|
|
error.SetErrorString("kernel thread is suspended");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-05-08 02:35:34 +08:00
|
|
|
lldb::ThreadSP ProcessKDP::GetKernelThread() {
|
2012-09-25 10:40:06 +08:00
|
|
|
// KDP only tells us about one thread/core. Any other threads will usually
|
|
|
|
// be the ones that are read from memory by the OS plug-ins.
|
|
|
|
|
2013-05-08 02:35:34 +08:00
|
|
|
ThreadSP thread_sp(m_kernel_thread_wp.lock());
|
2012-09-25 10:40:06 +08:00
|
|
|
if (!thread_sp) {
|
2019-02-12 07:13:08 +08:00
|
|
|
thread_sp = std::make_shared<ThreadKDP>(*this, g_kernel_tid);
|
2013-05-08 02:35:34 +08:00
|
|
|
m_kernel_thread_wp = thread_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-04-10 08:18:59 +08:00
|
|
|
return thread_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-25 10:40:06 +08:00
|
|
|
|
2021-01-23 02:22:26 +08:00
|
|
|
bool ProcessKDP::DoUpdateThreadList(ThreadList &old_thread_list,
|
|
|
|
ThreadList &new_thread_list) {
|
2011-07-15 11:27:12 +08:00
|
|
|
// locker will keep a mutex locked until it goes out of scope
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Thread);
|
2017-02-07 05:46:22 +08:00
|
|
|
LLDB_LOGV(log, "pid = {0}", GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-12 06:23:34 +08:00
|
|
|
// Even though there is a CPU mask, it doesn't mean we can see each CPU
|
2015-07-03 02:48:40 +08:00
|
|
|
// individually, there is really only one. Lets call this thread 1.
|
2013-05-08 02:35:34 +08:00
|
|
|
ThreadSP thread_sp(
|
|
|
|
old_thread_list.FindThreadByProtocolID(g_kernel_tid, false));
|
|
|
|
if (!thread_sp)
|
|
|
|
thread_sp = GetKernelThread();
|
|
|
|
new_thread_list.AddThread(thread_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-04-10 08:18:59 +08:00
|
|
|
return new_thread_list.GetSize(false) > 0;
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessKDP::RefreshStateAfterStop() {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Let all threads recover from stopping and do any clean up based on the
|
|
|
|
// previous thread state (if any).
|
2011-07-15 11:27:12 +08:00
|
|
|
m_thread_list.RefreshStateAfterStop();
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoHalt(bool &caused_stop) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
if (m_comm.IsRunning()) {
|
|
|
|
if (m_destroy_in_process) {
|
2018-05-29 17:10:46 +08:00
|
|
|
// If we are attempting to destroy, we need to not return an error to Halt
|
2018-05-01 00:49:04 +08:00
|
|
|
// or DoDestroy won't get called. We are also currently running, so send
|
|
|
|
// a process stopped event
|
2012-09-25 10:40:06 +08:00
|
|
|
SetPrivateState(eStateStopped);
|
|
|
|
} else {
|
|
|
|
error.SetErrorString("KDP cannot interrupt a running kernel");
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoDetach(bool keep_stopped) {
|
|
|
|
Status error;
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Process);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
if (m_comm.IsRunning()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We are running and we can't interrupt a running kernel, so we need to
|
|
|
|
// just close the connection to the kernel and hope for the best
|
2012-09-25 10:40:06 +08:00
|
|
|
} else {
|
2013-05-02 08:27:30 +08:00
|
|
|
// If we are going to keep the target stopped, then don't send the
|
|
|
|
// disconnect message.
|
|
|
|
if (!keep_stopped && m_comm.IsConnected()) {
|
2013-05-09 09:55:29 +08:00
|
|
|
const bool success = m_comm.SendRequestDisconnect();
|
2012-09-25 10:40:06 +08:00
|
|
|
if (log) {
|
2013-05-09 09:55:29 +08:00
|
|
|
if (success)
|
|
|
|
log->PutCString(
|
|
|
|
"ProcessKDP::DoDetach() detach packet sent successfully");
|
2012-09-25 10:40:06 +08:00
|
|
|
else
|
2013-05-09 08:05:35 +08:00
|
|
|
log->PutCString(
|
|
|
|
"ProcessKDP::DoDetach() connection channel shutdown failed");
|
2012-09-25 10:40:06 +08:00
|
|
|
}
|
2013-05-09 09:55:29 +08:00
|
|
|
m_comm.Disconnect();
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-25 10:40:06 +08:00
|
|
|
StopAsyncThread();
|
2012-01-31 12:56:17 +08:00
|
|
|
m_comm.Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
SetPrivateState(eStateDetached);
|
|
|
|
ResumePrivateStateThread();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
// KillDebugserverProcess ();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoDestroy() {
|
2012-09-22 00:31:20 +08:00
|
|
|
// For KDP there really is no difference between destroy and detach
|
2013-05-02 08:27:30 +08:00
|
|
|
bool keep_stopped = false;
|
|
|
|
return DoDetach(keep_stopped);
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process Queries
|
|
|
|
|
|
|
|
bool ProcessKDP::IsAlive() {
|
2015-11-06 07:03:44 +08:00
|
|
|
return m_comm.IsConnected() && Process::IsAlive();
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process Memory
|
|
|
|
size_t ProcessKDP::DoReadMemory(addr_t addr, void *buf, size_t size,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2014-05-22 07:44:02 +08:00
|
|
|
uint8_t *data_buffer = (uint8_t *)buf;
|
2011-07-19 11:57:15 +08:00
|
|
|
if (m_comm.IsConnected()) {
|
2014-05-22 07:44:02 +08:00
|
|
|
const size_t max_read_size = 512;
|
|
|
|
size_t total_bytes_read = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-05-22 07:44:02 +08:00
|
|
|
// Read the requested amount of memory in 512 byte chunks
|
|
|
|
while (total_bytes_read < size) {
|
|
|
|
size_t bytes_to_read_this_request = size - total_bytes_read;
|
|
|
|
if (bytes_to_read_this_request > max_read_size) {
|
|
|
|
bytes_to_read_this_request = max_read_size;
|
|
|
|
}
|
|
|
|
size_t bytes_read = m_comm.SendRequestReadMemory(
|
|
|
|
addr + total_bytes_read, data_buffer + total_bytes_read,
|
|
|
|
bytes_to_read_this_request, error);
|
|
|
|
total_bytes_read += bytes_read;
|
|
|
|
if (error.Fail() || bytes_read == 0) {
|
|
|
|
return total_bytes_read;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-05-22 07:44:02 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2012-09-22 00:31:20 +08:00
|
|
|
return total_bytes_read;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-22 00:31:20 +08:00
|
|
|
error.SetErrorString("not connected");
|
2011-07-15 11:27:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ProcessKDP::DoWriteMemory(addr_t addr, const void *buf, size_t size,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2011-07-15 11:27:12 +08:00
|
|
|
if (m_comm.IsConnected())
|
|
|
|
return m_comm.SendRequestWriteMemory(addr, buf, size, error);
|
|
|
|
error.SetErrorString("not connected");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t ProcessKDP::DoAllocateMemory(size_t size, uint32_t permissions,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"memory allocation not supported in kdp remote debugging");
|
2011-07-15 11:27:12 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoDeallocateMemory(lldb::addr_t addr) {
|
|
|
|
Status error;
|
2011-07-21 09:12:01 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"memory deallocation not supported in kdp remote debugging");
|
2011-07-20 11:41:06 +08:00
|
|
|
return error;
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::EnableBreakpointSite(BreakpointSite *bp_site) {
|
2020-07-22 19:52:52 +08:00
|
|
|
if (bp_site->HardwareRequired())
|
|
|
|
return Status("Hardware breakpoints are not supported.");
|
|
|
|
|
2011-07-20 11:41:06 +08:00
|
|
|
if (m_comm.LocalBreakpointsAreSupported()) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-07-21 09:12:01 +08:00
|
|
|
if (!bp_site->IsEnabled()) {
|
2012-09-25 10:40:06 +08:00
|
|
|
if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress())) {
|
|
|
|
bp_site->SetEnabled(true);
|
|
|
|
bp_site->SetType(BreakpointSite::eExternal);
|
|
|
|
} else {
|
|
|
|
error.SetErrorString("KDP set breakpoint failed");
|
2011-07-21 09:12:01 +08:00
|
|
|
}
|
2011-07-20 11:41:06 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
return EnableSoftwareBreakpoint(bp_site);
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DisableBreakpointSite(BreakpointSite *bp_site) {
|
2011-07-15 11:27:12 +08:00
|
|
|
if (m_comm.LocalBreakpointsAreSupported()) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-07-21 09:12:01 +08:00
|
|
|
if (bp_site->IsEnabled()) {
|
|
|
|
BreakpointSite::Type bp_type = bp_site->GetType();
|
2011-07-15 11:27:12 +08:00
|
|
|
if (bp_type == BreakpointSite::eExternal) {
|
|
|
|
if (m_destroy_in_process && m_comm.IsRunning()) {
|
|
|
|
// We are trying to destroy our connection and we are running
|
2011-07-21 09:12:01 +08:00
|
|
|
bp_site->SetEnabled(false);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-07-21 09:12:01 +08:00
|
|
|
if (m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress()))
|
|
|
|
bp_site->SetEnabled(false);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString("KDP remove breakpoint failed");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-15 11:27:12 +08:00
|
|
|
error = DisableSoftwareBreakpoint(bp_site);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
return DisableSoftwareBreakpoint(bp_site);
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::EnableWatchpoint(Watchpoint *wp, bool notify) {
|
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"watchpoints are not supported in kdp remote debugging");
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DisableWatchpoint(Watchpoint *wp, bool notify) {
|
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"watchpoints are not supported in kdp remote debugging");
|
2011-07-20 11:41:06 +08:00
|
|
|
return error;
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessKDP::Clear() { m_thread_list.Clear(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ProcessKDP::DoSignal(int signo) {
|
|
|
|
Status error;
|
2011-07-15 11:27:12 +08:00
|
|
|
error.SetErrorString(
|
2018-05-29 17:10:46 +08:00
|
|
|
"sending signals is not supported in kdp remote debugging");
|
2011-07-15 11:27:12 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessKDP::Initialize() {
|
2017-02-07 01:55:02 +08:00
|
|
|
static llvm::once_flag g_once_flag;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-02-07 01:55:02 +08:00
|
|
|
llvm::call_once(g_once_flag, []() {
|
2011-07-15 11:27:12 +08:00
|
|
|
PluginManager::RegisterPlugin(GetPluginNameStatic(),
|
|
|
|
GetPluginDescriptionStatic(), CreateInstance,
|
2015-04-03 17:13:18 +08:00
|
|
|
DebuggerInitialize);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-02-17 23:08:08 +08:00
|
|
|
ProcessKDPLog::Initialize();
|
2015-04-03 12:24:32 +08:00
|
|
|
});
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
2013-07-16 06:54:20 +08:00
|
|
|
void ProcessKDP::DebuggerInitialize(lldb_private::Debugger &debugger) {
|
|
|
|
if (!PluginManager::GetSettingForProcessPlugin(
|
|
|
|
debugger, PluginProperties::GetSettingName())) {
|
|
|
|
const bool is_global_setting = true;
|
|
|
|
PluginManager::CreateSettingForProcessPlugin(
|
2021-10-07 21:44:47 +08:00
|
|
|
debugger, GetGlobalPluginProperties().GetValueProperties(),
|
2013-07-16 06:54:20 +08:00
|
|
|
ConstString("Properties for the kdp-remote process plug-in."),
|
|
|
|
is_global_setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
bool ProcessKDP::StartAsyncThread() {
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Process);
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::StartAsyncThread ()");
|
2012-09-22 00:31:20 +08:00
|
|
|
|
2014-09-24 02:32:09 +08:00
|
|
|
if (m_async_thread.IsJoinable())
|
|
|
|
return true;
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2019-07-06 01:42:08 +08:00
|
|
|
llvm::Expected<HostThread> async_thread = ThreadLauncher::LaunchThread(
|
2022-02-21 18:07:38 +08:00
|
|
|
"<lldb.process.kdp-remote.async>", [this] { return AsyncThread(); });
|
2019-07-06 01:42:08 +08:00
|
|
|
if (!async_thread) {
|
2022-01-31 15:22:31 +08:00
|
|
|
LLDB_LOG_ERROR(GetLog(LLDBLog::Host), async_thread.takeError(),
|
|
|
|
"failed to launch host thread: {}");
|
2019-07-06 01:42:08 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_async_thread = *async_thread;
|
2014-09-24 02:32:09 +08:00
|
|
|
return m_async_thread.IsJoinable();
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessKDP::StopAsyncThread() {
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Process);
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::StopAsyncThread ()");
|
2012-09-22 00:31:20 +08:00
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncThreadShouldExit);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
// Stop the stdio thread
|
|
|
|
if (m_async_thread.IsJoinable())
|
|
|
|
m_async_thread.Join(nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-02-21 18:07:38 +08:00
|
|
|
void *ProcessKDP::AsyncThread() {
|
|
|
|
const lldb::pid_t pid = GetID();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-01-31 15:22:31 +08:00
|
|
|
Log *log = GetLog(KDPLog::Process);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
2022-02-21 18:07:38 +08:00
|
|
|
"ProcessKDP::AsyncThread(pid = %" PRIu64 ") thread starting...",
|
|
|
|
pid);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 00:31:20 +08:00
|
|
|
ListenerSP listener_sp(Listener::MakeListener("ProcessKDP::AsyncThread"));
|
2011-07-15 11:27:12 +08:00
|
|
|
EventSP event_sp;
|
2012-09-22 00:31:20 +08:00
|
|
|
const uint32_t desired_event_mask =
|
|
|
|
eBroadcastBitAsyncContinue | eBroadcastBitAsyncThreadShouldExit;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-02-21 18:07:38 +08:00
|
|
|
if (listener_sp->StartListeningForEvents(
|
|
|
|
&m_async_broadcaster, desired_event_mask) == desired_event_mask) {
|
2012-09-22 00:31:20 +08:00
|
|
|
bool done = false;
|
2011-07-15 11:27:12 +08:00
|
|
|
while (!done) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ProcessKDP::AsyncThread (pid = %" PRIu64
|
|
|
|
") listener.WaitForEvent (NULL, event_sp)...",
|
|
|
|
pid);
|
2016-11-30 19:09:47 +08:00
|
|
|
if (listener_sp->GetEvent(event_sp, llvm::None)) {
|
2013-04-03 04:32:37 +08:00
|
|
|
uint32_t event_type = event_sp->GetType();
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ProcessKDP::AsyncThread (pid = %" PRIu64
|
|
|
|
") Got an event of type: %d...",
|
|
|
|
pid, event_type);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-22 00:31:20 +08:00
|
|
|
// When we are running, poll for 1 second to try and get an exception
|
|
|
|
// to indicate the process has stopped. If we don't get one, check to
|
|
|
|
// make sure no one asked us to exit
|
|
|
|
bool is_running = false;
|
|
|
|
DataExtractor exc_reply_packet;
|
|
|
|
do {
|
|
|
|
switch (event_type) {
|
|
|
|
case eBroadcastBitAsyncContinue: {
|
2012-11-30 05:49:15 +08:00
|
|
|
is_running = true;
|
2022-02-21 18:07:38 +08:00
|
|
|
if (m_comm.WaitForPacketWithTimeoutMicroSeconds(
|
2012-11-30 05:49:15 +08:00
|
|
|
exc_reply_packet, 1 * USEC_PER_SEC)) {
|
2022-02-21 18:07:38 +08:00
|
|
|
ThreadSP thread_sp(GetKernelThread());
|
2012-11-30 05:49:15 +08:00
|
|
|
if (thread_sp) {
|
|
|
|
lldb::RegisterContextSP reg_ctx_sp(
|
2012-09-22 00:31:20 +08:00
|
|
|
thread_sp->GetRegisterContext());
|
|
|
|
if (reg_ctx_sp)
|
2012-11-30 05:49:15 +08:00
|
|
|
reg_ctx_sp->InvalidateAllRegisters();
|
|
|
|
static_cast<ThreadKDP *>(thread_sp.get())
|
|
|
|
->SetStopInfoFrom_KDP_EXCEPTION(exc_reply_packet);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
// TODO: parse the stop reply packet
|
2012-09-22 00:31:20 +08:00
|
|
|
is_running = false;
|
2022-02-21 18:07:38 +08:00
|
|
|
SetPrivateState(eStateStopped);
|
2012-11-30 05:49:15 +08:00
|
|
|
} else {
|
|
|
|
// Check to see if we are supposed to exit. There is no way to
|
|
|
|
// interrupt a running kernel, so all we can do is wait for an
|
2012-09-22 00:31:20 +08:00
|
|
|
// exception or detach...
|
2016-11-30 19:09:47 +08:00
|
|
|
if (listener_sp->GetEvent(event_sp,
|
|
|
|
std::chrono::microseconds(0))) {
|
2012-11-30 05:49:15 +08:00
|
|
|
// We got an event, go through the loop again
|
2011-07-15 11:27:12 +08:00
|
|
|
event_type = event_sp->GetType();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-15 11:27:12 +08:00
|
|
|
case eBroadcastBitAsyncThreadShouldExit:
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ProcessKDP::AsyncThread (pid = %" PRIu64
|
|
|
|
") got eBroadcastBitAsyncThreadShouldExit...",
|
|
|
|
pid);
|
2011-07-15 11:27:12 +08:00
|
|
|
done = true;
|
2012-09-22 00:31:20 +08:00
|
|
|
is_running = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ProcessKDP::AsyncThread (pid = %" PRIu64
|
|
|
|
") got unknown event 0x%8.8x",
|
|
|
|
pid, event_type);
|
2011-07-15 11:27:12 +08:00
|
|
|
done = true;
|
2012-09-22 00:31:20 +08:00
|
|
|
is_running = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 00:31:20 +08:00
|
|
|
} while (is_running);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ProcessKDP::AsyncThread (pid = %" PRIu64
|
|
|
|
") listener.WaitForEvent (NULL, event_sp) => false",
|
|
|
|
pid);
|
2011-07-15 11:27:12 +08:00
|
|
|
done = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2022-02-21 18:07:38 +08:00
|
|
|
LLDB_LOGF(log, "ProcessKDP::AsyncThread(pid = %" PRIu64 ") thread exiting...",
|
|
|
|
pid);
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2022-02-21 18:07:38 +08:00
|
|
|
m_async_thread.Reset();
|
2011-07-15 11:27:12 +08:00
|
|
|
return NULL;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-15 11:27:12 +08:00
|
|
|
|
2012-10-20 06:22:57 +08:00
|
|
|
class CommandObjectProcessKDPPacketSend : public CommandObjectParsed {
|
|
|
|
private:
|
|
|
|
OptionGroupOptions m_option_group;
|
|
|
|
OptionGroupUInt64 m_command_byte;
|
|
|
|
OptionGroupString m_packet_data;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-07-16 02:33:15 +08:00
|
|
|
Options *GetOptions() override { return &m_option_group; }
|
2012-10-20 06:22:57 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
CommandObjectProcessKDPPacketSend(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "process plugin packet send",
|
|
|
|
"Send a custom packet through the KDP protocol by "
|
|
|
|
"specifying the command byte and the packet "
|
|
|
|
"payload data. A packet will be sent with a "
|
|
|
|
"correct header and payload, and the raw result "
|
|
|
|
"bytes will be displayed as a string value. ",
|
|
|
|
NULL),
|
2016-08-12 07:51:28 +08:00
|
|
|
m_option_group(),
|
2012-10-20 06:22:57 +08:00
|
|
|
m_command_byte(LLDB_OPT_SET_1, true, "command", 'c', 0, eArgTypeNone,
|
|
|
|
"Specify the command byte to use when sending the KDP "
|
|
|
|
"request packet.",
|
|
|
|
0),
|
|
|
|
m_packet_data(LLDB_OPT_SET_1, false, "payload", 'p', 0, eArgTypeNone,
|
|
|
|
"Specify packet payload bytes as a hex ASCII string with "
|
|
|
|
"no spaces or hex prefixes.",
|
|
|
|
NULL) {
|
|
|
|
m_option_group.Append(&m_command_byte, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
|
|
|
|
m_option_group.Append(&m_packet_data, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
|
|
|
|
m_option_group.Finalize();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-23 04:28:59 +08:00
|
|
|
~CommandObjectProcessKDPPacketSend() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-07-16 02:33:15 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2022-06-24 00:33:40 +08:00
|
|
|
if (!m_command_byte.GetOptionValue().OptionWasSet()) {
|
|
|
|
result.AppendError(
|
|
|
|
"the --command option must be set to a valid command byte");
|
|
|
|
} else {
|
|
|
|
const uint64_t command_byte =
|
|
|
|
m_command_byte.GetOptionValue().GetUInt64Value(0);
|
|
|
|
if (command_byte > 0 && command_byte <= UINT8_MAX) {
|
|
|
|
ProcessKDP *process =
|
|
|
|
(ProcessKDP *)m_interpreter.GetExecutionContext().GetProcessPtr();
|
|
|
|
if (process) {
|
|
|
|
const StateType state = process->GetState();
|
|
|
|
|
|
|
|
if (StateIsStoppedState(state, true)) {
|
|
|
|
std::vector<uint8_t> payload_bytes;
|
|
|
|
const char *ascii_hex_bytes_cstr =
|
|
|
|
m_packet_data.GetOptionValue().GetCurrentValue();
|
|
|
|
if (ascii_hex_bytes_cstr && ascii_hex_bytes_cstr[0]) {
|
|
|
|
StringExtractor extractor(ascii_hex_bytes_cstr);
|
|
|
|
const size_t ascii_hex_bytes_cstr_len =
|
|
|
|
extractor.GetStringRef().size();
|
|
|
|
if (ascii_hex_bytes_cstr_len & 1) {
|
|
|
|
result.AppendErrorWithFormat("payload data must contain an "
|
|
|
|
"even number of ASCII hex "
|
|
|
|
"characters: '%s'",
|
|
|
|
ascii_hex_bytes_cstr);
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-06-24 00:33:40 +08:00
|
|
|
payload_bytes.resize(ascii_hex_bytes_cstr_len / 2);
|
|
|
|
if (extractor.GetHexBytes(payload_bytes, '\xdd') !=
|
|
|
|
payload_bytes.size()) {
|
|
|
|
result.AppendErrorWithFormat("payload data must only contain "
|
|
|
|
"ASCII hex characters (no "
|
|
|
|
"spaces or hex prefixes): '%s'",
|
|
|
|
ascii_hex_bytes_cstr);
|
2012-10-20 06:22:57 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-06-24 00:33:40 +08:00
|
|
|
}
|
|
|
|
Status error;
|
|
|
|
DataExtractor reply;
|
|
|
|
process->GetCommunication().SendRawRequest(
|
|
|
|
command_byte,
|
|
|
|
payload_bytes.empty() ? NULL : payload_bytes.data(),
|
|
|
|
payload_bytes.size(), reply, error);
|
|
|
|
|
|
|
|
if (error.Success()) {
|
|
|
|
// Copy the binary bytes into a hex ASCII string for the result
|
|
|
|
StreamString packet;
|
|
|
|
packet.PutBytesAsRawHex8(
|
|
|
|
reply.GetDataStart(), reply.GetByteSize(),
|
|
|
|
endian::InlHostByteOrder(), endian::InlHostByteOrder());
|
|
|
|
result.AppendMessage(packet.GetString());
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2022-06-24 00:33:40 +08:00
|
|
|
const char *error_cstr = error.AsCString();
|
|
|
|
if (error_cstr && error_cstr[0])
|
|
|
|
result.AppendError(error_cstr);
|
|
|
|
else
|
|
|
|
result.AppendErrorWithFormat("unknown error 0x%8.8x",
|
|
|
|
error.GetError());
|
|
|
|
return false;
|
2012-10-20 06:22:57 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2022-06-24 00:33:40 +08:00
|
|
|
result.AppendErrorWithFormat("process must be stopped in order "
|
|
|
|
"to send KDP packets, state is %s",
|
|
|
|
StateAsCString(state));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-24 00:33:40 +08:00
|
|
|
result.AppendError("invalid process");
|
2012-10-20 06:22:57 +08:00
|
|
|
}
|
2022-06-24 00:33:40 +08:00
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat("invalid command byte 0x%" PRIx64
|
|
|
|
", valid values are 1 - 255",
|
|
|
|
command_byte);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-10-20 06:22:57 +08:00
|
|
|
}
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-10-20 06:22:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CommandObjectProcessKDPPacket : public CommandObjectMultiword {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
CommandObjectProcessKDPPacket(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectMultiword(interpreter, "process plugin packet",
|
|
|
|
"Commands that deal with KDP remote packets.",
|
|
|
|
NULL) {
|
|
|
|
LoadSubCommand(
|
|
|
|
"send",
|
|
|
|
CommandObjectSP(new CommandObjectProcessKDPPacketSend(interpreter)));
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-04-23 04:28:59 +08:00
|
|
|
~CommandObjectProcessKDPPacket() override = default;
|
2012-10-20 06:22:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CommandObjectMultiwordProcessKDP : public CommandObjectMultiword {
|
|
|
|
public:
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectMultiwordProcessKDP(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectMultiword(
|
|
|
|
interpreter, "process plugin",
|
|
|
|
"Commands for operating on a ProcessKDP process.",
|
|
|
|
"process plugin <subcommand> [<subcommand-options>]") {
|
2012-10-20 06:22:57 +08:00
|
|
|
LoadSubCommand("packet", CommandObjectSP(new CommandObjectProcessKDPPacket(
|
|
|
|
interpreter)));
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-04-23 04:28:59 +08:00
|
|
|
~CommandObjectMultiwordProcessKDP() override = default;
|
2012-10-20 06:22:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CommandObject *ProcessKDP::GetPluginCommandObject() {
|
|
|
|
if (!m_command_sp)
|
2019-02-12 07:13:08 +08:00
|
|
|
m_command_sp = std::make_shared<CommandObjectMultiwordProcessKDP>(
|
|
|
|
GetTarget().GetDebugger().GetCommandInterpreter());
|
2012-10-20 06:22:57 +08:00
|
|
|
return m_command_sp.get();
|
|
|
|
}
|