101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//===-- CommandObjectWatchpoint.cpp -----------------------------*- C++ -*-===//
201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//
301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//                     The LLVM Compiler Infrastructure
401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//
501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// This file is distributed under the University of Illinois Open Source
601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// License. See LICENSE.TXT for details.
701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//
801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//===----------------------------------------------------------------------===//
901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
10d891f9b872103235cfd2ed452c6f14a4394d9b3aDaniel Malea#include "lldb/lldb-python.h"
11d891f9b872103235cfd2ed452c6f14a4394d9b3aDaniel Malea
1201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include "CommandObjectWatchpoint.h"
13f3ec4617297810223deb545cb68214ca4dd8009cJohnny Chen#include "CommandObjectWatchpointCommand.h"
1401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
1501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// C Includes
1601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// C++ Includes
1701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// Other libraries and framework includes
1801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// Project includes
19ecd4feb5111432d2878e95461220c720cb2d24c8Johnny Chen#include "lldb/Breakpoint/Watchpoint.h"
20ecd4feb5111432d2878e95461220c720cb2d24c8Johnny Chen#include "lldb/Breakpoint/WatchpointList.h"
2101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include "lldb/Core/StreamString.h"
2255a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen#include "lldb/Core/ValueObject.h"
2355a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen#include "lldb/Core/ValueObjectVariable.h"
2401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include "lldb/Interpreter/CommandInterpreter.h"
2501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include "lldb/Interpreter/CommandReturnObject.h"
2601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include "lldb/Interpreter/CommandCompletions.h"
2755a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen#include "lldb/Symbol/Variable.h"
2855a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen#include "lldb/Symbol/VariableList.h"
2955a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen#include "lldb/Target/Target.h"
3001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
3101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include <vector>
3201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
3301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chenusing namespace lldb;
3401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chenusing namespace lldb_private;
3501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
3601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chenstatic void
37ecd4feb5111432d2878e95461220c720cb2d24c8Johnny ChenAddWatchpointDescription(Stream *s, Watchpoint *wp, lldb::DescriptionLevel level)
3801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
3901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    s->IndentMore();
40ecd4feb5111432d2878e95461220c720cb2d24c8Johnny Chen    wp->GetDescription(s, level);
4101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    s->IndentLess();
4201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    s->EOL();
4301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen}
4401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
4501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chenstatic bool
4601acfa76010b8db2e77016c144963c4dd70f1392Johnny ChenCheckTargetForWatchpointOperations(Target *target, CommandReturnObject &result)
4701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
4801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    if (target == NULL)
4901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    {
5001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        result.AppendError ("Invalid target.  No existing target or watchpoints.");
5101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        result.SetStatus (eReturnStatusFailed);
5201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        return false;
5301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
5401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    bool process_is_valid = target->GetProcessSP() && target->GetProcessSP()->IsAlive();
5501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    if (!process_is_valid)
5601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    {
5701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        result.AppendError ("Thre's no process or it is not alive.");
5801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        result.SetStatus (eReturnStatusFailed);
5901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        return false;
6001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
6101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // Target passes our checks, return true.
6201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    return true;
6301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen}
6401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
65da26bd203cbb104291b39891febf7481794f205fJim Ingham// FIXME: This doesn't seem to be the right place for this functionality.
6601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#include "llvm/ADT/StringRef.h"
67da26bd203cbb104291b39891febf7481794f205fJim Inghamstatic inline void StripLeadingSpaces(llvm::StringRef &Str)
68da26bd203cbb104291b39891febf7481794f205fJim Ingham{
69da26bd203cbb104291b39891febf7481794f205fJim Ingham    while (!Str.empty() && isspace(Str[0]))
70da26bd203cbb104291b39891febf7481794f205fJim Ingham        Str = Str.substr(1);
71da26bd203cbb104291b39891febf7481794f205fJim Ingham}
7201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
7301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// Equivalent class: {"-", "to", "To", "TO"} of range specifier array.
7401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chenstatic const char* RSA[4] = { "-", "to", "To", "TO" };
7501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
7601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// Return the index to RSA if found; otherwise -1 is returned.
7701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chenstatic int32_t
7801acfa76010b8db2e77016c144963c4dd70f1392Johnny ChenWithRSAIndex(llvm::StringRef &Arg)
7901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
8001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
8101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    uint32_t i;
8201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    for (i = 0; i < 4; ++i)
8301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if (Arg.find(RSA[i]) != llvm::StringRef::npos)
8401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            return i;
8501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    return -1;
8601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen}
8701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
8801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// Return true if wp_ids is successfully populated with the watch ids.
8901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// False otherwise.
901032089fb6aa3be226d204df5db6306e119d8fb8Johnny Chenbool
91bf1bec6263157c86b5df7d6b19090571ed7885a3Jim InghamCommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(Target *target, Args &args, std::vector<uint32_t> &wp_ids)
9201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
9301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // Pre-condition: args.GetArgumentCount() > 0.
94bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham    if (args.GetArgumentCount() == 0)
95bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham    {
96bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham        if (target == NULL)
97bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            return false;
98bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham        WatchpointSP watch_sp = target->GetLastCreatedWatchpoint();
99bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham        if (watch_sp)
100bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham        {
101bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            wp_ids.push_back(watch_sp->GetID());
102bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            return true;
103bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham        }
104bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham        else
105bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            return false;
106bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham    }
10701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
10801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    llvm::StringRef Minus("-");
10901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    std::vector<llvm::StringRef> StrRefArgs;
11001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    std::pair<llvm::StringRef, llvm::StringRef> Pair;
11101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    size_t i;
11201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    int32_t idx;
11301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // Go through the argments and make a canonical form of arg list containing
11401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // only numbers with possible "-" in between.
11501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    for (i = 0; i < args.GetArgumentCount(); ++i) {
11601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        llvm::StringRef Arg(args.GetArgumentAtIndex(i));
11701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if ((idx = WithRSAIndex(Arg)) == -1) {
11801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            StrRefArgs.push_back(Arg);
11901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            continue;
12001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
12101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        // The Arg contains the range specifier, split it, then.
12201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        Pair = Arg.split(RSA[idx]);
12301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if (!Pair.first.empty())
12401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            StrRefArgs.push_back(Pair.first);
12501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        StrRefArgs.push_back(Minus);
12601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if (!Pair.second.empty())
12701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            StrRefArgs.push_back(Pair.second);
12801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
12901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // Now process the canonical list and fill in the vector of uint32_t's.
13001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // If there is any error, return false and the client should ignore wp_ids.
13101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    uint32_t beg, end, id;
13201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    size_t size = StrRefArgs.size();
13301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    bool in_range = false;
13401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    for (i = 0; i < size; ++i) {
13501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        llvm::StringRef Arg = StrRefArgs[i];
13601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if (in_range) {
13701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            // Look for the 'end' of the range.  Note StringRef::getAsInteger()
13801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            // returns true to signify error while parsing.
13901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            if (Arg.getAsInteger(0, end))
14001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen                return false;
14101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            // Found a range!  Now append the elements.
14201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            for (id = beg; id <= end; ++id)
14301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen                wp_ids.push_back(id);
14401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            in_range = false;
14501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            continue;
14601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
14701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if (i < (size - 1) && StrRefArgs[i+1] == Minus) {
14801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            if (Arg.getAsInteger(0, beg))
14901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen                return false;
15001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            // Turn on the in_range flag, we are looking for end of range next.
15101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            ++i; in_range = true;
15201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            continue;
15301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
15401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        // Otherwise, we have a simple ID.  Just append it.
15501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        if (Arg.getAsInteger(0, beg))
15601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            return false;
15701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        wp_ids.push_back(beg);
15801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
15901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    // It is an error if after the loop, we're still in_range.
16001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    if (in_range)
16101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        return false;
16201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
16301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    return true; // Success!
16401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen}
16501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
16601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
167da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectWatchpointList
16801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
169da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark List
17001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
171da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointList : public CommandObjectParsed
17201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
173da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
174da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointList (CommandInterpreter &interpreter) :
175da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed (interpreter,
176da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "watchpoint list",
177da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "List all watchpoints at configurable levels of detail.",
178da26bd203cbb104291b39891febf7481794f205fJim Ingham                             NULL),
179da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_options(interpreter)
180da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
181da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
182da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
183da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Add the entry for the first argument for this command to the object's arguments vector.
184da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back(arg);
185da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
18601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
187da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
188da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointList () {}
18901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
190da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual Options *
191da26bd203cbb104291b39891febf7481794f205fJim Ingham    GetOptions ()
192da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
193da26bd203cbb104291b39891febf7481794f205fJim Ingham        return &m_options;
194da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
19501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
196da26bd203cbb104291b39891febf7481794f205fJim Ingham    class CommandOptions : public Options
197da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
198da26bd203cbb104291b39891febf7481794f205fJim Ingham    public:
19901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
200da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandOptions (CommandInterpreter &interpreter) :
201da26bd203cbb104291b39891febf7481794f205fJim Ingham            Options(interpreter),
202da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_level(lldb::eDescriptionLevelBrief) // Watchpoint List defaults to brief descriptions
203da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
204da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
20501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
206da26bd203cbb104291b39891febf7481794f205fJim Ingham        virtual
207da26bd203cbb104291b39891febf7481794f205fJim Ingham        ~CommandOptions () {}
20801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
209da26bd203cbb104291b39891febf7481794f205fJim Ingham        virtual Error
210da26bd203cbb104291b39891febf7481794f205fJim Ingham        SetOptionValue (uint32_t option_idx, const char *option_arg)
211da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
212da26bd203cbb104291b39891febf7481794f205fJim Ingham            Error error;
2136475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton            const int short_option = m_getopt_table[option_idx].val;
21401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
215da26bd203cbb104291b39891febf7481794f205fJim Ingham            switch (short_option)
216da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
217da26bd203cbb104291b39891febf7481794f205fJim Ingham                case 'b':
218da26bd203cbb104291b39891febf7481794f205fJim Ingham                    m_level = lldb::eDescriptionLevelBrief;
219da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
220da26bd203cbb104291b39891febf7481794f205fJim Ingham                case 'f':
221da26bd203cbb104291b39891febf7481794f205fJim Ingham                    m_level = lldb::eDescriptionLevelFull;
222da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
223da26bd203cbb104291b39891febf7481794f205fJim Ingham                case 'v':
224da26bd203cbb104291b39891febf7481794f205fJim Ingham                    m_level = lldb::eDescriptionLevelVerbose;
225da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
226da26bd203cbb104291b39891febf7481794f205fJim Ingham                default:
227da26bd203cbb104291b39891febf7481794f205fJim Ingham                    error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
228da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
229da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
23001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
231da26bd203cbb104291b39891febf7481794f205fJim Ingham            return error;
232da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
23301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
234da26bd203cbb104291b39891febf7481794f205fJim Ingham        void
235da26bd203cbb104291b39891febf7481794f205fJim Ingham        OptionParsingStarting ()
236da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
23701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            m_level = lldb::eDescriptionLevelFull;
238da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
23901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
240da26bd203cbb104291b39891febf7481794f205fJim Ingham        const OptionDefinition *
241da26bd203cbb104291b39891febf7481794f205fJim Ingham        GetDefinitions ()
242da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
243da26bd203cbb104291b39891febf7481794f205fJim Ingham            return g_option_table;
244da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
24501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
24601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
247da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Options table: Required for subclasses of Options.
24801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
249da26bd203cbb104291b39891febf7481794f205fJim Ingham        static OptionDefinition g_option_table[];
25001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
251da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Instance variables to hold the values for command options.
25201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
253da26bd203cbb104291b39891febf7481794f205fJim Ingham        lldb::DescriptionLevel m_level;
254da26bd203cbb104291b39891febf7481794f205fJim Ingham    };
25501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
256da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
257da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
258da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (Args& command, CommandReturnObject &result)
2597cbdcfb0cefcfd877b507ff2d83e51a1bde3fcc7Johnny Chen    {
260da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
261da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (target == NULL)
262da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
263da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendError ("Invalid target. No current target or watchpoints.");
264da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
265da26bd203cbb104291b39891febf7481794f205fJim Ingham            return true;
266da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
26701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
268da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (target->GetProcessSP() && target->GetProcessSP()->IsAlive())
269da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
270da26bd203cbb104291b39891febf7481794f205fJim Ingham            uint32_t num_supported_hardware_watchpoints;
271da26bd203cbb104291b39891febf7481794f205fJim Ingham            Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
272da26bd203cbb104291b39891febf7481794f205fJim Ingham            if (error.Success())
273da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n",
274da26bd203cbb104291b39891febf7481794f205fJim Ingham                                               num_supported_hardware_watchpoints);
275da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
27601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
277da26bd203cbb104291b39891febf7481794f205fJim Ingham        const WatchpointList &watchpoints = target->GetWatchpointList();
278da26bd203cbb104291b39891febf7481794f205fJim Ingham        Mutex::Locker locker;
279da26bd203cbb104291b39891febf7481794f205fJim Ingham        target->GetWatchpointList().GetListMutex(locker);
28001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
281da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t num_watchpoints = watchpoints.GetSize();
28201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
283da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (num_watchpoints == 0)
28401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
285da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessage("No watchpoints currently set.");
286da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusSuccessFinishNoResult);
287da26bd203cbb104291b39891febf7481794f205fJim Ingham            return true;
28801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
28901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
290da26bd203cbb104291b39891febf7481794f205fJim Ingham        Stream &output_stream = result.GetOutputStream();
291da26bd203cbb104291b39891febf7481794f205fJim Ingham
292da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() == 0)
29301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
294da26bd203cbb104291b39891febf7481794f205fJim Ingham            // No watchpoint selected; show info about all currently set watchpoints.
295da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessage ("Current watchpoints:");
296da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < num_watchpoints; ++i)
297da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
298da26bd203cbb104291b39891febf7481794f205fJim Ingham                Watchpoint *wp = watchpoints.GetByIndex(i).get();
299ecd4feb5111432d2878e95461220c720cb2d24c8Johnny Chen                AddWatchpointDescription(&output_stream, wp, m_options.m_level);
300da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
30101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            result.SetStatus(eReturnStatusSuccessFinishNoResult);
30201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
303da26bd203cbb104291b39891febf7481794f205fJim Ingham        else
304da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
305da26bd203cbb104291b39891febf7481794f205fJim Ingham            // Particular watchpoints selected; enable them.
306da26bd203cbb104291b39891febf7481794f205fJim Ingham            std::vector<uint32_t> wp_ids;
307bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
308da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
309da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Invalid watchpoints specification.");
310da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
311da26bd203cbb104291b39891febf7481794f205fJim Ingham                return false;
312da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
313da26bd203cbb104291b39891febf7481794f205fJim Ingham
314da26bd203cbb104291b39891febf7481794f205fJim Ingham            const size_t size = wp_ids.size();
315da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < size; ++i)
316da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
317da26bd203cbb104291b39891febf7481794f205fJim Ingham                Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get();
318da26bd203cbb104291b39891febf7481794f205fJim Ingham                if (wp)
319da26bd203cbb104291b39891febf7481794f205fJim Ingham                    AddWatchpointDescription(&output_stream, wp, m_options.m_level);
320da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusSuccessFinishNoResult);
321da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
322da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
323da26bd203cbb104291b39891febf7481794f205fJim Ingham
324da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
32501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
32601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
327da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate:
328da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandOptions m_options;
329da26bd203cbb104291b39891febf7481794f205fJim Ingham};
33001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
33101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
332da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectWatchpointList::Options
33301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
334da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark List::CommandOptions
335da26bd203cbb104291b39891febf7481794f205fJim InghamOptionDefinition
336da26bd203cbb104291b39891febf7481794f205fJim InghamCommandObjectWatchpointList::CommandOptions::g_option_table[] =
33701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
338da26bd203cbb104291b39891febf7481794f205fJim Ingham    { LLDB_OPT_SET_1, false, "brief",    'b', no_argument, NULL, 0, eArgTypeNone,
339da26bd203cbb104291b39891febf7481794f205fJim Ingham        "Give a brief description of the watchpoint (no location info)."},
34001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
341da26bd203cbb104291b39891febf7481794f205fJim Ingham    { LLDB_OPT_SET_2, false, "full",    'f', no_argument, NULL, 0, eArgTypeNone,
342da26bd203cbb104291b39891febf7481794f205fJim Ingham        "Give a full description of the watchpoint and its locations."},
34301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
344da26bd203cbb104291b39891febf7481794f205fJim Ingham    { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone,
345da26bd203cbb104291b39891febf7481794f205fJim Ingham        "Explain everything we know about the watchpoint (for debugging debugger bugs)." },
34601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
347da26bd203cbb104291b39891febf7481794f205fJim Ingham    { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
348da26bd203cbb104291b39891febf7481794f205fJim Ingham};
34901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
350da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
351da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectWatchpointEnable
352da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
353da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark Enable
35401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
355da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointEnable : public CommandObjectParsed
356da26bd203cbb104291b39891febf7481794f205fJim Ingham{
357da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
358da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointEnable (CommandInterpreter &interpreter) :
359da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed (interpreter,
360da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "enable",
361da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Enable the specified disabled watchpoint(s). If no watchpoints are specified, enable all of them.",
362da26bd203cbb104291b39891febf7481794f205fJim Ingham                             NULL)
36301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    {
364da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
365da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
366da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Add the entry for the first argument for this command to the object's arguments vector.
367da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back(arg);
36801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
36901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
370da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
371da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointEnable () {}
372da26bd203cbb104291b39891febf7481794f205fJim Ingham
373da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
374da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
375da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (Args& command,
376da26bd203cbb104291b39891febf7481794f205fJim Ingham             CommandReturnObject &result)
37701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    {
378da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
379da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (!CheckTargetForWatchpointOperations(target, result))
380da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
381da26bd203cbb104291b39891febf7481794f205fJim Ingham
382da26bd203cbb104291b39891febf7481794f205fJim Ingham        Mutex::Locker locker;
383da26bd203cbb104291b39891febf7481794f205fJim Ingham        target->GetWatchpointList().GetListMutex(locker);
384da26bd203cbb104291b39891febf7481794f205fJim Ingham
385da26bd203cbb104291b39891febf7481794f205fJim Ingham        const WatchpointList &watchpoints = target->GetWatchpointList();
386da26bd203cbb104291b39891febf7481794f205fJim Ingham
387da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t num_watchpoints = watchpoints.GetSize();
388da26bd203cbb104291b39891febf7481794f205fJim Ingham
389da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (num_watchpoints == 0)
39001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
391da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendError("No watchpoints exist to be enabled.");
39201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            result.SetStatus(eReturnStatusFailed);
39301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen            return false;
39401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
39501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
396da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() == 0)
397da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
398da26bd203cbb104291b39891febf7481794f205fJim Ingham            // No watchpoint selected; enable all currently set watchpoints.
399da26bd203cbb104291b39891febf7481794f205fJim Ingham            target->EnableAllWatchpoints();
400da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("All watchpoints enabled. (%lu watchpoints)\n", num_watchpoints);
401da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusSuccessFinishNoResult);
402da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
403da26bd203cbb104291b39891febf7481794f205fJim Ingham        else
404da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
405da26bd203cbb104291b39891febf7481794f205fJim Ingham            // Particular watchpoints selected; enable them.
406da26bd203cbb104291b39891febf7481794f205fJim Ingham            std::vector<uint32_t> wp_ids;
407bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
408da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
409da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Invalid watchpoints specification.");
410da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
411da26bd203cbb104291b39891febf7481794f205fJim Ingham                return false;
412da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
413da26bd203cbb104291b39891febf7481794f205fJim Ingham
414da26bd203cbb104291b39891febf7481794f205fJim Ingham            int count = 0;
415da26bd203cbb104291b39891febf7481794f205fJim Ingham            const size_t size = wp_ids.size();
416da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < size; ++i)
417da26bd203cbb104291b39891febf7481794f205fJim Ingham                if (target->EnableWatchpointByID(wp_ids[i]))
418da26bd203cbb104291b39891febf7481794f205fJim Ingham                    ++count;
419da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("%d watchpoints enabled.\n", count);
420da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusSuccessFinishNoResult);
421da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
422da26bd203cbb104291b39891febf7481794f205fJim Ingham
423da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
42401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
42501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
426da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate:
427da26bd203cbb104291b39891febf7481794f205fJim Ingham};
42801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
42901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
43001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// CommandObjectWatchpointDisable
43101acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
43201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#pragma mark Disable
43301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
434da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointDisable : public CommandObjectParsed
43501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
436da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
437da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointDisable (CommandInterpreter &interpreter) :
438da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed (interpreter,
439da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "watchpoint disable",
440da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Disable the specified watchpoint(s) without removing it/them.  If no watchpoints are specified, disable them all.",
441da26bd203cbb104291b39891febf7481794f205fJim Ingham                             NULL)
442da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
443da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
444da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
445da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Add the entry for the first argument for this command to the object's arguments vector.
446da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back(arg);
447da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
44801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
44901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
450da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
451da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointDisable () {}
45201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
453da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
454da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
455da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (Args& command, CommandReturnObject &result)
456da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
457da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
458da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (!CheckTargetForWatchpointOperations(target, result))
459da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
46001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
461da26bd203cbb104291b39891febf7481794f205fJim Ingham        Mutex::Locker locker;
462da26bd203cbb104291b39891febf7481794f205fJim Ingham        target->GetWatchpointList().GetListMutex(locker);
46301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
464da26bd203cbb104291b39891febf7481794f205fJim Ingham        const WatchpointList &watchpoints = target->GetWatchpointList();
465da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t num_watchpoints = watchpoints.GetSize();
46601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
467da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (num_watchpoints == 0)
46801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
469da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendError("No watchpoints exist to be disabled.");
470da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
471da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
47201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
473da26bd203cbb104291b39891febf7481794f205fJim Ingham
474da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() == 0)
47501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
476da26bd203cbb104291b39891febf7481794f205fJim Ingham            // No watchpoint selected; disable all currently set watchpoints.
477da26bd203cbb104291b39891febf7481794f205fJim Ingham            if (target->DisableAllWatchpoints())
478da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
479da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendMessageWithFormat("All watchpoints disabled. (%lu watchpoints)\n", num_watchpoints);
480da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusSuccessFinishNoResult);
481da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
482da26bd203cbb104291b39891febf7481794f205fJim Ingham            else
483da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
484da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Disable all watchpoints failed\n");
485da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
486da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
48701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
488da26bd203cbb104291b39891febf7481794f205fJim Ingham        else
48901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
490da26bd203cbb104291b39891febf7481794f205fJim Ingham            // Particular watchpoints selected; disable them.
491da26bd203cbb104291b39891febf7481794f205fJim Ingham            std::vector<uint32_t> wp_ids;
492bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
493da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
494da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Invalid watchpoints specification.");
495da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
496da26bd203cbb104291b39891febf7481794f205fJim Ingham                return false;
497da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
498da26bd203cbb104291b39891febf7481794f205fJim Ingham
499da26bd203cbb104291b39891febf7481794f205fJim Ingham            int count = 0;
500da26bd203cbb104291b39891febf7481794f205fJim Ingham            const size_t size = wp_ids.size();
501da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < size; ++i)
502da26bd203cbb104291b39891febf7481794f205fJim Ingham                if (target->DisableWatchpointByID(wp_ids[i]))
503da26bd203cbb104291b39891febf7481794f205fJim Ingham                    ++count;
504da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("%d watchpoints disabled.\n", count);
505da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusSuccessFinishNoResult);
50601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
50701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
508da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
50901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
51001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
511da26bd203cbb104291b39891febf7481794f205fJim Ingham};
51201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
51301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
51401acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen// CommandObjectWatchpointDelete
51501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen//-------------------------------------------------------------------------
51601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen#pragma mark Delete
51701acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
518da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointDelete : public CommandObjectParsed
51901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen{
520da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
521da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointDelete (CommandInterpreter &interpreter) :
522da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed(interpreter,
523da26bd203cbb104291b39891febf7481794f205fJim Ingham                            "watchpoint delete",
524da26bd203cbb104291b39891febf7481794f205fJim Ingham                            "Delete the specified watchpoint(s).  If no watchpoints are specified, delete them all.",
525da26bd203cbb104291b39891febf7481794f205fJim Ingham                            NULL)
526da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
527da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
528da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
529da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Add the entry for the first argument for this command to the object's arguments vector.
530da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back(arg);
531da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
53201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
533da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
534da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointDelete () {}
53501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
536da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
537da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
538da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (Args& command, CommandReturnObject &result)
539da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
540da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
541da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (!CheckTargetForWatchpointOperations(target, result))
542da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
54301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
544da26bd203cbb104291b39891febf7481794f205fJim Ingham        Mutex::Locker locker;
545da26bd203cbb104291b39891febf7481794f205fJim Ingham        target->GetWatchpointList().GetListMutex(locker);
546da26bd203cbb104291b39891febf7481794f205fJim Ingham
547da26bd203cbb104291b39891febf7481794f205fJim Ingham        const WatchpointList &watchpoints = target->GetWatchpointList();
54801acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
549da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t num_watchpoints = watchpoints.GetSize();
55001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
551da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (num_watchpoints == 0)
55201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
553da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendError("No watchpoints exist to be deleted.");
554da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
555da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
55601acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
557da26bd203cbb104291b39891febf7481794f205fJim Ingham
558da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() == 0)
55901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
560da26bd203cbb104291b39891febf7481794f205fJim Ingham            if (!m_interpreter.Confirm("About to delete all watchpoints, do you want to do that?", true))
561da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
562da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendMessage("Operation cancelled...");
563da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
564da26bd203cbb104291b39891febf7481794f205fJim Ingham            else
565da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
566da26bd203cbb104291b39891febf7481794f205fJim Ingham                target->RemoveAllWatchpoints();
567da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendMessageWithFormat("All watchpoints removed. (%lu watchpoints)\n", num_watchpoints);
568da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
569da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
570da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
571da26bd203cbb104291b39891febf7481794f205fJim Ingham        else
57201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        {
573da26bd203cbb104291b39891febf7481794f205fJim Ingham            // Particular watchpoints selected; delete them.
574da26bd203cbb104291b39891febf7481794f205fJim Ingham            std::vector<uint32_t> wp_ids;
575bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
576da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
577da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Invalid watchpoints specification.");
578da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
579da26bd203cbb104291b39891febf7481794f205fJim Ingham                return false;
580da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
581da26bd203cbb104291b39891febf7481794f205fJim Ingham
582da26bd203cbb104291b39891febf7481794f205fJim Ingham            int count = 0;
583da26bd203cbb104291b39891febf7481794f205fJim Ingham            const size_t size = wp_ids.size();
584da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < size; ++i)
585da26bd203cbb104291b39891febf7481794f205fJim Ingham                if (target->RemoveWatchpointByID(wp_ids[i]))
586da26bd203cbb104291b39891febf7481794f205fJim Ingham                    ++count;
587da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("%d watchpoints deleted.\n",count);
588da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
58901acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen        }
59001acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
591da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
59201acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen    }
59301acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
594da26bd203cbb104291b39891febf7481794f205fJim Ingham};
59501acfa76010b8db2e77016c144963c4dd70f1392Johnny Chen
596e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen//-------------------------------------------------------------------------
597da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectWatchpointIgnore
598e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen//-------------------------------------------------------------------------
599e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
600da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointIgnore : public CommandObjectParsed
601e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen{
602da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
603da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointIgnore (CommandInterpreter &interpreter) :
604da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed (interpreter,
605da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "watchpoint ignore",
606da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Set ignore count on the specified watchpoint(s).  If no watchpoints are specified, set them all.",
607da26bd203cbb104291b39891febf7481794f205fJim Ingham                             NULL),
608da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_options (interpreter)
609da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
610da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
611da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
612da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Add the entry for the first argument for this command to the object's arguments vector.
613da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back(arg);
614da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
615e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
616da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
617da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointIgnore () {}
618e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
619da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual Options *
620da26bd203cbb104291b39891febf7481794f205fJim Ingham    GetOptions ()
621da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
622da26bd203cbb104291b39891febf7481794f205fJim Ingham        return &m_options;
623da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
624e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
625da26bd203cbb104291b39891febf7481794f205fJim Ingham    class CommandOptions : public Options
626e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen    {
627da26bd203cbb104291b39891febf7481794f205fJim Ingham    public:
628da26bd203cbb104291b39891febf7481794f205fJim Ingham
629da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandOptions (CommandInterpreter &interpreter) :
630da26bd203cbb104291b39891febf7481794f205fJim Ingham            Options (interpreter),
631da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_ignore_count (0)
632e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen        {
633e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen        }
634e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
635da26bd203cbb104291b39891febf7481794f205fJim Ingham        virtual
636da26bd203cbb104291b39891febf7481794f205fJim Ingham        ~CommandOptions () {}
637e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
638da26bd203cbb104291b39891febf7481794f205fJim Ingham        virtual Error
639da26bd203cbb104291b39891febf7481794f205fJim Ingham        SetOptionValue (uint32_t option_idx, const char *option_arg)
640da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
641da26bd203cbb104291b39891febf7481794f205fJim Ingham            Error error;
6426475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton            const int short_option = m_getopt_table[option_idx].val;
643e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
644da26bd203cbb104291b39891febf7481794f205fJim Ingham            switch (short_option)
645da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
646da26bd203cbb104291b39891febf7481794f205fJim Ingham                case 'i':
647da26bd203cbb104291b39891febf7481794f205fJim Ingham                {
648da26bd203cbb104291b39891febf7481794f205fJim Ingham                    m_ignore_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0);
649da26bd203cbb104291b39891febf7481794f205fJim Ingham                    if (m_ignore_count == UINT32_MAX)
650da26bd203cbb104291b39891febf7481794f205fJim Ingham                       error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
651da26bd203cbb104291b39891febf7481794f205fJim Ingham                }
652da26bd203cbb104291b39891febf7481794f205fJim Ingham                break;
653da26bd203cbb104291b39891febf7481794f205fJim Ingham                default:
654da26bd203cbb104291b39891febf7481794f205fJim Ingham                    error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
655da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
656da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
657e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
658da26bd203cbb104291b39891febf7481794f205fJim Ingham            return error;
659da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
660e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
661da26bd203cbb104291b39891febf7481794f205fJim Ingham        void
662da26bd203cbb104291b39891febf7481794f205fJim Ingham        OptionParsingStarting ()
663da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
664da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_ignore_count = 0;
665da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
666e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
667da26bd203cbb104291b39891febf7481794f205fJim Ingham        const OptionDefinition *
668da26bd203cbb104291b39891febf7481794f205fJim Ingham        GetDefinitions ()
669da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
670da26bd203cbb104291b39891febf7481794f205fJim Ingham            return g_option_table;
671da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
672e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
673e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
674da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Options table: Required for subclasses of Options.
675e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
676da26bd203cbb104291b39891febf7481794f205fJim Ingham        static OptionDefinition g_option_table[];
677e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
678da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Instance variables to hold the values for command options.
679da26bd203cbb104291b39891febf7481794f205fJim Ingham
680da26bd203cbb104291b39891febf7481794f205fJim Ingham        uint32_t m_ignore_count;
681da26bd203cbb104291b39891febf7481794f205fJim Ingham    };
682da26bd203cbb104291b39891febf7481794f205fJim Ingham
683da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
684da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
685da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (Args& command,
686da26bd203cbb104291b39891febf7481794f205fJim Ingham             CommandReturnObject &result)
687e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen    {
688da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
689da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (!CheckTargetForWatchpointOperations(target, result))
690da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
691da26bd203cbb104291b39891febf7481794f205fJim Ingham
692da26bd203cbb104291b39891febf7481794f205fJim Ingham        Mutex::Locker locker;
693da26bd203cbb104291b39891febf7481794f205fJim Ingham        target->GetWatchpointList().GetListMutex(locker);
694da26bd203cbb104291b39891febf7481794f205fJim Ingham
695da26bd203cbb104291b39891febf7481794f205fJim Ingham        const WatchpointList &watchpoints = target->GetWatchpointList();
696da26bd203cbb104291b39891febf7481794f205fJim Ingham
697da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t num_watchpoints = watchpoints.GetSize();
698da26bd203cbb104291b39891febf7481794f205fJim Ingham
699da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (num_watchpoints == 0)
700e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen        {
701da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendError("No watchpoints exist to be ignored.");
702e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen            result.SetStatus(eReturnStatusFailed);
703e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen            return false;
704e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen        }
705e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
706da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() == 0)
707da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
708da26bd203cbb104291b39891febf7481794f205fJim Ingham            target->IgnoreAllWatchpoints(m_options.m_ignore_count);
709da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("All watchpoints ignored. (%lu watchpoints)\n", num_watchpoints);
710da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
711da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
712da26bd203cbb104291b39891febf7481794f205fJim Ingham        else
713da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
714da26bd203cbb104291b39891febf7481794f205fJim Ingham            // Particular watchpoints selected; ignore them.
715da26bd203cbb104291b39891febf7481794f205fJim Ingham            std::vector<uint32_t> wp_ids;
716bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
717da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
718da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Invalid watchpoints specification.");
719da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
720da26bd203cbb104291b39891febf7481794f205fJim Ingham                return false;
721da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
722e14cf4e7dc9d561224f744807b70a8ab91a8b36dJohnny Chen
723da26bd203cbb104291b39891febf7481794f205fJim Ingham            int count = 0;
724da26bd203cbb104291b39891febf7481794f205fJim Ingham            const size_t size = wp_ids.size();
725da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < size; ++i)
726da26bd203cbb104291b39891febf7481794f205fJim Ingham                if (target->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count))
727da26bd203cbb104291b39891febf7481794f205fJim Ingham                    ++count;
728da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("%d watchpoints ignored.\n",count);
729da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
730da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
731712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
732da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
733da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
734712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
735da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate:
736da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandOptions m_options;
737da26bd203cbb104291b39891febf7481794f205fJim Ingham};
738712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
739da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark Ignore::CommandOptions
740712a628dde2f4f786389feecf7e06e59f0853c75Johnny ChenOptionDefinition
741da26bd203cbb104291b39891febf7481794f205fJim InghamCommandObjectWatchpointIgnore::CommandOptions::g_option_table[] =
742712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen{
743560c51483461697b2f78c145d70d0cd285012c4dFilipe Cabecinhas    { LLDB_OPT_SET_ALL, true, "ignore-count", 'i', required_argument, NULL, 0, eArgTypeCount, "Set the number of times this watchpoint is skipped before stopping." },
744da26bd203cbb104291b39891febf7481794f205fJim Ingham    { 0,                false, NULL,            0 , 0,                 NULL, 0,    eArgTypeNone, NULL }
745712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen};
746712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
747712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
748da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
749da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectWatchpointModify
750da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
751da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark Modify
752da26bd203cbb104291b39891febf7481794f205fJim Ingham
753da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointModify : public CommandObjectParsed
754712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen{
755da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
756da26bd203cbb104291b39891febf7481794f205fJim Ingham
757da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointModify (CommandInterpreter &interpreter) :
758da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed (interpreter,
759da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "watchpoint modify",
760da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Modify the options on a watchpoint or set of watchpoints in the executable.  "
761da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "If no watchpoint is specified, act on the last created watchpoint.  "
762da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Passing an empty argument clears the modification.",
763da26bd203cbb104291b39891febf7481794f205fJim Ingham                             NULL),
764da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_options (interpreter)
765da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
766da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
767da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
768da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Add the entry for the first argument for this command to the object's arguments vector.
769da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back (arg);
770da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
771712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
772da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
773da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointModify () {}
774da26bd203cbb104291b39891febf7481794f205fJim Ingham
775da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual Options *
776da26bd203cbb104291b39891febf7481794f205fJim Ingham    GetOptions ()
777712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen    {
778da26bd203cbb104291b39891febf7481794f205fJim Ingham        return &m_options;
779712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen    }
780712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
781da26bd203cbb104291b39891febf7481794f205fJim Ingham    class CommandOptions : public Options
782da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
783da26bd203cbb104291b39891febf7481794f205fJim Ingham    public:
784712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
785da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandOptions (CommandInterpreter &interpreter) :
786da26bd203cbb104291b39891febf7481794f205fJim Ingham            Options (interpreter),
787da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_condition (),
788da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_condition_passed (false)
789da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
790da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
791712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
792da26bd203cbb104291b39891febf7481794f205fJim Ingham        virtual
793da26bd203cbb104291b39891febf7481794f205fJim Ingham        ~CommandOptions () {}
794712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
795da26bd203cbb104291b39891febf7481794f205fJim Ingham        virtual Error
796da26bd203cbb104291b39891febf7481794f205fJim Ingham        SetOptionValue (uint32_t option_idx, const char *option_arg)
797da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
798da26bd203cbb104291b39891febf7481794f205fJim Ingham            Error error;
7996475c42148a8ea1ca86e5db465db7eca742d897dGreg Clayton            const int short_option = m_getopt_table[option_idx].val;
800712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
801da26bd203cbb104291b39891febf7481794f205fJim Ingham            switch (short_option)
802da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
803da26bd203cbb104291b39891febf7481794f205fJim Ingham                case 'c':
804da26bd203cbb104291b39891febf7481794f205fJim Ingham                    if (option_arg != NULL)
805da26bd203cbb104291b39891febf7481794f205fJim Ingham                        m_condition.assign (option_arg);
806da26bd203cbb104291b39891febf7481794f205fJim Ingham                    else
807da26bd203cbb104291b39891febf7481794f205fJim Ingham                        m_condition.clear();
808da26bd203cbb104291b39891febf7481794f205fJim Ingham                    m_condition_passed = true;
809da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
810da26bd203cbb104291b39891febf7481794f205fJim Ingham                default:
811da26bd203cbb104291b39891febf7481794f205fJim Ingham                    error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
812da26bd203cbb104291b39891febf7481794f205fJim Ingham                    break;
813da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
814712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
815da26bd203cbb104291b39891febf7481794f205fJim Ingham            return error;
816da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
817712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
818da26bd203cbb104291b39891febf7481794f205fJim Ingham        void
819da26bd203cbb104291b39891febf7481794f205fJim Ingham        OptionParsingStarting ()
820da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
821da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_condition.clear();
822da26bd203cbb104291b39891febf7481794f205fJim Ingham            m_condition_passed = false;
823da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
824da26bd203cbb104291b39891febf7481794f205fJim Ingham
825da26bd203cbb104291b39891febf7481794f205fJim Ingham        const OptionDefinition*
826da26bd203cbb104291b39891febf7481794f205fJim Ingham        GetDefinitions ()
827da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
828da26bd203cbb104291b39891febf7481794f205fJim Ingham            return g_option_table;
829da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
830712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
831da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Options table: Required for subclasses of Options.
832712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
833da26bd203cbb104291b39891febf7481794f205fJim Ingham        static OptionDefinition g_option_table[];
834712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
835da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Instance variables to hold the values for command options.
836712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
837da26bd203cbb104291b39891febf7481794f205fJim Ingham        std::string m_condition;
838da26bd203cbb104291b39891febf7481794f205fJim Ingham        bool m_condition_passed;
839da26bd203cbb104291b39891febf7481794f205fJim Ingham    };
840da26bd203cbb104291b39891febf7481794f205fJim Ingham
841da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
842da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
843da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (Args& command, CommandReturnObject &result)
844712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen    {
845da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
846da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (!CheckTargetForWatchpointOperations(target, result))
847da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
848da26bd203cbb104291b39891febf7481794f205fJim Ingham
849da26bd203cbb104291b39891febf7481794f205fJim Ingham        Mutex::Locker locker;
850da26bd203cbb104291b39891febf7481794f205fJim Ingham        target->GetWatchpointList().GetListMutex(locker);
851da26bd203cbb104291b39891febf7481794f205fJim Ingham
852da26bd203cbb104291b39891febf7481794f205fJim Ingham        const WatchpointList &watchpoints = target->GetWatchpointList();
853da26bd203cbb104291b39891febf7481794f205fJim Ingham
854da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t num_watchpoints = watchpoints.GetSize();
855da26bd203cbb104291b39891febf7481794f205fJim Ingham
856da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (num_watchpoints == 0)
857712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen        {
858da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendError("No watchpoints exist to be modified.");
859712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen            result.SetStatus(eReturnStatusFailed);
860712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen            return false;
861712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen        }
862712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
863da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() == 0)
864da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
865da26bd203cbb104291b39891febf7481794f205fJim Ingham            WatchpointSP wp_sp = target->GetLastCreatedWatchpoint();
866da26bd203cbb104291b39891febf7481794f205fJim Ingham            wp_sp->SetCondition(m_options.m_condition.c_str());
867da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
868da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
869da26bd203cbb104291b39891febf7481794f205fJim Ingham        else
870712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen        {
871da26bd203cbb104291b39891febf7481794f205fJim Ingham            // Particular watchpoints selected; set condition on them.
872da26bd203cbb104291b39891febf7481794f205fJim Ingham            std::vector<uint32_t> wp_ids;
873bf1bec6263157c86b5df7d6b19090571ed7885a3Jim Ingham            if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
874712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen            {
875da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError("Invalid watchpoints specification.");
876da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.SetStatus(eReturnStatusFailed);
877da26bd203cbb104291b39891febf7481794f205fJim Ingham                return false;
878712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen            }
879712a628dde2f4f786389feecf7e06e59f0853c75Johnny Chen
880da26bd203cbb104291b39891febf7481794f205fJim Ingham            int count = 0;
881da26bd203cbb104291b39891febf7481794f205fJim Ingham            const size_t size = wp_ids.size();
882da26bd203cbb104291b39891febf7481794f205fJim Ingham            for (size_t i = 0; i < size; ++i)
883da26bd203cbb104291b39891febf7481794f205fJim Ingham            {
884da26bd203cbb104291b39891febf7481794f205fJim Ingham                WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]);
885da26bd203cbb104291b39891febf7481794f205fJim Ingham                if (wp_sp)
886da26bd203cbb104291b39891febf7481794f205fJim Ingham                {
887da26bd203cbb104291b39891febf7481794f205fJim Ingham                    wp_sp->SetCondition(m_options.m_condition.c_str());
888da26bd203cbb104291b39891febf7481794f205fJim Ingham                    ++count;
889da26bd203cbb104291b39891febf7481794f205fJim Ingham                }
890da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
891da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.AppendMessageWithFormat("%d watchpoints modified.\n",count);
892da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus (eReturnStatusSuccessFinishNoResult);
893da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
89455a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
895da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
896da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
8976183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
898da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate:
899da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandOptions m_options;
900da26bd203cbb104291b39891febf7481794f205fJim Ingham};
9016183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
902da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark Modify::CommandOptions
903da26bd203cbb104291b39891febf7481794f205fJim InghamOptionDefinition
904da26bd203cbb104291b39891febf7481794f205fJim InghamCommandObjectWatchpointModify::CommandOptions::g_option_table[] =
9056183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen{
906560c51483461697b2f78c145d70d0cd285012c4dFilipe Cabecinhas{ LLDB_OPT_SET_ALL, false, "condition",    'c', required_argument, NULL, 0, eArgTypeExpression, "The watchpoint stops only if this condition expression evaluates to true."},
907da26bd203cbb104291b39891febf7481794f205fJim Ingham{ 0,                false, NULL,            0 , 0,                 NULL, 0,    eArgTypeNone, NULL }
908da26bd203cbb104291b39891febf7481794f205fJim Ingham};
9096183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
91042404d284b22750851b26ae9a4ab42101f673089Johnny Chen//-------------------------------------------------------------------------
91142404d284b22750851b26ae9a4ab42101f673089Johnny Chen// CommandObjectWatchpointSetVariable
91242404d284b22750851b26ae9a4ab42101f673089Johnny Chen//-------------------------------------------------------------------------
913da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark SetVariable
9146183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
915da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointSetVariable : public CommandObjectParsed
9166183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen{
917da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
918da26bd203cbb104291b39891febf7481794f205fJim Ingham
919da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointSetVariable (CommandInterpreter &interpreter) :
920da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectParsed (interpreter,
921da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "watchpoint set variable",
922da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Set a watchpoint on a variable. "
923da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Use the '-w' option to specify the type of watchpoint and "
924da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "the '-x' option to specify the byte size to watch for. "
92526a24b73aadfa2c6eb3121419a9db47c09bd30edJohnny Chen                             "If no '-w' option is specified, it defaults to write. "
926da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "If no '-x' option is specified, it defaults to the variable's "
927da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "byte size. "
928da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "Note that there are limited hardware resources for watchpoints. "
929da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "If watchpoint setting fails, consider disable/delete existing ones "
930da26bd203cbb104291b39891febf7481794f205fJim Ingham                             "to free up resources.",
931da26bd203cbb104291b39891febf7481794f205fJim Ingham                             NULL,
932ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                             eFlagRequiresFrame         |
933ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                             eFlagTryTargetAPILock      |
934ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                             eFlagProcessMustBeLaunched |
935ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                             eFlagProcessMustBePaused   ),
936da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_group (interpreter),
937da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_watchpoint ()
93842404d284b22750851b26ae9a4ab42101f673089Johnny Chen    {
939da26bd203cbb104291b39891febf7481794f205fJim Ingham        SetHelpLong(
940da26bd203cbb104291b39891febf7481794f205fJim Ingham    "Examples: \n\
941da26bd203cbb104291b39891febf7481794f205fJim Ingham    \n\
942da26bd203cbb104291b39891febf7481794f205fJim Ingham        watchpoint set variable -w read_wriate my_global_var \n\
943da26bd203cbb104291b39891febf7481794f205fJim Ingham        # Watch my_global_var for read/write access, with the region to watch corresponding to the byte size of the data type.\n");
944da26bd203cbb104291b39891febf7481794f205fJim Ingham
945da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
946da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentData var_name_arg;
947da26bd203cbb104291b39891febf7481794f205fJim Ingham
948da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Define the only variant of this arg.
949da26bd203cbb104291b39891febf7481794f205fJim Ingham        var_name_arg.arg_type = eArgTypeVarName;
950da26bd203cbb104291b39891febf7481794f205fJim Ingham        var_name_arg.arg_repetition = eArgRepeatPlain;
951da26bd203cbb104291b39891febf7481794f205fJim Ingham
952da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Push the variant into the argument entry.
953da26bd203cbb104291b39891febf7481794f205fJim Ingham        arg.push_back (var_name_arg);
954da26bd203cbb104291b39891febf7481794f205fJim Ingham
955da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Push the data for the only argument into the m_arguments vector.
956da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back (arg);
957da26bd203cbb104291b39891febf7481794f205fJim Ingham
958da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Absorb the '-w' and '-x' options into our option group.
959da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
960da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_group.Finalize();
96142404d284b22750851b26ae9a4ab42101f673089Johnny Chen    }
9626183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
963da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
964da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointSetVariable () {}
965da26bd203cbb104291b39891febf7481794f205fJim Ingham
966da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual Options *
967da26bd203cbb104291b39891febf7481794f205fJim Ingham    GetOptions ()
9686183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen    {
969da26bd203cbb104291b39891febf7481794f205fJim Ingham        return &m_option_group;
9706183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen    }
9716183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
972da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
97336da2aa6dc5ad9994b638ed09eb81c44cc05540bGreg Clayton    static size_t GetVariableCallback (void *baton,
97436da2aa6dc5ad9994b638ed09eb81c44cc05540bGreg Clayton                                       const char *name,
97536da2aa6dc5ad9994b638ed09eb81c44cc05540bGreg Clayton                                       VariableList &variable_list)
9760b5a40cfc980f687f065321586239d3a8365d87dSean Callanan    {
9770b5a40cfc980f687f065321586239d3a8365d87dSean Callanan        Target *target = static_cast<Target *>(baton);
9780b5a40cfc980f687f065321586239d3a8365d87dSean Callanan        if (target)
9790b5a40cfc980f687f065321586239d3a8365d87dSean Callanan        {
9800b5a40cfc980f687f065321586239d3a8365d87dSean Callanan            return target->GetImages().FindGlobalVariables (ConstString(name),
9810b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                            true,
9820b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                            UINT32_MAX,
9830b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                            variable_list);
9840b5a40cfc980f687f065321586239d3a8365d87dSean Callanan        }
9850b5a40cfc980f687f065321586239d3a8365d87dSean Callanan        return 0;
9860b5a40cfc980f687f065321586239d3a8365d87dSean Callanan    }
9870b5a40cfc980f687f065321586239d3a8365d87dSean Callanan
988da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
989ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton    DoExecute (Args& command, CommandReturnObject &result)
99042404d284b22750851b26ae9a4ab42101f673089Johnny Chen    {
991da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
992ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        StackFrame *frame = m_exe_ctx.GetFramePtr();
9936183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
994da26bd203cbb104291b39891febf7481794f205fJim Ingham        // If no argument is present, issue an error message.  There's no way to set a watchpoint.
995da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (command.GetArgumentCount() <= 0)
996da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
997da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.GetErrorStream().Printf("error: required argument missing; specify your program variable to watch for\n");
998da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
999da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
1000da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
100142404d284b22750851b26ae9a4ab42101f673089Johnny Chen
100226a24b73aadfa2c6eb3121419a9db47c09bd30edJohnny Chen        // If no '-w' is specified, default to '-w write'.
1003da26bd203cbb104291b39891febf7481794f205fJim Ingham        if (!m_option_watchpoint.watch_type_specified)
1004da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
100526a24b73aadfa2c6eb3121419a9db47c09bd30edJohnny Chen            m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
1006da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
100742404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1008da26bd203cbb104291b39891febf7481794f205fJim Ingham        // We passed the sanity check for the command.
1009da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Proceed to set the watchpoint now.
1010da26bd203cbb104291b39891febf7481794f205fJim Ingham        lldb::addr_t addr = 0;
1011da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t size = 0;
1012da26bd203cbb104291b39891febf7481794f205fJim Ingham
1013da26bd203cbb104291b39891febf7481794f205fJim Ingham        VariableSP var_sp;
1014da26bd203cbb104291b39891febf7481794f205fJim Ingham        ValueObjectSP valobj_sp;
1015da26bd203cbb104291b39891febf7481794f205fJim Ingham        Stream &output_stream = result.GetOutputStream();
1016da26bd203cbb104291b39891febf7481794f205fJim Ingham
1017da26bd203cbb104291b39891febf7481794f205fJim Ingham        // A simple watch variable gesture allows only one argument.
1018ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (command.GetArgumentCount() != 1)
1019ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
1020da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.GetErrorStream().Printf("error: specify exactly one variable to watch for\n");
1021da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
1022da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
1023da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
102442404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1025da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Things have checked out ok...
1026da26bd203cbb104291b39891febf7481794f205fJim Ingham        Error error;
1027b3a1a2bba41281ba56a99fe64887a8a04760784cGreg Clayton        uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
1028b3a1a2bba41281ba56a99fe64887a8a04760784cGreg Clayton                                     StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
1029da26bd203cbb104291b39891febf7481794f205fJim Ingham        valobj_sp = frame->GetValueForVariableExpressionPath (command.GetArgumentAtIndex(0),
1030da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                              eNoDynamicValues,
1031da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                              expr_path_options,
1032da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                              var_sp,
1033da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                              error);
10340b5a40cfc980f687f065321586239d3a8365d87dSean Callanan
1035ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (!valobj_sp)
1036ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
10370b5a40cfc980f687f065321586239d3a8365d87dSean Callanan            // Not in the frame; let's check the globals.
10380b5a40cfc980f687f065321586239d3a8365d87dSean Callanan
10390b5a40cfc980f687f065321586239d3a8365d87dSean Callanan            VariableList variable_list;
10400b5a40cfc980f687f065321586239d3a8365d87dSean Callanan            ValueObjectList valobj_list;
10410b5a40cfc980f687f065321586239d3a8365d87dSean Callanan
10420b5a40cfc980f687f065321586239d3a8365d87dSean Callanan            Error error (Variable::GetValuesForVariableExpressionPath (command.GetArgumentAtIndex(0),
1043ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                                                                       m_exe_ctx.GetBestExecutionContextScope(),
10440b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                                       GetVariableCallback,
10450b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                                       target,
10460b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                                       variable_list,
10470b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                                                                       valobj_list));
10480b5a40cfc980f687f065321586239d3a8365d87dSean Callanan
10490b5a40cfc980f687f065321586239d3a8365d87dSean Callanan            if (valobj_list.GetSize())
10500b5a40cfc980f687f065321586239d3a8365d87dSean Callanan                valobj_sp = valobj_list.GetValueObjectAtIndex(0);
10510b5a40cfc980f687f065321586239d3a8365d87dSean Callanan        }
10520b5a40cfc980f687f065321586239d3a8365d87dSean Callanan
105352f792329be5db8e38961350589e97e8f2823acdGreg Clayton        ClangASTType clang_type;
10549e376625d6354d77cd6240007f0d42034dd3f1eeJim Ingham
1055ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (valobj_sp)
1056ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
1057da26bd203cbb104291b39891febf7481794f205fJim Ingham            AddressType addr_type;
1058da26bd203cbb104291b39891febf7481794f205fJim Ingham            addr = valobj_sp->GetAddressOf(false, &addr_type);
1059ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton            if (addr_type == eAddressTypeLoad)
1060ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton            {
1061da26bd203cbb104291b39891febf7481794f205fJim Ingham                // We're in business.
1062da26bd203cbb104291b39891febf7481794f205fJim Ingham                // Find out the size of this variable.
1063da26bd203cbb104291b39891febf7481794f205fJim Ingham                size = m_option_watchpoint.watch_size == 0 ? valobj_sp->GetByteSize()
1064da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                           : m_option_watchpoint.watch_size;
1065da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
106652f792329be5db8e38961350589e97e8f2823acdGreg Clayton            clang_type = valobj_sp->GetClangType();
1067ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        }
1068ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        else
1069ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
1070da26bd203cbb104291b39891febf7481794f205fJim Ingham            const char *error_cstr = error.AsCString(NULL);
1071da26bd203cbb104291b39891febf7481794f205fJim Ingham            if (error_cstr)
1072da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.GetErrorStream().Printf("error: %s\n", error_cstr);
1073da26bd203cbb104291b39891febf7481794f205fJim Ingham            else
1074da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n",
1075da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                command.GetArgumentAtIndex(0));
1076da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
107742404d284b22750851b26ae9a4ab42101f673089Johnny Chen        }
107842404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1079da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Now it's time to create the watchpoint.
1080da26bd203cbb104291b39891febf7481794f205fJim Ingham        uint32_t watch_type = m_option_watchpoint.watch_type;
1081be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham
1082da26bd203cbb104291b39891febf7481794f205fJim Ingham        error.Clear();
108352f792329be5db8e38961350589e97e8f2823acdGreg Clayton        Watchpoint *wp = target->CreateWatchpoint(addr, size, &clang_type, watch_type, error).get();
1084ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (wp)
1085ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
10869e98559420d8c7c248b0c75b48db65ffd878402bJohnny Chen            wp->SetWatchSpec(command.GetArgumentAtIndex(0));
10879e98559420d8c7c248b0c75b48db65ffd878402bJohnny Chen            wp->SetWatchVariable(true);
1088ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton            if (var_sp && var_sp->GetDeclaration().GetFile())
1089ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton            {
1090da26bd203cbb104291b39891febf7481794f205fJim Ingham                StreamString ss;
1091da26bd203cbb104291b39891febf7481794f205fJim Ingham                // True to show fullpath for declaration file.
1092da26bd203cbb104291b39891febf7481794f205fJim Ingham                var_sp->GetDeclaration().DumpStopContext(&ss, true);
1093da26bd203cbb104291b39891febf7481794f205fJim Ingham                wp->SetDeclInfo(ss.GetString());
1094da26bd203cbb104291b39891febf7481794f205fJim Ingham            }
1095da26bd203cbb104291b39891febf7481794f205fJim Ingham            output_stream.Printf("Watchpoint created: ");
1096da26bd203cbb104291b39891febf7481794f205fJim Ingham            wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
1097da26bd203cbb104291b39891febf7481794f205fJim Ingham            output_stream.EOL();
1098da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusSuccessFinishResult);
1099ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        }
1100ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        else
1101ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
11025f35a4be95aed0e5b2cb36f7d785bcbfc67284aeDaniel Malea            result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%" PRIx64 ", size=%lu, variable expression='%s').\n",
11039e98559420d8c7c248b0c75b48db65ffd878402bJohnny Chen                                         addr, size, command.GetArgumentAtIndex(0));
1104da26bd203cbb104291b39891febf7481794f205fJim Ingham            if (error.AsCString(NULL))
1105da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError(error.AsCString());
1106da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
110742404d284b22750851b26ae9a4ab42101f673089Johnny Chen        }
1108da26bd203cbb104291b39891febf7481794f205fJim Ingham
1109da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
111042404d284b22750851b26ae9a4ab42101f673089Johnny Chen    }
111142404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1112da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate:
1113da26bd203cbb104291b39891febf7481794f205fJim Ingham    OptionGroupOptions m_option_group;
1114da26bd203cbb104291b39891febf7481794f205fJim Ingham    OptionGroupWatchpoint m_option_watchpoint;
1115da26bd203cbb104291b39891febf7481794f205fJim Ingham};
11166183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
11176183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen//-------------------------------------------------------------------------
111842404d284b22750851b26ae9a4ab42101f673089Johnny Chen// CommandObjectWatchpointSetExpression
111955a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen//-------------------------------------------------------------------------
112055a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen#pragma mark Set
112155a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1122da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointSetExpression : public CommandObjectRaw
112355a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen{
1124da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
1125da26bd203cbb104291b39891febf7481794f205fJim Ingham
1126da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointSetExpression (CommandInterpreter &interpreter) :
1127da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectRaw (interpreter,
1128da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "watchpoint set expression",
1129da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "Set a watchpoint on an address by supplying an expression. "
1130da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "Use the '-w' option to specify the type of watchpoint and "
1131da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "the '-x' option to specify the byte size to watch for. "
113226a24b73aadfa2c6eb3121419a9db47c09bd30edJohnny Chen                          "If no '-w' option is specified, it defaults to write. "
1133da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "If no '-x' option is specified, it defaults to the target's "
1134da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "pointer byte size. "
1135da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "Note that there are limited hardware resources for watchpoints. "
1136da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "If watchpoint setting fails, consider disable/delete existing ones "
1137da26bd203cbb104291b39891febf7481794f205fJim Ingham                          "to free up resources.",
1138da26bd203cbb104291b39891febf7481794f205fJim Ingham                          NULL,
1139ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                          eFlagRequiresFrame         |
1140ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                          eFlagTryTargetAPILock      |
1141ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                          eFlagProcessMustBeLaunched |
1142ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton                          eFlagProcessMustBePaused   ),
1143da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_group (interpreter),
1144da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_watchpoint ()
1145da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
1146da26bd203cbb104291b39891febf7481794f205fJim Ingham        SetHelpLong(
1147da26bd203cbb104291b39891febf7481794f205fJim Ingham    "Examples: \n\
1148da26bd203cbb104291b39891febf7481794f205fJim Ingham    \n\
1149da26bd203cbb104291b39891febf7481794f205fJim Ingham        watchpoint set expression -w write -x 1 -- foo + 32\n\
1150da26bd203cbb104291b39891febf7481794f205fJim Ingham        # Watch write access for the 1-byte region pointed to by the address 'foo + 32'.\n");
1151da26bd203cbb104291b39891febf7481794f205fJim Ingham
1152da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentEntry arg;
1153da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandArgumentData expression_arg;
1154da26bd203cbb104291b39891febf7481794f205fJim Ingham
1155da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Define the only variant of this arg.
1156da26bd203cbb104291b39891febf7481794f205fJim Ingham        expression_arg.arg_type = eArgTypeExpression;
1157da26bd203cbb104291b39891febf7481794f205fJim Ingham        expression_arg.arg_repetition = eArgRepeatPlain;
1158da26bd203cbb104291b39891febf7481794f205fJim Ingham
1159da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Push the only variant into the argument entry.
1160da26bd203cbb104291b39891febf7481794f205fJim Ingham        arg.push_back (expression_arg);
1161da26bd203cbb104291b39891febf7481794f205fJim Ingham
1162da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Push the data for the only argument into the m_arguments vector.
1163da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_arguments.push_back (arg);
1164da26bd203cbb104291b39891febf7481794f205fJim Ingham
1165da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Absorb the '-w' and '-x' options into our option group.
1166da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
1167da26bd203cbb104291b39891febf7481794f205fJim Ingham        m_option_group.Finalize();
1168da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
11696183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
11706183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
1171da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
1172da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointSetExpression () {}
117355a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1174da26bd203cbb104291b39891febf7481794f205fJim Ingham    // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
1175da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
1176da26bd203cbb104291b39891febf7481794f205fJim Ingham    WantsCompletion() { return true; }
117755a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1178da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual Options *
1179da26bd203cbb104291b39891febf7481794f205fJim Ingham    GetOptions ()
1180da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
1181da26bd203cbb104291b39891febf7481794f205fJim Ingham        return &m_option_group;
1182da26bd203cbb104291b39891febf7481794f205fJim Ingham    }
118355a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1184da26bd203cbb104291b39891febf7481794f205fJim Inghamprotected:
1185da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual bool
1186da26bd203cbb104291b39891febf7481794f205fJim Ingham    DoExecute (const char *raw_command, CommandReturnObject &result)
1187da26bd203cbb104291b39891febf7481794f205fJim Ingham    {
1188ca4c37b4874dfcbc2001852624644fa2a2c30f2cSean Callanan        m_option_group.NotifyOptionParsingStarting(); // This is a raw command, so notify the option group
1189ca4c37b4874dfcbc2001852624644fa2a2c30f2cSean Callanan
1190da26bd203cbb104291b39891febf7481794f205fJim Ingham        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1191ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        StackFrame *frame = m_exe_ctx.GetFramePtr();
119242404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1193da26bd203cbb104291b39891febf7481794f205fJim Ingham        Args command(raw_command);
11949caf151a9da17c0791d0b642c25c001217222224Greg Clayton        const char *expr = NULL;
11959caf151a9da17c0791d0b642c25c001217222224Greg Clayton        if (raw_command[0] == '-')
11969caf151a9da17c0791d0b642c25c001217222224Greg Clayton        {
11979caf151a9da17c0791d0b642c25c001217222224Greg Clayton            // We have some options and these options MUST end with --.
11989caf151a9da17c0791d0b642c25c001217222224Greg Clayton            const char *end_options = NULL;
11999caf151a9da17c0791d0b642c25c001217222224Greg Clayton            const char *s = raw_command;
12009caf151a9da17c0791d0b642c25c001217222224Greg Clayton            while (s && s[0])
12019caf151a9da17c0791d0b642c25c001217222224Greg Clayton            {
12029caf151a9da17c0791d0b642c25c001217222224Greg Clayton                end_options = ::strstr (s, "--");
12039caf151a9da17c0791d0b642c25c001217222224Greg Clayton                if (end_options)
12049caf151a9da17c0791d0b642c25c001217222224Greg Clayton                {
12059caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    end_options += 2; // Get past the "--"
12069caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    if (::isspace (end_options[0]))
12079caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    {
12089caf151a9da17c0791d0b642c25c001217222224Greg Clayton                        expr = end_options;
12099caf151a9da17c0791d0b642c25c001217222224Greg Clayton                        while (::isspace (*expr))
12109caf151a9da17c0791d0b642c25c001217222224Greg Clayton                            ++expr;
12119caf151a9da17c0791d0b642c25c001217222224Greg Clayton                        break;
12129caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    }
12139caf151a9da17c0791d0b642c25c001217222224Greg Clayton                }
12149caf151a9da17c0791d0b642c25c001217222224Greg Clayton                s = end_options;
12159caf151a9da17c0791d0b642c25c001217222224Greg Clayton            }
12169caf151a9da17c0791d0b642c25c001217222224Greg Clayton
12179caf151a9da17c0791d0b642c25c001217222224Greg Clayton            if (end_options)
12189caf151a9da17c0791d0b642c25c001217222224Greg Clayton            {
12199caf151a9da17c0791d0b642c25c001217222224Greg Clayton                Args args (raw_command, end_options - raw_command);
12209caf151a9da17c0791d0b642c25c001217222224Greg Clayton                if (!ParseOptions (args, result))
12219caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    return false;
12229caf151a9da17c0791d0b642c25c001217222224Greg Clayton
12239caf151a9da17c0791d0b642c25c001217222224Greg Clayton                Error error (m_option_group.NotifyOptionParsingFinished());
12249caf151a9da17c0791d0b642c25c001217222224Greg Clayton                if (error.Fail())
12259caf151a9da17c0791d0b642c25c001217222224Greg Clayton                {
12269caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    result.AppendError (error.AsCString());
12279caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    result.SetStatus (eReturnStatusFailed);
12289caf151a9da17c0791d0b642c25c001217222224Greg Clayton                    return false;
12299caf151a9da17c0791d0b642c25c001217222224Greg Clayton                }
12309caf151a9da17c0791d0b642c25c001217222224Greg Clayton            }
12319caf151a9da17c0791d0b642c25c001217222224Greg Clayton        }
123242404d284b22750851b26ae9a4ab42101f673089Johnny Chen
12339caf151a9da17c0791d0b642c25c001217222224Greg Clayton        if (expr == NULL)
12349caf151a9da17c0791d0b642c25c001217222224Greg Clayton            expr = raw_command;
123542404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1236da26bd203cbb104291b39891febf7481794f205fJim Ingham        // If no argument is present, issue an error message.  There's no way to set a watchpoint.
12379caf151a9da17c0791d0b642c25c001217222224Greg Clayton        if (command.GetArgumentCount() == 0)
1238da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
1239be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham            result.GetErrorStream().Printf("error: required argument missing; specify an expression to evaulate into the address to watch for\n");
1240da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
1241da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
1242da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
124355a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
124426a24b73aadfa2c6eb3121419a9db47c09bd30edJohnny Chen        // If no '-w' is specified, default to '-w write'.
1245be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham        if (!m_option_watchpoint.watch_type_specified)
1246da26bd203cbb104291b39891febf7481794f205fJim Ingham        {
124726a24b73aadfa2c6eb3121419a9db47c09bd30edJohnny Chen            m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
1248da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
124942404d284b22750851b26ae9a4ab42101f673089Johnny Chen
1250da26bd203cbb104291b39891febf7481794f205fJim Ingham        // We passed the sanity check for the command.
1251da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Proceed to set the watchpoint now.
1252da26bd203cbb104291b39891febf7481794f205fJim Ingham        lldb::addr_t addr = 0;
1253da26bd203cbb104291b39891febf7481794f205fJim Ingham        size_t size = 0;
12546183fccd61b67e814d9e7e85b25516a28edfe864Johnny Chen
1255da26bd203cbb104291b39891febf7481794f205fJim Ingham        ValueObjectSP valobj_sp;
1256da26bd203cbb104291b39891febf7481794f205fJim Ingham
1257da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Use expression evaluation to arrive at the address to watch.
125847beabb1386be44e3f90dbc30a0b22c23b93a4dcJim Ingham        EvaluateExpressionOptions options;
1259d27026e46d8430fb451d85ac161a8492e1930245Enrico Granata        options.SetCoerceToId(false)
1260d27026e46d8430fb451d85ac161a8492e1930245Enrico Granata        .SetUnwindOnError(true)
1261d27026e46d8430fb451d85ac161a8492e1930245Enrico Granata        .SetKeepInMemory(false)
126247beabb1386be44e3f90dbc30a0b22c23b93a4dcJim Ingham        .SetRunOthers(true)
126347beabb1386be44e3f90dbc30a0b22c23b93a4dcJim Ingham        .SetTimeoutUsec(0);
1264d27026e46d8430fb451d85ac161a8492e1930245Enrico Granata
12659caf151a9da17c0791d0b642c25c001217222224Greg Clayton        ExecutionResults expr_result = target->EvaluateExpression (expr,
1266da26bd203cbb104291b39891febf7481794f205fJim Ingham                                                                   frame,
12676cca9695637b27bd583eaae310d5c09dede7cc49Enrico Granata                                                                   valobj_sp,
1268d27026e46d8430fb451d85ac161a8492e1930245Enrico Granata                                                                   options);
1269ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (expr_result != eExecutionCompleted)
1270ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
1271da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n");
12729caf151a9da17c0791d0b642c25c001217222224Greg Clayton            result.GetErrorStream().Printf("expression evaluated: %s\n", expr);
1273da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
1274da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
1275da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
1276da26bd203cbb104291b39891febf7481794f205fJim Ingham
1277da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Get the address to watch.
1278da26bd203cbb104291b39891febf7481794f205fJim Ingham        bool success = false;
1279da26bd203cbb104291b39891febf7481794f205fJim Ingham        addr = valobj_sp->GetValueAsUnsigned(0, &success);
1280ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (!success)
1281ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
1282da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.GetErrorStream().Printf("error: expression did not evaluate to an address\n");
1283da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
1284da26bd203cbb104291b39891febf7481794f205fJim Ingham            return false;
1285da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
1286be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham
1287be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham        if (m_option_watchpoint.watch_size != 0)
1288be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham            size = m_option_watchpoint.watch_size;
1289be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham        else
1290be2f9090cf7d64a0f021cbc4036f4172baba1cd2Jim Ingham            size = target->GetArchitecture().GetAddressByteSize();
1291da26bd203cbb104291b39891febf7481794f205fJim Ingham
1292da26bd203cbb104291b39891febf7481794f205fJim Ingham        // Now it's time to create the watchpoint.
1293da26bd203cbb104291b39891febf7481794f205fJim Ingham        uint32_t watch_type = m_option_watchpoint.watch_type;
12949e376625d6354d77cd6240007f0d42034dd3f1eeJim Ingham
12959e376625d6354d77cd6240007f0d42034dd3f1eeJim Ingham        // Fetch the type from the value object, the type of the watched object is the pointee type
12969e376625d6354d77cd6240007f0d42034dd3f1eeJim Ingham        /// of the expression, so convert to that if we  found a valid type.
129752f792329be5db8e38961350589e97e8f2823acdGreg Clayton        ClangASTType clang_type(valobj_sp->GetClangType());
12989e376625d6354d77cd6240007f0d42034dd3f1eeJim Ingham
1299da26bd203cbb104291b39891febf7481794f205fJim Ingham        Error error;
130052f792329be5db8e38961350589e97e8f2823acdGreg Clayton        Watchpoint *wp = target->CreateWatchpoint(addr, size, &clang_type, watch_type, error).get();
1301ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        if (wp)
1302ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
13039caf151a9da17c0791d0b642c25c001217222224Greg Clayton            Stream &output_stream = result.GetOutputStream();
1304da26bd203cbb104291b39891febf7481794f205fJim Ingham            output_stream.Printf("Watchpoint created: ");
1305da26bd203cbb104291b39891febf7481794f205fJim Ingham            wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
1306da26bd203cbb104291b39891febf7481794f205fJim Ingham            output_stream.EOL();
1307da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusSuccessFinishResult);
1308ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        }
1309ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        else
1310ea0bb4d45c14447a2fe9be9f4bd8e79a84513537Greg Clayton        {
13115f35a4be95aed0e5b2cb36f7d785bcbfc67284aeDaniel Malea            result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%" PRIx64 ", size=%lu).\n",
1312da26bd203cbb104291b39891febf7481794f205fJim Ingham                                         addr, size);
1313da26bd203cbb104291b39891febf7481794f205fJim Ingham            if (error.AsCString(NULL))
1314da26bd203cbb104291b39891febf7481794f205fJim Ingham                result.AppendError(error.AsCString());
1315da26bd203cbb104291b39891febf7481794f205fJim Ingham            result.SetStatus(eReturnStatusFailed);
1316da26bd203cbb104291b39891febf7481794f205fJim Ingham        }
1317da26bd203cbb104291b39891febf7481794f205fJim Ingham
1318da26bd203cbb104291b39891febf7481794f205fJim Ingham        return result.Succeeded();
131955a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen    }
132055a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1321da26bd203cbb104291b39891febf7481794f205fJim Inghamprivate:
1322da26bd203cbb104291b39891febf7481794f205fJim Ingham    OptionGroupOptions m_option_group;
1323da26bd203cbb104291b39891febf7481794f205fJim Ingham    OptionGroupWatchpoint m_option_watchpoint;
1324da26bd203cbb104291b39891febf7481794f205fJim Ingham};
132555a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1326da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
1327da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectWatchpointSet
1328da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
1329da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark Set
133055a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1331da26bd203cbb104291b39891febf7481794f205fJim Inghamclass CommandObjectWatchpointSet : public CommandObjectMultiword
1332da26bd203cbb104291b39891febf7481794f205fJim Ingham{
1333da26bd203cbb104291b39891febf7481794f205fJim Inghampublic:
13348c1af79e3d88f26e7569e895c5bd70a0de87d3bcJohnny Chen
1335da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectWatchpointSet (CommandInterpreter &interpreter) :
1336da26bd203cbb104291b39891febf7481794f205fJim Ingham        CommandObjectMultiword (interpreter,
1337da26bd203cbb104291b39891febf7481794f205fJim Ingham                                "watchpoint set",
1338da26bd203cbb104291b39891febf7481794f205fJim Ingham                                "A set of commands for setting a watchpoint.",
1339da26bd203cbb104291b39891febf7481794f205fJim Ingham                                "watchpoint set <subcommand> [<subcommand-options>]")
13408c1af79e3d88f26e7569e895c5bd70a0de87d3bcJohnny Chen    {
1341da26bd203cbb104291b39891febf7481794f205fJim Ingham
1342da26bd203cbb104291b39891febf7481794f205fJim Ingham        LoadSubCommand ("variable",   CommandObjectSP (new CommandObjectWatchpointSetVariable (interpreter)));
1343da26bd203cbb104291b39891febf7481794f205fJim Ingham        LoadSubCommand ("expression", CommandObjectSP (new CommandObjectWatchpointSetExpression (interpreter)));
13448c1af79e3d88f26e7569e895c5bd70a0de87d3bcJohnny Chen    }
134542404d284b22750851b26ae9a4ab42101f673089Johnny Chen
134655a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1347da26bd203cbb104291b39891febf7481794f205fJim Ingham    virtual
1348da26bd203cbb104291b39891febf7481794f205fJim Ingham    ~CommandObjectWatchpointSet () {}
134955a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen
1350da26bd203cbb104291b39891febf7481794f205fJim Ingham};
1351da26bd203cbb104291b39891febf7481794f205fJim Ingham
1352da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
1353da26bd203cbb104291b39891febf7481794f205fJim Ingham// CommandObjectMultiwordWatchpoint
1354da26bd203cbb104291b39891febf7481794f205fJim Ingham//-------------------------------------------------------------------------
1355da26bd203cbb104291b39891febf7481794f205fJim Ingham#pragma mark MultiwordWatchpoint
1356da26bd203cbb104291b39891febf7481794f205fJim Ingham
1357da26bd203cbb104291b39891febf7481794f205fJim InghamCommandObjectMultiwordWatchpoint::CommandObjectMultiwordWatchpoint(CommandInterpreter &interpreter) :
1358da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectMultiword (interpreter,
1359da26bd203cbb104291b39891febf7481794f205fJim Ingham                            "watchpoint",
1360da26bd203cbb104291b39891febf7481794f205fJim Ingham                            "A set of commands for operating on watchpoints.",
1361da26bd203cbb104291b39891febf7481794f205fJim Ingham                            "watchpoint <command> [<command-options>]")
1362da26bd203cbb104291b39891febf7481794f205fJim Ingham{
1363da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP list_command_object (new CommandObjectWatchpointList (interpreter));
1364da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP enable_command_object (new CommandObjectWatchpointEnable (interpreter));
1365da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP disable_command_object (new CommandObjectWatchpointDisable (interpreter));
1366da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP delete_command_object (new CommandObjectWatchpointDelete (interpreter));
1367da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP ignore_command_object (new CommandObjectWatchpointIgnore (interpreter));
1368f3ec4617297810223deb545cb68214ca4dd8009cJohnny Chen    CommandObjectSP command_command_object (new CommandObjectWatchpointCommand (interpreter));
1369da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP modify_command_object (new CommandObjectWatchpointModify (interpreter));
1370da26bd203cbb104291b39891febf7481794f205fJim Ingham    CommandObjectSP set_command_object (new CommandObjectWatchpointSet (interpreter));
1371da26bd203cbb104291b39891febf7481794f205fJim Ingham
1372da26bd203cbb104291b39891febf7481794f205fJim Ingham    list_command_object->SetCommandName ("watchpoint list");
1373da26bd203cbb104291b39891febf7481794f205fJim Ingham    enable_command_object->SetCommandName("watchpoint enable");
1374da26bd203cbb104291b39891febf7481794f205fJim Ingham    disable_command_object->SetCommandName("watchpoint disable");
1375da26bd203cbb104291b39891febf7481794f205fJim Ingham    delete_command_object->SetCommandName("watchpoint delete");
1376da26bd203cbb104291b39891febf7481794f205fJim Ingham    ignore_command_object->SetCommandName("watchpoint ignore");
1377f3ec4617297810223deb545cb68214ca4dd8009cJohnny Chen    command_command_object->SetCommandName ("watchpoint command");
1378da26bd203cbb104291b39891febf7481794f205fJim Ingham    modify_command_object->SetCommandName("watchpoint modify");
1379da26bd203cbb104291b39891febf7481794f205fJim Ingham    set_command_object->SetCommandName("watchpoint set");
1380da26bd203cbb104291b39891febf7481794f205fJim Ingham
13814a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("list",       list_command_object);
13824a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("enable",     enable_command_object);
13834a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("disable",    disable_command_object);
13844a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("delete",     delete_command_object);
13854a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("ignore",     ignore_command_object);
1386f3ec4617297810223deb545cb68214ca4dd8009cJohnny Chen    LoadSubCommand ("command",    command_command_object);
13874a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("modify",     modify_command_object);
13884a379b1194f3e6b308cd6e80b45d6ca5dd0aafd7Greg Clayton    LoadSubCommand ("set",        set_command_object);
138955a2d5a49d82fcfc0fe72825293f6c04d1970e21Johnny Chen}
1390da26bd203cbb104291b39891febf7481794f205fJim Ingham
1391da26bd203cbb104291b39891febf7481794f205fJim InghamCommandObjectMultiwordWatchpoint::~CommandObjectMultiwordWatchpoint()
1392da26bd203cbb104291b39891febf7481794f205fJim Ingham{
1393da26bd203cbb104291b39891febf7481794f205fJim Ingham}
1394da26bd203cbb104291b39891febf7481794f205fJim Ingham
1395