diff options
author | dim <dim@FreeBSD.org> | 2017-04-02 17:24:58 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2017-04-02 17:24:58 +0000 |
commit | 60b571e49a90d38697b3aca23020d9da42fc7d7f (patch) | |
tree | 99351324c24d6cb146b6285b6caffa4d26fce188 /contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp | |
parent | bea1b22c7a9bce1dfdd73e6e5b65bc4752215180 (diff) | |
download | FreeBSD-src-60b571e49a90d38697b3aca23020d9da42fc7d7f.zip FreeBSD-src-60b571e49a90d38697b3aca23020d9da42fc7d7f.tar.gz |
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release:
MFC r309142 (by emaste):
Add WITH_LLD_AS_LD build knob
If set it installs LLD as /usr/bin/ld. LLD (as of version 3.9) is not
capable of linking the world and kernel, but can self-host and link many
substantial applications. GNU ld continues to be used for the world and
kernel build, regardless of how this knob is set.
It is on by default for arm64, and off for all other CPU architectures.
Sponsored by: The FreeBSD Foundation
MFC r310840:
Reapply 310775, now it also builds correctly if lldb is disabled:
Move llvm-objdump from CLANG_EXTRAS to installed by default
We currently install three tools from binutils 2.17.50: as, ld, and
objdump. Work is underway to migrate to a permissively-licensed
tool-chain, with one goal being the retirement of binutils 2.17.50.
LLVM's llvm-objdump is intended to be compatible with GNU objdump
although it is currently missing some options and may have formatting
differences. Enable it by default for testing and further investigation.
It may later be changed to install as /usr/bin/objdump, it becomes a
fully viable replacement.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D8879
MFC r312855 (by emaste):
Rename LLD_AS_LD to LLD_IS_LD, for consistency with CLANG_IS_CC
Reported by: Dan McGregor <dan.mcgregor usask.ca>
MFC r313559 | glebius | 2017-02-10 18:34:48 +0100 (Fri, 10 Feb 2017) | 5 lines
Don't check struct rtentry on FreeBSD, it is an internal kernel structure.
On other systems it may be API structure for SIOCADDRT/SIOCDELRT.
Reviewed by: emaste, dim
MFC r314152 (by jkim):
Remove an assembler flag, which is redundant since r309124. The upstream
took care of it by introducing a macro NO_EXEC_STACK_DIRECTIVE.
http://llvm.org/viewvc/llvm-project?rev=273500&view=rev
Reviewed by: dim
MFC r314564:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
4.0.0 (branches/release_40 296509). The release will follow soon.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Also note that as of 4.0.0, lld should be able to link the base system
on amd64 and aarch64. See the WITH_LLD_IS_LLD setting in src.conf(5).
Though please be aware that this is work in progress.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/4.0.0/docs/ReleaseNotes.html>
<http://releases.llvm.org/4.0.0/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/4.0.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Jan Beich, Antoine Brodin and Eric Fiselier for
their help.
Relnotes: yes
Exp-run: antoine
PR: 215969, 216008
MFC r314708:
For now, revert r287232 from upstream llvm trunk (by Daniil Fukalov):
[SCEV] limit recursion depth of CompareSCEVComplexity
Summary:
CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled
loop) and runs almost infinite time.
Added cache of "equal" SCEV pairs to earlier cutoff of further
estimation. Recursion depth limit was also introduced as a parameter.
Reviewers: sanjoy
Subscribers: mzolotukhin, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D26389
This commit is the cause of excessive compile times on skein_block.c
(and possibly other files) during kernel builds on amd64.
We never saw the problematic behavior described in this upstream commit,
so for now it is better to revert it. An upstream bug has been filed
here: https://bugs.llvm.org/show_bug.cgi?id=32142
Reported by: mjg
MFC r314795:
Reapply r287232 from upstream llvm trunk (by Daniil Fukalov):
[SCEV] limit recursion depth of CompareSCEVComplexity
Summary:
CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled
loop) and runs almost infinite time.
Added cache of "equal" SCEV pairs to earlier cutoff of further
estimation. Recursion depth limit was also introduced as a parameter.
Reviewers: sanjoy
Subscribers: mzolotukhin, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D26389
Pull in r296992 from upstream llvm trunk (by Sanjoy Das):
[SCEV] Decrease the recursion threshold for CompareValueComplexity
Fixes PR32142.
r287232 accidentally increased the recursion threshold for
CompareValueComplexity from 2 to 32. This change reverses that
change by introducing a separate flag for CompareValueComplexity's
threshold.
The latter revision fixes the excessive compile times for skein_block.c.
MFC r314907 | mmel | 2017-03-08 12:40:27 +0100 (Wed, 08 Mar 2017) | 7 lines
Unbreak ARMv6 world.
The new compiler_rt library imported with clang 4.0.0 have several fatal
issues (non-functional __udivsi3 for example) with ARM specific instrict
functions. As temporary workaround, until upstream solve these problems,
disable all thumb[1][2] related feature.
MFC r315016:
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release.
We were already very close to the last release candidate, so this is a
pretty minor update.
Relnotes: yes
MFC r316005:
Revert r314907, and pull in r298713 from upstream compiler-rt trunk (by
Weiming Zhao):
builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA.
Summary:
Value of __ARM_ARCH_ISA_THUMB isn't based on the actual compilation
mode (-mthumb, -marm), it reflect's capability of given CPU.
Due to this:
- use __tbumb__ and __thumb2__ insteand of __ARM_ARCH_ISA_THUMB
- use '.thumb' directive consistently in all affected files
- decorate all thumb functions using
DEFINE_COMPILERRT_THUMB_FUNCTION()
---------
Note: This patch doesn't fix broken Thumb1 variant of __udivsi3 !
Reviewers: weimingz, rengolin, compnerd
Subscribers: aemerson, dim
Differential Revision: https://reviews.llvm.org/D30938
Discussed with: mmel
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp')
-rw-r--r-- | contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp | 2074 |
1 files changed, 1059 insertions, 1015 deletions
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index 26a2e69..e4e6810 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -12,12 +12,16 @@ #include <errno.h> // C Includes + +#ifdef __APPLE__ +#include <TargetConditionals.h> +#endif + // C++ Includes -#include <cstring> #include <chrono> +#include <cstring> // Other libraries and framework includes -#include "llvm/ADT/Triple.h" #include "lldb/Core/Log.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/StreamGDBRemote.h" @@ -34,6 +38,8 @@ #include "lldb/Target/FileAction.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/JSON.h" +#include "llvm/ADT/Triple.h" // Project includes #include "ProcessGDBRemoteLog.h" @@ -43,1214 +49,1252 @@ #include "lldb/Host/android/HostInfoAndroid.h" #endif +#include "llvm/ADT/StringSwitch.h" + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_gdb_remote; #ifdef __ANDROID__ - const static uint32_t g_default_packet_timeout_sec = 20; // seconds +const static uint32_t g_default_packet_timeout_sec = 20; // seconds #else - const static uint32_t g_default_packet_timeout_sec = 0; // not specified +const static uint32_t g_default_packet_timeout_sec = 0; // not specified #endif //---------------------------------------------------------------------- // GDBRemoteCommunicationServerCommon constructor //---------------------------------------------------------------------- -GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon(const char *comm_name, const char *listener_name) : - GDBRemoteCommunicationServer (comm_name, listener_name), - m_process_launch_info (), - m_process_launch_error (), - m_proc_infos (), - m_proc_infos_index (0), - m_thread_suffix_supported (false), - m_list_threads_in_stop_reply (false) -{ - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_A, - &GDBRemoteCommunicationServerCommon::Handle_A); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QEnvironment, - &GDBRemoteCommunicationServerCommon::Handle_QEnvironment); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QEnvironmentHexEncoded, - &GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qfProcessInfo, - &GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qGroupName, - &GDBRemoteCommunicationServerCommon::Handle_qGroupName); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qHostInfo, - &GDBRemoteCommunicationServerCommon::Handle_qHostInfo); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QLaunchArch, - &GDBRemoteCommunicationServerCommon::Handle_QLaunchArch); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess, - &GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QListThreadsInStopReply, - &GDBRemoteCommunicationServerCommon::Handle_QListThreadsInStopReply); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qEcho, - &GDBRemoteCommunicationServerCommon::Handle_qEcho); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qModuleInfo, - &GDBRemoteCommunicationServerCommon::Handle_qModuleInfo); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod, - &GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir, - &GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qPlatform_shell, - &GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID, - &GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QSetDetachOnError, - &GDBRemoteCommunicationServerCommon::Handle_QSetDetachOnError); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QSetSTDERR, - &GDBRemoteCommunicationServerCommon::Handle_QSetSTDERR); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QSetSTDIN, - &GDBRemoteCommunicationServerCommon::Handle_QSetSTDIN); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT, - &GDBRemoteCommunicationServerCommon::Handle_QSetSTDOUT); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qSpeedTest, - &GDBRemoteCommunicationServerCommon::Handle_qSpeedTest); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qsProcessInfo, - &GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode, - &GDBRemoteCommunicationServerCommon::Handle_QStartNoAckMode); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qSupported, - &GDBRemoteCommunicationServerCommon::Handle_qSupported); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_QThreadSuffixSupported, - &GDBRemoteCommunicationServerCommon::Handle_QThreadSuffixSupported); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_qUserName, - &GDBRemoteCommunicationServerCommon::Handle_qUserName); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_close, - &GDBRemoteCommunicationServerCommon::Handle_vFile_Close); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_exists, - &GDBRemoteCommunicationServerCommon::Handle_vFile_Exists); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_md5, - &GDBRemoteCommunicationServerCommon::Handle_vFile_MD5); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_mode, - &GDBRemoteCommunicationServerCommon::Handle_vFile_Mode); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_open, - &GDBRemoteCommunicationServerCommon::Handle_vFile_Open); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_pread, - &GDBRemoteCommunicationServerCommon::Handle_vFile_pRead); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_pwrite, - &GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_size, - &GDBRemoteCommunicationServerCommon::Handle_vFile_Size); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_stat, - &GDBRemoteCommunicationServerCommon::Handle_vFile_Stat); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_symlink, - &GDBRemoteCommunicationServerCommon::Handle_vFile_symlink); - RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_vFile_unlink, - &GDBRemoteCommunicationServerCommon::Handle_vFile_unlink); +GDBRemoteCommunicationServerCommon::GDBRemoteCommunicationServerCommon( + const char *comm_name, const char *listener_name) + : GDBRemoteCommunicationServer(comm_name, listener_name), + m_process_launch_info(), m_process_launch_error(), m_proc_infos(), + m_proc_infos_index(0), m_thread_suffix_supported(false), + m_list_threads_in_stop_reply(false) { + RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_A, + &GDBRemoteCommunicationServerCommon::Handle_A); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QEnvironment, + &GDBRemoteCommunicationServerCommon::Handle_QEnvironment); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QEnvironmentHexEncoded, + &GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qfProcessInfo, + &GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qGroupName, + &GDBRemoteCommunicationServerCommon::Handle_qGroupName); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qHostInfo, + &GDBRemoteCommunicationServerCommon::Handle_qHostInfo); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QLaunchArch, + &GDBRemoteCommunicationServerCommon::Handle_QLaunchArch); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qLaunchSuccess, + &GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QListThreadsInStopReply, + &GDBRemoteCommunicationServerCommon::Handle_QListThreadsInStopReply); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qEcho, + &GDBRemoteCommunicationServerCommon::Handle_qEcho); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qModuleInfo, + &GDBRemoteCommunicationServerCommon::Handle_qModuleInfo); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_jModulesInfo, + &GDBRemoteCommunicationServerCommon::Handle_jModulesInfo); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qPlatform_chmod, + &GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qPlatform_mkdir, + &GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qPlatform_shell, + &GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qProcessInfoPID, + &GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QSetDetachOnError, + &GDBRemoteCommunicationServerCommon::Handle_QSetDetachOnError); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QSetSTDERR, + &GDBRemoteCommunicationServerCommon::Handle_QSetSTDERR); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QSetSTDIN, + &GDBRemoteCommunicationServerCommon::Handle_QSetSTDIN); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QSetSTDOUT, + &GDBRemoteCommunicationServerCommon::Handle_QSetSTDOUT); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qSpeedTest, + &GDBRemoteCommunicationServerCommon::Handle_qSpeedTest); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qsProcessInfo, + &GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QStartNoAckMode, + &GDBRemoteCommunicationServerCommon::Handle_QStartNoAckMode); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qSupported, + &GDBRemoteCommunicationServerCommon::Handle_qSupported); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_QThreadSuffixSupported, + &GDBRemoteCommunicationServerCommon::Handle_QThreadSuffixSupported); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_qUserName, + &GDBRemoteCommunicationServerCommon::Handle_qUserName); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_close, + &GDBRemoteCommunicationServerCommon::Handle_vFile_Close); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_exists, + &GDBRemoteCommunicationServerCommon::Handle_vFile_Exists); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_md5, + &GDBRemoteCommunicationServerCommon::Handle_vFile_MD5); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_mode, + &GDBRemoteCommunicationServerCommon::Handle_vFile_Mode); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_open, + &GDBRemoteCommunicationServerCommon::Handle_vFile_Open); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_pread, + &GDBRemoteCommunicationServerCommon::Handle_vFile_pRead); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_pwrite, + &GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_size, + &GDBRemoteCommunicationServerCommon::Handle_vFile_Size); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_stat, + &GDBRemoteCommunicationServerCommon::Handle_vFile_Stat); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_symlink, + &GDBRemoteCommunicationServerCommon::Handle_vFile_symlink); + RegisterMemberFunctionHandler( + StringExtractorGDBRemote::eServerPacketType_vFile_unlink, + &GDBRemoteCommunicationServerCommon::Handle_vFile_unlink); } //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- -GDBRemoteCommunicationServerCommon::~GDBRemoteCommunicationServerCommon() -{ -} +GDBRemoteCommunicationServerCommon::~GDBRemoteCommunicationServerCommon() {} GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qHostInfo (StringExtractorGDBRemote &packet) -{ - StreamString response; +GDBRemoteCommunicationServerCommon::Handle_qHostInfo( + StringExtractorGDBRemote &packet) { + StreamString response; - // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00 + // $cputype:16777223;cpusubtype:3;ostype:Darwin;vendor:apple;endian:little;ptrsize:8;#00 - ArchSpec host_arch(HostInfo::GetArchitecture()); - const llvm::Triple &host_triple = host_arch.GetTriple(); - response.PutCString("triple:"); - response.PutCStringAsRawHex8(host_triple.getTriple().c_str()); - response.Printf (";ptrsize:%u;",host_arch.GetAddressByteSize()); - - const char* distribution_id = host_arch.GetDistributionId ().AsCString (); - if (distribution_id) - { - response.PutCString("distribution_id:"); - response.PutCStringAsRawHex8(distribution_id); - response.PutCString(";"); - } + ArchSpec host_arch(HostInfo::GetArchitecture()); + const llvm::Triple &host_triple = host_arch.GetTriple(); + response.PutCString("triple:"); + response.PutCStringAsRawHex8(host_triple.getTriple().c_str()); + response.Printf(";ptrsize:%u;", host_arch.GetAddressByteSize()); + + const char *distribution_id = host_arch.GetDistributionId().AsCString(); + if (distribution_id) { + response.PutCString("distribution_id:"); + response.PutCStringAsRawHex8(distribution_id); + response.PutCString(";"); + } - // Only send out MachO info when lldb-platform/llgs is running on a MachO host. #if defined(__APPLE__) - uint32_t cpu = host_arch.GetMachOCPUType(); - uint32_t sub = host_arch.GetMachOCPUSubType(); - if (cpu != LLDB_INVALID_CPUTYPE) - response.Printf ("cputype:%u;", cpu); - if (sub != LLDB_INVALID_CPUTYPE) - response.Printf ("cpusubtype:%u;", sub); - - if (cpu == ArchSpec::kCore_arm_any) - response.Printf("watchpoint_exceptions_received:before;"); // On armv7 we use "synchronous" watchpoints which means the exception is delivered before the instruction executes. - else - response.Printf("watchpoint_exceptions_received:after;"); + // For parity with debugserver, we'll include the vendor key. + response.PutCString("vendor:apple;"); + + // Send out MachO info. + uint32_t cpu = host_arch.GetMachOCPUType(); + uint32_t sub = host_arch.GetMachOCPUSubType(); + if (cpu != LLDB_INVALID_CPUTYPE) + response.Printf("cputype:%u;", cpu); + if (sub != LLDB_INVALID_CPUTYPE) + response.Printf("cpusubtype:%u;", sub); + + if (cpu == ArchSpec::kCore_arm_any) { +// Indicate the OS type. +#if defined(TARGET_OS_TV) && TARGET_OS_TV == 1 + response.PutCString("ostype:tvos;"); +#elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH == 1 + response.PutCString("ostype:watchos;"); #else - if (host_arch.GetMachine() == llvm::Triple::aarch64 || - host_arch.GetMachine() == llvm::Triple::aarch64_be || - host_arch.GetMachine() == llvm::Triple::arm || - host_arch.GetMachine() == llvm::Triple::armeb || - host_arch.GetMachine() == llvm::Triple::mips64 || - host_arch.GetMachine() == llvm::Triple::mips64el || - host_arch.GetMachine() == llvm::Triple::mips || - host_arch.GetMachine() == llvm::Triple::mipsel) - response.Printf("watchpoint_exceptions_received:before;"); - else - response.Printf("watchpoint_exceptions_received:after;"); + response.PutCString("ostype:ios;"); #endif - switch (endian::InlHostByteOrder()) - { - case eByteOrderBig: response.PutCString ("endian:big;"); break; - case eByteOrderLittle: response.PutCString ("endian:little;"); break; - case eByteOrderPDP: response.PutCString ("endian:pdp;"); break; - default: response.PutCString ("endian:unknown;"); break; - } + // On arm, we use "synchronous" watchpoints which means the exception is + // delivered before the instruction executes. + response.PutCString("watchpoint_exceptions_received:before;"); + } else { + response.PutCString("ostype:macosx;"); + response.Printf("watchpoint_exceptions_received:after;"); + } - uint32_t major = UINT32_MAX; - uint32_t minor = UINT32_MAX; - uint32_t update = UINT32_MAX; - if (HostInfo::GetOSVersion(major, minor, update)) - { - if (major != UINT32_MAX) - { - response.Printf("os_version:%u", major); - if (minor != UINT32_MAX) - { - response.Printf(".%u", minor); - if (update != UINT32_MAX) - response.Printf(".%u", update); - } - response.PutChar(';'); - } - } +#else + if (host_arch.GetMachine() == llvm::Triple::aarch64 || + host_arch.GetMachine() == llvm::Triple::aarch64_be || + host_arch.GetMachine() == llvm::Triple::arm || + host_arch.GetMachine() == llvm::Triple::armeb || + host_arch.GetMachine() == llvm::Triple::mips64 || + host_arch.GetMachine() == llvm::Triple::mips64el || + host_arch.GetMachine() == llvm::Triple::mips || + host_arch.GetMachine() == llvm::Triple::mipsel) + response.Printf("watchpoint_exceptions_received:before;"); + else + response.Printf("watchpoint_exceptions_received:after;"); +#endif - std::string s; - if (HostInfo::GetOSBuildString(s)) - { - response.PutCString ("os_build:"); - response.PutCStringAsRawHex8(s.c_str()); - response.PutChar(';'); - } - if (HostInfo::GetOSKernelDescription(s)) - { - response.PutCString ("os_kernel:"); - response.PutCStringAsRawHex8(s.c_str()); - response.PutChar(';'); + switch (endian::InlHostByteOrder()) { + case eByteOrderBig: + response.PutCString("endian:big;"); + break; + case eByteOrderLittle: + response.PutCString("endian:little;"); + break; + case eByteOrderPDP: + response.PutCString("endian:pdp;"); + break; + default: + response.PutCString("endian:unknown;"); + break; + } + + uint32_t major = UINT32_MAX; + uint32_t minor = UINT32_MAX; + uint32_t update = UINT32_MAX; + if (HostInfo::GetOSVersion(major, minor, update)) { + if (major != UINT32_MAX) { + response.Printf("os_version:%u", major); + if (minor != UINT32_MAX) { + response.Printf(".%u", minor); + if (update != UINT32_MAX) + response.Printf(".%u", update); + } + response.PutChar(';'); } + } + + std::string s; + if (HostInfo::GetOSBuildString(s)) { + response.PutCString("os_build:"); + response.PutCStringAsRawHex8(s.c_str()); + response.PutChar(';'); + } + if (HostInfo::GetOSKernelDescription(s)) { + response.PutCString("os_kernel:"); + response.PutCStringAsRawHex8(s.c_str()); + response.PutChar(';'); + } #if defined(__APPLE__) #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) - // For iOS devices, we are connected through a USB Mux so we never pretend - // to actually have a hostname as far as the remote lldb that is connecting - // to this lldb-platform is concerned - response.PutCString ("hostname:"); - response.PutCStringAsRawHex8("127.0.0.1"); + // For iOS devices, we are connected through a USB Mux so we never pretend + // to actually have a hostname as far as the remote lldb that is connecting + // to this lldb-platform is concerned + response.PutCString("hostname:"); + response.PutCStringAsRawHex8("127.0.0.1"); + response.PutChar(';'); +#else // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) + if (HostInfo::GetHostname(s)) { + response.PutCString("hostname:"); + response.PutCStringAsRawHex8(s.c_str()); response.PutChar(';'); -#else // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) - if (HostInfo::GetHostname(s)) - { - response.PutCString ("hostname:"); - response.PutCStringAsRawHex8(s.c_str()); - response.PutChar(';'); - } -#endif // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) + } +#endif // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__) -#else // #if defined(__APPLE__) - if (HostInfo::GetHostname(s)) - { - response.PutCString ("hostname:"); - response.PutCStringAsRawHex8(s.c_str()); - response.PutChar(';'); - } -#endif // #if defined(__APPLE__) +#else // #if defined(__APPLE__) + if (HostInfo::GetHostname(s)) { + response.PutCString("hostname:"); + response.PutCStringAsRawHex8(s.c_str()); + response.PutChar(';'); + } +#endif // #if defined(__APPLE__) - if (g_default_packet_timeout_sec > 0) - response.Printf ("default_packet_timeout:%u;", g_default_packet_timeout_sec); + if (g_default_packet_timeout_sec > 0) + response.Printf("default_packet_timeout:%u;", g_default_packet_timeout_sec); - return SendPacketNoLock (response.GetData(), response.GetSize()); + return SendPacketNoLock(response.GetString()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID (StringExtractorGDBRemote &packet) -{ - // Packet format: "qProcessInfoPID:%i" where %i is the pid - packet.SetFilePos (::strlen ("qProcessInfoPID:")); - lldb::pid_t pid = packet.GetU32 (LLDB_INVALID_PROCESS_ID); - if (pid != LLDB_INVALID_PROCESS_ID) - { - ProcessInstanceInfo proc_info; - if (Host::GetProcessInfo (pid, proc_info)) - { - StreamString response; - CreateProcessInfoResponse (proc_info, response); - return SendPacketNoLock (response.GetData(), response.GetSize()); - } +GDBRemoteCommunicationServerCommon::Handle_qProcessInfoPID( + StringExtractorGDBRemote &packet) { + // Packet format: "qProcessInfoPID:%i" where %i is the pid + packet.SetFilePos(::strlen("qProcessInfoPID:")); + lldb::pid_t pid = packet.GetU32(LLDB_INVALID_PROCESS_ID); + if (pid != LLDB_INVALID_PROCESS_ID) { + ProcessInstanceInfo proc_info; + if (Host::GetProcessInfo(pid, proc_info)) { + StreamString response; + CreateProcessInfoResponse(proc_info, response); + return SendPacketNoLock(response.GetString()); } - return SendErrorResponse (1); + } + return SendErrorResponse(1); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo (StringExtractorGDBRemote &packet) -{ - m_proc_infos_index = 0; - m_proc_infos.Clear(); - - ProcessInstanceInfoMatch match_info; - packet.SetFilePos(::strlen ("qfProcessInfo")); - if (packet.GetChar() == ':') - { - - std::string key; - std::string value; - while (packet.GetNameColonValue(key, value)) - { - bool success = true; - if (key.compare("name") == 0) - { - StringExtractor extractor; - extractor.GetStringRef().swap(value); - extractor.GetHexByteString (value); - match_info.GetProcessInfo().GetExecutableFile().SetFile(value.c_str(), false); - } - else if (key.compare("name_match") == 0) - { - if (value.compare("equals") == 0) - { - match_info.SetNameMatchType (eNameMatchEquals); - } - else if (value.compare("starts_with") == 0) - { - match_info.SetNameMatchType (eNameMatchStartsWith); - } - else if (value.compare("ends_with") == 0) - { - match_info.SetNameMatchType (eNameMatchEndsWith); - } - else if (value.compare("contains") == 0) - { - match_info.SetNameMatchType (eNameMatchContains); - } - else if (value.compare("regex") == 0) - { - match_info.SetNameMatchType (eNameMatchRegularExpression); - } - else - { - success = false; - } - } - else if (key.compare("pid") == 0) - { - match_info.GetProcessInfo().SetProcessID (StringConvert::ToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success)); - } - else if (key.compare("parent_pid") == 0) - { - match_info.GetProcessInfo().SetParentProcessID (StringConvert::ToUInt32(value.c_str(), LLDB_INVALID_PROCESS_ID, 0, &success)); - } - else if (key.compare("uid") == 0) - { - match_info.GetProcessInfo().SetUserID (StringConvert::ToUInt32(value.c_str(), UINT32_MAX, 0, &success)); - } - else if (key.compare("gid") == 0) - { - match_info.GetProcessInfo().SetGroupID (StringConvert::ToUInt32(value.c_str(), UINT32_MAX, 0, &success)); - } - else if (key.compare("euid") == 0) - { - match_info.GetProcessInfo().SetEffectiveUserID (StringConvert::ToUInt32(value.c_str(), UINT32_MAX, 0, &success)); - } - else if (key.compare("egid") == 0) - { - match_info.GetProcessInfo().SetEffectiveGroupID (StringConvert::ToUInt32(value.c_str(), UINT32_MAX, 0, &success)); - } - else if (key.compare("all_users") == 0) - { - match_info.SetMatchAllUsers(Args::StringToBoolean(value.c_str(), false, &success)); - } - else if (key.compare("triple") == 0) - { - match_info.GetProcessInfo().GetArchitecture().SetTriple (value.c_str(), NULL); - } - else - { - success = false; - } - - if (!success) - return SendErrorResponse (2); - } - } - - if (Host::FindProcesses (match_info, m_proc_infos)) - { - // We found something, return the first item by calling the get - // subsequent process info packet handler... - return Handle_qsProcessInfo (packet); +GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo( + StringExtractorGDBRemote &packet) { + m_proc_infos_index = 0; + m_proc_infos.Clear(); + + ProcessInstanceInfoMatch match_info; + packet.SetFilePos(::strlen("qfProcessInfo")); + if (packet.GetChar() == ':') { + llvm::StringRef key; + llvm::StringRef value; + while (packet.GetNameColonValue(key, value)) { + bool success = true; + if (key.equals("name")) { + StringExtractor extractor(value); + std::string file; + extractor.GetHexByteString(file); + match_info.GetProcessInfo().GetExecutableFile().SetFile(file, false); + } else if (key.equals("name_match")) { + NameMatchType name_match = + llvm::StringSwitch<NameMatchType>(value) + .Case("equals", eNameMatchEquals) + .Case("starts_with", eNameMatchStartsWith) + .Case("ends_with", eNameMatchEndsWith) + .Case("contains", eNameMatchContains) + .Case("regex", eNameMatchRegularExpression) + .Default(eNameMatchIgnore); + match_info.SetNameMatchType(name_match); + if (name_match == eNameMatchIgnore) + return SendErrorResponse(2); + } else if (key.equals("pid")) { + lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; + if (value.getAsInteger(0, pid)) + return SendErrorResponse(2); + match_info.GetProcessInfo().SetProcessID(pid); + } else if (key.equals("parent_pid")) { + lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; + if (value.getAsInteger(0, pid)) + return SendErrorResponse(2); + match_info.GetProcessInfo().SetParentProcessID(pid); + } else if (key.equals("uid")) { + uint32_t uid = UINT32_MAX; + if (value.getAsInteger(0, uid)) + return SendErrorResponse(2); + match_info.GetProcessInfo().SetUserID(uid); + } else if (key.equals("gid")) { + uint32_t gid = UINT32_MAX; + if (value.getAsInteger(0, gid)) + return SendErrorResponse(2); + match_info.GetProcessInfo().SetGroupID(gid); + } else if (key.equals("euid")) { + uint32_t uid = UINT32_MAX; + if (value.getAsInteger(0, uid)) + return SendErrorResponse(2); + match_info.GetProcessInfo().SetEffectiveUserID(uid); + } else if (key.equals("egid")) { + uint32_t gid = UINT32_MAX; + if (value.getAsInteger(0, gid)) + return SendErrorResponse(2); + match_info.GetProcessInfo().SetEffectiveGroupID(gid); + } else if (key.equals("all_users")) { + match_info.SetMatchAllUsers( + Args::StringToBoolean(value, false, &success)); + } else if (key.equals("triple")) { + match_info.GetProcessInfo().GetArchitecture().SetTriple( + value.str().c_str(), NULL); + } else { + success = false; + } + + if (!success) + return SendErrorResponse(2); } - return SendErrorResponse (3); + } + + if (Host::FindProcesses(match_info, m_proc_infos)) { + // We found something, return the first item by calling the get + // subsequent process info packet handler... + return Handle_qsProcessInfo(packet); + } + return SendErrorResponse(3); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo (StringExtractorGDBRemote &packet) -{ - if (m_proc_infos_index < m_proc_infos.GetSize()) - { - StreamString response; - CreateProcessInfoResponse (m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response); - ++m_proc_infos_index; - return SendPacketNoLock (response.GetData(), response.GetSize()); - } - return SendErrorResponse (4); +GDBRemoteCommunicationServerCommon::Handle_qsProcessInfo( + StringExtractorGDBRemote &packet) { + if (m_proc_infos_index < m_proc_infos.GetSize()) { + StreamString response; + CreateProcessInfoResponse( + m_proc_infos.GetProcessInfoAtIndex(m_proc_infos_index), response); + ++m_proc_infos_index; + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(4); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qUserName (StringExtractorGDBRemote &packet) -{ +GDBRemoteCommunicationServerCommon::Handle_qUserName( + StringExtractorGDBRemote &packet) { #if !defined(LLDB_DISABLE_POSIX) - Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__); - - // Packet format: "qUserName:%i" where %i is the uid - packet.SetFilePos(::strlen ("qUserName:")); - uint32_t uid = packet.GetU32 (UINT32_MAX); - if (uid != UINT32_MAX) - { - std::string name; - if (HostInfo::LookupUserName(uid, name)) - { - StreamString response; - response.PutCStringAsRawHex8 (name.c_str()); - return SendPacketNoLock (response.GetData(), response.GetSize()); - } + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); + if (log) + log->Printf("GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__); + + // Packet format: "qUserName:%i" where %i is the uid + packet.SetFilePos(::strlen("qUserName:")); + uint32_t uid = packet.GetU32(UINT32_MAX); + if (uid != UINT32_MAX) { + std::string name; + if (HostInfo::LookupUserName(uid, name)) { + StreamString response; + response.PutCStringAsRawHex8(name.c_str()); + return SendPacketNoLock(response.GetString()); } - if (log) - log->Printf("GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__); + } + if (log) + log->Printf("GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__); #endif - return SendErrorResponse (5); - + return SendErrorResponse(5); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qGroupName (StringExtractorGDBRemote &packet) -{ +GDBRemoteCommunicationServerCommon::Handle_qGroupName( + StringExtractorGDBRemote &packet) { #if !defined(LLDB_DISABLE_POSIX) - // Packet format: "qGroupName:%i" where %i is the gid - packet.SetFilePos(::strlen ("qGroupName:")); - uint32_t gid = packet.GetU32 (UINT32_MAX); - if (gid != UINT32_MAX) - { - std::string name; - if (HostInfo::LookupGroupName(gid, name)) - { - StreamString response; - response.PutCStringAsRawHex8 (name.c_str()); - return SendPacketNoLock (response.GetData(), response.GetSize()); - } + // Packet format: "qGroupName:%i" where %i is the gid + packet.SetFilePos(::strlen("qGroupName:")); + uint32_t gid = packet.GetU32(UINT32_MAX); + if (gid != UINT32_MAX) { + std::string name; + if (HostInfo::LookupGroupName(gid, name)) { + StreamString response; + response.PutCStringAsRawHex8(name.c_str()); + return SendPacketNoLock(response.GetString()); } + } #endif - return SendErrorResponse (6); + return SendErrorResponse(6); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qSpeedTest (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("qSpeedTest:")); - - std::string key; - std::string value; - bool success = packet.GetNameColonValue(key, value); - if (success && key.compare("response_size") == 0) - { - uint32_t response_size = StringConvert::ToUInt32(value.c_str(), 0, 0, &success); - if (success) - { - if (response_size == 0) - return SendOKResponse(); - StreamString response; - uint32_t bytes_left = response_size; - response.PutCString("data:"); - while (bytes_left > 0) - { - if (bytes_left >= 26) - { - response.PutCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - bytes_left -= 26; - } - else - { - response.Printf ("%*.*s;", bytes_left, bytes_left, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - bytes_left = 0; - } - } - return SendPacketNoLock (response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_qSpeedTest( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("qSpeedTest:")); + + llvm::StringRef key; + llvm::StringRef value; + bool success = packet.GetNameColonValue(key, value); + if (success && key.equals("response_size")) { + uint32_t response_size = 0; + if (!value.getAsInteger(0, response_size)) { + if (response_size == 0) + return SendOKResponse(); + StreamString response; + uint32_t bytes_left = response_size; + response.PutCString("data:"); + while (bytes_left > 0) { + if (bytes_left >= 26) { + response.PutCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + bytes_left -= 26; + } else { + response.Printf("%*.*s;", bytes_left, bytes_left, + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + bytes_left = 0; } + } + return SendPacketNoLock(response.GetString()); } - return SendErrorResponse (7); + } + return SendErrorResponse(7); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_Open (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:open:")); - std::string path; - packet.GetHexByteStringTerminatedBy(path,','); - if (!path.empty()) - { - if (packet.GetChar() == ',') - { - uint32_t flags = File::ConvertOpenOptionsForPOSIXOpen( - packet.GetHexMaxU32(false, 0)); - if (packet.GetChar() == ',') - { - mode_t mode = packet.GetHexMaxU32(false, 0600); - Error error; - const FileSpec path_spec{path, true}; - int fd = ::open(path_spec.GetCString(), flags, mode); - const int save_errno = fd == -1 ? errno : 0; - StreamString response; - response.PutChar('F'); - response.Printf("%i", fd); - if (save_errno) - response.Printf(",%i", save_errno); - return SendPacketNoLock(response.GetData(), response.GetSize()); - } - } +GDBRemoteCommunicationServerCommon::Handle_vFile_Open( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:open:")); + std::string path; + packet.GetHexByteStringTerminatedBy(path, ','); + if (!path.empty()) { + if (packet.GetChar() == ',') { + uint32_t flags = + File::ConvertOpenOptionsForPOSIXOpen(packet.GetHexMaxU32(false, 0)); + if (packet.GetChar() == ',') { + mode_t mode = packet.GetHexMaxU32(false, 0600); + Error error; + const FileSpec path_spec{path, true}; + int fd = ::open(path_spec.GetCString(), flags, mode); + const int save_errno = fd == -1 ? errno : 0; + StreamString response; + response.PutChar('F'); + response.Printf("%i", fd); + if (save_errno) + response.Printf(",%i", save_errno); + return SendPacketNoLock(response.GetString()); + } } - return SendErrorResponse(18); + } + return SendErrorResponse(18); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_Close (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:close:")); - int fd = packet.GetS32(-1); - Error error; - int err = -1; - int save_errno = 0; - if (fd >= 0) - { - err = close(fd); - save_errno = err == -1 ? errno : 0; - } - else - { - save_errno = EINVAL; - } - StreamString response; - response.PutChar('F'); - response.Printf("%i", err); - if (save_errno) - response.Printf(",%i", save_errno); - return SendPacketNoLock(response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_vFile_Close( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:close:")); + int fd = packet.GetS32(-1); + Error error; + int err = -1; + int save_errno = 0; + if (fd >= 0) { + err = close(fd); + save_errno = err == -1 ? errno : 0; + } else { + save_errno = EINVAL; + } + StreamString response; + response.PutChar('F'); + response.Printf("%i", err); + if (save_errno) + response.Printf(",%i", save_errno); + return SendPacketNoLock(response.GetString()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_pRead (StringExtractorGDBRemote &packet) -{ +GDBRemoteCommunicationServerCommon::Handle_vFile_pRead( + StringExtractorGDBRemote &packet) { #ifdef _WIN32 - // Not implemented on Windows - return SendUnimplementedResponse("GDBRemoteCommunicationServerCommon::Handle_vFile_pRead() unimplemented"); + // Not implemented on Windows + return SendUnimplementedResponse( + "GDBRemoteCommunicationServerCommon::Handle_vFile_pRead() unimplemented"); #else - StreamGDBRemote response; - packet.SetFilePos(::strlen("vFile:pread:")); - int fd = packet.GetS32(-1); - if (packet.GetChar() == ',') - { - uint64_t count = packet.GetU64(UINT64_MAX); - if (packet.GetChar() == ',') - { - uint64_t offset = packet.GetU64(UINT32_MAX); - if (count == UINT64_MAX) - { - response.Printf("F-1:%i", EINVAL); - return SendPacketNoLock(response.GetData(), response.GetSize()); - } - - std::string buffer(count, 0); - const ssize_t bytes_read = ::pread (fd, &buffer[0], buffer.size(), offset); - const int save_errno = bytes_read == -1 ? errno : 0; - response.PutChar('F'); - response.Printf("%zi", bytes_read); - if (save_errno) - response.Printf(",%i", save_errno); - else - { - response.PutChar(';'); - response.PutEscapedBytes(&buffer[0], bytes_read); - } - return SendPacketNoLock(response.GetData(), response.GetSize()); - } + StreamGDBRemote response; + packet.SetFilePos(::strlen("vFile:pread:")); + int fd = packet.GetS32(-1); + if (packet.GetChar() == ',') { + uint64_t count = packet.GetU64(UINT64_MAX); + if (packet.GetChar() == ',') { + uint64_t offset = packet.GetU64(UINT32_MAX); + if (count == UINT64_MAX) { + response.Printf("F-1:%i", EINVAL); + return SendPacketNoLock(response.GetString()); + } + + std::string buffer(count, 0); + const ssize_t bytes_read = ::pread(fd, &buffer[0], buffer.size(), offset); + const int save_errno = bytes_read == -1 ? errno : 0; + response.PutChar('F'); + response.Printf("%zi", bytes_read); + if (save_errno) + response.Printf(",%i", save_errno); + else { + response.PutChar(';'); + response.PutEscapedBytes(&buffer[0], bytes_read); + } + return SendPacketNoLock(response.GetString()); } - return SendErrorResponse(21); + } + return SendErrorResponse(21); #endif } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite (StringExtractorGDBRemote &packet) -{ +GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite( + StringExtractorGDBRemote &packet) { #ifdef _WIN32 - return SendUnimplementedResponse("GDBRemoteCommunicationServerCommon::Handle_vFile_pWrite() unimplemented"); + return SendUnimplementedResponse("GDBRemoteCommunicationServerCommon::Handle_" + "vFile_pWrite() unimplemented"); #else - packet.SetFilePos(::strlen("vFile:pwrite:")); - - StreamGDBRemote response; - response.PutChar('F'); - - int fd = packet.GetU32(UINT32_MAX); - if (packet.GetChar() == ',') - { - off_t offset = packet.GetU64(UINT32_MAX); - if (packet.GetChar() == ',') - { - std::string buffer; - if (packet.GetEscapedBinaryData(buffer)) - { - const ssize_t bytes_written = ::pwrite (fd, buffer.data(), buffer.size(), offset); - const int save_errno = bytes_written == -1 ? errno : 0; - response.Printf("%zi", bytes_written); - if (save_errno) - response.Printf(",%i", save_errno); - } - else - { - response.Printf ("-1,%i", EINVAL); - } - return SendPacketNoLock(response.GetData(), response.GetSize()); - } + packet.SetFilePos(::strlen("vFile:pwrite:")); + + StreamGDBRemote response; + response.PutChar('F'); + + int fd = packet.GetU32(UINT32_MAX); + if (packet.GetChar() == ',') { + off_t offset = packet.GetU64(UINT32_MAX); + if (packet.GetChar() == ',') { + std::string buffer; + if (packet.GetEscapedBinaryData(buffer)) { + const ssize_t bytes_written = + ::pwrite(fd, buffer.data(), buffer.size(), offset); + const int save_errno = bytes_written == -1 ? errno : 0; + response.Printf("%zi", bytes_written); + if (save_errno) + response.Printf(",%i", save_errno); + } else { + response.Printf("-1,%i", EINVAL); + } + return SendPacketNoLock(response.GetString()); } - return SendErrorResponse(27); + } + return SendErrorResponse(27); #endif } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_Size (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:size:")); - std::string path; - packet.GetHexByteString(path); - if (!path.empty()) - { - lldb::user_id_t retcode = FileSystem::GetFileSize(FileSpec(path.c_str(), false)); - StreamString response; - response.PutChar('F'); - response.PutHex64(retcode); - if (retcode == UINT64_MAX) - { - response.PutChar(','); - response.PutHex64(retcode); // TODO: replace with Host::GetSyswideErrorCode() - } - return SendPacketNoLock(response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_vFile_Size( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:size:")); + std::string path; + packet.GetHexByteString(path); + if (!path.empty()) { + lldb::user_id_t retcode = FileSystem::GetFileSize(FileSpec(path, false)); + StreamString response; + response.PutChar('F'); + response.PutHex64(retcode); + if (retcode == UINT64_MAX) { + response.PutChar(','); + response.PutHex64( + retcode); // TODO: replace with Host::GetSyswideErrorCode() } - return SendErrorResponse(22); + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(22); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_Mode (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:mode:")); - std::string path; - packet.GetHexByteString(path); - if (!path.empty()) - { - Error error; - const uint32_t mode = File::GetPermissions(FileSpec{path, true}, error); - StreamString response; - response.Printf("F%u", mode); - if (mode == 0 || error.Fail()) - response.Printf(",%i", (int)error.GetError()); - return SendPacketNoLock(response.GetData(), response.GetSize()); - } - return SendErrorResponse(23); +GDBRemoteCommunicationServerCommon::Handle_vFile_Mode( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:mode:")); + std::string path; + packet.GetHexByteString(path); + if (!path.empty()) { + Error error; + const uint32_t mode = File::GetPermissions(FileSpec{path, true}, error); + StreamString response; + response.Printf("F%u", mode); + if (mode == 0 || error.Fail()) + response.Printf(",%i", (int)error.GetError()); + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(23); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_Exists (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:exists:")); - std::string path; - packet.GetHexByteString(path); - if (!path.empty()) - { - bool retcode = FileSystem::GetFileExists(FileSpec(path.c_str(), false)); - StreamString response; - response.PutChar('F'); - response.PutChar(','); - if (retcode) - response.PutChar('1'); - else - response.PutChar('0'); - return SendPacketNoLock(response.GetData(), response.GetSize()); - } - return SendErrorResponse(24); +GDBRemoteCommunicationServerCommon::Handle_vFile_Exists( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:exists:")); + std::string path; + packet.GetHexByteString(path); + if (!path.empty()) { + bool retcode = FileSystem::GetFileExists(FileSpec(path, false)); + StreamString response; + response.PutChar('F'); + response.PutChar(','); + if (retcode) + response.PutChar('1'); + else + response.PutChar('0'); + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(24); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_symlink (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:symlink:")); - std::string dst, src; - packet.GetHexByteStringTerminatedBy(dst, ','); - packet.GetChar(); // Skip ',' char - packet.GetHexByteString(src); - Error error = FileSystem::Symlink(FileSpec{src, true}, FileSpec{dst, false}); - StreamString response; - response.Printf("F%u,%u", error.GetError(), error.GetError()); - return SendPacketNoLock(response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_vFile_symlink( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:symlink:")); + std::string dst, src; + packet.GetHexByteStringTerminatedBy(dst, ','); + packet.GetChar(); // Skip ',' char + packet.GetHexByteString(src); + Error error = FileSystem::Symlink(FileSpec{src, true}, FileSpec{dst, false}); + StreamString response; + response.Printf("F%u,%u", error.GetError(), error.GetError()); + return SendPacketNoLock(response.GetString()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_unlink (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:unlink:")); - std::string path; - packet.GetHexByteString(path); - Error error = FileSystem::Unlink(FileSpec{path, true}); - StreamString response; - response.Printf("F%u,%u", error.GetError(), error.GetError()); - return SendPacketNoLock(response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_vFile_unlink( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:unlink:")); + std::string path; + packet.GetHexByteString(path); + Error error = FileSystem::Unlink(FileSpec{path, true}); + StreamString response; + response.Printf("F%u,%u", error.GetError(), error.GetError()); + return SendPacketNoLock(response.GetString()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("qPlatform_shell:")); - std::string path; - std::string working_dir; - packet.GetHexByteStringTerminatedBy(path,','); - if (!path.empty()) - { - if (packet.GetChar() == ',') - { - // FIXME: add timeout to qPlatform_shell packet - // uint32_t timeout = packet.GetHexMaxU32(false, 32); - uint32_t timeout = 10; - if (packet.GetChar() == ',') - packet.GetHexByteString(working_dir); - int status, signo; - std::string output; - Error err = Host::RunShellCommand(path.c_str(), - FileSpec{working_dir, true}, - &status, &signo, &output, timeout); - StreamGDBRemote response; - if (err.Fail()) - { - response.PutCString("F,"); - response.PutHex32(UINT32_MAX); - } - else - { - response.PutCString("F,"); - response.PutHex32(status); - response.PutChar(','); - response.PutHex32(signo); - response.PutChar(','); - response.PutEscapedBytes(output.c_str(), output.size()); - } - return SendPacketNoLock(response.GetData(), response.GetSize()); - } +GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("qPlatform_shell:")); + std::string path; + std::string working_dir; + packet.GetHexByteStringTerminatedBy(path, ','); + if (!path.empty()) { + if (packet.GetChar() == ',') { + // FIXME: add timeout to qPlatform_shell packet + // uint32_t timeout = packet.GetHexMaxU32(false, 32); + uint32_t timeout = 10; + if (packet.GetChar() == ',') + packet.GetHexByteString(working_dir); + int status, signo; + std::string output; + Error err = + Host::RunShellCommand(path.c_str(), FileSpec{working_dir, true}, + &status, &signo, &output, timeout); + StreamGDBRemote response; + if (err.Fail()) { + response.PutCString("F,"); + response.PutHex32(UINT32_MAX); + } else { + response.PutCString("F,"); + response.PutHex32(status); + response.PutChar(','); + response.PutHex32(signo); + response.PutChar(','); + response.PutEscapedBytes(output.c_str(), output.size()); + } + return SendPacketNoLock(response.GetString()); } - return SendErrorResponse(24); + } + return SendErrorResponse(24); } - GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_Stat (StringExtractorGDBRemote &packet) -{ - return SendUnimplementedResponse("GDBRemoteCommunicationServerCommon::Handle_vFile_Stat() unimplemented"); +GDBRemoteCommunicationServerCommon::Handle_vFile_Stat( + StringExtractorGDBRemote &packet) { + return SendUnimplementedResponse( + "GDBRemoteCommunicationServerCommon::Handle_vFile_Stat() unimplemented"); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_vFile_MD5 (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("vFile:MD5:")); - std::string path; - packet.GetHexByteString(path); - if (!path.empty()) - { - uint64_t a,b; - StreamGDBRemote response; - if (!FileSystem::CalculateMD5(FileSpec(path.c_str(), false), a, b)) - { - response.PutCString("F,"); - response.PutCString("x"); - } - else - { - response.PutCString("F,"); - response.PutHex64(a); - response.PutHex64(b); - } - return SendPacketNoLock(response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_vFile_MD5( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("vFile:MD5:")); + std::string path; + packet.GetHexByteString(path); + if (!path.empty()) { + uint64_t a, b; + StreamGDBRemote response; + if (!FileSystem::CalculateMD5(FileSpec(path, false), a, b)) { + response.PutCString("F,"); + response.PutCString("x"); + } else { + response.PutCString("F,"); + response.PutHex64(a); + response.PutHex64(b); } - return SendErrorResponse(25); + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(25); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("qPlatform_mkdir:")); - mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); - if (packet.GetChar() == ',') - { - std::string path; - packet.GetHexByteString(path); - Error error = FileSystem::MakeDirectory(FileSpec{path, false}, mode); - - StreamGDBRemote response; - response.Printf("F%u", error.GetError()); - - return SendPacketNoLock(response.GetData(), response.GetSize()); - } - return SendErrorResponse(20); +GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("qPlatform_mkdir:")); + mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); + if (packet.GetChar() == ',') { + std::string path; + packet.GetHexByteString(path); + Error error = FileSystem::MakeDirectory(FileSpec{path, false}, mode); + + StreamGDBRemote response; + response.Printf("F%u", error.GetError()); + + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(20); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("qPlatform_chmod:")); +GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("qPlatform_chmod:")); - mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); - if (packet.GetChar() == ',') - { - std::string path; - packet.GetHexByteString(path); - Error error = FileSystem::SetFilePermissions(FileSpec{path, true}, mode); + mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX); + if (packet.GetChar() == ',') { + std::string path; + packet.GetHexByteString(path); + Error error = FileSystem::SetFilePermissions(FileSpec{path, true}, mode); - StreamGDBRemote response; - response.Printf("F%u", error.GetError()); + StreamGDBRemote response; + response.Printf("F%u", error.GetError()); - return SendPacketNoLock(response.GetData(), response.GetSize()); - } - return SendErrorResponse(19); + return SendPacketNoLock(response.GetString()); + } + return SendErrorResponse(19); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qSupported (StringExtractorGDBRemote &packet) -{ - StreamGDBRemote response; - - // Features common to lldb-platform and llgs. - uint32_t max_packet_size = 128 * 1024; // 128KBytes is a reasonable max packet size--debugger can always use less - response.Printf ("PacketSize=%x", max_packet_size); - - response.PutCString (";QStartNoAckMode+"); - response.PutCString (";QThreadSuffixSupported+"); - response.PutCString (";QListThreadsInStopReply+"); - response.PutCString (";qEcho+"); +GDBRemoteCommunicationServerCommon::Handle_qSupported( + StringExtractorGDBRemote &packet) { + StreamGDBRemote response; + + // Features common to lldb-platform and llgs. + uint32_t max_packet_size = 128 * 1024; // 128KBytes is a reasonable max packet + // size--debugger can always use less + response.Printf("PacketSize=%x", max_packet_size); + + response.PutCString(";QStartNoAckMode+"); + response.PutCString(";QThreadSuffixSupported+"); + response.PutCString(";QListThreadsInStopReply+"); + response.PutCString(";qEcho+"); #if defined(__linux__) - response.PutCString (";qXfer:auxv:read+"); + response.PutCString(";qXfer:auxv:read+"); #endif - return SendPacketNoLock(response.GetData(), response.GetSize()); + return SendPacketNoLock(response.GetString()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QThreadSuffixSupported (StringExtractorGDBRemote &packet) -{ - m_thread_suffix_supported = true; - return SendOKResponse(); +GDBRemoteCommunicationServerCommon::Handle_QThreadSuffixSupported( + StringExtractorGDBRemote &packet) { + m_thread_suffix_supported = true; + return SendOKResponse(); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QListThreadsInStopReply (StringExtractorGDBRemote &packet) -{ - m_list_threads_in_stop_reply = true; - return SendOKResponse(); +GDBRemoteCommunicationServerCommon::Handle_QListThreadsInStopReply( + StringExtractorGDBRemote &packet) { + m_list_threads_in_stop_reply = true; + return SendOKResponse(); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QSetDetachOnError (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("QSetDetachOnError:")); - if (packet.GetU32(0)) - m_process_launch_info.GetFlags().Set (eLaunchFlagDetachOnError); - else - m_process_launch_info.GetFlags().Clear (eLaunchFlagDetachOnError); - return SendOKResponse (); +GDBRemoteCommunicationServerCommon::Handle_QSetDetachOnError( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QSetDetachOnError:")); + if (packet.GetU32(0)) + m_process_launch_info.GetFlags().Set(eLaunchFlagDetachOnError); + else + m_process_launch_info.GetFlags().Clear(eLaunchFlagDetachOnError); + return SendOKResponse(); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QStartNoAckMode (StringExtractorGDBRemote &packet) -{ - // Send response first before changing m_send_acks to we ack this packet - PacketResult packet_result = SendOKResponse (); - m_send_acks = false; - return packet_result; +GDBRemoteCommunicationServerCommon::Handle_QStartNoAckMode( + StringExtractorGDBRemote &packet) { + // Send response first before changing m_send_acks to we ack this packet + PacketResult packet_result = SendOKResponse(); + m_send_acks = false; + return packet_result; } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QSetSTDIN (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("QSetSTDIN:")); - FileAction file_action; - std::string path; - packet.GetHexByteString(path); - const bool read = false; - const bool write = true; - if (file_action.Open(STDIN_FILENO, FileSpec{path, false}, read, write)) - { - m_process_launch_info.AppendFileAction(file_action); - return SendOKResponse (); - } - return SendErrorResponse (15); +GDBRemoteCommunicationServerCommon::Handle_QSetSTDIN( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QSetSTDIN:")); + FileAction file_action; + std::string path; + packet.GetHexByteString(path); + const bool read = true; + const bool write = false; + if (file_action.Open(STDIN_FILENO, FileSpec{path, false}, read, write)) { + m_process_launch_info.AppendFileAction(file_action); + return SendOKResponse(); + } + return SendErrorResponse(15); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QSetSTDOUT (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("QSetSTDOUT:")); - FileAction file_action; - std::string path; - packet.GetHexByteString(path); - const bool read = true; - const bool write = false; - if (file_action.Open(STDOUT_FILENO, FileSpec{path, false}, read, write)) - { - m_process_launch_info.AppendFileAction(file_action); - return SendOKResponse (); - } - return SendErrorResponse (16); +GDBRemoteCommunicationServerCommon::Handle_QSetSTDOUT( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QSetSTDOUT:")); + FileAction file_action; + std::string path; + packet.GetHexByteString(path); + const bool read = false; + const bool write = true; + if (file_action.Open(STDOUT_FILENO, FileSpec{path, false}, read, write)) { + m_process_launch_info.AppendFileAction(file_action); + return SendOKResponse(); + } + return SendErrorResponse(16); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QSetSTDERR (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("QSetSTDERR:")); - FileAction file_action; - std::string path; - packet.GetHexByteString(path); - const bool read = true; - const bool write = false; - if (file_action.Open(STDERR_FILENO, FileSpec{path, false}, read, write)) - { - m_process_launch_info.AppendFileAction(file_action); - return SendOKResponse (); - } - return SendErrorResponse (17); +GDBRemoteCommunicationServerCommon::Handle_QSetSTDERR( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QSetSTDERR:")); + FileAction file_action; + std::string path; + packet.GetHexByteString(path); + const bool read = false; + const bool write = true; + if (file_action.Open(STDERR_FILENO, FileSpec{path, false}, read, write)) { + m_process_launch_info.AppendFileAction(file_action); + return SendOKResponse(); + } + return SendErrorResponse(17); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess (StringExtractorGDBRemote &packet) -{ - if (m_process_launch_error.Success()) - return SendOKResponse(); - StreamString response; - response.PutChar('E'); - response.PutCString(m_process_launch_error.AsCString("<unknown error>")); - return SendPacketNoLock (response.GetData(), response.GetSize()); +GDBRemoteCommunicationServerCommon::Handle_qLaunchSuccess( + StringExtractorGDBRemote &packet) { + if (m_process_launch_error.Success()) + return SendOKResponse(); + StreamString response; + response.PutChar('E'); + response.PutCString(m_process_launch_error.AsCString("<unknown error>")); + return SendPacketNoLock(response.GetString()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QEnvironment (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("QEnvironment:")); - const uint32_t bytes_left = packet.GetBytesLeft(); - if (bytes_left > 0) - { - m_process_launch_info.GetEnvironmentEntries ().AppendArgument (packet.Peek()); - return SendOKResponse (); - } - return SendErrorResponse (12); +GDBRemoteCommunicationServerCommon::Handle_QEnvironment( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QEnvironment:")); + const uint32_t bytes_left = packet.GetBytesLeft(); + if (bytes_left > 0) { + m_process_launch_info.GetEnvironmentEntries().AppendArgument( + llvm::StringRef::withNullAsEmpty(packet.Peek())); + return SendOKResponse(); + } + return SendErrorResponse(12); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen("QEnvironmentHexEncoded:")); - const uint32_t bytes_left = packet.GetBytesLeft(); - if (bytes_left > 0) - { - std::string str; - packet.GetHexByteString(str); - m_process_launch_info.GetEnvironmentEntries().AppendArgument(str.c_str()); - return SendOKResponse(); - } - return SendErrorResponse(12); +GDBRemoteCommunicationServerCommon::Handle_QEnvironmentHexEncoded( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QEnvironmentHexEncoded:")); + const uint32_t bytes_left = packet.GetBytesLeft(); + if (bytes_left > 0) { + std::string str; + packet.GetHexByteString(str); + m_process_launch_info.GetEnvironmentEntries().AppendArgument(str); + return SendOKResponse(); + } + return SendErrorResponse(12); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_QLaunchArch (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("QLaunchArch:")); - const uint32_t bytes_left = packet.GetBytesLeft(); - if (bytes_left > 0) - { - const char* arch_triple = packet.Peek(); - ArchSpec arch_spec(arch_triple,NULL); - m_process_launch_info.SetArchitecture(arch_spec); - return SendOKResponse(); - } - return SendErrorResponse(13); +GDBRemoteCommunicationServerCommon::Handle_QLaunchArch( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("QLaunchArch:")); + const uint32_t bytes_left = packet.GetBytesLeft(); + if (bytes_left > 0) { + const char *arch_triple = packet.Peek(); + ArchSpec arch_spec(arch_triple, NULL); + m_process_launch_info.SetArchitecture(arch_spec); + return SendOKResponse(); + } + return SendErrorResponse(13); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_A (StringExtractorGDBRemote &packet) -{ - // The 'A' packet is the most over designed packet ever here with - // redundant argument indexes, redundant argument lengths and needed hex - // encoded argument string values. Really all that is needed is a comma - // separated hex encoded argument value list, but we will stay true to the - // documented version of the 'A' packet here... - - Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - int actual_arg_index = 0; - - packet.SetFilePos(1); // Skip the 'A' - bool success = true; - while (success && packet.GetBytesLeft() > 0) - { - // Decode the decimal argument string length. This length is the - // number of hex nibbles in the argument string value. - const uint32_t arg_len = packet.GetU32(UINT32_MAX); - if (arg_len == UINT32_MAX) +GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) { + // The 'A' packet is the most over designed packet ever here with + // redundant argument indexes, redundant argument lengths and needed hex + // encoded argument string values. Really all that is needed is a comma + // separated hex encoded argument value list, but we will stay true to the + // documented version of the 'A' packet here... + + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); + int actual_arg_index = 0; + + packet.SetFilePos(1); // Skip the 'A' + bool success = true; + while (success && packet.GetBytesLeft() > 0) { + // Decode the decimal argument string length. This length is the + // number of hex nibbles in the argument string value. + const uint32_t arg_len = packet.GetU32(UINT32_MAX); + if (arg_len == UINT32_MAX) + success = false; + else { + // Make sure the argument hex string length is followed by a comma + if (packet.GetChar() != ',') + success = false; + else { + // Decode the argument index. We ignore this really because + // who would really send down the arguments in a random order??? + const uint32_t arg_idx = packet.GetU32(UINT32_MAX); + if (arg_idx == UINT32_MAX) + success = false; + else { + // Make sure the argument index is followed by a comma + if (packet.GetChar() != ',') success = false; - else - { - // Make sure the argument hex string length is followed by a comma - if (packet.GetChar() != ',') - success = false; - else - { - // Decode the argument index. We ignore this really because - // who would really send down the arguments in a random order??? - const uint32_t arg_idx = packet.GetU32(UINT32_MAX); - if (arg_idx == UINT32_MAX) - success = false; - else - { - // Make sure the argument index is followed by a comma - if (packet.GetChar() != ',') - success = false; - else - { - // Decode the argument string value from hex bytes - // back into a UTF8 string and make sure the length - // matches the one supplied in the packet - std::string arg; - if (packet.GetHexByteStringFixedLength(arg, arg_len) != (arg_len / 2)) - success = false; - else - { - // If there are any bytes left - if (packet.GetBytesLeft()) - { - if (packet.GetChar() != ',') - success = false; - } - - if (success) - { - if (arg_idx == 0) - m_process_launch_info.GetExecutableFile().SetFile(arg.c_str(), false); - m_process_launch_info.GetArguments().AppendArgument(arg.c_str()); - if (log) - log->Printf ("LLGSPacketHandler::%s added arg %d: \"%s\"", __FUNCTION__, actual_arg_index, arg.c_str ()); - ++actual_arg_index; - } - } - } - } + else { + // Decode the argument string value from hex bytes + // back into a UTF8 string and make sure the length + // matches the one supplied in the packet + std::string arg; + if (packet.GetHexByteStringFixedLength(arg, arg_len) != + (arg_len / 2)) + success = false; + else { + // If there are any bytes left + if (packet.GetBytesLeft()) { + if (packet.GetChar() != ',') + success = false; + } + + if (success) { + if (arg_idx == 0) + m_process_launch_info.GetExecutableFile().SetFile(arg, false); + m_process_launch_info.GetArguments().AppendArgument(arg); + if (log) + log->Printf("LLGSPacketHandler::%s added arg %d: \"%s\"", + __FUNCTION__, actual_arg_index, arg.c_str()); + ++actual_arg_index; + } } + } } + } } - - if (success) - { - m_process_launch_error = LaunchProcess (); - if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) - { - return SendOKResponse (); - } - else - { - Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); - if (log) - log->Printf("LLGSPacketHandler::%s failed to launch exe: %s", - __FUNCTION__, - m_process_launch_error.AsCString()); - - } + } + + if (success) { + m_process_launch_error = LaunchProcess(); + if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) { + return SendOKResponse(); + } else { + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); + if (log) + log->Printf("LLGSPacketHandler::%s failed to launch exe: %s", + __FUNCTION__, m_process_launch_error.AsCString()); } - return SendErrorResponse (8); + } + return SendErrorResponse(8); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qEcho (StringExtractorGDBRemote &packet) -{ - // Just echo back the exact same packet for qEcho... - return SendPacketNoLock(packet.GetStringRef().c_str(), packet.GetStringRef().size()); +GDBRemoteCommunicationServerCommon::Handle_qEcho( + StringExtractorGDBRemote &packet) { + // Just echo back the exact same packet for qEcho... + return SendPacketNoLock(packet.GetStringRef()); } GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServerCommon::Handle_qModuleInfo (StringExtractorGDBRemote &packet) -{ - packet.SetFilePos(::strlen ("qModuleInfo:")); - - std::string module_path; - packet.GetHexByteStringTerminatedBy(module_path, ';'); - if (module_path.empty()) - return SendErrorResponse (1); - - if (packet.GetChar() != ';') - return SendErrorResponse (2); - - std::string triple; - packet.GetHexByteString(triple); - ArchSpec arch(triple.c_str()); - - const FileSpec req_module_path_spec(module_path.c_str(), true); - const FileSpec module_path_spec = FindModuleFile(req_module_path_spec.GetPath(), arch); - const ModuleSpec module_spec(module_path_spec, arch); - - ModuleSpecList module_specs; - if (!ObjectFile::GetModuleSpecifications(module_path_spec, 0, 0, module_specs)) - return SendErrorResponse (3); +GDBRemoteCommunicationServerCommon::Handle_qModuleInfo( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("qModuleInfo:")); + + std::string module_path; + packet.GetHexByteStringTerminatedBy(module_path, ';'); + if (module_path.empty()) + return SendErrorResponse(1); + + if (packet.GetChar() != ';') + return SendErrorResponse(2); + + std::string triple; + packet.GetHexByteString(triple); + + ModuleSpec matched_module_spec = GetModuleInfo(module_path, triple); + if (!matched_module_spec.GetFileSpec()) + return SendErrorResponse(3); + + const auto file_offset = matched_module_spec.GetObjectOffset(); + const auto file_size = matched_module_spec.GetObjectSize(); + const auto uuid_str = matched_module_spec.GetUUID().GetAsString(""); + + StreamGDBRemote response; + + if (uuid_str.empty()) { + std::string md5_hash; + if (!FileSystem::CalculateMD5AsString(matched_module_spec.GetFileSpec(), + file_offset, file_size, md5_hash)) + return SendErrorResponse(5); + response.PutCString("md5:"); + response.PutCStringAsRawHex8(md5_hash.c_str()); + } else { + response.PutCString("uuid:"); + response.PutCStringAsRawHex8(uuid_str.c_str()); + } + response.PutChar(';'); + + const auto &module_arch = matched_module_spec.GetArchitecture(); + response.PutCString("triple:"); + response.PutCStringAsRawHex8(module_arch.GetTriple().getTriple().c_str()); + response.PutChar(';'); + + response.PutCString("file_path:"); + response.PutCStringAsRawHex8(matched_module_spec.GetFileSpec().GetCString()); + response.PutChar(';'); + response.PutCString("file_offset:"); + response.PutHex64(file_offset); + response.PutChar(';'); + response.PutCString("file_size:"); + response.PutHex64(file_size); + response.PutChar(';'); + + return SendPacketNoLock(response.GetString()); +} - ModuleSpec matched_module_spec; - if (!module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) - return SendErrorResponse (4); +GDBRemoteCommunication::PacketResult +GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( + StringExtractorGDBRemote &packet) { + packet.SetFilePos(::strlen("jModulesInfo:")); + + StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(packet.Peek()); + if (!object_sp) + return SendErrorResponse(1); + + StructuredData::Array *packet_array = object_sp->GetAsArray(); + if (!packet_array) + return SendErrorResponse(2); + + JSONArray::SP response_array_sp = std::make_shared<JSONArray>(); + for (size_t i = 0; i < packet_array->GetSize(); ++i) { + StructuredData::Dictionary *query = + packet_array->GetItemAtIndex(i)->GetAsDictionary(); + if (!query) + continue; + std::string file, triple; + if (!query->GetValueForKeyAsString("file", file) || + !query->GetValueForKeyAsString("triple", triple)) + continue; + + ModuleSpec matched_module_spec = GetModuleInfo(file, triple); + if (!matched_module_spec.GetFileSpec()) + continue; const auto file_offset = matched_module_spec.GetObjectOffset(); const auto file_size = matched_module_spec.GetObjectSize(); const auto uuid_str = matched_module_spec.GetUUID().GetAsString(""); - StreamGDBRemote response; - if (uuid_str.empty()) - { - std::string md5_hash; - if (!FileSystem::CalculateMD5AsString(matched_module_spec.GetFileSpec(), file_offset, file_size, md5_hash)) - return SendErrorResponse (5); - response.PutCString ("md5:"); - response.PutCStringAsRawHex8(md5_hash.c_str()); - } - else{ - response.PutCString ("uuid:"); - response.PutCStringAsRawHex8(uuid_str.c_str()); - } - response.PutChar(';'); + continue; + + JSONObject::SP response = std::make_shared<JSONObject>(); + response_array_sp->AppendObject(response); + response->SetObject("uuid", std::make_shared<JSONString>(uuid_str)); + response->SetObject( + "triple", + std::make_shared<JSONString>( + matched_module_spec.GetArchitecture().GetTriple().getTriple())); + response->SetObject("file_path", + std::make_shared<JSONString>( + matched_module_spec.GetFileSpec().GetPath())); + response->SetObject("file_offset", + std::make_shared<JSONNumber>(file_offset)); + response->SetObject("file_size", std::make_shared<JSONNumber>(file_size)); + } + + StreamString response; + response_array_sp->Write(response); + StreamGDBRemote escaped_response; + escaped_response.PutEscapedBytes(response.GetString().data(), + response.GetSize()); + return SendPacketNoLock(escaped_response.GetString()); +} - const auto &module_arch = matched_module_spec.GetArchitecture(); +void GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse( + const ProcessInstanceInfo &proc_info, StreamString &response) { + response.Printf( + "pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;", + proc_info.GetProcessID(), proc_info.GetParentProcessID(), + proc_info.GetUserID(), proc_info.GetGroupID(), + proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID()); + response.PutCString("name:"); + response.PutCStringAsRawHex8(proc_info.GetExecutableFile().GetCString()); + response.PutChar(';'); + const ArchSpec &proc_arch = proc_info.GetArchitecture(); + if (proc_arch.IsValid()) { + const llvm::Triple &proc_triple = proc_arch.GetTriple(); response.PutCString("triple:"); - response.PutCStringAsRawHex8( module_arch.GetTriple().getTriple().c_str()); - response.PutChar(';'); - - response.PutCString("file_path:"); - response.PutCStringAsRawHex8(module_path_spec.GetCString()); - response.PutChar(';'); - response.PutCString("file_offset:"); - response.PutHex64(file_offset); + response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); response.PutChar(';'); - response.PutCString("file_size:"); - response.PutHex64(file_size); - response.PutChar(';'); - - return SendPacketNoLock(response.GetData(), response.GetSize()); + } } -void -GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, - StreamString &response) -{ - response.Printf ("pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;", - proc_info.GetProcessID(), - proc_info.GetParentProcessID(), - proc_info.GetUserID(), - proc_info.GetGroupID(), - proc_info.GetEffectiveUserID(), - proc_info.GetEffectiveGroupID()); - response.PutCString ("name:"); - response.PutCStringAsRawHex8(proc_info.GetExecutableFile().GetCString()); +void GDBRemoteCommunicationServerCommon:: + CreateProcessInfoResponse_DebugServerStyle( + const ProcessInstanceInfo &proc_info, StreamString &response) { + response.Printf("pid:%" PRIx64 ";parent-pid:%" PRIx64 + ";real-uid:%x;real-gid:%x;effective-uid:%x;effective-gid:%x;", + proc_info.GetProcessID(), proc_info.GetParentProcessID(), + proc_info.GetUserID(), proc_info.GetGroupID(), + proc_info.GetEffectiveUserID(), + proc_info.GetEffectiveGroupID()); + + const ArchSpec &proc_arch = proc_info.GetArchitecture(); + if (proc_arch.IsValid()) { + const llvm::Triple &proc_triple = proc_arch.GetTriple(); +#if defined(__APPLE__) + // We'll send cputype/cpusubtype. + const uint32_t cpu_type = proc_arch.GetMachOCPUType(); + if (cpu_type != 0) + response.Printf("cputype:%" PRIx32 ";", cpu_type); + + const uint32_t cpu_subtype = proc_arch.GetMachOCPUSubType(); + if (cpu_subtype != 0) + response.Printf("cpusubtype:%" PRIx32 ";", cpu_subtype); + + const std::string vendor = proc_triple.getVendorName(); + if (!vendor.empty()) + response.Printf("vendor:%s;", vendor.c_str()); +#else + // We'll send the triple. + response.PutCString("triple:"); + response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); response.PutChar(';'); - const ArchSpec &proc_arch = proc_info.GetArchitecture(); - if (proc_arch.IsValid()) - { - const llvm::Triple &proc_triple = proc_arch.GetTriple(); - response.PutCString("triple:"); - response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); - response.PutChar(';'); +#endif + std::string ostype = proc_triple.getOSName(); + // Adjust so ostype reports ios for Apple/ARM and Apple/ARM64. + if (proc_triple.getVendor() == llvm::Triple::Apple) { + switch (proc_triple.getArch()) { + case llvm::Triple::arm: + case llvm::Triple::thumb: + case llvm::Triple::aarch64: + ostype = "ios"; + break; + default: + // No change. + break; + } + } + response.Printf("ostype:%s;", ostype.c_str()); + + switch (proc_arch.GetByteOrder()) { + case lldb::eByteOrderLittle: + response.PutCString("endian:little;"); + break; + case lldb::eByteOrderBig: + response.PutCString("endian:big;"); + break; + case lldb::eByteOrderPDP: + response.PutCString("endian:pdp;"); + break; + default: + // Nothing. + break; } + // In case of MIPS64, pointer size is depend on ELF ABI + // For N32 the pointer size is 4 and for N64 it is 8 + std::string abi = proc_arch.GetTargetABI(); + if (!abi.empty()) + response.Printf("elf_abi:%s;", abi.c_str()); + response.Printf("ptrsize:%d;", proc_arch.GetAddressByteSize()); + } } -void -GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse_DebugServerStyle ( - const ProcessInstanceInfo &proc_info, StreamString &response) -{ - response.Printf ("pid:%" PRIx64 ";parent-pid:%" PRIx64 ";real-uid:%x;real-gid:%x;effective-uid:%x;effective-gid:%x;", - proc_info.GetProcessID(), - proc_info.GetParentProcessID(), - proc_info.GetUserID(), - proc_info.GetGroupID(), - proc_info.GetEffectiveUserID(), - proc_info.GetEffectiveGroupID()); - - const ArchSpec &proc_arch = proc_info.GetArchitecture(); - if (proc_arch.IsValid()) - { - const llvm::Triple &proc_triple = proc_arch.GetTriple(); -#if defined(__APPLE__) - // We'll send cputype/cpusubtype. - const uint32_t cpu_type = proc_arch.GetMachOCPUType(); - if (cpu_type != 0) - response.Printf ("cputype:%" PRIx32 ";", cpu_type); - - const uint32_t cpu_subtype = proc_arch.GetMachOCPUSubType(); - if (cpu_subtype != 0) - response.Printf ("cpusubtype:%" PRIx32 ";", cpu_subtype); - - const std::string vendor = proc_triple.getVendorName (); - if (!vendor.empty ()) - response.Printf ("vendor:%s;", vendor.c_str ()); +FileSpec GDBRemoteCommunicationServerCommon::FindModuleFile( + const std::string &module_path, const ArchSpec &arch) { +#ifdef __ANDROID__ + return HostInfoAndroid::ResolveLibraryPath(module_path, arch); #else - // We'll send the triple. - response.PutCString("triple:"); - response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); - response.PutChar(';'); + return FileSpec(module_path, true); #endif - std::string ostype = proc_triple.getOSName (); - // Adjust so ostype reports ios for Apple/ARM and Apple/ARM64. - if (proc_triple.getVendor () == llvm::Triple::Apple) - { - switch (proc_triple.getArch ()) - { - case llvm::Triple::arm: - case llvm::Triple::thumb: - case llvm::Triple::aarch64: - ostype = "ios"; - break; - default: - // No change. - break; - } - } - response.Printf ("ostype:%s;", ostype.c_str ()); +} +ModuleSpec GDBRemoteCommunicationServerCommon::GetModuleInfo( + const std::string &module_path, const std::string &triple) { + ArchSpec arch(triple.c_str()); - switch (proc_arch.GetByteOrder ()) - { - case lldb::eByteOrderLittle: response.PutCString ("endian:little;"); break; - case lldb::eByteOrderBig: response.PutCString ("endian:big;"); break; - case lldb::eByteOrderPDP: response.PutCString ("endian:pdp;"); break; - default: - // Nothing. - break; - } + const FileSpec req_module_path_spec(module_path, true); + const FileSpec module_path_spec = + FindModuleFile(req_module_path_spec.GetPath(), arch); + const ModuleSpec module_spec(module_path_spec, arch); - // In case of MIPS64, pointer size is depend on ELF ABI - // For N32 the pointer size is 4 and for N64 it is 8 - std::string abi = proc_arch.GetTargetABI(); - if (!abi.empty()) - response.Printf("elf_abi:%s;", abi.c_str()); - response.Printf("ptrsize:%d;", proc_arch.GetAddressByteSize()); - } -} + ModuleSpecList module_specs; + if (!ObjectFile::GetModuleSpecifications(module_path_spec, 0, 0, + module_specs)) + return ModuleSpec(); -FileSpec -GDBRemoteCommunicationServerCommon::FindModuleFile(const std::string& module_path, - const ArchSpec& arch) -{ -#ifdef __ANDROID__ - return HostInfoAndroid::ResolveLibraryPath(module_path, arch); -#else - return FileSpec(module_path.c_str(), true); -#endif + ModuleSpec matched_module_spec; + if (!module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) + return ModuleSpec(); + + return matched_module_spec; } |