summaryrefslogtreecommitdiffstats
path: root/lldb/source/Breakpoint/Watchpoint.cpp
blob: e9b314b24aca322b34d0f993ace9fd11ef76d0ca (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//===-- Watchpoint.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/Breakpoint/Watchpoint.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Stream.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ThreadSpec.h"
#include "lldb/Target/ThreadPlanTestCondition.h"

using namespace lldb;
using namespace lldb_private;

Watchpoint::Watchpoint (lldb::addr_t addr, size_t size, bool hardware) :
    StoppointLocation (GetNextID(), addr, size, hardware),
    m_target(NULL),
    m_enabled(0),
    m_is_hardware(hardware),
    m_watch_read(0),
    m_watch_write(0),
    m_watch_was_read(0),
    m_watch_was_written(0),
    m_ignore_count(0),
    m_callback(NULL),
    m_callback_baton(NULL),
    m_decl_str(),
    m_error()
{
}

Watchpoint::~Watchpoint()
{
}

break_id_t
Watchpoint::GetNextID()
{
    static break_id_t g_next_ID = 0;
    return ++g_next_ID;
}

bool
Watchpoint::SetCallback (WatchpointHitCallback callback, void *callback_baton)
{
    m_callback = callback;
    m_callback_baton = callback_baton;
    return true;
}

void
Watchpoint::SetDeclInfo (std::string &str)
{
    m_decl_str = str;
    return;
}


bool
Watchpoint::IsHardware () const
{
    return m_is_hardware;
}

// RETURNS - true if we should stop at this breakpoint, false if we
// should continue.

bool
Watchpoint::ShouldStop (StoppointCallbackContext *context)
{
    ++m_hit_count;

    if (!IsEnabled())
        return false;

    if (m_hit_count <= GetIgnoreCount())
        return false;

    return true;
}

void
Watchpoint::GetDescription (Stream *s, lldb::DescriptionLevel level)
{
    DumpWithLevel(s, level);
    return;
}

void
Watchpoint::Dump(Stream *s) const
{
    DumpWithLevel(s, lldb::eDescriptionLevelBrief);
}

void
Watchpoint::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
{
    if (s == NULL)
        return;

    assert(description_level >= lldb::eDescriptionLevelBrief &&
           description_level <= lldb::eDescriptionLevelVerbose);

    s->Printf("Watchpoint %u: addr = 0x%8.8llx size = %u state = %s type = %s%s",
              GetID(),
              (uint64_t)m_addr,
              m_byte_size,
              m_enabled ? "enabled" : "disabled",
              m_watch_read ? "r" : "",
              m_watch_write ? "w" : "");

    if (description_level >= lldb::eDescriptionLevelFull) {
        if (m_decl_str.c_str())
            s->Printf("\n    declare @ '%s'", m_decl_str.c_str());
        if (GetConditionText())
            s->Printf("\n    condition = '%s'", GetConditionText());
    }

    if (description_level >= lldb::eDescriptionLevelVerbose)
        if (m_callback)
            s->Printf("\n    hw_index = %i  hit_count = %-4u  ignore_count = %-4u  callback = %8p baton = %8p",
                      GetHardwareIndex(),
                      GetHitCount(),
                      GetIgnoreCount(),
                      m_callback,
                      m_callback_baton);
        else
            s->Printf("\n    hw_index = %i  hit_count = %-4u  ignore_count = %-4u",
                      GetHardwareIndex(),
                      GetHitCount(),
                      GetIgnoreCount());
}

bool
Watchpoint::IsEnabled() const
{
    return m_enabled;
}

void
Watchpoint::SetEnabled(bool enabled)
{
    if (!enabled)
        SetHardwareIndex(LLDB_INVALID_INDEX32);
    m_enabled = enabled;
}

void
Watchpoint::SetWatchpointType (uint32_t type)
{
    m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
    m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
}

bool
Watchpoint::WatchpointRead () const
{
    return m_watch_read != 0;
}
bool
Watchpoint::WatchpointWrite () const
{
    return m_watch_write != 0;
}
uint32_t
Watchpoint::GetIgnoreCount () const
{
    return m_ignore_count;
}

void
Watchpoint::SetIgnoreCount (uint32_t n)
{
    m_ignore_count = n;
}

bool
Watchpoint::InvokeCallback (StoppointCallbackContext *context)
{
    if (m_callback && context->is_synchronous)
    {
        uint32_t access = 0;
        if (m_watch_was_read)
            access |= LLDB_WATCH_TYPE_READ;
        if (m_watch_was_written)
            access |= LLDB_WATCH_TYPE_WRITE;
        return m_callback(m_callback_baton, context, GetID(), access);
    }
    else
        return true;
}

void 
Watchpoint::SetCondition (const char *condition)
{
    if (condition == NULL || condition[0] == '\0')
    {
        if (m_condition_ap.get())
            m_condition_ap.reset();
    }
    else
    {
        // Pass NULL for expr_prefix (no translation-unit level definitions).
        m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny));
    }
}

const char *
Watchpoint::GetConditionText () const
{
    if (m_condition_ap.get())
        return m_condition_ap->GetUserText();
    else
        return NULL;
}

OpenPOWER on IntegriCloud