summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/lldb/source/Plugins/Process
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2017-09-26 19:56:36 +0000
committerLuiz Souza <luiz@netgate.com>2018-02-21 15:12:19 -0300
commit1dcd2e8d24b295bc73e513acec2ed1514bb66be4 (patch)
tree4bd13a34c251e980e1a6b13584ca1f63b0dfe670 /contrib/llvm/tools/lldb/source/Plugins/Process
parentf45541ca2a56a1ba1202f94c080b04e96c1fa239 (diff)
downloadFreeBSD-src-1dcd2e8d24b295bc73e513acec2ed1514bb66be4.zip
FreeBSD-src-1dcd2e8d24b295bc73e513acec2ed1514bb66be4.tar.gz
Merge clang, llvm, lld, lldb, compiler-rt and libc++ 5.0.0 release.
MFC r309126 (by emaste): Correct lld llvm-tblgen dependency file name MFC r309169: Get rid of separate Subversion mergeinfo properties for llvm-dwarfdump and llvm-lto. The mergeinfo confuses Subversion enormously, and these directories will just use the mergeinfo for llvm itself. MFC r312765: Pull in r276136 from upstream llvm trunk (by Wei Mi): Use ValueOffsetPair to enhance value reuse during SCEV expansion. In D12090, the ExprValueMap was added to reuse existing value during SCEV expansion. However, const folding and sext/zext distribution can make the reuse still difficult. A simplified case is: suppose we know S1 expands to V1 in ExprValueMap, and S1 = S2 + C_a S3 = S2 + C_b where C_a and C_b are different SCEVConstants. Then we'd like to expand S3 as V1 - C_a + C_b instead of expanding S2 literally. It is helpful when S2 is a complex SCEV expr and S2 has no entry in ExprValueMap, which is usually caused by the fact that S3 is generated from S1 after const folding. In order to do that, we represent ExprValueMap as a mapping from SCEV to ValueOffsetPair. We will save both S1->{V1, 0} and S2->{V1, C_a} into the ExprValueMap when we create SCEV for V1. When S3 is expanded, it will first expand S2 to V1 - C_a because of S2->{V1, C_a} in the map, then expand S3 to V1 - C_a + C_b. Differential Revision: https://reviews.llvm.org/D21313 This should fix assertion failures when building OpenCV >= 3.1. PR: 215649 MFC r312831: Revert r312765 for now, since it causes assertions when building lang/spidermonkey24. Reported by: antoine PR: 215649 MFC r316511 (by jhb): Add an implementation of __ffssi2() derived from __ffsdi2(). Newer versions of GCC include an __ffssi2() symbol in libgcc and the compiler can emit calls to it in generated code. This is true for at least GCC 6.2 when compiling world for mips and mips64. Reviewed by: jmallett, dim Sponsored by: DARPA / AFRL Differential Revision: https://reviews.freebsd.org/D10086 MFC r318601 (by adrian): [libcompiler-rt] add bswapdi2/bswapsi2 This is required for mips gcc 6.3 userland to build/run. Reviewed by: emaste, dim Approved by: emaste Differential Revision: https://reviews.freebsd.org/D10838 MFC r318884 (by emaste): lldb: map TRAP_CAP to a trace trap In the absense of a more specific handler for TRAP_CAP (generated by ENOTCAPABLE or ECAPMODE while in capability mode) treat it as a trace trap. Example usage (testing the bug in PR219173): % proccontrol -m trapcap lldb usr.bin/hexdump/obj/hexdump -- -Cv -s 1 /bin/ls ... (lldb) run Process 12980 launching Process 12980 launched: '.../usr.bin/hexdump/obj/hexdump' (x86_64) Process 12980 stopped * thread #1, stop reason = trace frame #0: 0x0000004b80c65f1a libc.so.7`__sys_lseek + 10 ... In the future we should have LLDB control the trapcap procctl itself (as it does with ASLR), as well as report a specific stop reason. This change eliminates an assertion failure from LLDB for now. MFC r319796: Remove a few unneeded files from libllvm, libclang and liblldb. MFC r319885 (by emaste): lld: ELF: Fix ICF crash on absolute symbol relocations. If two sections contained relocations to absolute symbols with the same value we would crash when trying to access their sections. Add a check that both symbols point to sections before accessing their sections, and treat absolute symbols as equal if their values are equal. Obtained from: LLD commit r292578 MFC r319918: Revert r319796 for now, it can cause undefined references when linking in some circumstances. Reported by: Shawn Webb <shawn.webb@hardenedbsd.org> MFC r319957 (by emaste): lld: Add armelf emulation mode Obtained from: LLD r305375 MFC r321369: Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to 5.0.0 (trunk r308421). Upstream has branched for the 5.0.0 release, which should be in about a month. Please report bugs and regressions, so we can get them into the release. Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11 support to build; see UPDATING for more information. MFC r321420: Add a few more object files to liblldb, which should solve errors when linking the lldb executable in some cases. In particular, when the -ffunction-sections -fdata-sections options are turned off, or ineffective. Reported by: Shawn Webb, Mark Millard MFC r321433: Cleanup stale Options.inc files from the previous libllvm build for clang 4.0.0. Otherwise, these can get included before the two newly generated ones (which are different) for clang 5.0.0. Reported by: Mark Millard MFC r321439 (by bdrewery): Move llvm Options.inc hack from r321433 for NO_CLEAN to lib/clang/libllvm. The files are only ever generated to .OBJDIR, not to WORLDTMP (as a sysroot) and are only ever included from a compilation. So using a beforebuild target here removes the file before the compilation tries to include it. MFC r321664: Pull in r308891 from upstream llvm trunk (by Benjamin Kramer): [CodeGenPrepare] Cut off FindAllMemoryUses if there are too many uses. This avoids excessive compile time. The case I'm looking at is Function.cpp from an old version of LLVM that still had the giant memcmp string matcher in it. Before r308322 this compiled in about 2 minutes, after it, clang takes infinite* time to compile it. With this patch we're at 5 min, which is still bad but this is a pathological case. The cut off at 20 uses was chosen by looking at other cut-offs in LLVM for user scanning. It's probably too high, but does the job and is very unlikely to regress anything. Fixes PR33900. * I'm impatient and aborted after 15 minutes, on the bug report it was killed after 2h. Pull in r308986 from upstream llvm trunk (by Simon Pilgrim): [X86][CGP] Reduce memcmp() expansion to 2 load pairs (PR33914) D35067/rL308322 attempted to support up to 4 load pairs for memcmp inlining which resulted in regressions for some optimized libc memcmp implementations (PR33914). Until we can match these more optimal cases, this patch reduces the memcmp expansion to a maximum of 2 load pairs (which matches what we do for -Os). This patch should be considered for the 5.0.0 release branch as well Differential Revision: https://reviews.llvm.org/D35830 These fix a hang (or extremely long compile time) when building older LLVM ports. Reported by: antoine PR: 219139 MFC r321719: Pull in r309503 from upstream clang trunk (by Richard Smith): PR33902: Invalidate line number cache when adding more text to existing buffer. This led to crashes as the line number cache would report a bogus line number for a line of code, and we'd try to find a nonexistent column within the line when printing diagnostics. This fixes an assertion when building the graphics/champlain port. Reported by: antoine, kwm PR: 219139 MFC r321723: Upgrade our copies of clang, llvm, lld and lldb to r309439 from the upstream release_50 branch. This is just after upstream's 5.0.0-rc1. MFC r322320: Upgrade our copies of clang, llvm and libc++ to r310316 from the upstream release_50 branch. MFC r322326 (by emaste): lldb: Make i386-*-freebsd expression work on JIT path * Enable i386 ABI creation for freebsd * Added an extra argument in ABISysV_i386::PrepareTrivialCall for mmap syscall * Unlike linux, the last argument of mmap is actually 64-bit(off_t). This requires us to push an additional word for the higher order bits. * Prior to this change, ktrace dump will show mmap failures due to invalid argument coming from the 6th mmap argument. Submitted by: Karnajit Wangkhem Differential Revision: https://reviews.llvm.org/D34776 MFC r322360 (by emaste): lldb: Report inferior signals as signals, not exceptions, on FreeBSD This is the FreeBSD equivalent of LLVM r238549. This serves 2 purposes: * LLDB should handle inferior process signals SIGSEGV/SIGILL/SIGBUS/ SIGFPE the way it is suppose to be handled. Prior to this fix these signals will neither create a coredump, nor exit from the debugger or work for signal handling scenario. * eInvalidCrashReason need not report "unknown crash reason" if we have a valid si_signo llvm.org/pr23699 Patch by Karnajit Wangkhem Differential Revision: https://reviews.llvm.org/D35223 Submitted by: Karnajit Wangkhem Obtained from: LLVM r310591 MFC r322474 (by emaste): lld: Add `-z muldefs` option. Obtained from: LLVM r310757 MFC r322740: Upgrade our copies of clang, llvm, lld and libc++ to r311219 from the upstream release_50 branch. MFC r322855: Upgrade our copies of clang, llvm, lldb and compiler-rt to r311606 from the upstream release_50 branch. As of this version, lib/msun's trig test should also work correctly again (see bug 220989 for more information). PR: 220989 MFC r323112: Upgrade our copies of clang, llvm, lldb and compiler-rt to r312293 from the upstream release_50 branch. This corresponds to 5.0.0 rc4. As of this version, the cad/stepcode port should now compile in a more reasonable time on i386 (see bug 221836 for more information). PR: 221836 MFC r323245: Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to 5.0.0 release (upstream r312559). Release notes for llvm, clang and lld will be available here soon: <http://releases.llvm.org/5.0.0/docs/ReleaseNotes.html> <http://releases.llvm.org/5.0.0/tools/clang/docs/ReleaseNotes.html> <http://releases.llvm.org/5.0.0/tools/lld/docs/ReleaseNotes.html> Relnotes: yes (cherry picked from commit 12cd91cf4c6b96a24427c0de5374916f2808d263)
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Plugins/Process')
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp76
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.h5
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.cpp30
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.h12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp182
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.h109
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.h12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp85
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp16
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.h23
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp338
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h78
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp99
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h20
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h3
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/CMakeLists.txt21
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp939
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h144
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp112
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h74
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp940
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h96
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp218
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h81
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/CrashReason.cpp6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp193
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h78
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp33
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp43
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h41
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NetBSDSignals.cpp34
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.cpp97
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.cpp35
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp67
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.h62
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp3
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.cpp86
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.cpp97
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.h7
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextNetBSD_x86_64.cpp285
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp80
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h26
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp107
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h31
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp112
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h15
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp10
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h3
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h1
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm.cpp (renamed from contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.cpp)38
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm.h (renamed from contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.h)12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp12
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp130
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h16
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp22
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp143
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h53
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp83
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h14
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp456
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h76
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp28
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h13
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp94
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h11
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp1131
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h49
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp50
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h8
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp11
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp365
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h104
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp221
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h19
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp18
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/CMakeLists.txt11
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.h4
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp24
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.h6
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp50
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.h16
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp2
-rw-r--r--contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ThreadMinidump.cpp4
136 files changed, 6110 insertions, 2687 deletions
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
index 63b1ae6..c6daf6c 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
@@ -30,11 +30,12 @@
// LLDB includes
#include "lldb/lldb-enumerations.h"
-#include "lldb/Core/Error.h"
-#include "lldb/Core/Log.h"
-#include "lldb/Core/StreamString.h"
+#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Target/ProcessLaunchInfo.h"
-#include "lldb/Utility/PseudoTerminal.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/Errno.h"
#include "CFBundle.h"
#include "CFString.h"
@@ -131,10 +132,10 @@ static bool ResolveExecutablePath(const char *path, char *resolved_path,
// TODO check if we have a general purpose fork and exec. We may be
// able to get rid of this entirely.
-static Error ForkChildForPTraceDebugging(const char *path, char const *argv[],
- char const *envp[], ::pid_t *pid,
- int *pty_fd) {
- Error error;
+static Status ForkChildForPTraceDebugging(const char *path, char const *argv[],
+ char const *envp[], ::pid_t *pid,
+ int *pty_fd) {
+ Status error;
if (!path || !argv || !envp || !pid || !pty_fd) {
error.SetErrorString("invalid arguments");
return error;
@@ -149,7 +150,7 @@ static Error ForkChildForPTraceDebugging(const char *path, char const *argv[],
*pid = static_cast<::pid_t>(pty.Fork(fork_error, sizeof(fork_error)));
if (*pid < 0) {
//--------------------------------------------------------------
- // Error during fork.
+ // Status during fork.
//--------------------------------------------------------------
*pid = static_cast<::pid_t>(LLDB_INVALID_PROCESS_ID);
error.SetErrorStringWithFormat("%s(): fork failed: %s", __FUNCTION__,
@@ -205,10 +206,10 @@ static Error ForkChildForPTraceDebugging(const char *path, char const *argv[],
return error;
}
-static Error
+static Status
CreatePosixSpawnFileAction(const FileAction &action,
posix_spawn_file_actions_t *file_actions) {
- Error error;
+ Status error;
// Log it.
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
@@ -270,11 +271,11 @@ CreatePosixSpawnFileAction(const FileAction &action,
return error;
}
-static Error PosixSpawnChildForPTraceDebugging(const char *path,
- ProcessLaunchInfo &launch_info,
- ::pid_t *pid,
- cpu_type_t *actual_cpu_type) {
- Error error;
+static Status PosixSpawnChildForPTraceDebugging(const char *path,
+ ProcessLaunchInfo &launch_info,
+ ::pid_t *pid,
+ cpu_type_t *actual_cpu_type) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
if (!pid) {
@@ -319,13 +320,12 @@ static Error PosixSpawnChildForPTraceDebugging(const char *path,
::posix_spawnattr_setsigdefault(&attr, &all_signals);
if ((error_code = ::posix_spawnattr_setflags(&attr, flags)) != 0) {
- if (log)
- log->Printf("::posix_spawnattr_setflags(&attr, "
- "POSIX_SPAWN_START_SUSPENDED%s) failed: %s",
- flags & _POSIX_SPAWN_DISABLE_ASLR
- ? " | _POSIX_SPAWN_DISABLE_ASLR"
- : "",
- strerror(error_code));
+ LLDB_LOG(log,
+ "::posix_spawnattr_setflags(&attr, "
+ "POSIX_SPAWN_START_SUSPENDED{0}) failed: {1}",
+ flags & _POSIX_SPAWN_DISABLE_ASLR ? " | _POSIX_SPAWN_DISABLE_ASLR"
+ : "",
+ llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -341,10 +341,10 @@ static Error PosixSpawnChildForPTraceDebugging(const char *path,
error_code =
::posix_spawnattr_setbinpref_np(&attr, 1, &desired_cpu_type, &ocount);
if (error_code != 0) {
- if (log)
- log->Printf("::posix_spawnattr_setbinpref_np(&attr, 1, "
- "cpu_type = 0x%8.8x, count => %llu): %s",
- desired_cpu_type, (uint64_t)ocount, strerror(error_code));
+ LLDB_LOG(log,
+ "::posix_spawnattr_setbinpref_np(&attr, 1, "
+ "cpu_type = {0:x8}, count => {1}): {2}",
+ desired_cpu_type, ocount, llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -361,10 +361,8 @@ static Error PosixSpawnChildForPTraceDebugging(const char *path,
posix_spawn_file_actions_t file_actions;
if ((error_code = ::posix_spawn_file_actions_init(&file_actions)) != 0) {
- if (log)
- log->Printf("::posix_spawn_file_actions_init(&file_actions) "
- "failed: %s",
- strerror(error_code));
+ LLDB_LOG(log, "::posix_spawn_file_actions_init(&file_actions) failed: {0}",
+ llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -409,11 +407,11 @@ static Error PosixSpawnChildForPTraceDebugging(const char *path,
error_code = ::posix_spawnp(pid, path, &file_actions, &attr,
(char *const *)argv, (char *const *)envp);
if (error_code != 0) {
- if (log)
- log->Printf("::posix_spawnp(pid => %p, path = '%s', file_actions "
- "= %p, attr = %p, argv = %p, envp = %p) failed: %s",
- pid, path, &file_actions, &attr, argv, envp,
- strerror(error_code));
+ LLDB_LOG(log,
+ "::posix_spawnp(pid => {0}, path = '{1}', file_actions "
+ "= {2}, attr = {3}, argv = {4}, envp = {5}) failed: {6}",
+ pid, path, &file_actions, &attr, argv, envp,
+ llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -436,9 +434,9 @@ static Error PosixSpawnChildForPTraceDebugging(const char *path,
return error;
}
-Error LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
- LaunchFlavor *launch_flavor) {
- Error error;
+Status LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
+ LaunchFlavor *launch_flavor) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
if (!launch_flavor) {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.h
index d1af4d0..a0e8ce5 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/DarwinProcessLauncher.h
@@ -39,8 +39,9 @@ namespace darwin_process_launcher {
/// @param[out] launch_flavor
/// Contains the launch flavor used when launching the process.
// =============================================================================
-Error LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
- lldb_private::process_darwin::LaunchFlavor *launch_flavor);
+Status
+LaunchInferior(ProcessLaunchInfo &launch_info, int *pty_master_fd,
+ lldb_private::process_darwin::LaunchFlavor *launch_flavor);
} // darwin_process_launcher
} // lldb_private
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.cpp
index 8170644..7d956df 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.cpp
@@ -22,11 +22,11 @@
#include <mutex>
// LLDB includes
-#include "lldb/Core/Error.h"
-#include "lldb/Core/Log.h"
-#include "lldb/Core/Stream.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/Stream.h"
using namespace lldb;
using namespace lldb_private;
@@ -211,11 +211,11 @@ bool MachException::Data::GetStopInfo(struct ThreadStopInfo *stop_info,
return true;
}
-Error MachException::Message::Receive(mach_port_t port,
- mach_msg_option_t options,
- mach_msg_timeout_t timeout,
- mach_port_t notify_port) {
- Error error;
+Status MachException::Message::Receive(mach_port_t port,
+ mach_msg_option_t options,
+ mach_msg_timeout_t timeout,
+ mach_port_t notify_port) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
mach_msg_timeout_t mach_msg_timeout =
@@ -312,10 +312,10 @@ bool MachException::Message::CatchExceptionRaise(task_t task) {
return success;
}
-Error MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task,
- int signal) {
+Status MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task,
+ int signal) {
// Reply to the exception...
- Error error;
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
@@ -412,8 +412,8 @@ Error MachException::Message::Reply(::pid_t inferior_pid, task_t inferior_task,
#define LLDB_EXC_MASK (EXC_MASK_ALL & ~EXC_MASK_RESOURCE)
-Error MachException::PortInfo::Save(task_t task) {
- Error error;
+Status MachException::PortInfo::Save(task_t task) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
if (log)
@@ -471,8 +471,8 @@ Error MachException::PortInfo::Save(task_t task) {
return error;
}
-Error MachException::PortInfo::Restore(task_t task) {
- Error error;
+Status MachException::PortInfo::Restore(task_t task) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.h
index ac8cd70..2da6a36 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/MachException.h
@@ -40,9 +40,9 @@ public:
thread_state_flavor_t flavors[EXC_TYPES_COUNT];
mach_msg_type_number_t count;
- Error Save(task_t task);
+ Status Save(task_t task);
- Error Restore(task_t task);
+ Status Restore(task_t task);
};
struct Data {
@@ -96,11 +96,11 @@ public:
bool CatchExceptionRaise(task_t task);
- Error Reply(::pid_t inferior_pid, task_t inferior_task, int signal);
+ Status Reply(::pid_t inferior_pid, task_t inferior_task, int signal);
- Error Receive(mach_port_t receive_port, mach_msg_option_t options,
- mach_msg_timeout_t timeout,
- mach_port_t notify_port = MACH_PORT_NULL);
+ Status Receive(mach_port_t receive_port, mach_msg_option_t options,
+ mach_msg_timeout_t timeout,
+ mach_port_t notify_port = MACH_PORT_NULL);
void Dump(Stream &stream) const;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
index e56375e..518f0d2 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
@@ -19,11 +19,11 @@
// C++ includes
// LLDB includes
-#include "lldb/Core/Log.h"
#include "lldb/Core/State.h"
-#include "lldb/Core/StreamString.h"
+#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Target/ProcessLaunchInfo.h"
-#include "lldb/Utility/PseudoTerminal.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/StreamString.h"
#include "CFBundle.h"
#include "CFString.h"
@@ -31,6 +31,8 @@
#include "MachException.h"
+#include "llvm/Support/FileSystem.h"
+
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_darwin;
@@ -51,19 +53,19 @@ struct hack_task_dyld_info {
// Public Static Methods
// -----------------------------------------------------------------------------
-Error NativeProcessProtocol::Launch(
+Status NativeProcessProtocol::Launch(
ProcessLaunchInfo &launch_info,
NativeProcessProtocol::NativeDelegate &native_delegate, MainLoop &mainloop,
NativeProcessProtocolSP &native_process_sp) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
- Error error;
+ Status error;
// Verify the working directory is valid if one was specified.
FileSpec working_dir(launch_info.GetWorkingDirectory());
if (working_dir &&
(!working_dir.ResolvePath() ||
- working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) {
+ !llvm::sys::fs::is_directory(working_dir.GetPath())) {
error.SetErrorStringWithFormat("No such file or directory: %s",
working_dir.GetCString());
return error;
@@ -118,7 +120,7 @@ Error NativeProcessProtocol::Launch(
return error;
}
-Error NativeProcessProtocol::Attach(
+Status NativeProcessProtocol::Attach(
lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
MainLoop &mainloop, NativeProcessProtocolSP &native_process_sp) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
@@ -128,7 +130,7 @@ Error NativeProcessProtocol::Attach(
// Retrieve the architecture for the running process.
ArchSpec process_arch;
- Error error = ResolveProcessArchitecture(pid, process_arch);
+ Status error = ResolveProcessArchitecture(pid, process_arch);
if (!error.Success())
return error;
@@ -172,9 +174,9 @@ NativeProcessDarwin::~NativeProcessDarwin() {}
// Instance methods
// -----------------------------------------------------------------------------
-Error NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
- MainLoop &main_loop) {
- Error error;
+Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
+ MainLoop &main_loop) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
#if 0
@@ -259,7 +261,7 @@ Error NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor,
return error;
}
-Error NativeProcessDarwin::SaveExceptionPortInfo() {
+Status NativeProcessDarwin::SaveExceptionPortInfo() {
return m_exc_port_info.Save(m_task);
}
@@ -346,7 +348,7 @@ void *NativeProcessDarwin::DoExceptionThread() {
// polling is expensive. On devices, we need to minimize overhead caused
// by the process monitor.
uint32_t num_exceptions_received = 0;
- Error error;
+ Status error;
task_t task = m_task;
mach_msg_timeout_t periodic_timeout = 0;
@@ -548,8 +550,8 @@ void *NativeProcessDarwin::DoExceptionThread() {
return nullptr;
}
-Error NativeProcessDarwin::StartExceptionThread() {
- Error error;
+Status NativeProcessDarwin::StartExceptionThread() {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
if (log)
log->Printf("NativeProcessDarwin::%s() called", __FUNCTION__);
@@ -638,7 +640,7 @@ Error NativeProcessDarwin::StartExceptionThread() {
}
lldb::addr_t
-NativeProcessDarwin::GetDYLDAllImageInfosAddress(Error &error) const {
+NativeProcessDarwin::GetDYLDAllImageInfosAddress(Status &error) const {
error.Clear();
struct hack_task_dyld_info dyld_info;
@@ -692,7 +694,7 @@ uint32_t NativeProcessDarwin::GetCPUType() const {
task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
// We have a complete bundle of exceptions for our child process.
- Error error;
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
@@ -735,7 +737,7 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() {
const addr_t info_array_count_addr = aii_addr + 4;
uint32_t info_array_count = 0;
size_t bytes_read = 0;
- Error read_error;
+ Status read_error;
read_error = ReadMemory(info_array_count_addr, // source addr
&info_array_count, // dest addr
4, // byte count
@@ -883,8 +885,8 @@ void NativeProcessDarwin::StartSTDIOThread() {
// TODO implement
}
-Error NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) {
- Error error;
+Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
// Strategy: create a thread that sits on waitpid(), waiting for the
@@ -971,7 +973,7 @@ void *NativeProcessDarwin::DoWaitpidThread() {
// Ensure we don't get CPU starved.
MaybeRaiseThreadPriority();
- Error error;
+ Status error;
int status = -1;
while (1) {
@@ -1036,9 +1038,9 @@ void *NativeProcessDarwin::DoWaitpidThread() {
return nullptr;
}
-Error NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid,
- int status) {
- Error error;
+Status NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid,
+ int status) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
size_t bytes_written = 0;
@@ -1067,8 +1069,8 @@ Error NativeProcessDarwin::SendInferiorExitStatusToMainLoop(::pid_t pid,
return error;
}
-Error NativeProcessDarwin::HandleWaitpidResult() {
- Error error;
+Status NativeProcessDarwin::HandleWaitpidResult() {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
// Read the pid.
@@ -1083,8 +1085,7 @@ Error NativeProcessDarwin::HandleWaitpidResult() {
"waitpid exiting pid from the pipe. Will notify "
"as if parent process died with exit status -1.",
__FUNCTION__);
- SetExitStatus(eExitTypeInvalid, -1, "failed to receive waitpid result",
- notify_status);
+ SetExitStatus(WaitStatus(WaitStatus::Exit, -1), notify_status);
return error;
}
@@ -1097,8 +1098,7 @@ Error NativeProcessDarwin::HandleWaitpidResult() {
"waitpid exit status from the pipe. Will notify "
"as if parent process died with exit status -1.",
__FUNCTION__);
- SetExitStatus(eExitTypeInvalid, -1, "failed to receive waitpid result",
- notify_status);
+ SetExitStatus(WaitStatus(WaitStatus::Exit, -1), notify_status);
return error;
}
@@ -1109,22 +1109,11 @@ Error NativeProcessDarwin::HandleWaitpidResult() {
__FUNCTION__, pid,
(pid == m_pid) ? "the inferior" : "not the inferior", status);
- ExitType exit_type = eExitTypeInvalid;
- int exit_status = -1;
-
- if (WIFEXITED(status)) {
- exit_type = eExitTypeExit;
- exit_status = WEXITSTATUS(status);
- } else if (WIFSIGNALED(status)) {
- exit_type = eExitTypeSignal;
- exit_status = WTERMSIG(status);
- }
-
- SetExitStatus(exit_type, exit_status, nullptr, notify_status);
+ SetExitStatus(WaitStatus::Decode(status), notify_status);
return error;
}
-task_t NativeProcessDarwin::TaskPortForProcessID(Error &error,
+task_t NativeProcessDarwin::TaskPortForProcessID(Status &error,
bool force) const {
if ((m_task == TASK_NULL) || force) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
@@ -1176,12 +1165,12 @@ task_t NativeProcessDarwin::TaskPortForProcessID(Error &error,
}
void NativeProcessDarwin::AttachToInferior(MainLoop &mainloop, lldb::pid_t pid,
- Error &error) {
+ Status &error) {
error.SetErrorString("TODO: implement");
}
-Error NativeProcessDarwin::PrivateResume() {
- Error error;
+Status NativeProcessDarwin::PrivateResume() {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
std::lock_guard<std::recursive_mutex> locker(m_exception_messages_mutex);
@@ -1223,8 +1212,8 @@ Error NativeProcessDarwin::PrivateResume() {
return error;
}
-Error NativeProcessDarwin::ReplyToAllExceptions() {
- Error error;
+Status NativeProcessDarwin::ReplyToAllExceptions() {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE));
TaskPortForProcessID(error);
@@ -1280,8 +1269,8 @@ Error NativeProcessDarwin::ReplyToAllExceptions() {
return error;
}
-Error NativeProcessDarwin::ResumeTask() {
- Error error;
+Status NativeProcessDarwin::ResumeTask() {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
TaskPortForProcessID(error);
@@ -1362,9 +1351,10 @@ bool NativeProcessDarwin::IsExceptionPortValid() const {
return MACH_PORT_VALID(m_exception_port);
}
-Error NativeProcessDarwin::GetTaskBasicInfo(
- task_t task, struct task_basic_info *info) const {
- Error error;
+Status
+NativeProcessDarwin::GetTaskBasicInfo(task_t task,
+ struct task_basic_info *info) const {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
// Validate args.
@@ -1410,8 +1400,8 @@ Error NativeProcessDarwin::GetTaskBasicInfo(
return error;
}
-Error NativeProcessDarwin::SuspendTask() {
- Error error;
+Status NativeProcessDarwin::SuspendTask() {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
if (m_task == TASK_NULL) {
@@ -1430,8 +1420,8 @@ Error NativeProcessDarwin::SuspendTask() {
return error;
}
-Error NativeProcessDarwin::Resume(const ResumeActionList &resume_actions) {
- Error error;
+Status NativeProcessDarwin::Resume(const ResumeActionList &resume_actions) {
+ Status error;
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
if (log)
@@ -1459,74 +1449,74 @@ Error NativeProcessDarwin::Resume(const ResumeActionList &resume_actions) {
return error;
}
-Error NativeProcessDarwin::Halt() {
- Error error;
+Status NativeProcessDarwin::Halt() {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::Detach() {
- Error error;
+Status NativeProcessDarwin::Detach() {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::Signal(int signo) {
- Error error;
+Status NativeProcessDarwin::Signal(int signo) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::Interrupt() {
- Error error;
+Status NativeProcessDarwin::Interrupt() {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::Kill() {
- Error error;
+Status NativeProcessDarwin::Kill() {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::GetMemoryRegionInfo(lldb::addr_t load_addr,
- MemoryRegionInfo &range_info) {
- Error error;
+Status NativeProcessDarwin::GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &range_info) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
- size_t &bytes_read) {
- Error error;
+Status NativeProcessDarwin::ReadMemory(lldb::addr_t addr, void *buf,
+ size_t size, size_t &bytes_read) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf,
- size_t size,
- size_t &bytes_read) {
- Error error;
+Status NativeProcessDarwin::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf,
+ size_t size,
+ size_t &bytes_read) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::WriteMemory(lldb::addr_t addr, const void *buf,
- size_t size, size_t &bytes_written) {
- Error error;
+Status NativeProcessDarwin::WriteMemory(lldb::addr_t addr, const void *buf,
+ size_t size, size_t &bytes_written) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::AllocateMemory(size_t size, uint32_t permissions,
- lldb::addr_t &addr) {
- Error error;
+Status NativeProcessDarwin::AllocateMemory(size_t size, uint32_t permissions,
+ lldb::addr_t &addr) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::DeallocateMemory(lldb::addr_t addr) {
- Error error;
+Status NativeProcessDarwin::DeallocateMemory(lldb::addr_t addr) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
@@ -1541,25 +1531,25 @@ bool NativeProcessDarwin::GetArchitecture(ArchSpec &arch) const {
return false;
}
-Error NativeProcessDarwin::SetBreakpoint(lldb::addr_t addr, uint32_t size,
- bool hardware) {
- Error error;
+Status NativeProcessDarwin::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
void NativeProcessDarwin::DoStopIDBumped(uint32_t newBumpId) {}
-Error NativeProcessDarwin::GetLoadedModuleFileSpec(const char *module_path,
- FileSpec &file_spec) {
- Error error;
+Status NativeProcessDarwin::GetLoadedModuleFileSpec(const char *module_path,
+ FileSpec &file_spec) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
-Error NativeProcessDarwin::GetFileLoadAddress(const llvm::StringRef &file_name,
- lldb::addr_t &load_addr) {
- Error error;
+Status NativeProcessDarwin::GetFileLoadAddress(const llvm::StringRef &file_name,
+ lldb::addr_t &load_addr) {
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
@@ -1567,10 +1557,10 @@ Error NativeProcessDarwin::GetFileLoadAddress(const llvm::StringRef &file_name,
// -----------------------------------------------------------------
// NativeProcessProtocol protected interface
// -----------------------------------------------------------------
-Error NativeProcessDarwin::GetSoftwareBreakpointTrapOpcode(
+Status NativeProcessDarwin::GetSoftwareBreakpointTrapOpcode(
size_t trap_opcode_size_hint, size_t &actual_opcode_size,
const uint8_t *&trap_opcode_bytes) {
- Error error;
+ Status error;
error.SetErrorString("TODO: implement");
return error;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.h
index 69c1b8d..2214bbc 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeProcessDarwin.h
@@ -24,11 +24,11 @@
// Other libraries and framework includes
#include "lldb/Core/ArchSpec.h"
#include "lldb/Host/Debug.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/Pipe.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/FileSpec.h"
#include "lldb/lldb-types.h"
#include "LaunchFlavor.h"
@@ -37,7 +37,7 @@
#include "NativeThreadListDarwin.h"
namespace lldb_private {
-class Error;
+class Status;
class Scalar;
namespace process_darwin {
@@ -50,11 +50,11 @@ namespace process_darwin {
///
/// Changes in the inferior process state are broadcasted.
class NativeProcessDarwin : public NativeProcessProtocol {
- friend Error NativeProcessProtocol::Launch(
+ friend Status NativeProcessProtocol::Launch(
ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
- friend Error NativeProcessProtocol::Attach(
+ friend Status NativeProcessProtocol::Attach(
lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
@@ -64,34 +64,34 @@ public:
// -----------------------------------------------------------------
// NativeProcessProtocol Interface
// -----------------------------------------------------------------
- Error Resume(const ResumeActionList &resume_actions) override;
+ Status Resume(const ResumeActionList &resume_actions) override;
- Error Halt() override;
+ Status Halt() override;
- Error Detach() override;
+ Status Detach() override;
- Error Signal(int signo) override;
+ Status Signal(int signo) override;
- Error Interrupt() override;
+ Status Interrupt() override;
- Error Kill() override;
+ Status Kill() override;
- Error GetMemoryRegionInfo(lldb::addr_t load_addr,
- MemoryRegionInfo &range_info) override;
+ Status GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &range_info) override;
- Error ReadMemory(lldb::addr_t addr, void *buf, size_t size,
- size_t &bytes_read) override;
+ Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+ size_t &bytes_read) override;
- Error ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
- size_t &bytes_read) override;
+ Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
+ size_t &bytes_read) override;
- Error WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
- size_t &bytes_written) override;
+ Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
+ size_t &bytes_written) override;
- Error AllocateMemory(size_t size, uint32_t permissions,
- lldb::addr_t &addr) override;
+ Status AllocateMemory(size_t size, uint32_t permissions,
+ lldb::addr_t &addr) override;
- Error DeallocateMemory(lldb::addr_t addr) override;
+ Status DeallocateMemory(lldb::addr_t addr) override;
lldb::addr_t GetSharedLibraryInfoAddress() override;
@@ -99,15 +99,16 @@ public:
bool GetArchitecture(ArchSpec &arch) const override;
- Error SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override;
+ Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) override;
void DoStopIDBumped(uint32_t newBumpId) override;
- Error GetLoadedModuleFileSpec(const char *module_path,
- FileSpec &file_spec) override;
+ Status GetLoadedModuleFileSpec(const char *module_path,
+ FileSpec &file_spec) override;
- Error GetFileLoadAddress(const llvm::StringRef &file_name,
- lldb::addr_t &load_addr) override;
+ Status GetFileLoadAddress(const llvm::StringRef &file_name,
+ lldb::addr_t &load_addr) override;
NativeThreadDarwinSP GetThreadByID(lldb::tid_t id);
@@ -116,9 +117,9 @@ public:
// -----------------------------------------------------------------
// Interface used by NativeRegisterContext-derived classes.
// -----------------------------------------------------------------
- static Error PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
- void *data = nullptr, size_t data_size = 0,
- long *result = nullptr);
+ static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
+ void *data = nullptr, size_t data_size = 0,
+ long *result = nullptr);
bool SupportHardwareSingleStepping() const;
@@ -126,7 +127,7 @@ protected:
// -----------------------------------------------------------------
// NativeProcessProtocol protected interface
// -----------------------------------------------------------------
- Error
+ Status
GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
size_t &actual_opcode_size,
const uint8_t *&trap_opcode_bytes) override;
@@ -236,19 +237,19 @@ private:
/// operations. Failure here will force termination of the
/// launched process and debugging session.
// -----------------------------------------------------------------
- Error FinalizeLaunch(LaunchFlavor launch_flavor, MainLoop &main_loop);
+ Status FinalizeLaunch(LaunchFlavor launch_flavor, MainLoop &main_loop);
- Error SaveExceptionPortInfo();
+ Status SaveExceptionPortInfo();
void ExceptionMessageReceived(const MachException::Message &message);
void MaybeRaiseThreadPriority();
- Error StartExceptionThread();
+ Status StartExceptionThread();
- Error SendInferiorExitStatusToMainLoop(::pid_t pid, int status);
+ Status SendInferiorExitStatusToMainLoop(::pid_t pid, int status);
- Error HandleWaitpidResult();
+ Status HandleWaitpidResult();
bool ProcessUsingSpringBoard() const;
@@ -258,7 +259,7 @@ private:
void *DoExceptionThread();
- lldb::addr_t GetDYLDAllImageInfosAddress(Error &error) const;
+ lldb::addr_t GetDYLDAllImageInfosAddress(Status &error) const;
static uint32_t GetCPUTypeForLocalProcess(::pid_t pid);
@@ -268,25 +269,25 @@ private:
void StartSTDIOThread();
- Error StartWaitpidThread(MainLoop &main_loop);
+ Status StartWaitpidThread(MainLoop &main_loop);
static void *WaitpidThread(void *arg);
void *DoWaitpidThread();
- task_t TaskPortForProcessID(Error &error, bool force = false) const;
+ task_t TaskPortForProcessID(Status &error, bool force = false) const;
/// Attaches to an existing process. Forms the
/// implementation of Process::DoAttach.
- void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Error &error);
+ void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Status &error);
- ::pid_t Attach(lldb::pid_t pid, Error &error);
+ ::pid_t Attach(lldb::pid_t pid, Status &error);
- Error PrivateResume();
+ Status PrivateResume();
- Error ReplyToAllExceptions();
+ Status ReplyToAllExceptions();
- Error ResumeTask();
+ Status ResumeTask();
bool IsTaskValid() const;
@@ -296,11 +297,11 @@ private:
bool IsExceptionPortValid() const;
- Error GetTaskBasicInfo(task_t task, struct task_basic_info *info) const;
+ Status GetTaskBasicInfo(task_t task, struct task_basic_info *info) const;
- Error SuspendTask();
+ Status SuspendTask();
- static Error SetDefaultPtraceOpts(const lldb::pid_t);
+ static Status SetDefaultPtraceOpts(const lldb::pid_t);
static void *MonitorThread(void *baton);
@@ -319,7 +320,7 @@ private:
void MonitorSignal(const siginfo_t &info, NativeThreadDarwin &thread,
bool exited);
- Error SetupSoftwareSingleStepping(NativeThreadDarwin &thread);
+ Status SetupSoftwareSingleStepping(NativeThreadDarwin &thread);
#if 0
static ::ProcessMessage::CrashReason
@@ -341,22 +342,22 @@ private:
NativeThreadDarwinSP AddThread(lldb::tid_t thread_id);
- Error GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
+ Status GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
- Error FixupBreakpointPCAsNeeded(NativeThreadDarwin &thread);
+ Status FixupBreakpointPCAsNeeded(NativeThreadDarwin &thread);
/// Writes a siginfo_t structure corresponding to the given thread
/// ID to the memory region pointed to by @p siginfo.
- Error GetSignalInfo(lldb::tid_t tid, void *siginfo);
+ Status GetSignalInfo(lldb::tid_t tid, void *siginfo);
/// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG)
/// corresponding to the given thread ID to the memory pointed to
/// by @p message.
- Error GetEventMessage(lldb::tid_t tid, unsigned long *message);
+ Status GetEventMessage(lldb::tid_t tid, unsigned long *message);
void NotifyThreadDeath(lldb::tid_t tid);
- Error Detach(lldb::tid_t tid);
+ Status Detach(lldb::tid_t tid);
// This method is requests a stop on all threads which are still
// running. It sets up a deferred delegate notification, which will
@@ -370,8 +371,8 @@ private:
// Resume the given thread, optionally passing it the given signal.
// The type of resume operation (continue, single-step) depends on
// the state parameter.
- Error ResumeThread(NativeThreadDarwin &thread, lldb::StateType state,
- int signo);
+ Status ResumeThread(NativeThreadDarwin &thread, lldb::StateType state,
+ int signo);
void ThreadWasCreated(NativeThreadDarwin &thread);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
index 5e7f9ae..07398ab 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.cpp
@@ -13,7 +13,7 @@
#include <libproc.h>
// LLDB includes
-#include "lldb/Core/Stream.h"
+#include "lldb/Utility/Stream.h"
#include "NativeProcessDarwin.h"
@@ -94,15 +94,15 @@ NativeRegisterContextSP NativeThreadDarwin::GetRegisterContext() {
return NativeRegisterContextSP();
}
-Error NativeThreadDarwin::SetWatchpoint(lldb::addr_t addr, size_t size,
- uint32_t watch_flags, bool hardware) {
- Error error;
+Status NativeThreadDarwin::SetWatchpoint(lldb::addr_t addr, size_t size,
+ uint32_t watch_flags, bool hardware) {
+ Status error;
error.SetErrorString("not yet implemented");
return error;
}
-Error NativeThreadDarwin::RemoveWatchpoint(lldb::addr_t addr) {
- Error error;
+Status NativeThreadDarwin::RemoveWatchpoint(lldb::addr_t addr) {
+ Status error;
error.SetErrorString("not yet implemented");
return error;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.h
index b8d9089..f66f8fe 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadDarwin.h
@@ -58,10 +58,10 @@ public:
NativeRegisterContextSP GetRegisterContext() override;
- Error SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
- bool hardware) override;
+ Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
+ bool hardware) override;
- Error RemoveWatchpoint(lldb::addr_t addr) override;
+ Status RemoveWatchpoint(lldb::addr_t addr) override;
// -----------------------------------------------------------------
// New methods that are fine for others to call.
@@ -75,11 +75,11 @@ private:
/// Resumes the thread. If @p signo is anything but
/// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
- Error Resume(uint32_t signo);
+ Status Resume(uint32_t signo);
/// Single steps the thread. If @p signo is anything but
/// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
- Error SingleStep(uint32_t signo);
+ Status SingleStep(uint32_t signo);
bool NotifyException(MachException::Data &exc);
@@ -117,7 +117,7 @@ private:
void SetExited();
- Error RequestStop();
+ Status RequestStop();
// -------------------------------------------------------------------------
/// Return the mach thread port number for this thread.
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
index aa9b041..7d44ade 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.cpp
@@ -20,9 +20,9 @@
#include <sys/sysctl.h>
// LLDB includes
-#include "lldb/Core/Error.h"
-#include "lldb/Core/Log.h"
-#include "lldb/Core/Stream.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/Stream.h"
#include "lldb/lldb-enumerations.h"
#include "NativeProcessDarwin.h"
@@ -343,7 +343,7 @@ uint32_t NativeThreadListDarwin::UpdateThreadList(NativeProcessDarwin &process,
mach_msg_type_number_t thread_list_count = 0;
task_t task = process.GetTask();
- Error error;
+ Status error;
auto mach_err = ::task_threads(task, &thread_list, &thread_list_count);
error.SetError(mach_err, eErrorTypeMachKernel);
if (error.Fail()) {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.h
index 2b194bc..7b59afb 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Darwin/NativeThreadListDarwin.h
@@ -123,7 +123,7 @@ protected:
typedef collection::iterator iterator;
typedef collection::const_iterator const_iterator;
- // Consider having this return an lldb_private::Error.
+ // Consider having this return an lldb_private::Status.
uint32_t UpdateThreadList(NativeProcessDarwin &process, bool update,
collection *num_threads = nullptr);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
index be92a0d..f50f18b 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp
@@ -9,6 +9,12 @@
// C Includes
#include <errno.h>
+#include <pthread.h>
+#include <pthread_np.h>
+#include <stdlib.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/user.h>
// C++ Includes
// Other libraries and framework includes
@@ -18,16 +24,16 @@
// Project includes
#include "FreeBSDThread.h"
#include "POSIXStopInfo.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
+#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
#include "Plugins/Process/Utility/UnwindLLDB.h"
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
-#include "ProcessPOSIXLog.h"
#include "RegisterContextPOSIXProcessMonitor_arm.h"
#include "RegisterContextPOSIXProcessMonitor_arm64.h"
#include "RegisterContextPOSIXProcessMonitor_mips64.h"
@@ -53,8 +59,7 @@ FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid)
: Thread(process, tid), m_frame_ap(), m_breakpoint(),
m_thread_name_valid(false), m_thread_name(), m_posix_thread(NULL) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
- if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
- log->Printf("FreeBSDThread::%s (tid = %" PRIi64 ")", __FUNCTION__, tid);
+ LLDB_LOGV(log, "tid = {0}", tid);
// Set the current watchpoints for this thread.
Target &target = GetProcess()->GetTarget();
@@ -114,9 +119,41 @@ void FreeBSDThread::SetName(const char *name) {
const char *FreeBSDThread::GetName() {
if (!m_thread_name_valid) {
- llvm::SmallString<32> thread_name;
- HostNativeThread::GetName(GetID(), thread_name);
- m_thread_name = thread_name.c_str();
+ m_thread_name.clear();
+ int pid = GetProcess()->GetID();
+
+ struct kinfo_proc *kp = nullptr, *nkp;
+ size_t len = 0;
+ int error;
+ int ctl[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD,
+ pid};
+
+ while (1) {
+ error = sysctl(ctl, 4, kp, &len, nullptr, 0);
+ if (kp == nullptr || (error != 0 && errno == ENOMEM)) {
+ // Add extra space in case threads are added before next call.
+ len += sizeof(*kp) + len / 10;
+ nkp = (struct kinfo_proc *)realloc(kp, len);
+ if (nkp == nullptr) {
+ free(kp);
+ return nullptr;
+ }
+ kp = nkp;
+ continue;
+ }
+ if (error != 0)
+ len = 0;
+ break;
+ }
+
+ for (size_t i = 0; i < len / sizeof(*kp); i++) {
+ if (kp[i].ki_tid == (lwpid_t)GetID()) {
+ m_thread_name.append(kp[i].ki_tdname,
+ kp[i].ki_tdname + strlen(kp[i].ki_tdname));
+ break;
+ }
+ }
+ free(kp);
m_thread_name_valid = true;
}
@@ -138,7 +175,7 @@ lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() {
reg_interface = new RegisterInfoPOSIX_arm64(target_arch);
break;
case llvm::Triple::arm:
- reg_interface = new RegisterContextFreeBSD_arm(target_arch);
+ reg_interface = new RegisterInfoPOSIX_arm(target_arch);
break;
case llvm::Triple::ppc:
#ifndef __powerpc64__
@@ -215,8 +252,7 @@ FreeBSDThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) {
uint32_t concrete_frame_idx = 0;
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
- if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
- log->Printf("FreeBSDThread::%s ()", __FUNCTION__);
+ LLDB_LOGV(log, "called");
if (frame)
concrete_frame_idx = frame->GetConcreteFrameIndex();
@@ -339,6 +375,7 @@ void FreeBSDThread::Notify(const ProcessMessage &message) {
LimboNotify(message);
break;
+ case ProcessMessage::eCrashMessage:
case ProcessMessage::eSignalMessage:
SignalNotify(message);
break;
@@ -359,10 +396,6 @@ void FreeBSDThread::Notify(const ProcessMessage &message) {
WatchNotify(message);
break;
- case ProcessMessage::eCrashMessage:
- CrashNotify(message);
- break;
-
case ProcessMessage::eExecMessage:
ExecNotify(message);
break;
@@ -541,7 +574,14 @@ void FreeBSDThread::LimboNotify(const ProcessMessage &message) {
void FreeBSDThread::SignalNotify(const ProcessMessage &message) {
int signo = message.GetSignal();
- SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
+ if (message.GetKind() == ProcessMessage::eCrashMessage) {
+ std::string stop_description = GetCrashReasonString(
+ message.GetCrashReason(), message.GetFaultAddress());
+ SetStopInfo(StopInfo::CreateStopReasonWithSignal(
+ *this, signo, stop_description.c_str()));
+ } else {
+ SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
+ }
}
void FreeBSDThread::SignalDeliveredNotify(const ProcessMessage &message) {
@@ -549,21 +589,6 @@ void FreeBSDThread::SignalDeliveredNotify(const ProcessMessage &message) {
SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
}
-void FreeBSDThread::CrashNotify(const ProcessMessage &message) {
- // FIXME: Update stop reason as per bugzilla 14598
- int signo = message.GetSignal();
-
- assert(message.GetKind() == ProcessMessage::eCrashMessage);
-
- Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
- if (log)
- log->Printf("FreeBSDThread::%s () signo = %i, reason = '%s'", __FUNCTION__,
- signo, message.PrintCrashReason());
-
- SetStopInfo(lldb::StopInfoSP(new POSIXCrashStopInfo(
- *this, signo, message.GetCrashReason(), message.GetFaultAddress())));
-}
-
unsigned FreeBSDThread::GetRegisterIndexFromOffset(unsigned offset) {
unsigned reg = LLDB_INVALID_REGNUM;
ArchSpec arch = HostInfo::GetArchitecture();
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp
index dfbd695..9c75c26 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.cpp
@@ -28,22 +28,6 @@ bool POSIXLimboStopInfo::ShouldStop(Event *event_ptr) { return false; }
bool POSIXLimboStopInfo::ShouldNotify(Event *event_ptr) { return false; }
//===----------------------------------------------------------------------===//
-// POSIXCrashStopInfo
-
-POSIXCrashStopInfo::POSIXCrashStopInfo(FreeBSDThread &thread, uint32_t status,
- CrashReason reason,
- lldb::addr_t fault_addr)
- : POSIXStopInfo(thread, status) {
- m_description = ::GetCrashReasonString(reason, fault_addr);
-}
-
-POSIXCrashStopInfo::~POSIXCrashStopInfo() {}
-
-lldb::StopReason POSIXCrashStopInfo::GetStopReason() const {
- return lldb::eStopReasonException;
-}
-
-//===----------------------------------------------------------------------===//
// POSIXNewThreadStopInfo
POSIXNewThreadStopInfo::~POSIXNewThreadStopInfo() {}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.h b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
index 1ee16dd..9686185 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/POSIXStopInfo.h
@@ -10,15 +10,9 @@
#ifndef liblldb_POSIXStopInfo_H_
#define liblldb_POSIXStopInfo_H_
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
-#include "lldb/Target/StopInfo.h"
-
-#include "CrashReason.h"
#include "FreeBSDThread.h"
-
+#include "Plugins/Process/POSIX/CrashReason.h"
+#include "lldb/Target/StopInfo.h"
#include <string>
//===----------------------------------------------------------------------===//
@@ -51,19 +45,6 @@ public:
};
//===----------------------------------------------------------------------===//
-/// @class POSIXCrashStopInfo
-/// @brief Represents the stop state of process that is ready to crash.
-///
-class POSIXCrashStopInfo : public POSIXStopInfo {
-public:
- POSIXCrashStopInfo(FreeBSDThread &thread, uint32_t status, CrashReason reason,
- lldb::addr_t fault_addr);
- ~POSIXCrashStopInfo();
-
- lldb::StopReason GetStopReason() const;
-};
-
-//===----------------------------------------------------------------------===//
/// @class POSIXNewThreadStopInfo
/// @brief Represents the stop state of process when a new thread is spawned.
///
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
index 82e45a5..3046150 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
@@ -10,12 +10,21 @@
// C Includes
#include <errno.h>
+#include <pthread.h>
+#include <pthread_np.h>
+#include <stdlib.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <machine/elf.h>
// C++ Includes
#include <mutex>
+#include <unordered_map>
// Other libraries and framework includes
#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/State.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -23,11 +32,11 @@
#include "lldb/Target/Target.h"
#include "FreeBSDThread.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/FreeBSDSignals.h"
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
-#include "ProcessPOSIXLog.h"
// Other libraries and framework includes
#include "lldb/Breakpoint/BreakpointLocation.h"
@@ -36,15 +45,19 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/State.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/FileSpec.h"
#include "lldb/Host/posix/Fcntl.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -70,12 +83,11 @@ ProcessFreeBSD::CreateInstance(lldb::TargetSP target_sp,
}
void ProcessFreeBSD::Initialize() {
- static std::once_flag g_once_flag;
+ static llvm::once_flag g_once_flag;
- std::call_once(g_once_flag, []() {
+ llvm::call_once(g_once_flag, []() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(), CreateInstance);
- ProcessPOSIXLog::Initialize(GetPluginNameStatic());
});
}
@@ -99,8 +111,8 @@ uint32_t ProcessFreeBSD::GetPluginVersion() { return 1; }
void ProcessFreeBSD::Terminate() {}
-Error ProcessFreeBSD::DoDetach(bool keep_stopped) {
- Error error;
+Status ProcessFreeBSD::DoDetach(bool keep_stopped) {
+ Status error;
if (keep_stopped) {
error.SetErrorString("Detaching with keep_stopped true is not currently "
"supported on FreeBSD.");
@@ -115,13 +127,14 @@ Error ProcessFreeBSD::DoDetach(bool keep_stopped) {
return error;
}
-Error ProcessFreeBSD::DoResume() {
+Status ProcessFreeBSD::DoResume() {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
SetPrivateState(eStateRunning);
std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
bool do_step = false;
+ bool software_single_step = !SupportHardwareSingleStepping();
for (tid_collection::const_iterator t_pos = m_run_tids.begin(),
t_end = m_run_tids.end();
@@ -133,6 +146,11 @@ Error ProcessFreeBSD::DoResume() {
t_pos != t_end; ++t_pos) {
m_monitor->ThreadSuspend(*t_pos, false);
do_step = true;
+ if (software_single_step) {
+ Status error = SetupSoftwareSingleStepping(*t_pos);
+ if (error.Fail())
+ return error;
+ }
}
for (tid_collection::const_iterator t_pos = m_suspend_tids.begin(),
t_end = m_suspend_tids.end();
@@ -145,12 +163,12 @@ Error ProcessFreeBSD::DoResume() {
if (log)
log->Printf("process %" PRIu64 " resuming (%s)", GetID(),
do_step ? "step" : "continue");
- if (do_step)
+ if (do_step && !software_single_step)
m_monitor->SingleStep(GetID(), m_resume_signo);
else
m_monitor->Resume(GetID(), m_resume_signo);
- return Error();
+ return Status();
}
bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list,
@@ -191,7 +209,7 @@ bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list,
return true;
}
-Error ProcessFreeBSD::WillResume() {
+Status ProcessFreeBSD::WillResume() {
m_resume_signo = 0;
m_suspend_tids.clear();
m_run_tids.clear();
@@ -275,14 +293,14 @@ bool ProcessFreeBSD::CanDebug(lldb::TargetSP target_sp,
return true;
}
-Error ProcessFreeBSD::DoAttachToProcessWithID(
- lldb::pid_t pid, const ProcessAttachInfo &attach_info) {
- Error error;
+Status
+ProcessFreeBSD::DoAttachToProcessWithID(lldb::pid_t pid,
+ const ProcessAttachInfo &attach_info) {
+ Status error;
assert(m_monitor == NULL);
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
- if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
- log->Printf("ProcessFreeBSD::%s(pid = %" PRIi64 ")", __FUNCTION__, GetID());
+ LLDB_LOGV(log, "pid = {0}", GetID());
m_monitor = new ProcessMonitor(this, pid, error);
@@ -326,8 +344,8 @@ Error ProcessFreeBSD::DoAttachToProcessWithID(
return error;
}
-Error ProcessFreeBSD::WillLaunch(Module *module) {
- Error error;
+Status ProcessFreeBSD::WillLaunch(Module *module) {
+ Status error;
return error;
}
@@ -349,14 +367,15 @@ ProcessFreeBSD::GetFileSpec(const lldb_private::FileAction *file_action,
return file_spec;
}
-Error ProcessFreeBSD::DoLaunch(Module *module, ProcessLaunchInfo &launch_info) {
- Error error;
+Status ProcessFreeBSD::DoLaunch(Module *module,
+ ProcessLaunchInfo &launch_info) {
+ Status error;
assert(m_monitor == NULL);
FileSpec working_dir = launch_info.GetWorkingDirectory();
- if (working_dir &&
- (!working_dir.ResolvePath() ||
- working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) {
+ namespace fs = llvm::sys::fs;
+ if (working_dir && (!working_dir.ResolvePath() ||
+ !fs::is_directory(working_dir.GetPath()))) {
error.SetErrorStringWithFormat("No such file or directory: %s",
working_dir.GetCString());
return error;
@@ -439,8 +458,8 @@ addr_t ProcessFreeBSD::GetImageInfoAddress() {
return LLDB_INVALID_ADDRESS;
}
-Error ProcessFreeBSD::DoHalt(bool &caused_stop) {
- Error error;
+Status ProcessFreeBSD::DoHalt(bool &caused_stop) {
+ Status error;
if (IsStopped()) {
caused_stop = false;
@@ -453,8 +472,8 @@ Error ProcessFreeBSD::DoHalt(bool &caused_stop) {
return error;
}
-Error ProcessFreeBSD::DoSignal(int signal) {
- Error error;
+Status ProcessFreeBSD::DoSignal(int signal) {
+ Status error;
if (kill(GetID(), signal))
error.SetErrorToErrno();
@@ -462,8 +481,8 @@ Error ProcessFreeBSD::DoSignal(int signal) {
return error;
}
-Error ProcessFreeBSD::DoDestroy() {
- Error error;
+Status ProcessFreeBSD::DoDestroy() {
+ Status error;
if (!HasExited()) {
assert(m_monitor);
@@ -496,7 +515,7 @@ void ProcessFreeBSD::DoDidExec() {
target->GetArchitecture());
FileSpecList executable_search_paths(
Target::GetDefaultExecutableSearchPaths());
- Error error = platform_sp->ResolveExecutable(
+ Status error = platform_sp->ResolveExecutable(
exe_module_spec, exe_module_sp,
executable_search_paths.GetSize() ? &executable_search_paths : NULL);
if (!error.Success())
@@ -528,9 +547,7 @@ ProcessFreeBSD::CreateNewFreeBSDThread(lldb_private::Process &process,
void ProcessFreeBSD::RefreshStateAfterStop() {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
- if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
- log->Printf("ProcessFreeBSD::%s(), message_queue size = %d", __FUNCTION__,
- (int)m_message_queue.size());
+ LLDB_LOGV(log, "message_queue size = {0}", m_message_queue.size());
std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
@@ -542,10 +559,8 @@ void ProcessFreeBSD::RefreshStateAfterStop() {
// Resolve the thread this message corresponds to and pass it along.
lldb::tid_t tid = message.GetTID();
- if (log)
- log->Printf(
- "ProcessFreeBSD::%s(), message_queue size = %d, pid = %" PRIi64,
- __FUNCTION__, (int)m_message_queue.size(), tid);
+ LLDB_LOGV(log, " message_queue size = {0}, pid = {1}",
+ m_message_queue.size(), tid);
m_thread_list.RefreshStateAfterStop();
@@ -557,10 +572,7 @@ void ProcessFreeBSD::RefreshStateAfterStop() {
if (message.GetKind() == ProcessMessage::eExitMessage) {
// FIXME: We should tell the user about this, but the limbo message is
// probably better for that.
- if (log)
- log->Printf("ProcessFreeBSD::%s() removing thread, tid = %" PRIi64,
- __FUNCTION__, tid);
-
+ LLDB_LOG(log, "removing thread, tid = {0}", tid);
std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
ThreadSP thread_sp = m_thread_list.RemoveThreadByID(tid, false);
@@ -579,19 +591,19 @@ bool ProcessFreeBSD::IsAlive() {
}
size_t ProcessFreeBSD::DoReadMemory(addr_t vm_addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
assert(m_monitor);
return m_monitor->ReadMemory(vm_addr, buf, size, error);
}
size_t ProcessFreeBSD::DoWriteMemory(addr_t vm_addr, const void *buf,
- size_t size, Error &error) {
+ size_t size, Status &error) {
assert(m_monitor);
return m_monitor->WriteMemory(vm_addr, buf, size, error);
}
addr_t ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions,
- Error &error) {
+ Status &error) {
addr_t allocated_addr = LLDB_INVALID_ADDRESS;
unsigned prot = 0;
@@ -616,8 +628,8 @@ addr_t ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions,
return allocated_addr;
}
-Error ProcessFreeBSD::DoDeallocateMemory(lldb::addr_t addr) {
- Error error;
+Status ProcessFreeBSD::DoDeallocateMemory(lldb::addr_t addr) {
+ Status error;
MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
if (pos != m_addr_to_mmap_size.end() &&
InferiorCallMunmap(this, addr, pos->second))
@@ -681,16 +693,16 @@ ProcessFreeBSD::GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site) {
return opcode_size;
}
-Error ProcessFreeBSD::EnableBreakpointSite(BreakpointSite *bp_site) {
+Status ProcessFreeBSD::EnableBreakpointSite(BreakpointSite *bp_site) {
return EnableSoftwareBreakpoint(bp_site);
}
-Error ProcessFreeBSD::DisableBreakpointSite(BreakpointSite *bp_site) {
+Status ProcessFreeBSD::DisableBreakpointSite(BreakpointSite *bp_site) {
return DisableSoftwareBreakpoint(bp_site);
}
-Error ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) {
- Error error;
+Status ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) {
+ Status error;
if (wp) {
user_id_t watchID = wp->GetID();
addr_t addr = wp->GetLoadAddress();
@@ -744,8 +756,8 @@ Error ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) {
return error;
}
-Error ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify) {
- Error error;
+Status ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify) {
+ Status error;
if (wp) {
user_id_t watchID = wp->GetID();
addr_t addr = wp->GetLoadAddress();
@@ -787,8 +799,8 @@ Error ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify) {
return error;
}
-Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num) {
- Error error;
+Status ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num) {
+ Status error;
std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
FreeBSDThread *thread = static_cast<FreeBSDThread *>(
m_thread_list.GetThreadAtIndex(0, false).get());
@@ -799,8 +811,8 @@ Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num) {
return error;
}
-Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
- Error error = GetWatchpointSupportInfo(num);
+Status ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
+ Status error = GetWatchpointSupportInfo(num);
// Watchpoints trigger and halt the inferior after
// the corresponding instruction has been executed.
after = true;
@@ -845,7 +857,7 @@ ByteOrder ProcessFreeBSD::GetByteOrder() const {
return m_byte_order;
}
-size_t ProcessFreeBSD::PutSTDIN(const char *buf, size_t len, Error &error) {
+size_t ProcessFreeBSD::PutSTDIN(const char *buf, size_t len, Status &error) {
ssize_t status;
if ((status = write(m_monitor->GetTerminalFD(), buf, len)) < 0) {
error.SetErrorToErrno();
@@ -903,13 +915,207 @@ bool ProcessFreeBSD::IsAThreadRunning() {
const DataBufferSP ProcessFreeBSD::GetAuxvData() {
// If we're the local platform, we can ask the host for auxv data.
PlatformSP platform_sp = GetTarget().GetPlatform();
- if (platform_sp && platform_sp->IsHost())
- return lldb_private::Host::GetAuxvData(this);
-
- // Somewhat unexpected - the process is not running locally or we don't have a
- // platform.
- assert(
- false &&
- "no platform or not the host - how did we get here with ProcessFreeBSD?");
- return DataBufferSP();
+ assert(platform_sp && platform_sp->IsHost());
+
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_AUXV, (int)m_process->GetID()};
+ size_t auxv_size = AT_COUNT * sizeof(Elf_Auxinfo);
+ DataBufferSP buf_sp(new DataBufferHeap(auxv_size, 0));
+
+ if (::sysctl(mib, 4, buf_sp->GetBytes(), &auxv_size, NULL, 0) != 0) {
+ perror("sysctl failed on auxv");
+ buf_sp.reset();
+ }
+
+ return buf_sp;
+}
+
+struct EmulatorBaton {
+ ProcessFreeBSD *m_process;
+ RegisterContext *m_reg_context;
+
+ // eRegisterKindDWARF -> RegisterValue
+ std::unordered_map<uint32_t, RegisterValue> m_register_values;
+
+ EmulatorBaton(ProcessFreeBSD *process, RegisterContext *reg_context)
+ : m_process(process), m_reg_context(reg_context) {}
+};
+
+static size_t ReadMemoryCallback(EmulateInstruction *instruction, void *baton,
+ const EmulateInstruction::Context &context,
+ lldb::addr_t addr, void *dst, size_t length) {
+ EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
+
+ Status error;
+ size_t bytes_read =
+ emulator_baton->m_process->DoReadMemory(addr, dst, length, error);
+ if (!error.Success())
+ bytes_read = 0;
+ return bytes_read;
+}
+
+static bool ReadRegisterCallback(EmulateInstruction *instruction, void *baton,
+ const RegisterInfo *reg_info,
+ RegisterValue &reg_value) {
+ EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
+
+ auto it = emulator_baton->m_register_values.find(
+ reg_info->kinds[eRegisterKindDWARF]);
+ if (it != emulator_baton->m_register_values.end()) {
+ reg_value = it->second;
+ return true;
+ }
+
+ // The emulator only fills in the dwarf register numbers (and in some cases
+ // the generic register numbers). Get the full register info from the
+ // register context based on the dwarf register numbers.
+ const RegisterInfo *full_reg_info =
+ emulator_baton->m_reg_context->GetRegisterInfo(
+ eRegisterKindDWARF, reg_info->kinds[eRegisterKindDWARF]);
+
+ bool error =
+ emulator_baton->m_reg_context->ReadRegister(full_reg_info, reg_value);
+ return error;
+}
+
+static bool WriteRegisterCallback(EmulateInstruction *instruction, void *baton,
+ const EmulateInstruction::Context &context,
+ const RegisterInfo *reg_info,
+ const RegisterValue &reg_value) {
+ EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
+ emulator_baton->m_register_values[reg_info->kinds[eRegisterKindDWARF]] =
+ reg_value;
+ return true;
+}
+
+static size_t WriteMemoryCallback(EmulateInstruction *instruction, void *baton,
+ const EmulateInstruction::Context &context,
+ lldb::addr_t addr, const void *dst,
+ size_t length) {
+ return length;
+}
+
+bool ProcessFreeBSD::SingleStepBreakpointHit(
+ void *baton, lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id) {
+ return false;
+}
+
+Status ProcessFreeBSD::SetSoftwareSingleStepBreakpoint(lldb::tid_t tid,
+ lldb::addr_t addr) {
+ Status error;
+
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ if (log) {
+ log->Printf("ProcessFreeBSD::%s addr = 0x%" PRIx64, __FUNCTION__, addr);
+ log->Printf("SoftwareBreakpoint::%s addr = 0x%" PRIx64, __FUNCTION__, addr);
+ }
+
+ // Validate the address.
+ if (addr == LLDB_INVALID_ADDRESS)
+ return Status("ProcessFreeBSD::%s invalid load address specified.",
+ __FUNCTION__);
+
+ Breakpoint *const sw_step_break =
+ m_process->GetTarget().CreateBreakpoint(addr, true, false).get();
+ sw_step_break->SetCallback(SingleStepBreakpointHit, this, true);
+ sw_step_break->SetBreakpointKind("software-signle-step");
+
+ if (log)
+ log->Printf("ProcessFreeBSD::%s addr = 0x%" PRIx64 " -- SUCCESS",
+ __FUNCTION__, addr);
+
+ m_threads_stepping_with_breakpoint.insert({tid, sw_step_break->GetID()});
+ return Status();
+}
+
+bool ProcessFreeBSD::IsSoftwareStepBreakpoint(lldb::tid_t tid) {
+ ThreadSP thread = GetThreadList().FindThreadByID(tid);
+ if (!thread)
+ return false;
+
+ assert(thread->GetRegisterContext());
+ lldb::addr_t stop_pc = thread->GetRegisterContext()->GetPC();
+
+ const auto &iter = m_threads_stepping_with_breakpoint.find(tid);
+ if (iter == m_threads_stepping_with_breakpoint.end())
+ return false;
+
+ lldb::break_id_t bp_id = iter->second;
+ BreakpointSP bp = GetTarget().GetBreakpointByID(bp_id);
+ if (!bp)
+ return false;
+
+ BreakpointLocationSP bp_loc = bp->FindLocationByAddress(stop_pc);
+ if (!bp_loc)
+ return false;
+
+ GetTarget().RemoveBreakpointByID(bp_id);
+ m_threads_stepping_with_breakpoint.erase(tid);
+ return true;
+}
+
+bool ProcessFreeBSD::SupportHardwareSingleStepping() const {
+ lldb_private::ArchSpec arch = GetTarget().GetArchitecture();
+ if (arch.GetMachine() == llvm::Triple::arm ||
+ arch.GetMachine() == llvm::Triple::mips64 ||
+ arch.GetMachine() == llvm::Triple::mips64el ||
+ arch.GetMachine() == llvm::Triple::mips ||
+ arch.GetMachine() == llvm::Triple::mipsel)
+ return false;
+ return true;
+}
+
+Status ProcessFreeBSD::SetupSoftwareSingleStepping(lldb::tid_t tid) {
+ std::unique_ptr<EmulateInstruction> emulator_ap(
+ EmulateInstruction::FindPlugin(GetTarget().GetArchitecture(),
+ eInstructionTypePCModifying, nullptr));
+
+ if (emulator_ap == nullptr)
+ return Status("Instruction emulator not found!");
+
+ FreeBSDThread *thread = static_cast<FreeBSDThread *>(
+ m_thread_list.FindThreadByID(tid, false).get());
+ if (thread == NULL)
+ return Status("Thread not found not found!");
+
+ lldb::RegisterContextSP register_context_sp = thread->GetRegisterContext();
+
+ EmulatorBaton baton(this, register_context_sp.get());
+ emulator_ap->SetBaton(&baton);
+ emulator_ap->SetReadMemCallback(&ReadMemoryCallback);
+ emulator_ap->SetReadRegCallback(&ReadRegisterCallback);
+ emulator_ap->SetWriteMemCallback(&WriteMemoryCallback);
+ emulator_ap->SetWriteRegCallback(&WriteRegisterCallback);
+
+ if (!emulator_ap->ReadInstruction())
+ return Status("Read instruction failed!");
+
+ bool emulation_result =
+ emulator_ap->EvaluateInstruction(eEmulateInstructionOptionAutoAdvancePC);
+ const RegisterInfo *reg_info_pc = register_context_sp->GetRegisterInfo(
+ eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ auto pc_it =
+ baton.m_register_values.find(reg_info_pc->kinds[eRegisterKindDWARF]);
+
+ lldb::addr_t next_pc;
+ if (emulation_result) {
+ assert(pc_it != baton.m_register_values.end() &&
+ "Emulation was successful but PC wasn't updated");
+ next_pc = pc_it->second.GetAsUInt64();
+ } else if (pc_it == baton.m_register_values.end()) {
+ // Emulate instruction failed and it haven't changed PC. Advance PC
+ // with the size of the current opcode because the emulation of all
+ // PC modifying instruction should be successful. The failure most
+ // likely caused by a not supported instruction which don't modify PC.
+ next_pc =
+ register_context_sp->GetPC() + emulator_ap->GetOpcode().GetByteSize();
+ } else {
+ // The instruction emulation failed after it modified the PC. It is an
+ // unknown error where we can't continue because the next instruction is
+ // modifying the PC but we don't know how.
+ return Status("Instruction emulation failed unexpectedly");
+ }
+
+ SetSoftwareSingleStepBreakpoint(tid, next_pc);
+ return Status();
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
index cd38989..7ed2a56 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
@@ -11,19 +11,13 @@
#ifndef liblldb_ProcessFreeBSD_H_
#define liblldb_ProcessFreeBSD_H_
-// C Includes
-
-// C++ Includes
+#include "Plugins/Process/POSIX/ProcessMessage.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/ThreadList.h"
#include <mutex>
#include <queue>
#include <set>
-// Other libraries and framework includes
-#include "ProcessFreeBSD.h"
-#include "ProcessMessage.h"
-#include "lldb/Target/Process.h"
-#include "lldb/Target/ThreadList.h"
-
class ProcessMonitor;
class FreeBSDThread;
@@ -53,7 +47,7 @@ public:
~ProcessFreeBSD();
- virtual lldb_private::Error WillResume() override;
+ virtual lldb_private::Status WillResume() override;
//------------------------------------------------------------------
// PluginInterface protocol
@@ -71,27 +65,27 @@ public:
bool CanDebug(lldb::TargetSP target_sp,
bool plugin_specified_by_name) override;
- lldb_private::Error WillLaunch(lldb_private::Module *module) override;
+ lldb_private::Status WillLaunch(lldb_private::Module *module) override;
- lldb_private::Error DoAttachToProcessWithID(
+ lldb_private::Status DoAttachToProcessWithID(
lldb::pid_t pid,
const lldb_private::ProcessAttachInfo &attach_info) override;
- lldb_private::Error
+ lldb_private::Status
DoLaunch(lldb_private::Module *exe_module,
lldb_private::ProcessLaunchInfo &launch_info) override;
void DidLaunch() override;
- lldb_private::Error DoResume() override;
+ lldb_private::Status DoResume() override;
- lldb_private::Error DoHalt(bool &caused_stop) override;
+ lldb_private::Status DoHalt(bool &caused_stop) override;
- lldb_private::Error DoDetach(bool keep_stopped) override;
+ lldb_private::Status DoDetach(bool keep_stopped) override;
- lldb_private::Error DoSignal(int signal) override;
+ lldb_private::Status DoSignal(int signal) override;
- lldb_private::Error DoDestroy() override;
+ lldb_private::Status DoDestroy() override;
void DoDidExec() override;
@@ -100,35 +94,35 @@ public:
bool IsAlive() override;
size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
- lldb_private::Error DoDeallocateMemory(lldb::addr_t ptr) override;
+ lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override;
virtual size_t
GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite *bp_site);
- lldb_private::Error
+ lldb_private::Status
EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
- lldb_private::Error
+ lldb_private::Status
DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override;
- lldb_private::Error EnableWatchpoint(lldb_private::Watchpoint *wp,
- bool notify = true) override;
-
- lldb_private::Error DisableWatchpoint(lldb_private::Watchpoint *wp,
+ lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp,
bool notify = true) override;
- lldb_private::Error GetWatchpointSupportInfo(uint32_t &num) override;
+ lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp,
+ bool notify = true) override;
- lldb_private::Error GetWatchpointSupportInfo(uint32_t &num,
- bool &after) override;
+ lldb_private::Status GetWatchpointSupportInfo(uint32_t &num) override;
+
+ lldb_private::Status GetWatchpointSupportInfo(uint32_t &num,
+ bool &after) override;
virtual uint32_t UpdateThreadListIfNeeded();
@@ -140,7 +134,7 @@ public:
lldb::addr_t GetImageInfoAddress() override;
size_t PutSTDIN(const char *buf, size_t len,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
const lldb::DataBufferSP GetAuxvData() override;
@@ -171,7 +165,25 @@ public:
virtual FreeBSDThread *CreateNewFreeBSDThread(lldb_private::Process &process,
lldb::tid_t tid);
+ static bool SingleStepBreakpointHit(
+ void *baton, lldb_private::StoppointCallbackContext *context,
+ lldb::user_id_t break_id, lldb::user_id_t break_loc_id);
+
+ lldb_private::Status SetupSoftwareSingleStepping(lldb::tid_t tid);
+
+ lldb_private::Status SetSoftwareSingleStepBreakpoint(lldb::tid_t tid,
+ lldb::addr_t addr);
+
+ bool IsSoftwareStepBreakpoint(lldb::tid_t tid);
+
+ bool SupportHardwareSingleStepping() const;
+
+ typedef std::vector<lldb::tid_t> tid_collection;
+ tid_collection &GetStepTids() { return m_step_tids; }
+
protected:
+ static const size_t MAX_TRAP_OPCODE_SIZE = 8;
+
/// Target byte order.
lldb::ByteOrder m_byte_order;
@@ -207,10 +219,10 @@ protected:
friend class FreeBSDThread;
- typedef std::vector<lldb::tid_t> tid_collection;
tid_collection m_suspend_tids;
tid_collection m_run_tids;
tid_collection m_step_tids;
+ std::map<lldb::tid_t, lldb::break_id_t> m_threads_stepping_with_breakpoint;
int m_resume_signo;
};
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index afc649d..6291d09 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -21,21 +21,22 @@
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/Error.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
#include "lldb/Host/Host.h"
+#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/UnixSignals.h"
-#include "lldb/Utility/PseudoTerminal.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
#include "FreeBSDThread.h"
#include "Plugins/Process/POSIX/CrashReason.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
-#include "ProcessPOSIXLog.h"
extern "C" {
extern char **environ;
@@ -154,7 +155,7 @@ PtraceWrapper((req), (pid), (addr), (data))
// functions without needed to go thru the thread funnel.
static size_t DoReadMemory(lldb::pid_t pid, lldb::addr_t vm_addr, void *buf,
- size_t size, Error &error) {
+ size_t size, Status &error) {
struct ptrace_io_desc pi_desc;
pi_desc.piod_op = PIOD_READ_D;
@@ -168,7 +169,7 @@ static size_t DoReadMemory(lldb::pid_t pid, lldb::addr_t vm_addr, void *buf,
}
static size_t DoWriteMemory(lldb::pid_t pid, lldb::addr_t vm_addr,
- const void *buf, size_t size, Error &error) {
+ const void *buf, size_t size, Status &error) {
struct ptrace_io_desc pi_desc;
pi_desc.piod_op = PIOD_WRITE_D;
@@ -183,7 +184,7 @@ static size_t DoWriteMemory(lldb::pid_t pid, lldb::addr_t vm_addr,
// Simple helper function to ensure flags are enabled on the given file
// descriptor.
-static bool EnsureFDFlags(int fd, int flags, Error &error) {
+static bool EnsureFDFlags(int fd, int flags, Status &error) {
int status;
if ((status = fcntl(fd, F_GETFL)) == -1) {
@@ -221,7 +222,7 @@ public:
/// @brief Implements ProcessMonitor::ReadMemory.
class ReadOperation : public Operation {
public:
- ReadOperation(lldb::addr_t addr, void *buff, size_t size, Error &error,
+ ReadOperation(lldb::addr_t addr, void *buff, size_t size, Status &error,
size_t &result)
: m_addr(addr), m_buff(buff), m_size(size), m_error(error),
m_result(result) {}
@@ -232,7 +233,7 @@ private:
lldb::addr_t m_addr;
void *m_buff;
size_t m_size;
- Error &m_error;
+ Status &m_error;
size_t &m_result;
};
@@ -247,8 +248,8 @@ void ReadOperation::Execute(ProcessMonitor *monitor) {
/// @brief Implements ProcessMonitor::WriteMemory.
class WriteOperation : public Operation {
public:
- WriteOperation(lldb::addr_t addr, const void *buff, size_t size, Error &error,
- size_t &result)
+ WriteOperation(lldb::addr_t addr, const void *buff, size_t size,
+ Status &error, size_t &result)
: m_addr(addr), m_buff(buff), m_size(size), m_error(error),
m_result(result) {}
@@ -258,7 +259,7 @@ private:
lldb::addr_t m_addr;
const void *m_buff;
size_t m_size;
- Error &m_error;
+ Status &m_error;
size_t &m_result;
};
@@ -529,10 +530,8 @@ void ResumeOperation::Execute(ProcessMonitor *monitor) {
if (PTRACE(PT_CONTINUE, pid, (caddr_t)1, data)) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
-
- if (log)
- log->Printf("ResumeOperation (%" PRIu64 ") failed: %s", pid,
- strerror(errno));
+ LLDB_LOG(log, "ResumeOperation ({0}) failed: {1}", pid,
+ llvm::sys::StrError(errno));
m_result = false;
} else
m_result = true;
@@ -672,12 +671,12 @@ void KillOperation::Execute(ProcessMonitor *monitor) {
/// @brief Implements ProcessMonitor::Detach.
class DetachOperation : public Operation {
public:
- DetachOperation(Error &result) : m_error(result) {}
+ DetachOperation(Status &result) : m_error(result) {}
void Execute(ProcessMonitor *monitor);
private:
- Error &m_error;
+ Status &m_error;
};
void DetachOperation::Execute(ProcessMonitor *monitor) {
@@ -731,7 +730,7 @@ ProcessMonitor::ProcessMonitor(
const FileSpec &stdout_file_spec, const FileSpec &stderr_file_spec,
const FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo & /* launch_info */,
- lldb_private::Error &error)
+ lldb_private::Status &error)
: m_process(static_cast<ProcessFreeBSD *>(process)),
m_pid(LLDB_INVALID_PROCESS_ID), m_terminal_fd(-1), m_operation(0) {
using namespace std::placeholders;
@@ -747,15 +746,9 @@ ProcessMonitor::ProcessMonitor(
if (!error.Success())
return;
-WAIT_AGAIN:
- // Wait for the operation thread to initialize.
- if (sem_wait(&args->m_semaphore)) {
- if (errno == EINTR)
- goto WAIT_AGAIN;
- else {
- error.SetErrorToErrno();
- return;
- }
+ if (llvm::sys::RetryAfterSignal(-1, sem_wait, &args->m_semaphore) == -1) {
+ error.SetErrorToErrno();
+ return;
}
// Check that the launch was a success.
@@ -777,7 +770,7 @@ WAIT_AGAIN:
}
ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
- lldb_private::Error &error)
+ lldb_private::Status &error)
: m_process(static_cast<ProcessFreeBSD *>(process)), m_pid(pid),
m_terminal_fd(-1), m_operation(0) {
using namespace std::placeholders;
@@ -791,15 +784,9 @@ ProcessMonitor::ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
if (!error.Success())
return;
-WAIT_AGAIN:
- // Wait for the operation thread to initialize.
- if (sem_wait(&args->m_semaphore)) {
- if (errno == EINTR)
- goto WAIT_AGAIN;
- else {
- error.SetErrorToErrno();
- return;
- }
+ if (llvm::sys::RetryAfterSignal(-1, sem_wait, &args->m_semaphore) == -1) {
+ error.SetErrorToErrno();
+ return;
}
// Check that the attach was a success.
@@ -824,7 +811,7 @@ ProcessMonitor::~ProcessMonitor() { StopMonitor(); }
//------------------------------------------------------------------------------
// Thread setup and tear down.
-void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Error &error) {
+void ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Status &error) {
static const char *g_thread_name = "lldb.process.freebsd.operation";
if (m_operation_thread.IsJoinable())
@@ -992,7 +979,7 @@ FINISH:
}
void ProcessMonitor::StartAttachOpThread(AttachArgs *args,
- lldb_private::Error &error) {
+ lldb_private::Status &error) {
static const char *g_thread_name = "lldb.process.freebsd.operation";
if (m_operation_thread.IsJoinable())
@@ -1132,6 +1119,10 @@ ProcessMessage ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
case 0:
case TRAP_TRACE:
+#ifdef TRAP_CAP
+ // Map TRAP_CAP to a trace trap in the absense of a more specific handler.
+ case TRAP_CAP:
+#endif
if (log)
log->Printf("ProcessMonitor::%s() received trace event, tid = %" PRIu64
" : si_code = %d",
@@ -1141,11 +1132,19 @@ ProcessMessage ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
case SI_KERNEL:
case TRAP_BRKPT:
- if (log)
- log->Printf(
- "ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64,
- __FUNCTION__, tid);
- message = ProcessMessage::Break(tid);
+ if (monitor->m_process->IsSoftwareStepBreakpoint(tid)) {
+ if (log)
+ log->Printf("ProcessMonitor::%s() received sw single step breakpoint "
+ "event, tid = %" PRIu64,
+ __FUNCTION__, tid);
+ message = ProcessMessage::Trace(tid);
+ } else {
+ if (log)
+ log->Printf(
+ "ProcessMonitor::%s() received breakpoint event, tid = %" PRIu64,
+ __FUNCTION__, tid);
+ message = ProcessMessage::Break(tid);
+ }
break;
}
@@ -1193,7 +1192,9 @@ ProcessMessage ProcessMonitor::MonitorSignal(ProcessMonitor *monitor,
case SIGBUS:
lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
const auto reason = GetCrashReason(*info);
- return ProcessMessage::Crash(tid, reason, signo, fault_addr);
+ if (reason != CrashReason::eInvalidCrashReason) {
+ return ProcessMessage::Crash(tid, reason, signo, fault_addr);
+ } // else; Use atleast si_signo info for other si_code
}
// Everything else is "normal" and does not require any special action on
@@ -1232,7 +1233,7 @@ void ProcessMonitor::DoOperation(Operation *op) {
}
size_t ProcessMonitor::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
size_t result;
ReadOperation op(vm_addr, buf, size, error, result);
DoOperation(&op);
@@ -1240,7 +1241,7 @@ size_t ProcessMonitor::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
}
size_t ProcessMonitor::WriteMemory(lldb::addr_t vm_addr, const void *buf,
- size_t size, lldb_private::Error &error) {
+ size_t size, lldb_private::Status &error) {
size_t result;
WriteOperation op(vm_addr, buf, size, error, result);
DoOperation(&op);
@@ -1381,8 +1382,8 @@ bool ProcessMonitor::GetEventMessage(lldb::tid_t tid, unsigned long *message) {
return result;
}
-lldb_private::Error ProcessMonitor::Detach(lldb::tid_t tid) {
- lldb_private::Error error;
+lldb_private::Status ProcessMonitor::Detach(lldb::tid_t tid) {
+ lldb_private::Status error;
if (tid != LLDB_INVALID_THREAD_ID) {
DetachOperation op(error);
DoOperation(&op);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
index 4c2594e..0963453 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -18,12 +18,12 @@
#include <mutex>
// Other libraries and framework includes
-#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostThread.h"
+#include "lldb/Utility/FileSpec.h"
#include "lldb/lldb-types.h"
namespace lldb_private {
-class Error;
+class Status;
class Module;
class Scalar;
} // End lldb_private namespace.
@@ -54,10 +54,10 @@ public:
const lldb_private::FileSpec &stderr_file_spec,
const lldb_private::FileSpec &working_dir,
const lldb_private::ProcessLaunchInfo &launch_info,
- lldb_private::Error &error);
+ lldb_private::Status &error);
ProcessMonitor(ProcessFreeBSD *process, lldb::pid_t pid,
- lldb_private::Error &error);
+ lldb_private::Status &error);
~ProcessMonitor();
@@ -86,14 +86,14 @@ public:
///
/// This method is provided to implement Process::DoReadMemory.
size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
- lldb_private::Error &error);
+ lldb_private::Status &error);
/// Writes @p size bytes from address @p vm_adder in the inferior process
/// address space.
///
/// This method is provided to implement Process::DoWriteMemory.
size_t WriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
- lldb_private::Error &error);
+ lldb_private::Status &error);
/// Reads the contents from the register identified by the given (architecture
/// dependent) offset.
@@ -178,7 +178,7 @@ public:
/// Terminate the traced process.
bool Kill();
- lldb_private::Error Detach(lldb::tid_t tid);
+ lldb_private::Status Detach(lldb::tid_t tid);
void StopMonitor();
@@ -210,7 +210,7 @@ private:
ProcessMonitor *m_monitor; // The monitor performing the attach.
sem_t m_semaphore; // Posted to once operation complete.
- lldb_private::Error m_error; // Set if process operation failed.
+ lldb_private::Status m_error; // Set if process operation failed.
};
/// @class LauchArgs
@@ -238,7 +238,7 @@ private:
const lldb_private::FileSpec m_working_dir; // Working directory or empty.
};
- void StartLaunchOpThread(LaunchArgs *args, lldb_private::Error &error);
+ void StartLaunchOpThread(LaunchArgs *args, lldb_private::Status &error);
static void *LaunchOpThread(void *arg);
@@ -252,7 +252,7 @@ private:
lldb::pid_t m_pid; // pid of the process to be attached.
};
- void StartAttachOpThread(AttachArgs *args, lldb_private::Error &error);
+ void StartAttachOpThread(AttachArgs *args, lldb_private::Status &error);
static void *AttachOpThread(void *args);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
index f8d5f2e..59d42b9 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm.cpp
@@ -7,9 +7,9 @@
//
//===---------------------------------------------------------------------===//
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
@@ -75,7 +75,7 @@ bool RegisterContextPOSIXProcessMonitor_arm::WriteRegister(
// Read the full register.
if (ReadRegister(full_reg_info, full_value)) {
- Error error;
+ Status error;
ByteOrder byte_order = GetByteOrder();
uint8_t dst[RegisterValue::kMaxRegisterByteSize];
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp
index 98a213a..93ffeb5 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_arm64.cpp
@@ -7,9 +7,9 @@
//
//===---------------------------------------------------------------------===//
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
#include "Plugins/Process/Utility/RegisterContextPOSIX_arm64.h"
#include "ProcessFreeBSD.h"
@@ -77,7 +77,7 @@ bool RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(
// Read the full register.
if (ReadRegister(full_reg_info, full_value)) {
- lldb_private::Error error;
+ lldb_private::Status error;
lldb::ByteOrder byte_order = GetByteOrder();
uint8_t dst[lldb_private::RegisterValue::kMaxRegisterByteSize];
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
index 020636e..b911ee2 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
#include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
#include "ProcessFreeBSD.h"
@@ -76,7 +76,7 @@ bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
// Read the full register.
if (ReadRegister(full_reg_info, full_value)) {
- Error error;
+ Status error;
ByteOrder byte_order = GetByteOrder();
uint8_t dst[RegisterValue::kMaxRegisterByteSize];
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h
index 2f75e60..6f57b0d 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.h
@@ -11,6 +11,7 @@
#define liblldb_RegisterContextPOSIXProcessMonitor_mips64_H_
#include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
+#include "Plugins/Process/Utility/lldb-mips-freebsd-register-enums.h"
#include "RegisterContextPOSIX.h"
class RegisterContextPOSIXProcessMonitor_mips64
@@ -72,6 +73,8 @@ protected:
uint32_t NumSupportedHardwareWatchpoints();
private:
+ uint64_t
+ m_gpr_mips64[k_num_gpr_registers_mips64]; // general purpose registers.
ProcessMonitor &GetMonitor();
};
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
index e7b01fa..bc1d4df 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_powerpc.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
#include "ProcessFreeBSD.h"
#include "ProcessMonitor.h"
@@ -88,7 +88,7 @@ bool RegisterContextPOSIXProcessMonitor_powerpc::WriteRegister(
// Read the full register.
if (ReadRegister(full_reg_info, full_value)) {
- Error error;
+ Status error;
ByteOrder byte_order = GetByteOrder();
uint8_t dst[RegisterValue::kMaxRegisterByteSize];
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
index 976b190..1cd8f1a 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_x86.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
#include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
#include "Plugins/Process/FreeBSD/ProcessMonitor.h"
@@ -130,7 +130,7 @@ bool RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(
// Read the full register.
if (ReadRegister(full_reg_info, full_value)) {
- Error error;
+ Status error;
ByteOrder byte_order = GetByteOrder();
uint8_t dst[RegisterValue::kMaxRegisterByteSize];
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/CMakeLists.txt b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/CMakeLists.txt
new file mode 100644
index 0000000..5b2cef8
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/CMakeLists.txt
@@ -0,0 +1,21 @@
+include_directories(.)
+include_directories(../POSIX)
+include_directories(../Utility)
+
+add_lldb_library(lldbPluginProcessNetBSD PLUGIN
+ NativeProcessNetBSD.cpp
+ NativeRegisterContextNetBSD.cpp
+ NativeRegisterContextNetBSD_x86_64.cpp
+ NativeThreadNetBSD.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ lldbSymbol
+ lldbTarget
+ lldbUtility
+ lldbPluginProcessPOSIX
+ lldbPluginProcessUtility
+ LINK_COMPONENTS
+ Support
+ )
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
new file mode 100644
index 0000000..388989a
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -0,0 +1,939 @@
+//===-- NativeProcessNetBSD.cpp ------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "NativeProcessNetBSD.h"
+
+// C Includes
+
+// C++ Includes
+
+// Other libraries and framework includes
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Core/State.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/common/NativeBreakpoint.h"
+#include "lldb/Host/common/NativeRegisterContext.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Target/Process.h"
+#include "llvm/Support/Errno.h"
+
+// System includes - They have to be included after framework includes because
+// they define some
+// macros which collide with variable names in other modules
+// clang-format off
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/sysctl.h>
+#include <sys/wait.h>
+#include <uvm/uvm_prot.h>
+#include <elf.h>
+#include <util.h>
+// clang-format on
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_netbsd;
+using namespace llvm;
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static Status EnsureFDFlags(int fd, int flags) {
+ Status error;
+
+ int status = fcntl(fd, F_GETFL);
+ if (status == -1) {
+ error.SetErrorToErrno();
+ return error;
+ }
+
+ if (fcntl(fd, F_SETFL, status | flags) == -1) {
+ error.SetErrorToErrno();
+ return error;
+ }
+
+ return error;
+}
+
+// -----------------------------------------------------------------------------
+// Public Static Methods
+// -----------------------------------------------------------------------------
+
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessNetBSD::Factory::Launch(ProcessLaunchInfo &launch_info,
+ NativeDelegate &native_delegate,
+ MainLoop &mainloop) const {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+
+ Status status;
+ ::pid_t pid = ProcessLauncherPosixFork()
+ .LaunchProcess(launch_info, status)
+ .GetProcessId();
+ LLDB_LOG(log, "pid = {0:x}", pid);
+ if (status.Fail()) {
+ LLDB_LOG(log, "failed to launch process: {0}", status);
+ return status.ToError();
+ }
+
+ // Wait for the child process to trap on its call to execve.
+ int wstatus;
+ ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+ assert(wpid == pid);
+ (void)wpid;
+ if (!WIFSTOPPED(wstatus)) {
+ LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+ return llvm::make_error<StringError>("Could not sync with inferior process",
+ llvm::inconvertibleErrorCode());
+ }
+ LLDB_LOG(log, "inferior started, now in stopped state");
+
+ ArchSpec arch;
+ if ((status = ResolveProcessArchitecture(pid, arch)).Fail())
+ return status.ToError();
+
+ // Set the architecture to the exe architecture.
+ LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid,
+ arch.GetArchitectureName());
+
+ std::unique_ptr<NativeProcessNetBSD> process_up(new NativeProcessNetBSD(
+ pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate,
+ arch, mainloop));
+
+ status = process_up->ReinitializeThreads();
+ if (status.Fail())
+ return status.ToError();
+
+ for (const auto &thread_sp : process_up->m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+ SIGSTOP);
+ }
+ process_up->SetState(StateType::eStateStopped);
+
+ return std::move(process_up);
+}
+
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessNetBSD::Factory::Attach(
+ lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
+ MainLoop &mainloop) const {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ LLDB_LOG(log, "pid = {0:x}", pid);
+
+ // Retrieve the architecture for the running process.
+ ArchSpec arch;
+ Status status = ResolveProcessArchitecture(pid, arch);
+ if (!status.Success())
+ return status.ToError();
+
+ std::unique_ptr<NativeProcessNetBSD> process_up(
+ new NativeProcessNetBSD(pid, -1, native_delegate, arch, mainloop));
+
+ status = process_up->Attach();
+ if (!status.Success())
+ return status.ToError();
+
+ return std::move(process_up);
+}
+
+// -----------------------------------------------------------------------------
+// Public Instance Methods
+// -----------------------------------------------------------------------------
+
+NativeProcessNetBSD::NativeProcessNetBSD(::pid_t pid, int terminal_fd,
+ NativeDelegate &delegate,
+ const ArchSpec &arch,
+ MainLoop &mainloop)
+ : NativeProcessProtocol(pid, terminal_fd, delegate), m_arch(arch) {
+ if (m_terminal_fd != -1) {
+ Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
+ assert(status.Success());
+ }
+
+ Status status;
+ m_sigchld_handle = mainloop.RegisterSignal(
+ SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+ assert(m_sigchld_handle && status.Success());
+}
+
+// Handles all waitpid events from the inferior process.
+void NativeProcessNetBSD::MonitorCallback(lldb::pid_t pid, int signal) {
+ switch (signal) {
+ case SIGTRAP:
+ return MonitorSIGTRAP(pid);
+ case SIGSTOP:
+ return MonitorSIGSTOP(pid);
+ default:
+ return MonitorSignal(pid, signal);
+ }
+}
+
+void NativeProcessNetBSD::MonitorExited(lldb::pid_t pid, WaitStatus status) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+
+ LLDB_LOG(log, "got exit signal({0}) , pid = {1}", status, pid);
+
+ /* Stop Tracking All Threads attached to Process */
+ m_threads.clear();
+
+ SetExitStatus(status, true);
+
+ // Notify delegate that our process has exited.
+ SetState(StateType::eStateExited, true);
+}
+
+void NativeProcessNetBSD::MonitorSIGSTOP(lldb::pid_t pid) {
+ ptrace_siginfo_t info;
+
+ const auto siginfo_err =
+ PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
+
+ // Get details on the signal raised.
+ if (siginfo_err.Success()) {
+ // Handle SIGSTOP from LLGS (LLDB GDB Server)
+ if (info.psi_siginfo.si_code == SI_USER &&
+ info.psi_siginfo.si_pid == ::getpid()) {
+ /* Stop Tracking All Threads attached to Process */
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+ SIGSTOP, &info.psi_siginfo);
+ }
+ }
+ }
+}
+
+void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ ptrace_siginfo_t info;
+
+ const auto siginfo_err =
+ PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
+
+ // Get details on the signal raised.
+ if (siginfo_err.Fail()) {
+ return;
+ }
+
+ switch (info.psi_siginfo.si_code) {
+ case TRAP_BRKPT:
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)
+ ->SetStoppedByBreakpoint();
+ FixupBreakpointPCAsNeeded(
+ *static_pointer_cast<NativeThreadNetBSD>(thread_sp));
+ }
+ SetState(StateType::eStateStopped, true);
+ break;
+ case TRAP_TRACE:
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByTrace();
+ }
+ SetState(StateType::eStateStopped, true);
+ break;
+ case TRAP_EXEC: {
+ Status error = ReinitializeThreads();
+ if (error.Fail()) {
+ SetState(StateType::eStateInvalid);
+ return;
+ }
+
+ // Let our delegate know we have just exec'd.
+ NotifyDidExec();
+
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByExec();
+ }
+ SetState(StateType::eStateStopped, true);
+ } break;
+ case TRAP_DBREG: {
+ // If a watchpoint was hit, report it
+ uint32_t wp_index;
+ Status error =
+ static_pointer_cast<NativeThreadNetBSD>(m_threads[info.psi_lwpid])
+ ->GetRegisterContext()
+ ->GetWatchpointHitIndex(wp_index,
+ (uintptr_t)info.psi_siginfo.si_addr);
+ if (error.Fail())
+ LLDB_LOG(log,
+ "received error while checking for watchpoint hits, pid = "
+ "{0}, LWP = {1}, error = {2}",
+ GetID(), info.psi_lwpid, error);
+ if (wp_index != LLDB_INVALID_INDEX32) {
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)
+ ->SetStoppedByWatchpoint(wp_index);
+ }
+ SetState(StateType::eStateStopped, true);
+ break;
+ }
+
+ // If a breakpoint was hit, report it
+ uint32_t bp_index;
+ error = static_pointer_cast<NativeThreadNetBSD>(m_threads[info.psi_lwpid])
+ ->GetRegisterContext()
+ ->GetHardwareBreakHitIndex(bp_index,
+ (uintptr_t)info.psi_siginfo.si_addr);
+ if (error.Fail())
+ LLDB_LOG(log,
+ "received error while checking for hardware "
+ "breakpoint hits, pid = {0}, LWP = {1}, error = {2}",
+ GetID(), info.psi_lwpid, error);
+ if (bp_index != LLDB_INVALID_INDEX32) {
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)
+ ->SetStoppedByBreakpoint();
+ }
+ SetState(StateType::eStateStopped, true);
+ break;
+ }
+ } break;
+ }
+}
+
+void NativeProcessNetBSD::MonitorSignal(lldb::pid_t pid, int signal) {
+ ptrace_siginfo_t info;
+ const auto siginfo_err =
+ PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
+
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+ info.psi_siginfo.si_signo, &info.psi_siginfo);
+ }
+ SetState(StateType::eStateStopped, true);
+}
+
+Status NativeProcessNetBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
+ int data, int *result) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PTRACE));
+ Status error;
+ int ret;
+
+ errno = 0;
+ ret = ptrace(req, static_cast<::pid_t>(pid), addr, data);
+
+ if (ret == -1)
+ error.SetErrorToErrno();
+
+ if (result)
+ *result = ret;
+
+ LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3})={4:x}", req, pid, addr, data, ret);
+
+ if (error.Fail())
+ LLDB_LOG(log, "ptrace() failed: {0}", error);
+
+ return error;
+}
+
+Status NativeProcessNetBSD::GetSoftwareBreakpointPCOffset(
+ uint32_t &actual_opcode_size) {
+ // FIXME put this behind a breakpoint protocol class that can be
+ // set per architecture. Need ARM, MIPS support here.
+ static const uint8_t g_i386_opcode[] = {0xCC};
+ switch (m_arch.GetMachine()) {
+ case llvm::Triple::x86_64:
+ actual_opcode_size = static_cast<uint32_t>(sizeof(g_i386_opcode));
+ return Status();
+ default:
+ assert(false && "CPU type not supported!");
+ return Status("CPU type not supported");
+ }
+}
+
+Status
+NativeProcessNetBSD::FixupBreakpointPCAsNeeded(NativeThreadNetBSD &thread) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_BREAKPOINTS));
+ Status error;
+ // Find out the size of a breakpoint (might depend on where we are in the
+ // code).
+ NativeRegisterContextSP context_sp = thread.GetRegisterContext();
+ if (!context_sp) {
+ error.SetErrorString("cannot get a NativeRegisterContext for the thread");
+ LLDB_LOG(log, "failed: {0}", error);
+ return error;
+ }
+ uint32_t breakpoint_size = 0;
+ error = GetSoftwareBreakpointPCOffset(breakpoint_size);
+ if (error.Fail()) {
+ LLDB_LOG(log, "GetBreakpointSize() failed: {0}", error);
+ return error;
+ } else
+ LLDB_LOG(log, "breakpoint size: {0}", breakpoint_size);
+ // First try probing for a breakpoint at a software breakpoint location: PC
+ // - breakpoint size.
+ const lldb::addr_t initial_pc_addr =
+ context_sp->GetPCfromBreakpointLocation();
+ lldb::addr_t breakpoint_addr = initial_pc_addr;
+ if (breakpoint_size > 0) {
+ // Do not allow breakpoint probe to wrap around.
+ if (breakpoint_addr >= breakpoint_size)
+ breakpoint_addr -= breakpoint_size;
+ }
+ // Check if we stopped because of a breakpoint.
+ NativeBreakpointSP breakpoint_sp;
+ error = m_breakpoint_list.GetBreakpoint(breakpoint_addr, breakpoint_sp);
+ if (!error.Success() || !breakpoint_sp) {
+ // We didn't find one at a software probe location. Nothing to do.
+ LLDB_LOG(log,
+ "pid {0} no lldb breakpoint found at current pc with "
+ "adjustment: {1}",
+ GetID(), breakpoint_addr);
+ return Status();
+ }
+ // If the breakpoint is not a software breakpoint, nothing to do.
+ if (!breakpoint_sp->IsSoftwareBreakpoint()) {
+ LLDB_LOG(
+ log,
+ "pid {0} breakpoint found at {1:x}, not software, nothing to adjust",
+ GetID(), breakpoint_addr);
+ return Status();
+ }
+ //
+ // We have a software breakpoint and need to adjust the PC.
+ //
+ // Sanity check.
+ if (breakpoint_size == 0) {
+ // Nothing to do! How did we get here?
+ LLDB_LOG(log,
+ "pid {0} breakpoint found at {1:x}, it is software, but the "
+ "size is zero, nothing to do (unexpected)",
+ GetID(), breakpoint_addr);
+ return Status();
+ }
+ //
+ // We have a software breakpoint and need to adjust the PC.
+ //
+ // Sanity check.
+ if (breakpoint_size == 0) {
+ // Nothing to do! How did we get here?
+ LLDB_LOG(log,
+ "pid {0} breakpoint found at {1:x}, it is software, but the "
+ "size is zero, nothing to do (unexpected)",
+ GetID(), breakpoint_addr);
+ return Status();
+ }
+ // Change the program counter.
+ LLDB_LOG(log, "pid {0} tid {1}: changing PC from {2:x} to {3:x}", GetID(),
+ thread.GetID(), initial_pc_addr, breakpoint_addr);
+ error = context_sp->SetPC(breakpoint_addr);
+ if (error.Fail()) {
+ LLDB_LOG(log, "pid {0} tid {1}: failed to set PC: {2}", GetID(),
+ thread.GetID(), error);
+ return error;
+ }
+ return error;
+}
+
+Status NativeProcessNetBSD::Resume(const ResumeActionList &resume_actions) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ LLDB_LOG(log, "pid {0}", GetID());
+
+ const auto &thread_sp = m_threads[0];
+ const ResumeAction *const action =
+ resume_actions.GetActionForThread(thread_sp->GetID(), true);
+
+ if (action == nullptr) {
+ LLDB_LOG(log, "no action specified for pid {0} tid {1}", GetID(),
+ thread_sp->GetID());
+ return Status();
+ }
+
+ Status error;
+
+ switch (action->state) {
+ case eStateRunning: {
+ // Run the thread, possibly feeding it the signal.
+ error = NativeProcessNetBSD::PtraceWrapper(PT_CONTINUE, GetID(), (void *)1,
+ action->signal);
+ if (!error.Success())
+ return error;
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetRunning();
+ }
+ SetState(eStateRunning, true);
+ break;
+ }
+ case eStateStepping:
+ // Run the thread, possibly feeding it the signal.
+ error = NativeProcessNetBSD::PtraceWrapper(PT_STEP, GetID(), (void *)1,
+ action->signal);
+ if (!error.Success())
+ return error;
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStepping();
+ }
+ SetState(eStateStepping, true);
+ break;
+
+ case eStateSuspended:
+ case eStateStopped:
+ llvm_unreachable("Unexpected state");
+
+ default:
+ return Status("NativeProcessNetBSD::%s (): unexpected state %s specified "
+ "for pid %" PRIu64 ", tid %" PRIu64,
+ __FUNCTION__, StateAsCString(action->state), GetID(),
+ thread_sp->GetID());
+ }
+
+ return Status();
+}
+
+Status NativeProcessNetBSD::Halt() {
+ Status error;
+
+ if (kill(GetID(), SIGSTOP) != 0)
+ error.SetErrorToErrno();
+
+ return error;
+}
+
+Status NativeProcessNetBSD::Detach() {
+ Status error;
+
+ // Stop monitoring the inferior.
+ m_sigchld_handle.reset();
+
+ // Tell ptrace to detach from the process.
+ if (GetID() == LLDB_INVALID_PROCESS_ID)
+ return error;
+
+ return PtraceWrapper(PT_DETACH, GetID());
+}
+
+Status NativeProcessNetBSD::Signal(int signo) {
+ Status error;
+
+ if (kill(GetID(), signo))
+ error.SetErrorToErrno();
+
+ return error;
+}
+
+Status NativeProcessNetBSD::Kill() {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ LLDB_LOG(log, "pid {0}", GetID());
+
+ Status error;
+
+ switch (m_state) {
+ case StateType::eStateInvalid:
+ case StateType::eStateExited:
+ case StateType::eStateCrashed:
+ case StateType::eStateDetached:
+ case StateType::eStateUnloaded:
+ // Nothing to do - the process is already dead.
+ LLDB_LOG(log, "ignored for PID {0} due to current state: {1}", GetID(),
+ StateAsCString(m_state));
+ return error;
+
+ case StateType::eStateConnected:
+ case StateType::eStateAttaching:
+ case StateType::eStateLaunching:
+ case StateType::eStateStopped:
+ case StateType::eStateRunning:
+ case StateType::eStateStepping:
+ case StateType::eStateSuspended:
+ // We can try to kill a process in these states.
+ break;
+ }
+
+ if (kill(GetID(), SIGKILL) != 0) {
+ error.SetErrorToErrno();
+ return error;
+ }
+
+ return error;
+}
+
+Status NativeProcessNetBSD::GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &range_info) {
+
+ if (m_supports_mem_region == LazyBool::eLazyBoolNo) {
+ // We're done.
+ return Status("unsupported");
+ }
+
+ Status error = PopulateMemoryRegionCache();
+ if (error.Fail()) {
+ return error;
+ }
+
+ lldb::addr_t prev_base_address = 0;
+ // FIXME start by finding the last region that is <= target address using
+ // binary search. Data is sorted.
+ // There can be a ton of regions on pthreads apps with lots of threads.
+ for (auto it = m_mem_region_cache.begin(); it != m_mem_region_cache.end();
+ ++it) {
+ MemoryRegionInfo &proc_entry_info = it->first;
+ // Sanity check assumption that memory map entries are ascending.
+ assert((proc_entry_info.GetRange().GetRangeBase() >= prev_base_address) &&
+ "descending memory map entries detected, unexpected");
+ prev_base_address = proc_entry_info.GetRange().GetRangeBase();
+ UNUSED_IF_ASSERT_DISABLED(prev_base_address);
+ // If the target address comes before this entry, indicate distance to
+ // next region.
+ if (load_addr < proc_entry_info.GetRange().GetRangeBase()) {
+ range_info.GetRange().SetRangeBase(load_addr);
+ range_info.GetRange().SetByteSize(
+ proc_entry_info.GetRange().GetRangeBase() - load_addr);
+ range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+ range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+ range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+ range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+ return error;
+ } else if (proc_entry_info.GetRange().Contains(load_addr)) {
+ // The target address is within the memory region we're processing here.
+ range_info = proc_entry_info;
+ return error;
+ }
+ // The target memory address comes somewhere after the region we just
+ // parsed.
+ }
+ // If we made it here, we didn't find an entry that contained the given
+ // address. Return the
+ // load_addr as start and the amount of bytes betwwen load address and the
+ // end of the memory as size.
+ range_info.GetRange().SetRangeBase(load_addr);
+ range_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
+ range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+ range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+ range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+ range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
+ return error;
+}
+
+Status NativeProcessNetBSD::PopulateMemoryRegionCache() {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ // If our cache is empty, pull the latest. There should always be at least
+ // one memory region if memory region handling is supported.
+ if (!m_mem_region_cache.empty()) {
+ LLDB_LOG(log, "reusing {0} cached memory region entries",
+ m_mem_region_cache.size());
+ return Status();
+ }
+
+ struct kinfo_vmentry *vm;
+ size_t count, i;
+ vm = kinfo_getvmmap(GetID(), &count);
+ if (vm == NULL) {
+ m_supports_mem_region = LazyBool::eLazyBoolNo;
+ Status error;
+ error.SetErrorString("not supported");
+ return error;
+ }
+ for (i = 0; i < count; i++) {
+ MemoryRegionInfo info;
+ info.Clear();
+ info.GetRange().SetRangeBase(vm[i].kve_start);
+ info.GetRange().SetRangeEnd(vm[i].kve_end);
+ info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
+
+ if (vm[i].kve_protection & VM_PROT_READ)
+ info.SetReadable(MemoryRegionInfo::OptionalBool::eYes);
+ else
+ info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
+
+ if (vm[i].kve_protection & VM_PROT_WRITE)
+ info.SetWritable(MemoryRegionInfo::OptionalBool::eYes);
+ else
+ info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
+
+ if (vm[i].kve_protection & VM_PROT_EXECUTE)
+ info.SetExecutable(MemoryRegionInfo::OptionalBool::eYes);
+ else
+ info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
+
+ if (vm[i].kve_path[0])
+ info.SetName(vm[i].kve_path);
+
+ m_mem_region_cache.emplace_back(
+ info, FileSpec(info.GetName().GetCString(), true));
+ }
+ free(vm);
+
+ if (m_mem_region_cache.empty()) {
+ // No entries after attempting to read them. This shouldn't happen.
+ // Assume we don't support map entries.
+ LLDB_LOG(log, "failed to find any vmmap entries, assuming no support "
+ "for memory region metadata retrieval");
+ m_supports_mem_region = LazyBool::eLazyBoolNo;
+ Status error;
+ error.SetErrorString("not supported");
+ return error;
+ }
+ LLDB_LOG(log, "read {0} memory region entries from process {1}",
+ m_mem_region_cache.size(), GetID());
+ // We support memory retrieval, remember that.
+ m_supports_mem_region = LazyBool::eLazyBoolYes;
+ return Status();
+}
+
+Status NativeProcessNetBSD::AllocateMemory(size_t size, uint32_t permissions,
+ lldb::addr_t &addr) {
+ return Status("Unimplemented");
+}
+
+Status NativeProcessNetBSD::DeallocateMemory(lldb::addr_t addr) {
+ return Status("Unimplemented");
+}
+
+lldb::addr_t NativeProcessNetBSD::GetSharedLibraryInfoAddress() {
+ // punt on this for now
+ return LLDB_INVALID_ADDRESS;
+}
+
+size_t NativeProcessNetBSD::UpdateThreads() { return m_threads.size(); }
+
+bool NativeProcessNetBSD::GetArchitecture(ArchSpec &arch) const {
+ arch = m_arch;
+ return true;
+}
+
+Status NativeProcessNetBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) {
+ if (hardware)
+ return Status("NativeProcessNetBSD does not support hardware breakpoints");
+ else
+ return SetSoftwareBreakpoint(addr, size);
+}
+
+Status NativeProcessNetBSD::GetSoftwareBreakpointTrapOpcode(
+ size_t trap_opcode_size_hint, size_t &actual_opcode_size,
+ const uint8_t *&trap_opcode_bytes) {
+ static const uint8_t g_i386_opcode[] = {0xCC};
+
+ switch (m_arch.GetMachine()) {
+ case llvm::Triple::x86:
+ case llvm::Triple::x86_64:
+ trap_opcode_bytes = g_i386_opcode;
+ actual_opcode_size = sizeof(g_i386_opcode);
+ return Status();
+ default:
+ assert(false && "CPU type not supported!");
+ return Status("CPU type not supported");
+ }
+}
+
+Status NativeProcessNetBSD::GetLoadedModuleFileSpec(const char *module_path,
+ FileSpec &file_spec) {
+ return Status("Unimplemented");
+}
+
+Status NativeProcessNetBSD::GetFileLoadAddress(const llvm::StringRef &file_name,
+ lldb::addr_t &load_addr) {
+ load_addr = LLDB_INVALID_ADDRESS;
+ return Status();
+}
+
+void NativeProcessNetBSD::SigchldHandler() {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
+ // Process all pending waitpid notifications.
+ int status;
+ ::pid_t wait_pid =
+ llvm::sys::RetryAfterSignal(-1, waitpid, GetID(), &status, WALLSIG | WNOHANG);
+
+ if (wait_pid == 0)
+ return; // We are done.
+
+ if (wait_pid == -1) {
+ Status error(errno, eErrorTypePOSIX);
+ LLDB_LOG(log, "waitpid ({0}, &status, _) failed: {1}", GetID(), error);
+ }
+
+ WaitStatus wait_status = WaitStatus::Decode(status);
+ bool exited = wait_status.type == WaitStatus::Exit ||
+ (wait_status.type == WaitStatus::Signal &&
+ wait_pid == static_cast<::pid_t>(GetID()));
+
+ LLDB_LOG(log,
+ "waitpid ({0}, &status, _) => pid = {1}, status = {2}, exited = {3}",
+ GetID(), wait_pid, status, exited);
+
+ if (exited)
+ MonitorExited(wait_pid, wait_status);
+ else {
+ assert(wait_status.type == WaitStatus::Stop);
+ MonitorCallback(wait_pid, wait_status.status);
+ }
+}
+
+bool NativeProcessNetBSD::HasThreadNoLock(lldb::tid_t thread_id) {
+ for (auto thread_sp : m_threads) {
+ assert(thread_sp && "thread list should not contain NULL threads");
+ if (thread_sp->GetID() == thread_id) {
+ // We have this thread.
+ return true;
+ }
+ }
+
+ // We don't have this thread.
+ return false;
+}
+
+NativeThreadNetBSDSP NativeProcessNetBSD::AddThread(lldb::tid_t thread_id) {
+
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+ LLDB_LOG(log, "pid {0} adding thread with tid {1}", GetID(), thread_id);
+
+ assert(!HasThreadNoLock(thread_id) &&
+ "attempted to add a thread by id that already exists");
+
+ // If this is the first thread, save it as the current thread
+ if (m_threads.empty())
+ SetCurrentThreadID(thread_id);
+
+ auto thread_sp = std::make_shared<NativeThreadNetBSD>(*this, thread_id);
+ m_threads.push_back(thread_sp);
+ return thread_sp;
+}
+
+Status NativeProcessNetBSD::Attach() {
+ // Attach to the requested process.
+ // An attach will cause the thread to stop with a SIGSTOP.
+ Status status = PtraceWrapper(PT_ATTACH, m_pid);
+ if (status.Fail())
+ return status;
+
+ int wstatus;
+ // Need to use WALLSIG otherwise we receive an error with errno=ECHLD
+ // At this point we should have a thread stopped if waitpid succeeds.
+ if ((wstatus = waitpid(m_pid, NULL, WALLSIG)) < 0)
+ return Status(errno, eErrorTypePOSIX);
+
+ /* Initialize threads */
+ status = ReinitializeThreads();
+ if (status.Fail())
+ return status;
+
+ for (const auto &thread_sp : m_threads) {
+ static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+ SIGSTOP);
+ }
+
+ // Let our process instance know the thread has stopped.
+ SetState(StateType::eStateStopped);
+ return Status();
+}
+
+Status NativeProcessNetBSD::ReadMemory(lldb::addr_t addr, void *buf,
+ size_t size, size_t &bytes_read) {
+ unsigned char *dst = static_cast<unsigned char *>(buf);
+ struct ptrace_io_desc io;
+
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_MEMORY));
+ LLDB_LOG(log, "addr = {0}, buf = {1}, size = {2}", addr, buf, size);
+
+ bytes_read = 0;
+ io.piod_op = PIOD_READ_D;
+ io.piod_len = size;
+
+ do {
+ io.piod_offs = (void *)(addr + bytes_read);
+ io.piod_addr = dst + bytes_read;
+
+ Status error = NativeProcessNetBSD::PtraceWrapper(PT_IO, GetID(), &io);
+ if (error.Fail())
+ return error;
+
+ bytes_read = io.piod_len;
+ io.piod_len = size - bytes_read;
+ } while (bytes_read < size);
+
+ return Status();
+}
+
+Status NativeProcessNetBSD::ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf,
+ size_t size,
+ size_t &bytes_read) {
+ Status error = ReadMemory(addr, buf, size, bytes_read);
+ if (error.Fail())
+ return error;
+ return m_breakpoint_list.RemoveTrapsFromBuffer(addr, buf, size);
+}
+
+Status NativeProcessNetBSD::WriteMemory(lldb::addr_t addr, const void *buf,
+ size_t size, size_t &bytes_written) {
+ const unsigned char *src = static_cast<const unsigned char *>(buf);
+ Status error;
+ struct ptrace_io_desc io;
+
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_MEMORY));
+ LLDB_LOG(log, "addr = {0}, buf = {1}, size = {2}", addr, buf, size);
+
+ bytes_written = 0;
+ io.piod_op = PIOD_WRITE_D;
+ io.piod_len = size;
+
+ do {
+ io.piod_addr = const_cast<void *>(static_cast<const void *>(src + bytes_written));
+ io.piod_offs = (void *)(addr + bytes_written);
+
+ Status error = NativeProcessNetBSD::PtraceWrapper(PT_IO, GetID(), &io);
+ if (error.Fail())
+ return error;
+
+ bytes_written = io.piod_len;
+ io.piod_len = size - bytes_written;
+ } while (bytes_written < size);
+
+ return error;
+}
+
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+NativeProcessNetBSD::GetAuxvData() const {
+ /*
+ * ELF_AUX_ENTRIES is currently restricted to kernel
+ * (<sys/exec_elf.h> r. 1.155 specifies 15)
+ *
+ * ptrace(2) returns the whole AUXV including extra fiels after AT_NULL this
+ * information isn't needed.
+ */
+ size_t auxv_size = 100 * sizeof(AuxInfo);
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> buf =
+ llvm::MemoryBuffer::getNewMemBuffer(auxv_size);
+
+ struct ptrace_io_desc io;
+ io.piod_op = PIOD_READ_AUXV;
+ io.piod_offs = 0;
+ io.piod_addr = const_cast<void *>(static_cast<const void *>(buf.get()->getBufferStart()));
+ io.piod_len = auxv_size;
+
+ Status error = NativeProcessNetBSD::PtraceWrapper(PT_IO, GetID(), &io);
+
+ if (error.Fail())
+ return std::error_code(error.GetError(), std::generic_category());
+
+ if (io.piod_len < 1)
+ return std::error_code(ECANCELED, std::generic_category());
+
+ return buf;
+}
+
+Status NativeProcessNetBSD::ReinitializeThreads() {
+ // Clear old threads
+ m_threads.clear();
+
+ // Initialize new thread
+ struct ptrace_lwpinfo info = {};
+ Status error = PtraceWrapper(PT_LWPINFO, GetID(), &info, sizeof(info));
+ if (error.Fail()) {
+ return error;
+ }
+ // Reinitialize from scratch threads and register them in process
+ while (info.pl_lwpid != 0) {
+ NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
+ error = PtraceWrapper(PT_LWPINFO, GetID(), &info, sizeof(info));
+ if (error.Fail()) {
+ return error;
+ }
+ }
+
+ return error;
+}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
new file mode 100644
index 0000000..2cbd5e3
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -0,0 +1,144 @@
+//===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_NativeProcessNetBSD_H_
+#define liblldb_NativeProcessNetBSD_H_
+
+// C++ Includes
+
+// Other libraries and framework includes
+
+#include "lldb/Core/ArchSpec.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/FileSpec.h"
+
+#include "NativeThreadNetBSD.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
+
+namespace lldb_private {
+namespace process_netbsd {
+/// @class NativeProcessNetBSD
+/// @brief Manages communication with the inferior (debugee) process.
+///
+/// Upon construction, this class prepares and launches an inferior process for
+/// debugging.
+///
+/// Changes in the inferior process state are broadcasted.
+class NativeProcessNetBSD : public NativeProcessProtocol {
+public:
+ class Factory : public NativeProcessProtocol::Factory {
+ public:
+ llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+ Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
+ MainLoop &mainloop) const override;
+
+ llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+ Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
+ MainLoop &mainloop) const override;
+ };
+
+ // ---------------------------------------------------------------------
+ // NativeProcessProtocol Interface
+ // ---------------------------------------------------------------------
+ Status Resume(const ResumeActionList &resume_actions) override;
+
+ Status Halt() override;
+
+ Status Detach() override;
+
+ Status Signal(int signo) override;
+
+ Status Kill() override;
+
+ Status GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &range_info) override;
+
+ Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
+ size_t &bytes_read) override;
+
+ Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
+ size_t &bytes_read) override;
+
+ Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
+ size_t &bytes_written) override;
+
+ Status AllocateMemory(size_t size, uint32_t permissions,
+ lldb::addr_t &addr) override;
+
+ Status DeallocateMemory(lldb::addr_t addr) override;
+
+ lldb::addr_t GetSharedLibraryInfoAddress() override;
+
+ size_t UpdateThreads() override;
+
+ bool GetArchitecture(ArchSpec &arch) const override;
+
+ Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
+ bool hardware) override;
+
+ Status GetLoadedModuleFileSpec(const char *module_path,
+ FileSpec &file_spec) override;
+
+ Status GetFileLoadAddress(const llvm::StringRef &file_name,
+ lldb::addr_t &load_addr) override;
+
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ GetAuxvData() const override;
+
+ // ---------------------------------------------------------------------
+ // Interface used by NativeRegisterContext-derived classes.
+ // ---------------------------------------------------------------------
+ static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
+ int data = 0, int *result = nullptr);
+
+protected:
+ // ---------------------------------------------------------------------
+ // NativeProcessProtocol protected interface
+ // ---------------------------------------------------------------------
+
+ Status
+ GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
+ size_t &actual_opcode_size,
+ const uint8_t *&trap_opcode_bytes) override;
+
+private:
+ MainLoop::SignalHandleUP m_sigchld_handle;
+ ArchSpec m_arch;
+ LazyBool m_supports_mem_region = eLazyBoolCalculate;
+ std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
+
+ // ---------------------------------------------------------------------
+ // Private Instance Methods
+ // ---------------------------------------------------------------------
+ NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
+ const ArchSpec &arch, MainLoop &mainloop);
+
+ bool HasThreadNoLock(lldb::tid_t thread_id);
+
+ NativeThreadNetBSDSP AddThread(lldb::tid_t thread_id);
+
+ void MonitorCallback(lldb::pid_t pid, int signal);
+ void MonitorExited(lldb::pid_t pid, WaitStatus status);
+ void MonitorSIGSTOP(lldb::pid_t pid);
+ void MonitorSIGTRAP(lldb::pid_t pid);
+ void MonitorSignal(lldb::pid_t pid, int signal);
+
+ Status GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
+ Status FixupBreakpointPCAsNeeded(NativeThreadNetBSD &thread);
+ Status PopulateMemoryRegionCache();
+ void SigchldHandler();
+
+ Status Attach();
+ Status ReinitializeThreads();
+};
+
+} // namespace process_netbsd
+} // namespace lldb_private
+
+#endif // #ifndef liblldb_NativeProcessNetBSD_H_
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
new file mode 100644
index 0000000..dde8688
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
@@ -0,0 +1,112 @@
+//===-- NativeRegisterContextNetBSD.cpp -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "NativeRegisterContextNetBSD.h"
+
+#include "lldb/Host/common/NativeProcessProtocol.h"
+
+using namespace lldb_private;
+using namespace lldb_private::process_netbsd;
+
+// clang-format off
+#include <sys/types.h>
+#include <sys/ptrace.h>
+// clang-format on
+
+NativeRegisterContextNetBSD::NativeRegisterContextNetBSD(
+ NativeThreadProtocol &native_thread, uint32_t concrete_frame_idx,
+ RegisterInfoInterface *reg_info_interface_p)
+ : NativeRegisterContextRegisterInfo(native_thread, concrete_frame_idx,
+ reg_info_interface_p) {}
+
+Status NativeRegisterContextNetBSD::ReadGPR() {
+ void *buf = GetGPRBuffer();
+ if (!buf)
+ return Status("GPR buffer is NULL");
+
+ return DoReadGPR(buf);
+}
+
+Status NativeRegisterContextNetBSD::WriteGPR() {
+ void *buf = GetGPRBuffer();
+ if (!buf)
+ return Status("GPR buffer is NULL");
+
+ return DoWriteGPR(buf);
+}
+
+Status NativeRegisterContextNetBSD::ReadFPR() {
+ void *buf = GetFPRBuffer();
+ if (!buf)
+ return Status("FPR buffer is NULL");
+
+ return DoReadFPR(buf);
+}
+
+Status NativeRegisterContextNetBSD::WriteFPR() {
+ void *buf = GetFPRBuffer();
+ if (!buf)
+ return Status("FPR buffer is NULL");
+
+ return DoWriteFPR(buf);
+}
+
+Status NativeRegisterContextNetBSD::ReadDBR() {
+ void *buf = GetDBRBuffer();
+ if (!buf)
+ return Status("DBR buffer is NULL");
+
+ return DoReadDBR(buf);
+}
+
+Status NativeRegisterContextNetBSD::WriteDBR() {
+ void *buf = GetDBRBuffer();
+ if (!buf)
+ return Status("DBR buffer is NULL");
+
+ return DoWriteDBR(buf);
+}
+
+Status NativeRegisterContextNetBSD::DoReadGPR(void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf,
+ m_thread.GetID());
+}
+
+Status NativeRegisterContextNetBSD::DoWriteGPR(void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf,
+ m_thread.GetID());
+}
+
+Status NativeRegisterContextNetBSD::DoReadFPR(void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf,
+ m_thread.GetID());
+}
+
+Status NativeRegisterContextNetBSD::DoWriteFPR(void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf,
+ m_thread.GetID());
+}
+
+Status NativeRegisterContextNetBSD::DoReadDBR(void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf,
+ m_thread.GetID());
+}
+
+Status NativeRegisterContextNetBSD::DoWriteDBR(void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf,
+ m_thread.GetID());
+}
+
+NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() {
+ return static_cast<NativeProcessNetBSD &>(m_thread.GetProcess());
+}
+
+::pid_t NativeRegisterContextNetBSD::GetProcessPid() {
+ return GetProcess().GetID();
+}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
new file mode 100644
index 0000000..d96b7ae
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
@@ -0,0 +1,74 @@
+//===-- NativeRegisterContextNetBSD.h ---------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_NativeRegisterContextNetBSD_h
+#define lldb_NativeRegisterContextNetBSD_h
+
+#include "lldb/Host/common/NativeThreadProtocol.h"
+
+#include "Plugins/Process/NetBSD/NativeProcessNetBSD.h"
+#include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"
+
+namespace lldb_private {
+namespace process_netbsd {
+
+class NativeRegisterContextNetBSD : public NativeRegisterContextRegisterInfo {
+public:
+ NativeRegisterContextNetBSD(NativeThreadProtocol &native_thread,
+ uint32_t concrete_frame_idx,
+ RegisterInfoInterface *reg_info_interface_p);
+
+ // This function is implemented in the NativeRegisterContextNetBSD_*
+ // subclasses to create a new instance of the host specific
+ // NativeRegisterContextNetBSD. The implementations can't collide as only one
+ // NativeRegisterContextNetBSD_* variant should be compiled into the final
+ // executable.
+ static NativeRegisterContextNetBSD *
+ CreateHostNativeRegisterContextNetBSD(const ArchSpec &target_arch,
+ NativeThreadProtocol &native_thread,
+ uint32_t concrete_frame_idx);
+
+protected:
+ virtual Status ReadGPR();
+ virtual Status WriteGPR();
+
+ virtual Status ReadFPR();
+ virtual Status WriteFPR();
+
+ virtual Status ReadDBR();
+ virtual Status WriteDBR();
+
+ virtual void *GetGPRBuffer() { return nullptr; }
+ virtual size_t GetGPRSize() {
+ return GetRegisterInfoInterface().GetGPRSize();
+ }
+
+ virtual void *GetFPRBuffer() { return nullptr; }
+ virtual size_t GetFPRSize() { return 0; }
+
+ virtual void *GetDBRBuffer() { return nullptr; }
+ virtual size_t GetDBRSize() { return 0; }
+
+ virtual Status DoReadGPR(void *buf);
+ virtual Status DoWriteGPR(void *buf);
+
+ virtual Status DoReadFPR(void *buf);
+ virtual Status DoWriteFPR(void *buf);
+
+ virtual Status DoReadDBR(void *buf);
+ virtual Status DoWriteDBR(void *buf);
+
+ virtual NativeProcessNetBSD &GetProcess();
+ virtual ::pid_t GetProcessPid();
+};
+
+} // namespace process_netbsd
+} // namespace lldb_private
+
+#endif // #ifndef lldb_NativeRegisterContextNetBSD_h
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
new file mode 100644
index 0000000..9690da0
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
@@ -0,0 +1,940 @@
+//===-- NativeRegisterContextNetBSD_x86_64.cpp ---------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(__x86_64__)
+
+#include "NativeRegisterContextNetBSD_x86_64.h"
+
+#include "lldb/Core/RegisterValue.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
+
+#include "Plugins/Process/Utility/RegisterContextNetBSD_x86_64.h"
+
+// clang-format off
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <x86/cpu.h>
+#include <elf.h>
+#include <err.h>
+#include <stdint.h>
+#include <stdlib.h>
+// clang-format on
+
+using namespace lldb_private;
+using namespace lldb_private::process_netbsd;
+
+// ----------------------------------------------------------------------------
+// Private namespace.
+// ----------------------------------------------------------------------------
+
+namespace {
+// x86 64-bit general purpose registers.
+static const uint32_t g_gpr_regnums_x86_64[] = {
+ lldb_rax_x86_64, lldb_rbx_x86_64, lldb_rcx_x86_64, lldb_rdx_x86_64,
+ lldb_rdi_x86_64, lldb_rsi_x86_64, lldb_rbp_x86_64, lldb_rsp_x86_64,
+ lldb_r8_x86_64, lldb_r9_x86_64, lldb_r10_x86_64, lldb_r11_x86_64,
+ lldb_r12_x86_64, lldb_r13_x86_64, lldb_r14_x86_64, lldb_r15_x86_64,
+ lldb_rip_x86_64, lldb_rflags_x86_64, lldb_cs_x86_64, lldb_fs_x86_64,
+ lldb_gs_x86_64, lldb_ss_x86_64, lldb_ds_x86_64, lldb_es_x86_64,
+ lldb_eax_x86_64, lldb_ebx_x86_64, lldb_ecx_x86_64, lldb_edx_x86_64,
+ lldb_edi_x86_64, lldb_esi_x86_64, lldb_ebp_x86_64, lldb_esp_x86_64,
+ lldb_r8d_x86_64, // Low 32 bits or r8
+ lldb_r9d_x86_64, // Low 32 bits or r9
+ lldb_r10d_x86_64, // Low 32 bits or r10
+ lldb_r11d_x86_64, // Low 32 bits or r11
+ lldb_r12d_x86_64, // Low 32 bits or r12
+ lldb_r13d_x86_64, // Low 32 bits or r13
+ lldb_r14d_x86_64, // Low 32 bits or r14
+ lldb_r15d_x86_64, // Low 32 bits or r15
+ lldb_ax_x86_64, lldb_bx_x86_64, lldb_cx_x86_64, lldb_dx_x86_64,
+ lldb_di_x86_64, lldb_si_x86_64, lldb_bp_x86_64, lldb_sp_x86_64,
+ lldb_r8w_x86_64, // Low 16 bits or r8
+ lldb_r9w_x86_64, // Low 16 bits or r9
+ lldb_r10w_x86_64, // Low 16 bits or r10
+ lldb_r11w_x86_64, // Low 16 bits or r11
+ lldb_r12w_x86_64, // Low 16 bits or r12
+ lldb_r13w_x86_64, // Low 16 bits or r13
+ lldb_r14w_x86_64, // Low 16 bits or r14
+ lldb_r15w_x86_64, // Low 16 bits or r15
+ lldb_ah_x86_64, lldb_bh_x86_64, lldb_ch_x86_64, lldb_dh_x86_64,
+ lldb_al_x86_64, lldb_bl_x86_64, lldb_cl_x86_64, lldb_dl_x86_64,
+ lldb_dil_x86_64, lldb_sil_x86_64, lldb_bpl_x86_64, lldb_spl_x86_64,
+ lldb_r8l_x86_64, // Low 8 bits or r8
+ lldb_r9l_x86_64, // Low 8 bits or r9
+ lldb_r10l_x86_64, // Low 8 bits or r10
+ lldb_r11l_x86_64, // Low 8 bits or r11
+ lldb_r12l_x86_64, // Low 8 bits or r12
+ lldb_r13l_x86_64, // Low 8 bits or r13
+ lldb_r14l_x86_64, // Low 8 bits or r14
+ lldb_r15l_x86_64, // Low 8 bits or r15
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+static_assert((sizeof(g_gpr_regnums_x86_64) / sizeof(g_gpr_regnums_x86_64[0])) -
+ 1 ==
+ k_num_gpr_registers_x86_64,
+ "g_gpr_regnums_x86_64 has wrong number of register infos");
+
+// Number of register sets provided by this context.
+enum { k_num_extended_register_sets = 2, k_num_register_sets = 4 };
+
+// Register sets for x86 64-bit.
+static const RegisterSet g_reg_sets_x86_64[k_num_register_sets] = {
+ {"General Purpose Registers", "gpr", k_num_gpr_registers_x86_64,
+ g_gpr_regnums_x86_64},
+};
+
+#define REG_CONTEXT_SIZE (GetRegisterInfoInterface().GetGPRSize())
+
+const int fpu_present = []() -> int {
+ int mib[2];
+ int error;
+ size_t len;
+ int val;
+
+ len = sizeof(val);
+ mib[0] = CTL_MACHDEP;
+ mib[1] = CPU_FPU_PRESENT;
+
+ error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
+ if (error)
+ errx(EXIT_FAILURE, "sysctl");
+
+ return val;
+}();
+
+const int osfxsr = []() -> int {
+ int mib[2];
+ int error;
+ size_t len;
+ int val;
+
+ len = sizeof(val);
+ mib[0] = CTL_MACHDEP;
+ mib[1] = CPU_OSFXSR;
+
+ error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
+ if (error)
+ errx(EXIT_FAILURE, "sysctl");
+
+ return val;
+}();
+
+const int fpu_save = []() -> int {
+ int mib[2];
+ int error;
+ size_t len;
+ int val;
+
+ len = sizeof(val);
+ mib[0] = CTL_MACHDEP;
+ mib[1] = CPU_FPU_SAVE;
+
+ error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
+ if (error)
+ errx(EXIT_FAILURE, "sysctl");
+
+ return val;
+}();
+
+} // namespace
+
+NativeRegisterContextNetBSD *
+NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
+ uint32_t concrete_frame_idx) {
+ return new NativeRegisterContextNetBSD_x86_64(target_arch, native_thread,
+ concrete_frame_idx);
+}
+
+// ----------------------------------------------------------------------------
+// NativeRegisterContextNetBSD_x86_64 members.
+// ----------------------------------------------------------------------------
+
+static RegisterInfoInterface *
+CreateRegisterInfoInterface(const ArchSpec &target_arch) {
+ assert((HostInfo::GetArchitecture().GetAddressByteSize() == 8) &&
+ "Register setting path assumes this is a 64-bit host");
+ // X86_64 hosts know how to work with 64-bit and 32-bit EXEs using the
+ // x86_64 register context.
+ return new RegisterContextNetBSD_x86_64(target_arch);
+}
+
+NativeRegisterContextNetBSD_x86_64::NativeRegisterContextNetBSD_x86_64(
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
+ uint32_t concrete_frame_idx)
+ : NativeRegisterContextNetBSD(native_thread, concrete_frame_idx,
+ CreateRegisterInfoInterface(target_arch)),
+ m_gpr_x86_64(), m_fpr_x86_64(), m_dbr_x86_64() {}
+
+// CONSIDER after local and llgs debugging are merged, register set support can
+// be moved into a base x86-64 class with IsRegisterSetAvailable made virtual.
+uint32_t NativeRegisterContextNetBSD_x86_64::GetRegisterSetCount() const {
+ uint32_t sets = 0;
+ for (uint32_t set_index = 0; set_index < k_num_register_sets; ++set_index) {
+ if (GetSetForNativeRegNum(set_index) != -1)
+ ++sets;
+ }
+
+ return sets;
+}
+
+const RegisterSet *
+NativeRegisterContextNetBSD_x86_64::GetRegisterSet(uint32_t set_index) const {
+ switch (GetRegisterInfoInterface().GetTargetArchitecture().GetMachine()) {
+ case llvm::Triple::x86_64:
+ return &g_reg_sets_x86_64[set_index];
+ default:
+ assert(false && "Unhandled target architecture.");
+ return nullptr;
+ }
+
+ return nullptr;
+}
+
+int NativeRegisterContextNetBSD_x86_64::GetSetForNativeRegNum(
+ int reg_num) const {
+ if (reg_num <= k_last_gpr_x86_64)
+ return GPRegSet;
+ else if (reg_num <= k_last_fpr_x86_64)
+ return (fpu_present == 1 && osfxsr == 1 && fpu_save >= 1) ? FPRegSet : -1;
+ else if (reg_num <= k_last_avx_x86_64)
+ return -1; // AVX
+ else if (reg_num <= k_last_mpxr_x86_64)
+ return -1; // MPXR
+ else if (reg_num <= k_last_mpxc_x86_64)
+ return -1; // MPXC
+ else if (reg_num <= lldb_dr7_x86_64)
+ return DBRegSet; // DBR
+ else
+ return -1;
+}
+
+int NativeRegisterContextNetBSD_x86_64::ReadRegisterSet(uint32_t set) {
+ switch (set) {
+ case GPRegSet:
+ ReadGPR();
+ return 0;
+ case FPRegSet:
+ ReadFPR();
+ return 0;
+ case DBRegSet:
+ ReadDBR();
+ return 0;
+ default:
+ break;
+ }
+ return -1;
+}
+int NativeRegisterContextNetBSD_x86_64::WriteRegisterSet(uint32_t set) {
+ switch (set) {
+ case GPRegSet:
+ WriteGPR();
+ return 0;
+ case FPRegSet:
+ WriteFPR();
+ return 0;
+ case DBRegSet:
+ WriteDBR();
+ return 0;
+ default:
+ break;
+ }
+ return -1;
+}
+
+Status
+NativeRegisterContextNetBSD_x86_64::ReadRegister(const RegisterInfo *reg_info,
+ RegisterValue &reg_value) {
+ Status error;
+
+ if (!reg_info) {
+ error.SetErrorString("reg_info NULL");
+ return error;
+ }
+
+ const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
+ if (reg == LLDB_INVALID_REGNUM) {
+ // This is likely an internal register for lldb use only and should not be
+ // directly queried.
+ error.SetErrorStringWithFormat("register \"%s\" is an internal-only lldb "
+ "register, cannot read directly",
+ reg_info->name);
+ return error;
+ }
+
+ int set = GetSetForNativeRegNum(reg);
+ if (set == -1) {
+ // This is likely an internal register for lldb use only and should not be
+ // directly queried.
+ error.SetErrorStringWithFormat("register \"%s\" is in unrecognized set",
+ reg_info->name);
+ return error;
+ }
+
+ if (ReadRegisterSet(set) != 0) {
+ // This is likely an internal register for lldb use only and should not be
+ // directly queried.
+ error.SetErrorStringWithFormat(
+ "reading register set for register \"%s\" failed", reg_info->name);
+ return error;
+ }
+
+ switch (reg) {
+ case lldb_rax_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RAX];
+ break;
+ case lldb_rbx_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RBX];
+ break;
+ case lldb_rcx_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RCX];
+ break;
+ case lldb_rdx_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RDX];
+ break;
+ case lldb_rdi_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RDI];
+ break;
+ case lldb_rsi_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RSI];
+ break;
+ case lldb_rbp_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RBP];
+ break;
+ case lldb_rsp_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RSP];
+ break;
+ case lldb_r8_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R8];
+ break;
+ case lldb_r9_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R9];
+ break;
+ case lldb_r10_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R10];
+ break;
+ case lldb_r11_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R11];
+ break;
+ case lldb_r12_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R12];
+ break;
+ case lldb_r13_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R13];
+ break;
+ case lldb_r14_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R14];
+ break;
+ case lldb_r15_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_R15];
+ break;
+ case lldb_rip_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RIP];
+ break;
+ case lldb_rflags_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_RFLAGS];
+ break;
+ case lldb_cs_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_CS];
+ break;
+ case lldb_fs_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_FS];
+ break;
+ case lldb_gs_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_GS];
+ break;
+ case lldb_ss_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_SS];
+ break;
+ case lldb_ds_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_DS];
+ break;
+ case lldb_es_x86_64:
+ reg_value = (uint64_t)m_gpr_x86_64.regs[_REG_ES];
+ break;
+ case lldb_fctrl_x86_64:
+ reg_value = (uint16_t)m_fpr_x86_64.fxstate.fx_cw;
+ break;
+ case lldb_fstat_x86_64:
+ reg_value = (uint16_t)m_fpr_x86_64.fxstate.fx_sw;
+ break;
+ case lldb_ftag_x86_64:
+ reg_value = (uint8_t)m_fpr_x86_64.fxstate.fx_tw;
+ break;
+ case lldb_fop_x86_64:
+ reg_value = (uint64_t)m_fpr_x86_64.fxstate.fx_opcode;
+ break;
+ case lldb_fiseg_x86_64:
+ reg_value = (uint64_t)m_fpr_x86_64.fxstate.fx_ip.fa_64;
+ break;
+ case lldb_fioff_x86_64:
+ reg_value = (uint32_t)m_fpr_x86_64.fxstate.fx_ip.fa_32.fa_off;
+ break;
+ case lldb_foseg_x86_64:
+ reg_value = (uint64_t)m_fpr_x86_64.fxstate.fx_dp.fa_64;
+ break;
+ case lldb_fooff_x86_64:
+ reg_value = (uint32_t)m_fpr_x86_64.fxstate.fx_dp.fa_32.fa_off;
+ break;
+ case lldb_mxcsr_x86_64:
+ reg_value = (uint32_t)m_fpr_x86_64.fxstate.fx_mxcsr;
+ break;
+ case lldb_mxcsrmask_x86_64:
+ reg_value = (uint32_t)m_fpr_x86_64.fxstate.fx_mxcsr_mask;
+ break;
+ case lldb_st0_x86_64:
+ case lldb_st1_x86_64:
+ case lldb_st2_x86_64:
+ case lldb_st3_x86_64:
+ case lldb_st4_x86_64:
+ case lldb_st5_x86_64:
+ case lldb_st6_x86_64:
+ case lldb_st7_x86_64:
+ reg_value.SetBytes(&m_fpr_x86_64.fxstate.fx_87_ac[reg - lldb_st0_x86_64],
+ reg_info->byte_size, endian::InlHostByteOrder());
+ break;
+ case lldb_mm0_x86_64:
+ case lldb_mm1_x86_64:
+ case lldb_mm2_x86_64:
+ case lldb_mm3_x86_64:
+ case lldb_mm4_x86_64:
+ case lldb_mm5_x86_64:
+ case lldb_mm6_x86_64:
+ case lldb_mm7_x86_64:
+ reg_value.SetBytes(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_mm0_x86_64],
+ reg_info->byte_size, endian::InlHostByteOrder());
+ break;
+ case lldb_xmm0_x86_64:
+ case lldb_xmm1_x86_64:
+ case lldb_xmm2_x86_64:
+ case lldb_xmm3_x86_64:
+ case lldb_xmm4_x86_64:
+ case lldb_xmm5_x86_64:
+ case lldb_xmm6_x86_64:
+ case lldb_xmm7_x86_64:
+ case lldb_xmm8_x86_64:
+ case lldb_xmm9_x86_64:
+ case lldb_xmm10_x86_64:
+ case lldb_xmm11_x86_64:
+ case lldb_xmm12_x86_64:
+ case lldb_xmm13_x86_64:
+ case lldb_xmm14_x86_64:
+ case lldb_xmm15_x86_64:
+ reg_value.SetBytes(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_xmm0_x86_64],
+ reg_info->byte_size, endian::InlHostByteOrder());
+ break;
+ case lldb_dr0_x86_64:
+ case lldb_dr1_x86_64:
+ case lldb_dr2_x86_64:
+ case lldb_dr3_x86_64:
+ case lldb_dr4_x86_64:
+ case lldb_dr5_x86_64:
+ case lldb_dr6_x86_64:
+ case lldb_dr7_x86_64:
+ reg_value = (uint64_t)m_dbr_x86_64.dr[reg - lldb_dr0_x86_64];
+ break;
+ }
+
+ return error;
+}
+
+Status NativeRegisterContextNetBSD_x86_64::WriteRegister(
+ const RegisterInfo *reg_info, const RegisterValue &reg_value) {
+
+ Status error;
+
+ if (!reg_info) {
+ error.SetErrorString("reg_info NULL");
+ return error;
+ }
+
+ const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
+ if (reg == LLDB_INVALID_REGNUM) {
+ // This is likely an internal register for lldb use only and should not be
+ // directly queried.
+ error.SetErrorStringWithFormat("register \"%s\" is an internal-only lldb "
+ "register, cannot read directly",
+ reg_info->name);
+ return error;
+ }
+
+ int set = GetSetForNativeRegNum(reg);
+ if (set == -1) {
+ // This is likely an internal register for lldb use only and should not be
+ // directly queried.
+ error.SetErrorStringWithFormat("register \"%s\" is in unrecognized set",
+ reg_info->name);
+ return error;
+ }
+
+ if (ReadRegisterSet(set) != 0) {
+ // This is likely an internal register for lldb use only and should not be
+ // directly queried.
+ error.SetErrorStringWithFormat(
+ "reading register set for register \"%s\" failed", reg_info->name);
+ return error;
+ }
+
+ switch (reg) {
+ case lldb_rax_x86_64:
+ m_gpr_x86_64.regs[_REG_RAX] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rbx_x86_64:
+ m_gpr_x86_64.regs[_REG_RBX] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rcx_x86_64:
+ m_gpr_x86_64.regs[_REG_RCX] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rdx_x86_64:
+ m_gpr_x86_64.regs[_REG_RDX] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rdi_x86_64:
+ m_gpr_x86_64.regs[_REG_RDI] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rsi_x86_64:
+ m_gpr_x86_64.regs[_REG_RSI] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rbp_x86_64:
+ m_gpr_x86_64.regs[_REG_RBP] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rsp_x86_64:
+ m_gpr_x86_64.regs[_REG_RSP] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r8_x86_64:
+ m_gpr_x86_64.regs[_REG_R8] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r9_x86_64:
+ m_gpr_x86_64.regs[_REG_R9] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r10_x86_64:
+ m_gpr_x86_64.regs[_REG_R10] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r11_x86_64:
+ m_gpr_x86_64.regs[_REG_R11] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r12_x86_64:
+ m_gpr_x86_64.regs[_REG_R12] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r13_x86_64:
+ m_gpr_x86_64.regs[_REG_R13] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r14_x86_64:
+ m_gpr_x86_64.regs[_REG_R14] = reg_value.GetAsUInt64();
+ break;
+ case lldb_r15_x86_64:
+ m_gpr_x86_64.regs[_REG_R15] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rip_x86_64:
+ m_gpr_x86_64.regs[_REG_RIP] = reg_value.GetAsUInt64();
+ break;
+ case lldb_rflags_x86_64:
+ m_gpr_x86_64.regs[_REG_RFLAGS] = reg_value.GetAsUInt64();
+ break;
+ case lldb_cs_x86_64:
+ m_gpr_x86_64.regs[_REG_CS] = reg_value.GetAsUInt64();
+ break;
+ case lldb_fs_x86_64:
+ m_gpr_x86_64.regs[_REG_FS] = reg_value.GetAsUInt64();
+ break;
+ case lldb_gs_x86_64:
+ m_gpr_x86_64.regs[_REG_GS] = reg_value.GetAsUInt64();
+ break;
+ case lldb_ss_x86_64:
+ m_gpr_x86_64.regs[_REG_SS] = reg_value.GetAsUInt64();
+ break;
+ case lldb_ds_x86_64:
+ m_gpr_x86_64.regs[_REG_DS] = reg_value.GetAsUInt64();
+ break;
+ case lldb_es_x86_64:
+ m_gpr_x86_64.regs[_REG_ES] = reg_value.GetAsUInt64();
+ break;
+ case lldb_fctrl_x86_64:
+ m_fpr_x86_64.fxstate.fx_cw = reg_value.GetAsUInt16();
+ break;
+ case lldb_fstat_x86_64:
+ m_fpr_x86_64.fxstate.fx_sw = reg_value.GetAsUInt16();
+ break;
+ case lldb_ftag_x86_64:
+ m_fpr_x86_64.fxstate.fx_tw = reg_value.GetAsUInt8();
+ break;
+ case lldb_fop_x86_64:
+ m_fpr_x86_64.fxstate.fx_opcode = reg_value.GetAsUInt16();
+ break;
+ case lldb_fiseg_x86_64:
+ m_fpr_x86_64.fxstate.fx_ip.fa_64 = reg_value.GetAsUInt64();
+ break;
+ case lldb_fioff_x86_64:
+ m_fpr_x86_64.fxstate.fx_ip.fa_32.fa_off = reg_value.GetAsUInt32();
+ break;
+ case lldb_foseg_x86_64:
+ m_fpr_x86_64.fxstate.fx_dp.fa_64 = reg_value.GetAsUInt64();
+ break;
+ case lldb_fooff_x86_64:
+ m_fpr_x86_64.fxstate.fx_dp.fa_32.fa_off = reg_value.GetAsUInt32();
+ break;
+ case lldb_mxcsr_x86_64:
+ m_fpr_x86_64.fxstate.fx_mxcsr = reg_value.GetAsUInt32();
+ break;
+ case lldb_mxcsrmask_x86_64:
+ m_fpr_x86_64.fxstate.fx_mxcsr_mask = reg_value.GetAsUInt32();
+ break;
+ case lldb_st0_x86_64:
+ case lldb_st1_x86_64:
+ case lldb_st2_x86_64:
+ case lldb_st3_x86_64:
+ case lldb_st4_x86_64:
+ case lldb_st5_x86_64:
+ case lldb_st6_x86_64:
+ case lldb_st7_x86_64:
+ ::memcpy(&m_fpr_x86_64.fxstate.fx_87_ac[reg - lldb_st0_x86_64],
+ reg_value.GetBytes(), reg_value.GetByteSize());
+ break;
+ case lldb_mm0_x86_64:
+ case lldb_mm1_x86_64:
+ case lldb_mm2_x86_64:
+ case lldb_mm3_x86_64:
+ case lldb_mm4_x86_64:
+ case lldb_mm5_x86_64:
+ case lldb_mm6_x86_64:
+ case lldb_mm7_x86_64:
+ ::memcpy(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_mm0_x86_64],
+ reg_value.GetBytes(), reg_value.GetByteSize());
+ break;
+ case lldb_xmm0_x86_64:
+ case lldb_xmm1_x86_64:
+ case lldb_xmm2_x86_64:
+ case lldb_xmm3_x86_64:
+ case lldb_xmm4_x86_64:
+ case lldb_xmm5_x86_64:
+ case lldb_xmm6_x86_64:
+ case lldb_xmm7_x86_64:
+ case lldb_xmm8_x86_64:
+ case lldb_xmm9_x86_64:
+ case lldb_xmm10_x86_64:
+ case lldb_xmm11_x86_64:
+ case lldb_xmm12_x86_64:
+ case lldb_xmm13_x86_64:
+ case lldb_xmm14_x86_64:
+ case lldb_xmm15_x86_64:
+ ::memcpy(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_xmm0_x86_64],
+ reg_value.GetBytes(), reg_value.GetByteSize());
+ break;
+ case lldb_dr0_x86_64:
+ case lldb_dr1_x86_64:
+ case lldb_dr2_x86_64:
+ case lldb_dr3_x86_64:
+ case lldb_dr4_x86_64:
+ case lldb_dr5_x86_64:
+ case lldb_dr6_x86_64:
+ case lldb_dr7_x86_64:
+ m_dbr_x86_64.dr[reg - lldb_dr0_x86_64] = reg_value.GetAsUInt64();
+ break;
+ }
+
+ if (WriteRegisterSet(set) != 0)
+ error.SetErrorStringWithFormat("failed to write register set");
+
+ return error;
+}
+
+Status NativeRegisterContextNetBSD_x86_64::ReadAllRegisterValues(
+ lldb::DataBufferSP &data_sp) {
+ Status error;
+
+ data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
+ if (!data_sp) {
+ error.SetErrorStringWithFormat(
+ "failed to allocate DataBufferHeap instance of size %" PRIu64,
+ REG_CONTEXT_SIZE);
+ return error;
+ }
+
+ error = ReadGPR();
+ if (error.Fail())
+ return error;
+
+ uint8_t *dst = data_sp->GetBytes();
+ if (dst == nullptr) {
+ error.SetErrorStringWithFormat("DataBufferHeap instance of size %" PRIu64
+ " returned a null pointer",
+ REG_CONTEXT_SIZE);
+ return error;
+ }
+
+ ::memcpy(dst, &m_gpr_x86_64, GetRegisterInfoInterface().GetGPRSize());
+ dst += GetRegisterInfoInterface().GetGPRSize();
+
+ RegisterValue value((uint64_t)-1);
+ const RegisterInfo *reg_info =
+ GetRegisterInfoInterface().GetDynamicRegisterInfo("orig_eax");
+ if (reg_info == nullptr)
+ reg_info = GetRegisterInfoInterface().GetDynamicRegisterInfo("orig_rax");
+ return error;
+}
+
+Status NativeRegisterContextNetBSD_x86_64::WriteAllRegisterValues(
+ const lldb::DataBufferSP &data_sp) {
+ Status error;
+
+ if (!data_sp) {
+ error.SetErrorStringWithFormat(
+ "NativeRegisterContextNetBSD_x86_64::%s invalid data_sp provided",
+ __FUNCTION__);
+ return error;
+ }
+
+ if (data_sp->GetByteSize() != REG_CONTEXT_SIZE) {
+ error.SetErrorStringWithFormat(
+ "NativeRegisterContextNetBSD_x86_64::%s data_sp contained mismatched "
+ "data size, expected %" PRIu64 ", actual %" PRIu64,
+ __FUNCTION__, REG_CONTEXT_SIZE, data_sp->GetByteSize());
+ return error;
+ }
+
+ uint8_t *src = data_sp->GetBytes();
+ if (src == nullptr) {
+ error.SetErrorStringWithFormat("NativeRegisterContextNetBSD_x86_64::%s "
+ "DataBuffer::GetBytes() returned a null "
+ "pointer",
+ __FUNCTION__);
+ return error;
+ }
+ ::memcpy(&m_gpr_x86_64, src, GetRegisterInfoInterface().GetGPRSize());
+
+ error = WriteGPR();
+ if (error.Fail())
+ return error;
+ src += GetRegisterInfoInterface().GetGPRSize();
+
+ return error;
+}
+
+Status NativeRegisterContextNetBSD_x86_64::IsWatchpointHit(uint32_t wp_index,
+ bool &is_hit) {
+ if (wp_index >= NumSupportedHardwareWatchpoints())
+ return Status("Watchpoint index out of range");
+
+ RegisterValue reg_value;
+ const RegisterInfo *const reg_info = GetRegisterInfoAtIndex(lldb_dr6_x86_64);
+ Status error = ReadRegister(reg_info, reg_value);
+ if (error.Fail()) {
+ is_hit = false;
+ return error;
+ }
+
+ uint64_t status_bits = reg_value.GetAsUInt64();
+
+ is_hit = status_bits & (1 << wp_index);
+
+ return error;
+}
+
+Status NativeRegisterContextNetBSD_x86_64::GetWatchpointHitIndex(
+ uint32_t &wp_index, lldb::addr_t trap_addr) {
+ uint32_t num_hw_wps = NumSupportedHardwareWatchpoints();
+ for (wp_index = 0; wp_index < num_hw_wps; ++wp_index) {
+ bool is_hit;
+ Status error = IsWatchpointHit(wp_index, is_hit);
+ if (error.Fail()) {
+ wp_index = LLDB_INVALID_INDEX32;
+ return error;
+ } else if (is_hit) {
+ return error;
+ }
+ }
+ wp_index = LLDB_INVALID_INDEX32;
+ return Status();
+}
+
+Status NativeRegisterContextNetBSD_x86_64::IsWatchpointVacant(uint32_t wp_index,
+ bool &is_vacant) {
+ if (wp_index >= NumSupportedHardwareWatchpoints())
+ return Status("Watchpoint index out of range");
+
+ RegisterValue reg_value;
+ const RegisterInfo *const reg_info = GetRegisterInfoAtIndex(lldb_dr7_x86_64);
+ Status error = ReadRegister(reg_info, reg_value);
+ if (error.Fail()) {
+ is_vacant = false;
+ return error;
+ }
+
+ uint64_t control_bits = reg_value.GetAsUInt64();
+
+ is_vacant = !(control_bits & (1 << (2 * wp_index)));
+
+ return error;
+}
+
+Status NativeRegisterContextNetBSD_x86_64::SetHardwareWatchpointWithIndex(
+ lldb::addr_t addr, size_t size, uint32_t watch_flags, uint32_t wp_index) {
+
+ if (wp_index >= NumSupportedHardwareWatchpoints())
+ return Status("Watchpoint index out of range");
+
+ // Read only watchpoints aren't supported on x86_64. Fall back to read/write
+ // waitchpoints instead.
+ // TODO: Add logic to detect when a write happens and ignore that watchpoint
+ // hit.
+ if (watch_flags == 0x2)
+ watch_flags = 0x3;
+
+ if (watch_flags != 0x1 && watch_flags != 0x3)
+ return Status("Invalid read/write bits for watchpoint");
+
+ if (size != 1 && size != 2 && size != 4 && size != 8)
+ return Status("Invalid size for watchpoint");
+
+ bool is_vacant;
+ Status error = IsWatchpointVacant(wp_index, is_vacant);
+ if (error.Fail())
+ return error;
+ if (!is_vacant)
+ return Status("Watchpoint index not vacant");
+
+ RegisterValue reg_value;
+ const RegisterInfo *const reg_info_dr7 =
+ GetRegisterInfoAtIndex(lldb_dr7_x86_64);
+ error = ReadRegister(reg_info_dr7, reg_value);
+ if (error.Fail())
+ return error;
+
+ // for watchpoints 0, 1, 2, or 3, respectively,
+ // set bits 1, 3, 5, or 7
+ uint64_t enable_bit = 1 << (2 * wp_index);
+
+ // set bits 16-17, 20-21, 24-25, or 28-29
+ // with 0b01 for write, and 0b11 for read/write
+ uint64_t rw_bits = watch_flags << (16 + 4 * wp_index);
+
+ // set bits 18-19, 22-23, 26-27, or 30-31
+ // with 0b00, 0b01, 0b10, or 0b11
+ // for 1, 2, 8 (if supported), or 4 bytes, respectively
+ uint64_t size_bits = (size == 8 ? 0x2 : size - 1) << (18 + 4 * wp_index);
+
+ uint64_t bit_mask = (0x3 << (2 * wp_index)) | (0xF << (16 + 4 * wp_index));
+
+ uint64_t control_bits = reg_value.GetAsUInt64() & ~bit_mask;
+
+ control_bits |= enable_bit | rw_bits | size_bits;
+
+ const RegisterInfo *const reg_info_drN =
+ GetRegisterInfoAtIndex(lldb_dr0_x86_64 + wp_index);
+ error = WriteRegister(reg_info_drN, RegisterValue(addr));
+ if (error.Fail())
+ return error;
+
+ error = WriteRegister(reg_info_dr7, RegisterValue(control_bits));
+ if (error.Fail())
+ return error;
+
+ error.Clear();
+ return error;
+}
+
+bool NativeRegisterContextNetBSD_x86_64::ClearHardwareWatchpoint(
+ uint32_t wp_index) {
+ if (wp_index >= NumSupportedHardwareWatchpoints())
+ return false;
+
+ RegisterValue reg_value;
+
+ // for watchpoints 0, 1, 2, or 3, respectively,
+ // clear bits 0, 1, 2, or 3 of the debug status register (DR6)
+ const RegisterInfo *const reg_info_dr6 =
+ GetRegisterInfoAtIndex(lldb_dr6_x86_64);
+ Status error = ReadRegister(reg_info_dr6, reg_value);
+ if (error.Fail())
+ return false;
+ uint64_t bit_mask = 1 << wp_index;
+ uint64_t status_bits = reg_value.GetAsUInt64() & ~bit_mask;
+ error = WriteRegister(reg_info_dr6, RegisterValue(status_bits));
+ if (error.Fail())
+ return false;
+
+ // for watchpoints 0, 1, 2, or 3, respectively,
+ // clear bits {0-1,16-19}, {2-3,20-23}, {4-5,24-27}, or {6-7,28-31}
+ // of the debug control register (DR7)
+ const RegisterInfo *const reg_info_dr7 =
+ GetRegisterInfoAtIndex(lldb_dr7_x86_64);
+ error = ReadRegister(reg_info_dr7, reg_value);
+ if (error.Fail())
+ return false;
+ bit_mask = (0x3 << (2 * wp_index)) | (0xF << (16 + 4 * wp_index));
+ uint64_t control_bits = reg_value.GetAsUInt64() & ~bit_mask;
+ return WriteRegister(reg_info_dr7, RegisterValue(control_bits)).Success();
+}
+
+Status NativeRegisterContextNetBSD_x86_64::ClearAllHardwareWatchpoints() {
+ RegisterValue reg_value;
+
+ // clear bits {0-4} of the debug status register (DR6)
+ const RegisterInfo *const reg_info_dr6 =
+ GetRegisterInfoAtIndex(lldb_dr6_x86_64);
+ Status error = ReadRegister(reg_info_dr6, reg_value);
+ if (error.Fail())
+ return error;
+ uint64_t bit_mask = 0xF;
+ uint64_t status_bits = reg_value.GetAsUInt64() & ~bit_mask;
+ error = WriteRegister(reg_info_dr6, RegisterValue(status_bits));
+ if (error.Fail())
+ return error;
+
+ // clear bits {0-7,16-31} of the debug control register (DR7)
+ const RegisterInfo *const reg_info_dr7 =
+ GetRegisterInfoAtIndex(lldb_dr7_x86_64);
+ error = ReadRegister(reg_info_dr7, reg_value);
+ if (error.Fail())
+ return error;
+ bit_mask = 0xFF | (0xFFFF << 16);
+ uint64_t control_bits = reg_value.GetAsUInt64() & ~bit_mask;
+ return WriteRegister(reg_info_dr7, RegisterValue(control_bits));
+}
+
+uint32_t NativeRegisterContextNetBSD_x86_64::SetHardwareWatchpoint(
+ lldb::addr_t addr, size_t size, uint32_t watch_flags) {
+ Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
+ const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
+ for (uint32_t wp_index = 0; wp_index < num_hw_watchpoints; ++wp_index) {
+ bool is_vacant;
+ Status error = IsWatchpointVacant(wp_index, is_vacant);
+ if (is_vacant) {
+ error = SetHardwareWatchpointWithIndex(addr, size, watch_flags, wp_index);
+ if (error.Success())
+ return wp_index;
+ }
+ if (error.Fail() && log) {
+ log->Printf("NativeRegisterContextNetBSD_x86_64::%s Error: %s",
+ __FUNCTION__, error.AsCString());
+ }
+ }
+ return LLDB_INVALID_INDEX32;
+}
+
+lldb::addr_t
+NativeRegisterContextNetBSD_x86_64::GetWatchpointAddress(uint32_t wp_index) {
+ if (wp_index >= NumSupportedHardwareWatchpoints())
+ return LLDB_INVALID_ADDRESS;
+ RegisterValue reg_value;
+ const RegisterInfo *const reg_info_drN =
+ GetRegisterInfoAtIndex(lldb_dr0_x86_64 + wp_index);
+ if (ReadRegister(reg_info_drN, reg_value).Fail())
+ return LLDB_INVALID_ADDRESS;
+ return reg_value.GetAsUInt64();
+}
+
+uint32_t NativeRegisterContextNetBSD_x86_64::NumSupportedHardwareWatchpoints() {
+ // Available debug address registers: dr0, dr1, dr2, dr3
+ return 4;
+}
+
+#endif // defined(__x86_64__)
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
new file mode 100644
index 0000000..5f5a6a0
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
@@ -0,0 +1,96 @@
+//===-- NativeRegisterContextNetBSD_x86_64.h --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(__x86_64__)
+
+#ifndef lldb_NativeRegisterContextNetBSD_x86_64_h
+#define lldb_NativeRegisterContextNetBSD_x86_64_h
+
+// clang-format off
+#include <sys/param.h>
+#include <sys/types.h>
+#include <machine/reg.h>
+// clang-format on
+
+#include "Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h"
+#include "Plugins/Process/Utility/RegisterContext_x86.h"
+#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
+
+namespace lldb_private {
+namespace process_netbsd {
+
+class NativeProcessNetBSD;
+
+class NativeRegisterContextNetBSD_x86_64 : public NativeRegisterContextNetBSD {
+public:
+ NativeRegisterContextNetBSD_x86_64(const ArchSpec &target_arch,
+ NativeThreadProtocol &native_thread,
+ uint32_t concrete_frame_idx);
+ uint32_t GetRegisterSetCount() const override;
+
+ const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
+
+ Status ReadRegister(const RegisterInfo *reg_info,
+ RegisterValue &reg_value) override;
+
+ Status WriteRegister(const RegisterInfo *reg_info,
+ const RegisterValue &reg_value) override;
+
+ Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
+
+ Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
+
+ Status IsWatchpointHit(uint32_t wp_index, bool &is_hit) override;
+
+ Status GetWatchpointHitIndex(uint32_t &wp_index,
+ lldb::addr_t trap_addr) override;
+
+ Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant) override;
+
+ bool ClearHardwareWatchpoint(uint32_t wp_index) override;
+
+ Status ClearAllHardwareWatchpoints() override;
+
+ Status SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
+ uint32_t watch_flags,
+ uint32_t wp_index);
+
+ uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
+ uint32_t watch_flags) override;
+
+ lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
+
+ uint32_t NumSupportedHardwareWatchpoints() override;
+
+protected:
+ void *GetGPRBuffer() override { return &m_gpr_x86_64; }
+ void *GetFPRBuffer() override { return &m_fpr_x86_64; }
+ void *GetDBRBuffer() override { return &m_dbr_x86_64; }
+
+private:
+ // Private member types.
+ enum { GPRegSet, FPRegSet, DBRegSet };
+
+ // Private member variables.
+ struct reg m_gpr_x86_64;
+ struct fpreg m_fpr_x86_64;
+ struct dbreg m_dbr_x86_64;
+
+ int GetSetForNativeRegNum(int reg_num) const;
+
+ int ReadRegisterSet(uint32_t set);
+ int WriteRegisterSet(uint32_t set);
+};
+
+} // namespace process_netbsd
+} // namespace lldb_private
+
+#endif // #ifndef lldb_NativeRegisterContextNetBSD_x86_64_h
+
+#endif // defined(__x86_64__)
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
new file mode 100644
index 0000000..1fd7400
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -0,0 +1,218 @@
+//===-- NativeThreadNetBSD.cpp -------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "NativeThreadNetBSD.h"
+#include "NativeRegisterContextNetBSD.h"
+
+#include "NativeProcessNetBSD.h"
+
+#include "Plugins/Process/POSIX/CrashReason.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Core/RegisterValue.h"
+#include "lldb/Core/State.h"
+#include "lldb/Utility/LLDBAssert.h"
+
+#include <sstream>
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_netbsd;
+
+NativeThreadNetBSD::NativeThreadNetBSD(NativeProcessNetBSD &process,
+ lldb::tid_t tid)
+ : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
+ m_stop_info(), m_reg_context_sp(), m_stop_description() {}
+
+void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo,
+ const siginfo_t *info) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+ LLDB_LOG(log, "tid = {0} in called with signal {1}", GetID(), signo);
+
+ SetStopped();
+
+ m_stop_info.reason = StopReason::eStopReasonSignal;
+ m_stop_info.details.signal.signo = signo;
+
+ m_stop_description.clear();
+ if (info) {
+ switch (signo) {
+ case SIGSEGV:
+ case SIGBUS:
+ case SIGFPE:
+ case SIGILL:
+ const auto reason = GetCrashReason(*info);
+ m_stop_description = GetCrashReasonString(reason, *info);
+ break;
+ }
+ }
+}
+
+void NativeThreadNetBSD::SetStoppedByBreakpoint() {
+ SetStopped();
+ m_stop_info.reason = StopReason::eStopReasonBreakpoint;
+ m_stop_info.details.signal.signo = SIGTRAP;
+}
+
+void NativeThreadNetBSD::SetStoppedByTrace() {
+ SetStopped();
+ m_stop_info.reason = StopReason::eStopReasonTrace;
+ m_stop_info.details.signal.signo = SIGTRAP;
+}
+
+void NativeThreadNetBSD::SetStoppedByExec() {
+ SetStopped();
+ m_stop_info.reason = StopReason::eStopReasonExec;
+ m_stop_info.details.signal.signo = SIGTRAP;
+}
+
+void NativeThreadNetBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
+ SetStopped();
+
+ lldbassert(wp_index != LLDB_INVALID_INDEX32 && "wp_index cannot be invalid");
+
+ std::ostringstream ostr;
+ ostr << GetRegisterContext()->GetWatchpointAddress(wp_index) << " ";
+ ostr << wp_index;
+
+ ostr << " " << GetRegisterContext()->GetWatchpointHitAddress(wp_index);
+
+ m_stop_description = ostr.str();
+
+ m_stop_info.reason = StopReason::eStopReasonWatchpoint;
+ m_stop_info.details.signal.signo = SIGTRAP;
+}
+
+void NativeThreadNetBSD::SetStopped() {
+ const StateType new_state = StateType::eStateStopped;
+ m_state = new_state;
+ m_stop_description.clear();
+}
+
+void NativeThreadNetBSD::SetRunning() {
+ m_state = StateType::eStateRunning;
+ m_stop_info.reason = StopReason::eStopReasonNone;
+}
+
+void NativeThreadNetBSD::SetStepping() {
+ m_state = StateType::eStateStepping;
+ m_stop_info.reason = StopReason::eStopReasonNone;
+}
+
+std::string NativeThreadNetBSD::GetName() { return std::string(""); }
+
+lldb::StateType NativeThreadNetBSD::GetState() { return m_state; }
+
+bool NativeThreadNetBSD::GetStopReason(ThreadStopInfo &stop_info,
+ std::string &description) {
+ Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
+
+ description.clear();
+
+ switch (m_state) {
+ case eStateStopped:
+ case eStateCrashed:
+ case eStateExited:
+ case eStateSuspended:
+ case eStateUnloaded:
+ stop_info = m_stop_info;
+ description = m_stop_description;
+
+ return true;
+
+ case eStateInvalid:
+ case eStateConnected:
+ case eStateAttaching:
+ case eStateLaunching:
+ case eStateRunning:
+ case eStateStepping:
+ case eStateDetached:
+ LLDB_LOG(log, "tid = {0} in state {1} cannot answer stop reason", GetID(),
+ StateAsCString(m_state));
+ return false;
+ }
+ llvm_unreachable("unhandled StateType!");
+}
+
+NativeRegisterContextSP NativeThreadNetBSD::GetRegisterContext() {
+ // Return the register context if we already created it.
+ if (m_reg_context_sp)
+ return m_reg_context_sp;
+
+ ArchSpec target_arch;
+ if (!m_process.GetArchitecture(target_arch))
+ return NativeRegisterContextSP();
+
+ const uint32_t concrete_frame_idx = 0;
+ m_reg_context_sp.reset(
+ NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(
+ target_arch, *this, concrete_frame_idx));
+
+ return m_reg_context_sp;
+}
+
+Status NativeThreadNetBSD::SetWatchpoint(lldb::addr_t addr, size_t size,
+ uint32_t watch_flags, bool hardware) {
+ if (!hardware)
+ return Status("not implemented");
+ if (m_state == eStateLaunching)
+ return Status();
+ Status error = RemoveWatchpoint(addr);
+ if (error.Fail())
+ return error;
+ NativeRegisterContextSP reg_ctx = GetRegisterContext();
+ uint32_t wp_index = reg_ctx->SetHardwareWatchpoint(addr, size, watch_flags);
+ if (wp_index == LLDB_INVALID_INDEX32)
+ return Status("Setting hardware watchpoint failed.");
+ m_watchpoint_index_map.insert({addr, wp_index});
+ return Status();
+}
+
+Status NativeThreadNetBSD::RemoveWatchpoint(lldb::addr_t addr) {
+ auto wp = m_watchpoint_index_map.find(addr);
+ if (wp == m_watchpoint_index_map.end())
+ return Status();
+ uint32_t wp_index = wp->second;
+ m_watchpoint_index_map.erase(wp);
+ if (GetRegisterContext()->ClearHardwareWatchpoint(wp_index))
+ return Status();
+ return Status("Clearing hardware watchpoint failed.");
+}
+
+Status NativeThreadNetBSD::SetHardwareBreakpoint(lldb::addr_t addr,
+ size_t size) {
+ if (m_state == eStateLaunching)
+ return Status();
+
+ Status error = RemoveHardwareBreakpoint(addr);
+ if (error.Fail())
+ return error;
+
+ NativeRegisterContextSP reg_ctx = GetRegisterContext();
+ uint32_t bp_index = reg_ctx->SetHardwareBreakpoint(addr, size);
+
+ if (bp_index == LLDB_INVALID_INDEX32)
+ return Status("Setting hardware breakpoint failed.");
+
+ m_hw_break_index_map.insert({addr, bp_index});
+ return Status();
+}
+
+Status NativeThreadNetBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) {
+ auto bp = m_hw_break_index_map.find(addr);
+ if (bp == m_hw_break_index_map.end())
+ return Status();
+
+ uint32_t bp_index = bp->second;
+ if (GetRegisterContext()->ClearHardwareBreakpoint(bp_index)) {
+ m_hw_break_index_map.erase(bp);
+ return Status();
+ }
+
+ return Status("Clearing hardware breakpoint failed.");
+}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
new file mode 100644
index 0000000..1e3f587
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
@@ -0,0 +1,81 @@
+//===-- NativeThreadNetBSD.h ---------------------------------- -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_NativeThreadNetBSD_H_
+#define liblldb_NativeThreadNetBSD_H_
+
+#include "lldb/Host/common/NativeThreadProtocol.h"
+
+#include <csignal>
+#include <map>
+#include <string>
+
+namespace lldb_private {
+namespace process_netbsd {
+
+class NativeProcessNetBSD;
+
+class NativeThreadNetBSD : public NativeThreadProtocol {
+ friend class NativeProcessNetBSD;
+
+public:
+ NativeThreadNetBSD(NativeProcessNetBSD &process, lldb::tid_t tid);
+
+ // ---------------------------------------------------------------------
+ // NativeThreadProtocol Interface
+ // ---------------------------------------------------------------------
+ std::string GetName() override;
+
+ lldb::StateType GetState() override;
+
+ bool GetStopReason(ThreadStopInfo &stop_info,
+ std::string &description) override;
+
+ NativeRegisterContextSP GetRegisterContext() override;
+
+ Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
+ bool hardware) override;
+
+ Status RemoveWatchpoint(lldb::addr_t addr) override;
+
+ Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
+
+ Status RemoveHardwareBreakpoint(lldb::addr_t addr) override;
+
+private:
+ // ---------------------------------------------------------------------
+ // Interface for friend classes
+ // ---------------------------------------------------------------------
+
+ void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
+ void SetStoppedByBreakpoint();
+ void SetStoppedByTrace();
+ void SetStoppedByExec();
+ void SetStoppedByWatchpoint(uint32_t wp_index);
+ void SetStopped();
+ void SetRunning();
+ void SetStepping();
+
+ // ---------------------------------------------------------------------
+ // Member Variables
+ // ---------------------------------------------------------------------
+ lldb::StateType m_state;
+ ThreadStopInfo m_stop_info;
+ NativeRegisterContextSP m_reg_context_sp;
+ std::string m_stop_description;
+ using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
+ WatchpointIndexMap m_watchpoint_index_map;
+ WatchpointIndexMap m_hw_break_index_map;
+};
+
+typedef std::shared_ptr<NativeThreadNetBSD> NativeThreadNetBSDSP;
+} // namespace process_netbsd
+} // namespace lldb_private
+
+#endif // #ifndef liblldb_NativeThreadNetBSD_H_
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/CrashReason.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
index 77d6e28..864418c 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
@@ -62,7 +62,6 @@ CrashReason GetCrashReasonForSIGSEGV(const siginfo_t &info) {
return CrashReason::eBoundViolation;
}
- assert(false && "unexpected si_code for SIGSEGV");
return CrashReason::eInvalidCrashReason;
}
@@ -88,7 +87,6 @@ CrashReason GetCrashReasonForSIGILL(const siginfo_t &info) {
return CrashReason::eInternalStackError;
}
- assert(false && "unexpected si_code for SIGILL");
return CrashReason::eInvalidCrashReason;
}
@@ -114,7 +112,6 @@ CrashReason GetCrashReasonForSIGFPE(const siginfo_t &info) {
return CrashReason::eFloatSubscriptRange;
}
- assert(false && "unexpected si_code for SIGFPE");
return CrashReason::eInvalidCrashReason;
}
@@ -130,7 +127,6 @@ CrashReason GetCrashReasonForSIGBUS(const siginfo_t &info) {
return CrashReason::eHardwareError;
}
- assert(false && "unexpected si_code for SIGBUS");
return CrashReason::eInvalidCrashReason;
}
}
@@ -158,7 +154,7 @@ std::string GetCrashReasonString(CrashReason reason, lldb::addr_t fault_addr) {
switch (reason) {
default:
- assert(false && "invalid CrashReason");
+ str = "unknown crash reason";
break;
case CrashReason::eInvalidAddress:
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
index 9ced11c..f1beb0f 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
@@ -10,188 +10,23 @@
#include "ProcessPOSIXLog.h"
-#include <mutex>
+#include "llvm/Support/Threading.h"
-#include "lldb/Core/StreamFile.h"
-#include "lldb/Interpreter/Args.h"
-
-#include "ProcessPOSIXLog.h"
-
-using namespace lldb;
using namespace lldb_private;
-// We want to avoid global constructors where code needs to be run so here we
-// control access to our static g_log_sp by hiding it in a singleton function
-// that will construct the static g_log_sp the first time this function is
-// called.
-static bool g_log_enabled = false;
-static Log *g_log = NULL;
-static Log *GetLog() {
- if (!g_log_enabled)
- return NULL;
- return g_log;
-}
+static constexpr Log::Category g_categories[] = {
+ {{"break"}, {"log breakpoints"}, POSIX_LOG_BREAKPOINTS},
+ {{"memory"}, {"log memory reads and writes"}, POSIX_LOG_MEMORY},
+ {{"process"}, {"log process events and activities"}, POSIX_LOG_PROCESS},
+ {{"ptrace"}, {"log all calls to ptrace"}, POSIX_LOG_PTRACE},
+ {{"registers"}, {"log register read/writes"}, POSIX_LOG_REGISTERS},
+ {{"thread"}, {"log thread events and activities"}, POSIX_LOG_THREAD},
+ {{"watch"}, {"log watchpoint related activities"}, POSIX_LOG_WATCHPOINTS},
+};
-void ProcessPOSIXLog::Initialize(ConstString name) {
- static std::once_flag g_once_flag;
-
- std::call_once(g_once_flag, [name]() {
- Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories};
-
- Log::RegisterLogChannel(name, log_callbacks);
- RegisterPluginName(name);
- });
-}
+Log::Channel ProcessPOSIXLog::g_channel(g_categories, POSIX_LOG_DEFAULT);
-Log *ProcessPOSIXLog::GetLogIfAllCategoriesSet(uint32_t mask) {
- Log *log(GetLog());
- if (log && mask) {
- uint32_t log_mask = log->GetMask().Get();
- if ((log_mask & mask) != mask)
- return NULL;
- }
- return log;
+void ProcessPOSIXLog::Initialize() {
+ static llvm::once_flag g_once_flag;
+ llvm::call_once(g_once_flag, []() { Log::Register("posix", g_channel); });
}
-
-static uint32_t GetFlagBits(const char *arg) {
- if (::strcasecmp(arg, "all") == 0)
- return POSIX_LOG_ALL;
- else if (::strcasecmp(arg, "async") == 0)
- return POSIX_LOG_ASYNC;
- else if (::strncasecmp(arg, "break", 5) == 0)
- return POSIX_LOG_BREAKPOINTS;
- else if (::strncasecmp(arg, "comm", 4) == 0)
- return POSIX_LOG_COMM;
- else if (::strcasecmp(arg, "default") == 0)
- return POSIX_LOG_DEFAULT;
- else if (::strcasecmp(arg, "packets") == 0)
- return POSIX_LOG_PACKETS;
- else if (::strcasecmp(arg, "memory") == 0)
- return POSIX_LOG_MEMORY;
- else if (::strcasecmp(arg, "data-short") == 0)
- return POSIX_LOG_MEMORY_DATA_SHORT;
- else if (::strcasecmp(arg, "data-long") == 0)
- return POSIX_LOG_MEMORY_DATA_LONG;
- else if (::strcasecmp(arg, "process") == 0)
- return POSIX_LOG_PROCESS;
- else if (::strcasecmp(arg, "ptrace") == 0)
- return POSIX_LOG_PTRACE;
- else if (::strcasecmp(arg, "registers") == 0)
- return POSIX_LOG_REGISTERS;
- else if (::strcasecmp(arg, "step") == 0)
- return POSIX_LOG_STEP;
- else if (::strcasecmp(arg, "thread") == 0)
- return POSIX_LOG_THREAD;
- else if (::strcasecmp(arg, "verbose") == 0)
- return POSIX_LOG_VERBOSE;
- else if (::strncasecmp(arg, "watch", 5) == 0)
- return POSIX_LOG_WATCHPOINTS;
- return 0;
-}
-
-void ProcessPOSIXLog::DisableLog(const char **args, Stream *feedback_strm) {
- Log *log(GetLog());
- if (log) {
- uint32_t flag_bits = 0;
-
- flag_bits = log->GetMask().Get();
- for (; args && args[0]; args++) {
- const char *arg = args[0];
- uint32_t bits = GetFlagBits(arg);
-
- if (bits) {
- flag_bits &= ~bits;
- } else {
- feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
- ListLogCategories(feedback_strm);
- }
- }
-
- log->GetMask().Reset(flag_bits);
- if (flag_bits == 0)
- g_log_enabled = false;
- }
-
- return;
-}
-
-Log *ProcessPOSIXLog::EnableLog(StreamSP &log_stream_sp, uint32_t log_options,
- const char **args, Stream *feedback_strm) {
- // Try see if there already is a log - that way we can reuse its settings.
- // We could reuse the log in toto, but we don't know that the stream is the
- // same.
- uint32_t flag_bits = 0;
- if (g_log)
- flag_bits = g_log->GetMask().Get();
-
- // Now make a new log with this stream if one was provided
- if (log_stream_sp) {
- if (g_log)
- g_log->SetStream(log_stream_sp);
- else
- g_log = new Log(log_stream_sp);
- }
-
- if (g_log) {
- bool got_unknown_category = false;
- for (; args && args[0]; args++) {
- const char *arg = args[0];
- uint32_t bits = GetFlagBits(arg);
-
- if (bits) {
- flag_bits |= bits;
- } else {
- feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
- if (got_unknown_category == false) {
- got_unknown_category = true;
- ListLogCategories(feedback_strm);
- }
- }
- }
- if (flag_bits == 0)
- flag_bits = POSIX_LOG_DEFAULT;
- g_log->GetMask().Reset(flag_bits);
- g_log->GetOptions().Reset(log_options);
- g_log_enabled = true;
- }
- return g_log;
-}
-
-void ProcessPOSIXLog::ListLogCategories(Stream *strm) {
- strm->Printf(
- "Logging categories for '%s':\n"
- " all - turn on all available logging categories\n"
- " async - log asynchronous activity\n"
- " break - log breakpoints\n"
- " communication - log communication activity\n"
- " default - enable the default set of logging categories for liblldb\n"
- " packets - log gdb remote packets\n"
- " memory - log memory reads and writes\n"
- " data-short - log memory bytes for memory reads and writes for short "
- "transactions only\n"
- " data-long - log memory bytes for memory reads and writes for all "
- "transactions\n"
- " process - log process events and activities\n"
-#ifndef LLDB_CONFIGURATION_BUILDANDINTEGRATION
- " ptrace - log all calls to ptrace\n"
-#endif
- " registers - log register read/writes\n"
- " thread - log thread events and activities\n"
- " step - log step related activities\n"
- " verbose - enable verbose logging\n"
- " watch - log watchpoint related activities\n",
- ProcessPOSIXLog::m_pluginname);
-}
-
-void ProcessPOSIXLog::LogIf(uint32_t mask, const char *format, ...) {
- Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(mask));
- if (log) {
- va_list args;
- va_start(args, format);
- log->VAPrintf(format, args);
- va_end(args);
- }
-}
-
-int ProcessPOSIXLog::m_nestinglevel;
-const char *ProcessPOSIXLog::m_pluginname = "";
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h b/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
index 7d187da..1340135 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
@@ -16,87 +16,29 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/Log.h"
+#include "lldb/Utility/Log.h"
-#define POSIX_LOG_VERBOSE (1u << 0)
#define POSIX_LOG_PROCESS (1u << 1)
#define POSIX_LOG_THREAD (1u << 2)
-#define POSIX_LOG_PACKETS (1u << 3)
#define POSIX_LOG_MEMORY (1u << 4) // Log memory reads/writes calls
-#define POSIX_LOG_MEMORY_DATA_SHORT \
- (1u << 5) // Log short memory reads/writes bytes
-#define POSIX_LOG_MEMORY_DATA_LONG \
- (1u << 6) // Log all memory reads/writes bytes
+#define POSIX_LOG_PTRACE (1u << 5)
+#define POSIX_LOG_REGISTERS (1u << 6)
#define POSIX_LOG_BREAKPOINTS (1u << 7)
#define POSIX_LOG_WATCHPOINTS (1u << 8)
-#define POSIX_LOG_STEP (1u << 9)
-#define POSIX_LOG_COMM (1u << 10)
-#define POSIX_LOG_ASYNC (1u << 11)
-#define POSIX_LOG_PTRACE (1u << 12)
-#define POSIX_LOG_REGISTERS (1u << 13)
#define POSIX_LOG_ALL (UINT32_MAX)
-#define POSIX_LOG_DEFAULT POSIX_LOG_PACKETS
-
-// The size which determines "short memory reads/writes".
-#define POSIX_LOG_MEMORY_SHORT_BYTES (4 * sizeof(ptrdiff_t))
+#define POSIX_LOG_DEFAULT POSIX_LOG_PROCESS
+namespace lldb_private {
class ProcessPOSIXLog {
- static int m_nestinglevel;
- static const char *m_pluginname;
+ static Log::Channel g_channel;
public:
- // ---------------------------------------------------------------------
- // Public Static Methods
- // ---------------------------------------------------------------------
- static void Initialize(lldb_private::ConstString name);
-
- static void RegisterPluginName(const char *pluginName) {
- m_pluginname = pluginName;
- }
-
- static void RegisterPluginName(lldb_private::ConstString pluginName) {
- m_pluginname = pluginName.GetCString();
- }
-
- static lldb_private::Log *GetLogIfAllCategoriesSet(uint32_t mask = 0);
-
- static void DisableLog(const char **args,
- lldb_private::Stream *feedback_strm);
-
- static lldb_private::Log *EnableLog(lldb::StreamSP &log_stream_sp,
- uint32_t log_options, const char **args,
- lldb_private::Stream *feedback_strm);
-
- static void ListLogCategories(lldb_private::Stream *strm);
-
- static void LogIf(uint32_t mask, const char *format, ...);
-
- // The following functions can be used to enable the client to limit
- // logging to only the top level function calls. This is useful for
- // recursive functions. FIXME: not thread safe!
- // Example:
- // void NestingFunc() {
- // LogSP log
- // (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_ALL));
- // if (log)
- // {
- // ProcessPOSIXLog::IncNestLevel();
- // if (ProcessPOSIXLog::AtTopNestLevel())
- // log->Print(msg);
- // }
- // NestingFunc();
- // if (log)
- // ProcessPOSIXLog::DecNestLevel();
- // }
-
- static bool AtTopNestLevel() { return m_nestinglevel == 1; }
-
- static void IncNestLevel() { ++m_nestinglevel; }
+ static void Initialize();
- static void DecNestLevel() {
- --m_nestinglevel;
- assert(m_nestinglevel >= 0);
+ static Log *GetLogIfAllCategoriesSet(uint32_t mask) {
+ return g_channel.GetLogIfAll(mask);
}
};
+}
#endif // liblldb_ProcessPOSIXLog_h_
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
index 75f7251..1a4511a 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -14,12 +14,12 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StructuredData.h"
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/StringExtractor.h"
+#include "lldb/Utility/StructuredData.h"
using namespace lldb;
using namespace lldb_private;
@@ -48,10 +48,10 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
if (dict.GetValueForKeyAsArray("sets", sets)) {
const uint32_t num_sets = sets->GetSize();
for (uint32_t i = 0; i < num_sets; ++i) {
- std::string set_name_str;
+ llvm::StringRef set_name_str;
ConstString set_name;
if (sets->GetItemAtIndexAsString(i, set_name_str))
- set_name.SetCString(set_name_str.c_str());
+ set_name.SetString(set_name_str);
if (set_name) {
RegisterSet new_set = {set_name.AsCString(), NULL, 0, NULL};
m_sets.push_back(new_set);
@@ -115,7 +115,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
// expression
// we can calculate the offset
bool success = false;
- std::string slice_str;
+ llvm::StringRef slice_str;
if (reg_info_dict->GetValueForKeyAsString("slice", slice_str, nullptr)) {
// Slices use the following format:
// REGNAME[MSBIT:LSBIT]
@@ -131,9 +131,9 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
llvm::StringRef reg_name_str;
std::string msbit_str;
std::string lsbit_str;
- if (regex_match.GetMatchAtIndex(slice_str.c_str(), 1, reg_name_str) &&
- regex_match.GetMatchAtIndex(slice_str.c_str(), 2, msbit_str) &&
- regex_match.GetMatchAtIndex(slice_str.c_str(), 3, lsbit_str)) {
+ if (regex_match.GetMatchAtIndex(slice_str, 1, reg_name_str) &&
+ regex_match.GetMatchAtIndex(slice_str, 2, msbit_str) &&
+ regex_match.GetMatchAtIndex(slice_str, 3, lsbit_str)) {
const uint32_t msbit =
StringConvert::ToUInt32(msbit_str.c_str(), UINT32_MAX);
const uint32_t lsbit =
@@ -269,18 +269,17 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
reg_info.byte_size = bitsize / 8;
- std::string dwarf_opcode_string;
+ llvm::StringRef dwarf_opcode_string;
if (reg_info_dict->GetValueForKeyAsString("dynamic_size_dwarf_expr_bytes",
dwarf_opcode_string)) {
- reg_info.dynamic_size_dwarf_len = dwarf_opcode_string.length() / 2;
+ reg_info.dynamic_size_dwarf_len = dwarf_opcode_string.size() / 2;
assert(reg_info.dynamic_size_dwarf_len > 0);
std::vector<uint8_t> dwarf_opcode_bytes(reg_info.dynamic_size_dwarf_len);
uint32_t j;
- StringExtractor opcode_extractor;
- // Swap "dwarf_opcode_string" over into "opcode_extractor"
- opcode_extractor.GetStringRef().swap(dwarf_opcode_string);
+ StringExtractor opcode_extractor(dwarf_opcode_string);
uint32_t ret_val = opcode_extractor.GetHexBytesAvail(dwarf_opcode_bytes);
+ UNUSED_IF_ASSERT_DISABLED(ret_val);
assert(ret_val == reg_info.dynamic_size_dwarf_len);
for (j = 0; j < reg_info.dynamic_size_dwarf_len; ++j)
@@ -289,9 +288,9 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
reg_info.dynamic_size_dwarf_expr_bytes = m_dynamic_reg_size_map[i].data();
}
- std::string format_str;
+ llvm::StringRef format_str;
if (reg_info_dict->GetValueForKeyAsString("format", format_str, nullptr)) {
- if (Args::StringToFormat(format_str.c_str(), reg_info.format, NULL)
+ if (Args::StringToFormat(format_str.str().c_str(), reg_info.format, NULL)
.Fail()) {
Clear();
printf("error: invalid 'format' value in register dictionary\n");
@@ -303,7 +302,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
eFormatHex);
}
- std::string encoding_str;
+ llvm::StringRef encoding_str;
if (reg_info_dict->GetValueForKeyAsString("encoding", encoding_str))
reg_info.encoding = Args::StringToEncoding(encoding_str, eEncodingUint);
else
@@ -333,7 +332,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
reg_info.kinds[lldb::eRegisterKindEHFrame] = eh_frame_regno;
reg_info_dict->GetValueForKeyAsInteger(
"dwarf", reg_info.kinds[lldb::eRegisterKindDWARF], LLDB_INVALID_REGNUM);
- std::string generic_str;
+ llvm::StringRef generic_str;
if (reg_info_dict->GetValueForKeyAsString("generic", generic_str))
reg_info.kinds[lldb::eRegisterKindGeneric] =
Args::StringToGenericRegister(generic_str);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
index e5c22fe..228acfb 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.h
@@ -17,8 +17,8 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/ConstString.h"
-#include "lldb/Core/StructuredData.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/StructuredData.h"
#include "lldb/lldb-private.h"
class DynamicRegisterInfo {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.cpp
index d27a7b0..4983dcd 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.cpp
@@ -13,9 +13,9 @@
#include "Plugins/Process/Utility/HistoryUnwind.h"
#include "Plugins/Process/Utility/RegisterContextHistory.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrameList.h"
+#include "lldb/Utility/Log.h"
using namespace lldb;
using namespace lldb_private;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.h
index 1a4898a..363ba26 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/HistoryThread.h
@@ -18,11 +18,11 @@
// Project includes
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/Event.h"
-#include "lldb/Core/UserID.h"
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/StackFrameList.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/UserID.h"
#include "lldb/lldb-private.h"
namespace lldb_private {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
index 4e1f10c..5c51a03 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -64,7 +64,7 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTrapExceptions(false);
- addr_t prot_arg, flags_arg = 0;
+ addr_t prot_arg;
if (prot == eMmapProtNone)
prot_arg = PROT_NONE;
else {
@@ -77,11 +77,6 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
prot_arg |= PROT_WRITE;
}
- const ArchSpec arch = process->GetTarget().GetArchitecture();
- flags_arg =
- process->GetTarget().GetPlatform()->ConvertMmapFlagsToPlatform(arch,
- flags);
-
AddressRange mmap_range;
if (sc.GetAddressRange(range_scope, 0, use_inline_block_range,
mmap_range)) {
@@ -89,7 +84,10 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
process->GetTarget().GetScratchClangASTContext();
CompilerType clang_void_ptr_type =
clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
- lldb::addr_t args[] = {addr, length, prot_arg, flags_arg, fd, offset};
+ const ArchSpec arch = process->GetTarget().GetArchitecture();
+ MmapArgList args =
+ process->GetTarget().GetPlatform()->GetMmapArgumentList(
+ arch, addr, length, prot_arg, flags, fd, offset);
lldb::ThreadPlanSP call_plan_sp(
new ThreadPlanCallFunction(*thread, mmap_range.GetBaseAddress(),
clang_void_ptr_type, args, options));
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp
new file mode 100644
index 0000000..0b18143
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.cpp
@@ -0,0 +1,43 @@
+//===-- NativeRegisterContextRegisterInfo.cpp -------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "NativeRegisterContextRegisterInfo.h"
+#include "lldb/lldb-private-forward.h"
+#include "lldb/lldb-types.h"
+
+using namespace lldb_private;
+
+NativeRegisterContextRegisterInfo::NativeRegisterContextRegisterInfo(
+ NativeThreadProtocol &thread, uint32_t concrete_frame_idx,
+ RegisterInfoInterface *register_info_interface)
+ : NativeRegisterContext(thread, concrete_frame_idx),
+ m_register_info_interface_up(register_info_interface) {
+ assert(register_info_interface && "null register_info_interface");
+}
+
+uint32_t NativeRegisterContextRegisterInfo::GetRegisterCount() const {
+ return m_register_info_interface_up->GetRegisterCount();
+}
+
+uint32_t NativeRegisterContextRegisterInfo::GetUserRegisterCount() const {
+ return m_register_info_interface_up->GetUserRegisterCount();
+}
+
+const RegisterInfo *NativeRegisterContextRegisterInfo::GetRegisterInfoAtIndex(
+ uint32_t reg_index) const {
+ if (reg_index <= GetRegisterCount())
+ return m_register_info_interface_up->GetRegisterInfo() + reg_index;
+ else
+ return nullptr;
+}
+
+const RegisterInfoInterface &
+NativeRegisterContextRegisterInfo::GetRegisterInfoInterface() const {
+ return *m_register_info_interface_up;
+}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h
new file mode 100644
index 0000000..c1b5974
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h
@@ -0,0 +1,41 @@
+//===-- NativeRegisterContextRegisterInfo.h ---------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_PLUGINS_PROCESS_UTIILTY_NATIVE_REGISTER_CONTEXT_REGISTER_INFO
+#define LLDB_PLUGINS_PROCESS_UTIILTY_NATIVE_REGISTER_CONTEXT_REGISTER_INFO
+
+#include <memory>
+
+#include "RegisterInfoInterface.h"
+#include "lldb/Host/common/NativeRegisterContext.h"
+
+namespace lldb_private {
+class NativeRegisterContextRegisterInfo : public NativeRegisterContext {
+public:
+ ///
+ /// Construct a NativeRegisterContextRegisterInfo, taking ownership
+ /// of the register_info_interface pointer.
+ ///
+ NativeRegisterContextRegisterInfo(
+ NativeThreadProtocol &thread, uint32_t concrete_frame_idx,
+ RegisterInfoInterface *register_info_interface);
+
+ uint32_t GetRegisterCount() const override;
+
+ uint32_t GetUserRegisterCount() const override;
+
+ const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg_index) const override;
+
+ const RegisterInfoInterface &GetRegisterInfoInterface() const;
+
+private:
+ std::unique_ptr<RegisterInfoInterface> m_register_info_interface_up;
+};
+}
+#endif
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NetBSDSignals.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NetBSDSignals.cpp
index 9b9db51..7ed7189 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NetBSDSignals.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/NetBSDSignals.cpp
@@ -24,7 +24,35 @@ void NetBSDSignals::Reset() {
// ===================================================
AddSignal(32, "SIGPWR", false, true, true,
"power fail/restart (not reset when caught)");
-#ifdef SIGRTMIN /* SIGRTMAX */
- /* Kernel only; not exposed to userland yet */
-#endif
+ AddSignal(33, "SIGRTMIN", false, false, false, "real time signal 0");
+ AddSignal(34, "SIGRTMIN+1", false, false, false, "real time signal 1");
+ AddSignal(35, "SIGRTMIN+2", false, false, false, "real time signal 2");
+ AddSignal(36, "SIGRTMIN+3", false, false, false, "real time signal 3");
+ AddSignal(37, "SIGRTMIN+4", false, false, false, "real time signal 4");
+ AddSignal(38, "SIGRTMIN+5", false, false, false, "real time signal 5");
+ AddSignal(39, "SIGRTMIN+6", false, false, false, "real time signal 6");
+ AddSignal(40, "SIGRTMIN+7", false, false, false, "real time signal 7");
+ AddSignal(41, "SIGRTMIN+8", false, false, false, "real time signal 8");
+ AddSignal(42, "SIGRTMIN+9", false, false, false, "real time signal 9");
+ AddSignal(43, "SIGRTMIN+10", false, false, false, "real time signal 10");
+ AddSignal(44, "SIGRTMIN+11", false, false, false, "real time signal 11");
+ AddSignal(45, "SIGRTMIN+12", false, false, false, "real time signal 12");
+ AddSignal(46, "SIGRTMIN+13", false, false, false, "real time signal 13");
+ AddSignal(47, "SIGRTMIN+14", false, false, false, "real time signal 14");
+ AddSignal(48, "SIGRTMIN+15", false, false, false, "real time signal 15");
+ AddSignal(49, "SIGRTMIN-14", false, false, false, "real time signal 16");
+ AddSignal(50, "SIGRTMAX-13", false, false, false, "real time signal 17");
+ AddSignal(51, "SIGRTMAX-12", false, false, false, "real time signal 18");
+ AddSignal(52, "SIGRTMAX-11", false, false, false, "real time signal 19");
+ AddSignal(53, "SIGRTMAX-10", false, false, false, "real time signal 20");
+ AddSignal(54, "SIGRTMAX-9", false, false, false, "real time signal 21");
+ AddSignal(55, "SIGRTMAX-8", false, false, false, "real time signal 22");
+ AddSignal(56, "SIGRTMAX-7", false, false, false, "real time signal 23");
+ AddSignal(57, "SIGRTMAX-6", false, false, false, "real time signal 24");
+ AddSignal(58, "SIGRTMAX-5", false, false, false, "real time signal 25");
+ AddSignal(59, "SIGRTMAX-4", false, false, false, "real time signal 26");
+ AddSignal(60, "SIGRTMAX-3", false, false, false, "real time signal 27");
+ AddSignal(61, "SIGRTMAX-2", false, false, false, "real time signal 28");
+ AddSignal(62, "SIGRTMAX-1", false, false, false, "real time signal 29");
+ AddSignal(63, "SIGRTMAX", false, false, false, "real time signal 30");
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
index 52ace56..64a697f 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
@@ -17,12 +17,12 @@
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/Log.h"
#include "llvm/Support/Compiler.h"
#include "Plugins/Process/Utility/InstructionUtils.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
index 64983a2..0c36f1a 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
@@ -19,14 +19,14 @@
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/Log.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
index f42fb00..c818fad 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
@@ -12,12 +12,12 @@
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/Log.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
index 7c0bafa..50e7292 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
@@ -14,12 +14,12 @@
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/Log.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
index 93bb09b..dd6ca92 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
@@ -10,8 +10,6 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/AddressRange.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
@@ -28,6 +26,8 @@
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/Log.h"
#include "lldb/lldb-private.h"
#include "RegisterContextDummy.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.cpp
deleted file mode 100644
index fecfae0..0000000
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-//===-- RegisterContextFreeBSD_arm.cpp -------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===---------------------------------------------------------------------===//
-
-#include <cassert>
-#include <stddef.h>
-#include <vector>
-
-#include "lldb/lldb-defines.h"
-#include "llvm/Support/Compiler.h"
-
-#include "RegisterContextFreeBSD_arm.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// Based on RegisterContextLinux_arm.cpp and
-// http://svnweb.freebsd.org/base/head/sys/arm/include/reg.h
-#define GPR_OFFSET(idx) ((idx)*4)
-#define FPU_OFFSET(idx) ((idx)*4 + sizeof(RegisterContextFreeBSD_arm::GPR))
-#define FPSCR_OFFSET \
- (LLVM_EXTENSION offsetof(RegisterContextFreeBSD_arm::FPU, fpscr) + \
- sizeof(RegisterContextFreeBSD_arm::GPR))
-#define EXC_OFFSET(idx) \
- ((idx)*4 + sizeof(RegisterContextFreeBSD_arm::GPR) + \
- sizeof(RegisterContextFreeBSD_arm::FPU))
-#define DBG_OFFSET(reg) \
- ((LLVM_EXTENSION offsetof(RegisterContextFreeBSD_arm::DBG, reg) + \
- sizeof(RegisterContextFreeBSD_arm::GPR) + \
- sizeof(RegisterContextFreeBSD_arm::FPU) + \
- sizeof(RegisterContextFreeBSD_arm::EXC)))
-
-#define DEFINE_DBG(reg, i) \
- #reg, NULL, sizeof(((RegisterContextFreeBSD_arm::DBG *) NULL)->reg[i]), \
- DBG_OFFSET(reg[i]), eEncodingUint, eFormatHex, \
- {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- dbg_##reg##i }, \
- NULL, NULL, NULL, 0
-#define REG_CONTEXT_SIZE \
- (sizeof(RegisterContextFreeBSD_arm::GPR) + \
- sizeof(RegisterContextFreeBSD_arm::FPU) + \
- sizeof(RegisterContextFreeBSD_arm::EXC))
-
-//-----------------------------------------------------------------------------
-// Include RegisterInfos_arm to declare our g_register_infos_arm structure.
-//-----------------------------------------------------------------------------
-#define DECLARE_REGISTER_INFOS_ARM_STRUCT
-#include "RegisterInfos_arm.h"
-#undef DECLARE_REGISTER_INFOS_ARM_STRUCT
-
-static const lldb_private::RegisterInfo *
-GetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch) {
- switch (target_arch.GetMachine()) {
- case llvm::Triple::arm:
- return g_register_infos_arm;
- default:
- assert(false && "Unhandled target architecture.");
- return NULL;
- }
-}
-
-static uint32_t
-GetRegisterInfoCount(const lldb_private::ArchSpec &target_arch) {
- switch (target_arch.GetMachine()) {
- case llvm::Triple::arm:
- return static_cast<uint32_t>(sizeof(g_register_infos_arm) /
- sizeof(g_register_infos_arm[0]));
- default:
- assert(false && "Unhandled target architecture.");
- return 0;
- }
-}
-
-RegisterContextFreeBSD_arm::RegisterContextFreeBSD_arm(
- const lldb_private::ArchSpec &target_arch)
- : lldb_private::RegisterInfoInterface(target_arch),
- m_register_info_p(GetRegisterInfoPtr(target_arch)),
- m_register_info_count(GetRegisterInfoCount(target_arch)) {}
-
-size_t RegisterContextFreeBSD_arm::GetGPRSize() const {
- return sizeof(struct RegisterContextFreeBSD_arm::GPR);
-}
-
-const lldb_private::RegisterInfo *
-RegisterContextFreeBSD_arm::GetRegisterInfo() const {
- return m_register_info_p;
-}
-
-uint32_t RegisterContextFreeBSD_arm::GetRegisterCount() const {
- return m_register_info_count;
-}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.cpp
index c114cfb..55a72b2 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.cpp
@@ -9,11 +9,33 @@
#include "RegisterContextFreeBSD_mips64.h"
#include "RegisterContextPOSIX_mips64.h"
+#include "lldb-mips-freebsd-register-enums.h"
#include <vector>
using namespace lldb_private;
using namespace lldb;
+static const uint32_t g_gpr_regnums[] = {
+ gpr_zero_mips64, gpr_r1_mips64, gpr_r2_mips64, gpr_r3_mips64,
+ gpr_r4_mips64, gpr_r5_mips64, gpr_r6_mips64, gpr_r7_mips64,
+ gpr_r8_mips64, gpr_r9_mips64, gpr_r10_mips64, gpr_r11_mips64,
+ gpr_r12_mips64, gpr_r13_mips64, gpr_r14_mips64, gpr_r15_mips64,
+ gpr_r16_mips64, gpr_r17_mips64, gpr_r18_mips64, gpr_r19_mips64,
+ gpr_r20_mips64, gpr_r21_mips64, gpr_r22_mips64, gpr_r23_mips64,
+ gpr_r24_mips64, gpr_r25_mips64, gpr_r26_mips64, gpr_r27_mips64,
+ gpr_gp_mips64, gpr_sp_mips64, gpr_r30_mips64, gpr_ra_mips64,
+ gpr_sr_mips64, gpr_mullo_mips64, gpr_mulhi_mips64, gpr_badvaddr_mips64,
+ gpr_cause_mips64, gpr_pc_mips64, gpr_ic_mips64, gpr_dummy_mips64};
+
+// Number of register sets provided by this context.
+constexpr size_t k_num_register_sets = 1;
+
+static const RegisterSet g_reg_sets_mips64[k_num_register_sets] = {
+ {"General Purpose Registers", "gpr", k_num_gpr_registers_mips64,
+ g_gpr_regnums},
+};
+
+
// http://svnweb.freebsd.org/base/head/sys/mips/include/regnum.h
typedef struct _GPR {
uint64_t zero;
@@ -74,6 +96,19 @@ size_t RegisterContextFreeBSD_mips64::GetGPRSize() const {
return sizeof(GPR_freebsd_mips);
}
+const RegisterSet *
+RegisterContextFreeBSD_mips64::GetRegisterSet(size_t set) const {
+ // Check if RegisterSet is available
+ if (set < k_num_register_sets)
+ return &g_reg_sets_mips64[set];
+ return nullptr;
+}
+
+size_t
+RegisterContextFreeBSD_mips64::GetRegisterSetCount() const {
+ return k_num_register_sets;
+}
+
const RegisterInfo *RegisterContextFreeBSD_mips64::GetRegisterInfo() const {
assert(m_target_arch.GetCore() == ArchSpec::eCore_mips64);
return g_register_infos_mips64;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h
index 043e638..5e5de71 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h
@@ -19,6 +19,10 @@ public:
size_t GetGPRSize() const override;
+ const lldb_private::RegisterSet *GetRegisterSet(size_t set) const;
+
+ size_t GetRegisterSetCount() const;
+
const lldb_private::RegisterInfo *GetRegisterInfo() const override;
uint32_t GetRegisterCount() const override;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
index 0fc47fc..cc0d696 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
@@ -10,8 +10,6 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/AddressRange.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
@@ -28,6 +26,8 @@
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/Log.h"
#include "lldb/lldb-private.h"
#include "RegisterContextHistory.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
index ba84c40..bd73a29 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -9,8 +9,6 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/AddressRange.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Value.h"
@@ -31,6 +29,8 @@
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/Log.h"
#include "lldb/lldb-private.h"
#include "RegisterContextLLDB.h"
@@ -297,6 +297,14 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
return;
}
+ ExecutionContext exe_ctx(m_thread.shared_from_this());
+ Process *process = exe_ctx.GetProcessPtr();
+ // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
+ // this will strip bit zero in case we read a PC from memory or from the LR.
+ ABI *abi = process->GetABI().get();
+ if (abi)
+ pc = abi->FixCodeAddress(pc);
+
if (log) {
UnwindLogMsg("pc = 0x%" PRIx64, pc);
addr_t reg_val;
@@ -321,15 +329,8 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
}
}
- ExecutionContext exe_ctx(m_thread.shared_from_this());
- Process *process = exe_ctx.GetProcessPtr();
- // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
- // this will strip bit zero in case we read a PC from memory or from the LR.
- ABI *abi = process->GetABI().get();
- if (abi)
- pc = abi->FixCodeAddress(pc);
-
- m_current_pc.SetLoadAddress(pc, &process->GetTarget());
+ const bool allow_section_end = true;
+ m_current_pc.SetLoadAddress(pc, &process->GetTarget(), allow_section_end);
// If we don't have a Module for some reason, we're not going to find
// symbol/function information - just
@@ -477,11 +478,12 @@ void RegisterContextLLDB::InitializeNonZerothFrame() {
// Or if we're in the middle of the stack (and not "above" an asynchronous
// event like sigtramp),
// and our "current" pc is the start of a function...
- if (m_sym_ctx_valid && GetNextFrame()->m_frame_type != eTrapHandlerFrame &&
+ if (GetNextFrame()->m_frame_type != eTrapHandlerFrame &&
GetNextFrame()->m_frame_type != eDebuggerFrame &&
- addr_range.GetBaseAddress().IsValid() &&
- addr_range.GetBaseAddress().GetSection() == m_current_pc.GetSection() &&
- addr_range.GetBaseAddress().GetOffset() == m_current_pc.GetOffset()) {
+ (!m_sym_ctx_valid ||
+ (addr_range.GetBaseAddress().IsValid() &&
+ addr_range.GetBaseAddress().GetSection() == m_current_pc.GetSection() &&
+ addr_range.GetBaseAddress().GetOffset() == m_current_pc.GetOffset()))) {
decr_pc_and_recompute_addr_range = true;
}
@@ -1055,7 +1057,7 @@ bool RegisterContextLLDB::ReadRegisterValueFromRegisterLocation(
case UnwindLLDB::RegisterLocation::eRegisterSavedAtHostMemoryLocation:
llvm_unreachable("FIXME debugger inferior function call unwind");
case UnwindLLDB::RegisterLocation::eRegisterSavedAtMemoryLocation: {
- Error error(ReadRegisterValueFromMemory(
+ Status error(ReadRegisterValueFromMemory(
reg_info, regloc.location.target_memory_location, reg_info->byte_size,
value));
success = error.Success();
@@ -1097,7 +1099,7 @@ bool RegisterContextLLDB::WriteRegisterValueToRegisterLocation(
case UnwindLLDB::RegisterLocation::eRegisterSavedAtHostMemoryLocation:
llvm_unreachable("FIXME debugger inferior function call unwind");
case UnwindLLDB::RegisterLocation::eRegisterSavedAtMemoryLocation: {
- Error error(WriteRegisterValueToMemory(
+ Status error(WriteRegisterValueToMemory(
reg_info, regloc.location.target_memory_location, reg_info->byte_size,
value));
success = error.Success();
@@ -1514,7 +1516,7 @@ RegisterContextLLDB::SavedLocationForRegister(
unwindplan_regloc.GetDWARFExpressionLength());
dwarfexpr.SetRegisterKind(unwindplan_registerkind);
Value result;
- Error error;
+ Status error;
if (dwarfexpr.Evaluate(&exe_ctx, nullptr, nullptr, this, 0, nullptr,
nullptr, result, &error)) {
addr_t val;
@@ -1769,7 +1771,7 @@ bool RegisterContextLLDB::ReadCFAValueForRow(
GetRegisterInfoAtIndex(cfa_reg.GetAsKind(eRegisterKindLLDB));
RegisterValue reg_value;
if (reg_info) {
- Error error = ReadRegisterValueFromMemory(
+ Status error = ReadRegisterValueFromMemory(
reg_info, cfa_reg_contents, reg_info->byte_size, reg_value);
if (error.Success()) {
cfa_value = reg_value.GetAsUInt64();
@@ -1824,7 +1826,7 @@ bool RegisterContextLLDB::ReadCFAValueForRow(
row->GetCFAValue().GetDWARFExpressionLength());
dwarfexpr.SetRegisterKind(row_register_kind);
Value result;
- Error error;
+ Status error;
if (dwarfexpr.Evaluate(&exe_ctx, nullptr, nullptr, this, 0, nullptr,
nullptr, result, &error)) {
cfa_value = result.GetScalar().ULongLong();
@@ -2015,7 +2017,18 @@ bool RegisterContextLLDB::GetStartPC(addr_t &start_pc) {
return false;
if (!m_start_pc.IsValid()) {
- return ReadPC(start_pc);
+ bool read_successfully = ReadPC (start_pc);
+ if (read_successfully)
+ {
+ ProcessSP process_sp (m_thread.GetProcess());
+ if (process_sp)
+ {
+ ABI *abi = process_sp->GetABI().get();
+ if (abi)
+ start_pc = abi->FixCodeAddress(start_pc);
+ }
+ }
+ return read_successfully;
}
start_pc = m_start_pc.GetLoadAddress(CalculateTarget().get());
return true;
@@ -2041,12 +2054,20 @@ bool RegisterContextLLDB::ReadPC(addr_t &pc) {
// unwind past that frame to help
// find the bug.
+ ProcessSP process_sp (m_thread.GetProcess());
+ if (process_sp)
+ {
+ ABI *abi = process_sp->GetABI().get();
+ if (abi)
+ pc = abi->FixCodeAddress(pc);
+ }
+
if (m_all_registers_available == false && above_trap_handler == false &&
(pc == 0 || pc == 1)) {
return false;
- } else {
- return true;
}
+
+ return true;
} else {
return false;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h
index cb22eed..7e9e77d 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLLDB.h
@@ -21,7 +21,7 @@
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Target/RegisterContext.h"
-#include "lldb/Utility/RegisterNumber.h"
+#include "lldb/Target/RegisterNumber.h"
#include "lldb/lldb-private.h"
namespace lldb_private {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.h
deleted file mode 100644
index 9065bc0..0000000
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.h
+++ /dev/null
@@ -1,62 +0,0 @@
-//===-- RegisterContextLinux_arm.h -----------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_RegisterContextLinux_arm_h_
-#define liblldb_RegisterContextLinux_arm_h_
-
-#include "RegisterInfoInterface.h"
-#include "lldb/Target/RegisterContext.h"
-#include "lldb/lldb-private.h"
-
-class RegisterContextLinux_arm : public lldb_private::RegisterInfoInterface {
-public:
- struct GPR {
- uint32_t r[16]; // R0-R15
- uint32_t cpsr; // CPSR
- };
-
- struct QReg {
- uint8_t bytes[16];
- };
-
- struct FPU {
- union {
- uint32_t s[32];
- uint64_t d[32];
- QReg q[16]; // the 128-bit NEON registers
- } floats;
- uint32_t fpscr;
- };
- struct EXC {
- uint32_t exception;
- uint32_t fsr; /* Fault status */
- uint32_t far; /* Virtual Fault Address */
- };
-
- struct DBG {
- uint32_t bvr[16];
- uint32_t bcr[16];
- uint32_t wvr[16];
- uint32_t wcr[16];
- };
-
- RegisterContextLinux_arm(const lldb_private::ArchSpec &target_arch);
-
- size_t GetGPRSize() const override;
-
- const lldb_private::RegisterInfo *GetRegisterInfo() const override;
-
- uint32_t GetRegisterCount() const override;
-
-private:
- const lldb_private::RegisterInfo *m_register_info_p;
- uint32_t m_register_info_count;
-};
-
-#endif // liblldb_RegisterContextLinux_arm_h_
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
index 6563796..2cb17cb 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_i386.cpp
@@ -36,8 +36,7 @@ struct GPR {
struct FPR_i386 {
uint16_t fctrl; // FPU Control Word (fcw)
uint16_t fstat; // FPU Status Word (fsw)
- uint8_t ftag; // FPU Tag Word (ftw)
- uint8_t reserved_1; // Reserved
+ uint16_t ftag; // FPU Tag Word (ftw)
uint16_t fop; // Last Instruction Opcode (fop)
union {
struct {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.cpp
index 982eefe..7b16531 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.cpp
@@ -29,6 +29,73 @@ using namespace lldb;
#include "RegisterInfos_mips.h"
#undef DECLARE_REGISTER_INFOS_MIPS_STRUCT
+// mips general purpose registers.
+const uint32_t g_gp_regnums_mips[] = {
+ gpr_zero_mips, gpr_r1_mips, gpr_r2_mips, gpr_r3_mips,
+ gpr_r4_mips, gpr_r5_mips, gpr_r6_mips, gpr_r7_mips,
+ gpr_r8_mips, gpr_r9_mips, gpr_r10_mips, gpr_r11_mips,
+ gpr_r12_mips, gpr_r13_mips, gpr_r14_mips, gpr_r15_mips,
+ gpr_r16_mips, gpr_r17_mips, gpr_r18_mips, gpr_r19_mips,
+ gpr_r20_mips, gpr_r21_mips, gpr_r22_mips, gpr_r23_mips,
+ gpr_r24_mips, gpr_r25_mips, gpr_r26_mips, gpr_r27_mips,
+ gpr_gp_mips, gpr_sp_mips, gpr_r30_mips, gpr_ra_mips,
+ gpr_sr_mips, gpr_mullo_mips, gpr_mulhi_mips, gpr_badvaddr_mips,
+ gpr_cause_mips, gpr_pc_mips, gpr_config5_mips,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+
+static_assert((sizeof(g_gp_regnums_mips) / sizeof(g_gp_regnums_mips[0])) - 1 ==
+ k_num_gpr_registers_mips,
+ "g_gp_regnums_mips has wrong number of register infos");
+// mips floating point registers.
+const uint32_t g_fp_regnums_mips[] = {
+ fpr_f0_mips, fpr_f1_mips, fpr_f2_mips, fpr_f3_mips,
+ fpr_f4_mips, fpr_f5_mips, fpr_f6_mips, fpr_f7_mips,
+ fpr_f8_mips, fpr_f9_mips, fpr_f10_mips, fpr_f11_mips,
+ fpr_f12_mips, fpr_f13_mips, fpr_f14_mips, fpr_f15_mips,
+ fpr_f16_mips, fpr_f17_mips, fpr_f18_mips, fpr_f19_mips,
+ fpr_f20_mips, fpr_f21_mips, fpr_f22_mips, fpr_f23_mips,
+ fpr_f24_mips, fpr_f25_mips, fpr_f26_mips, fpr_f27_mips,
+ fpr_f28_mips, fpr_f29_mips, fpr_f30_mips, fpr_f31_mips,
+ fpr_fcsr_mips, fpr_fir_mips, fpr_config5_mips,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+
+static_assert((sizeof(g_fp_regnums_mips) / sizeof(g_fp_regnums_mips[0])) - 1 ==
+ k_num_fpr_registers_mips,
+ "g_fp_regnums_mips has wrong number of register infos");
+
+// mips MSA registers.
+const uint32_t g_msa_regnums_mips[] = {
+ msa_w0_mips, msa_w1_mips, msa_w2_mips, msa_w3_mips,
+ msa_w4_mips, msa_w5_mips, msa_w6_mips, msa_w7_mips,
+ msa_w8_mips, msa_w9_mips, msa_w10_mips, msa_w11_mips,
+ msa_w12_mips, msa_w13_mips, msa_w14_mips, msa_w15_mips,
+ msa_w16_mips, msa_w17_mips, msa_w18_mips, msa_w19_mips,
+ msa_w20_mips, msa_w21_mips, msa_w22_mips, msa_w23_mips,
+ msa_w24_mips, msa_w25_mips, msa_w26_mips, msa_w27_mips,
+ msa_w28_mips, msa_w29_mips, msa_w30_mips, msa_w31_mips,
+ msa_fcsr_mips, msa_fir_mips, msa_mcsr_mips, msa_mir_mips,
+ msa_config5_mips,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+
+static_assert((sizeof(g_msa_regnums_mips) / sizeof(g_msa_regnums_mips[0])) -
+ 1 ==
+ k_num_msa_registers_mips,
+ "g_msa_regnums_mips has wrong number of register infos");
+
+// Number of register sets provided by this context.
+constexpr size_t k_num_register_sets = 3;
+
+// Register sets for mips.
+static const RegisterSet g_reg_sets_mips[k_num_register_sets] = {
+ {"General Purpose Registers", "gpr", k_num_gpr_registers_mips,
+ g_gp_regnums_mips},
+ {"Floating Point Registers", "fpu", k_num_fpr_registers_mips,
+ g_fp_regnums_mips},
+ {"MSA Registers", "msa", k_num_msa_registers_mips, g_msa_regnums_mips}};
+
uint32_t GetUserRegisterInfoCount(bool msa_present) {
if (msa_present)
return static_cast<uint32_t>(k_num_user_registers_mips);
@@ -56,6 +123,25 @@ const RegisterInfo *RegisterContextLinux_mips::GetRegisterInfo() const {
}
}
+const RegisterSet *
+RegisterContextLinux_mips::GetRegisterSet(size_t set) const {
+ if (set >= k_num_register_sets)
+ return nullptr;
+ switch (m_target_arch.GetMachine()) {
+ case llvm::Triple::mips:
+ case llvm::Triple::mipsel:
+ return &g_reg_sets_mips[set];
+ default:
+ assert(false && "Unhandled target architecture.");
+ return nullptr;
+ }
+}
+
+size_t
+RegisterContextLinux_mips::GetRegisterSetCount() const {
+ return k_num_register_sets;
+}
+
uint32_t RegisterContextLinux_mips::GetRegisterCount() const {
return static_cast<uint32_t>(sizeof(g_register_infos_mips) /
sizeof(g_register_infos_mips[0]));
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.h
index cba4ee6..a16c4ec 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips.h
@@ -22,6 +22,10 @@ public:
const lldb_private::RegisterInfo *GetRegisterInfo() const override;
+ const lldb_private::RegisterSet *GetRegisterSet(size_t set) const;
+
+ size_t GetRegisterSetCount() const;
+
uint32_t GetRegisterCount() const override;
uint32_t GetUserRegisterCount() const override;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.cpp
index c40f694..1bb16c7 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.cpp
@@ -7,7 +7,6 @@
//
//===---------------------------------------------------------------------===//
-#if defined(__mips__)
#include <stddef.h>
#include <vector>
@@ -41,6 +40,101 @@ using namespace lldb_private;
#include "RegisterInfos_mips.h"
#undef DECLARE_REGISTER_INFOS_MIPS_STRUCT
+// mips64 general purpose registers.
+const uint32_t g_gp_regnums_mips64[] = {
+ gpr_zero_mips64, gpr_r1_mips64, gpr_r2_mips64,
+ gpr_r3_mips64, gpr_r4_mips64, gpr_r5_mips64,
+ gpr_r6_mips64, gpr_r7_mips64, gpr_r8_mips64,
+ gpr_r9_mips64, gpr_r10_mips64, gpr_r11_mips64,
+ gpr_r12_mips64, gpr_r13_mips64, gpr_r14_mips64,
+ gpr_r15_mips64, gpr_r16_mips64, gpr_r17_mips64,
+ gpr_r18_mips64, gpr_r19_mips64, gpr_r20_mips64,
+ gpr_r21_mips64, gpr_r22_mips64, gpr_r23_mips64,
+ gpr_r24_mips64, gpr_r25_mips64, gpr_r26_mips64,
+ gpr_r27_mips64, gpr_gp_mips64, gpr_sp_mips64,
+ gpr_r30_mips64, gpr_ra_mips64, gpr_sr_mips64,
+ gpr_mullo_mips64, gpr_mulhi_mips64, gpr_badvaddr_mips64,
+ gpr_cause_mips64, gpr_pc_mips64, gpr_config5_mips64,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+
+static_assert((sizeof(g_gp_regnums_mips64) / sizeof(g_gp_regnums_mips64[0])) -
+ 1 ==
+ k_num_gpr_registers_mips64,
+ "g_gp_regnums_mips64 has wrong number of register infos");
+
+// mips64 floating point registers.
+const uint32_t g_fp_regnums_mips64[] = {
+ fpr_f0_mips64, fpr_f1_mips64, fpr_f2_mips64, fpr_f3_mips64,
+ fpr_f4_mips64, fpr_f5_mips64, fpr_f6_mips64, fpr_f7_mips64,
+ fpr_f8_mips64, fpr_f9_mips64, fpr_f10_mips64, fpr_f11_mips64,
+ fpr_f12_mips64, fpr_f13_mips64, fpr_f14_mips64, fpr_f15_mips64,
+ fpr_f16_mips64, fpr_f17_mips64, fpr_f18_mips64, fpr_f19_mips64,
+ fpr_f20_mips64, fpr_f21_mips64, fpr_f22_mips64, fpr_f23_mips64,
+ fpr_f24_mips64, fpr_f25_mips64, fpr_f26_mips64, fpr_f27_mips64,
+ fpr_f28_mips64, fpr_f29_mips64, fpr_f30_mips64, fpr_f31_mips64,
+ fpr_fcsr_mips64, fpr_fir_mips64, fpr_config5_mips64,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+
+static_assert((sizeof(g_fp_regnums_mips64) / sizeof(g_fp_regnums_mips64[0])) -
+ 1 ==
+ k_num_fpr_registers_mips64,
+ "g_fp_regnums_mips64 has wrong number of register infos");
+
+// mips64 MSA registers.
+const uint32_t g_msa_regnums_mips64[] = {
+ msa_w0_mips64, msa_w1_mips64, msa_w2_mips64, msa_w3_mips64,
+ msa_w4_mips64, msa_w5_mips64, msa_w6_mips64, msa_w7_mips64,
+ msa_w8_mips64, msa_w9_mips64, msa_w10_mips64, msa_w11_mips64,
+ msa_w12_mips64, msa_w13_mips64, msa_w14_mips64, msa_w15_mips64,
+ msa_w16_mips64, msa_w17_mips64, msa_w18_mips64, msa_w19_mips64,
+ msa_w20_mips64, msa_w21_mips64, msa_w22_mips64, msa_w23_mips64,
+ msa_w24_mips64, msa_w25_mips64, msa_w26_mips64, msa_w27_mips64,
+ msa_w28_mips64, msa_w29_mips64, msa_w30_mips64, msa_w31_mips64,
+ msa_fcsr_mips64, msa_fir_mips64, msa_mcsr_mips64, msa_mir_mips64,
+ msa_config5_mips64,
+ LLDB_INVALID_REGNUM // register sets need to end with this flag
+};
+
+static_assert((sizeof(g_msa_regnums_mips64) / sizeof(g_msa_regnums_mips64[0])) -
+ 1 ==
+ k_num_msa_registers_mips64,
+ "g_msa_regnums_mips64 has wrong number of register infos");
+
+// Number of register sets provided by this context.
+constexpr size_t k_num_register_sets = 3;
+
+// Register sets for mips64.
+static const RegisterSet g_reg_sets_mips64[k_num_register_sets] = {
+ {"General Purpose Registers", "gpr", k_num_gpr_registers_mips64,
+ g_gp_regnums_mips64},
+ {"Floating Point Registers", "fpu", k_num_fpr_registers_mips64,
+ g_fp_regnums_mips64},
+ {"MSA Registers", "msa", k_num_msa_registers_mips64, g_msa_regnums_mips64},
+};
+
+const RegisterSet *
+RegisterContextLinux_mips64::GetRegisterSet(size_t set) const {
+ if (set >= k_num_register_sets)
+ return nullptr;
+
+ switch (m_target_arch.GetMachine()) {
+ case llvm::Triple::mips64:
+ case llvm::Triple::mips64el:
+ return &g_reg_sets_mips64[set];
+ default:
+ assert(false && "Unhandled target architecture.");
+ return nullptr;
+ }
+ return nullptr;
+}
+
+size_t
+RegisterContextLinux_mips64::GetRegisterSetCount() const {
+ return k_num_register_sets;
+}
+
static const RegisterInfo *GetRegisterInfoPtr(const ArchSpec &target_arch) {
switch (target_arch.GetMachine()) {
case llvm::Triple::mips64:
@@ -116,4 +210,3 @@ uint32_t RegisterContextLinux_mips64::GetUserRegisterCount() const {
return m_user_register_count;
}
-#endif
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.h
index 9669b0d..d3ca9d7 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_mips64.h
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#if defined(__mips__)
-
#ifndef liblldb_RegisterContextLinux_mips64_H_
#define liblldb_RegisterContextLinux_mips64_H_
@@ -24,6 +22,10 @@ public:
const lldb_private::RegisterInfo *GetRegisterInfo() const override;
+ const lldb_private::RegisterSet *GetRegisterSet(size_t set) const;
+
+ size_t GetRegisterSetCount() const;
+
uint32_t GetRegisterCount() const override;
uint32_t GetUserRegisterCount() const override;
@@ -36,4 +38,3 @@ private:
#endif
-#endif
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
index 95b106d..2d24bda 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
@@ -12,12 +12,12 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/StreamString.h"
// Project includes
#include "Utility/StringExtractorGDBRemote.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
index 57966e1..8f0dfd2 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
@@ -14,11 +14,11 @@
// Other libraries and framework includes
// Project includes
#include "DynamicRegisterInfo.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Error.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/Status.h"
using namespace lldb;
using namespace lldb_private;
@@ -101,8 +101,8 @@ bool RegisterContextMemory::WriteRegister(const RegisterInfo *reg_info,
if (m_reg_data_addr != LLDB_INVALID_ADDRESS) {
const uint32_t reg_num = reg_info->kinds[eRegisterKindLLDB];
addr_t reg_addr = m_reg_data_addr + reg_info->byte_offset;
- Error error(WriteRegisterValueToMemory(reg_info, reg_addr,
- reg_info->byte_size, reg_value));
+ Status error(WriteRegisterValueToMemory(reg_info, reg_addr,
+ reg_info->byte_size, reg_value));
m_reg_valid[reg_num] = false;
return error.Success();
}
@@ -113,7 +113,7 @@ bool RegisterContextMemory::ReadAllRegisterValues(DataBufferSP &data_sp) {
if (m_reg_data_addr != LLDB_INVALID_ADDRESS) {
ProcessSP process_sp(CalculateProcess());
if (process_sp) {
- Error error;
+ Status error;
if (process_sp->ReadMemory(m_reg_data_addr, data_sp->GetBytes(),
data_sp->GetByteSize(),
error) == data_sp->GetByteSize()) {
@@ -130,7 +130,7 @@ bool RegisterContextMemory::WriteAllRegisterValues(
if (m_reg_data_addr != LLDB_INVALID_ADDRESS) {
ProcessSP process_sp(CalculateProcess());
if (process_sp) {
- Error error;
+ Status error;
SetAllRegisterValid(false);
if (process_sp->WriteMemory(m_reg_data_addr, data_sp->GetBytes(),
data_sp->GetByteSize(),
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
index 55de041..cad1592 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
@@ -16,8 +16,8 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/DataExtractor.h"
#include "lldb/lldb-private.h"
class DynamicRegisterInfo;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextNetBSD_x86_64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextNetBSD_x86_64.cpp
index 4f64a8c..ca7a013 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextNetBSD_x86_64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextNetBSD_x86_64.cpp
@@ -47,10 +47,14 @@ typedef struct _GPR {
uint64_t ss; /* 25 */
} GPR;
-/*
- * As of NetBSD-7.99.25 there is no support for debug registers
- * https://en.wikipedia.org/wiki/X86_debug_register
- */
+struct DBG {
+ uint64_t dr[16]; /* debug registers */
+ /* Index 0-3: debug address registers */
+ /* Index 4-5: reserved */
+ /* Index 6: debug status */
+ /* Index 7: debug control */
+ /* Index 8-15: reserved */
+};
/*
* src/sys/arch/amd64/include/mcontext.h
@@ -66,276 +70,21 @@ struct UserArea {
GPR gpr;
uint64_t mc_tlsbase;
FPR fpr;
+ DBG dbg;
};
-//---------------------------------------------------------------------------
-// Cherry-pick parts of RegisterInfos_x86_64.h, without debug registers
-//---------------------------------------------------------------------------
-// Computes the offset of the given GPR in the user data area.
-#define GPR_OFFSET(regname) (LLVM_EXTENSION offsetof(GPR, regname))
-
-// Computes the offset of the given FPR in the extended data area.
-#define FPR_OFFSET(regname) \
- (LLVM_EXTENSION offsetof(UserArea, fpr) + \
- LLVM_EXTENSION offsetof(FPR, xstate) + \
- LLVM_EXTENSION offsetof(FXSAVE, regname))
-
-// Computes the offset of the YMM register assembled from register halves.
-// Based on DNBArchImplX86_64.cpp from debugserver
-#define YMM_OFFSET(reg_index) \
- (LLVM_EXTENSION offsetof(UserArea, fpr) + \
- LLVM_EXTENSION offsetof(FPR, xstate) + \
- LLVM_EXTENSION offsetof(XSAVE, ymmh[0]) + (32 * reg_index))
-
-// Number of bytes needed to represent a FPR.
-#define FPR_SIZE(reg) sizeof(((FXSAVE *)nullptr)->reg)
-
-// Number of bytes needed to represent the i'th FP register.
-#define FP_SIZE sizeof(((MMSReg *)nullptr)->bytes)
-
-// Number of bytes needed to represent an XMM register.
-#define XMM_SIZE sizeof(XMMReg)
-
-// Number of bytes needed to represent a YMM register.
-#define YMM_SIZE sizeof(YMMReg)
-
-// RegisterKind: EHFrame, DWARF, Generic, Process Plugin, LLDB
-
-// Note that the size and offset will be updated by platform-specific classes.
-#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
- { \
- #reg, alt, sizeof(((GPR *)nullptr)->reg), \
- GPR_OFFSET(reg), eEncodingUint, eFormatHex, \
- {kind1, kind2, kind3, kind4, \
- lldb_##reg##_x86_64 }, \
- nullptr, nullptr, nullptr, 0 \
- }
-
-#define DEFINE_FPR(name, reg, kind1, kind2, kind3, kind4) \
- { \
- #name, nullptr, FPR_SIZE(reg), FPR_OFFSET(reg), eEncodingUint, eFormatHex, \
- {kind1, kind2, kind3, kind4, \
- lldb_##name##_x86_64 }, \
- nullptr, nullptr, nullptr, 0 \
- }
-
-#define DEFINE_FP_ST(reg, i) \
- { \
- #reg #i, nullptr, FP_SIZE, \
- LLVM_EXTENSION FPR_OFFSET( \
- stmm[i]), eEncodingVector, eFormatVectorOfUInt8, \
- {dwarf_st##i##_x86_64, dwarf_st##i##_x86_64, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM, lldb_st##i##_x86_64 }, \
- nullptr, nullptr, nullptr, 0 \
- }
-
-#define DEFINE_FP_MM(reg, i) \
- { \
- #reg #i, nullptr, sizeof(uint64_t), \
- LLVM_EXTENSION FPR_OFFSET( \
- stmm[i]), eEncodingUint, eFormatHex, \
- {dwarf_mm##i##_x86_64, dwarf_mm##i##_x86_64, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_mm##i##_x86_64 }, \
- nullptr, nullptr, nullptr, 0 \
- }
-
-#define DEFINE_XMM(reg, i) \
- { \
- #reg #i, nullptr, XMM_SIZE, \
- LLVM_EXTENSION FPR_OFFSET( \
- reg[i]), eEncodingVector, eFormatVectorOfUInt8, \
- {dwarf_##reg##i##_x86_64, dwarf_##reg##i##_x86_64, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_##reg##i##_x86_64 }, \
- nullptr, nullptr, nullptr, 0 \
- }
-
-#define DEFINE_YMM(reg, i) \
- { \
- #reg #i, nullptr, YMM_SIZE, \
- LLVM_EXTENSION YMM_OFFSET(i), eEncodingVector, eFormatVectorOfUInt8, \
- {dwarf_##reg##i##h_x86_64, \
- dwarf_##reg##i##h_x86_64, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_##reg##i##_x86_64 }, \
- nullptr, nullptr, nullptr, 0 \
- }
+#define DR_OFFSET(reg_index) \
+ (LLVM_EXTENSION offsetof(UserArea, dbg) + \
+ LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
-#define DEFINE_GPR_PSEUDO_32(reg32, reg64) \
- { \
- #reg32, nullptr, 4, \
- GPR_OFFSET(reg64), eEncodingUint, eFormatHex, \
- {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_##reg32##_x86_64 }, \
- RegisterContextPOSIX_x86::g_contained_##reg64, \
- RegisterContextPOSIX_x86::g_invalidate_##reg64, nullptr, 0 \
- }
-
-#define DEFINE_GPR_PSEUDO_16(reg16, reg64) \
- { \
- #reg16, nullptr, 2, \
- GPR_OFFSET(reg64), eEncodingUint, eFormatHex, \
- {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_##reg16##_x86_64 }, \
- RegisterContextPOSIX_x86::g_contained_##reg64, \
- RegisterContextPOSIX_x86::g_invalidate_##reg64, nullptr, 0 \
- }
-
-#define DEFINE_GPR_PSEUDO_8H(reg8, reg64) \
- { \
- #reg8, nullptr, 1, GPR_OFFSET(reg64) + 1, eEncodingUint, eFormatHex, \
- {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_##reg8##_x86_64 }, \
- RegisterContextPOSIX_x86::g_contained_##reg64, \
- RegisterContextPOSIX_x86::g_invalidate_##reg64,\
- nullptr, 0 \
- }
-
-#define DEFINE_GPR_PSEUDO_8L(reg8, reg64) \
- { \
- #reg8, nullptr, 1, GPR_OFFSET(reg64), eEncodingUint, eFormatHex, \
- {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- lldb_##reg8##_x86_64 }, \
- RegisterContextPOSIX_x86::g_contained_##reg64, \
- RegisterContextPOSIX_x86::g_invalidate_##reg64,\
- nullptr, 0 \
- }
-
-static RegisterInfo g_register_infos_x86_64[] = {
- // General purpose registers. EH_Frame, DWARF,
- // Generic, Process Plugin
- DEFINE_GPR(rax, nullptr, dwarf_rax_x86_64, dwarf_rax_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rbx, nullptr, dwarf_rbx_x86_64, dwarf_rbx_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rcx, "arg4", dwarf_rcx_x86_64, dwarf_rcx_x86_64,
- LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rdx, "arg3", dwarf_rdx_x86_64, dwarf_rdx_x86_64,
- LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rdi, "arg1", dwarf_rdi_x86_64, dwarf_rdi_x86_64,
- LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rsi, "arg2", dwarf_rsi_x86_64, dwarf_rsi_x86_64,
- LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rbp, "fp", dwarf_rbp_x86_64, dwarf_rbp_x86_64,
- LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rsp, "sp", dwarf_rsp_x86_64, dwarf_rsp_x86_64,
- LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r8, "arg5", dwarf_r8_x86_64, dwarf_r8_x86_64,
- LLDB_REGNUM_GENERIC_ARG5, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r9, "arg6", dwarf_r9_x86_64, dwarf_r9_x86_64,
- LLDB_REGNUM_GENERIC_ARG6, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r10, nullptr, dwarf_r10_x86_64, dwarf_r10_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r11, nullptr, dwarf_r11_x86_64, dwarf_r11_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r12, nullptr, dwarf_r12_x86_64, dwarf_r12_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r13, nullptr, dwarf_r13_x86_64, dwarf_r13_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r14, nullptr, dwarf_r14_x86_64, dwarf_r14_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(r15, nullptr, dwarf_r15_x86_64, dwarf_r15_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rip, "pc", dwarf_rip_x86_64, dwarf_rip_x86_64,
- LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM),
- DEFINE_GPR(rflags, "flags", dwarf_rflags_x86_64, dwarf_rflags_x86_64,
- LLDB_REGNUM_GENERIC_FLAGS, LLDB_INVALID_REGNUM),
- DEFINE_GPR(cs, nullptr, dwarf_cs_x86_64, dwarf_cs_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(fs, nullptr, dwarf_fs_x86_64, dwarf_fs_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(gs, nullptr, dwarf_gs_x86_64, dwarf_gs_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(ss, nullptr, dwarf_ss_x86_64, dwarf_ss_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(ds, nullptr, dwarf_ds_x86_64, dwarf_ds_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_GPR(es, nullptr, dwarf_es_x86_64, dwarf_es_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
-
- DEFINE_GPR_PSEUDO_32(eax, rax), DEFINE_GPR_PSEUDO_32(ebx, rbx),
- DEFINE_GPR_PSEUDO_32(ecx, rcx), DEFINE_GPR_PSEUDO_32(edx, rdx),
- DEFINE_GPR_PSEUDO_32(edi, rdi), DEFINE_GPR_PSEUDO_32(esi, rsi),
- DEFINE_GPR_PSEUDO_32(ebp, rbp), DEFINE_GPR_PSEUDO_32(esp, rsp),
- DEFINE_GPR_PSEUDO_32(r8d, r8), DEFINE_GPR_PSEUDO_32(r9d, r9),
- DEFINE_GPR_PSEUDO_32(r10d, r10), DEFINE_GPR_PSEUDO_32(r11d, r11),
- DEFINE_GPR_PSEUDO_32(r12d, r12), DEFINE_GPR_PSEUDO_32(r13d, r13),
- DEFINE_GPR_PSEUDO_32(r14d, r14), DEFINE_GPR_PSEUDO_32(r15d, r15),
- DEFINE_GPR_PSEUDO_16(ax, rax), DEFINE_GPR_PSEUDO_16(bx, rbx),
- DEFINE_GPR_PSEUDO_16(cx, rcx), DEFINE_GPR_PSEUDO_16(dx, rdx),
- DEFINE_GPR_PSEUDO_16(di, rdi), DEFINE_GPR_PSEUDO_16(si, rsi),
- DEFINE_GPR_PSEUDO_16(bp, rbp), DEFINE_GPR_PSEUDO_16(sp, rsp),
- DEFINE_GPR_PSEUDO_16(r8w, r8), DEFINE_GPR_PSEUDO_16(r9w, r9),
- DEFINE_GPR_PSEUDO_16(r10w, r10), DEFINE_GPR_PSEUDO_16(r11w, r11),
- DEFINE_GPR_PSEUDO_16(r12w, r12), DEFINE_GPR_PSEUDO_16(r13w, r13),
- DEFINE_GPR_PSEUDO_16(r14w, r14), DEFINE_GPR_PSEUDO_16(r15w, r15),
- DEFINE_GPR_PSEUDO_8H(ah, rax), DEFINE_GPR_PSEUDO_8H(bh, rbx),
- DEFINE_GPR_PSEUDO_8H(ch, rcx), DEFINE_GPR_PSEUDO_8H(dh, rdx),
- DEFINE_GPR_PSEUDO_8L(al, rax), DEFINE_GPR_PSEUDO_8L(bl, rbx),
- DEFINE_GPR_PSEUDO_8L(cl, rcx), DEFINE_GPR_PSEUDO_8L(dl, rdx),
- DEFINE_GPR_PSEUDO_8L(dil, rdi), DEFINE_GPR_PSEUDO_8L(sil, rsi),
- DEFINE_GPR_PSEUDO_8L(bpl, rbp), DEFINE_GPR_PSEUDO_8L(spl, rsp),
- DEFINE_GPR_PSEUDO_8L(r8l, r8), DEFINE_GPR_PSEUDO_8L(r9l, r9),
- DEFINE_GPR_PSEUDO_8L(r10l, r10), DEFINE_GPR_PSEUDO_8L(r11l, r11),
- DEFINE_GPR_PSEUDO_8L(r12l, r12), DEFINE_GPR_PSEUDO_8L(r13l, r13),
- DEFINE_GPR_PSEUDO_8L(r14l, r14), DEFINE_GPR_PSEUDO_8L(r15l, r15),
-
- // i387 Floating point registers. EH_frame,
- // DWARF, Generic, Process Plugin
- DEFINE_FPR(fctrl, fctrl, dwarf_fctrl_x86_64, dwarf_fctrl_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(fstat, fstat, dwarf_fstat_x86_64, dwarf_fstat_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(ftag, ftag, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(fop, fop, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(fiseg, ptr.i386_.fiseg, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(fioff, ptr.i386_.fioff, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(foseg, ptr.i386_.foseg, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(fooff, ptr.i386_.fooff, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(mxcsr, mxcsr, dwarf_mxcsr_x86_64, dwarf_mxcsr_x86_64,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
- DEFINE_FPR(mxcsrmask, mxcsrmask, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
- LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM),
-
- // FP registers.
- DEFINE_FP_ST(st, 0), DEFINE_FP_ST(st, 1), DEFINE_FP_ST(st, 2),
- DEFINE_FP_ST(st, 3), DEFINE_FP_ST(st, 4), DEFINE_FP_ST(st, 5),
- DEFINE_FP_ST(st, 6), DEFINE_FP_ST(st, 7), DEFINE_FP_MM(mm, 0),
- DEFINE_FP_MM(mm, 1), DEFINE_FP_MM(mm, 2), DEFINE_FP_MM(mm, 3),
- DEFINE_FP_MM(mm, 4), DEFINE_FP_MM(mm, 5), DEFINE_FP_MM(mm, 6),
- DEFINE_FP_MM(mm, 7),
-
- // XMM registers
- DEFINE_XMM(xmm, 0), DEFINE_XMM(xmm, 1), DEFINE_XMM(xmm, 2),
- DEFINE_XMM(xmm, 3), DEFINE_XMM(xmm, 4), DEFINE_XMM(xmm, 5),
- DEFINE_XMM(xmm, 6), DEFINE_XMM(xmm, 7), DEFINE_XMM(xmm, 8),
- DEFINE_XMM(xmm, 9), DEFINE_XMM(xmm, 10), DEFINE_XMM(xmm, 11),
- DEFINE_XMM(xmm, 12), DEFINE_XMM(xmm, 13), DEFINE_XMM(xmm, 14),
- DEFINE_XMM(xmm, 15),
-
- // Copy of YMM registers assembled from xmm and ymmh
- DEFINE_YMM(ymm, 0), DEFINE_YMM(ymm, 1), DEFINE_YMM(ymm, 2),
- DEFINE_YMM(ymm, 3), DEFINE_YMM(ymm, 4), DEFINE_YMM(ymm, 5),
- DEFINE_YMM(ymm, 6), DEFINE_YMM(ymm, 7), DEFINE_YMM(ymm, 8),
- DEFINE_YMM(ymm, 9), DEFINE_YMM(ymm, 10), DEFINE_YMM(ymm, 11),
- DEFINE_YMM(ymm, 12), DEFINE_YMM(ymm, 13), DEFINE_YMM(ymm, 14),
- DEFINE_YMM(ymm, 15),
-};
//---------------------------------------------------------------------------
-// End of cherry-pick of RegisterInfos_x86_64.h
+// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
+// structure.
//---------------------------------------------------------------------------
+#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
+#include "RegisterInfos_x86_64.h"
+#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
static const RegisterInfo *
PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch) {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
new file mode 100644
index 0000000..1f95810
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
@@ -0,0 +1,80 @@
+//===-- RegisterContextOpenBSD_i386.cpp ------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===---------------------------------------------------------------------===//
+
+#include "RegisterContextOpenBSD_i386.h"
+#include "RegisterContextPOSIX_x86.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+// /usr/include/machine/reg.h
+struct GPR {
+ uint32_t eax;
+ uint32_t ecx;
+ uint32_t edx;
+ uint32_t ebx;
+ uint32_t esp;
+ uint32_t ebp;
+ uint32_t esi;
+ uint32_t edi;
+ uint32_t eip;
+ uint32_t eflags;
+ uint32_t cs;
+ uint32_t ss;
+ uint32_t ds;
+ uint32_t es;
+ uint32_t fs;
+ uint32_t gs;
+};
+
+struct dbreg {
+ uint32_t dr[8]; /* debug registers */
+ /* Index 0-3: debug address registers */
+ /* Index 4-5: reserved */
+ /* Index 6: debug status */
+ /* Index 7: debug control */
+};
+
+using FPR_i386 = FXSAVE;
+
+struct UserArea {
+ GPR gpr;
+ FPR_i386 i387;
+};
+
+#define DR_SIZE sizeof(uint32_t)
+#define DR_OFFSET(reg_index) (LLVM_EXTENSION offsetof(dbreg, dr[reg_index]))
+
+//---------------------------------------------------------------------------
+// Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
+//---------------------------------------------------------------------------
+#define DECLARE_REGISTER_INFOS_I386_STRUCT
+#include "RegisterInfos_i386.h"
+#undef DECLARE_REGISTER_INFOS_I386_STRUCT
+
+RegisterContextOpenBSD_i386::RegisterContextOpenBSD_i386(
+ const ArchSpec &target_arch)
+ : RegisterInfoInterface(target_arch) {}
+
+size_t RegisterContextOpenBSD_i386::GetGPRSize() const { return sizeof(GPR); }
+
+const RegisterInfo *RegisterContextOpenBSD_i386::GetRegisterInfo() const {
+ switch (m_target_arch.GetMachine()) {
+ case llvm::Triple::x86:
+ return g_register_infos_i386;
+ default:
+ assert(false && "Unhandled target architecture.");
+ return NULL;
+ }
+}
+
+uint32_t RegisterContextOpenBSD_i386::GetRegisterCount() const {
+ return static_cast<uint32_t>(sizeof(g_register_infos_i386) /
+ sizeof(g_register_infos_i386[0]));
+}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h
new file mode 100644
index 0000000..d3c1300
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h
@@ -0,0 +1,26 @@
+//===-- RegisterContextOpenBSD_i386.h ---------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_RegisterContextOpenBSD_i386_H_
+#define liblldb_RegisterContextOpenBSD_i386_H_
+
+#include "RegisterInfoInterface.h"
+
+class RegisterContextOpenBSD_i386 : public lldb_private::RegisterInfoInterface {
+public:
+ RegisterContextOpenBSD_i386(const lldb_private::ArchSpec &target_arch);
+
+ size_t GetGPRSize() const override;
+
+ const lldb_private::RegisterInfo *GetRegisterInfo() const override;
+
+ uint32_t GetRegisterCount() const override;
+};
+
+#endif
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
new file mode 100644
index 0000000..e7ff073
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
@@ -0,0 +1,107 @@
+//===-- RegisterContextOpenBSD_x86_64.cpp ----------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===---------------------------------------------------------------------===//
+
+#include "RegisterContextOpenBSD_x86_64.h"
+#include "RegisterContextPOSIX_x86.h"
+#include <vector>
+
+using namespace lldb_private;
+using namespace lldb;
+
+// /usr/include/machine/reg.h
+typedef struct _GPR {
+ uint64_t rdi;
+ uint64_t rsi;
+ uint64_t rdx;
+ uint64_t rcx;
+ uint64_t r8;
+ uint64_t r9;
+ uint64_t r10;
+ uint64_t r11;
+ uint64_t r12;
+ uint64_t r13;
+ uint64_t r14;
+ uint64_t r15;
+ uint64_t rbp;
+ uint64_t rbx;
+ uint64_t rax;
+ uint64_t rsp;
+ uint64_t rip;
+ uint64_t rflags;
+ uint64_t cs;
+ uint64_t ss;
+ uint64_t ds;
+ uint64_t es;
+ uint64_t fs;
+ uint64_t gs;
+} GPR;
+
+struct DBG {
+ uint64_t dr[16]; /* debug registers */
+ /* Index 0-3: debug address registers */
+ /* Index 4-5: reserved */
+ /* Index 6: debug status */
+ /* Index 7: debug control */
+ /* Index 8-15: reserved */
+};
+
+struct UserArea {
+ GPR gpr;
+ FPR fpr;
+ DBG dbg;
+};
+
+#define DR_OFFSET(reg_index) (LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
+
+//---------------------------------------------------------------------------
+// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
+// structure.
+//---------------------------------------------------------------------------
+#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
+#include "RegisterInfos_x86_64.h"
+#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
+
+static const RegisterInfo *
+PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch) {
+ switch (target_arch.GetMachine()) {
+ case llvm::Triple::x86_64:
+ return g_register_infos_x86_64;
+ default:
+ assert(false && "Unhandled target architecture.");
+ return nullptr;
+ }
+}
+
+static uint32_t
+PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch) {
+ switch (target_arch.GetMachine()) {
+ case llvm::Triple::x86_64:
+ return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) /
+ sizeof(g_register_infos_x86_64[0]));
+ default:
+ assert(false && "Unhandled target architecture.");
+ return 0;
+ }
+}
+
+RegisterContextOpenBSD_x86_64::RegisterContextOpenBSD_x86_64(
+ const ArchSpec &target_arch)
+ : lldb_private::RegisterInfoInterface(target_arch),
+ m_register_info_p(PrivateGetRegisterInfoPtr(target_arch)),
+ m_register_count(PrivateGetRegisterCount(target_arch)) {}
+
+size_t RegisterContextOpenBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
+
+const RegisterInfo *RegisterContextOpenBSD_x86_64::GetRegisterInfo() const {
+ return m_register_info_p;
+}
+
+uint32_t RegisterContextOpenBSD_x86_64::GetRegisterCount() const {
+ return m_register_count;
+}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
new file mode 100644
index 0000000..aa2b773
--- /dev/null
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
@@ -0,0 +1,31 @@
+//===-- RegisterContextOpenBSD_x86_64.h -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_RegisterContextOpenBSD_x86_64_H_
+#define liblldb_RegisterContextOpenBSD_x86_64_H_
+
+#include "RegisterInfoInterface.h"
+
+class RegisterContextOpenBSD_x86_64
+ : public lldb_private::RegisterInfoInterface {
+public:
+ RegisterContextOpenBSD_x86_64(const lldb_private::ArchSpec &target_arch);
+
+ size_t GetGPRSize() const override;
+
+ const lldb_private::RegisterInfo *GetRegisterInfo() const override;
+
+ uint32_t GetRegisterCount() const override;
+
+private:
+ const lldb_private::RegisterInfo *m_register_info_p;
+ const uint32_t m_register_count;
+};
+
+#endif
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp
index 15d155e..bb35093 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.cpp
@@ -11,13 +11,13 @@
#include <errno.h>
#include <stdint.h>
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
#include "Plugins/Process/elf-core/ProcessElfCore.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
index 817649e..8c5fe9d 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
@@ -16,8 +16,8 @@
// Project includes
#include "RegisterInfoInterface.h"
#include "lldb-arm-register-enums.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/Log.h"
class ProcessMonitor;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
index 17c9dc3..89384c8 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
@@ -11,13 +11,13 @@
#include <errno.h>
#include <stdint.h>
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
#include "Plugins/Process/elf-core/ProcessElfCore.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
index 923e786..27251da 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
@@ -16,8 +16,8 @@
// Project includes
#include "RegisterInfoInterface.h"
#include "lldb-arm64-register-enums.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/Log.h"
class ProcessMonitor;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp
index 8c67fb8..6a55947 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.cpp
@@ -11,47 +11,33 @@
#include <errno.h>
#include <stdint.h>
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
#include "Plugins/Process/elf-core/ProcessElfCore.h"
#include "RegisterContextPOSIX_mips64.h"
+#include "RegisterContextFreeBSD_mips64.h"
+#include "RegisterContextLinux_mips64.h"
+#include "RegisterContextLinux_mips.h"
using namespace lldb_private;
using namespace lldb;
-static const uint32_t g_gpr_regnums[] = {
- gpr_zero_mips64, gpr_r1_mips64, gpr_r2_mips64, gpr_r3_mips64,
- gpr_r4_mips64, gpr_r5_mips64, gpr_r6_mips64, gpr_r7_mips64,
- gpr_r8_mips64, gpr_r9_mips64, gpr_r10_mips64, gpr_r11_mips64,
- gpr_r12_mips64, gpr_r13_mips64, gpr_r14_mips64, gpr_r15_mips64,
- gpr_r16_mips64, gpr_r17_mips64, gpr_r18_mips64, gpr_r19_mips64,
- gpr_r20_mips64, gpr_r21_mips64, gpr_r22_mips64, gpr_r23_mips64,
- gpr_r24_mips64, gpr_r25_mips64, gpr_r26_mips64, gpr_r27_mips64,
- gpr_gp_mips64, gpr_sp_mips64, gpr_r30_mips64, gpr_ra_mips64,
- gpr_sr_mips64, gpr_mullo_mips64, gpr_mulhi_mips64, gpr_badvaddr_mips64,
- gpr_cause_mips64, gpr_pc_mips64, gpr_ic_mips64, gpr_dummy_mips64};
-
-// Number of register sets provided by this context.
-enum { k_num_register_sets = 1 };
-
-static const RegisterSet g_reg_sets_mips64[k_num_register_sets] = {
- {"General Purpose Registers", "gpr", k_num_gpr_registers_mips64,
- g_gpr_regnums},
-};
-
bool RegisterContextPOSIX_mips64::IsGPR(unsigned reg) {
- return reg <= k_num_gpr_registers_mips64; // GPR's come first.
+ return reg < m_registers_count[gpr_registers_count]; // GPR's come first.
}
bool RegisterContextPOSIX_mips64::IsFPR(unsigned reg) {
- // XXX
+ int set = GetRegisterSetCount();
+ if (set > 1)
+ return reg < (m_registers_count[fpr_registers_count]
+ + m_registers_count[gpr_registers_count]);
return false;
}
@@ -60,6 +46,19 @@ RegisterContextPOSIX_mips64::RegisterContextPOSIX_mips64(
RegisterInfoInterface *register_info)
: RegisterContext(thread, concrete_frame_idx) {
m_register_info_ap.reset(register_info);
+ m_num_registers = GetRegisterCount();
+ int set = GetRegisterSetCount();
+
+ const RegisterSet *reg_set_ptr;
+ for(int i = 0; i < set; ++i) {
+ reg_set_ptr = GetRegisterSet(i);
+ m_registers_count[i] = reg_set_ptr->num_registers;
+ }
+
+ assert(m_num_registers ==
+ static_cast<uint32_t>(m_registers_count[gpr_registers_count] +
+ m_registers_count[fpr_registers_count] +
+ m_registers_count[msa_registers_count]));
// elf-core yet to support ReadFPR()
ProcessSP base = CalculateProcess();
@@ -74,18 +73,17 @@ void RegisterContextPOSIX_mips64::Invalidate() {}
void RegisterContextPOSIX_mips64::InvalidateAllRegisters() {}
unsigned RegisterContextPOSIX_mips64::GetRegisterOffset(unsigned reg) {
- assert(reg < k_num_registers_mips64 && "Invalid register number.");
+ assert(reg < m_num_registers && "Invalid register number.");
return GetRegisterInfo()[reg].byte_offset;
}
unsigned RegisterContextPOSIX_mips64::GetRegisterSize(unsigned reg) {
- assert(reg < k_num_registers_mips64 && "Invalid register number.");
+ assert(reg < m_num_registers && "Invalid register number.");
return GetRegisterInfo()[reg].byte_size;
}
size_t RegisterContextPOSIX_mips64::GetRegisterCount() {
- size_t num_registers = k_num_registers_mips64;
- return num_registers;
+ return m_register_info_ap->GetRegisterCount();
}
size_t RegisterContextPOSIX_mips64::GetGPRSize() {
@@ -101,31 +99,59 @@ const RegisterInfo *RegisterContextPOSIX_mips64::GetRegisterInfo() {
const RegisterInfo *
RegisterContextPOSIX_mips64::GetRegisterInfoAtIndex(size_t reg) {
- if (reg < k_num_registers_mips64)
+ if (reg < m_num_registers)
return &GetRegisterInfo()[reg];
else
return NULL;
}
size_t RegisterContextPOSIX_mips64::GetRegisterSetCount() {
- size_t sets = 0;
- for (size_t set = 0; set < k_num_register_sets; ++set) {
- if (IsRegisterSetAvailable(set))
- ++sets;
+ ArchSpec target_arch = m_register_info_ap->GetTargetArchitecture();
+ switch (target_arch.GetTriple().getOS()) {
+ case llvm::Triple::Linux: {
+ if ((target_arch.GetMachine() == llvm::Triple::mipsel) ||
+ (target_arch.GetMachine() == llvm::Triple::mips)) {
+ const auto *context = static_cast<const RegisterContextLinux_mips *>
+ (m_register_info_ap.get());
+ return context->GetRegisterSetCount();
+ }
+ const auto *context = static_cast<const RegisterContextLinux_mips64 *>
+ (m_register_info_ap.get());
+ return context->GetRegisterSetCount();
+ }
+ default: {
+ const auto *context = static_cast<const RegisterContextFreeBSD_mips64 *>
+ (m_register_info_ap.get());
+ return context->GetRegisterSetCount();
+ }
+
}
-
- return sets;
}
const RegisterSet *RegisterContextPOSIX_mips64::GetRegisterSet(size_t set) {
- if (IsRegisterSetAvailable(set))
- return &g_reg_sets_mips64[set];
- else
- return NULL;
+ ArchSpec target_arch = m_register_info_ap->GetTargetArchitecture();
+ switch (target_arch.GetTriple().getOS()) {
+ case llvm::Triple::Linux: {
+ if ((target_arch.GetMachine() == llvm::Triple::mipsel) ||
+ (target_arch.GetMachine() == llvm::Triple::mips)) {
+ const auto *context = static_cast<const RegisterContextLinux_mips *>
+ (m_register_info_ap.get());
+ return context->GetRegisterSet(set);
+ }
+ const auto *context = static_cast<const RegisterContextLinux_mips64 *>
+ (m_register_info_ap.get());
+ return context->GetRegisterSet(set);
+ }
+ default: {
+ const auto *context = static_cast<const RegisterContextFreeBSD_mips64 *>
+ (m_register_info_ap.get());
+ return context->GetRegisterSet(set);
+ }
+ }
}
const char *RegisterContextPOSIX_mips64::GetRegisterName(unsigned reg) {
- assert(reg < k_num_registers_mips64 && "Invalid register offset.");
+ assert(reg < m_num_registers && "Invalid register offset.");
return GetRegisterInfo()[reg].name;
}
@@ -141,7 +167,7 @@ lldb::ByteOrder RegisterContextPOSIX_mips64::GetByteOrder() {
}
bool RegisterContextPOSIX_mips64::IsRegisterSetAvailable(size_t set_index) {
- size_t num_sets = k_num_register_sets;
+ size_t num_sets = GetRegisterSetCount();
return (set_index < num_sets);
}
@@ -150,7 +176,7 @@ bool RegisterContextPOSIX_mips64::IsRegisterSetAvailable(size_t set_index) {
// object file sections that contain register numbers in them.
uint32_t RegisterContextPOSIX_mips64::ConvertRegisterKindToRegisterNumber(
lldb::RegisterKind kind, uint32_t num) {
- const uint32_t num_regs = GetRegisterCount();
+ const uint32_t num_regs = m_num_registers;
assert(kind < kNumRegisterKinds);
for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
index 90ff9d6..1695ec9 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
@@ -16,9 +16,8 @@
// Project includes
#include "RegisterContext_mips.h"
#include "RegisterInfoInterface.h"
-#include "lldb-mips-freebsd-register-enums.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/Log.h"
using namespace lldb_private;
@@ -26,6 +25,14 @@ class ProcessMonitor;
class RegisterContextPOSIX_mips64 : public lldb_private::RegisterContext {
public:
+
+ enum Register_count{
+ gpr_registers_count = 0,
+ fpr_registers_count,
+ msa_registers_count,
+ register_set_count
+ };
+
RegisterContextPOSIX_mips64(
lldb_private::Thread &thread, uint32_t concrete_frame_idx,
lldb_private::RegisterInfoInterface *register_info);
@@ -56,8 +63,8 @@ public:
uint32_t num) override;
protected:
- uint64_t
- m_gpr_mips64[k_num_gpr_registers_mips64]; // general purpose registers.
+ uint32_t m_num_registers;
+ uint8_t m_registers_count[register_set_count];
std::unique_ptr<lldb_private::RegisterInfoInterface>
m_register_info_ap; // Register Info Interface (FreeBSD or Linux)
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp
index 6a9838a..c2b73e2 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.cpp
@@ -12,13 +12,13 @@
#include <errno.h>
#include <stdint.h>
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
#include "Plugins/Process/elf-core/ProcessElfCore.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
index 79bb01f..50f2346 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
@@ -16,8 +16,8 @@
// Project includes
#include "RegisterContext_powerpc.h"
#include "RegisterInfoInterface.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/Log.h"
class ProcessMonitor;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp
index e4dbe33..b3365ee 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.cpp
@@ -11,14 +11,14 @@
#include <errno.h>
#include <stdint.h>
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
#include "RegisterContextPOSIX_s390x.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
index 1ffc45c..d533763 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
@@ -17,8 +17,8 @@
#include "RegisterContext_s390x.h"
#include "RegisterInfoInterface.h"
#include "lldb-s390x-register-enums.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/Log.h"
class ProcessMonitor;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
index 99525b6..5e1bf35 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
@@ -11,14 +11,14 @@
#include <errno.h>
#include <stdint.h>
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Host/Endian.h"
+#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
-#include "lldb/Target/Process.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Endian.h"
#include "llvm/Support/Compiler.h"
#include "RegisterContextPOSIX_x86.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
index c5afe08..aa68927 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
@@ -17,8 +17,8 @@
#include "RegisterContext_x86.h"
#include "RegisterInfoInterface.h"
#include "lldb-x86-register-enums.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/Log.h"
class ProcessMonitor;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
index 2b5cb00..96ad139 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
@@ -7,10 +7,10 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/Error.h"
#include "lldb/Target/OperatingSystem.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/Status.h"
#include "lldb/lldb-private.h"
#include "RegisterContextThreadMemory.h"
@@ -194,26 +194,26 @@ bool RegisterContextThreadMemory::HardwareSingleStep(bool enable) {
return false;
}
-Error RegisterContextThreadMemory::ReadRegisterValueFromMemory(
+Status RegisterContextThreadMemory::ReadRegisterValueFromMemory(
const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr,
uint32_t src_len, RegisterValue &reg_value) {
UpdateRegisterContext();
if (m_reg_ctx_sp)
return m_reg_ctx_sp->ReadRegisterValueFromMemory(reg_info, src_addr,
src_len, reg_value);
- Error error;
+ Status error;
error.SetErrorString("invalid register context");
return error;
}
-Error RegisterContextThreadMemory::WriteRegisterValueToMemory(
+Status RegisterContextThreadMemory::WriteRegisterValueToMemory(
const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr,
uint32_t dst_len, const RegisterValue &reg_value) {
UpdateRegisterContext();
if (m_reg_ctx_sp)
return m_reg_ctx_sp->WriteRegisterValueToMemory(reg_info, dst_addr, dst_len,
reg_value);
- Error error;
+ Status error;
error.SetErrorString("invalid register context");
return error;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
index 7e0a2a9..3b3b085 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
@@ -80,13 +80,13 @@ public:
bool HardwareSingleStep(bool enable) override;
- Error ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
- lldb::addr_t src_addr, uint32_t src_len,
- RegisterValue &reg_value) override;
+ Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
+ lldb::addr_t src_addr, uint32_t src_len,
+ RegisterValue &reg_value) override;
- Error WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
- lldb::addr_t dst_addr, uint32_t dst_len,
- const RegisterValue &reg_value) override;
+ Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
+ lldb::addr_t dst_addr, uint32_t dst_len,
+ const RegisterValue &reg_value) override;
protected:
void UpdateRegisterContext();
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h
index ab2ca2b..5f6fc29 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h
@@ -257,8 +257,7 @@ struct XMMReg {
struct FXSAVE {
uint16_t fctrl; // FPU Control Word (fcw)
uint16_t fstat; // FPU Status Word (fsw)
- uint8_t ftag; // FPU Tag Word (ftw)
- uint8_t reserved_1; // Reserved
+ uint16_t ftag; // FPU Tag Word (ftw)
uint16_t fop; // Last Instruction Opcode (fop)
union {
struct {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h
index 12db366..74d5d6e 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoInterface.h
@@ -13,6 +13,7 @@
#include <vector>
#include "lldb/Core/ArchSpec.h"
+#include "lldb/lldb-private-types.h"
namespace lldb_private {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm.cpp
index afa105f..0111b84 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextLinux_arm.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm.cpp
@@ -1,4 +1,4 @@
-//===-- RegisterContextLinux_arm.cpp ---------------------------*- C++ -*-===//
+//===-- RegisterInfoPOSIX_arm.cpp ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -14,37 +14,35 @@
#include "lldb/lldb-defines.h"
#include "llvm/Support/Compiler.h"
-#include "RegisterContextLinux_arm.h"
+#include "RegisterInfoPOSIX_arm.h"
using namespace lldb;
using namespace lldb_private;
// Based on RegisterContextDarwin_arm.cpp
#define GPR_OFFSET(idx) ((idx)*4)
-#define FPU_OFFSET(idx) ((idx)*4 + sizeof(RegisterContextLinux_arm::GPR))
+#define FPU_OFFSET(idx) ((idx)*4 + sizeof(RegisterInfoPOSIX_arm::GPR))
#define FPSCR_OFFSET \
- (LLVM_EXTENSION offsetof(RegisterContextLinux_arm::FPU, fpscr) + \
- sizeof(RegisterContextLinux_arm::GPR))
+ (LLVM_EXTENSION offsetof(RegisterInfoPOSIX_arm::FPU, fpscr) + \
+ sizeof(RegisterInfoPOSIX_arm::GPR))
#define EXC_OFFSET(idx) \
- ((idx)*4 + sizeof(RegisterContextLinux_arm::GPR) + \
- sizeof(RegisterContextLinux_arm::FPU))
+ ((idx)*4 + sizeof(RegisterInfoPOSIX_arm::GPR) + \
+ sizeof(RegisterInfoPOSIX_arm::FPU))
#define DBG_OFFSET(reg) \
- ((LLVM_EXTENSION offsetof(RegisterContextLinux_arm::DBG, reg) + \
- sizeof(RegisterContextLinux_arm::GPR) + \
- sizeof(RegisterContextLinux_arm::FPU) + \
- sizeof(RegisterContextLinux_arm::EXC)))
+ ((LLVM_EXTENSION offsetof(RegisterInfoPOSIX_arm::DBG, reg) + \
+ sizeof(RegisterInfoPOSIX_arm::GPR) + sizeof(RegisterInfoPOSIX_arm::FPU) + \
+ sizeof(RegisterInfoPOSIX_arm::EXC)))
#define DEFINE_DBG(reg, i) \
- #reg, NULL, sizeof(((RegisterContextLinux_arm::DBG *) NULL)->reg[i]), \
+ #reg, NULL, sizeof(((RegisterInfoPOSIX_arm::DBG *) NULL)->reg[i]), \
DBG_OFFSET(reg[i]), eEncodingUint, eFormatHex, \
{LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
dbg_##reg##i }, \
NULL, NULL, NULL, 0
#define REG_CONTEXT_SIZE \
- (sizeof(RegisterContextLinux_arm::GPR) + \
- sizeof(RegisterContextLinux_arm::FPU) + \
- sizeof(RegisterContextLinux_arm::EXC))
+ (sizeof(RegisterInfoPOSIX_arm::GPR) + sizeof(RegisterInfoPOSIX_arm::FPU) + \
+ sizeof(RegisterInfoPOSIX_arm::EXC))
//-----------------------------------------------------------------------------
// Include RegisterInfos_arm to declare our g_register_infos_arm structure.
@@ -76,21 +74,21 @@ GetRegisterInfoCount(const lldb_private::ArchSpec &target_arch) {
}
}
-RegisterContextLinux_arm::RegisterContextLinux_arm(
+RegisterInfoPOSIX_arm::RegisterInfoPOSIX_arm(
const lldb_private::ArchSpec &target_arch)
: lldb_private::RegisterInfoInterface(target_arch),
m_register_info_p(GetRegisterInfoPtr(target_arch)),
m_register_info_count(GetRegisterInfoCount(target_arch)) {}
-size_t RegisterContextLinux_arm::GetGPRSize() const {
- return sizeof(struct RegisterContextLinux_arm::GPR);
+size_t RegisterInfoPOSIX_arm::GetGPRSize() const {
+ return sizeof(struct RegisterInfoPOSIX_arm::GPR);
}
const lldb_private::RegisterInfo *
-RegisterContextLinux_arm::GetRegisterInfo() const {
+RegisterInfoPOSIX_arm::GetRegisterInfo() const {
return m_register_info_p;
}
-uint32_t RegisterContextLinux_arm::GetRegisterCount() const {
+uint32_t RegisterInfoPOSIX_arm::GetRegisterCount() const {
return m_register_info_count;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm.h
index 422ecb7..d90aec1 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextFreeBSD_arm.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm.h
@@ -1,4 +1,4 @@
-//===-- RegisterContextFreeBSD_arm.h ----------------------------*- C++ -*-===//
+//===-- RegisterInfoPOSIX_arm.h ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,14 +7,14 @@
//
//===----------------------------------------------------------------------===//
-#ifndef liblldb_RegisterContextFreeBSD_arm_h_
-#define liblldb_RegisterContextFreeBSD_arm_h_
+#ifndef liblldb_RegisterInfoPOSIX_arm_h_
+#define liblldb_RegisterInfoPOSIX_arm_h_
#include "RegisterInfoInterface.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/lldb-private.h"
-class RegisterContextFreeBSD_arm : public lldb_private::RegisterInfoInterface {
+class RegisterInfoPOSIX_arm : public lldb_private::RegisterInfoInterface {
public:
struct GPR {
uint32_t r[16]; // R0-R15
@@ -46,7 +46,7 @@ public:
uint32_t wcr[16];
};
- RegisterContextFreeBSD_arm(const lldb_private::ArchSpec &target_arch);
+ RegisterInfoPOSIX_arm(const lldb_private::ArchSpec &target_arch);
size_t GetGPRSize() const override;
@@ -59,4 +59,4 @@ private:
uint32_t m_register_info_count;
};
-#endif // liblldb_RegisterContextFreeBSD_arm_h_
+#endif // liblldb_RegisterInfoPOSIX_arm_h_
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64.h
index 2ba8059..8861ecd 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterInfos_x86_64.h
@@ -148,7 +148,7 @@
DR_OFFSET(i), eEncodingUint, eFormatHex, \
{LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, \
- LLDB_INVALID_REGNUM }, \
+ lldb_##reg##i##_x86_64 }, \
nullptr, nullptr, nullptr, 0 \
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
index 3b29a18..435f3d1 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
@@ -15,7 +15,6 @@
// Project includes
#include "lldb/Breakpoint/Watchpoint.h"
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Target/ExecutionContext.h"
@@ -25,6 +24,7 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlan.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
index b3cac1c..5ff928c 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
@@ -24,15 +24,11 @@ ThreadMemory::ThreadMemory(Process &process, tid_t tid,
: Thread(process, tid), m_backing_thread_sp(),
m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {}
-ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid, const char *name,
- const char *queue, lldb::addr_t register_data_addr)
+ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid,
+ llvm::StringRef name, llvm::StringRef queue,
+ lldb::addr_t register_data_addr)
: Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(),
- m_name(), m_queue(), m_register_data_addr(register_data_addr) {
- if (name)
- m_name = name;
- if (queue)
- m_queue = queue;
-}
+ m_name(name), m_queue(queue), m_register_data_addr(register_data_addr) {}
ThreadMemory::~ThreadMemory() { DestroyThread(); }
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.h
index 095544d..8922971 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.h
@@ -24,7 +24,7 @@ public:
const lldb::ValueObjectSP &thread_info_valobj_sp);
ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
- const char *name, const char *queue,
+ llvm::StringRef name, llvm::StringRef queue,
lldb::addr_t register_data_addr);
~ThreadMemory() override;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
index 6e2a9a9..2b34bdd 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/Function.h"
@@ -17,6 +16,7 @@
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/Log.h"
#include "RegisterContextLLDB.h"
#include "UnwindLLDB.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h
index b932303..3f84649 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h
@@ -16,11 +16,11 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/ConstString.h"
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Unwind.h"
+#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-public.h"
namespace lldb_private {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
index e2691be..f907735 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
@@ -105,7 +105,7 @@ size_t UnwindMacOSXFrameBackchain::GetStackFrameData_i386(
m_cursors.push_back(cursor);
const size_t k_frame_size = sizeof(frame);
- Error error;
+ Status error;
while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0)) {
// Read both the FP and PC (8 bytes)
if (process->ReadMemory(frame.fp, &frame.fp, k_frame_size, error) !=
@@ -196,7 +196,7 @@ size_t UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64(
Frame_x86_64 frame = {cursor.fp, cursor.pc};
m_cursors.push_back(cursor);
- Error error;
+ Status error;
const size_t k_frame_size = sizeof(frame);
while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0)) {
// Read both the FP and PC (16 bytes)
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 6ac308f..71eb643 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -14,8 +14,6 @@
#include <mutex>
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
@@ -25,8 +23,12 @@
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataBufferLLVM.h"
+#include "lldb/Utility/Log.h"
-#include "llvm/Support/ELF.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/Support/Threading.h"
#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
@@ -56,9 +58,12 @@ lldb::ProcessSP ProcessElfCore::CreateInstance(lldb::TargetSP target_sp,
lldb::ProcessSP process_sp;
if (crash_file) {
// Read enough data for a ELF32 header or ELF64 header
+ // Note: Here we care about e_type field only, so it is safe
+ // to ignore possible presence of the header extension.
const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
- lldb::DataBufferSP data_sp(crash_file->ReadFileContents(0, header_size));
+ auto data_sp = DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(),
+ header_size, 0);
if (data_sp && data_sp->GetByteSize() == header_size &&
elf::ELFHeader::MagicBytesMatch(data_sp->GetBytes())) {
elf::ELFHeader elf_header;
@@ -79,8 +84,8 @@ bool ProcessElfCore::CanDebug(lldb::TargetSP target_sp,
// For now we are just making sure the file exists for a given module
if (!m_core_module_sp && m_core_file.Exists()) {
ModuleSpec core_module_spec(m_core_file, target_sp->GetArchitecture());
- Error error(ModuleList::GetSharedModule(core_module_spec, m_core_module_sp,
- NULL, NULL, NULL));
+ Status error(ModuleList::GetSharedModule(core_module_spec, m_core_module_sp,
+ NULL, NULL, NULL));
if (m_core_module_sp) {
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
if (core_objfile && core_objfile->GetType() == ObjectFile::eTypeCoreFile)
@@ -152,8 +157,8 @@ lldb::addr_t ProcessElfCore::AddAddressRangeFromLoadSegment(
//----------------------------------------------------------------------
// Process Control
//----------------------------------------------------------------------
-Error ProcessElfCore::DoLoadCore() {
- Error error;
+Status ProcessElfCore::DoLoadCore() {
+ Status error;
if (!m_core_module_sp) {
error.SetErrorString("invalid core module");
return error;
@@ -209,16 +214,19 @@ Error ProcessElfCore::DoLoadCore() {
// Even if the architecture is set in the target, we need to override
// it to match the core file which is always single arch.
ArchSpec arch(m_core_module_sp->GetArchitecture());
- if (arch.IsValid())
- GetTarget().SetArchitecture(arch);
+ ArchSpec target_arch = GetTarget().GetArchitecture();
+ ArchSpec core_arch(m_core_module_sp->GetArchitecture());
+ target_arch.MergeFrom(core_arch);
+ GetTarget().SetArchitecture(target_arch);
+
SetUnixSignals(UnixSignals::Create(GetArchitecture()));
// Ensure we found at least one thread that was stopped on a signal.
bool siginfo_signal_found = false;
bool prstatus_signal_found = false;
// Check we found a signal in a SIGINFO note.
- for (const auto &thread_data: m_thread_data) {
+ for (const auto &thread_data : m_thread_data) {
if (thread_data.signo != 0)
siginfo_signal_found = true;
if (thread_data.prstatus_sig != 0)
@@ -228,7 +236,7 @@ Error ProcessElfCore::DoLoadCore() {
// If we don't have signal from SIGINFO use the signal from each threads
// PRSTATUS note.
if (prstatus_signal_found) {
- for (auto &thread_data: m_thread_data)
+ for (auto &thread_data : m_thread_data)
thread_data.signo = thread_data.prstatus_sig;
} else if (m_thread_data.size() > 0) {
// If all else fails force the first thread to be SIGSTOP
@@ -281,7 +289,7 @@ bool ProcessElfCore::UpdateThreadList(ThreadList &old_thread_list,
void ProcessElfCore::RefreshStateAfterStop() {}
-Error ProcessElfCore::DoDestroy() { return Error(); }
+Status ProcessElfCore::DoDestroy() { return Status(); }
//------------------------------------------------------------------
// Process Queries
@@ -293,14 +301,14 @@ bool ProcessElfCore::IsAlive() { return true; }
// Process Memory
//------------------------------------------------------------------
size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
// Don't allow the caching that lldb_private::Process::ReadMemory does
// since in core files we have it all cached our our core file anyway.
return DoReadMemory(addr, buf, size, error);
}
-Error ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr,
- MemoryRegionInfo &region_info) {
+Status ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &region_info) {
region_info.Clear();
const VMRangeToPermissions::Entry *permission_entry =
m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
@@ -327,7 +335,7 @@ Error ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr,
region_info.SetExecutable(MemoryRegionInfo::eNo);
region_info.SetMapped(MemoryRegionInfo::eNo);
}
- return Error();
+ return Status();
}
region_info.GetRange().SetRangeBase(load_addr);
@@ -336,11 +344,11 @@ Error ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr,
region_info.SetWritable(MemoryRegionInfo::eNo);
region_info.SetExecutable(MemoryRegionInfo::eNo);
region_info.SetMapped(MemoryRegionInfo::eNo);
- return Error();
+ return Status();
}
size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
if (core_objfile == NULL)
@@ -365,6 +373,10 @@ size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb::addr_t bytes_left =
0; // Number of bytes available in the core file from the given address
+ // Don't proceed if core file doesn't contain the actual data for this address range.
+ if (file_start == file_end)
+ return 0;
+
// Figure out how many on-disk bytes remain in this segment
// starting at the given offset
if (file_end > file_start + offset)
@@ -398,9 +410,9 @@ void ProcessElfCore::Clear() {
}
void ProcessElfCore::Initialize() {
- static std::once_flag g_once_flag;
+ static llvm::once_flag g_once_flag;
- std::call_once(g_once_flag, []() {
+ llvm::call_once(g_once_flag, []() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(), CreateInstance);
});
@@ -426,6 +438,10 @@ enum {
NT_FILE = 0x46494c45,
NT_PRXFPREG = 0x46e62b7f,
NT_SIGINFO = 0x53494749,
+ NT_OPENBSD_PROCINFO = 10,
+ NT_OPENBSD_AUXV = 11,
+ NT_OPENBSD_REGS = 20,
+ NT_OPENBSD_FPREGS = 21,
};
namespace FREEBSD {
@@ -440,6 +456,11 @@ enum {
};
}
+namespace NETBSD {
+
+enum { NT_PROCINFO = 1, NT_AUXV, NT_AMD64_REGS = 33, NT_AMD64_FPREGS = 35 };
+}
+
// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
static void ParseFreeBSDPrStatus(ThreadData &thread_data, DataExtractor &data,
ArchSpec &arch) {
@@ -476,6 +497,28 @@ static void ParseFreeBSDThrMisc(ThreadData &thread_data, DataExtractor &data) {
thread_data.name = data.GetCStr(&offset, 20);
}
+static void ParseNetBSDProcInfo(ThreadData &thread_data, DataExtractor &data) {
+ lldb::offset_t offset = 0;
+
+ int version = data.GetU32(&offset);
+ if (version != 1)
+ return;
+
+ offset += 4;
+ thread_data.signo = data.GetU32(&offset);
+}
+
+static void ParseOpenBSDProcInfo(ThreadData &thread_data, DataExtractor &data) {
+ lldb::offset_t offset = 0;
+
+ int version = data.GetU32(&offset);
+ if (version != 1)
+ return;
+
+ offset += 4;
+ thread_data.signo = data.GetU32(&offset);
+}
+
/// Parse Thread context from PT_NOTE segment and store it in the thread list
/// Notes:
/// 1) A PT_NOTE segment is composed of one or more NOTE entries.
@@ -497,7 +540,7 @@ static void ParseFreeBSDThrMisc(ThreadData &thread_data, DataExtractor &data) {
/// new thread when it finds NT_PRSTATUS or NT_PRPSINFO NOTE entry.
/// For case (b) there may be either one NT_PRPSINFO per thread, or a single
/// one that applies to all threads (depending on the platform type).
-Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
+Status ProcessElfCore::ParseThreadContextsFromNoteSegment(
const elf::ELFProgramHeader *segment_header, DataExtractor segment_data) {
assert(segment_header && segment_header->p_type == llvm::ELF::PT_NOTE);
@@ -512,7 +555,7 @@ Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
ELFLinuxSigInfo siginfo;
size_t header_size;
size_t len;
- Error error;
+ Status error;
// Loop through the NOTE entires in the segment
while (offset < segment_header->p_filesz) {
@@ -564,6 +607,39 @@ Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
default:
break;
}
+ } else if (note.n_name.substr(0, 11) == "NetBSD-CORE") {
+ // NetBSD per-thread information is stored in notes named
+ // "NetBSD-CORE@nnn" so match on the initial part of the string.
+ m_os = llvm::Triple::NetBSD;
+ if (note.n_type == NETBSD::NT_PROCINFO) {
+ ParseNetBSDProcInfo(*thread_data, note_data);
+ } else if (note.n_type == NETBSD::NT_AUXV) {
+ m_auxv = DataExtractor(note_data);
+ } else if (arch.GetMachine() == llvm::Triple::x86_64 &&
+ note.n_type == NETBSD::NT_AMD64_REGS) {
+ thread_data->gpregset = note_data;
+ } else if (arch.GetMachine() == llvm::Triple::x86_64 &&
+ note.n_type == NETBSD::NT_AMD64_FPREGS) {
+ thread_data->fpregset = note_data;
+ }
+ } else if (note.n_name.substr(0, 7) == "OpenBSD") {
+ // OpenBSD per-thread information is stored in notes named
+ // "OpenBSD@nnn" so match on the initial part of the string.
+ m_os = llvm::Triple::OpenBSD;
+ switch (note.n_type) {
+ case NT_OPENBSD_PROCINFO:
+ ParseOpenBSDProcInfo(*thread_data, note_data);
+ break;
+ case NT_OPENBSD_AUXV:
+ m_auxv = DataExtractor(note_data);
+ break;
+ case NT_OPENBSD_REGS:
+ thread_data->gpregset = note_data;
+ break;
+ case NT_OPENBSD_FPREGS:
+ thread_data->fpregset = note_data;
+ break;
+ }
} else if (note.n_name == "CORE") {
switch (note.n_type) {
case NT_PRSTATUS:
@@ -583,6 +659,8 @@ Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
// The result from FXSAVE is in NT_PRXFPREG for i386 core files
if (arch.GetCore() == ArchSpec::eCore_x86_64_x86_64)
thread_data->fpregset = note_data;
+ else if(arch.IsMIPS())
+ thread_data->fpregset = note_data;
break;
case NT_PRPSINFO:
have_prpsinfo = true;
@@ -650,6 +728,12 @@ ArchSpec ProcessElfCore::GetArchitecture() {
(ObjectFileELF *)(m_core_module_sp->GetObjectFile());
ArchSpec arch;
core_file->GetArchitecture(arch);
+
+ ArchSpec target_arch = GetTarget().GetArchitecture();
+
+ if (target_arch.IsMIPS())
+ return target_arch;
+
return arch;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
index a8dde47..dbf7f92 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -24,9 +24,9 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/ConstString.h"
-#include "lldb/Core/Error.h"
#include "lldb/Target/Process.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Status.h"
#include "Plugins/ObjectFile/ELF/ELFHeader.h"
@@ -66,7 +66,7 @@ public:
//------------------------------------------------------------------
// Creating a new process, or attaching to an existing one
//------------------------------------------------------------------
- lldb_private::Error DoLoadCore() override;
+ lldb_private::Status DoLoadCore() override;
lldb_private::DynamicLoader *GetDynamicLoader() override;
@@ -80,7 +80,7 @@ public:
//------------------------------------------------------------------
// Process Control
//------------------------------------------------------------------
- lldb_private::Error DoDestroy() override;
+ lldb_private::Status DoDestroy() override;
void RefreshStateAfterStop() override;
@@ -93,12 +93,12 @@ public:
// Process Memory
//------------------------------------------------------------------
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
- lldb_private::Error
+ lldb_private::Status
GetMemoryRegionInfo(lldb::addr_t load_addr,
lldb_private::MemoryRegionInfo &region_info) override;
@@ -160,7 +160,7 @@ private:
std::vector<NT_FILE_Entry> m_nt_file_entries;
// Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
- lldb_private::Error ParseThreadContextsFromNoteSegment(
+ lldb_private::Status ParseThreadContextsFromNoteSegment(
const elf::ELFProgramHeader *segment_header,
lldb_private::DataExtractor segment_data);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
index c0850e5..e095eac 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
@@ -15,8 +15,8 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Process/Utility/RegisterContextPOSIX_arm.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
class RegisterContextCorePOSIX_arm : public RegisterContextPOSIX_arm {
public:
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
index da3e5bf..3a2bbdb 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
@@ -15,8 +15,8 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Process/Utility/RegisterContextPOSIX_arm64.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
class RegisterContextCorePOSIX_arm64 : public RegisterContextPOSIX_arm64 {
public:
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
index 6a168d3..7549cf0 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
@@ -22,6 +22,10 @@ RegisterContextCorePOSIX_mips64::RegisterContextCorePOSIX_mips64(
new DataBufferHeap(gpregset.GetDataStart(), gpregset.GetByteSize()));
m_gpr.SetData(m_gpr_buffer);
m_gpr.SetByteOrder(gpregset.GetByteOrder());
+ m_fpr_buffer.reset(
+ new DataBufferHeap(fpregset.GetDataStart(), fpregset.GetByteSize()));
+ m_fpr.SetData(m_fpr_buffer);
+ m_fpr.SetByteOrder(fpregset.GetByteOrder());
}
RegisterContextCorePOSIX_mips64::~RegisterContextCorePOSIX_mips64() {}
@@ -42,12 +46,24 @@ bool RegisterContextCorePOSIX_mips64::WriteFPR() {
bool RegisterContextCorePOSIX_mips64::ReadRegister(const RegisterInfo *reg_info,
RegisterValue &value) {
+
lldb::offset_t offset = reg_info->byte_offset;
- uint64_t v = m_gpr.GetMaxU64(&offset, reg_info->byte_size);
- if (offset == reg_info->byte_offset + reg_info->byte_size) {
+ lldb_private::ArchSpec arch = m_register_info_ap->GetTargetArchitecture();
+ uint64_t v;
+ if (IsGPR(reg_info->kinds[lldb::eRegisterKindLLDB])) {
+ if (reg_info->byte_size == 4 && !(arch.GetMachine() == llvm::Triple::mips64el))
+ // In case of 32bit core file, the register data are placed at 4 byte
+ // offset.
+ offset = offset / 2;
+ v = m_gpr.GetMaxU64(&offset, reg_info->byte_size);
value = v;
return true;
- }
+ } else if (IsFPR(reg_info->kinds[lldb::eRegisterKindLLDB])) {
+ offset = offset - sizeof(GPR_linux_mips);
+ v =m_fpr.GetMaxU64(&offset, reg_info->byte_size);
+ value = v;
+ return true;
+ }
return false;
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
index b1deca3..2cb527a 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
@@ -15,8 +15,8 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
class RegisterContextCorePOSIX_mips64 : public RegisterContextPOSIX_mips64 {
public:
@@ -51,7 +51,9 @@ protected:
private:
lldb::DataBufferSP m_gpr_buffer;
+ lldb::DataBufferSP m_fpr_buffer;
lldb_private::DataExtractor m_gpr;
+ lldb_private::DataExtractor m_fpr;
};
#endif // liblldb_RegisterContextCorePOSIX_mips64_h_
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
index edfa190..62f6413 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
@@ -9,9 +9,9 @@
#include "RegisterContextPOSIXCore_powerpc.h"
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
using namespace lldb_private;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
index 8e6315f..aaa95e5 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
@@ -15,7 +15,7 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h"
-#include "lldb/Core/DataExtractor.h"
+#include "lldb/Utility/DataExtractor.h"
class RegisterContextCorePOSIX_powerpc : public RegisterContextPOSIX_powerpc {
public:
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
index 6db8177..b3530a8 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
@@ -9,9 +9,9 @@
#include "RegisterContextPOSIXCore_s390x.h"
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataBufferHeap.h"
using namespace lldb_private;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
index 516e5c5..2b4ae10 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
@@ -15,7 +15,7 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Process/Utility/RegisterContextPOSIX_s390x.h"
-#include "lldb/Core/DataExtractor.h"
+#include "lldb/Utility/DataExtractor.h"
class RegisterContextCorePOSIX_s390x : public RegisterContextPOSIX_s390x {
public:
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
index 7f8223f..5766923 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
@@ -8,9 +8,9 @@
//===----------------------------------------------------------------------===//
#include "RegisterContextPOSIXCore_x86_64.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataExtractor.h"
using namespace lldb_private;
@@ -71,7 +71,7 @@ bool RegisterContextCorePOSIX_x86_64::ReadRegister(const RegisterInfo *reg_info,
return false;
}
- Error error;
+ Status error;
value.SetFromMemoryData(reg_info, src + offset, reg_info->byte_size,
lldb::eByteOrderLittle, error);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 0143146..2f36622 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -7,22 +7,26 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Unwind.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Log.h"
-#include "Plugins/Process/Utility/RegisterContextFreeBSD_arm.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
#include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
-#include "Plugins/Process/Utility/RegisterContextLinux_arm.h"
+#include "Plugins/Process/Utility/RegisterContextLinux_mips64.h"
+#include "Plugins/Process/Utility/RegisterContextLinux_mips.h"
#include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
//#include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
#include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextNetBSD_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
+#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
#include "ProcessElfCore.h"
#include "RegisterContextPOSIXCore_arm.h"
@@ -88,7 +92,7 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
reg_interface = new RegisterInfoPOSIX_arm64(arch);
break;
case llvm::Triple::arm:
- reg_interface = new RegisterContextFreeBSD_arm(arch);
+ reg_interface = new RegisterInfoPOSIX_arm(arch);
break;
case llvm::Triple::ppc:
reg_interface = new RegisterContextFreeBSD_powerpc32(arch);
@@ -111,14 +115,33 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
break;
}
+ case llvm::Triple::NetBSD: {
+ switch (arch.GetMachine()) {
+ case llvm::Triple::x86_64:
+ reg_interface = new RegisterContextNetBSD_x86_64(arch);
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+
case llvm::Triple::Linux: {
switch (arch.GetMachine()) {
case llvm::Triple::arm:
- reg_interface = new RegisterContextLinux_arm(arch);
+ reg_interface = new RegisterInfoPOSIX_arm(arch);
break;
case llvm::Triple::aarch64:
reg_interface = new RegisterInfoPOSIX_arm64(arch);
break;
+ case llvm::Triple::mipsel:
+ case llvm::Triple::mips:
+ reg_interface = new RegisterContextLinux_mips(arch);
+ break;
+ case llvm::Triple::mips64el:
+ case llvm::Triple::mips64:
+ reg_interface = new RegisterContextLinux_mips64(arch);
+ break;
// case llvm::Triple::systemz:
// reg_interface = new RegisterContextLinux_s390x(arch);
// break;
@@ -134,6 +157,26 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
break;
}
+ case llvm::Triple::OpenBSD: {
+ switch (arch.GetMachine()) {
+ case llvm::Triple::aarch64:
+ reg_interface = new RegisterInfoPOSIX_arm64(arch);
+ break;
+ case llvm::Triple::arm:
+ reg_interface = new RegisterInfoPOSIX_arm(arch);
+ break;
+ case llvm::Triple::x86:
+ reg_interface = new RegisterContextOpenBSD_i386(arch);
+ break;
+ case llvm::Triple::x86_64:
+ reg_interface = new RegisterContextOpenBSD_x86_64(arch);
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+
default:
break;
}
@@ -154,7 +197,13 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_arm(
*this, reg_interface, m_gpregset_data, m_fpregset_data));
break;
+ case llvm::Triple::mipsel:
+ case llvm::Triple::mips:
+ m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64(
+ *this, reg_interface, m_gpregset_data, m_fpregset_data));
+ break;
case llvm::Triple::mips64:
+ case llvm::Triple::mips64el:
m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64(
*this, reg_interface, m_gpregset_data, m_fpregset_data));
break;
@@ -200,8 +249,33 @@ ELFLinuxPrStatus::ELFLinuxPrStatus() {
memset(this, 0, sizeof(ELFLinuxPrStatus));
}
-Error ELFLinuxPrStatus::Parse(DataExtractor &data, ArchSpec &arch) {
- Error error;
+size_t ELFLinuxPrStatus::GetSize(lldb_private::ArchSpec &arch) {
+ constexpr size_t mips_linux_pr_status_size_o32 = 96;
+ constexpr size_t mips_linux_pr_status_size_n32 = 72;
+ if (arch.IsMIPS()) {
+ std::string abi = arch.GetTargetABI();
+ assert(!abi.empty() && "ABI is not set");
+ if (!abi.compare("n64"))
+ return sizeof(ELFLinuxPrStatus);
+ else if (!abi.compare("o32"))
+ return mips_linux_pr_status_size_o32;
+ // N32 ABI
+ return mips_linux_pr_status_size_n32;
+ }
+ switch (arch.GetCore()) {
+ case lldb_private::ArchSpec::eCore_s390x_generic:
+ case lldb_private::ArchSpec::eCore_x86_64_x86_64:
+ return sizeof(ELFLinuxPrStatus);
+ case lldb_private::ArchSpec::eCore_x86_32_i386:
+ case lldb_private::ArchSpec::eCore_x86_32_i486:
+ return 72;
+ default:
+ return 0;
+ }
+}
+
+Status ELFLinuxPrStatus::Parse(DataExtractor &data, ArchSpec &arch) {
+ Status error;
if (GetSize(arch) > data.GetByteSize()) {
error.SetErrorStringWithFormat(
"NT_PRSTATUS size should be %zu, but the remaining bytes are: %" PRIu64,
@@ -239,7 +313,6 @@ Error ELFLinuxPrStatus::Parse(DataExtractor &data, ArchSpec &arch) {
pr_cstime.tv_sec = data.GetPointer(&offset);
pr_cstime.tv_usec = data.GetPointer(&offset);
-
return error;
}
@@ -250,8 +323,29 @@ ELFLinuxPrPsInfo::ELFLinuxPrPsInfo() {
memset(this, 0, sizeof(ELFLinuxPrPsInfo));
}
-Error ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch) {
- Error error;
+size_t ELFLinuxPrPsInfo::GetSize(lldb_private::ArchSpec &arch) {
+ constexpr size_t mips_linux_pr_psinfo_size_o32_n32 = 128;
+ if (arch.IsMIPS()) {
+ uint8_t address_byte_size = arch.GetAddressByteSize();
+ if (address_byte_size == 8)
+ return sizeof(ELFLinuxPrPsInfo);
+ return mips_linux_pr_psinfo_size_o32_n32;
+ }
+
+ switch (arch.GetCore()) {
+ case lldb_private::ArchSpec::eCore_s390x_generic:
+ case lldb_private::ArchSpec::eCore_x86_64_x86_64:
+ return sizeof(ELFLinuxPrPsInfo);
+ case lldb_private::ArchSpec::eCore_x86_32_i386:
+ case lldb_private::ArchSpec::eCore_x86_32_i486:
+ return 124;
+ default:
+ return 0;
+ }
+}
+
+Status ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch) {
+ Status error;
ByteOrder byteorder = data.GetByteOrder();
if (GetSize(arch) > data.GetByteSize()) {
error.SetErrorStringWithFormat(
@@ -273,9 +367,15 @@ Error ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch) {
pr_flag = data.GetPointer(&offset);
+ if (arch.IsMIPS()) {
+ // The pr_uid and pr_gid is always 32 bit irrespective of platforms
+ pr_uid = data.GetU32(&offset);
+ pr_gid = data.GetU32(&offset);
+ } else {
// 16 bit on 32 bit platforms, 32 bit on 64 bit platforms
pr_uid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
pr_gid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
+ }
pr_pid = data.GetU32(&offset);
pr_ppid = data.GetU32(&offset);
@@ -296,12 +396,25 @@ Error ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch) {
//----------------------------------------------------------------
// Parse SIGINFO from NOTE entry
//----------------------------------------------------------------
-ELFLinuxSigInfo::ELFLinuxSigInfo() {
- memset(this, 0, sizeof(ELFLinuxSigInfo));
+ELFLinuxSigInfo::ELFLinuxSigInfo() { memset(this, 0, sizeof(ELFLinuxSigInfo)); }
+
+size_t ELFLinuxSigInfo::GetSize(const lldb_private::ArchSpec &arch) {
+ if (arch.IsMIPS())
+ return sizeof(ELFLinuxSigInfo);
+ switch (arch.GetCore()) {
+ case lldb_private::ArchSpec::eCore_x86_64_x86_64:
+ return sizeof(ELFLinuxSigInfo);
+ case lldb_private::ArchSpec::eCore_s390x_generic:
+ case lldb_private::ArchSpec::eCore_x86_32_i386:
+ case lldb_private::ArchSpec::eCore_x86_32_i486:
+ return 12;
+ default:
+ return 0;
+ }
}
-Error ELFLinuxSigInfo::Parse(DataExtractor &data, const ArchSpec &arch) {
- Error error;
+Status ELFLinuxSigInfo::Parse(DataExtractor &data, const ArchSpec &arch) {
+ Status error;
if (GetSize(arch) > data.GetByteSize()) {
error.SetErrorStringWithFormat(
"NT_SIGINFO size should be %zu, but the remaining bytes are: %" PRIu64,
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 1957ac2..5218754 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -16,8 +16,8 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/DataExtractor.h"
struct compat_timeval {
alignas(8) uint64_t tv_sec;
@@ -57,26 +57,15 @@ struct ELFLinuxPrStatus {
ELFLinuxPrStatus();
- lldb_private::Error Parse(lldb_private::DataExtractor &data,
- lldb_private::ArchSpec &arch);
+ lldb_private::Status Parse(lldb_private::DataExtractor &data,
+ lldb_private::ArchSpec &arch);
// Return the bytesize of the structure
// 64 bit - just sizeof
// 32 bit - hardcoded because we are reusing the struct, but some of the
// members are smaller -
// so the layout is not the same
- static size_t GetSize(lldb_private::ArchSpec &arch) {
- switch (arch.GetCore()) {
- case lldb_private::ArchSpec::eCore_s390x_generic:
- case lldb_private::ArchSpec::eCore_x86_64_x86_64:
- return sizeof(ELFLinuxPrStatus);
- case lldb_private::ArchSpec::eCore_x86_32_i386:
- case lldb_private::ArchSpec::eCore_x86_32_i486:
- return 72;
- default:
- return 0;
- }
- }
+ static size_t GetSize(lldb_private::ArchSpec &arch);
};
static_assert(sizeof(ELFLinuxPrStatus) == 112,
@@ -89,26 +78,15 @@ struct ELFLinuxSigInfo {
ELFLinuxSigInfo();
- lldb_private::Error Parse(lldb_private::DataExtractor &data,
- const lldb_private::ArchSpec &arch);
+ lldb_private::Status Parse(lldb_private::DataExtractor &data,
+ const lldb_private::ArchSpec &arch);
// Return the bytesize of the structure
// 64 bit - just sizeof
// 32 bit - hardcoded because we are reusing the struct, but some of the
// members are smaller -
// so the layout is not the same
- static size_t GetSize(const lldb_private::ArchSpec &arch) {
- switch (arch.GetCore()) {
- case lldb_private::ArchSpec::eCore_x86_64_x86_64:
- return sizeof(ELFLinuxSigInfo);
- case lldb_private::ArchSpec::eCore_s390x_generic:
- case lldb_private::ArchSpec::eCore_x86_32_i386:
- case lldb_private::ArchSpec::eCore_x86_32_i486:
- return 12;
- default:
- return 0;
- }
- }
+ static size_t GetSize(const lldb_private::ArchSpec &arch);
};
static_assert(sizeof(ELFLinuxSigInfo) == 12,
@@ -135,26 +113,15 @@ struct ELFLinuxPrPsInfo {
ELFLinuxPrPsInfo();
- lldb_private::Error Parse(lldb_private::DataExtractor &data,
- lldb_private::ArchSpec &arch);
+ lldb_private::Status Parse(lldb_private::DataExtractor &data,
+ lldb_private::ArchSpec &arch);
// Return the bytesize of the structure
// 64 bit - just sizeof
// 32 bit - hardcoded because we are reusing the struct, but some of the
// members are smaller -
// so the layout is not the same
- static size_t GetSize(lldb_private::ArchSpec &arch) {
- switch (arch.GetCore()) {
- case lldb_private::ArchSpec::eCore_s390x_generic:
- case lldb_private::ArchSpec::eCore_x86_64_x86_64:
- return sizeof(ELFLinuxPrPsInfo);
- case lldb_private::ArchSpec::eCore_x86_32_i386:
- case lldb_private::ArchSpec::eCore_x86_32_i486:
- return 124;
- default:
- return 0;
- }
- }
+ static size_t GetSize(lldb_private::ArchSpec &arch);
};
static_assert(sizeof(ELFLinuxPrPsInfo) == 136,
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index bd87521..0c4df7e 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -16,12 +16,8 @@
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/Log.h"
-#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Pipe.h"
@@ -30,6 +26,10 @@
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/RegularExpression.h"
+#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -72,7 +72,7 @@ void GDBRemoteCommunication::History::AddPacket(char packet_char,
m_packets[idx].type = type;
m_packets[idx].bytes_transmitted = bytes_transmitted;
m_packets[idx].packet_idx = m_total_packet_count;
- m_packets[idx].tid = Host::GetCurrentThreadID();
+ m_packets[idx].tid = llvm::get_threadid();
}
}
@@ -87,7 +87,7 @@ void GDBRemoteCommunication::History::AddPacket(const std::string &src,
m_packets[idx].type = type;
m_packets[idx].bytes_transmitted = bytes_transmitted;
m_packets[idx].packet_idx = m_total_packet_count;
- m_packets[idx].tid = Host::GetCurrentThreadID();
+ m_packets[idx].tid = llvm::get_threadid();
}
}
@@ -319,10 +319,9 @@ GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote &packet,
Timeout<std::micro> timeout,
bool sync_on_timeout) {
uint8_t buffer[8192];
- Error error;
+ Status error;
- Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS |
- GDBR_LOG_VERBOSE));
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
// Check for a packet from our cache first without trying any reading...
if (CheckForPacket(NULL, 0, packet) != PacketType::Invalid)
@@ -334,12 +333,11 @@ GDBRemoteCommunication::WaitForPacketNoLock(StringExtractorGDBRemote &packet,
lldb::ConnectionStatus status = eConnectionStatusNoConnection;
size_t bytes_read = Read(buffer, sizeof(buffer), timeout, status, &error);
- if (log)
- log->Printf("%s: Read (buffer, (sizeof(buffer), timeout = %ld us, "
- "status = %s, error = %s) => bytes_read = %" PRIu64,
- LLVM_PRETTY_FUNCTION, long(timeout ? timeout->count() : -1),
- Communication::ConnectionStatusAsCString(status),
- error.AsCString(), (uint64_t)bytes_read);
+ LLDB_LOGV(log,
+ "Read(buffer, sizeof(buffer), timeout = {0}, "
+ "status = {1}, error = {2}) => bytes_read = {3}",
+ timeout, Communication::ConnectionStatusAsCString(status), error,
+ bytes_read);
if (bytes_read > 0) {
if (CheckForPacket(buffer, bytes_read, packet) != PacketType::Invalid)
@@ -607,10 +605,10 @@ bool GDBRemoteCommunication::DecompressPacket() {
m_compression_type == CompressionType::LZFSE ||
m_compression_type == CompressionType::LZ4)) {
compression_algorithm compression_type;
- if (m_compression_type == CompressionType::ZlibDeflate)
- compression_type = COMPRESSION_ZLIB;
- else if (m_compression_type == CompressionType::LZFSE)
+ if (m_compression_type == CompressionType::LZFSE)
compression_type = COMPRESSION_LZFSE;
+ else if (m_compression_type == CompressionType::ZlibDeflate)
+ compression_type = COMPRESSION_ZLIB;
else if (m_compression_type == CompressionType::LZ4)
compression_type = COMPRESSION_LZ4_RAW;
else if (m_compression_type == CompressionType::LZMA)
@@ -935,9 +933,9 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
return GDBRemoteCommunication::PacketType::Invalid;
}
-Error GDBRemoteCommunication::StartListenThread(const char *hostname,
- uint16_t port) {
- Error error;
+Status GDBRemoteCommunication::StartListenThread(const char *hostname,
+ uint16_t port) {
+ Status error;
if (m_listen_thread.IsJoinable()) {
error.SetErrorString("listen thread already running");
} else {
@@ -964,7 +962,7 @@ bool GDBRemoteCommunication::JoinListenThread() {
lldb::thread_result_t
GDBRemoteCommunication::ListenThread(lldb::thread_arg_t arg) {
GDBRemoteCommunication *comm = (GDBRemoteCommunication *)arg;
- Error error;
+ Status error;
ConnectionFileDescriptor *connection =
(ConnectionFileDescriptor *)comm->GetConnection();
@@ -977,7 +975,7 @@ GDBRemoteCommunication::ListenThread(lldb::thread_arg_t arg) {
return NULL;
}
-Error GDBRemoteCommunication::StartDebugserverProcess(
+Status GDBRemoteCommunication::StartDebugserverProcess(
const char *url, Platform *platform, ProcessLaunchInfo &launch_info,
uint16_t *port, const Args *inferior_args, int pass_comm_fd) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
@@ -986,7 +984,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess(
__FUNCTION__, url ? url : "<empty>",
port ? *port : uint16_t(0));
- Error error;
+ Status error;
// If we locate debugserver, keep that located version around
static FileSpec g_debugserver_file_spec;
@@ -1085,8 +1083,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess(
// port is null when debug server should listen on domain socket -
// we're not interested in port value but rather waiting for debug server
// to become available.
- if (pass_comm_fd == -1 &&
- ((port != nullptr && *port == 0) || port == nullptr)) {
+ if (pass_comm_fd == -1) {
if (url) {
// Create a temporary file to get the stdout/stderr and redirect the
// output of the command into this file. We will later read this file
@@ -1258,11 +1255,21 @@ Error GDBRemoteCommunication::StartDebugserverProcess(
port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
if (error.Success() && (port != nullptr)) {
assert(num_bytes > 0 && port_cstr[num_bytes - 1] == '\0');
- *port = StringConvert::ToUInt32(port_cstr, 0);
- if (log)
- log->Printf("GDBRemoteCommunication::%s() "
- "debugserver listens %u port",
- __FUNCTION__, *port);
+ uint16_t child_port = StringConvert::ToUInt32(port_cstr, 0);
+ if (*port == 0 || *port == child_port) {
+ *port = child_port;
+ if (log)
+ log->Printf("GDBRemoteCommunication::%s() "
+ "debugserver listens %u port",
+ __FUNCTION__, *port);
+ } else {
+ if (log)
+ log->Printf("GDBRemoteCommunication::%s() "
+ "debugserver listening on port "
+ "%d but requested port was %d",
+ __FUNCTION__, (uint32_t)child_port,
+ (uint32_t)(*port));
+ }
} else {
if (log)
log->Printf("GDBRemoteCommunication::%s() "
@@ -1303,12 +1310,20 @@ void GDBRemoteCommunication::DumpHistory(Stream &strm) { m_history.Dump(strm); }
GDBRemoteCommunication::ScopedTimeout::ScopedTimeout(
GDBRemoteCommunication &gdb_comm, std::chrono::seconds timeout)
- : m_gdb_comm(gdb_comm) {
- m_saved_timeout = m_gdb_comm.SetPacketTimeout(timeout);
+ : m_gdb_comm(gdb_comm), m_timeout_modified(false) {
+ auto curr_timeout = gdb_comm.GetPacketTimeout();
+ // Only update the timeout if the timeout is greater than the current
+ // timeout. If the current timeout is larger, then just use that.
+ if (curr_timeout < timeout) {
+ m_timeout_modified = true;
+ m_saved_timeout = m_gdb_comm.SetPacketTimeout(timeout);
+ }
}
GDBRemoteCommunication::ScopedTimeout::~ScopedTimeout() {
- m_gdb_comm.SetPacketTimeout(m_saved_timeout);
+ // Only restore the timeout if we set it in the constructor.
+ if (m_timeout_modified)
+ m_gdb_comm.SetPacketTimeout(m_saved_timeout);
}
// This function is called via the Communications class read thread when bytes
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 1f3fa17..ce90de3 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -65,9 +65,9 @@ public:
enum class PacketResult {
Success = 0, // Success
- ErrorSendFailed, // Error sending the packet
+ ErrorSendFailed, // Status sending the packet
ErrorSendAck, // Didn't get an ack back after sending a packet
- ErrorReplyFailed, // Error getting the reply
+ ErrorReplyFailed, // Status getting the reply
ErrorReplyTimeout, // Timed out waiting for reply
ErrorReplyInvalid, // Got a reply but it wasn't valid for the packet that
// was sent
@@ -89,6 +89,10 @@ public:
private:
GDBRemoteCommunication &m_gdb_comm;
std::chrono::seconds m_saved_timeout;
+ // Don't ever reduce the timeout for a packet, only increase it. If the
+ // requested timeout if less than the current timeout, we don't set it
+ // and won't need to restore it.
+ bool m_timeout_modified;
};
GDBRemoteCommunication(const char *comm_name, const char *listener_name);
@@ -127,7 +131,7 @@ public:
// Start a debugserver instance on the current host using the
// supplied connection URL.
//------------------------------------------------------------------
- Error StartDebugserverProcess(
+ Status StartDebugserverProcess(
const char *url,
Platform *platform, // If non nullptr, then check with the platform for
// the GDB server binary if it can't be located
@@ -251,8 +255,8 @@ protected:
// on m_bytes. The checksum was for the compressed packet.
bool DecompressPacket();
- Error StartListenThread(const char *hostname = "127.0.0.1",
- uint16_t port = 0);
+ Status StartListenThread(const char *hostname = "127.0.0.1",
+ uint16_t port = 0);
bool JoinListenThread();
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index b70f090..e6fd386 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -18,21 +18,19 @@
#include <sstream>
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/State.h"
-#include "lldb/Core/StreamGDBRemote.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/JSON.h"
#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/StreamString.h"
// Project includes
#include "ProcessGDBRemote.h"
@@ -87,6 +85,8 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient()
m_supports_jThreadExtendedInfo(eLazyBoolCalculate),
m_supports_jLoadedDynamicLibrariesInfos(eLazyBoolCalculate),
m_supports_jGetSharedCacheInfo(eLazyBoolCalculate),
+ m_supports_QPassSignals(eLazyBoolCalculate),
+ m_supports_error_string_reply(eLazyBoolCalculate),
m_supports_qProcessInfoPID(true), m_supports_qfProcessInfo(true),
m_supports_qUserName(true), m_supports_qGroupName(true),
m_supports_qThreadStopInfo(true), m_supports_z0(true),
@@ -113,7 +113,7 @@ GDBRemoteCommunicationClient::~GDBRemoteCommunicationClient() {
Disconnect();
}
-bool GDBRemoteCommunicationClient::HandshakeWithServer(Error *error_ptr) {
+bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
ResetDiscoverableSettings(false);
// Start the read thread after we send the handshake ack since if we
@@ -150,6 +150,13 @@ bool GDBRemoteCommunicationClient::GetEchoSupported() {
return m_supports_qEcho == eLazyBoolYes;
}
+bool GDBRemoteCommunicationClient::GetQPassSignalsSupported() {
+ if (m_supports_QPassSignals == eLazyBoolCalculate) {
+ GetRemoteQSupported();
+ }
+ return m_supports_QPassSignals == eLazyBoolYes;
+}
+
bool GDBRemoteCommunicationClient::GetAugmentedLibrariesSVR4ReadSupported() {
if (m_supports_augmented_libraries_svr4_read == eLazyBoolCalculate) {
GetRemoteQSupported();
@@ -419,6 +426,11 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
else
m_supports_qEcho = eLazyBoolNo;
+ if (::strstr(response_cstr, "QPassSignals+"))
+ m_supports_QPassSignals = eLazyBoolYes;
+ else
+ m_supports_QPassSignals = eLazyBoolNo;
+
const char *packet_size_str = ::strstr(response_cstr, "PacketSize=");
if (packet_size_str) {
StringExtractorGDBRemote packet_response(packet_size_str +
@@ -585,6 +597,21 @@ bool GDBRemoteCommunicationClient::GetThreadExtendedInfoSupported() {
return m_supports_jThreadExtendedInfo;
}
+void GDBRemoteCommunicationClient::EnableErrorStringInPacket() {
+ if (m_supports_error_string_reply == eLazyBoolCalculate) {
+ StringExtractorGDBRemote response;
+ // We try to enable error strings in remote packets
+ // but if we fail, we just work in the older way.
+ m_supports_error_string_reply = eLazyBoolNo;
+ if (SendPacketAndWaitForResponse("QEnableErrorStrings", response, false) ==
+ PacketResult::Success) {
+ if (response.IsOKResponse()) {
+ m_supports_error_string_reply = eLazyBoolYes;
+ }
+ }
+ }
+}
+
bool GDBRemoteCommunicationClient::GetLoadedDynamicLibrariesInfosSupported() {
if (m_supports_jLoadedDynamicLibrariesInfos == eLazyBoolCalculate) {
StringExtractorGDBRemote response;
@@ -1382,8 +1409,8 @@ bool GDBRemoteCommunicationClient::DeallocateMemory(addr_t addr) {
return false;
}
-Error GDBRemoteCommunicationClient::Detach(bool keep_stopped) {
- Error error;
+Status GDBRemoteCommunicationClient::Detach(bool keep_stopped) {
+ Status error;
if (keep_stopped) {
if (m_supports_detach_stay_stopped == eLazyBoolCalculate) {
@@ -1422,9 +1449,9 @@ Error GDBRemoteCommunicationClient::Detach(bool keep_stopped) {
return error;
}
-Error GDBRemoteCommunicationClient::GetMemoryRegionInfo(
+Status GDBRemoteCommunicationClient::GetMemoryRegionInfo(
lldb::addr_t addr, lldb_private::MemoryRegionInfo &region_info) {
- Error error;
+ Status error;
region_info.Clear();
if (m_supports_memory_region_info != eLazyBoolNo) {
@@ -1491,13 +1518,18 @@ Error GDBRemoteCommunicationClient::GetMemoryRegionInfo(
}
}
- // We got a valid address range back but no permissions -- which means
- // this is an unmapped page
- if (region_info.GetRange().IsValid() && saw_permissions == false) {
- region_info.SetReadable(MemoryRegionInfo::eNo);
- region_info.SetWritable(MemoryRegionInfo::eNo);
- region_info.SetExecutable(MemoryRegionInfo::eNo);
- region_info.SetMapped(MemoryRegionInfo::eNo);
+ if (region_info.GetRange().IsValid()) {
+ // We got a valid address range back but no permissions -- which means
+ // this is an unmapped page
+ if (!saw_permissions) {
+ region_info.SetReadable(MemoryRegionInfo::eNo);
+ region_info.SetWritable(MemoryRegionInfo::eNo);
+ region_info.SetExecutable(MemoryRegionInfo::eNo);
+ region_info.SetMapped(MemoryRegionInfo::eNo);
+ }
+ } else {
+ // We got an invalid address range back
+ error.SetErrorString("Server returned invalid range");
}
} else {
m_supports_memory_region_info = eLazyBoolNo;
@@ -1512,8 +1544,8 @@ Error GDBRemoteCommunicationClient::GetMemoryRegionInfo(
return error;
}
-Error GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) {
- Error error;
+Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) {
+ Status error;
if (m_supports_watchpoint_support_info == eLazyBoolYes) {
num = m_num_supported_hardware_watchpoints;
@@ -1551,18 +1583,18 @@ Error GDBRemoteCommunicationClient::GetWatchpointSupportInfo(uint32_t &num) {
return error;
}
-lldb_private::Error GDBRemoteCommunicationClient::GetWatchpointSupportInfo(
+lldb_private::Status GDBRemoteCommunicationClient::GetWatchpointSupportInfo(
uint32_t &num, bool &after, const ArchSpec &arch) {
- Error error(GetWatchpointSupportInfo(num));
+ Status error(GetWatchpointSupportInfo(num));
if (error.Success())
error = GetWatchpointsTriggerAfterInstruction(after, arch);
return error;
}
-lldb_private::Error
+lldb_private::Status
GDBRemoteCommunicationClient::GetWatchpointsTriggerAfterInstruction(
bool &after, const ArchSpec &arch) {
- Error error;
+ Status error;
llvm::Triple::ArchType atype = arch.GetMachine();
// we assume watchpoints will happen after running the relevant opcode
@@ -1660,7 +1692,7 @@ bool GDBRemoteCommunicationClient::GetWorkingDir(FileSpec &working_dir) {
return false;
std::string cwd;
response.GetHexByteString(cwd);
- working_dir.SetFile(cwd, false, GetHostArchitecture());
+ working_dir.SetFile(cwd, false, GetHostArchitecture().GetTriple());
return !cwd.empty();
}
return false;
@@ -1907,6 +1939,7 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
llvm::Triple triple(llvm::Twine("-") + vendor_name + "-" + os_name);
assert(triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat);
+ assert(triple.getObjectFormat() != llvm::Triple::Wasm);
switch (triple.getObjectFormat()) {
case llvm::Triple::MachO:
m_process_arch.SetArchitecture(eArchTypeMachO, cpu, sub);
@@ -1917,6 +1950,10 @@ bool GDBRemoteCommunicationClient::GetCurrentProcessInfo(bool allow_lazy) {
case llvm::Triple::COFF:
m_process_arch.SetArchitecture(eArchTypeCOFF, cpu, sub);
break;
+ case llvm::Triple::Wasm:
+ if (log)
+ log->Printf("error: not supported target architecture");
+ return false;
case llvm::Triple::UnknownObjectFormat:
if (log)
log->Printf("error: failed to determine target architecture");
@@ -1957,29 +1994,29 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
bool has_name_match = false;
if (name && name[0]) {
has_name_match = true;
- NameMatchType name_match_type = match_info.GetNameMatchType();
+ NameMatch name_match_type = match_info.GetNameMatchType();
switch (name_match_type) {
- case eNameMatchIgnore:
+ case NameMatch::Ignore:
has_name_match = false;
break;
- case eNameMatchEquals:
+ case NameMatch::Equals:
packet.PutCString("name_match:equals;");
break;
- case eNameMatchContains:
+ case NameMatch::Contains:
packet.PutCString("name_match:contains;");
break;
- case eNameMatchStartsWith:
+ case NameMatch::StartsWith:
packet.PutCString("name_match:starts_with;");
break;
- case eNameMatchEndsWith:
+ case NameMatch::EndsWith:
packet.PutCString("name_match:ends_with;");
break;
- case eNameMatchRegularExpression:
+ case NameMatch::RegularExpression:
packet.PutCString("name_match:regex;");
break;
}
@@ -2190,23 +2227,19 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
const duration<float> standard_deviation =
calculate_standard_deviation(packet_times);
if (json) {
- strm.Printf("%s\n {\"send_size\" : %6" PRIu32
- ", \"recv_size\" : %6" PRIu32
- ", \"total_time_nsec\" : %12" PRIu64
- ", \"standard_deviation_nsec\" : %9" PRIu64 " }",
+ strm.Format("{0}\n {{\"send_size\" : {1,6}, \"recv_size\" : "
+ "{2,6}, \"total_time_nsec\" : {3,12:ns-}, "
+ "\"standard_deviation_nsec\" : {4,9:ns-f0}}",
result_idx > 0 ? "," : "", send_size, recv_size,
- duration_cast<nanoseconds>(total_time).count(),
- duration_cast<nanoseconds>(standard_deviation).count());
+ total_time, standard_deviation);
++result_idx;
} else {
- strm.Printf(
- "qSpeedTest(send=%-7u, recv=%-7u) in %.9f"
- " sec for %9.2f packets/sec (%10.6f ms per packet) with standard "
- "deviation of %10.6f ms\n",
- send_size, recv_size, duration<float>(total_time).count(),
- packets_per_second,
- duration<float, std::milli>(average_per_packet).count(),
- duration<float, std::milli>(standard_deviation).count());
+ strm.Format("qSpeedTest(send={0,7}, recv={1,7}) in {2:s+f9} for "
+ "{3,9:f2} packets/s ({4,10:ms+f6} per packet) with "
+ "standard deviation of {5,10:ms+f6}\n",
+ send_size, recv_size, duration<float>(total_time),
+ packets_per_second, duration<float>(average_per_packet),
+ standard_deviation);
}
strm.Flush();
}
@@ -2249,21 +2282,18 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
const auto average_per_packet = total_time / packet_count;
if (json) {
- strm.Printf("%s\n {\"send_size\" : %6" PRIu32
- ", \"recv_size\" : %6" PRIu32
- ", \"total_time_nsec\" : %12" PRIu64 " }",
+ strm.Format("{0}\n {{\"send_size\" : {1,6}, \"recv_size\" : "
+ "{2,6}, \"total_time_nsec\" : {3,12:ns-}}",
result_idx > 0 ? "," : "", send_size, recv_size,
- duration_cast<nanoseconds>(total_time).count());
+ total_time);
++result_idx;
} else {
- strm.Printf("qSpeedTest(send=%-7u, recv=%-7u) %6u packets needed to "
- "receive %2.1fMB in %.9f"
- " sec for %f MB/sec for %9.2f packets/sec (%10.6f ms per "
- "packet)\n",
+ strm.Format("qSpeedTest(send={0,7}, recv={1,7}) {2,6} packets needed "
+ "to receive {3:f1}MB in {4:s+f9} for {5} MB/sec for "
+ "{6,9:f2} packets/sec ({7,10:ms+f6} per packet)\n",
send_size, recv_size, packet_count, k_recv_amount_mb,
- duration<float>(total_time).count(), mb_second,
- packets_per_second,
- duration<float, std::milli>(average_per_packet).count());
+ duration<float>(total_time), mb_second,
+ packets_per_second, duration<float>(average_per_packet));
}
strm.Flush();
}
@@ -2524,7 +2554,7 @@ uint8_t GDBRemoteCommunicationClient::SendGDBStoppointTypePacket(
if (response.IsOKResponse())
return 0;
- // Error while setting breakpoint, send back specific error
+ // Status while setting breakpoint, send back specific error
if (response.IsErrorResponse())
return response.GetError();
@@ -2620,7 +2650,7 @@ lldb::addr_t GDBRemoteCommunicationClient::GetShlibInfoAddr() {
return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
}
-lldb_private::Error GDBRemoteCommunicationClient::RunShellCommand(
+lldb_private::Status GDBRemoteCommunicationClient::RunShellCommand(
const char *command, // Shouldn't be NULL
const FileSpec &
working_dir, // Pass empty FileSpec to use the current working directory
@@ -2646,32 +2676,32 @@ lldb_private::Error GDBRemoteCommunicationClient::RunShellCommand(
if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
PacketResult::Success) {
if (response.GetChar() != 'F')
- return Error("malformed reply");
+ return Status("malformed reply");
if (response.GetChar() != ',')
- return Error("malformed reply");
+ return Status("malformed reply");
uint32_t exitcode = response.GetHexMaxU32(false, UINT32_MAX);
if (exitcode == UINT32_MAX)
- return Error("unable to run remote process");
+ return Status("unable to run remote process");
else if (status_ptr)
*status_ptr = exitcode;
if (response.GetChar() != ',')
- return Error("malformed reply");
+ return Status("malformed reply");
uint32_t signo = response.GetHexMaxU32(false, UINT32_MAX);
if (signo_ptr)
*signo_ptr = signo;
if (response.GetChar() != ',')
- return Error("malformed reply");
+ return Status("malformed reply");
std::string output;
response.GetEscapedBinaryData(output);
if (command_output)
command_output->assign(output);
- return Error();
+ return Status();
}
- return Error("unable to send packet");
+ return Status("unable to send packet");
}
-Error GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec,
- uint32_t file_permissions) {
+Status GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec,
+ uint32_t file_permissions) {
std::string path{file_spec.GetPath(false)};
lldb_private::StreamString stream;
stream.PutCString("qPlatform_mkdir:");
@@ -2683,16 +2713,17 @@ Error GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec,
if (SendPacketAndWaitForResponse(packet, response, false) !=
PacketResult::Success)
- return Error("failed to send '%s' packet", packet.str().c_str());
+ return Status("failed to send '%s' packet", packet.str().c_str());
if (response.GetChar() != 'F')
- return Error("invalid response to '%s' packet", packet.str().c_str());
+ return Status("invalid response to '%s' packet", packet.str().c_str());
- return Error(response.GetU32(UINT32_MAX), eErrorTypePOSIX);
+ return Status(response.GetU32(UINT32_MAX), eErrorTypePOSIX);
}
-Error GDBRemoteCommunicationClient::SetFilePermissions(
- const FileSpec &file_spec, uint32_t file_permissions) {
+Status
+GDBRemoteCommunicationClient::SetFilePermissions(const FileSpec &file_spec,
+ uint32_t file_permissions) {
std::string path{file_spec.GetPath(false)};
lldb_private::StreamString stream;
stream.PutCString("qPlatform_chmod:");
@@ -2704,16 +2735,16 @@ Error GDBRemoteCommunicationClient::SetFilePermissions(
if (SendPacketAndWaitForResponse(packet, response, false) !=
PacketResult::Success)
- return Error("failed to send '%s' packet", stream.GetData());
+ return Status("failed to send '%s' packet", stream.GetData());
if (response.GetChar() != 'F')
- return Error("invalid response to '%s' packet", stream.GetData());
+ return Status("invalid response to '%s' packet", stream.GetData());
- return Error(response.GetU32(UINT32_MAX), eErrorTypePOSIX);
+ return Status(response.GetU32(UINT32_MAX), eErrorTypePOSIX);
}
static uint64_t ParseHostIOPacketResponse(StringExtractorGDBRemote &response,
- uint64_t fail_result, Error &error) {
+ uint64_t fail_result, Status &error) {
response.SetFilePos(0);
if (response.GetChar() != 'F')
return fail_result;
@@ -2733,7 +2764,7 @@ static uint64_t ParseHostIOPacketResponse(StringExtractorGDBRemote &response,
lldb::user_id_t
GDBRemoteCommunicationClient::OpenFile(const lldb_private::FileSpec &file_spec,
uint32_t flags, mode_t mode,
- Error &error) {
+ Status &error) {
std::string path(file_spec.GetPath(false));
lldb_private::StreamString stream;
stream.PutCString("vFile:open:");
@@ -2752,7 +2783,8 @@ GDBRemoteCommunicationClient::OpenFile(const lldb_private::FileSpec &file_spec,
return UINT64_MAX;
}
-bool GDBRemoteCommunicationClient::CloseFile(lldb::user_id_t fd, Error &error) {
+bool GDBRemoteCommunicationClient::CloseFile(lldb::user_id_t fd,
+ Status &error) {
lldb_private::StreamString stream;
stream.Printf("vFile:close:%i", (int)fd);
StringExtractorGDBRemote response;
@@ -2781,10 +2813,11 @@ lldb::user_id_t GDBRemoteCommunicationClient::GetFileSize(
return UINT64_MAX;
}
-Error GDBRemoteCommunicationClient::GetFilePermissions(
- const FileSpec &file_spec, uint32_t &file_permissions) {
+Status
+GDBRemoteCommunicationClient::GetFilePermissions(const FileSpec &file_spec,
+ uint32_t &file_permissions) {
std::string path{file_spec.GetPath(false)};
- Error error;
+ Status error;
lldb_private::StreamString stream;
stream.PutCString("vFile:mode:");
stream.PutCStringAsRawHex8(path.c_str());
@@ -2819,7 +2852,7 @@ Error GDBRemoteCommunicationClient::GetFilePermissions(
uint64_t GDBRemoteCommunicationClient::ReadFile(lldb::user_id_t fd,
uint64_t offset, void *dst,
uint64_t dst_len,
- Error &error) {
+ Status &error) {
lldb_private::StreamString stream;
stream.Printf("vFile:pread:%i,%" PRId64 ",%" PRId64, (int)fd, dst_len,
offset);
@@ -2853,7 +2886,7 @@ uint64_t GDBRemoteCommunicationClient::WriteFile(lldb::user_id_t fd,
uint64_t offset,
const void *src,
uint64_t src_len,
- Error &error) {
+ Status &error) {
lldb_private::StreamGDBRemote stream;
stream.Printf("vFile:pwrite:%i,%" PRId64 ",", (int)fd, offset);
stream.PutEscapedBytes(src, src_len);
@@ -2881,10 +2914,10 @@ uint64_t GDBRemoteCommunicationClient::WriteFile(lldb::user_id_t fd,
return 0;
}
-Error GDBRemoteCommunicationClient::CreateSymlink(const FileSpec &src,
- const FileSpec &dst) {
+Status GDBRemoteCommunicationClient::CreateSymlink(const FileSpec &src,
+ const FileSpec &dst) {
std::string src_path{src.GetPath(false)}, dst_path{dst.GetPath(false)};
- Error error;
+ Status error;
lldb_private::StreamGDBRemote stream;
stream.PutCString("vFile:symlink:");
// the unix symlink() command reverses its parameters where the dst if first,
@@ -2915,9 +2948,9 @@ Error GDBRemoteCommunicationClient::CreateSymlink(const FileSpec &src,
return error;
}
-Error GDBRemoteCommunicationClient::Unlink(const FileSpec &file_spec) {
+Status GDBRemoteCommunicationClient::Unlink(const FileSpec &file_spec) {
std::string path{file_spec.GetPath(false)};
- Error error;
+ Status error;
lldb_private::StreamGDBRemote stream;
stream.PutCString("vFile:unlink:");
// the unix symlink() command reverses its parameters where the dst if first,
@@ -3134,6 +3167,213 @@ bool GDBRemoteCommunicationClient::SyncThreadState(lldb::tid_t tid) {
response.IsOKResponse();
}
+lldb::user_id_t
+GDBRemoteCommunicationClient::SendStartTracePacket(const TraceOptions &options,
+ Status &error) {
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ lldb::user_id_t ret_uid = LLDB_INVALID_UID;
+
+ StreamGDBRemote escaped_packet;
+ escaped_packet.PutCString("jTraceStart:");
+
+ StructuredData::Dictionary json_packet;
+ json_packet.AddIntegerItem("type", options.getType());
+ json_packet.AddIntegerItem("buffersize", options.getTraceBufferSize());
+ json_packet.AddIntegerItem("metabuffersize", options.getMetaDataBufferSize());
+
+ if (options.getThreadID() != LLDB_INVALID_THREAD_ID)
+ json_packet.AddIntegerItem("threadid", options.getThreadID());
+
+ StructuredData::DictionarySP custom_params = options.getTraceParams();
+ if (custom_params)
+ json_packet.AddItem("params", custom_params);
+
+ StreamString json_string;
+ json_packet.Dump(json_string, false);
+ escaped_packet.PutEscapedBytes(json_string.GetData(), json_string.GetSize());
+
+ StringExtractorGDBRemote response;
+ if (SendPacketAndWaitForResponse(escaped_packet.GetString(), response,
+ true) ==
+ GDBRemoteCommunication::PacketResult::Success) {
+ if (!response.IsNormalResponse()) {
+ error = response.GetStatus();
+ LLDB_LOG(log, "Target does not support Tracing , error {0}", error);
+ } else {
+ ret_uid = response.GetHexMaxU64(false, LLDB_INVALID_UID);
+ }
+ } else {
+ LLDB_LOG(log, "failed to send packet");
+ error.SetErrorStringWithFormat("failed to send packet: '%s'",
+ escaped_packet.GetData());
+ }
+ return ret_uid;
+}
+
+Status
+GDBRemoteCommunicationClient::SendStopTracePacket(lldb::user_id_t uid,
+ lldb::tid_t thread_id) {
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ StringExtractorGDBRemote response;
+ Status error;
+
+ StructuredData::Dictionary json_packet;
+ StreamGDBRemote escaped_packet;
+ StreamString json_string;
+ escaped_packet.PutCString("jTraceStop:");
+
+ json_packet.AddIntegerItem("traceid", uid);
+
+ if (thread_id != LLDB_INVALID_THREAD_ID)
+ json_packet.AddIntegerItem("threadid", thread_id);
+
+ json_packet.Dump(json_string, false);
+
+ escaped_packet.PutEscapedBytes(json_string.GetData(), json_string.GetSize());
+
+ if (SendPacketAndWaitForResponse(escaped_packet.GetString(), response,
+ true) ==
+ GDBRemoteCommunication::PacketResult::Success) {
+ if (!response.IsOKResponse()) {
+ error = response.GetStatus();
+ LLDB_LOG(log, "stop tracing failed");
+ }
+ } else {
+ LLDB_LOG(log, "failed to send packet");
+ error.SetErrorStringWithFormat(
+ "failed to send packet: '%s' with error '%d'", escaped_packet.GetData(),
+ response.GetError());
+ }
+ return error;
+}
+
+Status GDBRemoteCommunicationClient::SendGetDataPacket(
+ lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer, size_t offset) {
+
+ StreamGDBRemote escaped_packet;
+ escaped_packet.PutCString("jTraceBufferRead:");
+ return SendGetTraceDataPacket(escaped_packet, uid, thread_id, buffer, offset);
+}
+
+Status GDBRemoteCommunicationClient::SendGetMetaDataPacket(
+ lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer, size_t offset) {
+
+ StreamGDBRemote escaped_packet;
+ escaped_packet.PutCString("jTraceMetaRead:");
+ return SendGetTraceDataPacket(escaped_packet, uid, thread_id, buffer, offset);
+}
+
+Status
+GDBRemoteCommunicationClient::SendGetTraceConfigPacket(lldb::user_id_t uid,
+ TraceOptions &options) {
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ StringExtractorGDBRemote response;
+ Status error;
+
+ StreamString json_string;
+ StreamGDBRemote escaped_packet;
+ escaped_packet.PutCString("jTraceConfigRead:");
+
+ StructuredData::Dictionary json_packet;
+ json_packet.AddIntegerItem("traceid", uid);
+
+ if (options.getThreadID() != LLDB_INVALID_THREAD_ID)
+ json_packet.AddIntegerItem("threadid", options.getThreadID());
+
+ json_packet.Dump(json_string, false);
+ escaped_packet.PutEscapedBytes(json_string.GetData(), json_string.GetSize());
+
+ if (SendPacketAndWaitForResponse(escaped_packet.GetString(), response,
+ true) ==
+ GDBRemoteCommunication::PacketResult::Success) {
+ if (response.IsNormalResponse()) {
+ uint64_t type = std::numeric_limits<uint64_t>::max();
+ uint64_t buffersize = std::numeric_limits<uint64_t>::max();
+ uint64_t metabuffersize = std::numeric_limits<uint64_t>::max();
+
+ auto json_object = StructuredData::ParseJSON(response.Peek());
+
+ if (!json_object ||
+ json_object->GetType() != lldb::eStructuredDataTypeDictionary) {
+ error.SetErrorString("Invalid Configuration obtained");
+ return error;
+ }
+
+ auto json_dict = json_object->GetAsDictionary();
+
+ json_dict->GetValueForKeyAsInteger<uint64_t>("metabuffersize",
+ metabuffersize);
+ options.setMetaDataBufferSize(metabuffersize);
+
+ json_dict->GetValueForKeyAsInteger<uint64_t>("buffersize", buffersize);
+ options.setTraceBufferSize(buffersize);
+
+ json_dict->GetValueForKeyAsInteger<uint64_t>("type", type);
+ options.setType(static_cast<lldb::TraceType>(type));
+
+ StructuredData::ObjectSP custom_params_sp =
+ json_dict->GetValueForKey("params");
+ if (custom_params_sp) {
+ if (custom_params_sp->GetType() !=
+ lldb::eStructuredDataTypeDictionary) {
+ error.SetErrorString("Invalid Configuration obtained");
+ return error;
+ } else
+ options.setTraceParams(
+ static_pointer_cast<StructuredData::Dictionary>(
+ custom_params_sp));
+ }
+ } else {
+ error = response.GetStatus();
+ }
+ } else {
+ LLDB_LOG(log, "failed to send packet");
+ error.SetErrorStringWithFormat("failed to send packet: '%s'",
+ escaped_packet.GetData());
+ }
+ return error;
+}
+
+Status GDBRemoteCommunicationClient::SendGetTraceDataPacket(
+ StreamGDBRemote &packet, lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer, size_t offset) {
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ Status error;
+
+ StructuredData::Dictionary json_packet;
+
+ json_packet.AddIntegerItem("traceid", uid);
+ json_packet.AddIntegerItem("offset", offset);
+ json_packet.AddIntegerItem("buffersize", buffer.size());
+
+ if (thread_id != LLDB_INVALID_THREAD_ID)
+ json_packet.AddIntegerItem("threadid", thread_id);
+
+ StreamString json_string;
+ json_packet.Dump(json_string, false);
+
+ packet.PutEscapedBytes(json_string.GetData(), json_string.GetSize());
+ StringExtractorGDBRemote response;
+ if (SendPacketAndWaitForResponse(packet.GetString(), response, true) ==
+ GDBRemoteCommunication::PacketResult::Success) {
+ if (response.IsNormalResponse()) {
+ size_t filled_size = response.GetHexBytesAvail(buffer);
+ buffer = llvm::MutableArrayRef<uint8_t>(buffer.data(), filled_size);
+ } else {
+ error = response.GetStatus();
+ buffer = buffer.slice(buffer.size());
+ }
+ } else {
+ LLDB_LOG(log, "failed to send packet");
+ error.SetErrorStringWithFormat("failed to send packet: '%s'",
+ packet.GetData());
+ buffer = buffer.slice(buffer.size());
+ }
+ return error;
+}
+
bool GDBRemoteCommunicationClient::GetModuleInfo(
const FileSpec &module_file_spec, const lldb_private::ArchSpec &arch_spec,
ModuleSpec &module_spec) {
@@ -3193,7 +3433,7 @@ bool GDBRemoteCommunicationClient::GetModuleInfo(
StringExtractor extractor(value);
std::string path;
extractor.GetHexByteString(path);
- module_spec.GetFileSpec() = FileSpec(path, false, arch_spec);
+ module_spec.GetFileSpec() = FileSpec(path, false, arch_spec.GetTriple());
}
}
@@ -3206,12 +3446,12 @@ ParseModuleSpec(StructuredData::Dictionary *dict) {
if (!dict)
return llvm::None;
- std::string string;
+ llvm::StringRef string;
uint64_t integer;
if (!dict->GetValueForKeyAsString("uuid", string))
return llvm::None;
- result.GetUUID().SetFromCString(string.c_str(), string.size());
+ result.GetUUID().SetFromStringRef(string, string.size());
if (!dict->GetValueForKeyAsInteger("file_offset", integer))
return llvm::None;
@@ -3223,11 +3463,12 @@ ParseModuleSpec(StructuredData::Dictionary *dict) {
if (!dict->GetValueForKeyAsString("triple", string))
return llvm::None;
- result.GetArchitecture().SetTriple(string.c_str());
+ result.GetArchitecture().SetTriple(string);
if (!dict->GetValueForKeyAsString("file_path", string))
return llvm::None;
- result.GetFileSpec() = FileSpec(string, false, result.GetArchitecture());
+ result.GetFileSpec() =
+ FileSpec(string, false, result.GetArchitecture().GetTriple());
return result;
}
@@ -3254,6 +3495,9 @@ GDBRemoteCommunicationClient::GetModulesInfo(
payload.PutEscapedBytes(unescaped_payload.GetString().data(),
unescaped_payload.GetSize());
+ // Increase the timeout for jModulesInfo since this packet can take longer.
+ ScopedTimeout timeout(*this, std::chrono::seconds(10));
+
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse(payload.GetString(), response, false) !=
PacketResult::Success ||
@@ -3292,7 +3536,7 @@ GDBRemoteCommunicationClient::GetModulesInfo(
bool GDBRemoteCommunicationClient::ReadExtFeature(
const lldb_private::ConstString object,
const lldb_private::ConstString annex, std::string &out,
- lldb_private::Error &err) {
+ lldb_private::Status &err) {
std::stringstream output;
StringExtractorGDBRemote chunk;
@@ -3571,9 +3815,29 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() {
: nullptr;
}
-Error GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
+Status GDBRemoteCommunicationClient::SendSignalsToIgnore(
+ llvm::ArrayRef<int32_t> signals) {
+ // Format packet:
+ // QPassSignals:<hex_sig1>;<hex_sig2>...;<hex_sigN>
+ auto range = llvm::make_range(signals.begin(), signals.end());
+ std::string packet = formatv("QPassSignals:{0:$[;]@(x-2)}", range).str();
+
+ StringExtractorGDBRemote response;
+ auto send_status = SendPacketAndWaitForResponse(packet, response, false);
+
+ if (send_status != GDBRemoteCommunication::PacketResult::Success)
+ return Status("Sending QPassSignals packet failed");
+
+ if (response.IsOKResponse()) {
+ return Status();
+ } else {
+ return Status("Unknown error happened during sending QPassSignals packet.");
+ }
+}
+
+Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
const ConstString &type_name, const StructuredData::ObjectSP &config_sp) {
- Error error;
+ Status error;
if (type_name.GetLength() == 0) {
error.SetErrorString("invalid type_name argument");
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index 83162a6..712d85e 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -23,8 +23,9 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/StructuredData.h"
#include "lldb/Target/Process.h"
+#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/StructuredData.h"
#include "llvm/ADT/Optional.h"
@@ -41,7 +42,7 @@ public:
// After connecting, send the handshake to the server to make sure
// we are communicating with it.
//------------------------------------------------------------------
- bool HandshakeWithServer(Error *error_ptr);
+ bool HandshakeWithServer(Status *error_ptr);
// For packets which specify a range of output to be returned,
// return all of the output via a series of request packets of the form
@@ -230,17 +231,17 @@ public:
bool DeallocateMemory(lldb::addr_t addr);
- Error Detach(bool keep_stopped);
+ Status Detach(bool keep_stopped);
- Error GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info);
+ Status GetMemoryRegionInfo(lldb::addr_t addr, MemoryRegionInfo &range_info);
- Error GetWatchpointSupportInfo(uint32_t &num);
+ Status GetWatchpointSupportInfo(uint32_t &num);
- Error GetWatchpointSupportInfo(uint32_t &num, bool &after,
- const ArchSpec &arch);
+ Status GetWatchpointSupportInfo(uint32_t &num, bool &after,
+ const ArchSpec &arch);
- Error GetWatchpointsTriggerAfterInstruction(bool &after,
- const ArchSpec &arch);
+ Status GetWatchpointsTriggerAfterInstruction(bool &after,
+ const ArchSpec &arch);
const ArchSpec &GetHostArchitecture();
@@ -339,6 +340,8 @@ public:
bool GetQXferAuxvReadSupported();
+ void EnableErrorStringInPacket();
+
bool GetQXferLibrariesReadSupported();
bool GetQXferLibrariesSVR4ReadSupported();
@@ -347,6 +350,8 @@ public:
bool GetEchoSupported();
+ bool GetQPassSignalsSupported();
+
bool GetAugmentedLibrariesSVR4ReadSupported();
bool GetQXferFeaturesReadSupported();
@@ -363,33 +368,33 @@ public:
bool &sequence_mutex_unavailable);
lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
- mode_t mode, Error &error);
+ mode_t mode, Status &error);
- bool CloseFile(lldb::user_id_t fd, Error &error);
+ bool CloseFile(lldb::user_id_t fd, Status &error);
lldb::user_id_t GetFileSize(const FileSpec &file_spec);
- Error GetFilePermissions(const FileSpec &file_spec,
- uint32_t &file_permissions);
+ Status GetFilePermissions(const FileSpec &file_spec,
+ uint32_t &file_permissions);
- Error SetFilePermissions(const FileSpec &file_spec,
- uint32_t file_permissions);
+ Status SetFilePermissions(const FileSpec &file_spec,
+ uint32_t file_permissions);
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
- uint64_t dst_len, Error &error);
+ uint64_t dst_len, Status &error);
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src,
- uint64_t src_len, Error &error);
+ uint64_t src_len, Status &error);
- Error CreateSymlink(const FileSpec &src, const FileSpec &dst);
+ Status CreateSymlink(const FileSpec &src, const FileSpec &dst);
- Error Unlink(const FileSpec &file_spec);
+ Status Unlink(const FileSpec &file_spec);
- Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);
+ Status MakeDirectory(const FileSpec &file_spec, uint32_t mode);
bool GetFileExists(const FileSpec &file_spec);
- Error RunShellCommand(
+ Status RunShellCommand(
const char *command, // Shouldn't be nullptr
const FileSpec &working_dir, // Pass empty FileSpec to use the current
// working directory
@@ -446,10 +451,13 @@ public:
bool ReadExtFeature(const lldb_private::ConstString object,
const lldb_private::ConstString annex, std::string &out,
- lldb_private::Error &err);
+ lldb_private::Status &err);
void ServeSymbolLookups(lldb_private::Process *process);
+ // Sends QPassSignals packet to the server with given signals to ignore.
+ Status SendSignalsToIgnore(llvm::ArrayRef<int32_t> signals);
+
//------------------------------------------------------------------
/// Return the feature set supported by the gdb-remote server.
///
@@ -490,10 +498,25 @@ public:
///
/// @see \b Process::ConfigureStructuredData(...) for details.
//------------------------------------------------------------------
- Error
+ Status
ConfigureRemoteStructuredData(const ConstString &type_name,
const StructuredData::ObjectSP &config_sp);
+ lldb::user_id_t SendStartTracePacket(const TraceOptions &options,
+ Status &error);
+
+ Status SendStopTracePacket(lldb::user_id_t uid, lldb::tid_t thread_id);
+
+ Status SendGetDataPacket(lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset = 0);
+
+ Status SendGetMetaDataPacket(lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset = 0);
+
+ Status SendGetTraceConfigPacket(lldb::user_id_t uid, TraceOptions &options);
+
protected:
LazyBool m_supports_not_sending_acks;
LazyBool m_supports_thread_suffix;
@@ -527,6 +550,8 @@ protected:
LazyBool m_supports_jThreadExtendedInfo;
LazyBool m_supports_jLoadedDynamicLibrariesInfos;
LazyBool m_supports_jGetSharedCacheInfo;
+ LazyBool m_supports_QPassSignals;
+ LazyBool m_supports_error_string_reply;
bool m_supports_qProcessInfoPID : 1, m_supports_qfProcessInfo : 1,
m_supports_qUserName : 1, m_supports_qGroupName : 1,
@@ -581,6 +606,11 @@ protected:
lldb::tid_t tid, StreamString &&payload,
StringExtractorGDBRemote &response, bool send_async);
+ Status SendGetTraceDataPacket(StreamGDBRemote &packet, lldb::user_id_t uid,
+ lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset);
+
private:
DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunicationClient);
};
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 934824e..4be92b7 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -20,6 +20,7 @@
// Project includes
#include "ProcessGDBRemoteLog.h"
#include "Utility/StringExtractorGDBRemote.h"
+#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
@@ -27,7 +28,12 @@ using namespace lldb_private::process_gdb_remote;
GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(
const char *comm_name, const char *listener_name)
- : GDBRemoteCommunication(comm_name, listener_name), m_exit_now(false) {}
+ : GDBRemoteCommunication(comm_name, listener_name), m_exit_now(false) {
+ RegisterPacketHandler(
+ StringExtractorGDBRemote::eServerPacketType_QEnableErrorStrings,
+ [this](StringExtractorGDBRemote packet, Status &error, bool &interrupt,
+ bool &quit) { return this->Handle_QErrorStringEnable(packet); });
+}
GDBRemoteCommunicationServer::~GDBRemoteCommunicationServer() {}
@@ -39,7 +45,7 @@ void GDBRemoteCommunicationServer::RegisterPacketHandler(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::GetPacketAndSendResponse(
- Timeout<std::micro> timeout, Error &error, bool &interrupt, bool &quit) {
+ Timeout<std::micro> timeout, Status &error, bool &interrupt, bool &quit) {
StringExtractorGDBRemote packet;
PacketResult packet_result = WaitForPacketNoLock(packet, timeout, false);
@@ -100,6 +106,24 @@ GDBRemoteCommunicationServer::SendErrorResponse(uint8_t err) {
}
GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServer::SendErrorResponse(const Status &error) {
+ if (m_send_error_strings) {
+ lldb_private::StreamString packet;
+ packet.Printf("E%2.2x;", static_cast<uint8_t>(error.GetError()));
+ packet.PutCStringAsRawHex8(error.AsCString());
+ return SendPacketNoLock(packet.GetString());
+ } else
+ return SendErrorResponse(error.GetError());
+}
+
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServer::Handle_QErrorStringEnable(
+ StringExtractorGDBRemote &packet) {
+ m_send_error_strings = true;
+ return SendOKResponse();
+}
+
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServer::SendIllFormedResponse(
const StringExtractorGDBRemote &failed_packet, const char *message) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
index 0c583e6..a353524 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
@@ -31,8 +31,8 @@ class GDBRemoteCommunicationServer : public GDBRemoteCommunication {
public:
using PortMap = std::map<uint16_t, lldb::pid_t>;
using PacketHandler =
- std::function<PacketResult(StringExtractorGDBRemote &packet, Error &error,
- bool &interrupt, bool &quit)>;
+ std::function<PacketResult(StringExtractorGDBRemote &packet,
+ Status &error, bool &interrupt, bool &quit)>;
GDBRemoteCommunicationServer(const char *comm_name,
const char *listener_name);
@@ -44,7 +44,7 @@ public:
PacketHandler handler);
PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
- Error &error, bool &interrupt,
+ Status &error, bool &interrupt,
bool &quit);
// After connecting, do a little handshake with the client to make sure
@@ -57,6 +57,13 @@ protected:
bool m_exit_now; // use in asynchronous handling to indicate process should
// exit.
+ bool m_send_error_strings; // If the client enables this then
+ // we will send error strings as well.
+
+ PacketResult Handle_QErrorStringEnable(StringExtractorGDBRemote &packet);
+
+ PacketResult SendErrorResponse(const Status &error);
+
PacketResult SendUnimplementedResponse(const char *packet);
PacketResult SendErrorResponse(uint8_t error);
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 e4e6810..f53db50 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
@@ -22,23 +22,22 @@
#include <cstring>
// Other libraries and framework includes
-#include "lldb/Core/Log.h"
#include "lldb/Core/ModuleSpec.h"
-#include "lldb/Core/StreamGDBRemote.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Host/Config.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Host/File.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
+#include "lldb/Utility/Endian.h"
#include "lldb/Utility/JSON.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/Triple.h"
// Project includes
@@ -360,16 +359,15 @@ GDBRemoteCommunicationServerCommon::Handle_qfProcessInfo(
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);
+ NameMatch name_match = llvm::StringSwitch<NameMatch>(value)
+ .Case("equals", NameMatch::Equals)
+ .Case("starts_with", NameMatch::StartsWith)
+ .Case("ends_with", NameMatch::EndsWith)
+ .Case("contains", NameMatch::Contains)
+ .Case("regex", NameMatch::RegularExpression)
+ .Default(NameMatch::Ignore);
match_info.SetNameMatchType(name_match);
- if (name_match == eNameMatchIgnore)
+ if (name_match == NameMatch::Ignore)
return SendErrorResponse(2);
} else if (key.equals("pid")) {
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
@@ -525,7 +523,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Open(
File::ConvertOpenOptionsForPOSIXOpen(packet.GetHexMaxU32(false, 0));
if (packet.GetChar() == ',') {
mode_t mode = packet.GetHexMaxU32(false, 0600);
- Error error;
+ Status error;
const FileSpec path_spec{path, true};
int fd = ::open(path_spec.GetCString(), flags, mode);
const int save_errno = fd == -1 ? errno : 0;
@@ -546,7 +544,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Close(
StringExtractorGDBRemote &packet) {
packet.SetFilePos(::strlen("vFile:close:"));
int fd = packet.GetS32(-1);
- Error error;
+ Status error;
int err = -1;
int save_errno = 0;
if (fd >= 0) {
@@ -643,14 +641,15 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Size(
std::string path;
packet.GetHexByteString(path);
if (!path.empty()) {
- lldb::user_id_t retcode = FileSystem::GetFileSize(FileSpec(path, false));
+ uint64_t Size;
+ if (llvm::sys::fs::file_size(path, Size))
+ return SendErrorResponse(5);
StreamString response;
response.PutChar('F');
- response.PutHex64(retcode);
- if (retcode == UINT64_MAX) {
+ response.PutHex64(Size);
+ if (Size == UINT64_MAX) {
response.PutChar(',');
- response.PutHex64(
- retcode); // TODO: replace with Host::GetSyswideErrorCode()
+ response.PutHex64(Size); // TODO: replace with Host::GetSyswideErrorCode()
}
return SendPacketNoLock(response.GetString());
}
@@ -664,7 +663,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Mode(
std::string path;
packet.GetHexByteString(path);
if (!path.empty()) {
- Error error;
+ Status error;
const uint32_t mode = File::GetPermissions(FileSpec{path, true}, error);
StreamString response;
response.Printf("F%u", mode);
@@ -682,7 +681,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_Exists(
std::string path;
packet.GetHexByteString(path);
if (!path.empty()) {
- bool retcode = FileSystem::GetFileExists(FileSpec(path, false));
+ bool retcode = llvm::sys::fs::exists(path);
StreamString response;
response.PutChar('F');
response.PutChar(',');
@@ -703,7 +702,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_symlink(
packet.GetHexByteStringTerminatedBy(dst, ',');
packet.GetChar(); // Skip ',' char
packet.GetHexByteString(src);
- Error error = FileSystem::Symlink(FileSpec{src, true}, FileSpec{dst, false});
+ Status error = FileSystem::Symlink(FileSpec{src, true}, FileSpec{dst, false});
StreamString response;
response.Printf("F%u,%u", error.GetError(), error.GetError());
return SendPacketNoLock(response.GetString());
@@ -715,7 +714,7 @@ GDBRemoteCommunicationServerCommon::Handle_vFile_unlink(
packet.SetFilePos(::strlen("vFile:unlink:"));
std::string path;
packet.GetHexByteString(path);
- Error error = FileSystem::Unlink(FileSpec{path, true});
+ Status error(llvm::sys::fs::remove(path));
StreamString response;
response.Printf("F%u,%u", error.GetError(), error.GetError());
return SendPacketNoLock(response.GetString());
@@ -737,7 +736,7 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell(
packet.GetHexByteString(working_dir);
int status, signo;
std::string output;
- Error err =
+ Status err =
Host::RunShellCommand(path.c_str(), FileSpec{working_dir, true},
&status, &signo, &output, timeout);
StreamGDBRemote response;
@@ -772,15 +771,15 @@ GDBRemoteCommunicationServerCommon::Handle_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)) {
+ auto Result = llvm::sys::fs::md5_contents(path);
+ if (!Result) {
response.PutCString("F,");
response.PutCString("x");
} else {
response.PutCString("F,");
- response.PutHex64(a);
- response.PutHex64(b);
+ response.PutHex64(Result->low());
+ response.PutHex64(Result->high());
}
return SendPacketNoLock(response.GetString());
}
@@ -795,7 +794,7 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_mkdir(
if (packet.GetChar() == ',') {
std::string path;
packet.GetHexByteString(path);
- Error error = FileSystem::MakeDirectory(FileSpec{path, false}, mode);
+ Status error(llvm::sys::fs::create_directory(path, mode));
StreamGDBRemote response;
response.Printf("F%u", error.GetError());
@@ -810,11 +809,12 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod(
StringExtractorGDBRemote &packet) {
packet.SetFilePos(::strlen("qPlatform_chmod:"));
- mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX);
+ auto perms =
+ static_cast<llvm::sys::fs::perms>(packet.GetHexMaxU32(false, UINT32_MAX));
if (packet.GetChar() == ',') {
std::string path;
packet.GetHexByteString(path);
- Error error = FileSystem::SetFilePermissions(FileSpec{path, true}, mode);
+ Status error(llvm::sys::fs::setPermissions(path, perms));
StreamGDBRemote response;
response.Printf("F%u", error.GetError());
@@ -838,7 +838,8 @@ GDBRemoteCommunicationServerCommon::Handle_qSupported(
response.PutCString(";QThreadSuffixSupported+");
response.PutCString(";QListThreadsInStopReply+");
response.PutCString(";qEcho+");
-#if defined(__linux__)
+#if defined(__linux__) || defined(__NetBSD__)
+ response.PutCString(";QPassSignals+");
response.PutCString(";qXfer:auxv:read+");
#endif
@@ -1045,14 +1046,9 @@ GDBRemoteCommunicationServerCommon::Handle_A(StringExtractorGDBRemote &packet) {
if (success) {
m_process_launch_error = LaunchProcess();
- if (m_process_launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
+ if (m_process_launch_error.Success())
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());
- }
+ LLDB_LOG(log, "failed to launch exe: {0}", m_process_launch_error);
}
return SendErrorResponse(8);
}
@@ -1091,12 +1087,11 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo(
StreamGDBRemote response;
if (uuid_str.empty()) {
- std::string md5_hash;
- if (!FileSystem::CalculateMD5AsString(matched_module_spec.GetFileSpec(),
- file_offset, file_size, md5_hash))
+ auto Result = llvm::sys::fs::md5_contents(matched_module_spec.GetFileSpec().GetPath());
+ if (!Result)
return SendErrorResponse(5);
response.PutCString("md5:");
- response.PutCStringAsRawHex8(md5_hash.c_str());
+ response.PutCStringAsRawHex8(Result->digest().c_str());
} else {
response.PutCString("uuid:");
response.PutCStringAsRawHex8(uuid_str.c_str());
@@ -1140,7 +1135,7 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
packet_array->GetItemAtIndex(i)->GetAsDictionary();
if (!query)
continue;
- std::string file, triple;
+ llvm::StringRef file, triple;
if (!query->GetValueForKeyAsString("file", file) ||
!query->GetValueForKeyAsString("triple", triple))
continue;
@@ -1278,9 +1273,10 @@ FileSpec GDBRemoteCommunicationServerCommon::FindModuleFile(
#endif
}
-ModuleSpec GDBRemoteCommunicationServerCommon::GetModuleInfo(
- const std::string &module_path, const std::string &triple) {
- ArchSpec arch(triple.c_str());
+ModuleSpec
+GDBRemoteCommunicationServerCommon::GetModuleInfo(llvm::StringRef module_path,
+ llvm::StringRef triple) {
+ ArchSpec arch(triple);
const FileSpec req_module_path_spec(module_path, true);
const FileSpec module_path_spec =
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
index 321a922..e9ab8f1 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
@@ -38,7 +38,7 @@ public:
protected:
ProcessLaunchInfo m_process_launch_info;
- Error m_process_launch_error;
+ Status m_process_launch_error;
ProcessInstanceInfoList m_proc_infos;
uint32_t m_proc_infos_index;
bool m_thread_suffix_supported;
@@ -130,7 +130,7 @@ protected:
PacketResult (T::*handler)(StringExtractorGDBRemote &packet)) {
RegisterPacketHandler(packet_type,
[this, handler](StringExtractorGDBRemote packet,
- Error &error, bool &interrupt,
+ Status &error, bool &interrupt,
bool &quit) {
return (static_cast<T *>(this)->*handler)(packet);
});
@@ -144,17 +144,16 @@ protected:
/// with all the information for a child process to be launched.
///
/// @return
- /// An Error object indicating the success or failure of the
+ /// An Status object indicating the success or failure of the
/// launch.
//------------------------------------------------------------------
- virtual Error LaunchProcess() = 0;
+ virtual Status LaunchProcess() = 0;
virtual FileSpec FindModuleFile(const std::string &module_path,
const ArchSpec &arch);
private:
- ModuleSpec GetModuleInfo(const std::string &module_path,
- const std::string &triple);
+ ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple);
};
} // namespace process_gdb_remote
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index bf72673..9294359 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -12,7 +12,7 @@
#include "lldb/Host/Config.h"
#include "GDBRemoteCommunicationServerLLGS.h"
-#include "lldb/Core/StreamGDBRemote.h"
+#include "lldb/Utility/StreamGDBRemote.h"
// C Includes
// C++ Includes
@@ -21,27 +21,28 @@
#include <thread>
// Other libraries and framework includes
-#include "lldb/Core/DataBuffer.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/State.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/Debug.h"
-#include "lldb/Host/Endian.h"
#include "lldb/Host/File.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
+#include "lldb/Host/PosixApi.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
#include "lldb/Host/common/NativeRegisterContext.h"
#include "lldb/Host/common/NativeThreadProtocol.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/Endian.h"
#include "lldb/Utility/JSON.h"
#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/UriParser.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -49,7 +50,6 @@
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
#include "Utility/StringExtractorGDBRemote.h"
-#include "Utility/UriParser.h"
using namespace lldb;
using namespace lldb_private;
@@ -74,16 +74,11 @@ enum GDBRemoteServerError {
// GDBRemoteCommunicationServerLLGS constructor
//----------------------------------------------------------------------
GDBRemoteCommunicationServerLLGS::GDBRemoteCommunicationServerLLGS(
- MainLoop &mainloop)
+ MainLoop &mainloop, const NativeProcessProtocol::Factory &process_factory)
: GDBRemoteCommunicationServerCommon("gdb-remote.server",
"gdb-remote.server.rx_packet"),
- m_mainloop(mainloop), m_current_tid(LLDB_INVALID_THREAD_ID),
- m_continue_tid(LLDB_INVALID_THREAD_ID), m_debugged_process_mutex(),
- m_debugged_process_sp(), m_stdio_communication("process.stdio"),
- m_inferior_prev_state(StateType::eStateInvalid),
- m_active_auxv_buffer_sp(), m_saved_registers_mutex(),
- m_saved_registers_map(), m_next_saved_registers_id(1),
- m_handshake_completed(false) {
+ m_mainloop(mainloop), m_process_factory(process_factory),
+ m_stdio_communication("process.stdio") {
RegisterPacketHandlers();
}
@@ -181,37 +176,57 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() {
&GDBRemoteCommunicationServerLLGS::Handle_Z);
RegisterMemberFunctionHandler(StringExtractorGDBRemote::eServerPacketType_z,
&GDBRemoteCommunicationServerLLGS::Handle_z);
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_QPassSignals,
+ &GDBRemoteCommunicationServerLLGS::Handle_QPassSignals);
+
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_jTraceStart,
+ &GDBRemoteCommunicationServerLLGS::Handle_jTraceStart);
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_jTraceBufferRead,
+ &GDBRemoteCommunicationServerLLGS::Handle_jTraceRead);
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_jTraceMetaRead,
+ &GDBRemoteCommunicationServerLLGS::Handle_jTraceRead);
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_jTraceStop,
+ &GDBRemoteCommunicationServerLLGS::Handle_jTraceStop);
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_jTraceConfigRead,
+ &GDBRemoteCommunicationServerLLGS::Handle_jTraceConfigRead);
RegisterPacketHandler(StringExtractorGDBRemote::eServerPacketType_k,
- [this](StringExtractorGDBRemote packet, Error &error,
+ [this](StringExtractorGDBRemote packet, Status &error,
bool &interrupt, bool &quit) {
quit = true;
return this->Handle_k(packet);
});
}
-Error GDBRemoteCommunicationServerLLGS::SetLaunchArguments(
- const char *const args[], int argc) {
+Status
+GDBRemoteCommunicationServerLLGS::SetLaunchArguments(const char *const args[],
+ int argc) {
if ((argc < 1) || !args || !args[0] || !args[0][0])
- return Error("%s: no process command line specified to launch",
- __FUNCTION__);
+ return Status("%s: no process command line specified to launch",
+ __FUNCTION__);
m_process_launch_info.SetArguments(const_cast<const char **>(args), true);
- return Error();
+ return Status();
}
-Error GDBRemoteCommunicationServerLLGS::SetLaunchFlags(
- unsigned int launch_flags) {
+Status
+GDBRemoteCommunicationServerLLGS::SetLaunchFlags(unsigned int launch_flags) {
m_process_launch_info.GetFlags().Set(launch_flags);
- return Error();
+ return Status();
}
-Error GDBRemoteCommunicationServerLLGS::LaunchProcess() {
+Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
if (!m_process_launch_info.GetArguments().GetArgumentCount())
- return Error("%s: no process command line specified to launch",
- __FUNCTION__);
+ return Status("%s: no process command line specified to launch",
+ __FUNCTION__);
const bool should_forward_stdio =
m_process_launch_info.GetFileActionForFD(STDIN_FILENO) == nullptr ||
@@ -223,19 +238,20 @@ Error GDBRemoteCommunicationServerLLGS::LaunchProcess() {
const bool default_to_use_pty = true;
m_process_launch_info.FinalizeFileActions(nullptr, default_to_use_pty);
- Error error;
{
std::lock_guard<std::recursive_mutex> guard(m_debugged_process_mutex);
- assert(!m_debugged_process_sp && "lldb-server creating debugged "
+ assert(!m_debugged_process_up && "lldb-server creating debugged "
"process but one already exists");
- error = NativeProcessProtocol::Launch(m_process_launch_info, *this,
- m_mainloop, m_debugged_process_sp);
- }
-
- if (!error.Success()) {
- fprintf(stderr, "%s: failed to launch executable %s", __FUNCTION__,
- m_process_launch_info.GetArguments().GetArgumentAtIndex(0));
- return error;
+ auto process_or =
+ m_process_factory.Launch(m_process_launch_info, *this, m_mainloop);
+ if (!process_or) {
+ Status status(process_or.takeError());
+ llvm::errs() << llvm::formatv(
+ "failed to launch executable `{0}`: {1}",
+ m_process_launch_info.GetArguments().GetArgumentAtIndex(0), status);
+ return status;
+ }
+ m_debugged_process_up = std::move(*process_or);
}
// Handle mirroring of inferior stdout/stderr over the gdb-remote protocol
@@ -248,22 +264,21 @@ Error GDBRemoteCommunicationServerLLGS::LaunchProcess() {
// nullptr means it's not redirected to file or pty (in case of LLGS local)
// at least one of stdio will be transferred pty<->gdb-remote
// we need to give the pty master handle to this object to read and/or write
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " setting up stdout/stderr redirection via $O gdb-remote commands",
- __FUNCTION__, m_debugged_process_sp->GetID());
+ LLDB_LOG(log,
+ "pid = {0}: setting up stdout/stderr redirection via $O "
+ "gdb-remote commands",
+ m_debugged_process_up->GetID());
// Setup stdout/stderr mapping from inferior to $O
- auto terminal_fd = m_debugged_process_sp->GetTerminalFileDescriptor();
+ auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor();
if (terminal_fd >= 0) {
if (log)
log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting "
"inferior STDIO fd to %d",
__FUNCTION__, terminal_fd);
- error = SetSTDIOFileDescriptor(terminal_fd);
- if (error.Fail())
- return error;
+ Status status = SetSTDIOFileDescriptor(terminal_fd);
+ if (status.Fail())
+ return status;
} else {
if (log)
log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
@@ -271,23 +286,20 @@ Error GDBRemoteCommunicationServerLLGS::LaunchProcess() {
__FUNCTION__, terminal_fd);
}
} else {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " skipping stdout/stderr redirection via $O: inferior will "
- "communicate over client-provided file descriptors",
- __FUNCTION__, m_debugged_process_sp->GetID());
+ LLDB_LOG(log,
+ "pid = {0} skipping stdout/stderr redirection via $O: inferior "
+ "will communicate over client-provided file descriptors",
+ m_debugged_process_up->GetID());
}
printf("Launched '%s' as process %" PRIu64 "...\n",
m_process_launch_info.GetArguments().GetArgumentAtIndex(0),
- m_process_launch_info.GetProcessID());
+ m_debugged_process_up->GetID());
- return error;
+ return Status();
}
-Error GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
- Error error;
-
+Status GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64,
@@ -295,32 +307,33 @@ Error GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
// Before we try to attach, make sure we aren't already monitoring something
// else.
- if (m_debugged_process_sp &&
- m_debugged_process_sp->GetID() != LLDB_INVALID_PROCESS_ID)
- return Error("cannot attach to a process %" PRIu64
- " when another process with pid %" PRIu64
- " is being debugged.",
- pid, m_debugged_process_sp->GetID());
+ if (m_debugged_process_up &&
+ m_debugged_process_up->GetID() != LLDB_INVALID_PROCESS_ID)
+ return Status("cannot attach to a process %" PRIu64
+ " when another process with pid %" PRIu64
+ " is being debugged.",
+ pid, m_debugged_process_up->GetID());
// Try to attach.
- error = NativeProcessProtocol::Attach(pid, *this, m_mainloop,
- m_debugged_process_sp);
- if (!error.Success()) {
- fprintf(stderr, "%s: failed to attach to process %" PRIu64 ": %s",
- __FUNCTION__, pid, error.AsCString());
- return error;
+ auto process_or = m_process_factory.Attach(pid, *this, m_mainloop);
+ if (!process_or) {
+ Status status(process_or.takeError());
+ llvm::errs() << llvm::formatv("failed to attach to process {0}: {1}", pid,
+ status);
+ return status;
}
+ m_debugged_process_up = std::move(*process_or);
// Setup stdout/stderr mapping from inferior.
- auto terminal_fd = m_debugged_process_sp->GetTerminalFileDescriptor();
+ auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor();
if (terminal_fd >= 0) {
if (log)
log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting "
"inferior STDIO fd to %d",
__FUNCTION__, terminal_fd);
- error = SetSTDIOFileDescriptor(terminal_fd);
- if (error.Fail())
- return error;
+ Status status = SetSTDIOFileDescriptor(terminal_fd);
+ if (status.Fail())
+ return status;
} else {
if (log)
log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
@@ -329,8 +342,7 @@ Error GDBRemoteCommunicationServerLLGS::AttachToProcess(lldb::pid_t pid) {
}
printf("Attached to process %" PRIu64 "...\n", pid);
-
- return error;
+ return Status();
}
void GDBRemoteCommunicationServerLLGS::InitializeDelegate(
@@ -352,53 +364,23 @@ GDBRemoteCommunicationServerLLGS::SendWResponse(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
// send W notification
- ExitType exit_type = ExitType::eExitTypeInvalid;
- int return_code = 0;
- std::string exit_description;
-
- const bool got_exit_info =
- process->GetExitStatus(&exit_type, &return_code, exit_description);
- if (!got_exit_info) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- ", failed to retrieve process exit status",
- __FUNCTION__, process->GetID());
+ auto wait_status = process->GetExitStatus();
+ if (!wait_status) {
+ LLDB_LOG(log, "pid = {0}, failed to retrieve process exit status",
+ process->GetID());
StreamGDBRemote response;
response.PutChar('E');
response.PutHex8(GDBRemoteServerError::eErrorExitStatus);
return SendPacketNoLock(response.GetString());
- } else {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- ", returning exit type %d, return code %d [%s]",
- __FUNCTION__, process->GetID(), exit_type, return_code,
- exit_description.c_str());
-
- StreamGDBRemote response;
-
- char return_type_code;
- switch (exit_type) {
- case ExitType::eExitTypeExit:
- return_type_code = 'W';
- break;
- case ExitType::eExitTypeSignal:
- return_type_code = 'X';
- break;
- case ExitType::eExitTypeStop:
- return_type_code = 'S';
- break;
- case ExitType::eExitTypeInvalid:
- return_type_code = 'E';
- break;
- }
- response.PutChar(return_type_code);
+ }
- // POSIX exit status limited to unsigned 8 bits.
- response.PutHex8(return_code);
+ LLDB_LOG(log, "pid = {0}, returning exit type {1}", process->GetID(),
+ *wait_status);
- return SendPacketNoLock(response.GetString());
- }
+ StreamGDBRemote response;
+ response.Format("{0:g}", *wait_status);
+ return SendPacketNoLock(response.GetString());
}
static void AppendHexValue(StreamString &response, const uint8_t *buf,
@@ -415,10 +397,11 @@ static void AppendHexValue(StreamString &response, const uint8_t *buf,
static void WriteRegisterValueInHexFixedWidth(
StreamString &response, NativeRegisterContextSP &reg_ctx_sp,
- const RegisterInfo &reg_info, const RegisterValue *reg_value_p) {
+ const RegisterInfo &reg_info, const RegisterValue *reg_value_p,
+ lldb::ByteOrder byte_order) {
RegisterValue reg_value;
if (!reg_value_p) {
- Error error = reg_ctx_sp->ReadRegister(&reg_info, reg_value);
+ Status error = reg_ctx_sp->ReadRegister(&reg_info, reg_value);
if (error.Success())
reg_value_p = &reg_value;
// else log.
@@ -426,7 +409,8 @@ static void WriteRegisterValueInHexFixedWidth(
if (reg_value_p) {
AppendHexValue(response, (const uint8_t *)reg_value_p->GetBytes(),
- reg_value_p->GetByteSize(), false);
+ reg_value_p->GetByteSize(),
+ byte_order == lldb::eByteOrderLittle);
} else {
// Zero-out any unreadable values.
if (reg_info.byte_size > 0) {
@@ -436,8 +420,7 @@ static void WriteRegisterValueInHexFixedWidth(
}
}
-static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread,
- bool abridged) {
+static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
NativeRegisterContextSP reg_ctx_sp = thread.GetRegisterContext();
@@ -462,11 +445,8 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread,
static const uint32_t k_expedited_registers[] = {
LLDB_REGNUM_GENERIC_PC, LLDB_REGNUM_GENERIC_SP, LLDB_REGNUM_GENERIC_FP,
LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM};
- static const uint32_t k_abridged_expedited_registers[] = {
- LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM};
- for (const uint32_t *generic_reg_p = abridged ? k_abridged_expedited_registers
- : k_expedited_registers;
+ for (const uint32_t *generic_reg_p = k_expedited_registers;
*generic_reg_p != LLDB_INVALID_REGNUM; ++generic_reg_p) {
uint32_t reg_num = reg_ctx_sp->ConvertRegisterKindToRegisterNumber(
eRegisterKindGeneric, *generic_reg_p);
@@ -489,7 +469,7 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread,
// registers.
RegisterValue reg_value;
- Error error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
+ Status error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
if (error.Fail()) {
if (log)
log->Printf("%s failed to read register '%s' index %" PRIu32 ": %s",
@@ -501,7 +481,7 @@ static JSONObject::SP GetRegistersAsJSON(NativeThreadProtocol &thread,
StreamString stream;
WriteRegisterValueInHexFixedWidth(stream, reg_ctx_sp, *reg_info_p,
- &reg_value);
+ &reg_value, lldb::eByteOrderBig);
register_object_sp->SetObject(
llvm::to_string(reg_num),
@@ -567,8 +547,10 @@ static JSONArray::SP GetJSONThreadsInfo(NativeProcessProtocol &process,
JSONObject::SP thread_obj_sp = std::make_shared<JSONObject>();
threads_array_sp->AppendObject(thread_obj_sp);
- if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread_sp, abridged))
- thread_obj_sp->SetObject("registers", registers_sp);
+ if (!abridged) {
+ if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread_sp))
+ thread_obj_sp->SetObject("registers", registers_sp);
+ }
thread_obj_sp->SetObject("tid", std::make_shared<JSONNumber>(tid));
if (signum != 0)
@@ -614,18 +596,15 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
// Ensure we have a debugged process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
return SendErrorResponse(50);
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s preparing packet for pid %" PRIu64
- " tid %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID(), tid);
+ LLDB_LOG(log, "preparing packet for pid {0} tid {1}",
+ m_debugged_process_up->GetID(), tid);
// Ensure we can get info on the given thread.
- NativeThreadProtocolSP thread_sp(m_debugged_process_sp->GetThreadByID(tid));
+ NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
if (!thread_sp)
return SendErrorResponse(51);
@@ -646,13 +625,11 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
// Output the T packet with the thread
response.PutChar('T');
int signum = tid_stop_info.details.signal.signo;
- if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " tid %" PRIu64
- " got signal signo = %d, reason = %d, exc_type = %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID(), tid, signum,
- tid_stop_info.reason, tid_stop_info.details.exception.type);
- }
+ LLDB_LOG(
+ log,
+ "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}",
+ m_debugged_process_up->GetID(), tid, signum, int(tid_stop_info.reason),
+ tid_stop_info.details.exception.type);
// Print the signal number.
response.PutHex8(signum & 0xff);
@@ -690,9 +667,9 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
uint32_t thread_index = 0;
NativeThreadProtocolSP listed_thread_sp;
for (listed_thread_sp =
- m_debugged_process_sp->GetThreadAtIndex(thread_index);
+ m_debugged_process_up->GetThreadAtIndex(thread_index);
listed_thread_sp; ++thread_index,
- listed_thread_sp = m_debugged_process_sp->GetThreadAtIndex(
+ listed_thread_sp = m_debugged_process_up->GetThreadAtIndex(
thread_index)) {
if (thread_index > 0)
response.PutChar(',');
@@ -709,18 +686,52 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
if (thread_index > 0) {
const bool threads_with_valid_stop_info_only = true;
JSONArray::SP threads_info_sp = GetJSONThreadsInfo(
- *m_debugged_process_sp, threads_with_valid_stop_info_only);
+ *m_debugged_process_up, threads_with_valid_stop_info_only);
if (threads_info_sp) {
response.PutCString("jstopinfo:");
StreamString unescaped_response;
threads_info_sp->Write(unescaped_response);
response.PutCStringAsRawHex8(unescaped_response.GetData());
response.PutChar(';');
- } else if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to prepare a "
- "jstopinfo field for pid %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID());
+ } else
+ LLDB_LOG(log, "failed to prepare a jstopinfo field for pid {0}",
+ m_debugged_process_up->GetID());
}
+
+ uint32_t i = 0;
+ response.PutCString("thread-pcs");
+ char delimiter = ':';
+ for (NativeThreadProtocolSP thread_sp;
+ (thread_sp = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr;
+ ++i) {
+ NativeRegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
+ if (!reg_ctx_sp)
+ continue;
+
+ uint32_t reg_to_read = reg_ctx_sp->ConvertRegisterKindToRegisterNumber(
+ eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ const RegisterInfo *const reg_info_p =
+ reg_ctx_sp->GetRegisterInfoAtIndex(reg_to_read);
+
+ RegisterValue reg_value;
+ Status error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
+ if (error.Fail()) {
+ if (log)
+ log->Printf("%s failed to read register '%s' index %" PRIu32 ": %s",
+ __FUNCTION__,
+ reg_info_p->name ? reg_info_p->name
+ : "<unnamed-register>",
+ reg_to_read, error.AsCString());
+ continue;
+ }
+
+ response.PutChar(delimiter);
+ delimiter = ',';
+ WriteRegisterValueInHexFixedWidth(response, reg_ctx_sp, *reg_info_p,
+ &reg_value, endian::InlHostByteOrder());
+ }
+
+ response.PutChar(';');
}
//
@@ -757,11 +768,11 @@ GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread(
} else if (reg_info_p->value_regs == nullptr) {
// Only expediate registers that are not contained in other registers.
RegisterValue reg_value;
- Error error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
+ Status error = reg_ctx_sp->ReadRegister(reg_info_p, reg_value);
if (error.Success()) {
response.Printf("%.02x:", *reg_num_p);
WriteRegisterValueInHexFixedWidth(response, reg_ctx_sp, *reg_info_p,
- &reg_value);
+ &reg_value, lldb::eByteOrderBig);
response.PutChar(';');
} else {
if (log)
@@ -924,7 +935,7 @@ void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() {
bool interrupt = false;
bool done = false;
- Error error;
+ Status error;
while (true) {
const PacketResult result = GetPacketAndSendResponse(
std::chrono::microseconds(0), error, interrupt, done);
@@ -942,12 +953,12 @@ void GDBRemoteCommunicationServerLLGS::DataAvailableCallback() {
}
}
-Error GDBRemoteCommunicationServerLLGS::InitializeConnection(
+Status GDBRemoteCommunicationServerLLGS::InitializeConnection(
std::unique_ptr<Connection> &&connection) {
IOObjectSP read_object_sp = connection->GetReadObject();
GDBRemoteCommunicationServer::SetConnection(connection.release());
- Error error;
+ Status error;
m_network_handle_up = m_mainloop.RegisterReadObject(
read_object_sp, [this](MainLoopBase &) { DataAvailableCallback(); },
error);
@@ -969,8 +980,8 @@ GDBRemoteCommunicationServerLLGS::SendONotification(const char *buffer,
return SendPacketNoLock(response.GetString());
}
-Error GDBRemoteCommunicationServerLLGS::SetSTDIOFileDescriptor(int fd) {
- Error error;
+Status GDBRemoteCommunicationServerLLGS::SetSTDIOFileDescriptor(int fd) {
+ Status error;
// Set up the reading/handling of process I/O
std::unique_ptr<ConnectionFileDescriptor> conn_up(
@@ -988,7 +999,7 @@ Error GDBRemoteCommunicationServerLLGS::SetSTDIOFileDescriptor(int fd) {
return error;
}
- return Error();
+ return Status();
}
void GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding() {
@@ -996,7 +1007,7 @@ void GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding() {
if (!m_stdio_communication.IsConnected())
return;
- Error error;
+ Status error;
lldbassert(!m_stdio_handle_up);
m_stdio_handle_up = m_mainloop.RegisterReadObject(
m_stdio_communication.GetConnection()->GetReadObject(),
@@ -1019,7 +1030,7 @@ void GDBRemoteCommunicationServerLLGS::StopSTDIOForwarding() {
void GDBRemoteCommunicationServerLLGS::SendProcessOutput() {
char buffer[1024];
ConnectionStatus status;
- Error error;
+ Status error;
while (true) {
size_t bytes_read = m_stdio_communication.Read(
buffer, sizeof buffer, std::chrono::microseconds(0), status, &error);
@@ -1047,14 +1058,239 @@ void GDBRemoteCommunicationServerLLGS::SendProcessOutput() {
}
GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_jTraceStart(
+ StringExtractorGDBRemote &packet) {
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
+ // Fail if we don't have a current process.
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
+ return SendErrorResponse(68);
+
+ if (!packet.ConsumeFront("jTraceStart:"))
+ return SendIllFormedResponse(packet, "jTraceStart: Ill formed packet ");
+
+ TraceOptions options;
+ uint64_t type = std::numeric_limits<uint64_t>::max();
+ uint64_t buffersize = std::numeric_limits<uint64_t>::max();
+ lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
+ uint64_t metabuffersize = std::numeric_limits<uint64_t>::max();
+
+ auto json_object = StructuredData::ParseJSON(packet.Peek());
+
+ if (!json_object ||
+ json_object->GetType() != lldb::eStructuredDataTypeDictionary)
+ return SendIllFormedResponse(packet, "jTraceStart: Ill formed packet ");
+
+ auto json_dict = json_object->GetAsDictionary();
+
+ json_dict->GetValueForKeyAsInteger("metabuffersize", metabuffersize);
+ options.setMetaDataBufferSize(metabuffersize);
+
+ json_dict->GetValueForKeyAsInteger("buffersize", buffersize);
+ options.setTraceBufferSize(buffersize);
+
+ json_dict->GetValueForKeyAsInteger("type", type);
+ options.setType(static_cast<lldb::TraceType>(type));
+
+ json_dict->GetValueForKeyAsInteger("threadid", tid);
+ options.setThreadID(tid);
+
+ StructuredData::ObjectSP custom_params_sp =
+ json_dict->GetValueForKey("params");
+ if (custom_params_sp &&
+ custom_params_sp->GetType() != lldb::eStructuredDataTypeDictionary)
+ return SendIllFormedResponse(packet, "jTraceStart: Ill formed packet ");
+
+ options.setTraceParams(
+ static_pointer_cast<StructuredData::Dictionary>(custom_params_sp));
+
+ if (buffersize == std::numeric_limits<uint64_t>::max() ||
+ type != lldb::TraceType::eTraceTypeProcessorTrace) {
+ LLDB_LOG(log, "Ill formed packet buffersize = {0} type = {1}", buffersize,
+ type);
+ return SendIllFormedResponse(packet, "JTrace:start: Ill formed packet ");
+ }
+
+ Status error;
+ lldb::user_id_t uid = LLDB_INVALID_UID;
+ uid = m_debugged_process_up->StartTrace(options, error);
+ LLDB_LOG(log, "uid is {0} , error is {1}", uid, error.GetError());
+ if (error.Fail())
+ return SendErrorResponse(error);
+
+ StreamGDBRemote response;
+ response.Printf("%" PRIx64, uid);
+ return SendPacketNoLock(response.GetString());
+}
+
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_jTraceStop(
+ StringExtractorGDBRemote &packet) {
+ // Fail if we don't have a current process.
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
+ return SendErrorResponse(68);
+
+ if (!packet.ConsumeFront("jTraceStop:"))
+ return SendIllFormedResponse(packet, "jTraceStop: Ill formed packet ");
+
+ lldb::user_id_t uid = LLDB_INVALID_UID;
+ lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
+
+ auto json_object = StructuredData::ParseJSON(packet.Peek());
+
+ if (!json_object ||
+ json_object->GetType() != lldb::eStructuredDataTypeDictionary)
+ return SendIllFormedResponse(packet, "jTraceStop: Ill formed packet ");
+
+ auto json_dict = json_object->GetAsDictionary();
+
+ if (!json_dict->GetValueForKeyAsInteger("traceid", uid))
+ return SendIllFormedResponse(packet, "jTraceStop: Ill formed packet ");
+
+ json_dict->GetValueForKeyAsInteger("threadid", tid);
+
+ Status error = m_debugged_process_up->StopTrace(uid, tid);
+
+ if (error.Fail())
+ return SendErrorResponse(error);
+
+ return SendOKResponse();
+}
+
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_jTraceConfigRead(
+ StringExtractorGDBRemote &packet) {
+
+ // Fail if we don't have a current process.
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
+ return SendErrorResponse(68);
+
+ if (!packet.ConsumeFront("jTraceConfigRead:"))
+ return SendIllFormedResponse(packet,
+ "jTraceConfigRead: Ill formed packet ");
+
+ lldb::user_id_t uid = LLDB_INVALID_UID;
+ lldb::tid_t threadid = LLDB_INVALID_THREAD_ID;
+
+ auto json_object = StructuredData::ParseJSON(packet.Peek());
+
+ if (!json_object ||
+ json_object->GetType() != lldb::eStructuredDataTypeDictionary)
+ return SendIllFormedResponse(packet,
+ "jTraceConfigRead: Ill formed packet ");
+
+ auto json_dict = json_object->GetAsDictionary();
+
+ if (!json_dict->GetValueForKeyAsInteger("traceid", uid))
+ return SendIllFormedResponse(packet,
+ "jTraceConfigRead: Ill formed packet ");
+
+ json_dict->GetValueForKeyAsInteger("threadid", threadid);
+
+ TraceOptions options;
+ StreamGDBRemote response;
+
+ options.setThreadID(threadid);
+ Status error = m_debugged_process_up->GetTraceConfig(uid, options);
+
+ if (error.Fail())
+ return SendErrorResponse(error);
+
+ StreamGDBRemote escaped_response;
+ StructuredData::Dictionary json_packet;
+
+ json_packet.AddIntegerItem("type", options.getType());
+ json_packet.AddIntegerItem("buffersize", options.getTraceBufferSize());
+ json_packet.AddIntegerItem("metabuffersize", options.getMetaDataBufferSize());
+
+ StructuredData::DictionarySP custom_params = options.getTraceParams();
+ if (custom_params)
+ json_packet.AddItem("params", custom_params);
+
+ StreamString json_string;
+ json_packet.Dump(json_string, false);
+ escaped_response.PutEscapedBytes(json_string.GetData(),
+ json_string.GetSize());
+ return SendPacketNoLock(escaped_response.GetString());
+}
+
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_jTraceRead(
+ StringExtractorGDBRemote &packet) {
+
+ // Fail if we don't have a current process.
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
+ return SendErrorResponse(68);
+
+ enum PacketType { MetaData, BufferData };
+ PacketType tracetype = MetaData;
+
+ if (packet.ConsumeFront("jTraceBufferRead:"))
+ tracetype = BufferData;
+ else if (packet.ConsumeFront("jTraceMetaRead:"))
+ tracetype = MetaData;
+ else {
+ return SendIllFormedResponse(packet, "jTrace: Ill formed packet ");
+ }
+
+ lldb::user_id_t uid = LLDB_INVALID_UID;
+
+ uint64_t byte_count = std::numeric_limits<uint64_t>::max();
+ lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
+ uint64_t offset = std::numeric_limits<uint64_t>::max();
+
+ auto json_object = StructuredData::ParseJSON(packet.Peek());
+
+ if (!json_object ||
+ json_object->GetType() != lldb::eStructuredDataTypeDictionary)
+ return SendIllFormedResponse(packet, "jTrace: Ill formed packet ");
+
+ auto json_dict = json_object->GetAsDictionary();
+
+ if (!json_dict->GetValueForKeyAsInteger("traceid", uid) ||
+ !json_dict->GetValueForKeyAsInteger("offset", offset) ||
+ !json_dict->GetValueForKeyAsInteger("buffersize", byte_count))
+ return SendIllFormedResponse(packet, "jTrace: Ill formed packet ");
+
+ json_dict->GetValueForKeyAsInteger("threadid", tid);
+
+ // Allocate the response buffer.
+ std::unique_ptr<uint8_t[]> buffer (new (std::nothrow) uint8_t[byte_count]);
+ if (!buffer)
+ return SendErrorResponse(0x78);
+
+ StreamGDBRemote response;
+ Status error;
+ llvm::MutableArrayRef<uint8_t> buf(buffer.get(), byte_count);
+
+ if (tracetype == BufferData)
+ error = m_debugged_process_up->GetData(uid, tid, buf, offset);
+ else if (tracetype == MetaData)
+ error = m_debugged_process_up->GetMetaData(uid, tid, buf, offset);
+
+ if (error.Fail())
+ return SendErrorResponse(error);
+
+ for (auto i : buf)
+ response.PutHex8(i);
+
+ StreamGDBRemote escaped_response;
+ escaped_response.PutEscapedBytes(response.GetData(), response.GetSize());
+ return SendPacketNoLock(escaped_response.GetString());
+}
+
+GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qProcessInfo(
StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
return SendErrorResponse(68);
- lldb::pid_t pid = m_debugged_process_sp->GetID();
+ lldb::pid_t pid = m_debugged_process_up->GetID();
if (pid == LLDB_INVALID_PROCESS_ID)
return SendErrorResponse(1);
@@ -1071,16 +1307,16 @@ GDBRemoteCommunicationServerLLGS::Handle_qProcessInfo(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
return SendErrorResponse(68);
// Make sure we set the current thread so g and p packets return
// the data the gdb will expect.
- lldb::tid_t tid = m_debugged_process_sp->GetCurrentThreadID();
+ lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
SetCurrentThreadID(tid);
- NativeThreadProtocolSP thread_sp = m_debugged_process_sp->GetCurrentThread();
+ NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetCurrentThread();
if (!thread_sp)
return SendErrorResponse(69);
@@ -1096,20 +1332,15 @@ GDBRemoteCommunicationServerLLGS::Handle_k(StringExtractorGDBRemote &packet) {
StopSTDIOForwarding();
- if (!m_debugged_process_sp) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s No debugged process found.",
- __FUNCTION__);
+ if (!m_debugged_process_up) {
+ LLDB_LOG(log, "No debugged process found.");
return PacketResult::Success;
}
- Error error = m_debugged_process_sp->Kill();
- if (error.Fail() && log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s Failed to kill debugged "
- "process %" PRIu64 ": %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ Status error = m_debugged_process_up->Kill();
+ if (error.Fail())
+ LLDB_LOG(log, "Failed to kill debugged process {0}: {1}",
+ m_debugged_process_up->GetID(), error);
// No OK response for kill packet.
// return SendOKResponse ();
@@ -1157,7 +1388,7 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
// Ensure we have a native process.
- if (!m_debugged_process_sp) {
+ if (!m_debugged_process_up) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
"shared pointer",
@@ -1187,7 +1418,7 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
}
ResumeActionList resume_actions(StateType::eStateRunning, 0);
- Error error;
+ Status error;
// We have two branches: what to do if a continue thread is specified (in
// which case we target
@@ -1210,26 +1441,20 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
} else {
// Send the signal to the process since we weren't targeting a specific
// continue thread with the signal.
- error = m_debugged_process_sp->Signal(signo);
+ error = m_debugged_process_up->Signal(signo);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to send "
- "signal for process %" PRIu64 ": %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "failed to send signal for process {0}: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x52);
}
}
// Resume the threads.
- error = m_debugged_process_sp->Resume(resume_actions);
+ error = m_debugged_process_up->Resume(resume_actions);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to resume "
- "threads for process %" PRIu64 ": %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "failed to resume threads for process {0}: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x38);
}
@@ -1249,15 +1474,13 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) {
// For now just support all continue.
const bool has_continue_address = (packet.GetBytesLeft() > 0);
if (has_continue_address) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s not implemented for "
- "c{address} variant [%s remains]",
- __FUNCTION__, packet.Peek());
+ LLDB_LOG(log, "not implemented for c[address] variant [{0} remains]",
+ packet.Peek());
return SendUnimplementedResponse(packet.GetStringRef().c_str());
}
// Ensure we have a native process.
- if (!m_debugged_process_sp) {
+ if (!m_debugged_process_up) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
"shared pointer",
@@ -1268,22 +1491,14 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) {
// Build the ResumeActionList
ResumeActionList actions(StateType::eStateRunning, 0);
- Error error = m_debugged_process_sp->Resume(actions);
+ Status error = m_debugged_process_up->Resume(actions);
if (error.Fail()) {
- if (log) {
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s c failed for process %" PRIu64
- ": %s",
- __FUNCTION__, m_debugged_process_sp->GetID(), error.AsCString());
- }
+ LLDB_LOG(log, "c failed for process {0}: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(GDBRemoteServerError::eErrorResume);
}
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s continued process %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID());
-
+ LLDB_LOG(log, "continued process {0}", m_debugged_process_up->GetID());
// No response required from continue.
return PacketResult::Success;
}
@@ -1327,11 +1542,8 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont(
}
// Ensure we have a native process.
- if (!m_debugged_process_sp) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
- "shared pointer",
- __FUNCTION__);
+ if (!m_debugged_process_up) {
+ LLDB_LOG(log, "no debugged process");
return SendErrorResponse(0x36);
}
@@ -1392,44 +1604,30 @@ GDBRemoteCommunicationServerLLGS::Handle_vCont(
thread_actions.Append(thread_action);
}
- Error error = m_debugged_process_sp->Resume(thread_actions);
+ Status error = m_debugged_process_up->Resume(thread_actions);
if (error.Fail()) {
- if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s vCont failed for "
- "process %" PRIu64 ": %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
- }
+ LLDB_LOG(log, "vCont failed for process {0}: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(GDBRemoteServerError::eErrorResume);
}
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s continued process %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID());
-
+ LLDB_LOG(log, "continued process {0}", m_debugged_process_up->GetID());
// No response required from vCont.
return PacketResult::Success;
}
void GDBRemoteCommunicationServerLLGS::SetCurrentThreadID(lldb::tid_t tid) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s setting current thread "
- "id to %" PRIu64,
- __FUNCTION__, tid);
+ LLDB_LOG(log, "setting current thread id to {0}", tid);
m_current_tid = tid;
- if (m_debugged_process_sp)
- m_debugged_process_sp->SetCurrentThreadID(m_current_tid);
+ if (m_debugged_process_up)
+ m_debugged_process_up->SetCurrentThreadID(m_current_tid);
}
void GDBRemoteCommunicationServerLLGS::SetContinueThreadID(lldb::tid_t tid) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s setting continue thread "
- "id to %" PRIu64,
- __FUNCTION__, tid);
+ LLDB_LOG(log, "setting continue thread id to {0}", tid);
m_continue_tid = tid;
}
@@ -1440,10 +1638,10 @@ GDBRemoteCommunicationServerLLGS::Handle_stop_reason(
// Handle the $? gdbremote command.
// If no process, indicate error
- if (!m_debugged_process_sp)
+ if (!m_debugged_process_up)
return SendErrorResponse(02);
- return SendStopReasonForState(m_debugged_process_sp->GetState());
+ return SendStopReasonForState(m_debugged_process_up->GetState());
}
GDBRemoteCommunication::PacketResult
@@ -1464,7 +1662,7 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState(
case eStateSuspended:
case eStateStopped:
case eStateCrashed: {
- lldb::tid_t tid = m_debugged_process_sp->GetCurrentThreadID();
+ lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
// Make sure we set the current thread so g and p packets return
// the data the gdb will expect.
SetCurrentThreadID(tid);
@@ -1474,15 +1672,11 @@ GDBRemoteCommunicationServerLLGS::SendStopReasonForState(
case eStateInvalid:
case eStateUnloaded:
case eStateExited:
- return SendWResponse(m_debugged_process_sp.get());
+ return SendWResponse(m_debugged_process_up.get());
default:
- if (log) {
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- ", current state reporting not handled: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- StateAsCString(process_state));
- }
+ LLDB_LOG(log, "pid {0}, current state reporting not handled: {1}",
+ m_debugged_process_up->GetID(), process_state);
break;
}
@@ -1493,12 +1687,12 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
return SendErrorResponse(68);
// Ensure we have a thread.
- NativeThreadProtocolSP thread_sp(m_debugged_process_sp->GetThreadAtIndex(0));
+ NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadAtIndex(0));
if (!thread_sp)
return SendErrorResponse(69);
@@ -1702,47 +1896,33 @@ GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s() no process (%s), "
- "returning OK",
- __FUNCTION__,
- m_debugged_process_sp ? "invalid process id"
- : "null m_debugged_process_sp");
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ LLDB_LOG(log, "no process ({0}), returning OK",
+ m_debugged_process_up ? "invalid process id"
+ : "null m_debugged_process_up");
return SendOKResponse();
}
StreamGDBRemote response;
response.PutChar('m');
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s() starting thread iteration",
- __FUNCTION__);
-
+ LLDB_LOG(log, "starting thread iteration");
NativeThreadProtocolSP thread_sp;
uint32_t thread_index;
for (thread_index = 0,
- thread_sp = m_debugged_process_sp->GetThreadAtIndex(thread_index);
+ thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index);
thread_sp; ++thread_index,
- thread_sp = m_debugged_process_sp->GetThreadAtIndex(thread_index)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s() iterated thread %" PRIu32
- "(%s, tid=0x%" PRIx64 ")",
- __FUNCTION__, thread_index, thread_sp ? "is not null" : "null",
- thread_sp ? thread_sp->GetID() : LLDB_INVALID_THREAD_ID);
+ thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
+ LLDB_LOG(log, "iterated thread {0}({1}, tid={2})", thread_index,
+ thread_sp ? "is not null" : "null",
+ thread_sp ? thread_sp->GetID() : LLDB_INVALID_THREAD_ID);
if (thread_index > 0)
response.PutChar(',');
response.Printf("%" PRIx64, thread_sp->GetID());
}
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s() finished thread iteration",
- __FUNCTION__);
-
+ LLDB_LOG(log, "finished thread iteration");
return SendPacketNoLock(response.GetString());
}
@@ -1783,11 +1963,10 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
// Get the thread's register context.
NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
if (!reg_context_sp) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
- " failed, no register context available for the thread",
- __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+ LLDB_LOG(
+ log,
+ "pid {0} tid {1} failed, no register context available for the thread",
+ m_debugged_process_up->GetID(), thread_sp->GetID());
return SendErrorResponse(0x15);
}
@@ -1817,7 +1996,7 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
// Retrieve the value
RegisterValue reg_value;
- Error error = reg_context_sp->ReadRegister(reg_info, reg_value);
+ Status error = reg_context_sp->ReadRegister(reg_info, reg_value);
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, read of "
@@ -1870,8 +2049,8 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
// Get process architecture.
ArchSpec process_arch;
- if (!m_debugged_process_sp ||
- !m_debugged_process_sp->GetArchitecture(process_arch)) {
+ if (!m_debugged_process_up ||
+ !m_debugged_process_up->GetArchitecture(process_arch)) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to retrieve "
"inferior architecture",
@@ -1900,7 +2079,7 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
" failed, no register context available for the thread",
- __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+ __FUNCTION__, m_debugged_process_up->GetID(), thread_sp->GetID());
return SendErrorResponse(0x15);
}
@@ -1937,7 +2116,7 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
StreamGDBRemote response;
RegisterValue reg_value(reg_bytes, reg_size, process_arch.GetByteOrder());
- Error error = reg_context_sp->WriteRegister(reg_info, reg_value);
+ Status error = reg_context_sp->WriteRegister(reg_info, reg_value);
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, write of "
@@ -1954,8 +2133,8 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -1998,7 +2177,7 @@ GDBRemoteCommunicationServerLLGS::Handle_H(StringExtractorGDBRemote &packet) {
// Ensure we have the given thread when not specifying -1 (all threads) or 0
// (any thread).
if (tid != LLDB_INVALID_THREAD_ID && tid != 0) {
- NativeThreadProtocolSP thread_sp(m_debugged_process_sp->GetThreadByID(tid));
+ NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
if (!thread_sp) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
@@ -2032,8 +2211,8 @@ GDBRemoteCommunicationServerLLGS::Handle_I(StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2052,7 +2231,7 @@ GDBRemoteCommunicationServerLLGS::Handle_I(StringExtractorGDBRemote &packet) {
// TODO: enqueue this block in circular buffer and send window size to
// remote host
ConnectionStatus status;
- Error error;
+ Status error;
m_stdio_communication.Write(tmp, read, status, &error);
if (error.Fail()) {
return SendErrorResponse(0x15);
@@ -2068,30 +2247,21 @@ GDBRemoteCommunicationServerLLGS::Handle_interrupt(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ LLDB_LOG(log, "failed, no process available");
return SendErrorResponse(0x15);
}
// Interrupt the process.
- Error error = m_debugged_process_sp->Interrupt();
+ Status error = m_debugged_process_up->Interrupt();
if (error.Fail()) {
- if (log) {
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed for process %" PRIu64
- ": %s",
- __FUNCTION__, m_debugged_process_sp->GetID(), error.AsCString());
- }
+ LLDB_LOG(log, "failed for process {0}: {1}", m_debugged_process_up->GetID(),
+ error);
return SendErrorResponse(GDBRemoteServerError::eErrorResume);
}
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s stopped process %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID());
+ LLDB_LOG(log, "stopped process {0}", m_debugged_process_up->GetID());
// No response required from stop all.
return PacketResult::Success;
@@ -2102,8 +2272,8 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2145,13 +2315,13 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
// Retrieve the process memory.
size_t bytes_read = 0;
- Error error = m_debugged_process_sp->ReadMemoryWithoutTrap(
+ Status error = m_debugged_process_up->ReadMemoryWithoutTrap(
read_addr, &buf[0], byte_count, bytes_read);
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
" mem 0x%" PRIx64 ": failed to read. Error: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(), read_addr,
+ __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
error.AsCString());
return SendErrorResponse(0x08);
}
@@ -2160,7 +2330,7 @@ GDBRemoteCommunicationServerLLGS::Handle_memory_read(
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
" mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes",
- __FUNCTION__, m_debugged_process_sp->GetID(), read_addr,
+ __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
byte_count);
return SendErrorResponse(0x08);
}
@@ -2183,8 +2353,8 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2212,10 +2382,7 @@ GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) {
const uint64_t byte_count = packet.GetHexMaxU64(false, 0);
if (byte_count == 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s nothing to write: "
- "zero-length packet",
- __FUNCTION__);
+ LLDB_LOG(log, "nothing to write: zero-length packet");
return PacketResult::Success;
}
@@ -2233,12 +2400,11 @@ GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) {
StreamGDBRemote response;
const uint64_t convert_count = packet.GetHexBytes(buf, 0);
if (convert_count != byte_count) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": asked to write %" PRIu64
- " bytes, but only found %" PRIu64 " to convert.",
- __FUNCTION__, m_debugged_process_sp->GetID(), write_addr,
- byte_count, convert_count);
+ LLDB_LOG(log,
+ "pid {0} mem {1:x}: asked to write {2} bytes, but only found {3} "
+ "to convert.",
+ m_debugged_process_up->GetID(), write_addr, byte_count,
+ convert_count);
return SendIllFormedResponse(packet, "M content byte length specified did "
"not match hex-encoded content "
"length");
@@ -2246,23 +2412,17 @@ GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) {
// Write the process memory.
size_t bytes_written = 0;
- Error error = m_debugged_process_sp->WriteMemory(write_addr, &buf[0],
- byte_count, bytes_written);
+ Status error = m_debugged_process_up->WriteMemory(write_addr, &buf[0],
+ byte_count, bytes_written);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": failed to write. Error: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(), write_addr,
- error.AsCString());
+ LLDB_LOG(log, "pid {0} mem {1:x}: failed to write. Error: {2}",
+ m_debugged_process_up->GetID(), write_addr, error);
return SendErrorResponse(0x09);
}
if (bytes_written == 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " mem 0x%" PRIx64 ": wrote 0 of %" PRIu64 " requested bytes",
- __FUNCTION__, m_debugged_process_sp->GetID(), write_addr,
- byte_count);
+ LLDB_LOG(log, "pid {0} mem {1:x}: wrote 0 of {2} requested bytes",
+ m_debugged_process_up->GetID(), write_addr, byte_count);
return SendErrorResponse(0x09);
}
@@ -2282,8 +2442,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfoSupported(
// Ensure we have a process running; otherwise, we can't figure this out
// since we won't have a NativeProcessProtocol.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2293,8 +2453,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfoSupported(
// Test if we can get any region back when asking for the region around NULL.
MemoryRegionInfo region_info;
- const Error error =
- m_debugged_process_sp->GetMemoryRegionInfo(0, region_info);
+ const Status error =
+ m_debugged_process_up->GetMemoryRegionInfo(0, region_info);
if (error.Fail()) {
// We don't support memory region info collection for this
// NativeProcessProtocol.
@@ -2310,8 +2470,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
// Ensure we have a process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2331,8 +2491,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
// Get the memory region info for the target address.
MemoryRegionInfo region_info;
- const Error error =
- m_debugged_process_sp->GetMemoryRegionInfo(read_addr, region_info);
+ const Status error =
+ m_debugged_process_up->GetMemoryRegionInfo(read_addr, region_info);
if (error.Fail()) {
// Return the error message.
@@ -2376,13 +2536,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_Z(StringExtractorGDBRemote &packet) {
// Ensure we have a process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOG(log, "failed, no process available");
return SendErrorResponse(0x15);
}
@@ -2449,29 +2606,23 @@ GDBRemoteCommunicationServerLLGS::Handle_Z(StringExtractorGDBRemote &packet) {
if (want_breakpoint) {
// Try to set the breakpoint.
- const Error error =
- m_debugged_process_sp->SetBreakpoint(addr, size, want_hardware);
+ const Status error =
+ m_debugged_process_up->SetBreakpoint(addr, size, want_hardware);
if (error.Success())
return SendOKResponse();
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " failed to set breakpoint: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "pid {0} failed to set breakpoint: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x09);
} else {
// Try to set the watchpoint.
- const Error error = m_debugged_process_sp->SetWatchpoint(
+ const Status error = m_debugged_process_up->SetWatchpoint(
addr, size, watch_flags, want_hardware);
if (error.Success())
return SendOKResponse();
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " failed to set watchpoint: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "pid {0} failed to set watchpoint: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x09);
}
}
@@ -2479,13 +2630,10 @@ GDBRemoteCommunicationServerLLGS::Handle_Z(StringExtractorGDBRemote &packet) {
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_z(StringExtractorGDBRemote &packet) {
// Ensure we have a process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
- __FUNCTION__);
+ LLDB_LOG(log, "failed, no process available");
return SendErrorResponse(0x15);
}
@@ -2496,12 +2644,14 @@ GDBRemoteCommunicationServerLLGS::Handle_z(StringExtractorGDBRemote &packet) {
packet, "Too short z packet, missing software/hardware specifier");
bool want_breakpoint = true;
+ bool want_hardware = false;
const GDBStoppointType stoppoint_type =
GDBStoppointType(packet.GetS32(eStoppointInvalid));
switch (stoppoint_type) {
case eBreakpointHardware:
want_breakpoint = true;
+ want_hardware = true;
break;
case eBreakpointSoftware:
want_breakpoint = true;
@@ -2544,27 +2694,22 @@ GDBRemoteCommunicationServerLLGS::Handle_z(StringExtractorGDBRemote &packet) {
if (want_breakpoint) {
// Try to clear the breakpoint.
- const Error error = m_debugged_process_sp->RemoveBreakpoint(addr);
+ const Status error =
+ m_debugged_process_up->RemoveBreakpoint(addr, want_hardware);
if (error.Success())
return SendOKResponse();
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " failed to remove breakpoint: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "pid {0} failed to remove breakpoint: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x09);
} else {
// Try to clear the watchpoint.
- const Error error = m_debugged_process_sp->RemoveWatchpoint(addr);
+ const Status error = m_debugged_process_up->RemoveWatchpoint(addr);
if (error.Success())
return SendOKResponse();
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " failed to remove watchpoint: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "pid {0} failed to remove watchpoint: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x09);
}
}
@@ -2574,8 +2719,8 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
// Ensure we have a process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2594,7 +2739,7 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
// Double check that we have such a thread.
// TODO investigate: on MacOSX we might need to do an UpdateThreads () here.
- NativeThreadProtocolSP thread_sp = m_debugged_process_sp->GetThreadByID(tid);
+ NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetThreadByID(tid);
if (!thread_sp || thread_sp->GetID() != tid)
return SendErrorResponse(0x33);
@@ -2607,12 +2752,12 @@ GDBRemoteCommunicationServerLLGS::Handle_s(StringExtractorGDBRemote &packet) {
// All other threads stop while we're single stepping a thread.
actions.SetDefaultThreadActionIfNeeded(eStateStopped, 0);
- Error error = m_debugged_process_sp->Resume(actions);
+ Status error = m_debugged_process_up->Resume(actions);
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
" tid %" PRIu64 " Resume() failed with error: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(), tid,
+ __FUNCTION__, m_debugged_process_up->GetID(), tid,
error.AsCString());
return SendErrorResponse(0x49);
}
@@ -2625,7 +2770,7 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qXfer_auxv_read(
StringExtractorGDBRemote &packet) {
// *BSD impls should be able to do this too.
-#if defined(__linux__)
+#if defined(__linux__) || defined(__NetBSD__)
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
// Parse out the offset.
@@ -2653,10 +2798,10 @@ GDBRemoteCommunicationServerLLGS::Handle_qXfer_auxv_read(
"qXfer:auxv:read:: packet missing length");
// Grab the auxv data if we need it.
- if (!m_active_auxv_buffer_sp) {
+ if (!m_active_auxv_buffer_up) {
// Make sure we have a valid process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2665,55 +2810,45 @@ GDBRemoteCommunicationServerLLGS::Handle_qXfer_auxv_read(
}
// Grab the auxv data.
- m_active_auxv_buffer_sp = Host::GetAuxvData(m_debugged_process_sp->GetID());
- if (!m_active_auxv_buffer_sp ||
- m_active_auxv_buffer_sp->GetByteSize() == 0) {
- // Hmm, no auxv data, call that an error.
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, no auxv data "
- "retrieved",
- __FUNCTION__);
- m_active_auxv_buffer_sp.reset();
- return SendErrorResponse(0x11);
+ auto buffer_or_error = m_debugged_process_up->GetAuxvData();
+ if (!buffer_or_error) {
+ std::error_code ec = buffer_or_error.getError();
+ LLDB_LOG(log, "no auxv data retrieved: {0}", ec.message());
+ return SendErrorResponse(ec.value());
}
+ m_active_auxv_buffer_up = std::move(*buffer_or_error);
}
- // FIXME find out if/how I lock the stream here.
-
StreamGDBRemote response;
bool done_with_buffer = false;
- if (auxv_offset >= m_active_auxv_buffer_sp->GetByteSize()) {
+ llvm::StringRef buffer = m_active_auxv_buffer_up->getBuffer();
+ if (auxv_offset >= buffer.size()) {
// We have nothing left to send. Mark the buffer as complete.
response.PutChar('l');
done_with_buffer = true;
} else {
// Figure out how many bytes are available starting at the given offset.
- const uint64_t bytes_remaining =
- m_active_auxv_buffer_sp->GetByteSize() - auxv_offset;
-
- // Figure out how many bytes we're going to read.
- const uint64_t bytes_to_read =
- (auxv_length > bytes_remaining) ? bytes_remaining : auxv_length;
+ buffer = buffer.drop_front(auxv_offset);
// Mark the response type according to whether we're reading the remainder
// of the auxv data.
- if (bytes_to_read >= bytes_remaining) {
+ if (auxv_length >= buffer.size()) {
// There will be nothing left to read after this
response.PutChar('l');
done_with_buffer = true;
} else {
// There will still be bytes to read after this request.
response.PutChar('m');
+ buffer = buffer.take_front(auxv_length);
}
// Now write the data in encoded binary form.
- response.PutEscapedBytes(m_active_auxv_buffer_sp->GetBytes() + auxv_offset,
- bytes_to_read);
+ response.PutEscapedBytes(buffer.data(), buffer.size());
}
if (done_with_buffer)
- m_active_auxv_buffer_sp.reset();
+ m_active_auxv_buffer_up.reset();
return SendPacketNoLock(response.GetString());
#else
@@ -2743,23 +2878,19 @@ GDBRemoteCommunicationServerLLGS::Handle_QSaveRegisterState(
// Grab the register context for the thread.
NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
if (!reg_context_sp) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
- " failed, no register context available for the thread",
- __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+ LLDB_LOG(
+ log,
+ "pid {0} tid {1} failed, no register context available for the thread",
+ m_debugged_process_up->GetID(), thread_sp->GetID());
return SendErrorResponse(0x15);
}
// Save registers to a buffer.
DataBufferSP register_data_sp;
- Error error = reg_context_sp->ReadAllRegisterValues(register_data_sp);
+ Status error = reg_context_sp->ReadAllRegisterValues(register_data_sp);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " failed to save all register values: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "pid {0} failed to save all register values: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x75);
}
@@ -2793,10 +2924,8 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
const uint32_t save_id = packet.GetU32(0);
if (save_id == 0) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s QRestoreRegisterState "
- "packet has malformed save id, expecting decimal uint32_t",
- __FUNCTION__);
+ LLDB_LOG(log, "QRestoreRegisterState packet has malformed save id, "
+ "expecting decimal uint32_t");
return SendErrorResponse(0x76);
}
@@ -2814,11 +2943,10 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
// Grab the register context for the thread.
NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
if (!reg_context_sp) {
- if (log)
- log->Printf(
- "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
- " failed, no register context available for the thread",
- __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+ LLDB_LOG(
+ log,
+ "pid {0} tid {1} failed, no register context available for the thread",
+ m_debugged_process_up->GetID(), thread_sp->GetID());
return SendErrorResponse(0x15);
}
@@ -2830,10 +2958,9 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
// Find the register set buffer for the given save id.
auto it = m_saved_registers_map.find(save_id);
if (it == m_saved_registers_map.end()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " does not have a register set save buffer for id %" PRIu32,
- __FUNCTION__, m_debugged_process_sp->GetID(), save_id);
+ LLDB_LOG(log,
+ "pid {0} does not have a register set save buffer for id {1}",
+ m_debugged_process_up->GetID(), save_id);
return SendErrorResponse(0x77);
}
register_data_sp = it->second;
@@ -2842,13 +2969,10 @@ GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState(
m_saved_registers_map.erase(it);
}
- Error error = reg_context_sp->WriteAllRegisterValues(register_data_sp);
+ Status error = reg_context_sp->WriteAllRegisterValues(register_data_sp);
if (error.Fail()) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- " failed to restore all register values: %s",
- __FUNCTION__, m_debugged_process_sp->GetID(),
- error.AsCString());
+ LLDB_LOG(log, "pid {0} failed to restore all register values: {1}",
+ m_debugged_process_up->GetID(), error);
return SendErrorResponse(0x77);
}
@@ -2877,7 +3001,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach(
"pid %" PRIu64,
__FUNCTION__, pid);
- Error error = AttachToProcess(pid);
+ Status error = AttachToProcess(pid);
if (error.Fail()) {
if (log)
@@ -2888,7 +3012,7 @@ GDBRemoteCommunicationServerLLGS::Handle_vAttach(
}
// Notify we attached by sending a stop packet.
- return SendStopReasonForState(m_debugged_process_sp->GetState());
+ return SendStopReasonForState(m_debugged_process_up->GetState());
}
GDBRemoteCommunication::PacketResult
@@ -2898,8 +3022,8 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) {
StopSTDIOForwarding();
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
if (log)
log->Printf(
"GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2921,16 +3045,16 @@ GDBRemoteCommunicationServerLLGS::Handle_D(StringExtractorGDBRemote &packet) {
return SendIllFormedResponse(packet, "D failed to parse the process id");
}
- if (pid != LLDB_INVALID_PROCESS_ID && m_debugged_process_sp->GetID() != pid) {
+ if (pid != LLDB_INVALID_PROCESS_ID && m_debugged_process_up->GetID() != pid) {
return SendIllFormedResponse(packet, "Invalid pid");
}
- const Error error = m_debugged_process_sp->Detach();
+ const Status error = m_debugged_process_up->Detach();
if (error.Fail()) {
if (log)
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to detach from "
"pid %" PRIu64 ": %s\n",
- __FUNCTION__, m_debugged_process_sp->GetID(),
+ __FUNCTION__, m_debugged_process_up->GetID(),
error.AsCString());
return SendErrorResponse(0x01);
}
@@ -2961,24 +3085,18 @@ GDBRemoteCommunicationServerLLGS::Handle_jThreadsInfo(
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
// Ensure we have a debugged process.
- if (!m_debugged_process_sp ||
- (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+ if (!m_debugged_process_up ||
+ (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
return SendErrorResponse(50);
-
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s preparing packet for pid "
- "%" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID());
+ LLDB_LOG(log, "preparing packet for pid {0}", m_debugged_process_up->GetID());
StreamString response;
const bool threads_with_valid_stop_info_only = false;
JSONArray::SP threads_array_sp = GetJSONThreadsInfo(
- *m_debugged_process_sp, threads_with_valid_stop_info_only);
+ *m_debugged_process_up, threads_with_valid_stop_info_only);
if (!threads_array_sp) {
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to prepare a "
- "packet for pid %" PRIu64,
- __FUNCTION__, m_debugged_process_sp->GetID());
+ LLDB_LOG(log, "failed to prepare a packet for pid {0}",
+ m_debugged_process_up->GetID());
return SendErrorResponse(52);
}
@@ -2992,8 +3110,8 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qWatchpointSupportInfo(
StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)
+ if (!m_debugged_process_up ||
+ m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
return SendErrorResponse(68);
packet.SetFilePos(strlen("qWatchpointSupportInfo"));
@@ -3002,9 +3120,14 @@ GDBRemoteCommunicationServerLLGS::Handle_qWatchpointSupportInfo(
if (packet.GetChar() != ':')
return SendErrorResponse(67);
- uint32_t num = m_debugged_process_sp->GetMaxWatchpoints();
+ auto hw_debug_cap = m_debugged_process_up->GetHardwareDebugSupportInfo();
+
StreamGDBRemote response;
- response.Printf("num:%d;", num);
+ if (hw_debug_cap == llvm::None)
+ response.Printf("num:0;");
+ else
+ response.Printf("num:%d;", hw_debug_cap->second);
+
return SendPacketNoLock(response.GetString());
}
@@ -3012,8 +3135,8 @@ GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress(
StringExtractorGDBRemote &packet) {
// Fail if we don't have a current process.
- if (!m_debugged_process_sp ||
- m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)
+ if (!m_debugged_process_up ||
+ m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
return SendErrorResponse(67);
packet.SetFilePos(strlen("qFileLoadAddress:"));
@@ -3024,8 +3147,8 @@ GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress(
packet.GetHexByteString(file_name);
lldb::addr_t file_load_address = LLDB_INVALID_ADDRESS;
- Error error =
- m_debugged_process_sp->GetFileLoadAddress(file_name, file_load_address);
+ Status error =
+ m_debugged_process_up->GetFileLoadAddress(file_name, file_load_address);
if (error.Fail())
return SendErrorResponse(69);
@@ -3037,6 +3160,40 @@ GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress(
return SendPacketNoLock(response.GetString());
}
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_QPassSignals(
+ StringExtractorGDBRemote &packet) {
+ std::vector<int> signals;
+ packet.SetFilePos(strlen("QPassSignals:"));
+
+ // Read sequence of hex signal numbers divided by a semicolon and
+ // optionally spaces.
+ while (packet.GetBytesLeft() > 0) {
+ int signal = packet.GetS32(-1, 16);
+ if (signal < 0)
+ return SendIllFormedResponse(packet, "Failed to parse signal number.");
+ signals.push_back(signal);
+
+ packet.SkipSpaces();
+ char separator = packet.GetChar();
+ if (separator == '\0')
+ break; // End of string
+ if (separator != ';')
+ return SendIllFormedResponse(packet, "Invalid separator,"
+ " expected semicolon.");
+ }
+
+ // Fail if we don't have a current process.
+ if (!m_debugged_process_up)
+ return SendErrorResponse(68);
+
+ Status error = m_debugged_process_up->IgnoreSignals(signals);
+ if (error.Fail())
+ return SendErrorResponse(69);
+
+ return SendOKResponse();
+}
+
void GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection() {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
@@ -3044,7 +3201,7 @@ void GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection() {
if (m_stdio_communication.IsConnected()) {
auto connection = m_stdio_communication.GetConnection();
if (connection) {
- Error error;
+ Status error;
connection->Disconnect(&error);
if (error.Success()) {
@@ -3067,8 +3224,8 @@ NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
NativeThreadProtocolSP thread_sp;
// We have no thread if we don't have a process.
- if (!m_debugged_process_sp ||
- m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)
+ if (!m_debugged_process_up ||
+ m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
return thread_sp;
// If the client hasn't asked for thread suffix support, there will not be a
@@ -3080,9 +3237,9 @@ NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
return thread_sp;
else if (current_tid == 0) {
// Pick a thread.
- return m_debugged_process_sp->GetThreadAtIndex(0);
+ return m_debugged_process_up->GetThreadAtIndex(0);
} else
- return m_debugged_process_sp->GetThreadByID(current_tid);
+ return m_debugged_process_up->GetThreadByID(current_tid);
}
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
@@ -3112,7 +3269,7 @@ NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
const lldb::tid_t tid = packet.GetHexMaxU64(false, 0);
if (tid != 0)
- return m_debugged_process_sp->GetThreadByID(tid);
+ return m_debugged_process_up->GetThreadByID(tid);
return thread_sp;
}
@@ -3122,9 +3279,9 @@ lldb::tid_t GDBRemoteCommunicationServerLLGS::GetCurrentThreadID() const {
// Use whatever the debug process says is the current thread id
// since the protocol either didn't specify or specified we want
// any/all threads marked as the current thread.
- if (!m_debugged_process_sp)
+ if (!m_debugged_process_up)
return LLDB_INVALID_THREAD_ID;
- return m_debugged_process_sp->GetCurrentThreadID();
+ return m_debugged_process_up->GetCurrentThreadID();
}
// Use the specific current thread id set by the gdb remote protocol.
return m_current_tid;
@@ -3136,28 +3293,18 @@ uint32_t GDBRemoteCommunicationServerLLGS::GetNextSavedRegistersID() {
}
void GDBRemoteCommunicationServerLLGS::ClearProcessSpecificData() {
- Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | GDBR_LOG_PROCESS));
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s()", __FUNCTION__);
+ Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
-// Clear any auxv cached data.
-// *BSD impls should be able to do this too.
-#if defined(__linux__)
- if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s clearing auxv buffer "
- "(previously %s)",
- __FUNCTION__,
- m_active_auxv_buffer_sp ? "was set" : "was not set");
- m_active_auxv_buffer_sp.reset();
-#endif
+ LLDB_LOG(log, "clearing auxv buffer: {0}", m_active_auxv_buffer_up.get());
+ m_active_auxv_buffer_up.reset();
}
FileSpec
GDBRemoteCommunicationServerLLGS::FindModuleFile(const std::string &module_path,
const ArchSpec &arch) {
- if (m_debugged_process_sp) {
+ if (m_debugged_process_up) {
FileSpec file_spec;
- if (m_debugged_process_sp
+ if (m_debugged_process_up
->GetLoadedModuleFileSpec(module_path.c_str(), file_spec)
.Success()) {
if (file_spec.Exists())
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
index fa52cda..7119947 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
@@ -39,7 +39,9 @@ public:
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
- GDBRemoteCommunicationServerLLGS(MainLoop &mainloop);
+ GDBRemoteCommunicationServerLLGS(
+ MainLoop &mainloop,
+ const NativeProcessProtocol::Factory &process_factory);
//------------------------------------------------------------------
/// Specify the program to launch and its arguments.
@@ -51,10 +53,10 @@ public:
/// The number of elements in the args array of cstring pointers.
///
/// @return
- /// An Error object indicating the success or failure of making
+ /// An Status object indicating the success or failure of making
/// the setting.
//------------------------------------------------------------------
- Error SetLaunchArguments(const char *const args[], int argc);
+ Status SetLaunchArguments(const char *const args[], int argc);
//------------------------------------------------------------------
/// Specify the launch flags for the process.
@@ -63,10 +65,10 @@ public:
/// The launch flags to use when launching this process.
///
/// @return
- /// An Error object indicating the success or failure of making
+ /// An Status object indicating the success or failure of making
/// the setting.
//------------------------------------------------------------------
- Error SetLaunchFlags(unsigned int launch_flags);
+ Status SetLaunchFlags(unsigned int launch_flags);
//------------------------------------------------------------------
/// Launch a process with the current launch settings.
@@ -76,10 +78,10 @@ public:
/// with all the information for a child process to be launched.
///
/// @return
- /// An Error object indicating the success or failure of the
+ /// An Status object indicating the success or failure of the
/// launch.
//------------------------------------------------------------------
- Error LaunchProcess() override;
+ Status LaunchProcess() override;
//------------------------------------------------------------------
/// Attach to a process.
@@ -88,10 +90,10 @@ public:
/// configured Platform.
///
/// @return
- /// An Error object indicating the success or failure of the
+ /// An Status object indicating the success or failure of the
/// attach operation.
//------------------------------------------------------------------
- Error AttachToProcess(lldb::pid_t pid);
+ Status AttachToProcess(lldb::pid_t pid);
//------------------------------------------------------------------
// NativeProcessProtocol::NativeDelegate overrides
@@ -103,25 +105,26 @@ public:
void DidExec(NativeProcessProtocol *process) override;
- Error InitializeConnection(std::unique_ptr<Connection> &&connection);
+ Status InitializeConnection(std::unique_ptr<Connection> &&connection);
protected:
MainLoop &m_mainloop;
MainLoop::ReadHandleUP m_network_handle_up;
- lldb::tid_t m_current_tid;
- lldb::tid_t m_continue_tid;
+ const NativeProcessProtocol::Factory &m_process_factory;
+ lldb::tid_t m_current_tid = LLDB_INVALID_THREAD_ID;
+ lldb::tid_t m_continue_tid = LLDB_INVALID_THREAD_ID;
std::recursive_mutex m_debugged_process_mutex;
- NativeProcessProtocolSP m_debugged_process_sp;
+ std::unique_ptr<NativeProcessProtocol> m_debugged_process_up;
Communication m_stdio_communication;
MainLoop::ReadHandleUP m_stdio_handle_up;
- lldb::StateType m_inferior_prev_state;
- lldb::DataBufferSP m_active_auxv_buffer_sp;
+ lldb::StateType m_inferior_prev_state = lldb::StateType::eStateInvalid;
+ std::unique_ptr<llvm::MemoryBuffer> m_active_auxv_buffer_up;
std::mutex m_saved_registers_mutex;
std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
- uint32_t m_next_saved_registers_id;
- bool m_handshake_completed : 1;
+ uint32_t m_next_saved_registers_id = 1;
+ bool m_handshake_completed = false;
PacketResult SendONotification(const char *buffer, uint32_t len);
@@ -189,6 +192,14 @@ protected:
PacketResult Handle_QSaveRegisterState(StringExtractorGDBRemote &packet);
+ PacketResult Handle_jTraceStart(StringExtractorGDBRemote &packet);
+
+ PacketResult Handle_jTraceRead(StringExtractorGDBRemote &packet);
+
+ PacketResult Handle_jTraceStop(StringExtractorGDBRemote &packet);
+
+ PacketResult Handle_jTraceConfigRead(StringExtractorGDBRemote &packet);
+
PacketResult Handle_QRestoreRegisterState(StringExtractorGDBRemote &packet);
PacketResult Handle_vAttach(StringExtractorGDBRemote &packet);
@@ -203,6 +214,8 @@ protected:
PacketResult Handle_qFileLoadAddress(StringExtractorGDBRemote &packet);
+ PacketResult Handle_QPassSignals(StringExtractorGDBRemote &packet);
+
void SetCurrentThreadID(lldb::tid_t tid);
lldb::tid_t GetCurrentThreadID() const;
@@ -211,7 +224,7 @@ protected:
lldb::tid_t GetContinueThreadID() const { return m_continue_tid; }
- Error SetSTDIOFileDescriptor(int fd);
+ Status SetSTDIOFileDescriptor(int fd);
FileSpec FindModuleFile(const std::string &module_path,
const ArchSpec &arch) override;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 1106974..977c34c 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -20,25 +20,25 @@
// Other libraries and framework includes
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
-#include "lldb/Core/Log.h"
-#include "lldb/Core/StreamGDBRemote.h"
-#include "lldb/Core/StreamString.h"
-#include "lldb/Core/StructuredData.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/JSON.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/Utility/UriParser.h"
// Project includes
#include "Utility/StringExtractorGDBRemote.h"
-#include "Utility/UriParser.h"
using namespace lldb;
using namespace lldb_private;
@@ -82,8 +82,8 @@ GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
&GDBRemoteCommunicationServerPlatform::Handle_jSignalsInfo);
RegisterPacketHandler(StringExtractorGDBRemote::eServerPacketType_interrupt,
- [this](StringExtractorGDBRemote packet, Error &error,
- bool &interrupt, bool &quit) {
+ [](StringExtractorGDBRemote packet, Status &error,
+ bool &interrupt, bool &quit) {
error.SetErrorString("interrupt received");
interrupt = true;
return PacketResult::Success;
@@ -95,7 +95,7 @@ GDBRemoteCommunicationServerPlatform::GDBRemoteCommunicationServerPlatform(
//----------------------------------------------------------------------
GDBRemoteCommunicationServerPlatform::~GDBRemoteCommunicationServerPlatform() {}
-Error GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
+Status GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
const lldb_private::Args &args, std::string hostname, lldb::pid_t &pid,
uint16_t &port, std::string &socket_name) {
if (port == UINT16_MAX)
@@ -147,7 +147,7 @@ Error GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
port_ptr = nullptr;
}
- Error error = StartDebugserverProcess(
+ Status error = StartDebugserverProcess(
url.str().c_str(), nullptr, debugserver_launch_info, port_ptr, &args, -1);
pid = debugserver_launch_info.GetProcessID();
@@ -192,7 +192,7 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer(
lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID;
std::string socket_name;
- Error error =
+ Status error =
LaunchGDBServer(Args(), hostname, debugserver_pid, port, socket_name);
if (error.Fail()) {
if (log)
@@ -353,15 +353,13 @@ GDBRemoteCommunicationServerPlatform::Handle_qProcessInfo(
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir(
StringExtractorGDBRemote &packet) {
- // If this packet is sent to a platform, then change the current working
- // directory
- char cwd[PATH_MAX];
- if (getcwd(cwd, sizeof(cwd)) == NULL)
- return SendErrorResponse(errno);
+ llvm::SmallString<64> cwd;
+ if (std::error_code ec = llvm::sys::fs::current_path(cwd))
+ return SendErrorResponse(ec.value());
StreamString response;
- response.PutBytesAsRawHex8(cwd, strlen(cwd));
+ response.PutBytesAsRawHex8(cwd.data(), cwd.size());
return SendPacketNoLock(response.GetString());
}
@@ -372,10 +370,8 @@ GDBRemoteCommunicationServerPlatform::Handle_QSetWorkingDir(
std::string path;
packet.GetHexByteString(path);
- // If this packet is sent to a platform, then change the current working
- // directory
- if (::chdir(path.c_str()) != 0)
- return SendErrorResponse(errno);
+ if (std::error_code ec = llvm::sys::fs::set_current_path(path))
+ return SendErrorResponse(ec.value());
return SendOKResponse();
}
@@ -443,10 +439,10 @@ bool GDBRemoteCommunicationServerPlatform::DebugserverProcessReaped(
return true;
}
-Error GDBRemoteCommunicationServerPlatform::LaunchProcess() {
+Status GDBRemoteCommunicationServerPlatform::LaunchProcess() {
if (!m_process_launch_info.GetArguments().GetArgumentCount())
- return Error("%s: no process command line specified to launch",
- __FUNCTION__);
+ return Status("%s: no process command line specified to launch",
+ __FUNCTION__);
// specify the process monitor if not already set. This should
// generally be what happens since we need to reap started
@@ -458,7 +454,7 @@ Error GDBRemoteCommunicationServerPlatform::LaunchProcess() {
this, std::placeholders::_1),
false);
- Error error = Host::LaunchProcess(m_process_launch_info);
+ Status error = Host::LaunchProcess(m_process_launch_info);
if (!error.Success()) {
fprintf(stderr, "%s: failed to launch executable %s", __FUNCTION__,
m_process_launch_info.GetArguments().GetArgumentAtIndex(0));
@@ -532,9 +528,9 @@ bool GDBRemoteCommunicationServerPlatform::FreePortForProcess(lldb::pid_t pid) {
const FileSpec &GDBRemoteCommunicationServerPlatform::GetDomainSocketDir() {
static FileSpec g_domainsocket_dir;
- static std::once_flag g_once_flag;
+ static llvm::once_flag g_once_flag;
- std::call_once(g_once_flag, []() {
+ llvm::call_once(g_once_flag, []() {
const char *domainsocket_dir_env =
::getenv("LLDB_DEBUGSERVER_DOMAINSOCKET_DIR");
if (domainsocket_dir_env != nullptr)
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
index 472d86e..aed5106 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h
@@ -34,7 +34,7 @@ public:
~GDBRemoteCommunicationServerPlatform() override;
- Error LaunchProcess() override;
+ Status LaunchProcess() override;
// Set both ports to zero to let the platform automatically bind to
// a port chosen by the OS.
@@ -61,9 +61,9 @@ public:
void SetInferiorArguments(const lldb_private::Args &args);
- Error LaunchGDBServer(const lldb_private::Args &args, std::string hostname,
- lldb::pid_t &pid, uint16_t &port,
- std::string &socket_name);
+ Status LaunchGDBServer(const lldb_private::Args &args, std::string hostname,
+ lldb::pid_t &pid, uint16_t &port,
+ std::string &socket_name);
void SetPendingGdbServer(lldb::pid_t pid, uint16_t port,
const std::string &socket_name);
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index 27ce67d..612c714 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -12,14 +12,13 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Target.h"
-#include "lldb/Utility/Utils.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/StreamString.h"
// Project includes
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
@@ -96,8 +95,8 @@ bool GDBRemoteRegisterContext::ReadRegister(const RegisterInfo *reg_info,
// Read the register
if (ReadRegisterBytes(reg_info, m_reg_data)) {
const bool partial_data_ok = false;
- Error error(value.SetValueFromData(reg_info, m_reg_data,
- reg_info->byte_offset, partial_data_ok));
+ Status error(value.SetValueFromData(
+ reg_info, m_reg_data, reg_info->byte_offset, partial_data_ok));
return error.Success();
}
return false;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
index 5b3e04e..8ef91af 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
@@ -17,9 +17,9 @@
// Other libraries and framework includes
// Project includes
#include "Plugins/Process/Utility/DynamicRegisterInfo.h"
-#include "lldb/Core/ConstString.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Target/RegisterContext.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/DataExtractor.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-private.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 4b4d62d..e46bbeb 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -16,6 +16,7 @@
#include <netinet/in.h>
#include <sys/mman.h> // for mmap
#include <sys/socket.h>
+#include <unistd.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
@@ -35,14 +36,13 @@
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/State.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StreamString.h"
-#include "lldb/Core/Timer.h"
#include "lldb/Core/Value.h"
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostThread.h"
+#include "lldb/Host/PosixApi.h"
+#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Host/Symbols.h"
#include "lldb/Host/ThreadLauncher.h"
@@ -65,7 +65,9 @@
#include "lldb/Target/TargetList.h"
#include "lldb/Target/ThreadPlanCallFunction.h"
#include "lldb/Utility/CleanUp.h"
-#include "lldb/Utility/PseudoTerminal.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/Timer.h"
// Project includes
#include "GDBRemoteRegisterContext.h"
@@ -80,6 +82,7 @@
#include "lldb/Host/Host.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"
#define DEBUGSERVER_BASENAME "debugserver"
@@ -96,8 +99,8 @@ namespace lldb {
// function and get the packet history dumped to a file.
void DumpProcessGDBRemotePacketHistory(void *p, const char *path) {
StreamFile strm;
- Error error(strm.GetFile().Open(path, File::eOpenOptionWrite |
- File::eOpenOptionCanCreate));
+ Status error(strm.GetFile().Open(path, File::eOpenOptionWrite |
+ File::eOpenOptionCanCreate));
if (error.Success())
((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory(strm);
}
@@ -323,7 +326,7 @@ bool ProcessGDBRemote::ParsePythonTargetDefinition(
const FileSpec &target_definition_fspec) {
ScriptInterpreter *interpreter =
GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
- Error error;
+ Status error;
StructuredData::ObjectSP module_object_sp(
interpreter->LoadPluginModule(target_definition_fspec, error));
if (module_object_sp) {
@@ -576,7 +579,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
uint32_t ret_val =
opcode_extractor.GetHexBytesAvail(dwarf_opcode_bytes);
assert(dwarf_opcode_len == ret_val);
-
+ UNUSED_IF_ASSERT_DISABLED(ret_val);
reg_info.dynamic_size_dwarf_expr_bytes = dwarf_opcode_bytes.data();
}
}
@@ -598,7 +601,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
// gets called in DidAttach, when the target architecture (and
// consequently the ABI we'll get from
// the process) may be wrong.
- ABISP abi_to_use = ABI::FindPlugin(arch_to_use);
+ ABISP abi_to_use = ABI::FindPlugin(shared_from_this(), arch_to_use);
AugmentRegisterInfoViaABI(reg_info, reg_name, abi_to_use);
@@ -638,23 +641,23 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
m_register_info.Finalize(GetTarget().GetArchitecture());
}
-Error ProcessGDBRemote::WillLaunch(Module *module) {
+Status ProcessGDBRemote::WillLaunch(Module *module) {
return WillLaunchOrAttach();
}
-Error ProcessGDBRemote::WillAttachToProcessWithID(lldb::pid_t pid) {
+Status ProcessGDBRemote::WillAttachToProcessWithID(lldb::pid_t pid) {
return WillLaunchOrAttach();
}
-Error ProcessGDBRemote::WillAttachToProcessWithName(const char *process_name,
- bool wait_for_launch) {
+Status ProcessGDBRemote::WillAttachToProcessWithName(const char *process_name,
+ bool wait_for_launch) {
return WillLaunchOrAttach();
}
-Error ProcessGDBRemote::DoConnectRemote(Stream *strm,
- llvm::StringRef remote_url) {
+Status ProcessGDBRemote::DoConnectRemote(Stream *strm,
+ llvm::StringRef remote_url) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- Error error(WillLaunchOrAttach());
+ Status error(WillLaunchOrAttach());
if (error.Fail())
return error;
@@ -743,8 +746,8 @@ Error ProcessGDBRemote::DoConnectRemote(Stream *strm,
return error;
}
-Error ProcessGDBRemote::WillLaunchOrAttach() {
- Error error;
+Status ProcessGDBRemote::WillLaunchOrAttach() {
+ Status error;
m_stdio_communication.Clear();
return error;
}
@@ -752,10 +755,10 @@ Error ProcessGDBRemote::WillLaunchOrAttach() {
//----------------------------------------------------------------------
// Process Control
//----------------------------------------------------------------------
-Error ProcessGDBRemote::DoLaunch(Module *exe_module,
- ProcessLaunchInfo &launch_info) {
+Status ProcessGDBRemote::DoLaunch(Module *exe_module,
+ ProcessLaunchInfo &launch_info) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- Error error;
+ Status error;
if (log)
log->Printf("ProcessGDBRemote::%s() entered", __FUNCTION__);
@@ -964,8 +967,8 @@ Error ProcessGDBRemote::DoLaunch(Module *exe_module,
return error;
}
-Error ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
- Error error;
+Status ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
+ Status error;
// Only connect if we have a valid connect URL
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
@@ -1030,6 +1033,7 @@ Error ProcessGDBRemote::ConnectToDebugserver(llvm::StringRef connect_url) {
m_gdb_comm.GetHostInfo();
m_gdb_comm.GetVContSupported('c');
m_gdb_comm.GetVAttachOrWaitSupported();
+ m_gdb_comm.EnableErrorStringInPacket();
// Ask the remote server for the default thread id
if (GetTarget().GetNonStopModeEnabled())
@@ -1168,10 +1172,10 @@ void ProcessGDBRemote::DidLaunch() {
DidLaunchOrAttach(process_arch);
}
-Error ProcessGDBRemote::DoAttachToProcessWithID(
+Status ProcessGDBRemote::DoAttachToProcessWithID(
lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- Error error;
+ Status error;
if (log)
log->Printf("ProcessGDBRemote::%s()", __FUNCTION__);
@@ -1196,9 +1200,9 @@ Error ProcessGDBRemote::DoAttachToProcessWithID(
return error;
}
-Error ProcessGDBRemote::DoAttachToProcessWithName(
+Status ProcessGDBRemote::DoAttachToProcessWithName(
const char *process_name, const ProcessAttachInfo &attach_info) {
- Error error;
+ Status error;
// Clear out and clean up from any current state
Clear();
@@ -1235,6 +1239,32 @@ Error ProcessGDBRemote::DoAttachToProcessWithName(
return error;
}
+lldb::user_id_t ProcessGDBRemote::StartTrace(const TraceOptions &options,
+ Status &error) {
+ return m_gdb_comm.SendStartTracePacket(options, error);
+}
+
+Status ProcessGDBRemote::StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id) {
+ return m_gdb_comm.SendStopTracePacket(uid, thread_id);
+}
+
+Status ProcessGDBRemote::GetData(lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset) {
+ return m_gdb_comm.SendGetDataPacket(uid, thread_id, buffer, offset);
+}
+
+Status ProcessGDBRemote::GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset) {
+ return m_gdb_comm.SendGetMetaDataPacket(uid, thread_id, buffer, offset);
+}
+
+Status ProcessGDBRemote::GetTraceConfig(lldb::user_id_t uid,
+ TraceOptions &options) {
+ return m_gdb_comm.SendGetTraceConfigPacket(uid, options);
+}
+
void ProcessGDBRemote::DidExit() {
// When we exit, disconnect from the GDB server communications
m_gdb_comm.Disconnect();
@@ -1246,18 +1276,18 @@ void ProcessGDBRemote::DidAttach(ArchSpec &process_arch) {
DidLaunchOrAttach(process_arch);
}
-Error ProcessGDBRemote::WillResume() {
+Status ProcessGDBRemote::WillResume() {
m_continue_c_tids.clear();
m_continue_C_tids.clear();
m_continue_s_tids.clear();
m_continue_S_tids.clear();
m_jstopinfo_sp.reset();
m_jthreadsinfo_sp.reset();
- return Error();
+ return Status();
}
-Error ProcessGDBRemote::DoResume() {
- Error error;
+Status ProcessGDBRemote::DoResume() {
+ Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
if (log)
log->Printf("ProcessGDBRemote::Resume()");
@@ -1616,9 +1646,7 @@ bool ProcessGDBRemote::UpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) {
// locker will keep a mutex locked until it goes out of scope
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_THREAD));
- if (log && log->GetMask().Test(GDBR_LOG_VERBOSE))
- log->Printf("ProcessGDBRemote::%s (pid = %" PRIu64 ")", __FUNCTION__,
- GetID());
+ LLDB_LOGV(log, "pid = {0}", GetID());
size_t num_thread_ids = m_thread_ids.size();
// The "m_thread_ids" thread ID list should always be updated after each stop
@@ -1637,39 +1665,14 @@ bool ProcessGDBRemote::UpdateThreadList(ThreadList &old_thread_list,
old_thread_list_copy.RemoveThreadByProtocolID(tid, false));
if (!thread_sp) {
thread_sp.reset(new ThreadGDBRemote(*this, tid));
- if (log && log->GetMask().Test(GDBR_LOG_VERBOSE))
- log->Printf("ProcessGDBRemote::%s Making new thread: %p for thread "
- "ID: 0x%" PRIx64 ".\n",
- __FUNCTION__, static_cast<void *>(thread_sp.get()),
- thread_sp->GetID());
+ LLDB_LOGV(log, "Making new thread: {0} for thread ID: {1:x}.",
+ thread_sp.get(), thread_sp->GetID());
} else {
- if (log && log->GetMask().Test(GDBR_LOG_VERBOSE))
- log->Printf("ProcessGDBRemote::%s Found old thread: %p for thread "
- "ID: 0x%" PRIx64 ".\n",
- __FUNCTION__, static_cast<void *>(thread_sp.get()),
- thread_sp->GetID());
- }
- // The m_thread_pcs vector has pc values in big-endian order, not
- // target-endian, unlike most
- // of the register read/write packets in gdb-remote protocol.
- // Early in the process startup, we may not yet have set the process
- // ByteOrder so we ignore these;
- // they are a performance improvement over fetching thread register values
- // individually, the
- // method we will fall back to if needed.
- if (m_thread_ids.size() == m_thread_pcs.size() && thread_sp.get() &&
- GetByteOrder() != eByteOrderInvalid) {
- ThreadGDBRemote *gdb_thread =
- static_cast<ThreadGDBRemote *>(thread_sp.get());
- RegisterContextSP reg_ctx_sp(thread_sp->GetRegisterContext());
- if (reg_ctx_sp) {
- uint32_t pc_regnum = reg_ctx_sp->ConvertRegisterKindToRegisterNumber(
- eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- if (pc_regnum != LLDB_INVALID_REGNUM) {
- gdb_thread->PrivateSetRegisterValue(pc_regnum, m_thread_pcs[i]);
- }
- }
+ LLDB_LOGV(log, "Found old thread: {0} for thread ID: {1:x}.",
+ thread_sp.get(), thread_sp->GetID());
}
+
+ SetThreadPc(thread_sp, i);
new_thread_list.AddThreadSortedByIndexID(thread_sp);
}
}
@@ -1689,6 +1692,22 @@ bool ProcessGDBRemote::UpdateThreadList(ThreadList &old_thread_list,
return true;
}
+void ProcessGDBRemote::SetThreadPc(const ThreadSP &thread_sp, uint64_t index) {
+ if (m_thread_ids.size() == m_thread_pcs.size() && thread_sp.get() &&
+ GetByteOrder() != eByteOrderInvalid) {
+ ThreadGDBRemote *gdb_thread =
+ static_cast<ThreadGDBRemote *>(thread_sp.get());
+ RegisterContextSP reg_ctx_sp(thread_sp->GetRegisterContext());
+ if (reg_ctx_sp) {
+ uint32_t pc_regnum = reg_ctx_sp->ConvertRegisterKindToRegisterNumber(
+ eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
+ if (pc_regnum != LLDB_INVALID_REGNUM) {
+ gdb_thread->PrivateSetRegisterValue(pc_regnum, m_thread_pcs[index]);
+ }
+ }
+ }
+}
+
bool ProcessGDBRemote::GetThreadStopInfoFromJSON(
ThreadGDBRemote *thread, const StructuredData::ObjectSP &thread_infos_sp) {
// See if we got thread stop infos for all threads via the "jThreadsInfo"
@@ -1774,6 +1793,11 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
static_cast<ThreadGDBRemote *>(thread_sp.get());
gdb_thread->GetRegisterContext()->InvalidateIfNeeded(true);
+ auto iter = std::find(m_thread_ids.begin(), m_thread_ids.end(), tid);
+ if (iter != m_thread_ids.end()) {
+ SetThreadPc(thread_sp, iter - m_thread_ids.begin());
+ }
+
for (const auto &pair : expedited_register_map) {
StringExtractor reg_value_extractor;
reg_value_extractor.GetStringRef() = pair.second;
@@ -2118,9 +2142,9 @@ ProcessGDBRemote::SetThreadStopInfo(StructuredData::Dictionary *thread_dict) {
if (mem_cache_dict->GetValueForKeyAsInteger<lldb::addr_t>(
"address", mem_cache_addr)) {
if (mem_cache_addr != LLDB_INVALID_ADDRESS) {
- StringExtractor bytes;
- if (mem_cache_dict->GetValueForKeyAsString(
- "bytes", bytes.GetStringRef())) {
+ llvm::StringRef str;
+ if (mem_cache_dict->GetValueForKeyAsString("bytes", str)) {
+ StringExtractor bytes(str);
bytes.SetFilePos(0);
const size_t byte_size = bytes.GetStringRef().size() / 2;
@@ -2405,8 +2429,8 @@ void ProcessGDBRemote::RefreshStateAfterStop() {
m_thread_list_real.RefreshStateAfterStop();
}
-Error ProcessGDBRemote::DoHalt(bool &caused_stop) {
- Error error;
+Status ProcessGDBRemote::DoHalt(bool &caused_stop) {
+ Status error;
if (m_public_state.GetValue() == eStateAttaching) {
// We are being asked to halt during an attach. We need to just close
@@ -2417,8 +2441,8 @@ Error ProcessGDBRemote::DoHalt(bool &caused_stop) {
return error;
}
-Error ProcessGDBRemote::DoDetach(bool keep_stopped) {
- Error error;
+Status ProcessGDBRemote::DoDetach(bool keep_stopped) {
+ Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
if (log)
log->Printf("ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped);
@@ -2446,8 +2470,8 @@ Error ProcessGDBRemote::DoDetach(bool keep_stopped) {
return error;
}
-Error ProcessGDBRemote::DoDestroy() {
- Error error;
+Status ProcessGDBRemote::DoDestroy() {
+ Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
if (log)
log->Printf("ProcessGDBRemote::DoDestroy()");
@@ -2729,18 +2753,21 @@ void ProcessGDBRemote::WillPublicStop() {
// Process Memory
//------------------------------------------------------------------
size_t ProcessGDBRemote::DoReadMemory(addr_t addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
GetMaxMemorySize();
- if (size > m_max_memory_size) {
+ bool binary_memory_read = m_gdb_comm.GetxPacketSupported();
+ // M and m packets take 2 bytes for 1 byte of memory
+ size_t max_memory_size =
+ binary_memory_read ? m_max_memory_size : m_max_memory_size / 2;
+ if (size > max_memory_size) {
// Keep memory read sizes down to a sane limit. This function will be
// called multiple times in order to complete the task by
// lldb_private::Process so it is ok to do this.
- size = m_max_memory_size;
+ size = max_memory_size;
}
char packet[64];
int packet_len;
- bool binary_memory_read = m_gdb_comm.GetxPacketSupported();
packet_len = ::snprintf(packet, sizeof(packet), "%c%" PRIx64 ",%" PRIx64,
binary_memory_read ? 'x' : 'm', (uint64_t)addr,
(uint64_t)size);
@@ -2785,13 +2812,15 @@ size_t ProcessGDBRemote::DoReadMemory(addr_t addr, void *buf, size_t size,
}
size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf,
- size_t size, Error &error) {
+ size_t size, Status &error) {
GetMaxMemorySize();
- if (size > m_max_memory_size) {
+ // M and m packets take 2 bytes for 1 byte of memory
+ size_t max_memory_size = m_max_memory_size / 2;
+ if (size > max_memory_size) {
// Keep memory read sizes down to a sane limit. This function will be
// called multiple times in order to complete the task by
// lldb_private::Process so it is ok to do this.
- size = m_max_memory_size;
+ size = max_memory_size;
}
StreamString packet;
@@ -2824,7 +2853,7 @@ size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf,
lldb::addr_t ProcessGDBRemote::DoAllocateMemory(size_t size,
uint32_t permissions,
- Error &error) {
+ Status &error) {
Log *log(
GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_EXPRESSIONS));
addr_t allocated_addr = LLDB_INVALID_ADDRESS;
@@ -2868,27 +2897,27 @@ lldb::addr_t ProcessGDBRemote::DoAllocateMemory(size_t size,
return allocated_addr;
}
-Error ProcessGDBRemote::GetMemoryRegionInfo(addr_t load_addr,
- MemoryRegionInfo &region_info) {
+Status ProcessGDBRemote::GetMemoryRegionInfo(addr_t load_addr,
+ MemoryRegionInfo &region_info) {
- Error error(m_gdb_comm.GetMemoryRegionInfo(load_addr, region_info));
+ Status error(m_gdb_comm.GetMemoryRegionInfo(load_addr, region_info));
return error;
}
-Error ProcessGDBRemote::GetWatchpointSupportInfo(uint32_t &num) {
+Status ProcessGDBRemote::GetWatchpointSupportInfo(uint32_t &num) {
- Error error(m_gdb_comm.GetWatchpointSupportInfo(num));
+ Status error(m_gdb_comm.GetWatchpointSupportInfo(num));
return error;
}
-Error ProcessGDBRemote::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
- Error error(m_gdb_comm.GetWatchpointSupportInfo(
+Status ProcessGDBRemote::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
+ Status error(m_gdb_comm.GetWatchpointSupportInfo(
num, after, GetTarget().GetArchitecture()));
return error;
}
-Error ProcessGDBRemote::DoDeallocateMemory(lldb::addr_t addr) {
- Error error;
+Status ProcessGDBRemote::DoDeallocateMemory(lldb::addr_t addr) {
+ Status error;
LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory();
switch (supported) {
@@ -2926,7 +2955,7 @@ Error ProcessGDBRemote::DoDeallocateMemory(lldb::addr_t addr) {
// Process STDIO
//------------------------------------------------------------------
size_t ProcessGDBRemote::PutSTDIN(const char *src, size_t src_len,
- Error &error) {
+ Status &error) {
if (m_stdio_communication.IsConnected()) {
ConnectionStatus status;
m_stdio_communication.Write(src, src_len, status, NULL);
@@ -2936,8 +2965,8 @@ size_t ProcessGDBRemote::PutSTDIN(const char *src, size_t src_len,
return 0;
}
-Error ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
- Error error;
+Status ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
+ Status error;
assert(bp_site != NULL);
// Get logging info
@@ -3074,8 +3103,8 @@ Error ProcessGDBRemote::EnableBreakpointSite(BreakpointSite *bp_site) {
return EnableSoftwareBreakpoint(bp_site);
}
-Error ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) {
- Error error;
+Status ProcessGDBRemote::DisableBreakpointSite(BreakpointSite *bp_site) {
+ Status error;
assert(bp_site != NULL);
addr_t addr = bp_site->GetLoadAddress();
user_id_t site_id = bp_site->GetID();
@@ -3143,8 +3172,8 @@ static GDBStoppointType GetGDBStoppointType(Watchpoint *wp) {
return eWatchpointWrite;
}
-Error ProcessGDBRemote::EnableWatchpoint(Watchpoint *wp, bool notify) {
- Error error;
+Status ProcessGDBRemote::EnableWatchpoint(Watchpoint *wp, bool notify) {
+ Status error;
if (wp) {
user_id_t watchID = wp->GetID();
addr_t addr = wp->GetLoadAddress();
@@ -3180,8 +3209,8 @@ Error ProcessGDBRemote::EnableWatchpoint(Watchpoint *wp, bool notify) {
return error;
}
-Error ProcessGDBRemote::DisableWatchpoint(Watchpoint *wp, bool notify) {
- Error error;
+Status ProcessGDBRemote::DisableWatchpoint(Watchpoint *wp, bool notify) {
+ Status error;
if (wp) {
user_id_t watchID = wp->GetID();
@@ -3233,8 +3262,8 @@ void ProcessGDBRemote::Clear() {
m_thread_list.Clear();
}
-Error ProcessGDBRemote::DoSignal(int signo) {
- Error error;
+Status ProcessGDBRemote::DoSignal(int signo) {
+ Status error;
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
if (log)
log->Printf("ProcessGDBRemote::DoSignal (signal = %d)", signo);
@@ -3244,15 +3273,15 @@ Error ProcessGDBRemote::DoSignal(int signo) {
return error;
}
-Error ProcessGDBRemote::EstablishConnectionIfNeeded(
- const ProcessInfo &process_info) {
+Status
+ProcessGDBRemote::EstablishConnectionIfNeeded(const ProcessInfo &process_info) {
// Make sure we aren't already connected?
if (m_gdb_comm.IsConnected())
- return Error();
+ return Status();
PlatformSP platform_sp(GetTarget().GetPlatform());
if (platform_sp && !platform_sp->IsHost())
- return Error("Lost debug server connection");
+ return Status("Lost debug server connection");
auto error = LaunchAndConnectToDebugserver(process_info);
if (error.Fail()) {
@@ -3279,11 +3308,11 @@ static bool SetCloexecFlag(int fd) {
}
#endif
-Error ProcessGDBRemote::LaunchAndConnectToDebugserver(
+Status ProcessGDBRemote::LaunchAndConnectToDebugserver(
const ProcessInfo &process_info) {
using namespace std::placeholders; // For _1, _2, etc.
- Error error;
+ Status error;
if (m_debugserver_pid == LLDB_INVALID_PROCESS_ID) {
// If we locate debugserver, keep that located version around
static FileSpec g_debugserver_file_spec;
@@ -3429,9 +3458,9 @@ void ProcessGDBRemote::KillDebugserverProcess() {
}
void ProcessGDBRemote::Initialize() {
- static std::once_flag g_once_flag;
+ static llvm::once_flag g_once_flag;
- std::call_once(g_once_flag, []() {
+ llvm::call_once(g_once_flag, []() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(), CreateInstance,
DebuggerInitialize);
@@ -3741,6 +3770,43 @@ bool ProcessGDBRemote::NewThreadNotifyBreakpointHit(
return false;
}
+Status ProcessGDBRemote::UpdateAutomaticSignalFiltering() {
+ Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+ LLDB_LOG(log, "Check if need to update ignored signals");
+
+ // QPassSignals package is not supported by the server,
+ // there is no way we can ignore any signals on server side.
+ if (!m_gdb_comm.GetQPassSignalsSupported())
+ return Status();
+
+ // No signals, nothing to send.
+ if (m_unix_signals_sp == nullptr)
+ return Status();
+
+ // Signals' version hasn't changed, no need to send anything.
+ uint64_t new_signals_version = m_unix_signals_sp->GetVersion();
+ if (new_signals_version == m_last_signals_version) {
+ LLDB_LOG(log, "Signals' version hasn't changed. version={0}",
+ m_last_signals_version);
+ return Status();
+ }
+
+ auto signals_to_ignore =
+ m_unix_signals_sp->GetFilteredSignals(false, false, false);
+ Status error = m_gdb_comm.SendSignalsToIgnore(signals_to_ignore);
+
+ LLDB_LOG(log,
+ "Signals' version changed. old version={0}, new version={1}, "
+ "signals ignored={2}, update result={3}",
+ m_last_signals_version, new_signals_version,
+ signals_to_ignore.size(), error);
+
+ if (error.Success())
+ m_last_signals_version = new_signals_version;
+
+ return error;
+}
+
bool ProcessGDBRemote::StartNoticingNewThreads() {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
if (m_thread_create_bp_sp) {
@@ -3785,11 +3851,11 @@ DynamicLoader *ProcessGDBRemote::GetDynamicLoader() {
return m_dyld_ap.get();
}
-Error ProcessGDBRemote::SendEventData(const char *data) {
+Status ProcessGDBRemote::SendEventData(const char *data) {
int return_value;
bool was_supported;
- Error error;
+ Status error;
return_value = m_gdb_comm.SendLaunchEventDataPacket(data, &was_supported);
if (return_value != 0) {
@@ -3960,7 +4026,7 @@ StructuredData::ObjectSP ProcessGDBRemote::GetSharedCacheInfo() {
return object_sp;
}
-Error ProcessGDBRemote::ConfigureStructuredData(
+Status ProcessGDBRemote::ConfigureStructuredData(
const ConstString &type_name, const StructuredData::ObjectSP &config_sp) {
return m_gdb_comm.ConfigureRemoteStructuredData(type_name, config_sp);
}
@@ -3990,6 +4056,21 @@ void ProcessGDBRemote::GetMaxMemorySize() {
stub_max_size = reasonable_largeish_default;
}
+ // Memory packet have other overheads too like Maddr,size:#NN
+ // Instead of calculating the bytes taken by size and addr every
+ // time, we take a maximum guess here.
+ if (stub_max_size > 70)
+ stub_max_size -= 32 + 32 + 6;
+ else {
+ // In unlikely scenario that max packet size is less then 70, we will
+ // hope that data being written is small enough to fit.
+ Log *log(ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(
+ GDBR_LOG_COMM | GDBR_LOG_MEMORY));
+ if (log)
+ log->Warning("Packet size is too small. "
+ "LLDB may face problems while writing memory");
+ }
+
m_max_memory_size = stub_max_size;
} else {
m_max_memory_size = conservative_default;
@@ -4134,8 +4215,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
reg_node.ForEachAttribute([&target_info, &gdb_group, &gdb_type,
&reg_name, &alt_name, &set_name, &value_regs,
&invalidate_regs, &encoding_set, &format_set,
- &reg_info, &cur_reg_num, &reg_offset,
- &dwarf_opcode_bytes](
+ &reg_info, &reg_offset, &dwarf_opcode_bytes](
const llvm::StringRef &name,
const llvm::StringRef &value) -> bool {
if (name == "name") {
@@ -4215,7 +4295,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
uint32_t ret_val =
opcode_extractor.GetHexBytesAvail(dwarf_opcode_bytes);
assert(dwarf_opcode_len == ret_val);
-
+ UNUSED_IF_ASSERT_DISABLED(ret_val);
reg_info.dynamic_size_dwarf_expr_bytes = dwarf_opcode_bytes.data();
} else {
printf("unhandled attribute %s = %s\n", name.data(), value.data());
@@ -4283,7 +4363,7 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
// request the target xml file
std::string raw;
- lldb_private::Error lldberr;
+ lldb_private::Status lldberr;
if (!comm.ReadExtFeature(ConstString("features"), ConstString("target.xml"),
raw, lldberr)) {
return false;
@@ -4297,7 +4377,7 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
XMLNode target_node = xml_document.GetRootElement("target");
if (target_node) {
XMLNode feature_node;
- target_node.ForEachChildElement([&target_info, this, &feature_node](
+ target_node.ForEachChildElement([&target_info, &feature_node](
const XMLNode &node) -> bool {
llvm::StringRef name = node.GetName();
if (name == "architecture") {
@@ -4344,7 +4424,7 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
// that context we haven't
// set the Target's architecture yet, so the ABI is also potentially
// incorrect.
- ABISP abi_to_use_sp = ABI::FindPlugin(arch_to_use);
+ ABISP abi_to_use_sp = ABI::FindPlugin(shared_from_this(), arch_to_use);
if (feature_node) {
ParseRegisters(feature_node, target_info, this->m_register_info,
abi_to_use_sp, cur_reg_num, reg_offset);
@@ -4375,10 +4455,10 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
return m_register_info.GetNumRegisters() > 0;
}
-Error ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
+Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
// Make sure LLDB has an XML parser it can use first
if (!XMLDocument::XMLEnabled())
- return Error(0, ErrorType::eErrorTypeGeneric);
+ return Status(0, ErrorType::eErrorTypeGeneric);
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS);
if (log)
@@ -4392,11 +4472,11 @@ Error ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
// request the loaded library list
std::string raw;
- lldb_private::Error lldberr;
+ lldb_private::Status lldberr;
if (!comm.ReadExtFeature(ConstString("libraries-svr4"), ConstString(""),
raw, lldberr))
- return Error(0, ErrorType::eErrorTypeGeneric);
+ return Status(0, ErrorType::eErrorTypeGeneric);
// parse the xml file in memory
if (log)
@@ -4404,11 +4484,11 @@ Error ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
XMLDocument doc;
if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
- return Error(0, ErrorType::eErrorTypeGeneric);
+ return Status(0, ErrorType::eErrorTypeGeneric);
XMLNode root_element = doc.GetRootElement("library-list-svr4");
if (!root_element)
- return Error();
+ return Status();
// main link map structure
llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm");
@@ -4423,8 +4503,8 @@ Error ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
LoadedModuleInfoList::LoadedModuleInfo module;
library.ForEachAttribute(
- [log, &module](const llvm::StringRef &name,
- const llvm::StringRef &value) -> bool {
+ [&module](const llvm::StringRef &name,
+ const llvm::StringRef &value) -> bool {
if (name == "name")
module.set_name(value.str());
@@ -4479,22 +4559,22 @@ Error ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
// request the loaded library list
std::string raw;
- lldb_private::Error lldberr;
+ lldb_private::Status lldberr;
if (!comm.ReadExtFeature(ConstString("libraries"), ConstString(""), raw,
lldberr))
- return Error(0, ErrorType::eErrorTypeGeneric);
+ return Status(0, ErrorType::eErrorTypeGeneric);
if (log)
log->Printf("parsing: %s", raw.c_str());
XMLDocument doc;
if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
- return Error(0, ErrorType::eErrorTypeGeneric);
+ return Status(0, ErrorType::eErrorTypeGeneric);
XMLNode root_element = doc.GetRootElement("library-list");
if (!root_element)
- return Error();
+ return Status();
root_element.ForEachChildElementWithName(
"library", [log, &list](const XMLNode &library) -> bool {
@@ -4535,10 +4615,10 @@ Error ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
log->Printf("found %" PRId32 " modules in total",
(int)list.m_list.size());
} else {
- return Error(0, ErrorType::eErrorTypeGeneric);
+ return Status(0, ErrorType::eErrorTypeGeneric);
}
- return Error();
+ return Status();
}
lldb::ModuleSP ProcessGDBRemote::LoadModuleAtAddress(const FileSpec &file,
@@ -4637,15 +4717,15 @@ size_t ProcessGDBRemote::LoadModules() {
return LoadModules(module_list);
}
-Error ProcessGDBRemote::GetFileLoadAddress(const FileSpec &file,
- bool &is_loaded,
- lldb::addr_t &load_addr) {
+Status ProcessGDBRemote::GetFileLoadAddress(const FileSpec &file,
+ bool &is_loaded,
+ lldb::addr_t &load_addr) {
is_loaded = false;
load_addr = LLDB_INVALID_ADDRESS;
std::string file_path = file.GetPath(false);
if (file_path.empty())
- return Error("Empty file name specified");
+ return Status("Empty file name specified");
StreamString packet;
packet.PutCString("qFileLoadAddress:");
@@ -4655,27 +4735,28 @@ Error ProcessGDBRemote::GetFileLoadAddress(const FileSpec &file,
if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetString(), response,
false) !=
GDBRemoteCommunication::PacketResult::Success)
- return Error("Sending qFileLoadAddress packet failed");
+ return Status("Sending qFileLoadAddress packet failed");
if (response.IsErrorResponse()) {
if (response.GetError() == 1) {
// The file is not loaded into the inferior
is_loaded = false;
load_addr = LLDB_INVALID_ADDRESS;
- return Error();
+ return Status();
}
- return Error(
+ return Status(
"Fetching file load address from remote server returned an error");
}
if (response.IsNormalResponse()) {
is_loaded = true;
load_addr = response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
- return Error();
+ return Status();
}
- return Error("Unknown error happened during sending the load address packet");
+ return Status(
+ "Unknown error happened during sending the load address packet");
}
void ProcessGDBRemote::ModulesDidLoad(ModuleList &module_list) {
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 6423abc..54a472d 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -22,18 +22,19 @@
// Project includes
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Broadcaster.h"
-#include "lldb/Core/ConstString.h"
-#include "lldb/Core/Error.h"
#include "lldb/Core/LoadedModuleInfoList.h"
#include "lldb/Core/ModuleSpec.h"
-#include "lldb/Core/StreamString.h"
-#include "lldb/Core/StringList.h"
-#include "lldb/Core/StructuredData.h"
#include "lldb/Core/ThreadSafeValue.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamGDBRemote.h"
+#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StringExtractor.h"
+#include "lldb/Utility/StringList.h"
+#include "lldb/Utility/StructuredData.h"
#include "lldb/lldb-private-forward.h"
#include "GDBRemoteCommunicationClient.h"
@@ -78,25 +79,25 @@ public:
//------------------------------------------------------------------
// Creating a new process, or attaching to an existing one
//------------------------------------------------------------------
- Error WillLaunch(Module *module) override;
+ Status WillLaunch(Module *module) override;
- Error DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
+ Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
void DidLaunch() override;
- Error WillAttachToProcessWithID(lldb::pid_t pid) override;
+ Status WillAttachToProcessWithID(lldb::pid_t pid) override;
- Error WillAttachToProcessWithName(const char *process_name,
- bool wait_for_launch) override;
+ Status WillAttachToProcessWithName(const char *process_name,
+ bool wait_for_launch) override;
- Error DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override;
+ Status DoConnectRemote(Stream *strm, llvm::StringRef remote_url) override;
- Error WillLaunchOrAttach();
+ Status WillLaunchOrAttach();
- Error DoAttachToProcessWithID(lldb::pid_t pid,
- const ProcessAttachInfo &attach_info) override;
+ Status DoAttachToProcessWithID(lldb::pid_t pid,
+ const ProcessAttachInfo &attach_info) override;
- Error
+ Status
DoAttachToProcessWithName(const char *process_name,
const ProcessAttachInfo &attach_info) override;
@@ -112,19 +113,19 @@ public:
//------------------------------------------------------------------
// Process Control
//------------------------------------------------------------------
- Error WillResume() override;
+ Status WillResume() override;
- Error DoResume() override;
+ Status DoResume() override;
- Error DoHalt(bool &caused_stop) override;
+ Status DoHalt(bool &caused_stop) override;
- Error DoDetach(bool keep_stopped) override;
+ Status DoDetach(bool keep_stopped) override;
bool DetachRequiresHalt() override { return true; }
- Error DoSignal(int signal) override;
+ Status DoSignal(int signal) override;
- Error DoDestroy() override;
+ Status DoDestroy() override;
void RefreshStateAfterStop() override;
@@ -143,41 +144,56 @@ public:
// Process Memory
//------------------------------------------------------------------
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) override;
+ Status &error) override;
size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size,
- Error &error) override;
+ Status &error) override;
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
- Error &error) override;
+ Status &error) override;
- Error GetMemoryRegionInfo(lldb::addr_t load_addr,
- MemoryRegionInfo &region_info) override;
+ Status GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &region_info) override;
- Error DoDeallocateMemory(lldb::addr_t ptr) override;
+ Status DoDeallocateMemory(lldb::addr_t ptr) override;
//------------------------------------------------------------------
// Process STDIO
//------------------------------------------------------------------
- size_t PutSTDIN(const char *buf, size_t buf_size, Error &error) override;
+ size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
//----------------------------------------------------------------------
// Process Breakpoints
//----------------------------------------------------------------------
- Error EnableBreakpointSite(BreakpointSite *bp_site) override;
+ Status EnableBreakpointSite(BreakpointSite *bp_site) override;
- Error DisableBreakpointSite(BreakpointSite *bp_site) override;
+ Status DisableBreakpointSite(BreakpointSite *bp_site) override;
//----------------------------------------------------------------------
// Process Watchpoints
//----------------------------------------------------------------------
- Error EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
+ Status EnableWatchpoint(Watchpoint *wp, bool notify = true) override;
- Error DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
+ Status DisableWatchpoint(Watchpoint *wp, bool notify = true) override;
- Error GetWatchpointSupportInfo(uint32_t &num) override;
+ Status GetWatchpointSupportInfo(uint32_t &num) override;
- Error GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
+ lldb::user_id_t StartTrace(const TraceOptions &options,
+ Status &error) override;
+
+ Status StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id) override;
+
+ Status GetData(lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset = 0) override;
+
+ Status GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id,
+ llvm::MutableArrayRef<uint8_t> &buffer,
+ size_t offset = 0) override;
+
+ Status GetTraceConfig(lldb::user_id_t uid, TraceOptions &options) override;
+
+ Status GetWatchpointSupportInfo(uint32_t &num, bool &after) override;
bool StartNoticingNewThreads() override;
@@ -185,7 +201,7 @@ public:
GDBRemoteCommunicationClient &GetGDBRemote() { return m_gdb_comm; }
- Error SendEventData(const char *data) override;
+ Status SendEventData(const char *data) override;
//----------------------------------------------------------------------
// Override DidExit so we can disconnect from the remote GDB server
@@ -207,8 +223,8 @@ public:
size_t LoadModules() override;
- Error GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
- lldb::addr_t &load_addr) override;
+ Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
+ lldb::addr_t &load_addr) override;
void ModulesDidLoad(ModuleList &module_list) override;
@@ -216,7 +232,7 @@ public:
GetLoadedDynamicLibrariesInfos(lldb::addr_t image_list_address,
lldb::addr_t image_count) override;
- Error
+ Status
ConfigureStructuredData(const ConstString &type_name,
const StructuredData::ObjectSP &config_sp) override;
@@ -315,9 +331,9 @@ protected:
bool UpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) override;
- Error EstablishConnectionIfNeeded(const ProcessInfo &process_info);
+ Status EstablishConnectionIfNeeded(const ProcessInfo &process_info);
- Error LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
+ Status LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
void KillDebugserverProcess();
@@ -379,7 +395,7 @@ protected:
void DidLaunchOrAttach(ArchSpec &process_arch);
- Error ConnectToDebugserver(llvm::StringRef host_port);
+ Status ConnectToDebugserver(llvm::StringRef host_port);
const char *GetDispatchQueueNameForThread(lldb::addr_t thread_dispatch_qaddr,
std::string &dispatch_queue_name);
@@ -390,19 +406,22 @@ protected:
bool GetGDBServerRegisterInfo(ArchSpec &arch);
// Query remote GDBServer for a detailed loaded library list
- Error GetLoadedModuleList(LoadedModuleInfoList &);
+ Status GetLoadedModuleList(LoadedModuleInfoList &);
lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
lldb::addr_t link_map,
lldb::addr_t base_addr,
bool value_is_offset);
+ Status UpdateAutomaticSignalFiltering() override;
+
private:
//------------------------------------------------------------------
// For ProcessGDBRemote only
//------------------------------------------------------------------
std::string m_partial_profile_data;
std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
+ uint64_t m_last_signals_version = 0;
static bool NewThreadNotifyBreakpointHit(void *baton,
StoppointCallbackContext *context,
@@ -417,6 +436,7 @@ private:
void HandleStopReply() override;
void HandleAsyncStructuredDataPacket(llvm::StringRef data) override;
+ void SetThreadPc(const lldb::ThreadSP &thread_sp, uint64_t index);
using ModuleCacheKey = std::pair<std::string, std::string>;
// KeyInfo for the cached module spec DenseMap.
// The invariant is that all real keys will have the file and architecture
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
index 899037a..8f16b83 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
@@ -8,210 +8,37 @@
//===----------------------------------------------------------------------===//
#include "ProcessGDBRemoteLog.h"
-
-#include <mutex>
-
-#include "lldb/Core/StreamFile.h"
-#include "lldb/Interpreter/Args.h"
-
#include "ProcessGDBRemote.h"
+#include "llvm/Support/Threading.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
-// We want to avoid global constructors where code needs to be run so here we
-// control access to our static g_log_sp by hiding it in a singleton function
-// that will construct the static g_lob_sp the first time this function is
-// called.
-static bool g_log_enabled = false;
-static Log *g_log = NULL;
-static Log *GetLog() {
- if (!g_log_enabled)
- return NULL;
- return g_log;
-}
+static constexpr Log::Category g_categories[] = {
+ {{"async"}, {"log asynchronous activity"}, GDBR_LOG_ASYNC},
+ {{"break"}, {"log breakpoints"}, GDBR_LOG_BREAKPOINTS},
+ {{"comm"}, {"log communication activity"}, GDBR_LOG_COMM},
+ {{"packets"}, {"log gdb remote packets"}, GDBR_LOG_PACKETS},
+ {{"memory"}, {"log memory reads and writes"}, GDBR_LOG_MEMORY},
+ {{"data-short"},
+ {"log memory bytes for memory reads and writes for short transactions "
+ "only"},
+ GDBR_LOG_MEMORY_DATA_SHORT},
+ {{"data-long"},
+ {"log memory bytes for memory reads and writes for all transactions"},
+ GDBR_LOG_MEMORY_DATA_LONG},
+ {{"process"}, {"log process events and activities"}, GDBR_LOG_PROCESS},
+ {{"step"}, {"log step related activities"}, GDBR_LOG_STEP},
+ {{"thread"}, {"log thread events and activities"}, GDBR_LOG_THREAD},
+ {{"watch"}, {"log watchpoint related activities"}, GDBR_LOG_WATCHPOINTS},
+};
+
+Log::Channel ProcessGDBRemoteLog::g_channel(g_categories, GDBR_LOG_DEFAULT);
void ProcessGDBRemoteLog::Initialize() {
- static ConstString g_name("gdb-remote");
- static std::once_flag g_once_flag;
-
- std::call_once(g_once_flag, []() {
- Log::Callbacks log_callbacks = {DisableLog, EnableLog, ListLogCategories};
-
- Log::RegisterLogChannel(g_name, log_callbacks);
+ static llvm::once_flag g_once_flag;
+ llvm::call_once(g_once_flag, []() {
+ Log::Register("gdb-remote", g_channel);
});
}
-
-Log *ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(uint32_t mask) {
- Log *log(GetLog());
- if (log && mask) {
- uint32_t log_mask = log->GetMask().Get();
- if ((log_mask & mask) != mask)
- return NULL;
- }
- return log;
-}
-
-Log *ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet(uint32_t mask) {
- Log *log(GetLog());
- if (log && log->GetMask().Get() & mask)
- return log;
- return NULL;
-}
-
-void ProcessGDBRemoteLog::DisableLog(const char **categories,
- Stream *feedback_strm) {
- Log *log(GetLog());
- if (log) {
- uint32_t flag_bits = 0;
-
- if (categories && categories[0]) {
- flag_bits = log->GetMask().Get();
- for (size_t i = 0; categories[i] != NULL; ++i) {
- const char *arg = categories[i];
-
- if (::strcasecmp(arg, "all") == 0)
- flag_bits &= ~GDBR_LOG_ALL;
- else if (::strcasecmp(arg, "async") == 0)
- flag_bits &= ~GDBR_LOG_ASYNC;
- else if (::strncasecmp(arg, "break", 5) == 0)
- flag_bits &= ~GDBR_LOG_BREAKPOINTS;
- else if (::strncasecmp(arg, "comm", 4) == 0)
- flag_bits &= ~GDBR_LOG_COMM;
- else if (::strcasecmp(arg, "default") == 0)
- flag_bits &= ~GDBR_LOG_DEFAULT;
- else if (::strcasecmp(arg, "packets") == 0)
- flag_bits &= ~GDBR_LOG_PACKETS;
- else if (::strcasecmp(arg, "memory") == 0)
- flag_bits &= ~GDBR_LOG_MEMORY;
- else if (::strcasecmp(arg, "data-short") == 0)
- flag_bits &= ~GDBR_LOG_MEMORY_DATA_SHORT;
- else if (::strcasecmp(arg, "data-long") == 0)
- flag_bits &= ~GDBR_LOG_MEMORY_DATA_LONG;
- else if (::strcasecmp(arg, "process") == 0)
- flag_bits &= ~GDBR_LOG_PROCESS;
- else if (::strcasecmp(arg, "step") == 0)
- flag_bits &= ~GDBR_LOG_STEP;
- else if (::strcasecmp(arg, "thread") == 0)
- flag_bits &= ~GDBR_LOG_THREAD;
- else if (::strcasecmp(arg, "verbose") == 0)
- flag_bits &= ~GDBR_LOG_VERBOSE;
- else if (::strncasecmp(arg, "watch", 5) == 0)
- flag_bits &= ~GDBR_LOG_WATCHPOINTS;
- else {
- feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
- ListLogCategories(feedback_strm);
- }
- }
- }
-
- if (flag_bits == 0)
- g_log_enabled = false;
- else
- log->GetMask().Reset(flag_bits);
- }
-
- return;
-}
-
-Log *ProcessGDBRemoteLog::EnableLog(StreamSP &log_stream_sp,
- uint32_t log_options,
- const char **categories,
- Stream *feedback_strm) {
- // Try see if there already is a log - that way we can reuse its settings.
- // We could reuse the log in toto, but we don't know that the stream is the
- // same.
- uint32_t flag_bits = 0;
- if (g_log)
- flag_bits = g_log->GetMask().Get();
-
- // Now make a new log with this stream if one was provided
- if (log_stream_sp) {
- if (g_log)
- g_log->SetStream(log_stream_sp);
- else
- g_log = new Log(log_stream_sp);
- }
-
- if (g_log) {
- bool got_unknown_category = false;
- for (size_t i = 0; categories[i] != NULL; ++i) {
- const char *arg = categories[i];
-
- if (::strcasecmp(arg, "all") == 0)
- flag_bits |= GDBR_LOG_ALL;
- else if (::strcasecmp(arg, "async") == 0)
- flag_bits |= GDBR_LOG_ASYNC;
- else if (::strncasecmp(arg, "break", 5) == 0)
- flag_bits |= GDBR_LOG_BREAKPOINTS;
- else if (::strncasecmp(arg, "comm", 4) == 0)
- flag_bits |= GDBR_LOG_COMM;
- else if (::strcasecmp(arg, "default") == 0)
- flag_bits |= GDBR_LOG_DEFAULT;
- else if (::strcasecmp(arg, "packets") == 0)
- flag_bits |= GDBR_LOG_PACKETS;
- else if (::strcasecmp(arg, "memory") == 0)
- flag_bits |= GDBR_LOG_MEMORY;
- else if (::strcasecmp(arg, "data-short") == 0)
- flag_bits |= GDBR_LOG_MEMORY_DATA_SHORT;
- else if (::strcasecmp(arg, "data-long") == 0)
- flag_bits |= GDBR_LOG_MEMORY_DATA_LONG;
- else if (::strcasecmp(arg, "process") == 0)
- flag_bits |= GDBR_LOG_PROCESS;
- else if (::strcasecmp(arg, "step") == 0)
- flag_bits |= GDBR_LOG_STEP;
- else if (::strcasecmp(arg, "thread") == 0)
- flag_bits |= GDBR_LOG_THREAD;
- else if (::strcasecmp(arg, "verbose") == 0)
- flag_bits |= GDBR_LOG_VERBOSE;
- else if (::strncasecmp(arg, "watch", 5) == 0)
- flag_bits |= GDBR_LOG_WATCHPOINTS;
- else {
- feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
- if (got_unknown_category == false) {
- got_unknown_category = true;
- ListLogCategories(feedback_strm);
- }
- }
- }
- if (flag_bits == 0)
- flag_bits = GDBR_LOG_DEFAULT;
- g_log->GetMask().Reset(flag_bits);
- g_log->GetOptions().Reset(log_options);
- }
- g_log_enabled = true;
- return g_log;
-}
-
-void ProcessGDBRemoteLog::ListLogCategories(Stream *strm) {
- strm->Printf(
- "Logging categories for '%s':\n"
- " all - turn on all available logging categories\n"
- " async - log asynchronous activity\n"
- " break - log breakpoints\n"
- " communication - log communication activity\n"
- " default - enable the default set of logging categories for liblldb\n"
- " packets - log gdb remote packets\n"
- " memory - log memory reads and writes\n"
- " data-short - log memory bytes for memory reads and writes for short "
- "transactions only\n"
- " data-long - log memory bytes for memory reads and writes for all "
- "transactions\n"
- " process - log process events and activities\n"
- " thread - log thread events and activities\n"
- " step - log step related activities\n"
- " verbose - enable verbose logging\n"
- " watch - log watchpoint related activities\n",
- ProcessGDBRemote::GetPluginNameStatic().GetCString());
-}
-
-void ProcessGDBRemoteLog::LogIf(uint32_t mask, const char *format, ...) {
- Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(mask));
- if (log) {
- va_list args;
- va_start(args, format);
- log->VAPrintf(format, args);
- va_end(args);
- }
-}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
index f5e92b4..3c58011 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
@@ -15,9 +15,8 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/Log.h"
+#include "lldb/Utility/Log.h"
-#define GDBR_LOG_VERBOSE (1u << 0)
#define GDBR_LOG_PROCESS (1u << 1)
#define GDBR_LOG_THREAD (1u << 2)
#define GDBR_LOG_PACKETS (1u << 3)
@@ -37,21 +36,13 @@ namespace lldb_private {
namespace process_gdb_remote {
class ProcessGDBRemoteLog {
+ static Log::Channel g_channel;
+
public:
static void Initialize();
- static Log *GetLogIfAllCategoriesSet(uint32_t mask = 0);
-
- static Log *GetLogIfAnyCategoryIsSet(uint32_t mask);
-
- static void DisableLog(const char **categories, Stream *feedback_strm);
-
- static Log *EnableLog(lldb::StreamSP &log_stream_sp, uint32_t log_options,
- const char **categories, Stream *feedback_strm);
-
- static void ListLogCategories(Stream *strm);
-
- static void LogIf(uint32_t mask, const char *format, ...);
+ static Log *GetLogIfAllCategoriesSet(uint32_t mask) { return g_channel.GetLogIfAll(mask); }
+ static Log *GetLogIfAnyCategoryIsSet(uint32_t mask) { return g_channel.GetLogIfAny(mask); }
};
} // namespace process_gdb_remote
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
index ab55214..5197e8f 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -11,9 +11,7 @@
#include "lldb/Breakpoint/Watchpoint.h"
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/State.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
@@ -22,6 +20,8 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Target/Unwind.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/StreamString.h"
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
@@ -41,18 +41,16 @@ ThreadGDBRemote::ThreadGDBRemote(Process &process, lldb::tid_t tid)
m_dispatch_queue_t(LLDB_INVALID_ADDRESS), m_queue_kind(eQueueKindUnknown),
m_queue_serial_number(LLDB_INVALID_QUEUE_ID),
m_associated_with_libdispatch_queue(eLazyBoolCalculate) {
- ProcessGDBRemoteLog::LogIf(
- GDBR_LOG_THREAD,
- "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this,
- process.GetID(), GetID());
+ Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+ LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this, process.GetID(),
+ GetID());
}
ThreadGDBRemote::~ThreadGDBRemote() {
ProcessSP process_sp(GetProcess());
- ProcessGDBRemoteLog::LogIf(
- GDBR_LOG_THREAD,
- "%p: ThreadGDBRemote::~ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this,
- process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, GetID());
+ Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+ LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this,
+ process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, GetID());
DestroyThread();
}
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
index 27caf42..1a5b60a 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
@@ -16,9 +16,9 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Core/StructuredData.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
+#include "lldb/Utility/StructuredData.h"
class StringExtractor;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/CMakeLists.txt b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/CMakeLists.txt
index ddc89cb..61ce168 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/CMakeLists.txt
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/CMakeLists.txt
@@ -1,10 +1,19 @@
include_directories(../Utility)
-add_lldb_library(lldbPluginProcessMinidump
+add_lldb_library(lldbPluginProcessMinidump PLUGIN
MinidumpTypes.cpp
MinidumpParser.cpp
RegisterContextMinidump_x86_32.cpp
RegisterContextMinidump_x86_64.cpp
ProcessMinidump.cpp
ThreadMinidump.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbTarget
+ lldbUtility
+ lldbPluginProcessUtility
+ lldbPluginProcessElfCore
+ LINK_COMPONENTS
+ Support
)
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index 37b3709..36350fd 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -45,7 +45,7 @@ MinidumpParser::Create(const lldb::DataBufferSP &data_buf_sp) {
}
const MinidumpDirectory *directory = nullptr;
- Error error;
+ Status error;
llvm::ArrayRef<uint8_t> directory_data(
data_buf_sp->GetBytes() + directory_list_offset,
sizeof(MinidumpDirectory) * header->streams_count);
@@ -126,7 +126,7 @@ MinidumpParser::GetThreadContextWow64(const MinidumpThread &td) {
return {};
const TEB64 *wow64teb;
- Error error = consumeObject(teb_mem, wow64teb);
+ Status error = consumeObject(teb_mem, wow64teb);
if (error.Fail())
return {};
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.h b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 67523a7..df6deb4 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -16,8 +16,8 @@
// Other libraries and framework includes
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataBuffer.h"
-#include "lldb/Core/Error.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/Status.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
index 863d124..24ce3f9 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp
@@ -19,7 +19,7 @@ using namespace minidump;
const MinidumpHeader *MinidumpHeader::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpHeader *header = nullptr;
- Error error = consumeObject(data, header);
+ Status error = consumeObject(data, header);
const MinidumpHeaderConstants signature =
static_cast<const MinidumpHeaderConstants>(
@@ -45,7 +45,7 @@ lldb_private::minidump::parseMinidumpString(llvm::ArrayRef<uint8_t> &data) {
std::string result;
const uint32_t *source_length;
- Error error = consumeObject(data, source_length);
+ Status error = consumeObject(data, source_length);
if (error.Fail() || *source_length > data.size() || *source_length % 2 != 0)
return llvm::None;
@@ -71,7 +71,7 @@ lldb_private::minidump::parseMinidumpString(llvm::ArrayRef<uint8_t> &data) {
// MinidumpThread
const MinidumpThread *MinidumpThread::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpThread *thread = nullptr;
- Error error = consumeObject(data, thread);
+ Status error = consumeObject(data, thread);
if (error.Fail())
return nullptr;
@@ -81,7 +81,7 @@ const MinidumpThread *MinidumpThread::Parse(llvm::ArrayRef<uint8_t> &data) {
llvm::ArrayRef<MinidumpThread>
MinidumpThread::ParseThreadList(llvm::ArrayRef<uint8_t> &data) {
const llvm::support::ulittle32_t *thread_count;
- Error error = consumeObject(data, thread_count);
+ Status error = consumeObject(data, thread_count);
if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size())
return {};
@@ -93,7 +93,7 @@ MinidumpThread::ParseThreadList(llvm::ArrayRef<uint8_t> &data) {
const MinidumpSystemInfo *
MinidumpSystemInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpSystemInfo *system_info;
- Error error = consumeObject(data, system_info);
+ Status error = consumeObject(data, system_info);
if (error.Fail())
return nullptr;
@@ -103,7 +103,7 @@ MinidumpSystemInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
// MinidumpMiscInfo
const MinidumpMiscInfo *MinidumpMiscInfo::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpMiscInfo *misc_info;
- Error error = consumeObject(data, misc_info);
+ Status error = consumeObject(data, misc_info);
if (error.Fail())
return nullptr;
@@ -147,7 +147,7 @@ lldb::pid_t LinuxProcStatus::GetPid() const { return pid; }
// Module stuff
const MinidumpModule *MinidumpModule::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpModule *module = nullptr;
- Error error = consumeObject(data, module);
+ Status error = consumeObject(data, module);
if (error.Fail())
return nullptr;
@@ -158,7 +158,7 @@ llvm::ArrayRef<MinidumpModule>
MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
const llvm::support::ulittle32_t *modules_count;
- Error error = consumeObject(data, modules_count);
+ Status error = consumeObject(data, modules_count);
if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size())
return {};
@@ -170,7 +170,7 @@ MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
const MinidumpExceptionStream *
MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
const MinidumpExceptionStream *exception_stream = nullptr;
- Error error = consumeObject(data, exception_stream);
+ Status error = consumeObject(data, exception_stream);
if (error.Fail())
return nullptr;
@@ -180,7 +180,7 @@ MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
llvm::ArrayRef<MinidumpMemoryDescriptor>
MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
const llvm::support::ulittle32_t *mem_ranges_count;
- Error error = consumeObject(data, mem_ranges_count);
+ Status error = consumeObject(data, mem_ranges_count);
if (error.Fail() ||
*mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size())
return {};
@@ -193,7 +193,7 @@ MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
const llvm::support::ulittle64_t *mem_ranges_count;
- Error error = consumeObject(data, mem_ranges_count);
+ Status error = consumeObject(data, mem_ranges_count);
if (error.Fail() ||
*mem_ranges_count * sizeof(MinidumpMemoryDescriptor64) > data.size())
return {};
@@ -213,7 +213,7 @@ MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
std::vector<const MinidumpMemoryInfo *>
MinidumpMemoryInfo::ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data) {
const MinidumpMemoryInfoListHeader *header;
- Error error = consumeObject(data, header);
+ Status error = consumeObject(data, header);
if (error.Fail() ||
header->size_of_header < sizeof(MinidumpMemoryInfoListHeader) ||
header->size_of_entry < sizeof(MinidumpMemoryInfo))
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.h b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.h
index 46871a1..6de4f55 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -13,7 +13,7 @@
// Project includes
// Other libraries and framework includes
-#include "lldb/Core/Error.h"
+#include "lldb/Utility/Status.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitmaskEnum.h"
@@ -158,8 +158,8 @@ enum class MinidumpMiscInfoFlags : uint32_t {
};
template <typename T>
-Error consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
- Error error;
+Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
+ Status error;
if (Buffer.size() < sizeof(T)) {
error.SetErrorString("Insufficient buffer!");
return error;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 46d8df8..d4d65c0 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -12,8 +12,6 @@
#include "ThreadMinidump.h"
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
@@ -23,7 +21,12 @@
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/DataBufferLLVM.h"
#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/Log.h"
+
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Threading.h"
// C includes
// C++ includes
@@ -48,20 +51,25 @@ lldb::ProcessSP ProcessMinidump::CreateInstance(lldb::TargetSP target_sp,
lldb::ProcessSP process_sp;
// Read enough data for the Minidump header
- const size_t header_size = sizeof(MinidumpHeader);
- lldb::DataBufferSP data_sp(crash_file->MemoryMapFileContents(0, header_size));
- if (!data_sp)
+ constexpr size_t header_size = sizeof(MinidumpHeader);
+ auto DataPtr =
+ DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), header_size, 0);
+ if (!DataPtr)
return nullptr;
+ assert(DataPtr->GetByteSize() == header_size);
+
// first, only try to parse the header, beacuse we need to be fast
- llvm::ArrayRef<uint8_t> header_data(data_sp->GetBytes(), header_size);
- const MinidumpHeader *header = MinidumpHeader::Parse(header_data);
+ llvm::ArrayRef<uint8_t> HeaderBytes = DataPtr->GetData();
+ const MinidumpHeader *header = MinidumpHeader::Parse(HeaderBytes);
+ if (header == nullptr)
+ return nullptr;
- if (data_sp->GetByteSize() != header_size || header == nullptr)
+ auto AllData = DataBufferLLVM::CreateSliceFromPath(crash_file->GetPath(), -1, 0);
+ if (!AllData)
return nullptr;
- lldb::DataBufferSP all_data_sp(crash_file->MemoryMapFileContents());
- auto minidump_parser = MinidumpParser::Create(all_data_sp);
+ auto minidump_parser = MinidumpParser::Create(AllData);
// check if the parser object is valid
if (!minidump_parser)
return nullptr;
@@ -92,9 +100,9 @@ ProcessMinidump::~ProcessMinidump() {
}
void ProcessMinidump::Initialize() {
- static std::once_flag g_once_flag;
+ static llvm::once_flag g_once_flag;
- std::call_once(g_once_flag, []() {
+ llvm::call_once(g_once_flag, []() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(),
ProcessMinidump::CreateInstance);
@@ -105,8 +113,8 @@ void ProcessMinidump::Terminate() {
PluginManager::UnregisterPlugin(ProcessMinidump::CreateInstance);
}
-Error ProcessMinidump::DoLoadCore() {
- Error error;
+Status ProcessMinidump::DoLoadCore() {
+ Status error;
m_thread_list = m_minidump_parser.GetThreads();
m_active_exception = m_minidump_parser.GetExceptionStream();
@@ -133,7 +141,7 @@ ConstString ProcessMinidump::GetPluginName() { return GetPluginNameStatic(); }
uint32_t ProcessMinidump::GetPluginVersion() { return 1; }
-Error ProcessMinidump::DoDestroy() { return Error(); }
+Status ProcessMinidump::DoDestroy() { return Status(); }
void ProcessMinidump::RefreshStateAfterStop() {
if (!m_active_exception)
@@ -176,14 +184,14 @@ bool ProcessMinidump::IsAlive() { return true; }
bool ProcessMinidump::WarnBeforeDetach() const { return false; }
size_t ProcessMinidump::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
// Don't allow the caching that lldb_private::Process::ReadMemory does
// since we have it all cached in our dump file anyway.
return DoReadMemory(addr, buf, size, error);
}
size_t ProcessMinidump::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) {
+ Status &error) {
llvm::ArrayRef<uint8_t> mem = m_minidump_parser.GetMemory(addr, size);
if (mem.empty()) {
@@ -207,9 +215,9 @@ ArchSpec ProcessMinidump::GetArchitecture() {
return ArchSpec(triple);
}
-Error ProcessMinidump::GetMemoryRegionInfo(lldb::addr_t load_addr,
- MemoryRegionInfo &range_info) {
- Error error;
+Status ProcessMinidump::GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &range_info) {
+ Status error;
auto info = m_minidump_parser.GetMemoryRegionInfo(load_addr);
if (!info) {
error.SetErrorString("No valid MemoryRegionInfo found!");
@@ -270,7 +278,7 @@ void ProcessMinidump::ReadModuleList() {
const auto file_spec = FileSpec(name.getValue(), true);
ModuleSpec module_spec = file_spec;
- Error error;
+ Status error;
lldb::ModuleSP module_sp = GetTarget().GetSharedModule(module_spec, &error);
if (!module_sp || error.Fail()) {
continue;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.h b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.h
index 78eadc8..d5c46be 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.h
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ProcessMinidump.h
@@ -15,11 +15,11 @@
#include "MinidumpTypes.h"
// Other libraries and framework includes
-#include "lldb/Core/ConstString.h"
-#include "lldb/Core/Error.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Status.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
@@ -53,7 +53,7 @@ public:
bool CanDebug(lldb::TargetSP target_sp,
bool plugin_specified_by_name) override;
- Error DoLoadCore() override;
+ Status DoLoadCore() override;
DynamicLoader *GetDynamicLoader() override;
@@ -61,7 +61,7 @@ public:
uint32_t GetPluginVersion() override;
- Error DoDestroy() override;
+ Status DoDestroy() override;
void RefreshStateAfterStop() override;
@@ -70,15 +70,15 @@ public:
bool WarnBeforeDetach() const override;
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) override;
+ Status &error) override;
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
- Error &error) override;
+ Status &error) override;
ArchSpec GetArchitecture();
- Error GetMemoryRegionInfo(lldb::addr_t load_addr,
- MemoryRegionInfo &range_info) override;
+ Status GetMemoryRegionInfo(lldb::addr_t load_addr,
+ MemoryRegionInfo &range_info) override;
bool GetProcessInfo(ProcessInstanceInfo &info) override;
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
index 7f37682..7605f8b 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
@@ -11,7 +11,7 @@
#include "RegisterContextMinidump_x86_32.h"
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Utility/DataBufferHeap.h"
// C includes
// C++ includes
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
index 881c26a..ba1cb6d 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
@@ -11,7 +11,7 @@
#include "RegisterContextMinidump_x86_64.h"
// Other libraries and framework includes
-#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Utility/DataBufferHeap.h"
// C includes
// C++ includes
diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ThreadMinidump.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ThreadMinidump.cpp
index e42108b..9c21cc9 100644
--- a/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ThreadMinidump.cpp
+++ b/contrib/llvm/tools/lldb/source/Plugins/Process/minidump/ThreadMinidump.cpp
@@ -20,12 +20,12 @@
#include "Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h"
-#include "lldb/Core/DataExtractor.h"
-#include "lldb/Core/Log.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Unwind.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Log.h"
// C Includes
// C++ Includes
OpenPOWER on IntegriCloud