Skip to content

Commit 36f3b36

Browse files
committed
Added support for breakpoint conditions. I also had to separate the "run the expression" part of ClangFunction::Execute from the "Gather the expression result" so that in the case of the Breakpoint condition I can move the condition evaluation into the normal thread plan processing.
Also added support for remembering the "last set breakpoint" so that "break modify" will act on the last set breakpoint. llvm-svn: 116542
1 parent 3f1cf0f commit 36f3b36

26 files changed

+760
-129
lines changed

lldb/include/lldb/Breakpoint/Breakpoint.h

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,41 @@ class Breakpoint:
370370
ClearCallback ();
371371

372372
//------------------------------------------------------------------
373-
/// Set the condition expression to be checked when the breakpoint is hit.
374-
/// @param[in] expression
375-
/// The method that will get called when the breakpoint is hit.
373+
/// Set the breakpoint's condition.
374+
///
375+
/// @param[in] condition
376+
/// The condition expression to evaluate when the breakpoint is hit.
377+
/// Pass in NULL to clear the condition.
376378
//------------------------------------------------------------------
377-
void
378-
SetCondition (void *expression);
379+
void SetCondition (const char *condition);
380+
381+
//------------------------------------------------------------------
382+
/// Test the breakpoint condition in the Execution context passed in.
383+
///
384+
/// @param[in] exe_ctx
385+
/// The execution context in which to evaluate this expression.
386+
///
387+
/// @param[in] break_loc_sp
388+
/// A shared pointer to the location that we are testing thsi condition for.
389+
///
390+
/// @param[in] error
391+
/// Error messages will be written to this stream.
392+
///
393+
/// @return
394+
/// A thread plan to run to test the condition or NULL if no condition.
395+
//------------------------------------------------------------------
396+
ThreadPlan *GetThreadPlanToTestCondition (ExecutionContext &exe_ctx,
397+
lldb::BreakpointLocationSP break_loc_sp,
398+
Stream &error);
399+
400+
//------------------------------------------------------------------
401+
/// Return a pointer to the text of the condition expression.
402+
///
403+
/// @return
404+
/// A pointer to the condition expression text, or NULL if no
405+
// condition has been set.
406+
//------------------------------------------------------------------
407+
const char *GetConditionText ();
379408

380409
//------------------------------------------------------------------
381410
// The next section are various utility functions.

lldb/include/lldb/Breakpoint/BreakpointLocation.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,35 @@ class BreakpointLocation : public StoppointLocation
160160
ClearCallback ();
161161

162162
//------------------------------------------------------------------
163-
/// Set the condition expression to be checked when the breakpoint is hit.
163+
/// Set the breakpoint location's condition.
164164
///
165-
/// @param[in] expression
166-
/// The method that will get called when the breakpoint is hit.
165+
/// @param[in] condition
166+
/// The condition expression to evaluate when the breakpoint is hit.
167167
//------------------------------------------------------------------
168-
void
169-
SetCondition (void *condition);
168+
void SetCondition (const char *condition);
169+
170+
//------------------------------------------------------------------
171+
/// Test the breakpoint location's condition in the Execution context passed in.
172+
///
173+
/// @param[in] exe_ctx
174+
/// The execution context in which to evaluate this expression.
175+
///
176+
/// @param[in] error
177+
/// Error messages will be written to this stream.
178+
///
179+
/// @return
180+
/// A thread plan to run to test the condition, or NULL if there is no condition.
181+
//------------------------------------------------------------------
182+
ThreadPlan *GetThreadPlanToTestCondition (ExecutionContext &exe_ctx, Stream &error);
183+
184+
//------------------------------------------------------------------
185+
/// Return a pointer to the text of the condition expression.
186+
///
187+
/// @return
188+
/// A pointer to the condition expression text, or NULL if no
189+
// condition has been set.
190+
//------------------------------------------------------------------
191+
const char *GetConditionText ();
170192

