[lldb][NFC] Fix all formatting errors in .cpp file headers
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
2020-01-24 15:23:27 +08:00
|
|
|
//===-- CommandObjectBreakpointCommand.cpp --------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CommandObjectBreakpointCommand.h"
|
|
|
|
#include "CommandObjectBreakpoint.h"
|
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointIDList.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
2014-01-28 07:43:24 +08:00
|
|
|
#include "lldb/Core/IOHandler.h"
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-04-10 17:03:59 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2019-10-26 05:05:07 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
// FIXME: "script-type" needs to have its contents determined dynamically, so
|
2019-08-02 08:18:44 +08:00
|
|
|
// somebody can add a new scripting language to lldb and have it pickable here
|
|
|
|
// without having to change this enumeration by hand and rebuild lldb proper.
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionEnumValueElement g_script_option_enumeration[] = {
|
2019-08-02 08:18:44 +08:00
|
|
|
{
|
|
|
|
eScriptLanguageNone,
|
|
|
|
"command",
|
|
|
|
"Commands are in the lldb command interpreter language",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eScriptLanguagePython,
|
|
|
|
"python",
|
|
|
|
"Commands are in the Python language.",
|
|
|
|
},
|
|
|
|
{
|
2019-12-22 09:21:30 +08:00
|
|
|
eScriptLanguageLua,
|
|
|
|
"lua",
|
|
|
|
"Commands are in the Lua language.",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eScriptLanguageDefault,
|
2019-08-02 08:18:44 +08:00
|
|
|
"default-script",
|
|
|
|
"Commands are in the default scripting language.",
|
|
|
|
},
|
|
|
|
};
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr OptionEnumValues ScriptOptionEnum() {
|
|
|
|
return OptionEnumValues(g_script_option_enumeration);
|
|
|
|
}
|
|
|
|
|
2019-07-22 18:02:09 +08:00
|
|
|
#define LLDB_OPTIONS_breakpoint_command_add
|
|
|
|
#include "CommandOptions.inc"
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
class CommandObjectBreakpointCommandAdd : public CommandObjectParsed,
|
|
|
|
public IOHandlerDelegateMultiline {
|
2012-06-09 05:56:10 +08:00
|
|
|
public:
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectBreakpointCommandAdd(CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectParsed(interpreter, "add",
|
|
|
|
"Add LLDB commands to a breakpoint, to be executed "
|
|
|
|
"whenever the breakpoint is hit."
|
|
|
|
" If no breakpoint is specified, adds the "
|
|
|
|
"commands to the last created breakpoint.",
|
|
|
|
nullptr),
|
|
|
|
IOHandlerDelegateMultiline("DONE",
|
|
|
|
IOHandlerDelegate::Completion::LLDBCommand),
|
2019-10-26 05:05:07 +08:00
|
|
|
m_options(), m_func_options("breakpoint command", false, 'F') {
|
2012-06-09 05:56:10 +08:00
|
|
|
SetHelpLong(
|
2015-07-14 13:48:36 +08:00
|
|
|
R"(
|
|
|
|
General information about entering breakpoint commands
|
|
|
|
------------------------------------------------------
|
|
|
|
|
|
|
|
)"
|
|
|
|
"This command will prompt for commands to be executed when the specified \
|
|
|
|
breakpoint is hit. Each command is typed on its own line following the '> ' \
|
|
|
|
prompt until 'DONE' is entered."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
)"
|
|
|
|
"Syntactic errors may not be detected when initially entered, and many \
|
|
|
|
malformed commands can silently fail when executed. If your breakpoint commands \
|
|
|
|
do not appear to be executing, double-check the command syntax."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
)"
|
|
|
|
"Note: You may enter any debugger command exactly as you would at the debugger \
|
|
|
|
prompt. There is no limit to the number of commands supplied, but do NOT enter \
|
|
|
|
more than one command per line."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
Special information about PYTHON breakpoint commands
|
|
|
|
----------------------------------------------------
|
|
|
|
|
|
|
|
)"
|
|
|
|
"You may enter either one or more lines of Python, including function \
|
|
|
|
definitions or calls to functions that will have been imported by the time \
|
|
|
|
the code executes. Single line breakpoint commands will be interpreted 'as is' \
|
|
|
|
when the breakpoint is hit. Multiple lines of Python will be wrapped in a \
|
|
|
|
generated function, and a call to the function will be attached to the breakpoint."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
This auto-generated function is passed in three arguments:
|
|
|
|
|
|
|
|
frame: an lldb.SBFrame object for the frame which hit breakpoint.
|
|
|
|
|
|
|
|
bp_loc: an lldb.SBBreakpointLocation object that represents the breakpoint location that was hit.
|
|
|
|
|
|
|
|
dict: the python session dictionary hit.
|
|
|
|
|
|
|
|
)"
|
|
|
|
"When specifying a python function with the --python-function option, you need \
|
|
|
|
to supply the function name prepended by the module name:"
|
|
|
|
R"(
|
|
|
|
|
|
|
|
--python-function myutils.breakpoint_callback
|
|
|
|
|
2021-02-10 07:32:45 +08:00
|
|
|
The function itself must have either of the following prototypes:
|
2015-07-14 13:48:36 +08:00
|
|
|
|
2021-02-10 09:48:04 +08:00
|
|
|
def breakpoint_callback(frame, bp_loc, internal_dict):
|
2015-07-14 13:48:36 +08:00
|
|
|
# Your code goes here
|
|
|
|
|
2021-02-10 07:32:45 +08:00
|
|
|
or:
|
|
|
|
|
2021-02-10 09:48:04 +08:00
|
|
|
def breakpoint_callback(frame, bp_loc, extra_args, internal_dict):
|
2021-02-10 07:32:45 +08:00
|
|
|
# Your code goes here
|
|
|
|
|
2015-07-14 13:48:36 +08:00
|
|
|
)"
|
|
|
|
"The arguments are the same as the arguments passed to generated functions as \
|
2021-02-10 08:06:47 +08:00
|
|
|
described above. In the second form, any -k and -v pairs provided to the command will \
|
2021-02-10 07:32:45 +08:00
|
|
|
be packaged into a SBDictionary in an SBStructuredData and passed as the extra_args parameter. \
|
2021-02-10 08:06:47 +08:00
|
|
|
\n\n\
|
2021-02-10 07:32:45 +08:00
|
|
|
Note that the global variable 'lldb.frame' will NOT be updated when \
|
2015-07-14 13:48:36 +08:00
|
|
|
this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
|
|
|
|
can get you to the thread via frame.GetThread(), the thread can get you to the \
|
|
|
|
process via thread.GetProcess(), and the process can get you back to the target \
|
|
|
|
via process.GetTarget()."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
)"
|
|
|
|
"Important Note: As Python code gets collected into functions, access to global \
|
|
|
|
variables requires explicit scoping using the 'global' keyword. Be sure to use correct \
|
|
|
|
Python syntax, including indentation, when entering Python breakpoint commands."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
Example Python one-line breakpoint command:
|
|
|
|
|
|
|
|
(lldb) breakpoint command add -s python 1
|
|
|
|
Enter your Python command(s). Type 'DONE' to end.
|
2020-09-17 07:40:48 +08:00
|
|
|
def function (frame, bp_loc, internal_dict):
|
|
|
|
"""frame: the lldb.SBFrame for the location at which you stopped
|
|
|
|
bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information
|
|
|
|
internal_dict: an LLDB support object not to be used"""
|
|
|
|
print("Hit this breakpoint!")
|
|
|
|
DONE
|
2015-07-14 13:48:36 +08:00
|
|
|
|
|
|
|
As a convenience, this also works for a short Python one-liner:
|
|
|
|
|
2020-09-17 07:40:48 +08:00
|
|
|
(lldb) breakpoint command add -s python 1 -o 'import time; print(time.asctime())'
|
2015-07-14 13:48:36 +08:00
|
|
|
(lldb) run
|
|
|
|
Launching '.../a.out' (x86_64)
|
|
|
|
(lldb) Fri Sep 10 12:17:45 2010
|
|
|
|
Process 21778 Stopped
|
|
|
|
* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
|
|
|
|
36
|
|
|
|
37 int c(int val)
|
|
|
|
38 {
|
|
|
|
39 -> return val + 3;
|
|
|
|
40 }
|
|
|
|
41
|
|
|
|
42 int main (int argc, char const *argv[])
|
|
|
|
|
|
|
|
Example multiple line Python breakpoint command:
|
|
|
|
|
|
|
|
(lldb) breakpoint command add -s p 1
|
|
|
|
Enter your Python command(s). Type 'DONE' to end.
|
2020-09-17 07:40:48 +08:00
|
|
|
def function (frame, bp_loc, internal_dict):
|
|
|
|
"""frame: the lldb.SBFrame for the location at which you stopped
|
|
|
|
bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information
|
|
|
|
internal_dict: an LLDB support object not to be used"""
|
|
|
|
global bp_count
|
|
|
|
bp_count = bp_count + 1
|
|
|
|
print("Hit this breakpoint " + repr(bp_count) + " times!")
|
|
|
|
DONE
|
2015-07-14 13:48:36 +08:00
|
|
|
|
|
|
|
)"
|
|
|
|
"In this case, since there is a reference to a global variable, \
|
|
|
|
'bp_count', you will also need to make sure 'bp_count' exists and is \
|
|
|
|
initialized:"
|
|
|
|
R"(
|
|
|
|
|
|
|
|
(lldb) script
|
|
|
|
>>> bp_count = 0
|
|
|
|
>>> quit()
|
|
|
|
|
|
|
|
)"
|
|
|
|
"Your Python code, however organized, can optionally return a value. \
|
|
|
|
If the returned value is False, that tells LLDB not to stop at the breakpoint \
|
|
|
|
to which the code is associated. Returning anything other than False, or even \
|
|
|
|
returning None, or even omitting a return statement entirely, will cause \
|
|
|
|
LLDB to stop."
|
|
|
|
R"(
|
|
|
|
|
|
|
|
)"
|
|
|
|
"Final Note: A warning that no breakpoint command was generated when there \
|
|
|
|
are no syntax errors may indicate that a function was declared but never called.");
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2019-10-26 05:05:07 +08:00
|
|
|
m_all_options.Append(&m_options);
|
2019-10-31 06:26:19 +08:00
|
|
|
m_all_options.Append(&m_func_options, LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
|
2019-10-26 05:05:07 +08:00
|
|
|
LLDB_OPT_SET_2);
|
|
|
|
m_all_options.Finalize();
|
2019-10-31 06:26:19 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData bp_id_arg;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
2014-08-28 08:50:17 +08:00
|
|
|
bp_id_arg.arg_repetition = eArgRepeatOptional;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg.push_back(bp_id_arg);
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 03:33:46 +08:00
|
|
|
~CommandObjectBreakpointCommandAdd() override = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-10-26 05:05:07 +08:00
|
|
|
Options *GetOptions() override { return &m_all_options; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Quiet command regex instructions during batch execution
Summary:
Within .lldbinit, regex commands can be structured as a list of substitutions over
multiple lines. It's possible that this is uninentional, but it works and has
benefits.
For example:
command regex <command-name>
s/pat1/repl1/
s/pat2/repl2/
...
I use this form of `command regex` in my `~/.lldbinit`, because it makes it
clearer to write and read compared to a single line definition, because
multiline substitutions don't need to be quoted, and are broken up one per line.
However, multiline definitions result in usage instructions being printed for
each use. The result is that every time I run `lldb`, I get a dozen or more
lines of noise. With this change, the instructions are only printed when
`command regex` is invoked interactively, or from a terminal, neither of which
are true when lldb is sourcing `~/.lldbinit`.
Reviewers: clayborg, jingham
Reviewed By: clayborg
Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits
Differential Revision: https://reviews.llvm.org/D48752
llvm-svn: 355793
2019-03-11 07:15:48 +08:00
|
|
|
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
|
Quiet command regex instructions during batch execution
Summary:
Within .lldbinit, regex commands can be structured as a list of substitutions over
multiple lines. It's possible that this is uninentional, but it works and has
benefits.
For example:
command regex <command-name>
s/pat1/repl1/
s/pat2/repl2/
...
I use this form of `command regex` in my `~/.lldbinit`, because it makes it
clearer to write and read compared to a single line definition, because
multiline substitutions don't need to be quoted, and are broken up one per line.
However, multiline definitions result in usage instructions being printed for
each use. The result is that every time I run `lldb`, I get a dozen or more
lines of noise. With this change, the instructions are only printed when
`command regex` is invoked interactively, or from a terminal, neither of which
are true when lldb is sourcing `~/.lldbinit`.
Reviewers: clayborg, jingham
Reviewed By: clayborg
Subscribers: jdoerfert, kastiglione, xiaobai, keith, lldb-commits
Differential Revision: https://reviews.llvm.org/D48752
llvm-svn: 355793
2019-03-11 07:15:48 +08:00
|
|
|
if (output_sp && interactive) {
|
2014-01-28 07:43:24 +08:00
|
|
|
output_sp->PutCString(g_reader_instructions);
|
|
|
|
output_sp->Flush();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
void IOHandlerInputComplete(IOHandler &io_handler,
|
|
|
|
std::string &line) override {
|
2014-01-28 07:43:24 +08:00
|
|
|
io_handler.SetIsDone(true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-08-30 01:34:17 +08:00
|
|
|
std::vector<BreakpointOptions *> *bp_options_vec =
|
|
|
|
(std::vector<BreakpointOptions *> *)io_handler.GetUserData();
|
|
|
|
for (BreakpointOptions *bp_options : *bp_options_vec) {
|
|
|
|
if (!bp_options)
|
|
|
|
continue;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-08-15 06:19:23 +08:00
|
|
|
auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
|
2016-09-13 07:10:56 +08:00
|
|
|
cmd_data->user_source.SplitIntoLines(line.c_str(), line.size());
|
2016-09-21 06:54:49 +08:00
|
|
|
bp_options->SetCommandDataCallback(cmd_data);
|
2012-04-05 01:30:31 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-08-30 01:34:17 +08:00
|
|
|
void CollectDataForBreakpointCommandCallback(
|
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec,
|
2014-01-28 07:43:24 +08:00
|
|
|
CommandReturnObject &result) {
|
|
|
|
m_interpreter.GetLLDBCommandsFromIOHandler(
|
|
|
|
"> ", // Prompt
|
|
|
|
*this, // IOHandlerDelegate
|
2014-08-30 01:34:17 +08:00
|
|
|
&bp_options_vec); // Baton for the "io_handler" that will be passed back
|
|
|
|
// into our IOHandlerDelegate functions
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
/// Set a one-liner as the callback for the breakpoint.
|
2016-09-07 04:57:50 +08:00
|
|
|
void
|
2014-08-30 01:34:17 +08:00
|
|
|
SetBreakpointCommandCallback(std::vector<BreakpointOptions *> &bp_options_vec,
|
2012-06-09 05:56:10 +08:00
|
|
|
const char *oneliner) {
|
2014-08-30 01:34:17 +08:00
|
|
|
for (auto bp_options : bp_options_vec) {
|
2019-08-15 06:19:23 +08:00
|
|
|
auto cmd_data = std::make_unique<BreakpointOptions::CommandData>();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
cmd_data->user_source.AppendString(oneliner);
|
|
|
|
cmd_data->stop_on_error = m_options.m_stop_on_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-21 06:54:49 +08:00
|
|
|
bp_options->SetCommandDataCallback(cmd_data);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-26 05:05:07 +08:00
|
|
|
class CommandOptions : public OptionGroup {
|
2016-09-07 04:57:50 +08:00
|
|
|
public:
|
2012-06-09 05:56:10 +08:00
|
|
|
CommandOptions()
|
2019-10-26 05:05:07 +08:00
|
|
|
: OptionGroup(), m_use_commands(false), m_use_script_language(false),
|
2012-06-09 05:56:10 +08:00
|
|
|
m_script_language(eScriptLanguageNone), m_use_one_liner(false),
|
2019-10-26 05:05:07 +08:00
|
|
|
m_one_liner() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
~CommandOptions() override = default;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2019-10-31 06:26:19 +08:00
|
|
|
const int short_option =
|
|
|
|
g_breakpoint_command_add_options[option_idx].short_option;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-11 08:38:27 +08:00
|
|
|
switch (short_option) {
|
|
|
|
case 'o':
|
|
|
|
m_use_one_liner = true;
|
2020-01-29 03:23:46 +08:00
|
|
|
m_one_liner = std::string(option_arg);
|
2012-06-09 05:56:10 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
case 's':
|
2018-04-10 17:03:59 +08:00
|
|
|
m_script_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
|
2019-07-28 14:24:07 +08:00
|
|
|
option_arg,
|
|
|
|
g_breakpoint_command_add_options[option_idx].enum_values,
|
2012-06-09 05:56:10 +08:00
|
|
|
eScriptLanguageNone, error);
|
2019-12-22 09:21:30 +08:00
|
|
|
switch (m_script_language) {
|
|
|
|
case eScriptLanguagePython:
|
|
|
|
case eScriptLanguageLua:
|
2012-06-09 05:56:10 +08:00
|
|
|
m_use_script_language = true;
|
2019-12-22 09:21:30 +08:00
|
|
|
break;
|
|
|
|
case eScriptLanguageNone:
|
2019-12-22 13:54:44 +08:00
|
|
|
case eScriptLanguageUnknown:
|
2012-06-09 05:56:10 +08:00
|
|
|
m_use_script_language = false;
|
2019-12-22 09:21:30 +08:00
|
|
|
break;
|
2012-06-09 05:56:10 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
case 'e': {
|
|
|
|
bool success = false;
|
2018-04-10 17:03:59 +08:00
|
|
|
m_stop_on_error =
|
|
|
|
OptionArgParser::ToBoolean(option_arg, false, &success);
|
2012-06-09 05:56:10 +08:00
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat(
|
2016-11-13 00:56:47 +08:00
|
|
|
"invalid value for stop-on-error: \"%s\"",
|
|
|
|
option_arg.str().c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
case 'D':
|
|
|
|
m_use_dummy = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2012-06-09 05:56:10 +08:00
|
|
|
m_use_commands = true;
|
|
|
|
m_use_script_language = false;
|
2016-02-20 03:33:46 +08:00
|
|
|
m_script_language = eScriptLanguageNone;
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
m_use_one_liner = false;
|
|
|
|
m_stop_on_error = true;
|
|
|
|
m_one_liner.clear();
|
2014-12-06 09:28:03 +08:00
|
|
|
m_use_dummy = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2019-07-28 14:24:07 +08:00
|
|
|
return llvm::makeArrayRef(g_breakpoint_command_add_options);
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
}
|
2010-09-11 08:18:09 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Instance variables to hold the values for command options.
|
2010-09-11 08:18:09 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
bool m_use_commands;
|
|
|
|
bool m_use_script_language;
|
|
|
|
lldb::ScriptLanguage m_script_language;
|
2010-09-11 08:18:09 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Instance variables to hold the values for one_liner options.
|
|
|
|
bool m_use_one_liner;
|
|
|
|
std::string m_one_liner;
|
|
|
|
bool m_stop_on_error;
|
2014-12-06 09:28:03 +08:00
|
|
|
bool m_use_dummy;
|
2012-06-09 05:56:10 +08:00
|
|
|
};
|
2010-09-11 08:18:09 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2019-08-27 02:12:44 +08:00
|
|
|
Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-08-27 02:12:44 +08:00
|
|
|
const BreakpointList &breakpoints = target.GetBreakpointList();
|
2012-06-09 05:56:10 +08:00
|
|
|
size_t num_breakpoints = breakpoints.GetSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
if (num_breakpoints == 0) {
|
|
|
|
result.AppendError("No breakpoints exist to have commands added");
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
2010-10-28 02:34:42 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-10-26 05:05:07 +08:00
|
|
|
if (!m_func_options.GetName().empty()) {
|
|
|
|
m_options.m_use_one_liner = false;
|
2019-12-22 10:11:40 +08:00
|
|
|
if (!m_options.m_use_script_language) {
|
|
|
|
m_options.m_script_language = GetDebugger().GetScriptLanguage();
|
|
|
|
m_options.m_use_script_language = true;
|
|
|
|
}
|
2014-08-30 01:34:17 +08:00
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
|
2014-08-30 01:34:17 +08:00
|
|
|
BreakpointIDList valid_bp_ids;
|
|
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
|
2019-08-27 02:12:44 +08:00
|
|
|
command, &target, result, &valid_bp_ids,
|
2017-09-15 04:22:49 +08:00
|
|
|
BreakpointName::Permissions::PermissionKinds::listPerm);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-08-30 01:34:17 +08:00
|
|
|
m_bp_options_vec.clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-02-20 03:33:46 +08:00
|
|
|
if (result.Succeeded()) {
|
|
|
|
const size_t count = valid_bp_ids.GetSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-08-30 01:34:17 +08:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
|
|
|
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
|
2012-06-09 05:56:10 +08:00
|
|
|
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
|
|
|
|
Breakpoint *bp =
|
2019-08-27 02:12:44 +08:00
|
|
|
target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
|
2014-08-30 01:34:17 +08:00
|
|
|
BreakpointOptions *bp_options = nullptr;
|
|
|
|
if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID) {
|
|
|
|
// This breakpoint does not have an associated location.
|
|
|
|
bp_options = bp->GetOptions();
|
|
|
|
} else {
|
|
|
|
BreakpointLocationSP bp_loc_sp(
|
|
|
|
bp->FindLocationByID(cur_bp_id.GetLocationID()));
|
2018-05-01 00:49:04 +08:00
|
|
|
// This breakpoint does have an associated location. Get its
|
|
|
|
// breakpoint options.
|
2014-08-30 01:34:17 +08:00
|
|
|
if (bp_loc_sp)
|
|
|
|
bp_options = bp_loc_sp->GetLocationOptions();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-08-30 01:34:17 +08:00
|
|
|
if (bp_options)
|
|
|
|
m_bp_options_vec.push_back(bp_options);
|
2010-11-20 04:47:54 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we are using script language, get the script interpreter in order
|
|
|
|
// to set or collect command callback. Otherwise, call the methods
|
|
|
|
// associated with this object.
|
2014-08-30 01:34:17 +08:00
|
|
|
if (m_options.m_use_script_language) {
|
2020-12-06 22:30:57 +08:00
|
|
|
Status error;
|
2019-12-22 09:28:36 +08:00
|
|
|
ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter(
|
|
|
|
/*can_create=*/true, m_options.m_script_language);
|
2012-06-09 05:56:10 +08:00
|
|
|
// Special handling for one-liner specified inline.
|
2014-08-30 01:34:17 +08:00
|
|
|
if (m_options.m_use_one_liner) {
|
2020-12-06 22:30:57 +08:00
|
|
|
error = script_interp->SetBreakpointCommandCallback(
|
2014-08-30 01:34:17 +08:00
|
|
|
m_bp_options_vec, m_options.m_one_liner.c_str());
|
2019-10-26 05:05:07 +08:00
|
|
|
} else if (!m_func_options.GetName().empty()) {
|
2020-12-06 22:30:57 +08:00
|
|
|
error = script_interp->SetBreakpointCommandCallbackFunction(
|
2019-10-26 05:05:07 +08:00
|
|
|
m_bp_options_vec, m_func_options.GetName().c_str(),
|
|
|
|
m_func_options.GetStructuredData());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-08-30 01:34:17 +08:00
|
|
|
script_interp->CollectDataForBreakpointCommandCallback(
|
2012-06-09 05:56:10 +08:00
|
|
|
m_bp_options_vec, result);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-12-06 22:30:57 +08:00
|
|
|
if (!error.Success())
|
|
|
|
result.SetError(error);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-08-30 01:34:17 +08:00
|
|
|
// Special handling for one-liner specified inline.
|
|
|
|
if (m_options.m_use_one_liner)
|
|
|
|
SetBreakpointCommandCallback(m_bp_options_vec,
|
|
|
|
m_options.m_one_liner.c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2012-06-09 05:56:10 +08:00
|
|
|
CollectDataForBreakpointCommandCallback(m_bp_options_vec, result);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
private:
|
|
|
|
CommandOptions m_options;
|
2019-10-26 05:05:07 +08:00
|
|
|
OptionGroupPythonClassWithDict m_func_options;
|
|
|
|
OptionGroupOptions m_all_options;
|
|
|
|
|
2014-08-30 01:34:17 +08:00
|
|
|
std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the
|
|
|
|
// breakpoint options that
|
|
|
|
// we are currently
|
2018-05-01 00:49:04 +08:00
|
|
|
// collecting commands for. In the CollectData... calls we need to hand this
|
|
|
|
// off to the IOHandler, which may run asynchronously. So we have to have
|
|
|
|
// some way to keep it alive, and not leak it. Making it an ivar of the
|
|
|
|
// command object, which never goes away achieves this. Note that if we were
|
|
|
|
// able to run the same command concurrently in one interpreter we'd have to
|
|
|
|
// make this "per invocation". But there are many more reasons why it is not
|
|
|
|
// in general safe to do that in lldb at present, so it isn't worthwhile to
|
|
|
|
// come up with a more complex mechanism to address this particular weakness
|
|
|
|
// right now.
|
2012-06-09 05:56:10 +08:00
|
|
|
static const char *g_reader_instructions;
|
|
|
|
};
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
const char *CommandObjectBreakpointCommandAdd::g_reader_instructions =
|
|
|
|
"Enter your debugger command(s). Type 'DONE' to end.\n";
|
2012-06-09 05:56:10 +08:00
|
|
|
|
2011-05-22 15:14:46 +08:00
|
|
|
// CommandObjectBreakpointCommandDelete
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-07-22 18:02:09 +08:00
|
|
|
#define LLDB_OPTIONS_breakpoint_command_delete
|
|
|
|
#include "CommandOptions.inc"
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectBreakpointCommandDelete : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
CommandObjectBreakpointCommandDelete(CommandInterpreter &interpreter)
|
2016-02-20 03:33:46 +08:00
|
|
|
: CommandObjectParsed(interpreter, "delete",
|
|
|
|
"Delete the set of commands from a breakpoint.",
|
|
|
|
nullptr),
|
2016-08-12 07:51:28 +08:00
|
|
|
m_options() {
|
2012-06-09 05:56:10 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData bp_id_arg;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
|
|
|
bp_id_arg.arg_repetition = eArgRepeatPlain;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg.push_back(bp_id_arg);
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-02-20 03:33:46 +08:00
|
|
|
~CommandObjectBreakpointCommandDelete() override = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-10-08 00:56:17 +08:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2014-12-06 09:28:03 +08:00
|
|
|
|
|
|
|
class CommandOptions : public Options {
|
|
|
|
public:
|
2016-08-12 07:51:28 +08:00
|
|
|
CommandOptions() : Options(), m_use_dummy(false) {}
|
2014-12-06 09:28:03 +08:00
|
|
|
|
2016-02-20 03:33:46 +08:00
|
|
|
~CommandOptions() override = default;
|
2014-12-06 09:28:03 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2014-12-06 09:28:03 +08:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
|
|
|
|
|
|
|
switch (short_option) {
|
|
|
|
case 'D':
|
|
|
|
m_use_dummy = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2014-12-06 09:28:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2014-12-06 09:28:03 +08:00
|
|
|
m_use_dummy = false;
|
|
|
|
}
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2019-07-28 14:24:07 +08:00
|
|
|
return llvm::makeArrayRef(g_breakpoint_command_delete_options);
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
}
|
2014-12-06 09:28:03 +08:00
|
|
|
|
|
|
|
// Instance variables to hold the values for command options.
|
|
|
|
bool m_use_dummy;
|
|
|
|
};
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2019-08-27 02:12:44 +08:00
|
|
|
Target &target = GetSelectedOrDummyTarget(m_options.m_use_dummy);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-08-27 02:12:44 +08:00
|
|
|
const BreakpointList &breakpoints = target.GetBreakpointList();
|
2012-06-09 05:56:10 +08:00
|
|
|
size_t num_breakpoints = breakpoints.GetSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
if (num_breakpoints == 0) {
|
|
|
|
result.AppendError("No breakpoints exist to have commands deleted");
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-10-06 04:03:37 +08:00
|
|
|
if (command.empty()) {
|
2012-06-09 05:56:10 +08:00
|
|
|
result.AppendError(
|
|
|
|
"No breakpoint specified from which to delete the commands");
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
BreakpointIDList valid_bp_ids;
|
2014-12-17 07:40:14 +08:00
|
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
|
2019-08-27 02:12:44 +08:00
|
|
|
command, &target, result, &valid_bp_ids,
|
2017-09-15 04:22:49 +08:00
|
|
|
BreakpointName::Permissions::PermissionKinds::listPerm);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
if (result.Succeeded()) {
|
|
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
|
|
for (size_t i = 0; i < count; ++i) {
|
|
|
|
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
|
|
|
|
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
|
|
|
|
Breakpoint *bp =
|
2019-08-27 02:12:44 +08:00
|
|
|
target.GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
|
2012-06-09 05:56:10 +08:00
|
|
|
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
|
|
|
|
BreakpointLocationSP bp_loc_sp(
|
|
|
|
bp->FindLocationByID(cur_bp_id.GetLocationID()));
|
|
|
|
if (bp_loc_sp)
|
|
|
|
bp_loc_sp->ClearCallback();
|
|
|
|
else {
|
|
|
|
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
|
|
|
|
cur_bp_id.GetBreakpointID(),
|
|
|
|
cur_bp_id.GetLocationID());
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-06-09 05:56:10 +08:00
|
|
|
bp->ClearCallback();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-20 03:33:46 +08:00
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
private:
|
|
|
|
CommandOptions m_options;
|
|
|
|
};
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// CommandObjectBreakpointCommandList
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectBreakpointCommandList : public CommandObjectParsed {
|
|
|
|
public:
|
|
|
|
CommandObjectBreakpointCommandList(CommandInterpreter &interpreter)
|
2019-08-31 17:41:25 +08:00
|
|
|
: CommandObjectParsed(interpreter, "list",
|
|
|
|
"List the script or set of commands to be "
|
|
|
|
"executed when the breakpoint is hit.",
|
|
|
|
nullptr, eCommandRequiresTarget) {
|
2012-06-09 05:56:10 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData bp_id_arg;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
|
|
|
bp_id_arg.arg_repetition = eArgRepeatPlain;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// There is only one variant this argument could be; put it into the
|
|
|
|
// argument entry.
|
|
|
|
arg.push_back(bp_id_arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 03:33:46 +08:00
|
|
|
~CommandObjectBreakpointCommandList() override = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-10-08 00:56:17 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
2019-08-31 17:41:25 +08:00
|
|
|
Target *target = &GetSelectedTarget();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
const BreakpointList &breakpoints = target->GetBreakpointList();
|
|
|
|
size_t num_breakpoints = breakpoints.GetSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
if (num_breakpoints == 0) {
|
|
|
|
result.AppendError("No breakpoints exist for which to list commands");
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-10-06 04:03:37 +08:00
|
|
|
if (command.empty()) {
|
2012-06-09 05:56:10 +08:00
|
|
|
result.AppendError(
|
|
|
|
"No breakpoint specified for which to list the commands");
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
BreakpointIDList valid_bp_ids;
|
2014-12-17 07:40:14 +08:00
|
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointOrLocationIDs(
|
2019-08-02 08:18:44 +08:00
|
|
|
command, target, result, &valid_bp_ids,
|
2017-09-15 04:22:49 +08:00
|
|
|
BreakpointName::Permissions::PermissionKinds::listPerm);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
if (result.Succeeded()) {
|
|
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
|
|
for (size_t i = 0; i < count; ++i) {
|
|
|
|
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex(i);
|
|
|
|
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID) {
|
|
|
|
Breakpoint *bp =
|
|
|
|
target->GetBreakpointByID(cur_bp_id.GetBreakpointID()).get();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
if (bp) {
|
2017-08-02 08:16:10 +08:00
|
|
|
BreakpointLocationSP bp_loc_sp;
|
2012-06-09 05:56:10 +08:00
|
|
|
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
|
2019-10-31 06:26:19 +08:00
|
|
|
bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID());
|
|
|
|
if (!bp_loc_sp) {
|
2012-06-09 05:56:10 +08:00
|
|
|
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
|
|
|
|
cur_bp_id.GetBreakpointID(),
|
|
|
|
cur_bp_id.GetLocationID());
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-08-02 08:16:10 +08:00
|
|
|
StreamString id_str;
|
|
|
|
BreakpointID::GetCanonicalReference(&id_str,
|
|
|
|
cur_bp_id.GetBreakpointID(),
|
|
|
|
cur_bp_id.GetLocationID());
|
|
|
|
const Baton *baton = nullptr;
|
|
|
|
if (bp_loc_sp)
|
2019-10-31 06:26:19 +08:00
|
|
|
baton =
|
|
|
|
bp_loc_sp
|
|
|
|
->GetOptionsSpecifyingKind(BreakpointOptions::eCallback)
|
|
|
|
->GetBaton();
|
2017-08-02 08:16:10 +08:00
|
|
|
else
|
|
|
|
baton = bp->GetOptions()->GetBaton();
|
|
|
|
|
|
|
|
if (baton) {
|
|
|
|
result.GetOutputStream().Printf("Breakpoint %s:\n",
|
|
|
|
id_str.GetData());
|
2019-11-30 22:30:08 +08:00
|
|
|
baton->GetDescription(result.GetOutputStream().AsRawOstream(),
|
|
|
|
eDescriptionLevelFull,
|
|
|
|
result.GetOutputStream().GetIndentLevel() +
|
|
|
|
2);
|
2017-08-02 08:16:10 +08:00
|
|
|
} else {
|
|
|
|
result.AppendMessageWithFormat(
|
|
|
|
"Breakpoint %s does not have an associated command.\n",
|
|
|
|
id_str.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-02 08:16:10 +08:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
} else {
|
|
|
|
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n",
|
|
|
|
cur_bp_id.GetBreakpointID());
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
return result.Succeeded();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-06-09 05:56:10 +08:00
|
|
|
};
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// CommandObjectBreakpointCommand
|
|
|
|
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectBreakpointCommand::CommandObjectBreakpointCommand(
|
|
|
|
CommandInterpreter &interpreter)
|
|
|
|
: CommandObjectMultiword(
|
2019-10-31 06:26:19 +08:00
|
|
|
interpreter, "command",
|
|
|
|
"Commands for adding, removing and listing "
|
|
|
|
"LLDB commands executed when a breakpoint is "
|
|
|
|
"hit.",
|
2016-07-15 06:03:10 +08:00
|
|
|
"command <sub-command> [<sub-command-options>] <breakpoint-id>") {
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectSP add_command_object(
|
|
|
|
new CommandObjectBreakpointCommandAdd(interpreter));
|
2011-05-22 15:14:46 +08:00
|
|
|
CommandObjectSP delete_command_object(
|
|
|
|
new CommandObjectBreakpointCommandDelete(interpreter));
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectSP list_command_object(
|
|
|
|
new CommandObjectBreakpointCommandList(interpreter));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
add_command_object->SetCommandName("breakpoint command add");
|
2011-05-22 15:14:46 +08:00
|
|
|
delete_command_object->SetCommandName("breakpoint command delete");
|
2010-06-09 00:52:24 +08:00
|
|
|
list_command_object->SetCommandName("breakpoint command list");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-07-17 11:23:13 +08:00
|
|
|
LoadSubCommand("add", add_command_object);
|
|
|
|
LoadSubCommand("delete", delete_command_object);
|
|
|
|
LoadSubCommand("list", list_command_object);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 03:33:46 +08:00
|
|
|
CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand() = default;
|