Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 334d33a

Browse files
author
Greg Clayton
committedJan 30, 2012
SBFrame is now threadsafe using some extra tricks. One issue is that stack
frames might go away (the object itself, not the actual logical frame) when we are single stepping due to the way we currently sometimes end up flushing frames when stepping in/out/over. They later will come back to life represented by another object yet they have the same StackID. Now when you get a lldb::SBFrame object, it will track the frame it is initialized with until the thread goes away or the StackID no longer exists in the stack for the thread it was created on. It uses a weak_ptr to both the frame and thread and also stores the StackID. These three items allow us to determine when the stack frame object has gone away (the weak_ptr will be NULL) and allows us to find the correct frame again. In our test suite we had such cases where we were just getting lucky when something like this happened: 1 - stop at breakpoint 2 - get first frame in thread where we stopped 3 - run an expression that causes the program to JIT and run code 4 - run more expressions on the frame from step 2 which was very very luckily still around inside a shared pointer, yet, not part of the current thread (a new stack frame object had appeared with the same stack ID and depth). We now avoid all such issues and properly keep up to date, or we start returning errors when the frame doesn't exist and always responds with invalid answers. Also fixed the UserSettingsController (not going to rewrite this just yet) so that it doesn't crash on shutdown. Using weak_ptr's came in real handy to track when the master controller has already gone away and this allowed me to pull out the previous NotifyOwnerIsShuttingDown() patch as it is no longer needed. git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@149231 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 90c5214 commit 334d33a

27 files changed

+653
-503
lines changed
 

‎include/lldb/API/SBFrame.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace lldb {
1919
class SBFrame
2020
{
2121
public:
22+
typedef SHARED_PTR(lldb_private::StackFrameImpl) StackFrameImplSP;
2223
SBFrame ();
2324

2425
SBFrame (const lldb::SBFrame &rhs);
@@ -207,24 +208,13 @@ class SBFrame
207208
friend class lldb_private::ScriptInterpreterPython;
208209
#endif
209210

210-
#ifndef SWIG
211-
212-
lldb_private::StackFrame *
213-
operator->() const;
214-
215-
// Mimic shared pointer...
216-
lldb_private::StackFrame *
217-
get() const;
218-
219-
lldb::StackFrameSP &
220-
get_sp();
221-
222-
#endif
211+
lldb::StackFrameSP
212+
GetFrameSP() const;
223213

224214
void
225-
SetFrame (const lldb::StackFrameSP &lldb_object_sp);
215+
SetFrameSP (const lldb::StackFrameSP &lldb_object_sp);
226216

227-
lldb::StackFrameSP m_opaque_sp;
217+
StackFrameImplSP m_opaque_sp;
228218
};
229219

230220
} // namespace lldb

‎include/lldb/API/SBProcess.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,13 @@ class SBProcess
197197
friend class SBThread;
198198
friend class SBValue;
199199

200-
#ifndef SWIG
201-
202-
lldb_private::Process *
203-
operator->() const;
204-
205-
// Mimic shared pointer...
206-
lldb_private::Process *
207-
get() const;
208-
209-
#endif
210-
211-
212200
SBProcess (const lldb::ProcessSP &process_sp);
213201

202+
lldb::ProcessSP
203+
GetSP() const;
204+
214205
void
215-
SetProcess (const lldb::ProcessSP &process_sp);
206+
SetSP (const lldb::ProcessSP &process_sp);
216207

217208
lldb::ProcessSP m_opaque_sp;
218209
};

‎include/lldb/API/SBTarget.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,12 @@ class SBTarget
540540

541541
SBTarget (const lldb::TargetSP& target_sp);
542542

543-
void
544-
reset (const lldb::TargetSP& target_sp);
545-
546-
lldb_private::Target *
547-
operator ->() const;
543+
lldb::TargetSP
544+
GetSP () const;
548545

549-
lldb_private::Target *
550-
get() const;
546+
void
547+
SetSP (const lldb::TargetSP& target_sp);
551548

552-
const lldb::TargetSP &
553-
get_sp () const;
554549

555550
private:
556551
//------------------------------------------------------------------

‎include/lldb/Core/Debugger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DebuggerInstanceSettings : public InstanceSettings
5252
};
5353

5454

55-
DebuggerInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
55+
DebuggerInstanceSettings (const lldb::UserSettingsControllerSP &m_owner_sp, bool live_instance = true, const char *name = NULL);
5656

5757
DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs);
5858

‎include/lldb/Core/UserSettingsController.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ typedef struct
4949
std::vector<SettingEntry> instance_settings;
5050
} UserSettingDefinition;
5151