171193

172194
//------------------------------------------------------------------
@@ -211,6 +233,9 @@ class BreakpointLocation : public StoppointLocation
211233
//------------------------------------------------------------------
212234
bool
213235
IsResolved () const;
236+
237+
lldb::BreakpointSiteSP
238+
GetBreakpointSite() const;
214239

215240
//------------------------------------------------------------------
216241
// The next section are generic report functions.

lldb/include/lldb/Breakpoint/BreakpointOptions.h

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/lldb-private.h"
1919
#include "lldb/Core/Baton.h"
2020
#include "lldb/Core/StringList.h"
21+
#include "lldb/Expression/ClangUserExpression.h"
2122

2223
namespace lldb_private {
2324

@@ -88,7 +89,46 @@ class BreakpointOptions
8889
Baton *GetBaton ();
8990
const Baton *GetBaton () const;
9091
void ClearCallback ();
91-
92+
93+
//------------------------------------------------------------------
94+
// Condition
95+
//------------------------------------------------------------------
96+
//------------------------------------------------------------------
97+
/// Set the breakpoint option's condition.
98+
///
99+
/// @param[in] condition
100+
/// The condition expression to evaluate when the breakpoint is hit.
101+
//------------------------------------------------------------------
102+
void SetCondition (const char *condition);
103+
104+
//------------------------------------------------------------------
105+
/// Test the breakpoint condition in the Execution context passed in.
106+
///
107+
/// @param[in] exe_ctx
108+
/// The execution context in which to evaluate this expression.
109+
///
110+
/// @param[in] break_loc_sp
111+
/// A shared pointer to the location that we are testing thsi condition for.
112+
///
113+
/// @param[in] error
114+
/// Error messages will be written to this stream.
115+
///
116+
/// @return
117+
/// A thread plan to run to test the condition, or NULL if there is no thread plan.
118+
//------------------------------------------------------------------
119+
ThreadPlan *GetThreadPlanToTestCondition (ExecutionContext &exe_ctx,
120+
lldb::BreakpointLocationSP break_loc_sp,
121+
Stream &error);
122+
123+
//------------------------------------------------------------------
124+
/// Return a pointer to the text of the condition expression.
125+
///
126+
/// @return
127+
/// A pointer to the condition expression text, or NULL if no
128+
// condition has been set.
129+
//------------------------------------------------------------------
130+
const char *GetConditionText ();
131+
92132
//------------------------------------------------------------------
93133
// Enabled/Ignore Count
94134
//------------------------------------------------------------------
@@ -107,6 +147,12 @@ class BreakpointOptions
107147
void
108148
SetEnabled (bool enabled);
109149

150+
//------------------------------------------------------------------
151+
/// Set the breakpoint to ignore the next \a count breakpoint hits.
152+
/// @param[in] count
153+
/// The number of breakpoint hits to ignore.
154+
//------------------------------------------------------------------
155+
110156
void
111157
SetIgnoreCount (uint32_t n);
112158

@@ -118,12 +164,6 @@ class BreakpointOptions
118164
uint32_t
119165
GetIgnoreCount () const;
120166

121-
//------------------------------------------------------------------
122-
/// Set the breakpoint to ignore the next \a count breakpoint hits.
123-
/// @param[in] count
124-
/// The number of breakpoint hits to ignore.
125-
//------------------------------------------------------------------
126-
127167
//------------------------------------------------------------------
128168
/// Return the current thread spec for this option. This will return NULL if the no thread
129169
/// specifications have been set for this Option yet.
@@ -218,6 +258,7 @@ class BreakpointOptions
218258
bool m_enabled;
219259
uint32_t m_ignore_count; // Number of times to ignore this breakpoint
220260
std::auto_ptr<ThreadSpec> m_thread_spec_ap; // Thread for which this breakpoint will take
261+
std::auto_ptr<ClangUserExpression> m_condition_ap; // The condition to test.
221262

222263
};
223264

