| Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 1 | //===-- SWIG Interface for SBBreakpoint -------------------------*- 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 | namespace lldb { | 
|  | 11 |  | 
|  | 12 | %feature("docstring", | 
|  | 13 | "Represents a logical breakpoint and its associated settings. | 
|  | 14 |  | 
|  | 15 | For example (from test/functionalities/breakpoint/breakpoint_ignore_count/ | 
|  | 16 | TestBreakpointIgnoreCount.py), | 
|  | 17 |  | 
|  | 18 | def breakpoint_ignore_count_python(self): | 
|  | 19 | '''Use Python APIs to set breakpoint ignore count.''' | 
|  | 20 | exe = os.path.join(os.getcwd(), 'a.out') | 
|  | 21 |  | 
|  | 22 | # Create a target by the debugger. | 
|  | 23 | target = self.dbg.CreateTarget(exe) | 
|  | 24 | self.assertTrue(target, VALID_TARGET) | 
|  | 25 |  | 
|  | 26 | # Now create a breakpoint on main.c by name 'c'. | 
|  | 27 | breakpoint = target.BreakpointCreateByName('c', 'a.out') | 
|  | 28 | self.assertTrue(breakpoint and | 
|  | 29 | breakpoint.GetNumLocations() == 1, | 
|  | 30 | VALID_BREAKPOINT) | 
|  | 31 |  | 
|  | 32 | # Get the breakpoint location from breakpoint after we verified that, | 
|  | 33 | # indeed, it has one location. | 
|  | 34 | location = breakpoint.GetLocationAtIndex(0) | 
|  | 35 | self.assertTrue(location and | 
|  | 36 | location.IsEnabled(), | 
|  | 37 | VALID_BREAKPOINT_LOCATION) | 
|  | 38 |  | 
|  | 39 | # Set the ignore count on the breakpoint location. | 
|  | 40 | location.SetIgnoreCount(2) | 
|  | 41 | self.assertTrue(location.GetIgnoreCount() == 2, | 
|  | 42 | 'SetIgnoreCount() works correctly') | 
|  | 43 |  | 
|  | 44 | # Now launch the process, and do not stop at entry point. | 
|  | 45 | process = target.LaunchSimple(None, None, os.getcwd()) | 
|  | 46 | self.assertTrue(process, PROCESS_IS_VALID) | 
|  | 47 |  | 
|  | 48 | # Frame#0 should be on main.c:37, frame#1 should be on main.c:25, and | 
|  | 49 | # frame#2 should be on main.c:48. | 
|  | 50 | #lldbutil.print_stacktraces(process) | 
|  | 51 | from lldbutil import get_stopped_thread | 
|  | 52 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) | 
|  | 53 | self.assertTrue(thread != None, 'There should be a thread stopped due to breakpoint') | 
|  | 54 | frame0 = thread.GetFrameAtIndex(0) | 
|  | 55 | frame1 = thread.GetFrameAtIndex(1) | 
|  | 56 | frame2 = thread.GetFrameAtIndex(2) | 
|  | 57 | self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and | 
|  | 58 | frame1.GetLineEntry().GetLine() == self.line3 and | 
|  | 59 | frame2.GetLineEntry().GetLine() == self.line4, | 
|  | 60 | STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT) | 
|  | 61 |  | 
|  | 62 | # The hit count for the breakpoint should be 3. | 
|  | 63 | self.assertTrue(breakpoint.GetHitCount() == 3) | 
|  | 64 |  | 
|  | 65 | process.Continue() | 
|  | 66 |  | 
| Johnny Chen | f74cb50 | 2011-07-18 23:11:07 +0000 | [diff] [blame] | 67 | SBBreakpoint supports breakpoint location iteration, for example, | 
| Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | for bl in breakpoint: | 
|  | 70 | print 'breakpoint location load addr: %s' % hex(bl.GetLoadAddress()) | 
|  | 71 | print 'breakpoint location condition: %s' % hex(bl.GetCondition()) | 
| Johnny Chen | f74cb50 | 2011-07-18 23:11:07 +0000 | [diff] [blame] | 72 |  | 
|  | 73 | and rich comparion methods which allow the API program to use, | 
|  | 74 |  | 
|  | 75 | if aBreakpoint == bBreakpoint: | 
|  | 76 | ... | 
|  | 77 |  | 
|  | 78 | to compare two breakpoints for equality." | 
|  | 79 | ) SBBreakpoint; | 
| Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 80 | class SBBreakpoint | 
|  | 81 | { | 
|  | 82 | public: | 
|  | 83 |  | 
|  | 84 | typedef bool (*BreakpointHitCallback) (void *baton, | 
|  | 85 | SBProcess &process, | 
|  | 86 | SBThread &thread, | 
|  | 87 | lldb::SBBreakpointLocation &location); | 
|  | 88 |  | 
|  | 89 | SBBreakpoint (); | 
|  | 90 |  | 
|  | 91 | SBBreakpoint (const lldb::SBBreakpoint& rhs); | 
|  | 92 |  | 
|  | 93 | ~SBBreakpoint(); | 
|  | 94 |  | 
|  | 95 | break_id_t | 
|  | 96 | GetID () const; | 
|  | 97 |  | 
|  | 98 | bool | 
|  | 99 | IsValid() const; | 
|  | 100 |  | 
|  | 101 | void | 
|  | 102 | ClearAllBreakpointSites (); | 
|  | 103 |  | 
|  | 104 | lldb::SBBreakpointLocation | 
|  | 105 | FindLocationByAddress (lldb::addr_t vm_addr); | 
|  | 106 |  | 
|  | 107 | lldb::break_id_t | 
|  | 108 | FindLocationIDByAddress (lldb::addr_t vm_addr); | 
|  | 109 |  | 
|  | 110 | lldb::SBBreakpointLocation | 
|  | 111 | FindLocationByID (lldb::break_id_t bp_loc_id); | 
|  | 112 |  | 
|  | 113 | lldb::SBBreakpointLocation | 
|  | 114 | GetLocationAtIndex (uint32_t index); | 
|  | 115 |  | 
|  | 116 | void | 
|  | 117 | SetEnabled (bool enable); | 
|  | 118 |  | 
|  | 119 | bool | 
|  | 120 | IsEnabled (); | 
|  | 121 |  | 
|  | 122 | uint32_t | 
|  | 123 | GetHitCount () const; | 
|  | 124 |  | 
|  | 125 | void | 
|  | 126 | SetIgnoreCount (uint32_t count); | 
|  | 127 |  | 
|  | 128 | uint32_t | 
|  | 129 | GetIgnoreCount () const; | 
|  | 130 |  | 
| Johnny Chen | 85ced80 | 2011-10-18 19:13:06 +0000 | [diff] [blame] | 131 | %feature("docstring", " | 
|  | 132 | //-------------------------------------------------------------------------- | 
|  | 133 | /// The breakpoint stops only if the condition expression evaluates to true. | 
|  | 134 | //-------------------------------------------------------------------------- | 
|  | 135 | ") SetCondition; | 
| Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 136 | void | 
|  | 137 | SetCondition (const char *condition); | 
|  | 138 |  | 
| Johnny Chen | 85ced80 | 2011-10-18 19:13:06 +0000 | [diff] [blame] | 139 | %feature("docstring", " | 
|  | 140 | //------------------------------------------------------------------ | 
|  | 141 | /// Get the condition expression for the breakpoint. | 
|  | 142 | //------------------------------------------------------------------ | 
|  | 143 | ") GetCondition; | 
| Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 144 | const char * | 
|  | 145 | GetCondition (); | 
|  | 146 |  | 
|  | 147 | void | 
|  | 148 | SetThreadID (lldb::tid_t sb_thread_id); | 
|  | 149 |  | 
|  | 150 | lldb::tid_t | 
|  | 151 | GetThreadID (); | 
|  | 152 |  | 
|  | 153 | void | 
|  | 154 | SetThreadIndex (uint32_t index); | 
|  | 155 |  | 
|  | 156 | uint32_t | 
|  | 157 | GetThreadIndex() const; | 
|  | 158 |  | 
|  | 159 | void | 
|  | 160 | SetThreadName (const char *thread_name); | 
|  | 161 |  | 
|  | 162 | const char * | 
|  | 163 | GetThreadName () const; | 
|  | 164 |  | 
|  | 165 | void | 
|  | 166 | SetQueueName (const char *queue_name); | 
|  | 167 |  | 
|  | 168 | const char * | 
|  | 169 | GetQueueName () const; | 
|  | 170 |  | 
|  | 171 | void | 
|  | 172 | SetCallback (BreakpointHitCallback callback, void *baton); | 
|  | 173 |  | 
|  | 174 | size_t | 
|  | 175 | GetNumResolvedLocations() const; | 
|  | 176 |  | 
|  | 177 | size_t | 
|  | 178 | GetNumLocations() const; | 
|  | 179 |  | 
|  | 180 | bool | 
|  | 181 | GetDescription (lldb::SBStream &description); | 
|  | 182 |  | 
|  | 183 | static lldb::BreakpointEventType | 
|  | 184 | GetBreakpointEventTypeFromEvent (const lldb::SBEvent& event); | 
|  | 185 |  | 
|  | 186 | static lldb::SBBreakpoint | 
|  | 187 | GetBreakpointFromEvent (const lldb::SBEvent& event); | 
|  | 188 |  | 
|  | 189 | static lldb::SBBreakpointLocation | 
|  | 190 | GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx); | 
|  | 191 | }; | 
|  | 192 |  | 
|  | 193 | } // namespace lldb |