summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
blob: 076d010ae7ec723c1393301f41ffdcd00cc96d87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Interpreter/OptionGroupWatchpoint.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-enumerations.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Utility/Utils.h"

using namespace lldb;
using namespace lldb_private;

static OptionEnumValueElement g_watch_type[] =
{
    { OptionGroupWatchpoint::eWatchRead,      "read",       "Watch for read"},
    { OptionGroupWatchpoint::eWatchWrite,     "write",      "Watch for write"},
    { OptionGroupWatchpoint::eWatchReadWrite, "read_write", "Watch for read/write"},
    { 0, NULL, NULL }
};

static OptionEnumValueElement g_watch_size[] =
{
    { 1, "1", "Watch for byte size of 1"},
    { 2, "2", "Watch for byte size of 2"},
    { 4, "4", "Watch for byte size of 4"},
    { 8, "8", "Watch for byte size of 8"},
    { 0, NULL, NULL }
};

// if you add any options here, remember to update the counters in OptionGroupWatchpoint::GetNumDefinitions()
static OptionDefinition
g_option_table[] =
{
    { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Determine how to watch a variable (read, write, or read/write)."},
    { LLDB_OPT_SET_1, false, "xsize", 'x', required_argument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a location (1, 2, 4, or 8)."}
};


OptionGroupWatchpoint::OptionGroupWatchpoint () :
    OptionGroup()
{
}

OptionGroupWatchpoint::~OptionGroupWatchpoint ()
{
}

Error
OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter,
                                       uint32_t option_idx, 
                                       const char *option_arg)
{
    Error error;
    char short_option = (char) g_option_table[option_idx].short_option;
    switch (short_option)
    {
        case 'w': {
            OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
            watch_type = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable);
            if (!watch_variable)
                error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg);
            break;
        }
        case 'x': {
            bool success = false;
            OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
            watch_size = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &success);
            if (!success)
                error.SetErrorStringWithFormat("Invalid option arg for '-x': '%s'.\n", option_arg);
            break;
        }
        default:
            error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
            break;
    }
    
    return error;
}

void
OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
{
    watch_variable = false;
    watch_type     = eWatchInvalid;
    watch_size     = 0;
}


const OptionDefinition*
OptionGroupWatchpoint::GetDefinitions ()
{
    return g_option_table;
}

uint32_t
OptionGroupWatchpoint::GetNumDefinitions ()
{
    return arraysize(g_option_table);
}
OpenPOWER on IntegriCloud