summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
AgeCommit message (Collapse)Author
2024-08-27[lldb] Update NativeProcess*BSD to new Status APIAdrian Prantl
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2023-12-04[lldb] Fix building on NetBSD 8.x (#74191)Brad Smith
PT_STOP was introduced with NetBSD 9.0.
2023-03-30[lldb-server/linux] Use waitpid(-1) to collect inferior eventsPavel Labath
This is a follow-up to D116372, which had a rather unfortunate side effect of making the processing of a single SIGCHLD quadratic in the number of threads -- which does not matter for simple applications, but can get really bad for applications with thousands of threads. This patch fixes the problem by implementing the other possibility mentioned in the first patch -- doing waitpid(-1) centrally and then routing the events to the correct process instance. The "uncollected" threads are held in the process factory class -- which I've renamed to Manager for this purpose, as it now does more than creating processes. Differential Revision: https://reviews.llvm.org/D146977
2022-01-26[lldb] Convert POSIXLog to use the new APIPavel Labath
2021-09-06[lldb] [llgs server] Support creating core dumps on NetBSDMichał Górny
Add a new SaveCore() process method that can be used to request a core dump. This is currently implemented on NetBSD via the PT_DUMPCORE ptrace(2) request, and enabled via 'savecore' extension. Protocol-wise, a new qSaveCore packet is introduced. It accepts zero or more semicolon-separated key:value options, invokes the core dump and returns a key:value response. Currently the only option supported is "path-hint", and the return value contains the "path" actually used. The support for the feature is exposed via qSaveCore qSupported feature. Differential Revision: https://reviews.llvm.org/D101285
2021-04-27[lldb] [gdb-remote] Report QPassSignals and qXfer via extensions APIMichał Górny
Remove hardcoded platform list for QPassSignals, qXfer:auxv:read and qXfer:libraries-svr4:read and instead query the process plugin via the GetSupportedExtensions() API. Differential Revision: https://reviews.llvm.org/D101241
2021-04-25[lldb] [Process/NetBSD] Report fork/vfork events to LLGSMichał Górny
Differential Revision: https://reviews.llvm.org/D100554
2021-04-13Reland "[lldb] [Process] Watch for fork/vfork notifications" for NetBSDMichał Górny
Differential Revision: https://reviews.llvm.org/D98822
2021-04-13Revert "[lldb] [Process] Watch for fork/vfork notifications" and associated ↵Pavel Labath
followups This commit has caused the following tests to be flaky: TestThreadSpecificBpPlusCondition.py TestExitDuringExpression.py The exact cause is not known yet, but since both tests deal with threads, my guess is it has something to do with the tracking of creation of new threads (which the commit touches upon). This reverts the following commits: d01bff8cbdc98fb8751f7bf10af19b47ae5c445d, ba62ebc48e8c424ce3a78ba01acda679d536dd47, e761b6b4c58d4f7ae1073d925d7cb321d68ee93a, a345419ee03095c8cdfbe1c2728467c4da8fa0a4.
2021-04-13[lldb] Replace NativeProcess delegate list with a single delegatePavel Labath
In all this time, we've never used more than one delegate. The logic to support multiple delegates is therefore untested, and becomes particularly unwieldy once we need to support multiple processes. Just remove it.
2021-04-08[lldb] [Process] Watch for fork/vfork notificationsMichał Górny
Watch for fork(2)/vfork(2) (also fork/vfork-style clone(2) on Linux) notifications and explicitly detach the forked child process, and add initial tests for these cases. The code covers FreeBSD, Linux and NetBSD process plugins. There is no new user-visible functionality provided -- this change lays foundations over subsequent work on fork support. Differential Revision: https://reviews.llvm.org/D98822
2021-01-02[Process/NetBSD] Copy changes from FreeBSDRemote and reformatMichał Górny
Copy changes, including: - NativeProcessNetBSD::GetLoadedModuleFileSpec() and NativeProcessNetBSD::GetFileLoadAddress() methods - split x86 register sets by CPU extensions - use offset/size-based register reading/writing Differential Revision: https://reviews.llvm.org/D93541
2020-11-10[lldb] [Process/NetBSD] Copy the recent improvements from FreeBSDMichał Górny
Copy the recent improvements from the FreeBSDRemote plugin, notably: - moving event reporting setup into SetupTrace() helper - adding more debug info into SIGTRAP handling - handling user-generated (and unknown) SIGTRAP events - adding missing error handling to the generic signal handler - fixing attaching to processes - switching watchpoint helpers to use llvm::Error - minor style and formatting changes This fixes a number of tests, mostly related to fixed attaching. Differential Revision: https://reviews.llvm.org/D91167
2020-10-14[lldb-server][linux] Add ability to allocate memoryPavel Labath
This patch adds support for the _M and _m gdb-remote packets, which (de)allocate memory in the inferior. This works by "injecting" a m(un)map syscall into the inferior. This consists of: - finding an executable page of memory - writing the syscall opcode to it - setting up registers according to the os syscall convention - single stepping over the syscall The advantage of this approach over calling the mmap function is that this works even in case the mmap function is buggy or unavailable. The disadvantage is it is more platform-dependent, which is why this patch only works on X86 (_32 and _64) right now. Adding support for other linux architectures should be easy and consist of defining the appropriate syscall constants. Adding support for other OSes depends on the its ability to do a similar trick. Differential Revision: https://reviews.llvm.org/D89124
2020-06-15[lldb] Rename Master/Slave to Primary/Secondary (NFC)Jonas Devlieghere
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2019-12-24[lldb] Adapt for NetBSD-9.99.30 ptrace(2) API changesKamil Rytarowski
Switch from PT_LWPINFO to PT_LWPSTATUS/PT_LWPNEXT. Keep compat support for < 9.99.30. No functional change intended.
2019-11-25[lldb] [Process/NetBSD] Fix handling concurrent watchpoint eventsMichał Górny
Fix handling concurrent watchpoint events so that they are reported correctly in LLDB. If multiple watchpoints are hit concurrently, the NetBSD kernel reports them as series of SIGTRAPs with a thread specified, and the debugger investigates DR6 in order to establish which watchpoint was hit. This is normally fine. However, LLDB disables and reenables the watchpoint on all threads after each hit, which results in the hit status from DR6 being wiped. As a result, it can't establish which watchpoint was hit in successive SIGTRAP processing. In order to workaround this problem, clear DR6 only if the breakpoint is overwritten with a new one. More specifically, move cleaning DR6 from ClearHardwareWatchpoint() to SetHardwareWatchpointWithIndex(), and do that only if the newly requested watchpoint is different from the one being set previously. This ensures that the disable-enable logic of LLDB does not clear watchpoint hit status for the remaining threads. This also involves refactoring of watchpoint logic. With the old logic, clearing watchpoint involved wiping dr6 & dr7, and setting it setting dr{0..3} & dr7. With the new logic, only enable bit is cleared from dr7, and the remaining bits are cleared/overwritten while setting new watchpoint. Differential Revision: https://reviews.llvm.org/D70025
2019-11-25[lldb] [Process/NetBSD] Copy watchpoints to newly-created threadsMichał Górny
NetBSD ptrace interface does not populate watchpoints to newly-created threads. Solve this via copying the watchpoints from the current thread when new thread is reported via TRAP_LWP. Add a test that verifies that when the user does not have permissions to set watchpoints on NetBSD, the 'watchpoint set' errors out gracefully and thread monitoring does not crash on being unable to copy watchpoints to new threads. Differential Revision: https://reviews.llvm.org/D70023
2019-11-25[lldb] [Process/NetBSD] Improve threading supportMichał Górny
Implement major improvements to multithreaded program support. Notably, support tracking new and exited threads, associate signals and events with correct threads and support controlling individual threads when resuming. Firstly, use PT_SET_EVENT_MASK to enable reporting of created and exited threads via SIGTRAP. Handle TRAP_LWP events to keep track of the currently running threads. Secondly, update the signal (both generic and SIGTRAP) handling code to account for per-thread signals correctly. Signals delivered to the whole process are reported on all threads, while per-thread signals and events are reported only to the specific thread. The remaining threads are marked as 'stopped with no reason'. Note that NetBSD always stops all threads on debugger events. Thirdly, implement the ability to set every thread as running, stopped or single-stepping separately while continuing the process. This also provides the ability to send a signal to the whole process or to one of its thread while resuming. Differential Revision: https://reviews.llvm.org/D70022
2019-11-12[lldb] [Process/NetBSD] Use PT_STOP to stop the process [NFCI]Michał Górny
Differential Revision: https://reviews.llvm.org/D70060
2019-09-24[lldb] [Process/NetBSD] Fix handling LLDB_INVALID_SIGNAL_NUMBERMichal Gorny
Fix NativeProcessNetBSD::Resume() to handle LLDB_INVALID_SIGNAL_NUMBER correctly. Fixes breakage caused by r372090 and r372300. I have major rewrite of that function pending; however, the fixes to gdb-remote were committed prior to that. llvm-svn: 372755
2019-08-14[LLDB] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368933
2019-07-25[lldb] [Process/NetBSD] Report stopped process on SIGSTOPMichal Gorny
Mark the process as stopped when SIGSTOP arrives. This is necessary for lldb-server to generate correct response to 'process interrupt', and therefore to prevent the whole stack crashing when process is stopped. Thanks to Pavel Labath for the tip. Differential Revision: https://reviews.llvm.org/D65289 llvm-svn: 367047
2019-07-24Revert "Revert "[lldb] [Process/NetBSD] Fix constructor after r363707""Michal Gorny
The relevant changes have been reapplied, and broke build again. llvm-svn: 366889
2019-07-01[lldb] [Process/NetBSD] Fix segfault when handling watchpointMichal Gorny
Fix the watchpoint/breakpoint code to search for matching thread entry in m_threads explicitly rather than assuming that it will be present at specified index. The previous code segfault since it wrongly assumed that the index will match LWP ID which was incorrect even for a single thread (where index was 0 and LWP ID was 1). While fixing that off-by-one error would help for this specific task, I believe it is better to be explicit in what we are searching for. Differential Revision: https://reviews.llvm.org/D63791 llvm-svn: 364780
2019-07-01Revert "[lldb] [Process/NetBSD] Fix constructor after r363707"Michal Gorny
Now that r364751 has been reverted, we need to revert this fixup as well. llvm-svn: 364776
2019-06-19[lldb] [Process/NetBSD] Fix constructor after r363707Michal Gorny
llvm-svn: 363827
2019-04-30[lldb] [Process/NetBSD] Fix handling piod_len from PT_IO callsMichal Gorny
Fix bugs in piod_len return value processing in ReadMemory() and WriteMemory() methods. In particular, add support for piod_len == 0 indicating EOF, and fix summing bytes_read/bytes_written when PT_IO does partial reads/writes. The EOF condition could happen if LLDB attempts to read past vm.maxaddress, e.g. as a result of RBP containing large (invalid) value. Previously, the 0 return caused the function to retry reading via PT_IO indefinitely, effectively deadlooping lldb-server. Partial reads probably did not occur in practice, yet they would cause ReadMemory() to return incorrect bytes_read and/or overwrite previously read data. WriteMemory() suffered from analoguous problems. Differential Revision: https://reviews.llvm.org/D61310 llvm-svn: 359572
2019-04-10[NFC] Remove ASCII lines from commentsJonas Devlieghere
A lot of comments in LLDB are surrounded by an ASCII line to delimit the begging and end of the comment. Its use is not really consistent across the code base, sometimes the lines are longer, sometimes they are shorter and sometimes they are omitted. Furthermore, it looks kind of weird with the 80 column limit, where the comment actually extends past the line, but not by much. Furthermore, when /// is used for Doxygen comments, it looks particularly odd. And when // is used, it incorrectly gives the impression that it's actually a Doxygen comment. I assume these lines were added to improve distinguishing between comments and code. However, given that todays editors and IDEs do a great job at highlighting comments, I think it's worth to drop this for the sake of consistency. The alternative is fixing all the inconsistencies, which would create a lot more churn. Differential revision: https://reviews.llvm.org/D60508 llvm-svn: 358135
2019-03-25[lldb] [Process/NetBSD] Use nullptr to fix template arg deductionMichal Gorny
llvm-svn: 356960
2019-03-21[lldb] Add missing EINTR handlingMichal Gorny
Differential Revision: https://reviews.llvm.org/D59606 llvm-svn: 356703
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-11Remove header grouping comments.Jonas Devlieghere
This patch removes the comments grouping header includes. They were added after running IWYU over the LLDB codebase. However they add little value, are often outdates and burdensome to maintain. llvm-svn: 346626
2018-11-04Fix NetBSD build after "Move path resolution logic out of FileSpec"Kamil Rytarowski
D53915 llvm-svn: 346100
2018-11-04NativeProcessProtocol: Simplify breakpoint setting codePavel Labath
Summary: A fairly simple operation as setting a breakpoint (writing a breakpoint opcode) at a given address was going through three classes: NativeProcessProtocol which called NativeBreakpointList, which then called SoftwareBrekpoint, only to end up again in NativeProcessProtocol to do the actual writing itself. This is unnecessarily complex and can be simplified by moving all of the logic into NativeProcessProtocol class itself, removing a lot of boilerplate. One of the reeasons for this complexity was that (it seems) NativeBreakpointList class was meant to hold both software and hardware breakpoints. However, that never materialized, and hardware breakpoints are stored in a separate map holding only hardware breakpoints. Essentially, this patch makes software breakpoints follow that approach by replacing the heavy SoftwareBraekpoint with a light struct of the same name, which holds only the data necessary to describe one breakpoint. The rest of the logic is in the main class. As, at the lldb-server level, handling software and hardware breakpoints is very different, this seems like a reasonable state of things. Reviewers: krytarowski, zturner, clayborg Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D52941 llvm-svn: 346093
2018-10-03Pull FixupBreakpointPCAsNeeded into base classPavel Labath
Summary: This function existed (with identical code) in both NativeProcessLinux and NativeProcessNetBSD, and it is likely that it would be useful to any future implementation of NativeProcessProtocol. Therefore I move it to the base class. Reviewers: krytarowski Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D52719 llvm-svn: 343683
2018-09-30Pull GetSoftwareBreakpointPCOffset into base classPavel Labath
Summary: This function encodes the knowledge of whether the PC points to the breakpoint instruction of the one following it after the breakpoint is "hit". This behavior mainly(*) depends on the architecture and not on the OS, so it makes sense for it to be implemented in the base class, where it can be shared between different implementations (Linux and NetBSD atm). (*) It is possible for an OS to expose a different API, perhaps by doing some fixups in the kernel. In this case, the implementation can override this function to implement custom behavior. Reviewers: krytarowski, zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D52532 llvm-svn: 343409
2018-09-13NativeProcessProtocol: Sink ReadMemoryWithoutTrap into base classPavel Labath
The two existing implementations have the function implemented identically, and there's no reason to believe that this would be different for other implementations. llvm-svn: 342167
2018-09-09Re-commit "Modernize NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode"Pavel Labath
This recommits r341487, which was reverted due to failing tests with clang. It turned out I had incorrectly expected that the literal arrays passed to ArrayRef constructor will have static (permanent) storage. This was only the case with gcc, while clang was constructing them on stack, leading to dangling pointers when the function returns. The fix is to explicitly assign static storage duration to the opcode arrays. llvm-svn: 341758
2018-09-08Revert "Modernize NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode"Pavel Labath
This reverts commit r341487. Jan Kratochvil reports it breaks LLDB when compiling with clang. llvm-svn: 341747
2018-09-05Modernize NativeProcessProtocol::GetSoftwareBreakpointTrapOpcodePavel Labath
return the opcode as a Expected<ArrayRef> instead of a Status+pointer+size combo. I also move the linux implementation to the base class, as the trap opcodes are likely to be the same for all/most implementations of the class (except the arm one, where linux chooses a different opcode than what the arm spec recommends, which I keep linux-specific). llvm-svn: 341487
2018-08-07Move RegisterValue,Scalar,State from Core to UtilityPavel Labath
These three classes have no external dependencies, but they are used from various low-level APIs. Moving them down to Utility improves overall code layering (although it still does not break any particular dependency completely). The XCode project will need to be updated after this change. Differential Revision: https://reviews.llvm.org/D49740 llvm-svn: 339127
2018-04-30Reflow paragraphs in comments.Adrian Prantl
This is intended as a clean up after the big clang-format commit (r280751), which unfortunately resulted in many of the comment paragraphs in LLDB being very hard to read. FYI, the script I used was: import textwrap import commands import os import sys import re tmp = "%s.tmp"%sys.argv[1] out = open(tmp, "w+") with open(sys.argv[1], "r") as f: header = "" text = "" comment = re.compile(r'^( *//) ([^ ].*)$') special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$') for line in f: match = comment.match(line) if match and not special.match(match.group(2)): # skip intentionally short comments. if not text and len(match.group(2)) < 40: out.write(line) continue if text: text += " " + match.group(2) else: header = match.group(1) text = match.group(2) continue if text: filled = textwrap.wrap(text, width=(78-len(header)), break_long_words=False) for l in filled: out.write(header+" "+l+'\n') text = "" out.write(line) os.rename(tmp, sys.argv[1]) Differential Revision: https://reviews.llvm.org/D46144 llvm-svn: 331197
2018-02-05Fix a crash in *NetBSD::Factory::LaunchKamil Rytarowski
Summary: We cannot call process_up->SetState() inside the NativeProcessNetBSD::Factory::Launch function because it triggers a NULL pointer deference. The generic code for launching a process in: GDBRemoteCommunicationServerLLGS::LaunchProcess sets the m_debugged_process_up pointer after a successful call to m_process_factory.Launch(). If we attempt to call process_up->SetState() inside a platform specific Launch function we end up dereferencing a NULL pointer in NativeProcessProtocol::GetCurrentThreadID(). Use the proper call process_up->SetState(,false) that sets notify_delegates to false. Sponsored by <The NetBSD Foundation> Reviewers: labath, joerg Reviewed By: labath Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D42868 llvm-svn: 324234
2018-01-29Fix NetBsd build broken by r323637Pavel Labath
llvm-svn: 323639
2018-01-29Remove ObjectFile usage from HostLinux::GetProcessInfoPavel Labath
Summary: The ObjectFile class was used to determine the architecture of a running process by inspecting it's main executable. There were two issues with this: - it's in the wrong layer - the call can be very expensive (it can end up computing the crc of the whole file). Since the process is running on the host, ideally we would be able to just query the data straight from the OS like darwin does, but there doesn't seem to be a reasonable way to do that. So, this fixes the layering issue by using the llvm object library to inspect the file. Since we know the process is already running on the host, we just need to peek at a few bytes of the elf header to determine whether it's 32- or 64-bit (which should make this faster as well). Pretty much the same logic was implemented in NativeProcessProtocol::ResolveProcessArchitecture, so I delete this logic and replace calls with GetProcessInfo. Reviewers: eugene, krytarowski Subscribers: mgorny, hintonda, lldb-commits Differential Revision: https://reviews.llvm.org/D42488 llvm-svn: 323637
2018-01-15One more attempt to fix NetBSD buildPavel Labath
llvm-svn: 322477
2018-01-15Fix NetBSD build for llvm r322475Pavel Labath
llvm-svn: 322476