lldb/include/lldb/Core/Event.h

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,52 @@ class Event
134134
Dump (Stream *s) const;
135135

136136
EventData *
137-
GetData ();
137+
GetData ()
138+
{
139+
return m_data_ap.get();
140+
}
138141

139142
const EventData *
140-
GetData () const;
143+
GetData () const
144+
{
145+
return m_data_ap.get();
146+
}
147+
148+
void
149+
SetData (EventData *new_data)
150+
{
151+
m_data_ap.reset (new_data);
152+
}
141153

142154
uint32_t
143-
GetType () const;
155+
GetType () const
156+
{
157+
return m_type;
158+
}
159+
160+
void
161+
SetType (uint32_t new_type)
162+
{
163+
m_type = new_type;
164+
}
144165

145166
Broadcaster *
146-
GetBroadcaster () const;
147-
167+
GetBroadcaster () const
168+
{
169+
return m_broadcaster;
170+
}
171+
148172
bool
149-
BroadcasterIs (Broadcaster *broadcaster);
173+
BroadcasterIs (Broadcaster *broadcaster)
174+
{
175+
return broadcaster == m_broadcaster;
176+
}
150177

151178
void
152-
Clear();
179+
Clear()
180+
{
181+
m_data_ap.reset();
182+
}
153183

154184

155185
private:
@@ -164,7 +194,11 @@ class Event
164194
// know about it update the contained broadcaster so that events can be
165195
// popped off one queue and re-broadcast to others.
166196
void
167-
SetBroadcaster (Broadcaster *broadcaster);
197+
SetBroadcaster (Broadcaster *broadcaster)
198+
{
199+
m_broadcaster = broadcaster;
200+
}
201+
168202

169203
Broadcaster * m_broadcaster; // The broadcaster that sent this event
170204
uint32_t m_type; // The bit describing this event

lldb/include/lldb/Expression/ClangExpressionVariable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ struct ClangExpressionVariable
8989
/// The following values should stay valid for the life of the variable
9090
//----------------------------------------------------------------------
9191
std::string m_name; ///< The name of the variable
92-
TypeFromUser m_user_type; ///< The type of the variable according to some LLDB context; NULL if the type hasn't yet been migrated to one
92+
TypeFromUser m_user_type; ///< The type of the variable according to some LLDB context;
93+
///< NULL if the type hasn't yet been migrated to one
9394

9495
//----------------------------------------------------------------------
9596
/// The following values indicate where the variable originally came from

lldb/include/lldb/Expression/ClangUserExpression.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "lldb/lldb-private.h"
2525
#include "lldb/Core/ClangForward.h"
2626
#include "lldb/Expression/ClangExpression.h"
27+
#include "lldb/Expression/ClangExpressionVariable.h"
2728

2829
#include "llvm/ExecutionEngine/JITMemoryManager.h"
2930

@@ -90,7 +91,15 @@ class ClangUserExpression : public ClangExpression
9091
bool
9192
Execute (Stream &error_stream,
9293
ExecutionContext &exe_ctx,
93-
ClangExpressionVariable *& result);
94+
ClangExpressionVariable *&result);
95+
96+
ThreadPlan *
97+
GetThreadPlanToExecuteJITExpression (Stream &error_stream,
98+
ExecutionContext &exe_ctx);
99+
bool
100+
FinalizeJITExecution (Stream &error_stream,
101+
ExecutionContext &exe_ctx,
102+
ClangExpressionVariable *&result);
94103

95104
//------------------------------------------------------------------
96105
/// Return the string that the parser should parse. Must be a full
@@ -102,6 +111,15 @@ class ClangUserExpression : public ClangExpression
102111
return m_transformed_text.c_str();
103112
}
104113

