aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectBreakpoint.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-10[lldb] Support specifying a language for breakpoint conditions (#147603)Jonas Devlieghere1-1/+16
LLDB breakpoint conditions take an expression that's evaluated using the language of the code where the breakpoint is located. Users have asked to have an option to tell it to evaluate the expression in a specific language. This is feature is especially helpful for Swift, for example for a condition based on the value in memory at an offset from a register. Such a condition is pretty difficult to write in Swift, but easy in C. This PR adds a new argument (-Y) to specify the language of the condition expression. We can't reuse the current -L option, since you might want to break on only Swift symbols, but run a C expression there as per the example above. rdar://146119507
2025-07-09[lldb] Change breakpoint interfaces for error handling (#146972)Jonas Devlieghere1-3/+13
This RP changes some Breakpoint-related interfaces to return errors. On its own these improvements are small, but they encourage better error handling going forward. There are a bunch of other candidates, but these were the functions that I touched while working on #146602.
2025-06-26Fix a bug in the breakpoint ID verifier in CommandObjectBreakpoint. (#145994)jimingham1-2/+3
It was assuming that for any location M.N, N was always less than the number of breakpoint locations. But if you rebuild the target and rerun multiple times, when the section backing one of the locations is no longer valid, we remove the location, but we don't reuse the ID. So you can have a breakpoint that only has location 1.3. The num_locations check would say that was an invalid location.
2025-06-04[lldb] Remove an unused local variable (NFC) (#142882)Kazu Hirata1-1/+0
Note that CommandArgumentEntry is an alias for: std::vector<CommandArgumentData>
2024-09-05[lldb] Make conversions from llvm::Error explicit with Status::FromEr… ↵Adrian Prantl1-46/+57
(#107163) …ror() [NFC]
2024-08-30[lldb] Deal with SupportFiles in SourceManager (NFC) (#106740)Jonas Devlieghere1-6/+10
To support detecting MD5 checksum mismatches, deal with SupportFiles rather than a plain FileSpecs in the SourceManager.
2024-08-02[lldb] Eliminate more Targer* in favor of Target& in CommandObjects (NFC)Jonas Devlieghere1-14/+14
The majority of the replaced Target pointers were already used unconditionally and the few that were shouldn't even be NULL.
2024-07-31[lldb] Unify the way we get the Target in CommandObject (#101208)Jonas Devlieghere1-13/+14
Currently, CommandObjects are obtaining a target in a variety of ways. Often the command incorrectly operates on the selected target. As an example, when a breakpoint command is running, the current target is passed into the command but the target that hit the breakpoint is not the selected target. In other places we use the CommandObject's execution context, which is frozen during the execution of the command, and comes with its own limitations. Finally, we often want to fall back to the dummy target if no real target is available. Instead of having to guess how to get the target, this patch introduces one helper function in CommandObject to get the most relevant target. In order of priority, that's the target from the command object's execution context, from the interpreter's execution context, the selected target or the dummy target. rdar://110846511
2024-07-05[lldb-dap][NFC] Minor renamewalter erquinigo1-1/+2
As a minor follow up for https://github.com/llvm/llvm-project/pull/97675, I'm renaming `SupportsExceptionBreakpoints` to `SupportsExceptionBreakpointsOnThrow` and adding a `SupportsExceptionBreakpointsOnCatch` to have a bit of more granularity.
2024-07-04[LLDB] Support exception breakpoints for plugin-provided languages (#97675)Walter Erquinigo1-3/+6
CommandObjectBreakpoint has a harcoded list of languages for which exception breakpoints can be enabled. I'm making this a bit more generic so that my Mojo plugin can get this feature. Basically, I'm adding a new overridable method `Language::SupportsExceptionBreakpoints` that can be used by language plugins to determine whether they support this feature or not. This method is used in addition to the hardcoded list and, as an example, I'm using it for the ObjC language support. Another route is simply to avoid doing the check that it's being done right now and simply try to the create the exception breakpoint for whatever language that is not in the hardcoded list. I'm happy to do that if the reviewers think it's a good idea. As a note, the other possible place for adding this `SupportsExceptionBreakpoints` method is in `LanguageRuntime`. However, accessing it requires having a process, which is not always the case when invoking the `breakpoint set -E` command. The process might not be alive yet, so `Language` is a good second place for this. And as a final note, I don't want to make this `SupportsExceptionBreakpoints` complicated. I'm keeping it as simple as possible because it can easily evolve as it's not part of the public API.
2024-03-21[lldb] Reland: Store SupportFile in FileEntry (NFC) (#85892)Jonas Devlieghere1-2/+2
This is another step towards supporting DWARF5 checksums and inline source code in LLDB. This is a reland of #85468 but without the functional change of storing the support file from the line table (yet).
2024-03-19Revert "[lldb] Store SupportFile in FileEntry (NFC)" (#85885)Jonas Devlieghere1-2/+2
Reverts llvm/llvm-project#85468 because @slackito reports this broke stepping in one of their tests [1] and this patch was meant to be NFC. [1] https://github.com/llvm/llvm-project/commit/d5a277d309e92b1d3e493da6036cffdf815105b1#commitcomment-139991120
2024-03-15[lldb] Store SupportFile in FileEntry (NFC) (#85468)Jonas Devlieghere1-2/+2
This is another step towards supporting DWARF5 checksums and inline source code in LLDB.
2024-02-27Start to clean up the process of defining command arguments. (#83097)jimingham1-63/+9
Partly, there's just a lot of unnecessary boiler plate. It's also possible to define combinations of arguments that make no sense (e.g. eArgRepeatPlus followed by eArgRepeatPlain...) but these are never checked since we just push_back directly into the argument definitions. This commit is step 1 of this cleanup - do the obvious stuff. In it, all the simple homogenous argument lists and the breakpoint/watchpoint ID/Range types, are set with common functions. This is an NFC change, it just centralizes boiler plate. There's no checking yet because you can't get a single argument wrong. The end goal is that all argument definition goes through functions and m_arguments is hidden so that you can't define inconsistent argument sets.
2024-02-27[lldb] Use CreateOptionParsingError in CommandObjectBreakpoint (#83086)Alex Langford1-49/+52
This updates the remaining SetOptionValue methods in CommandObjectBreakpoint to use CreateOptionParsingError. I found a few minor bugs that were fixed during this refactor (e.g. using the wrong flag in an error message). That is one of the benefits of centralizing error message creation. I also found some option parsing code that is written incorrectly. I do not make an attempt to update those here because this PR is primarily about changing existing error handling code, not adding new error handling code.
2024-02-21[lldb] Standardize command option parsing error messages (#82273)Alex Langford1-17/+20
I have been looking to simplify parsing logic and improve the interfaces so that they are both easier to use and harder to abuse. To be specific, I am referring to functions such as `OptionArgParser::ToBoolean`: I would like to go from its current interface to something more like `llvm::Error<bool> ToBoolean(llvm::StringRef option_arg)`. Through working on that, I encountered 2 inconveniences: 1. Option parsing code is not uniform. Every function writes a slightly different error message, so incorporating an error message from the `ToBoolean` implementation is going to be laborious as I figure out what exactly needs to change or stay the same. 2. Changing the interface of `ToBoolean` would require a global atomic change across all of the Command code. This would be quite frustrating to do because of the non-uniformity of our existing code. To address these frustrations, I think it would be easiest to first standardize the error reporting mechanism when parsing options in commands. I do so by introducing `CreateOptionParsingError` which will create an error message of the shape: Invalid value ('${option_arg}') for -${short_value} ('${long_value}'): ${additional_context} Concretely, it would look something like this: (lldb) breakpoint set -n main -G yay error: Invalid value ('yay') for -G (auto-continue): Failed to parse as boolean After this, updating the interfaces for parsing the values themselves should become simpler. Because this can be adopted incrementally, this should be able to done over the course of time instead of all at once as a giant difficult-to-review change. I've changed exactly one function where this function would be used as an illustration of what I am proposing.
2024-01-26[lldb][NFCI] Change BreakpointIDList::FindBreakpointID to ↵Alex Langford1-3/+2
BreakpointIDList::Contains (#79517) `FindBreakpointID` take a BreakpointID and a pointer to a size_t (so you can get position information). It returns a bool to indicate whether the id was found in the list or not. There are 2 callers of this currently and neither one actually uses the position information, so I removed it. After that, I renamed it to Contains to more accurately reflect the intent. Additionally, I changed the argument type from a reference to a value (because BreakpointID is just a wrapper around 2 integers, copies are cheap).
2024-01-12[lldb][NFCI] Remove CommandReturnObject from BreakpointIDList (#77858)Alex Langford1-26/+28
BreakpointIDList does not need to know about CommandReturnObject. BreakpointIDList::FindAndReplaceIDRanges is the last place that uses it in BreakpointIDList. Instead of passing in a CommandReturnObject, it now returns an llvm::Error. The callsite uses the Error to populate the CommandReturnObject as needed.
2024-01-08[lldb][NFCI] Remove BreakpointIDList::InsertStringArray (#77161)Alex Langford1-1/+3
This abstraction is leaky and BreakpointIDList does not need to know about CommandReturnObject. Additionally, setting the CommandReturnObject inout param to a success state does very little. The function returns immediately if the input ArrayRef is empty, and reading CommandObjectMultiwordBreakpoint::VerifyIDs more closely, the input is always empty if the previous call to BreakpointIDList::FindAndReplaceIDRanges failed. If the call was successful, then the CommandReturnObject is already in a success state. I have opted to remove the function altogether and inline the functionality where it was used.
2023-11-09[lldb] Change interface of StructuredData::Array::GetItemAtIndexAsString ↵Alex Langford1-3/+3
(#71613) This patch changes the interface of StructuredData::Array::GetItemAtIndexAsString to return a `std::optional<llvm::StringRef>` instead of taking an out parameter. More generally, this commit serves as proposal that we change all of the sibling APIs (`GetItemAtIndexAs`) to do the same thing. The reason this isn't one giant patch is because it is rather unwieldy changing just one of these, so if this is approved, I will do all of the other ones as individual follow-ups.
2023-10-30[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` return `void` ↵Pete Lawrence1-63/+42
(not `bool`) (#69991) [lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` to return `void` instead of ~~`bool`~~ Justifications: - The code doesn't ultimately apply the `true`/`false` return values. - The methods already pass around a `CommandReturnObject`, typically with a `result` parameter. - Each command return object already contains: - A more precise status - The error code(s) that apply to that status Part 1 refactors the `CommandObject::Execute(...)` method. - See [https://github.com/llvm/llvm-project/pull/69989](https://github.com/llvm/llvm-project/pull/69989) rdar://117378957
2023-10-19[lldb] Remove FileSpecList::GetFileSpecPointerAtIndex (NFC)Jonas Devlieghere1-2/+2
There's only one use and it eventually converts the pointer into a reference. Simplify things and always use references.
2023-06-06[lldb/Commands] Add support to auto-completion for user commandsMed Ismail Bennani1-24/+16
This patch should allow the user to set specific auto-completion type for their custom commands. To do so, we had to hoist the `CompletionType` enum so the user can access it and add a new completion type flag to the CommandScriptAdd Command Object. So now, the user can specify which completion type will be used with their custom command, when they register it. This also makes the `crashlog` custom commands use disk-file completion type, to browse through the user file system and load the report. Differential Revision: https://reviews.llvm.org/D152011 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-14[lldb] Complete OptionValue cleanup (NFC)Jonas Devlieghere1-3/+5
Make the `Get.*Value` and `Set.*Value` function private and migrate the last remaining call sites to the new overloaded/templated functions.
2023-05-01[lldb] Refactor OptionValue to return a std::optional (NFC)Jonas Devlieghere1-2/+4
Refactor OptionValue to return a std::optional instead of taking a fail value. This allows the caller to handle situations where there's no value, instead of being unable to distinguish between the absence of a value and the value happening the match the fail value. When a fail value is required, std::optional::value_or() provides the same functionality.
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille1-10/+10
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-1/+1
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-19Revert "[lldb] Remove redundant .c_str() and .get() calls"Muhammad Omair Javaid1-2/+2
This reverts commit fbaf48be0ff6fb24b9aa8fe9c2284fe88a8798dd. This has broken all LLDB buildbots: https://lab.llvm.org/buildbot/#/builders/68/builds/44990 https://lab.llvm.org/buildbot/#/builders/96/builds/33160
2022-12-18[lldb] Remove redundant .c_str() and .get() callsFangrui Song1-2/+2
Removing .c_str() has a semantics difference, but the use scenarios likely do not matter as we don't have NUL in the strings.
2022-12-08Improve error handling for invalid breakpoint `-t` and `-x` options.Jordan Rupprecht1-20/+20
Breakpoint option `-t` checks that `option_arg` is empty by checking `option_arg[0] == '\0'`. This is unnecessary: the next two checks for comparing against "current" and calling `getAsInteger` already gracefully handle an empty StringRef. If the `option_arg` string is empty, this crashes (or triggers an assertion failure with asserts enabled). Also, this sets the thread id to `LLDB_INVALID_THREAD_ID` if the thread id is invalid -- it should just not set the thread id. Likewise of `-x` which checks `option_arg[0] == '\n'` unnecessarily. I believe both of these bugs are unreachable via normal LLDB usage, and are only accessible via the fuzzer -- most likely some other CLI parsing is trimming whitespace and rejecting empty inputs. Still, it doesn't hurt to simplify this bit.
2022-07-14[lldb] Refactor command option enum values (NFC)Jonas Devlieghere1-0/+1
Refactor the command option enum values and the command argument table to connect the two. This has two benefits: - We guarantee that two options that use the same argument type have the same accepted values. - We can print the enum values and their description in the help output. (D129707) Differential revision: https://reviews.llvm.org/D129703
2022-06-08Add help text for "breakpoint name", describing the feature more fully.Jim Ingham1-2/+93
https://reviews.llvm.org/D127038
2022-03-31[LLDB] Applying clang-tidy modernize-use-equals-default over LLDBShafik Yaghmour1-8/+8
Applied modernize-use-equals-default clang-tidy check over LLDB. This check is already present in the lldb/.clang-tidy config. Differential Revision: https://reviews.llvm.org/D121844
2022-01-23[Commands] Remove redundant member initialization (NFC)Kazu Hirata1-35/+21
Identified with readability-redundant-member-init.
2021-08-06Add a "current" token to the ThreadID option to break set/modify.Jim Ingham1-1/+13
This provides a convenient way to limit a breakpoint to the current thread when setting it from the command line w/o having to figure out what the current thread is. Differential Revision: https://reviews.llvm.org/D107015
2021-07-27Fix "break delete --disabled" with no arguments.Jim Ingham1-52/+59
The code that figured out which breakpoints to delete was supposed to set the result status if it found breakpoints, and then the code that actually deleted them checked that the result's status was set. The code for "break delete --disabled" failed to set the status if no "protected" breakpoints were provided. This was a confusing way to implement this, so I reworked it with early returns so it was less error prone, and added a test case for the no arguments case. Differential Revision: https://reviews.llvm.org/D106623
2021-06-23[lldb] Remove CommandReturnObject's SetError(StringRef)David Spickett1-6/+6
Replacing existing uses with AppendError. SetError is also part of the SBI API. This remains but instead of calling the underlying SetError it will call AppendError. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104768
2021-06-17[lldb] Remove redundant calls to set eReturnStatusFailedDavid Spickett1-32/+0
This is part 2, covering the commands source. Some uses remain where it's tricky to see what the logic is or they are not used with AppendError. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104448
2021-06-15Convert functions that were returning BreakpointOption * to BreakpointOption &.Jim Ingham1-4/+4
This is an NFC cleanup. Many of the API's that returned BreakpointOptions always returned valid ones. Internally the BreakpointLocations usually have null BreakpointOptions, since they use their owner's options until an option is set specifically on the location. So the original code used pointers & unique_ptr everywhere for consistency. But that made the code hard to reason about from the outside. This patch changes the code so that everywhere an API is guaranteed to return a non-null BreakpointOption, it returns it as a reference to make that clear. It also changes the Breakpoint to hold a BreakpointOption member where it previously had a UP. Since we were always filling the UP in the Breakpoint constructor, having the UP wasn't helping anything. Differential Revision: https://reviews.llvm.org/D104162
2021-06-09[lldb] Use C++11 default member initializersJonas Devlieghere1-33/+23
This converts a default constructor's member initializers into C++11 default member initializers. This patch was automatically generated with clang-tidy and the modernize-use-default-member-init check. $ run-clang-tidy.py -header-filter='lldb' -checks='-*,modernize-use-default-member-init' -fix This is a mass-refactoring patch and this commit will be added to .git-blame-ignore-revs. Differential revision: https://reviews.llvm.org/D103483
2020-09-23Add `breakpoint delete --disabled`: deletes all disabled breakpoints.Jim Ingham1-7/+39
Differential Revision: https://reviews.llvm.org/D88129
2020-08-20[lldb] tab completion for breakpoint namesGongyu Deng1-1/+73
1. created a common completion for breakpoint names; 2. bound the breakpoint name common completion with eArgTypeBreakpointName; 3. implemented the dedicated completion for breakpoint read -N. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D80693
2020-07-20Add an option (-y) to "break set" and "source list" that uses the sameJim Ingham1-1/+17
file:line:column form that we use to print out locations. Since we print them this way it makes sense we also accept that form. Differential Revision: https://reviews.llvm.org/D83975
2020-05-15Correct the argument list of command `breakpoint read`Gongyu Deng1-8/+1
Summary: Command `breakpoint read` should not accept breakpoint ids as arguments, and in fact, it is not implemented to deal with breakpoint id arguments either. So this patch is to correct the argument list of this command so that the help text won't misguide users. Reviewers: teemperor, JDevlieghere, jingham Reviewed By: teemperor, JDevlieghere Tags: #lldb Differential Revision: https://reviews.llvm.org/D79722
2020-05-11Tab completion for breakpoint write and breakpoint name add/deleteGongyu Deng1-0/+24
Summary: Apply the common completion created in [[ https://reviews.llvm.org/D75418 | Revision D75418 ]] to the commands `breakpoint write` and `breakpoint name add/delete`. Reviewers: teemperor, JDevlieghere Reviewed By: teemperor Tags: #lldb Differential Revision: https://reviews.llvm.org/D79686
2020-05-11Complete breakpoint enable/disable/delete/modify with a list of breakpoint IDsGongyu Deng1-0/+32
Summary: 1. A new common completion `CommandCompletions::Breakpoints` to provide a list of the breakpoints of the current context; 2. Apply the completion above to the commands breakpoint enable/disable/delete/modify; 3. Unit test. Reviewers: teemperor, JDevlieghere Reviewed By: teemperor Tags: #lldb Differential Revision: https://reviews.llvm.org/D79666
2020-05-06[lldb] Warn the user about starting the --func-regex parameter with an asteriskRaphael Isemann1-0/+8
Summary: Sometimes users think that setting a function regex for all function that contain the word 'needle' in their name looks like this: `*needle*`. However, LLDB only searches the function name and doesn't fully match it against the regex, so the leading and trailing '*' operators don't do anything and actually just cause the regex engine to reject the regular expression with "repetition-operator operand invalid". This patch makes this a bit more obvious to the user by printing a warning that a leading '*' before this regular expression here doesn't have any purpose (and will cause an error). This doesn't attempt to detect a case where there is only a trailing '*' as that would involve parsing the regex and it seems the most common way to end up in this situation is by doing `rbreak *needle*`. Reviewers: JDevlieghere Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D78809
2020-04-27[lldb] Improve error message when --func-regex parameter for the breakpoint ↵Raphael Isemann1-1/+1
command is invalid Summary: Currently the breakpoint command is prompting the user to file a bug report if the provided regex is invalid: ``` (lldb) rbreak *foo error: Function name regular expression could not be compiled: "Inconvertible error value. An error has occurred that could not be converted to a known std::error_code. Please file a bug. repetition-operator operand invalid" ``` The reason is simply that we are using the wrong StringError constructor (the one with the error code as the first parameter is also printing the string version of the error code, and the inconvertible error code is just an invalid place holder code with that description). Switching the StringError constructor parameters will only print the error message we get from the regex engine when we convert the error into a string. I checked the rest of the code base and I couldn't find the same issue anywhere else. Fixes rdar://62233561 Reviewers: JDevlieghere Reviewed By: JDevlieghere Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D78808
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-14/+14
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.