52-
class UserSettingsController
52+
class UserSettingsController :
53+
public std::tr1::enable_shared_from_this<UserSettingsController>
5354
{
5455
public:
5556

@@ -130,6 +131,11 @@ class UserSettingsController
130131
void
131132
RenameInstanceSettings (const char *old_name, const char *new_name);
132133

134+
void
135+
SetDefaultInstanceSettings (const lldb::InstanceSettingsSP &instance_settings_sp)
136+
{
137+
m_default_settings = instance_settings_sp;
138+
}
133139
// -------------------------------------------------------------------------
134140
// Public static methods
135141
// -------------------------------------------------------------------------
@@ -387,7 +393,7 @@ class InstanceSettings
387393
{
388394
public:
389395

390-
InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance = true);
396+
InstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, const char *instance_name, bool live_instance = true);
391397

392398
InstanceSettings (const InstanceSettings &rhs);
393399

@@ -399,9 +405,6 @@ class InstanceSettings
399405

400406
// Begin Pure Virtual Functions
401407

402-
virtual void
403-
NotifyOwnerIsShuttingDown ();
404-
405408
virtual void
406409
UpdateInstanceSettingsVariable (const ConstString &var_name,
407410
const char *index_value,
@@ -442,8 +445,7 @@ class InstanceSettings
442445

443446
protected:
444447

445-
UserSettingsController &m_owner;
446-
bool m_owner_is_live;
448+
lldb::UserSettingsControllerWP m_owner_wp;
447449
ConstString m_instance_name;
448450
};
449451

‎include/lldb/Target/Process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ProcessInstanceSettings : public InstanceSettings
5454
{
5555
public:
5656

57-
ProcessInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
57+
ProcessInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
5858

5959
ProcessInstanceSettings (const ProcessInstanceSettings &rhs);
6060

‎include/lldb/Target/Target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TargetInstanceSettings : public InstanceSettings
4343
public:
4444
static OptionEnumValueElement g_dynamic_value_types[];
4545

46-
TargetInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
46+
TargetInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
4747

4848
TargetInstanceSettings (const TargetInstanceSettings &rhs);
4949

‎include/lldb/Target/Thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ThreadInstanceSettings : public InstanceSettings
2525
{
2626
public:
2727

28-
ThreadInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
28+
ThreadInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
2929

3030
ThreadInstanceSettings (const ThreadInstanceSettings &rhs);
3131

‎include/lldb/lldb-forward.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class SectionList;
142142
class SourceManager;
143143
class SourceManagerImpl;
144144
class StackFrame;
145+
class StackFrameImpl;
145146
class StackFrameList;
146147
class StackID;
147148
class StopInfo;
@@ -293,6 +294,7 @@ namespace lldb {
293294
typedef std::tr1::shared_ptr<lldb_private::TypeImpl> TypeImplSP;
294295
typedef std::tr1::shared_ptr<lldb_private::FuncUnwinders> FuncUnwindersSP;
295296
typedef std::tr1::shared_ptr<lldb_private::UserSettingsController> UserSettingsControllerSP;
297+
typedef std::tr1::weak_ptr<lldb_private::UserSettingsController> UserSettingsControllerWP;
296298
typedef std::tr1::shared_ptr<lldb_private::UnwindPlan> UnwindPlanSP;
297299
typedef lldb_private::SharingPtr<lldb_private::ValueObject> ValueObjectSP;
298300
typedef std::tr1::shared_ptr<lldb_private::Value> ValueSP;

‎source/API/SBAddress.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,19 @@ SBAddress::GetLoadAddress (const SBTarget &target) const
170170
LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
171171

172172
lldb::addr_t addr = LLDB_INVALID_ADDRESS;
173+
TargetSP target_sp (target.GetSP());
173174
if (m_opaque_ap.get())
174175
{
175-
Mutex::Locker api_locker (target->GetAPIMutex());
176-
addr = m_opaque_ap->GetAddress().GetLoadAddress (target.get());
176+
Mutex::Locker api_locker (target_sp->GetAPIMutex());
177+
addr = m_opaque_ap->GetAddress().GetLoadAddress (target_sp.get());
177178
}
178179

179180
if (log)
180181
{
181182
if (addr == LLDB_INVALID_ADDRESS)
182-
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target.get());
183+
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target_sp.get());
183184
else
184-
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr);
185+
log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target_sp.get(), addr);
185186
}
186187

187188
return addr;

‎source/API/SBCommandInterpreter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,26 @@ SBCommandInterpreter::HasAliasOptions ()
188188
SBProcess
189189
SBCommandInterpreter::GetProcess ()
190190
{
191-
SBProcess process;
191+
SBProcess sb_process;
192+
ProcessSP process_sp;
192193
if (m_opaque_ptr)
193194
{
194195
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
195196
if (target_sp)
196197
{
197198
Mutex::Locker api_locker(target_sp->GetAPIMutex());
198-
process.SetProcess(target_sp->GetProcessSP());
199+
process_sp = target_sp->GetProcessSP();
200+
sb_process.SetSP(process_sp);
199201
}
200202
}
201203
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
202204

203205
if (log)
204206
log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)",
205-
m_opaque_ptr, process.get());
207+
m_opaque_ptr, process_sp.get());
206208

207209

208-
return process;
210+
return sb_process;
209211
}
210212

211213
CommandInterpreter *

0 commit comments

Comments
 (0)
This repository has been archived.