114+
//------------------------------------------------------------------
115+
/// Return the string that the user typed.
116+
//------------------------------------------------------------------
117+
const char *
118+
GetUserText ()
119+
{
120+
return m_expr_text.c_str();
121+
}
122+
105123
//------------------------------------------------------------------
106124
/// Return the function name that should be used for executing the
107125
/// expression. Text() should contain the definition of this
@@ -181,6 +199,12 @@ class ClangUserExpression : public ClangExpression
181199
//------------------------------------------------------------------
182200
void
183201
ScanContext(ExecutionContext &exe_ctx);
202+
203+
bool
204+
PrepareToExecuteJITExpression (Stream &error_stream,
205+
ExecutionContext &exe_ctx,
206+
lldb::addr_t &struct_address,
207+
lldb::addr_t object_ptr);
184208

185209
std::string m_expr_text; ///< The text of the expression, as typed by the user
186210
std::string m_transformed_text; ///< The text of the expression, as send to the parser

lldb/include/lldb/Target/Process.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class Process :
232232
public ProcessInstanceSettings
233233
{
234234
friend class ThreadList;
235+
friend class ClangFunction; // For WaitForStateChangeEventsPrivate
235236

236237
public:
237238

@@ -316,7 +317,6 @@ friend class ThreadList;
316317
static bool
317318
SetUpdateStateOnRemoval (Event *event_ptr);
318319

319-
320320
private:
321321

322322
void
@@ -1592,12 +1592,12 @@ friend class ThreadList;
15921592

15931593
DynamicCheckerFunctions *GetDynamicCheckers()
15941594
{
1595-
return m_dynamic_checkers.get();
1595+
return m_dynamic_checkers_ap.get();
15961596
}
15971597

15981598
void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers)
15991599
{
1600-
m_dynamic_checkers.reset(dynamic_checkers);
1600+
m_dynamic_checkers_ap.reset(dynamic_checkers);
16011601
}
16021602

16031603
//------------------------------------------------------------------
@@ -1646,7 +1646,7 @@ friend class ThreadList;
16461646
BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend
16471647
///< to insert in the target.
16481648
ClangPersistentVariables m_persistent_vars; ///< These are the persistent variables associated with this process for the expression parser.
1649-
std::auto_ptr<DynamicCheckerFunctions> m_dynamic_checkers; ///< The functions used by the expression parser to validate data that expressions use.
1649+
std::auto_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use.
16501650
UnixSignals m_unix_signals; /// This is the current signal set for this process.
16511651
ConstString m_target_triple;
16521652
lldb::ABISP m_abi_sp;

lldb/include/lldb/Target/StopInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class StopInfo
9090
static lldb::StopInfoSP
9191
CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id);
9292

93+
// This creates a StopInfo for the thread where the should_stop is already set, and won't be recalculated.
94+
static lldb::StopInfoSP
95+
CreateStopReasonWithBreakpointSiteID (Thread &thread, lldb::break_id_t break_id, bool should_stop);
96+
9397
static lldb::StopInfoSP
9498
CreateStopReasonWithWatchpointID (Thread &thread, lldb::break_id_t watch_id);
9599

lldb/include/lldb/Target/Target.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ class Target :
204204

205205
const BreakpointList &
206206
GetBreakpointList(bool internal = false) const;
207+
208+
lldb::BreakpointSP
209+
GetLastCreatedBreakpoint ()
210+
{
211+
return m_last_created_breakpoint;
212+
}
207213

208214
lldb::BreakpointSP
209215
GetBreakpointByID (lldb::break_id_t break_id);
@@ -443,6 +449,7 @@ class Target :
443449
SectionLoadList m_section_load_list;
444450
BreakpointList m_breakpoint_list;
445451
BreakpointList m_internal_breakpoint_list;
452+
lldb::BreakpointSP m_last_created_breakpoint;
446453
// We want to tightly control the process destruction process so
447454
// we can correctly tear down everything that we need to, so the only
448455
// class that knows about the process lifespan is this target class.

0 commit comments

Comments
 (0)