summaryrefslogtreecommitdiff
path: root/lldb/source/Target/RegisterContextUnwind.cpp
AgeCommit message (Collapse)Author
2025-10-13Delegate to ABI plugin to check if call frame addresses are valid (#161398)pveras
Specially when dealing with different address spaces, CFAs could start from addresses like 0. For instance, Nvidia GPUs have instructions to read from local memory that use 0-based offsets and stack memory can be referenced by these offsets rather than global addresses. Note that ABIs could already specify what they consider to be valid CFA values but this was never used in these parts of the unwinder code. For most ABIs, this makes the validation more strict, as they already used to discard 0s and then checked for alignment which would discard 1s. There a few exceptions where 0s were possible and this makes it less strict, like the RISCV and ARC ABIs. @jasonmolenda Would you be the appropriate reviewer for this? Also cc. @clayborg @walter-erquinigo
2025-09-19[lldb] Don't call FixDataAddress when reading fp in ReadGPRValue (#159606)Felipe de Azevedo Piovezan
Based on testing on processors that use pointer metadata, and with all the work done to delay calls to FixDataAddress, this is no longer necessary. Note that, with debugserver in particular, this is an NFC change: the code path here is for frame zero, and debugserver will strip metadata when reading fp from frame zero anyway.
2025-09-18[lldb][nfc] Remove no-op calls to Fix*Address (#159586)Felipe de Azevedo Piovezan
The first call, in InitializeNonZerothFrame, is inside a logging branch. For that, it's better to log the real value instead of the fixed one. The second call, inside RegisterContextUnwind::ReadFrameAddress, is computing an address which is then passed to ReadRegisterValueFromMemory, which boils down to a Process::ReadMemory, which fixes the address if it wants to. The current variable names are misleading, making readers believe it is the cfa value itself that is being passed to Fix*Address; that's not the case. This commit renames the variable to make this abundantly clear.
2025-09-12[lldb] Track CFA pointer metadata in StackID (#157498)Felipe de Azevedo Piovezan
[lldb] Track CFA pointer metadata in StackID In this commit: 9c8e71644227 [lldb] Make StackID call Fix{Code,Data} pointers (#152796) We made StackID keep track of the CFA without any pointer metadata in it. This is necessary when comparing two StackIDs to determine which one is "younger". However, the CFA inside StackIDs is also used in other contexts through the method StackID::GetCallFrameAddress. One notable case is DWARFExpression: the computation of `DW_OP_call_frame_address` is done using StackID. This feeds into many other places, e.g. expression evaluation may require the address of a variable that is computed from the CFA; to access the variable without faulting, we may need to preserve the pointer metadata. As such, StackID must be able to provide both versions of the CFA. In the spirit of allowing consumers of pointers to decide what to do with pointer metadata, this patch changes StackID to store both versions of the cfa pointer. Two getter methods are provided, and all call sites except DWARFExpression preserve their existing behavior (stripped pointer). Other alternatives were considered: * Just store the raw pointer. This would require changing the comparisong operator `<` to also receive a Process, as the comparison requires stripped pointers. It wasn't clear if all call-sites had a non-null process, whereas we know we have a process when creating a StackID. * Store a weak pointer to the process inside the class, and then strip metadata as needed. This would require a `weak_ptr::lock` in many operations of LLDB, and it felt wasteful. It also prevents stripping of the pointer if the process has gone away. This patch also changes RegisterContextUnwind::ReadFrameAddress, which is the method computing the CFA fed into StackID, to also preserve the signature pointers.
2025-09-09[lldb] Unwind through ARM Cortex-M exceptions automatically (#153922)Jason Molenda
When a processor faults/is interrupted/gets an exception, it will stop running code and jump to an exception catcher routine. Most processors will store the pc that was executing in a system register, and the catcher functions have special instructions to retrieve that & possibly other registers. It may then save those values to stack, and the author can add .cfi directives to tell lldb's unwinder where to find those saved values. ARM Cortex-M (microcontroller) processors have a simpler mechanism where a fixed set of registers are saved to the stack on an exception, and a unique value is put in the link register to indicate to the caller that this has taken place. No special handling needs to be written into the exception catcher, unless it wants to inspect these preserved values. And it is possible for a general stack walker to walk the stack with no special knowledge about what the catch function does. This patch adds an Architecture plugin method to allow an Architecture to override/augment the UnwindPlan that lldb would use for a stack frame, given the contents of the return address register. It resembles a feature where the LanguageRuntime can replace/augment the unwind plan for a function, but it is doing it at offset by one level. The LanguageRuntime is looking at the local register context and/or symbol name to decide if it will override the unwind rules. For the Cortex-M exception unwinds, we need to modify THIS frame's unwind plan if the CALLER's LR had a specific value. RegisterContextUnwind has to retrieve the caller's LR value before it has completely decided on the UnwindPlan it will use for THIS stack frame. This does mean that we will need one additional read of stack memory than we currently do when unwinding, on Armv7 Cortex-M targets. The unwinder walks the stack lazily, as stack frames are requested, and so now if you ask for 2 stack frames, we will read enough stack to walk 2 frames, plus we will read one extra word of memory, the spilled LR value from the stack. In practice, with 512-byte memory cache reads, this is unlikely to be a real performance hit. This PR includes a test with a yaml corefile description and a JSON ObjectFile, incorporating all of the necessary stack memory and symbol names from a real debug session I worked on. The architectural default unwind plans are used for all stack frames except the 0th because there's no instructions for the functions, and no unwind info. I may need to add an encoding of unwind fules to ObjectFileJSON in the future as we create more test cases like this. This PR depends on the yaml2macho-core utility from https://github.com/llvm/llvm-project/pull/153911 to run its API test. rdar://110663219
2025-08-11[lldb] remove a superfluous assignment statement (#152669)Matej Košík
`cfa_reg_contents` is a local variable. Whatever value we assign there right before the `return` statement will be lost anyway. Co-authored-by: Matej Košík <matej.kosik@codasip.com>
2025-08-05[lldb] Implement DW_CFA_val_offset and DW_CFA_val_offset_sf (#150732)Daniel Sanders
The test for this is artificial as I'm not aware of any upstream targets that use DW_CFA_val_offset RegisterContextUnwind::ReadFrameAddress now reports how it's attempting to obtain the CFA unless all success/failure cases emit logs that clearly identify the method it was attempting. Previously several of the existing failure paths emit no message or a message that's indistinguishable from those on other paths.
2025-06-09[lldb][NFC] Split RegisterContextUnwind::SavedLocationForRegister (#139817)Jason Molenda
RegisterContextUnwind::SavedLocationForRegister is around 450 lines that first find an abstract register location (e.g. "CFA-8") for a register by looking in the UnwindPlans. Then it evaluates the abstract register location to create a concrete register location (e.g. "stored at address 0x...", "live in register at frame 0"). There are some complicated cases in the first half of the method to handle return address register architectures correctly, in particular. Looking at the two halves, they're both exactly 226 lines long and there's little involvement between them except for passing an abstract register location along. (there were some parts in the "abstract register location" code that would set the concrete register location, unnecessarily) It's also a complex enough method that there are some bits of code that aren't actually doing anything at this point. This patch adds a RegisterContextUnwind::GetAbstractRegisterLocation method, which does the first half, and has a clearly defined return values. The code to convert an AbstractRegisterLocation into a ConcreteRegisterLocation remains in SavedLocationForRegister. It's a bit of a tricky patch to visually inspect, despite it not changing functionality, the reorganizations and rewrites make the diff unreadable. Nearly all the real changes are in the "find the abstract register location" first half of the method. I think reading the new code in its new form is the easiest way to inspect this PR. With a defined interface between the two of what is expected, it's pretty easy to look at the code and reason about whether it is written correctly. (whereas before, that was very difficult, for me at least.) --------- Co-authored-by: Pavel Labath <pavel@labath.sk>
2025-05-22[lldb] Disable some unwind plans for discontinuous functions (#140927)Pavel Labath
Basically, disable everything except the eh_frame unwind plan, as that's the only one which supports this right now. The other plans are working with now trying the interpret everything in between the function parts as a part of the function, which is more likely to produce wrong results than correct ones. I changed the interface for object file plans, to give the implementations a chance to implement this correctly, but I haven't actually converted PECallFrameInfo (its only implementation) to handle that. (from the looks of things, it should be relatively easy to do, if it becomes necessary) I'm also deleting UnwindPlan::GetFirstNonPrologueInsn, as it's not used, and it doesn't work for discontinuous functions.
2025-05-18[lldb] Remove redundant calls to std::unique_ptr<T>::get (NFC) (NFC) (#140440)Kazu Hirata
2025-05-15[lldb] Fix offset computation in RegisterContextUnwind (#137155)Pavel Labath
AddressFunctionScope was always returning the first address range of the function (assuming it was the only one). This doesn't work for RegisterContextUnwind (it's only caller), when the function doesn't start at the lowest address because it throws off the 'how many bytes "into" a function I am' computation. This patch replaces the result with a call to (recently introduced) SymbolContext::GetFunctionOrSymbolAddress.
2025-05-11[lldb] Provide lr value in faulting frame on arm64 (#138805)Jason Molenda
Re-landing this patch with small tweaks to address CI bot failures as it was run on many different configurations. I think the test may run on aarch64 Linux systems now. When a frameless function faults or is interrupted asynchronously, the UnwindPlan MAY have no register location rule for the return address register (lr on arm64); the value is simply live in the lr register when it was interrupted, and the frame below this on the stack -- e.g. sigtramp on a Unix system -- has the full register context, including that register. RegisterContextUnwind::SavedLocationForRegister, when asked to find the caller's pc value, will first see if there is a pc register location. If there isn't, on a Return Address Register architecture like arm/mips/riscv, we rewrite the register request from "pc" to "RA register", and search for a location. On frame 0 (the live frame) and an interrupted frame, the UnwindPlan may have no register location rule for the RA Reg, that is valid. A frameless function that never calls another may simply keep the return address in the live register the whole way. Our instruction emulation unwind plans explicitly add a rule (see Pavel's May 2024 change https://github.com/llvm/llvm-project/pull/91321 ), but an UnwindPlan sourced from debug_frame may not. I've got a case where this exactly happens - clang debug_frame for arm64 where there is no register location for the lr in a frameless function. There is a fault in the middle of this frameless function and we only get the lr value from the fault handler below this frame if lr has a register location of `IsSame`, in line with Pavel's 2024 change. Similar to how we see a request of the RA Reg from frame 0 after failing to find an unwind location for the pc register, the same style of special casing is needed when this is a function that was interrupted. Without this change, we can find the pc of the frame that was executing when it was interrupted, but we need $lr to find its caller, and we don't descend down to the trap handler to get that value, truncating the stack. rdar://145614545
2025-05-10[lldb] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#139428)Kazu Hirata
2025-05-09Revert "[lldb] Provide lr value in faulting frame on arm64 (#138805)"Jason Molenda
This test is failing on the LLDB Incremental bot (arm64), which is running an older set of tools (Xcode 15.2) and OS (macOS 14.1) and the CFI directives must not be emitted correctly by either the tools or the OS. I will need to reproduce how this is compiling on that older setup and see what the issue is. Reverting for now so the bots are not blocked. This reverts commit e897cb139ee6ef5c145fed5394c4d96baa658e6b.
2025-05-09[lldb] Provide lr value in faulting frame on arm64 (#138805)Jason Molenda
When a frameless function faults or is interrupted asynchronously, the UnwindPlan MAY have no register location rule for the return address register (lr on arm64); the value is simply live in the lr register when it was interrupted, and the frame below this on the stack -- e.g. sigtramp on a Unix system -- has the full register context, including that register. RegisterContextUnwind::SavedLocationForRegister, when asked to find the caller's pc value, will first see if there is a pc register location. If there isn't, on a Return Address Register architecture like arm/mips/riscv, we rewrite the register request from "pc" to "RA register", and search for a location. On frame 0 (the live frame) and an interrupted frame, the UnwindPlan may have no register location rule for the RA Reg, that is valid. A frameless function that never calls another may simply keep the return address in the live register the whole way. Our instruction emulation unwind plans explicitly add a rule (see Pavel's May 2024 change https://github.com/llvm/llvm-project/pull/91321 ), but an UnwindPlan sourced from debug_frame may not. I've got a case where this exactly happens - clang debug_frame for arm64 where there is no register location for the lr in a frameless function. There is a fault in the middle of this frameless function and we only get the lr value from the fault handler below this frame if lr has a register location of `IsSame`, in line with Pavel's 2024 change. Similar to how we see a request of the RA Reg from frame 0 after failing to find an unwind location for the pc register, the same style of special casing is needed when this is a function that was interrupted. Without this change, we can find the pc of the frame that was executing when it was interrupted, but we need $lr to find its caller, and we don't descend down to the trap handler to get that value, truncating the stack. rdar://145614545
2025-05-07[lldb] Parse DWARF CFI for discontinuous functions (#137006)Pavel Labath
This patch uses the previously build infrastructure to parse multiple FDE entries into a single unwind plan. There is one catch though: we parse only one FDE entry per unwind range. This is not fully correct because lldb coalesces adjecant address ranges, which means that something that originally looked like two separate address ranges (and two FDE entries) may get merged into one because if the linker decides to put the two ranges next to each other. In this case, we will ignore the second FDE entry. It would be more correct to try to parse another entry when the one we found turns out to be short, but I'm not doing this (yet), because: - this is how we've done things so far (although, monolithic functions are unlikely to have more than one FDE entry) - in cases where we don't have debug info or (full) symbol tables, we can end up with "symbols" which appear to span many megabytes (potentially, the whole module). If we tried to fill short FDE entries, we could end up parsing the entire eh_frame section in a single go. In a way, this would be more correct, but it would also probably be very slow. I haven't quite decided what to do about this case yet, though it's not particularly likely to happen in the "production" cases as typically the functions are split into two parts (hot/cold) instead of one part per basic block.
2025-04-04Reapply "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders " ↵Pavel Labath
(#134246) This reverts commit 094904303d50e0ab14bc5f2586a602f79af95953, reapplying d7afafdbc464e65c56a0a1d77bad426aa7538306 (#133247). The failure ought to be fixed by 0509932bb6a291ba11253f30c465ab3ad164ae08.
2025-04-03[lldb] Initialize active_row pointer variablePavel Labath
It's value is not set on all control flow paths. I believe this should fix the failure on some buildbots after #133247.
2025-04-03Revert "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders (#133247)"Vladislav Dzhidzhoev
This reverts commit d7afafdbc464e65c56a0a1d77bad426aa7538306. Caused remote Linux to Linux buildbot failure https://lab.llvm.org/buildbot/#/builders/195/builds/7046.
2025-04-02[lldb] Return *const* UnwindPlan pointers from FuncUnwinders (#133247)Pavel Labath
These plans are cached and accessed from multiple threads. Modifying them would be a Bad Idea(tm).
2025-03-31[lldb] Make GetRowForFunctionOffset compatible with discontinuous functions ↵Pavel Labath
(#133250) The function had special handling for -1, but that is incompatible with functions whose entry point is not the first address. Use std::nullopt instead.
2025-02-26[lldb] Modernize ABI-based unwind plan creation (#128505)Pavel Labath
Replace the by-ref return value with an actual result.
2025-02-25[lldb] Don't hand out UnwindPlan::Row shared_ptrs (#128181)Pavel Labath
The whole unwind plan is already stored in a shared pointer, and there's no need to persist Rows individually. If there's ever a need to do that, there are at least two options: - copy the row (they're not that big, and they're being copied left and right during construction already) - use the shared_ptr subobject constructor to create a shared_ptr which points to a Row but holds the entire unwind plan alive This also changes all of the getter functions to return const Row pointers, which is important for safety because all of these objects are cached and potentially accessed from multiple threads. (Technically one could hand out `shared_ptr<const Row>`s, but we don't have a habit of doing that.) As a next step, I'd like to remove the internal UnwindPlan usages of the shared pointer, but I'm doing this separately to gauge feedback, and also because the patch got rather big.
2024-11-19Revert "[lldb] Allow fetching of RA register when above fault handler (#98566)"Jason Molenda
This reverts commit fd424179dcb3417fc0675f77d2bf06c750dd1c33. This patch has two problems. First, it is unnecessary, Pavel landed a fix a week or so before mine which solves this problem in bbd54e08b08f5ccd38c4665178e65c58f7b14459 . Second, the fix is incorrect; for a function above a trap handler, where all registers are available, this patch would have lldb fetch the return address register from frame 0. This might be 10 frames up in the stack; the frame 0 return address register is incorrect. The change would have been correct a short bit later than this, but Pavel's fix is executed earlier in the function and none of this is needed.
2024-10-04[lldb] Add isConstant mode for FA locations (#110726)Felipe de Azevedo Piovezan
This is similar to 9fe455fd0c7d, but for FA locations instead of register locations. This is useful for unwind plans that cannot create abstract unwind rules, but instead must inspect the state of the program to determine the current CFA.
2024-09-23[lldb][NFC] New names for the two RegisterLocation classes (#109611)Jason Molenda
lldb has two RegisterLocation classes that do slightly different things. UnwindPlan::Row::RegisterLocation (new: AbstractRegisterLocation) has a description of how to find a register's value or location, not specific to a particular stopping point. It may say that at a given offset into a function, the caller's register has been spilled to stack memory at CFA minus an offset. Or it may say that the caller's register is at a DWARF exprssion. UnwindLLDB::RegisterLocation (new: ConcreteRegisterLocation) is a specific address where the register is currently stored, or the register it has been copied into, or its value at this point in the current function execution. When lldb stops in a function, it interprets the AbstractRegisterLocation's instructions using the register context and stack memory, to create the ConcreteRegisterLocation at this point in time for this stack frame. I'm not thrilled with AbstractRegisterLocation and ConcreteRegisterLocation, but it's better than the same name and it will be easier to update them if someone suggests a better pair.
2024-07-31[lldb] Add constant value mode for RegisterLocation in UnwindPlans (#100624)Felipe de Azevedo Piovezan
This is useful for language runtimes that compute register values by inspecting the state of the currently running process. Currently, there are no mechanisms enabling these runtimes to set register values to arbitrary values. The alternative considered would involve creating a dwarf expression that produces an arbitrary integer (e.g. using OP_constu). However, the current data structure for Rows is such that they do not own any memory associated with dwarf expressions, which implies any such expression would need to have static storage and therefore could not contain a runtime value. Adding a new rule for constants leads to a simpler implementation. It's also worth noting that this does not make the "Location" union any bigger, since it already contains a pointer+size pair.
2024-07-12[lldb] Allow fetching of RA register when above fault handler (#98566)Jason Molenda
In RegisterContextUnwind::SavedLocationForRegister we have special logic for retrieving the Return Address register when it has the caller's return address in it. An example would be the lr register on AArch64. This register is never retrieved from a newer stack frame because it is necessarly overwritten by a normal ABI function call. We allow frame 0 to provide its lr value to get the caller's return address, if it has not been overwritten/saved to stack yet. When a function is interrupted asynchronously by a POSIX signal (sigtramp), or a fault handler more generally, the sigtramp/fault handler has the entire register context available. In this situation, if the fault handler is frame 0, the function that was async interrupted is frame 1 and frame 2's return address may still be stored in lr. We need to get the lr value for frame 1 from the fault handler in frame 0, to get the return address for frame 2. Without this fix, a frameless function that faults in a firmware environment (that's where we've seen this issue most commonly) hasn't spilled lr to stack, so we need to retrieve it from the fault handler's full-register-context to find the caller of the frameless function that faulted. It's an unsurprising fix, all of the work was finding exactly where in RegisterContextUnwind we were only allowing RA register use for frame 0, when it should have been frame 0 or above a fault handler function. rdar://127518945
2024-06-05[lldb] Return an llvm::Expected from DWARFExpression::Evaluate (NFCI) (#94420)Jonas Devlieghere
Change the signature of `DWARFExpression::Evaluate` and `DWARFExpressionList::Evaluate` to return an `llvm::Expected` instead of a boolean. This eliminates the `Status` output parameter and generally improves error handling.
2024-05-21Reapply "[lldb/aarch64] Fix unwinding when signal interrupts a leaf f… ↵Pavel Labath
(#92503) …unction (#91321)" This reapplies fd1bd53ba5a06f344698a55578f6a5d79c457e30, which was reverted due to a test failure on aarch64/windows. The failure was caused by a combination of several factors: - clang targeting aarch64-windows (unlike msvc, and unlike clang targeting other aarch64 platforms) defaults to -fomit-frame-pointers - lldb's code for looking up register values for `<same>` unwind rules is recursive - the test binary creates a very long chain of fp-less function frames (it manages to fit about 22k frames before it blows its stack) Together, these things have caused lldb to recreate the same deep recursion when unwinding through this, and blow its own stack as well. Since lldb frames are larger, about 4k frames like this was sufficient to trigger the stack overflow. This version of the patch works around this problem by increasing the frame size of the test binary, thereby causing it to blow its stack sooner. This doesn't fix the issue -- the same problem can occur with a real binary -- but it's not very likely, as it requires an infinite recursion in a simple (so it doesn't use the frame pointer) function with a very small frame (so you can fit a lot of them on the stack). A more principled fix would be to make lldb's lookup code non-recursive, but I believe that's out of scope for this patch. The original patch description follows: A leaf function may not store the link register to stack, but we it can still end up being a non-zero frame if it gets interrupted by a signal. Currently, we were unable to unwind past this function because we could not read the link register value. To make this work, this patch: - changes the function-entry unwind plan to include the `fp|lr = <same>` rules. This in turn necessitated an adjustment in the generic instruction emulation logic to ensure that `lr=[sp-X]` can override the `<same>` rule. - allows the `<same>` rule for pc and lr in all `m_all_registers_available` frames (and not just frame zero). The test verifies that we can unwind in a situation like this, and that the backtrace matches the one we computed before getting a signal.
2024-05-13Revert "[lldb/aarch64] Fix unwinding when signal interrupts a leaf function ↵Muhammad Omair Javaid
(#91321)" This reverts commit fd1bd53ba5a06f344698a55578f6a5d79c457e30. TestInterruptBacktrace was broken on AArch64/Windows as a result of this change. See lldb-aarch64-windows buildbot here: https://lab.llvm.org/buildbot/#/builders/219/builds/11261
2024-05-09[lldb/aarch64] Fix unwinding when signal interrupts a leaf function (#91321)Pavel Labath
A leaf function may not store the link register to stack, but we it can still end up being a non-zero frame if it gets interrupted by a signal. Currently, we were unable to unwind past this function because we could not read the link register value. To make this work, this patch: - changes the function-entry unwind plan to include the `fp|lr = <same>` rules. This in turn necessitated an adjustment in the generic instruction emulation logic to ensure that `lr=[sp-X]` can override the `<same>` rule. - allows the `<same>` rule for pc and lr in all `m_all_registers_available` frames (and not just frame zero). The test verifies that we can unwind in a situation like this, and that the backtrace matches the one we computed before getting a signal.
2023-09-01[lldb] Fix duplicate word typos; NFCFangrui Song
Those fixes were taken from https://reviews.llvm.org/D137338
2023-06-14Clear non-addressable bits from pc/fp/sp in unwindsJason Molenda
Some Darwin corefiles can have the pc/fp/sp/lr in the live register context signed with pointer authentication; this patch changes RegisterContextUnwind to strip those bits off of those values as we try to walk the stack. Differential Revision: https://reviews.llvm.org/D152861 rdar://109185291
2023-02-06In InitializeZerothFrame check for a CFA/AFA or error outJason Molenda
There is a failure where we somehow get an invalid register number being used to calculate the canonical frame address, and this ends up with lldb crashing with a null deref because it assumes that it is always able to find information about that register. This patch adds a check for a failure to get a register, and declares the frame invalid in that case, with some additional logging or an assert for debug builds. Differential Revision: https://reviews.llvm.org/D143232 rdar://104428038
2022-07-25[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 2Slava Gurevich
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com: 1476275, 1274012, 1455035, 1364789, 1454282 1467483, 1406152, 1406255, 1454837, 1454416 1467446, 1462022, 1461909, 1420566, 1327228 1367767, 1431254, 1467299, 1312678, 1431780 1454731, 1490403 Differential Revision: https://reviews.llvm.org/D130528
2022-07-25Revert "[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity ↵Slava Gurevich
scan. Part 2" This reverts commit b9aedd94e6796e4b4866ab4c091b736b3db58cb7.
2022-07-25[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 2Slava Gurevich
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com: 1476275, 1274012, 1455035, 1364789, 1454282 1467483, 1406152, 1406255, 1454837, 1454416 1467446, 1462022, 1461909, 1420566, 1327228 1367767, 1431254, 1467299, 1312678, 1431780 1454731, 1490403 Differential Revision: https://reviews.llvm.org/D130528
2022-07-12Reland "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."Zequan Wu
This reland 227dffd0b6d78154516ace45f6ed28259c7baa48 and 562c3467a6738aa89203f72fc1d1343e5baadf3c with failed api tests fixed by keeping function base file addres in DWARFExpressionList.
2022-07-07Revert "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."Jonas Devlieghere
This reverts commit 227dffd0b6d78154516ace45f6ed28259c7baa48 and its follow up 562c3467a6738aa89203f72fc1d1343e5baadf3c because it breaks a bunch of tests on GreenDragon: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45155/
2022-07-07[LLDB][NFC] Decouple dwarf location table from DWARFExpression.Zequan Wu
Differential Revision: https://reviews.llvm.org/D125509
2022-05-05Decr return pc mid-stack when picking UnwindPlan rowJason Molenda
When picking the UnwindPlan row to use to backtrace, off of the zeroth frame, decrement the return pc so we're in the address range of the call instruction. If this is a noretrun function call, the instruction at the "return address" is likely an entirely different basic block with possibly very different unwind rules, and this can cause the backtrace to be incorrect. Differential Revision: https://reviews.llvm.org/D124957 rdar://84651805
2022-04-05[lldb] Refactor DataBuffer so we can map files as read-onlyJonas Devlieghere
Currently, all data buffers are assumed to be writable. This is a problem on macOS where it's not allowed to load unsigned binaries in memory as writable. To be more precise, MAP_RESILIENT_CODESIGN and MAP_RESILIENT_MEDIA need to be set for mapped (unsigned) binaries on our platform. Binaries are mapped through FileSystem::CreateDataBuffer which returns a DataBufferLLVM. The latter is backed by a llvm::WritableMemoryBuffer because every DataBuffer in LLDB is considered to be writable. In order to use a read-only llvm::MemoryBuffer I had to split our abstraction around it. This patch distinguishes between a DataBuffer (read-only) and WritableDataBuffer (read-write) and updates LLDB to use the appropriate one. rdar://74890607 Differential revision: https://reviews.llvm.org/D122856
2022-03-30[lldb] Remove vasprintf windows-compat implementationPavel Labath
We already have a VASprintf function for this purpose, so I'm switching the remaining few users to that.
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath
Most of our code was including Log.h even though that is not where the "lldb" log channel is defined (Log.h defines the generic logging infrastructure). This worked because Log.h included Logging.h, even though it should. After the recent refactor, it became impossible the two files include each other in this direction (the opposite inclusion is needed), so this patch removes the workaround that was put in place and cleans up all files to include the right thing. It also renames the file to LLDBLog to better reflect its purpose.
2022-02-02[lldb] Convert "LLDB" log channel to the new APIPavel Labath
2021-12-26Remove redundant string initialization (NFC)Kazu Hirata
Identified with readability-redundant-string-init.
2021-11-11[lldb][AArch64] Add UnwindPlan for Linux sigreturnDavid Spickett
This adds a specific unwind plan for AArch64 Linux sigreturn frames. Previously we assumed that the fp would be valid here but it is not. https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/vdso/sigreturn.S On Ubuntu Bionic it happened to point to an old frame info which meant you got what looked like a correct backtrace. On Focal, the info is completely invalid. (probably due to some code shuffling in libc) This adds an UnwindPlan that knows that the sp in a sigreturn frame points to an rt_sigframe from which we can offset to get saved sp and pc values to backtrace correctly. Based on LibUnwind's change: https://reviews.llvm.org/D90898 A new test is added that sets all compares the frames from the initial signal catch to the handler break. Ensuring that the stack/frame pointer, function name and register values match. (this test is AArch64 Linux specific because it's the only one with a specific unwind plan for this situation) Fixes https://bugs.llvm.org/show_bug.cgi?id=52165 Reviewed By: omjavaid, labath Differential Revision: https://reviews.llvm.org/D112069
2021-05-13[lldb] Fixup more code addressesJonas Devlieghere
The Swift async task pointers are signed on arm64e and we need to fixup the addresses in the CFA and DWARF expressions.
2021-04-16[lldb] Implement ABI::Fix{Code,Data}Address for AArch64Jonas Devlieghere
Implement FixCodeAddress and FixDataAddress for ABIMacOSX_arm64 and ABISysV_arm64 and add missing calls to RegisterContextUnwind. We need this to unwind on Apple Silicon where libraries like libSystem are arm64e even when the program being debugged is arm64. Differential revision: https://reviews.llvm.org/D100521