Watchpoint.h revision 116a5cd7b8a0ec7929f10281cd708edb2bf20ffa
1//===-- Watchpoint.h --------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_Watchpoint_h_
11#define liblldb_Watchpoint_h_
12
13// C Includes
14
15// C++ Includes
16#include <list>
17#include <string>
18
19// Other libraries and framework includes
20
21// Project includes
22#include "lldb/lldb-private.h"
23#include "lldb/Target/Target.h"
24#include "lldb/Core/UserID.h"
25#include "lldb/Breakpoint/StoppointLocation.h"
26
27namespace lldb_private {
28
29class Watchpoint :
30    public StoppointLocation
31{
32public:
33
34    Watchpoint (lldb::addr_t addr, size_t size, bool hardware = true);
35
36    ~Watchpoint ();
37
38    bool
39    IsEnabled () const;
40
41    void
42    SetEnabled (bool enabled);
43
44    virtual bool
45    IsHardware () const;
46
47    virtual bool
48    ShouldStop (StoppointCallbackContext *context);
49
50    bool        WatchpointRead () const;
51    bool        WatchpointWrite () const;
52    uint32_t    GetIgnoreCount () const;
53    void        SetIgnoreCount (uint32_t n);
54    void        SetWatchpointType (uint32_t type);
55    bool        SetCallback (WatchpointHitCallback callback, void *callback_baton);
56    void        ClearCallback();
57    void        SetDeclInfo (std::string &str);
58    void        SetWatchSpec (std::string &str);
59    void        GetDescription (Stream *s, lldb::DescriptionLevel level);
60    void        Dump (Stream *s) const;
61    void        DumpWithLevel (Stream *s, lldb::DescriptionLevel description_level) const;
62    Target      &GetTarget() { return *m_target; }
63    const Error &GetError() { return m_error; }
64
65    //------------------------------------------------------------------
66    /// Invoke the callback action when the watchpoint is hit.
67    ///
68    /// @param[in] context
69    ///     Described the watchpoint event.
70    ///
71    /// @return
72    ///     \b true if the target should stop at this watchpoint and \b false not.
73    //------------------------------------------------------------------
74    bool
75    InvokeCallback (StoppointCallbackContext *context);
76
77    //------------------------------------------------------------------
78    // Condition
79    //------------------------------------------------------------------
80    //------------------------------------------------------------------
81    /// Set the breakpoint's condition.
82    ///
83    /// @param[in] condition
84    ///    The condition expression to evaluate when the breakpoint is hit.
85    ///    Pass in NULL to clear the condition.
86    //------------------------------------------------------------------
87    void SetCondition (const char *condition);
88
89    //------------------------------------------------------------------
90    /// Return a pointer to the text of the condition expression.
91    ///
92    /// @return
93    ///    A pointer to the condition expression text, or NULL if no
94    //     condition has been set.
95    //------------------------------------------------------------------
96    const char *GetConditionText () const;
97
98private:
99    friend class Target;
100    friend class WatchpointList;
101
102    void        SetTarget(Target *target_ptr) { m_target = target_ptr; }
103    std::string GetWatchSpec() { return m_watch_spec_str; }
104    void        ResetHitCount() { m_hit_count = 0; }
105
106    Target      *m_target;
107    bool        m_enabled;             // Is this watchpoint enabled
108    bool        m_is_hardware;         // Is this a hardware watchpoint
109    uint32_t    m_watch_read:1,        // 1 if we stop when the watched data is read from
110                m_watch_write:1,       // 1 if we stop when the watched data is written to
111                m_watch_was_read:1,    // Set to 1 when watchpoint is hit for a read access
112                m_watch_was_written:1; // Set to 1 when watchpoint is hit for a write access
113    uint32_t    m_ignore_count;        // Number of times to ignore this breakpoint
114    WatchpointHitCallback m_callback;
115    void *      m_callback_baton;      // Callback user data to pass to callback
116    std::string m_decl_str;            // Declaration information, if any.
117    std::string m_watch_spec_str;      // Spec for the watchpoint (for future use).
118    Error       m_error;               // An error object describing errors creating watchpoint.
119
120    std::auto_ptr<ClangUserExpression> m_condition_ap;  // The condition to test.
121
122    void SetID(lldb::watch_id_t id) { m_loc_id = id; }
123
124    DISALLOW_COPY_AND_ASSIGN (Watchpoint);
125};
126
127} // namespace lldb_private
128
129#endif  // liblldb_Watchpoint_h_
130