blob: ca192e1533867e0678a70e30e6c83ab80d5735ca [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBTarget.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytone0d378b2011-03-24 21:19:54 +000014#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Claytondea8cb42011-06-29 22:09:02 +000016#include "lldb/API/SBDebugger.h"
17#include "lldb/API/SBBreakpoint.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000018#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000020#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000022#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000023#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000024#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000025#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
41#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000042#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Greg Clayton1f746072012-08-29 21:13:06 +000050#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000051#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000052#include "lldb/Symbol/VariableList.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000053#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000055
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Target.h"
57#include "lldb/Target/TargetList.h"
58
59#include "lldb/Interpreter/CommandReturnObject.h"
60#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000061#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64using namespace lldb;
65using namespace lldb_private;
66
67#define DEFAULT_DISASM_BYTE_SIZE 32
68
Jim Ingham106d0282014-06-25 02:32:56 +000069
Greg Clayton0e615682012-02-24 05:03:03 +000070SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +000071 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000072{
73}
74
75SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +000076 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000077{
78 m_opaque_sp->SetProcessID (pid);
79}
80
81SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +000082 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000083{
84 if (path && path[0])
85 m_opaque_sp->GetExecutableFile().SetFile(path, false);
86 m_opaque_sp->SetWaitForLaunch (wait_for);
87}
88
89SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +000090 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000091{
92 *m_opaque_sp = *rhs.m_opaque_sp;
93}
94
Greg Claytonecc7c0d2012-03-07 23:52:51 +000095SBAttachInfo::~SBAttachInfo()
96{
97}
98
99lldb_private::ProcessAttachInfo &
100SBAttachInfo::ref ()
101{
102 return *m_opaque_sp;
103}
104
Greg Clayton0e615682012-02-24 05:03:03 +0000105SBAttachInfo &
106SBAttachInfo::operator = (const SBAttachInfo &rhs)
107{
108 if (this != &rhs)
109 *m_opaque_sp = *rhs.m_opaque_sp;
110 return *this;
111}
112
113lldb::pid_t
114SBAttachInfo::GetProcessID ()
115{
116 return m_opaque_sp->GetProcessID();
117}
118
119void
120SBAttachInfo::SetProcessID (lldb::pid_t pid)
121{
122 m_opaque_sp->SetProcessID (pid);
123}
124
125
126uint32_t
127SBAttachInfo::GetResumeCount ()
128{
129 return m_opaque_sp->GetResumeCount();
130}
131
132void
133SBAttachInfo::SetResumeCount (uint32_t c)
134{
135 m_opaque_sp->SetResumeCount (c);
136}
137
138const char *
139SBAttachInfo::GetProcessPluginName ()
140{
141 return m_opaque_sp->GetProcessPluginName();
142}
143
144void
145SBAttachInfo::SetProcessPluginName (const char *plugin_name)
146{
147 return m_opaque_sp->SetProcessPluginName (plugin_name);
148}
149
150void
151SBAttachInfo::SetExecutable (const char *path)
152{
153 if (path && path[0])
154 m_opaque_sp->GetExecutableFile().SetFile(path, false);
155 else
156 m_opaque_sp->GetExecutableFile().Clear();
157}
158
159void
160SBAttachInfo::SetExecutable (SBFileSpec exe_file)
161{
162 if (exe_file.IsValid())
163 m_opaque_sp->GetExecutableFile() = exe_file.ref();
164 else
165 m_opaque_sp->GetExecutableFile().Clear();
166}
167
168bool
169SBAttachInfo::GetWaitForLaunch ()
170{
171 return m_opaque_sp->GetWaitForLaunch();
172}
173
174void
175SBAttachInfo::SetWaitForLaunch (bool b)
176{
177 m_opaque_sp->SetWaitForLaunch (b);
178}
179
Jim Inghamcd16df92012-07-20 21:37:13 +0000180bool
181SBAttachInfo::GetIgnoreExisting ()
182{
183 return m_opaque_sp->GetIgnoreExisting();
184}
185
186void
187SBAttachInfo::SetIgnoreExisting (bool b)
188{
189 m_opaque_sp->SetIgnoreExisting (b);
190}
191
Greg Clayton0e615682012-02-24 05:03:03 +0000192uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000193SBAttachInfo::GetUserID()
194{
195 return m_opaque_sp->GetUserID();
196}
197
198uint32_t
199SBAttachInfo::GetGroupID()
200{
201 return m_opaque_sp->GetGroupID();
202}
203
204bool
205SBAttachInfo::UserIDIsValid ()
206{
207 return m_opaque_sp->UserIDIsValid();
208}
209
210bool
211SBAttachInfo::GroupIDIsValid ()
212{
213 return m_opaque_sp->GroupIDIsValid();
214}
215
216void
217SBAttachInfo::SetUserID (uint32_t uid)
218{
219 m_opaque_sp->SetUserID (uid);
220}
221
222void
223SBAttachInfo::SetGroupID (uint32_t gid)
224{
225 m_opaque_sp->SetGroupID (gid);
226}
227
228uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000229SBAttachInfo::GetEffectiveUserID()
230{
231 return m_opaque_sp->GetEffectiveUserID();
232}
233
234uint32_t
235SBAttachInfo::GetEffectiveGroupID()
236{
237 return m_opaque_sp->GetEffectiveGroupID();
238}
239
240bool
241SBAttachInfo::EffectiveUserIDIsValid ()
242{
243 return m_opaque_sp->EffectiveUserIDIsValid();
244}
245
246bool
247SBAttachInfo::EffectiveGroupIDIsValid ()
248{
249 return m_opaque_sp->EffectiveGroupIDIsValid ();
250}
251
252void
253SBAttachInfo::SetEffectiveUserID (uint32_t uid)
254{
255 m_opaque_sp->SetEffectiveUserID(uid);
256}
257
258void
259SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
260{
261 m_opaque_sp->SetEffectiveGroupID(gid);
262}
263
264lldb::pid_t
265SBAttachInfo::GetParentProcessID ()
266{
267 return m_opaque_sp->GetParentProcessID();
268}
269
270void
271SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
272{
273 m_opaque_sp->SetParentProcessID (pid);
274}
275
276bool
277SBAttachInfo::ParentProcessIDIsValid()
278{
279 return m_opaque_sp->ParentProcessIDIsValid();
280}
281
Greg Clayton8012cad2014-11-17 19:39:20 +0000282SBListener
283SBAttachInfo::GetListener ()
284{
285 return SBListener(m_opaque_sp->GetListener());
286}
287
288void
289SBAttachInfo::SetListener (SBListener &listener)
290{
291 m_opaque_sp->SetListener(listener.GetSP());
292}
Greg Clayton0e615682012-02-24 05:03:03 +0000293
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000294namespace {
295
296Error
297AttachToProcess (ProcessAttachInfo &attach_info, Target &target)
298{
299 Mutex::Locker api_locker (target.GetAPIMutex ());
300
301 auto process_sp = target.GetProcessSP ();
302 if (process_sp)
303 {
304 const auto state = process_sp->GetState ();
305 if (process_sp->IsAlive () && state == eStateConnected)
306 {
307 // If we are already connected, then we have already specified the
308 // listener, so if a valid listener is supplied, we need to error out
309 // to let the client know.
310 if (attach_info.GetListener ())
311 return Error ("process is connected and already has a listener, pass empty listener");
312 }
313 }
314
315 return target.Attach (attach_info, nullptr);
316}
317
318} // namespace
319
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320//----------------------------------------------------------------------
321// SBTarget constructor
322//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000323SBTarget::SBTarget () :
324 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000325{
326}
327
328SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000329 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330{
331}
332
333SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000334 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335{
336}
337
Greg Claytonefabb122010-11-05 23:17:00 +0000338const SBTarget&
339SBTarget::operator = (const SBTarget& rhs)
340{
341 if (this != &rhs)
342 m_opaque_sp = rhs.m_opaque_sp;
343 return *this;
344}
345
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000346//----------------------------------------------------------------------
347// Destructor
348//----------------------------------------------------------------------
349SBTarget::~SBTarget()
350{
351}
352
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000353const char *
354SBTarget::GetBroadcasterClassName ()
355{
356 return Target::GetStaticBroadcasterClass().AsCString();
357}
358
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359bool
360SBTarget::IsValid () const
361{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000362 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
365SBProcess
366SBTarget::GetProcess ()
367{
368 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000369 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000370 TargetSP target_sp(GetSP());
371 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000372 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000373 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000374 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000375 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000376
Greg Clayton5160ce52013-03-27 23:08:40 +0000377 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000378 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000379 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
380 static_cast<void*>(target_sp.get()),
381 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000382
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 return sb_process;
384}
385
Matthew Gardinerc928de32014-10-22 07:22:56 +0000386SBPlatform
387SBTarget::GetPlatform ()
388{
389 TargetSP target_sp(GetSP());
390 if (!target_sp)
391 return SBPlatform();
392
393 SBPlatform platform;
394 platform.m_opaque_sp = target_sp->GetPlatform();
395
396 return platform;
397}
398
Greg Clayton66111032010-06-23 01:19:29 +0000399SBDebugger
400SBTarget::GetDebugger () const
401{
402 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000403 TargetSP target_sp(GetSP());
404 if (target_sp)
405 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000406 return debugger;
407}
408
Jim Ingham270684d2011-03-31 00:01:24 +0000409SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000410SBTarget::LoadCore (const char *core_file)
411{
412 SBProcess sb_process;
413 TargetSP target_sp(GetSP());
414 if (target_sp)
415 {
416 FileSpec filespec(core_file, true);
417 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
418 NULL,
419 &filespec));
420 if (process_sp)
421 {
422 process_sp->LoadCore();
423 sb_process.SetSP (process_sp);
424 }
425 }
426 return sb_process;
427}
428
429SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000430SBTarget::LaunchSimple
431(
432 char const **argv,
433 char const **envp,
434 const char *working_directory
435)
436{
437 char *stdin_path = NULL;
438 char *stdout_path = NULL;
439 char *stderr_path = NULL;
440 uint32_t launch_flags = 0;
441 bool stop_at_entry = false;
442 SBError error;
443 SBListener listener = GetDebugger().GetListener();
444 return Launch (listener,
445 argv,
446 envp,
447 stdin_path,
448 stdout_path,
449 stderr_path,
450 working_directory,
451 launch_flags,
452 stop_at_entry,
453 error);
454}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000455
Greg Claytonfbb76342013-11-20 21:07:01 +0000456SBError
457SBTarget::Install()
458{
459 SBError sb_error;
460 TargetSP target_sp(GetSP());
461 if (target_sp)
462 {
463 Mutex::Locker api_locker (target_sp->GetAPIMutex());
464 sb_error.ref() = target_sp->Install(NULL);
465 }
466 return sb_error;
467}
468
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000469SBProcess
470SBTarget::Launch
471(
Greg Clayton4b045622011-02-03 21:28:34 +0000472 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000473 char const **argv,
474 char const **envp,
475 const char *stdin_path,
476 const char *stdout_path,
477 const char *stderr_path,
478 const char *working_directory,
479 uint32_t launch_flags, // See LaunchFlags
480 bool stop_at_entry,
481 lldb::SBError& error
482)
483{
Greg Clayton5160ce52013-03-27 23:08:40 +0000484 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000485
Greg Claytonacdbe812012-01-30 09:04:36 +0000486 SBProcess sb_process;
487 ProcessSP process_sp;
488 TargetSP target_sp(GetSP());
489
Caroline Ticeceb6b132010-10-26 03:11:13 +0000490 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000491 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000492 static_cast<void*>(target_sp.get()),
493 static_cast<void*>(argv), static_cast<void*>(envp),
494 stdin_path ? stdin_path : "NULL",
495 stdout_path ? stdout_path : "NULL",
496 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000497 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000498 launch_flags, stop_at_entry,
499 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000500
501 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000503 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000504
Zachary Turner6fd3f342015-02-02 18:50:01 +0000505 if (stop_at_entry)
506 launch_flags |= eLaunchFlagStopAtEntry;
507
Greg Clayton645bf542011-01-27 01:01:10 +0000508 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
509 launch_flags |= eLaunchFlagDisableASLR;
510
Greg Clayton2289fa42011-04-30 01:09:13 +0000511 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000512 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000513 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000514 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000515 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000516
Greg Claytonb9556ac2012-01-30 07:41:31 +0000517 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000518 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000519 if (state == eStateAttaching)
520 error.SetErrorString ("process attach is in progress");
521 else
522 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000523 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000524 }
Greg Clayton931180e2011-01-27 06:44:37 +0000525 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000526
Greg Clayton2289fa42011-04-30 01:09:13 +0000527 if (state == eStateConnected)
528 {
529 // If we are already connected, then we have already specified the
530 // listener, so if a valid listener is supplied, we need to error out
531 // to let the client know.
532 if (listener.IsValid())
533 {
534 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000535 return sb_process;
536 }
537 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000538
539 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
540 launch_flags |= eLaunchFlagDisableSTDIO;
541
542 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000543
Greg Claytonb09c5382013-12-13 17:20:18 +0000544 Module *exe_module = target_sp->GetExecutableModulePointer();
545 if (exe_module)
546 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
547 if (argv)
548 launch_info.GetArguments().AppendArguments (argv);
549 if (envp)
550 launch_info.GetEnvironmentEntries ().SetArguments (envp);
551
552 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000553 launch_info.SetListener(listener.GetSP());
554
555 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000556
Greg Claytonb09c5382013-12-13 17:20:18 +0000557 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000558 }
559 else
560 {
561 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000563
Caroline Tice20ad3c42010-10-29 21:48:37 +0000564 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000565 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000566 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
567 static_cast<void*>(target_sp.get()),
568 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000569
Greg Clayton5d5028b2010-10-06 03:53:16 +0000570 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571}
572
Greg Clayton0e615682012-02-24 05:03:03 +0000573SBProcess
574SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
575{
Greg Clayton5160ce52013-03-27 23:08:40 +0000576 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000577
Greg Clayton0e615682012-02-24 05:03:03 +0000578 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000579 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000580
Greg Clayton0e615682012-02-24 05:03:03 +0000581 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000582 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
583 static_cast<void*>(target_sp.get()));
584
Greg Clayton0e615682012-02-24 05:03:03 +0000585 if (target_sp)
586 {
587 Mutex::Locker api_locker (target_sp->GetAPIMutex());
588 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000589 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000590 ProcessSP process_sp = target_sp->GetProcessSP();
591 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000592 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000593 state = process_sp->GetState();
594
595 if (process_sp->IsAlive() && state != eStateConnected)
596 {
597 if (state == eStateAttaching)
598 error.SetErrorString ("process attach is in progress");
599 else
600 error.SetErrorString ("a process is already being debugged");
601 return sb_process;
602 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000603 }
Greg Clayton0e615682012-02-24 05:03:03 +0000604 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000605
606 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
607
Greg Clayton3e32ad62014-05-07 20:16:06 +0000608 if (!launch_info.GetExecutableFile())
609 {
610 Module *exe_module = target_sp->GetExecutableModulePointer();
611 if (exe_module)
612 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
613 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000614
615 const ArchSpec &arch_spec = target_sp->GetArchitecture();
616 if (arch_spec.IsValid())
617 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000618
Greg Clayton8012cad2014-11-17 19:39:20 +0000619 error.SetError (target_sp->Launch (launch_info, NULL));
Greg Claytonb09c5382013-12-13 17:20:18 +0000620 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000621 }
622 else
623 {
624 error.SetErrorString ("SBTarget is invalid");
625 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000626
Greg Clayton0e615682012-02-24 05:03:03 +0000627 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
628 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000629 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000630 static_cast<void*>(target_sp.get()),
631 static_cast<void*>(sb_process.GetSP().get()));
632
Greg Clayton0e615682012-02-24 05:03:03 +0000633 return sb_process;
634}
635
636lldb::SBProcess
637SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
638{
Greg Clayton5160ce52013-03-27 23:08:40 +0000639 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000640
Greg Clayton0e615682012-02-24 05:03:03 +0000641 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000642 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000643
Sean Callanan575a4542012-10-20 00:21:31 +0000644 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000645 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
646 static_cast<void*>(target_sp.get()));
647
Greg Clayton0e615682012-02-24 05:03:03 +0000648 if (target_sp)
649 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000650 ProcessAttachInfo &attach_info = sb_attach_info.ref();
651 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Greg Clayton0e615682012-02-24 05:03:03 +0000652 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000653 PlatformSP platform_sp = target_sp->GetPlatform();
654 // See if we can pre-verify if a process exists or not
655 if (platform_sp && platform_sp->IsConnected())
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000656 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000657 lldb::pid_t attach_pid = attach_info.GetProcessID();
658 ProcessInstanceInfo instance_info;
659 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
Han Ming Ongcec8c902012-02-29 00:12:56 +0000660 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000661 attach_info.SetUserID(instance_info.GetEffectiveUserID());
662 }
663 else
664 {
665 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
666 if (log)
Greg Clayton91e407e2012-09-27 00:03:39 +0000667 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000668 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
669 static_cast<void*>(target_sp.get()), error.GetCString());
Greg Clayton91e407e2012-09-27 00:03:39 +0000670 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000671 return sb_process;
Han Ming Ongcec8c902012-02-29 00:12:56 +0000672 }
673 }
Greg Clayton0e615682012-02-24 05:03:03 +0000674 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000675 error.SetError(AttachToProcess(attach_info, *target_sp));
676 if (error.Success())
677 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000678 }
679 else
680 {
681 error.SetErrorString ("SBTarget is invalid");
682 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000683
Sean Callanan575a4542012-10-20 00:21:31 +0000684 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000685 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000686 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000687 static_cast<void*>(sb_process.GetSP().get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000688
Greg Clayton0e615682012-02-24 05:03:03 +0000689 return sb_process;
690}
691
692
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000693#if defined(__APPLE__)
694
695lldb::SBProcess
696SBTarget::AttachToProcessWithID (SBListener &listener,
697 ::pid_t pid,
698 lldb::SBError& error)
699{
700 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
701}
702
703#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000704
705lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000706SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000707(
Greg Clayton4b045622011-02-03 21:28:34 +0000708 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000709 lldb::pid_t pid,// The process ID to attach to
710 SBError& error // An error explaining what went wrong if attach fails
711)
712{
Greg Clayton5160ce52013-03-27 23:08:40 +0000713 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000714
Greg Clayton524e60b2010-10-06 22:10:17 +0000715 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000716 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000717
718 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000719 log->Printf ("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
720 static_cast<void*>(target_sp.get()),
721 __FUNCTION__,
722 pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000723
Greg Claytonacdbe812012-01-30 09:04:36 +0000724 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000725 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000726 ProcessAttachInfo attach_info;
727 attach_info.SetProcessID (pid);
728 if (listener.IsValid())
729 attach_info.SetListener(listener.GetSP());
Greg Clayton0c74e782011-06-24 03:21:43 +0000730
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000731 ProcessInstanceInfo instance_info;
732 if (target_sp->GetPlatform ()->GetProcessInfo (pid, instance_info))
733 attach_info.SetUserID (instance_info.GetEffectiveUserID ());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000734
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000735 error.SetError (AttachToProcess (attach_info, *target_sp));
736 if (error.Success ())
737 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000738 }
739 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000740 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000741
Sean Callanan575a4542012-10-20 00:21:31 +0000742 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000743 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
744 static_cast<void*>(target_sp.get ()),
745 __FUNCTION__,
746 static_cast<void*>(sb_process.GetSP().get ()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000747 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000748}
749
750lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000751SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +0000752(
Greg Clayton4b045622011-02-03 21:28:34 +0000753 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000754 const char *name, // basename of process to attach to
755 bool wait_for, // if true wait for a new instance of "name" to be launched
756 SBError& error // An error explaining what went wrong if attach fails
757)
758{
Greg Clayton5160ce52013-03-27 23:08:40 +0000759 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000760
Greg Clayton524e60b2010-10-06 22:10:17 +0000761 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000762 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000763
Sean Callanan575a4542012-10-20 00:21:31 +0000764 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000765 log->Printf ("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
766 static_cast<void*>(target_sp.get()),
767 __FUNCTION__,
768 name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000769 wait_for ? "true" : "false");
770
Greg Claytonacdbe812012-01-30 09:04:36 +0000771 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000772 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000773 ProcessAttachInfo attach_info;
774 attach_info.GetExecutableFile().SetFile(name, false);
775 attach_info.SetWaitForLaunch(wait_for);
776 if (listener.IsValid())
777 attach_info.SetListener(listener.GetSP());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000778
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000779 error.SetError (AttachToProcess (attach_info, *target_sp));
780 if (error.Success ())
781 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000782 }
783 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000784 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000785
Sean Callanan575a4542012-10-20 00:21:31 +0000786 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000787 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000788 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000789 __FUNCTION__,
790 static_cast<void*>(sb_process.GetSP().get()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000791 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000792}
793
James McIlree9631aae2011-03-04 00:31:13 +0000794lldb::SBProcess
795SBTarget::ConnectRemote
796(
797 SBListener &listener,
798 const char *url,
799 const char *plugin_name,
800 SBError& error
801)
802{
Greg Clayton5160ce52013-03-27 23:08:40 +0000803 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000804
James McIlree9631aae2011-03-04 00:31:13 +0000805 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000806 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000807 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000808
Sean Callanan575a4542012-10-20 00:21:31 +0000809 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000810 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
811 static_cast<void*>(target_sp.get()), url, plugin_name);
812
Greg Claytonacdbe812012-01-30 09:04:36 +0000813 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000814 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000815 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +0000816 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000817 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000818 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000819 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000820
Greg Claytonb9556ac2012-01-30 07:41:31 +0000821 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000822 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000823 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000824 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +0000825 }
826 else
827 {
828 error.SetErrorString ("unable to create lldb_private::Process");
829 }
830 }
831 else
832 {
833 error.SetErrorString ("SBTarget is invalid");
834 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000835
Sean Callanan575a4542012-10-20 00:21:31 +0000836 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000837 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000838 static_cast<void*>(target_sp.get()),
839 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +0000840 return sb_process;
841}
842
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843SBFileSpec
844SBTarget::GetExecutable ()
845{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000846
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +0000848 TargetSP target_sp(GetSP());
849 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000851 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +0000852 if (exe_module)
853 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000855
Greg Clayton5160ce52013-03-27 23:08:40 +0000856 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000857 if (log)
858 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000859 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
860 static_cast<void*>(target_sp.get()),
861 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000862 }
863
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000864 return exe_file_spec;
865}
866
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000868SBTarget::operator == (const SBTarget &rhs) const
869{
Greg Clayton66111032010-06-23 01:19:29 +0000870 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871}
872
873bool
874SBTarget::operator != (const SBTarget &rhs) const
875{
Greg Clayton66111032010-06-23 01:19:29 +0000876 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877}
878
Greg Claytonb9556ac2012-01-30 07:41:31 +0000879lldb::TargetSP
880SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +0000881{
882 return m_opaque_sp;
883}
884
Greg Clayton66111032010-06-23 01:19:29 +0000885void
Greg Claytonb9556ac2012-01-30 07:41:31 +0000886SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +0000887{
888 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000889}
890
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000891lldb::SBAddress
892SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000893{
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000894 lldb::SBAddress sb_addr;
895 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +0000896 TargetSP target_sp(GetSP());
897 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000898 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000899 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +0000900 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000901 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000902 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000903
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000904 // We have a load address that isn't in a section, just return an address
905 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +0000906 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000907 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000908}
909
Matthew Gardinerc928de32014-10-22 07:22:56 +0000910lldb::SBAddress
911SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
912{
913 lldb::SBAddress sb_addr;
914 Address &addr = sb_addr.ref();
915 TargetSP target_sp(GetSP());
916 if (target_sp)
917 {
918 Mutex::Locker api_locker (target_sp->GetAPIMutex());
919 if (target_sp->ResolveFileAddress (file_addr, addr))
920 return sb_addr;
921 }
922
923 addr.SetRawAddress(file_addr);
924 return sb_addr;
925}
Greg Claytond5944cd2013-12-06 01:12:00 +0000926
927lldb::SBAddress
928SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
929{
930 lldb::SBAddress sb_addr;
931 Address &addr = sb_addr.ref();
932 TargetSP target_sp(GetSP());
933 if (target_sp)
934 {
935 Mutex::Locker api_locker (target_sp->GetAPIMutex());
936 if (target_sp->ResolveLoadAddress (vm_addr, addr))
937 return sb_addr;
938 }
939
940 // We have a load address that isn't in a section, just return an address
941 // with the offset filled in (the address) and the section set to NULL
942 addr.SetRawAddress(vm_addr);
943 return sb_addr;
944}
945
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000946SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +0000947SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
948 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000949{
950 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +0000951 if (addr.IsValid())
952 {
953 TargetSP target_sp(GetSP());
954 if (target_sp)
955 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
956 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000957 return sc;
958}
959
Matthew Gardinerc928de32014-10-22 07:22:56 +0000960size_t
961SBTarget::ReadMemory (const SBAddress addr,
962 void *buf,
963 size_t size,
964 lldb::SBError &error)
965{
966 SBError sb_error;
967 size_t bytes_read = 0;
968 TargetSP target_sp(GetSP());
969 if (target_sp)
970 {
971 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8691dc52014-11-04 00:56:30 +0000972 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
973 }
974 else
975 {
976 sb_error.SetErrorString("invalid target");
Matthew Gardinerc928de32014-10-22 07:22:56 +0000977 }
978
979 return bytes_read;
980}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000981
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000982SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000983SBTarget::BreakpointCreateByLocation (const char *file,
984 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000985{
Greg Clayton7481c202010-11-08 00:28:40 +0000986 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000987}
988
989SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000990SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
991 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000992{
Greg Clayton5160ce52013-03-27 23:08:40 +0000993 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000994
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000996 TargetSP target_sp(GetSP());
997 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000998 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000999 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001000
Greg Clayton1f746072012-08-29 21:13:06 +00001001 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001002 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001003 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001004 const bool hardware = false;
1005 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001006 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001007
1008 if (log)
1009 {
1010 SBStream sstr;
1011 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001012 char path[PATH_MAX];
1013 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001014 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1015 static_cast<void*>(target_sp.get()), path, line,
1016 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001017 }
1018
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019 return sb_bp;
1020}
1021
1022SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001023SBTarget::BreakpointCreateByName (const char *symbol_name,
1024 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025{
Greg Clayton5160ce52013-03-27 23:08:40 +00001026 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001027
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001028 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001029 TargetSP target_sp(GetSP());
1030 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001032 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033
Jim Inghama8558b62012-05-22 00:12:20 +00001034 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001035 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001036 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037 if (module_name && module_name[0])
1038 {
Jim Ingham969795f2011-09-21 01:17:13 +00001039 FileSpecList module_spec_list;
1040 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001041 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042 }
1043 else
1044 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001045 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001046 }
1047 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001048
Caroline Ticeceb6b132010-10-26 03:11:13 +00001049 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001050 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1051 static_cast<void*>(target_sp.get()), symbol_name,
1052 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001053
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001054 return sb_bp;
1055}
1056
Jim Ingham87df91b2011-09-23 00:54:11 +00001057lldb::SBBreakpoint
1058SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001059 const SBFileSpecList &module_list,
1060 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001061{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001062 uint32_t name_type_mask = eFunctionNameTypeAuto;
1063 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1064}
1065
1066lldb::SBBreakpoint
1067SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001068 uint32_t name_type_mask,
1069 const SBFileSpecList &module_list,
1070 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001071{
Greg Clayton5160ce52013-03-27 23:08:40 +00001072 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001073
1074 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001075 TargetSP target_sp(GetSP());
1076 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001077 {
Jim Inghama8558b62012-05-22 00:12:20 +00001078 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001079 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001080 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001081 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1082 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001083 comp_unit_list.get(),
1084 symbol_name,
1085 name_type_mask,
1086 skip_prologue,
1087 internal,
1088 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001089 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001090
Jim Ingham87df91b2011-09-23 00:54:11 +00001091 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001092 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1093 static_cast<void*>(target_sp.get()), symbol_name,
1094 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001095
1096 return sb_bp;
1097}
1098
Jim Inghamfab10e82012-03-06 00:37:27 +00001099lldb::SBBreakpoint
1100SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1101 uint32_t num_names,
1102 uint32_t name_type_mask,
1103 const SBFileSpecList &module_list,
1104 const SBFileSpecList &comp_unit_list)
1105{
Greg Clayton5160ce52013-03-27 23:08:40 +00001106 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001107
1108 SBBreakpoint sb_bp;
1109 TargetSP target_sp(GetSP());
1110 if (target_sp && num_names > 0)
1111 {
1112 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001113 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001114 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001115 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001116 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1117 comp_unit_list.get(),
1118 symbol_names,
1119 num_names,
1120 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001121 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001122 internal,
1123 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001124 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001125
Jim Inghamfab10e82012-03-06 00:37:27 +00001126 if (log)
1127 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001128 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1129 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001130 for (uint32_t i = 0 ; i < num_names; i++)
1131 {
1132 char sep;
1133 if (i < num_names - 1)
1134 sep = ',';
1135 else
1136 sep = '}';
1137 if (symbol_names[i] != NULL)
1138 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1139 else
1140 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001141 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001142 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1143 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001144 }
1145
1146 return sb_bp;
1147}
Jim Ingham87df91b2011-09-23 00:54:11 +00001148
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001149SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001150SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1151 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152{
Greg Clayton5160ce52013-03-27 23:08:40 +00001153 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001154
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001156 TargetSP target_sp(GetSP());
1157 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001158 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001159 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001161 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001162 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001163 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001164
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001165 if (module_name && module_name[0])
1166 {
Jim Ingham969795f2011-09-21 01:17:13 +00001167 FileSpecList module_spec_list;
1168 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001169
Greg Claytoneb023e72013-10-11 19:48:25 +00001170 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 }
1172 else
1173 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001174 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175 }
1176 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001177
1178 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001179 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1180 static_cast<void*>(target_sp.get()), symbol_name_regex,
1181 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001182
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001183 return sb_bp;
1184}
1185
Jim Ingham87df91b2011-09-23 00:54:11 +00001186lldb::SBBreakpoint
1187SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001188 const SBFileSpecList &module_list,
1189 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001190{
Greg Clayton5160ce52013-03-27 23:08:40 +00001191 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001192
Jim Ingham87df91b2011-09-23 00:54:11 +00001193 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001194 TargetSP target_sp(GetSP());
1195 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001196 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001197 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001198 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001199 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001200 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001201 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001202
Greg Claytoneb023e72013-10-11 19:48:25 +00001203 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001204 }
1205
1206 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001207 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1208 static_cast<void*>(target_sp.get()), symbol_name_regex,
1209 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001210
1211 return sb_bp;
1212}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213
1214SBBreakpoint
1215SBTarget::BreakpointCreateByAddress (addr_t address)
1216{
Greg Clayton5160ce52013-03-27 23:08:40 +00001217 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001218
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001220 TargetSP target_sp(GetSP());
1221 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001222 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001223 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001224 const bool hardware = false;
1225 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001226 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001227
Caroline Ticeceb6b132010-10-26 03:11:13 +00001228 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001229 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1230 static_cast<void*>(target_sp.get()),
1231 static_cast<uint64_t>(address),
1232 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001233
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001234 return sb_bp;
1235}
1236
Jim Ingham969795f2011-09-21 01:17:13 +00001237lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001238SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1239 const lldb::SBFileSpec &source_file,
1240 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001241{
Greg Clayton5160ce52013-03-27 23:08:40 +00001242 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001243
1244 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001245 TargetSP target_sp(GetSP());
1246 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001247 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001248 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001249 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001250 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001251 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001252 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001253
Jim Ingham969795f2011-09-21 01:17:13 +00001254 if (module_name && module_name[0])
1255 {
1256 FileSpecList module_spec_list;
1257 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001258
Greg Claytoneb023e72013-10-11 19:48:25 +00001259 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001260 }
1261 else
1262 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001263 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001264 }
1265 }
1266
1267 if (log)
1268 {
1269 char path[PATH_MAX];
1270 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001271 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1272 static_cast<void*>(target_sp.get()), source_regex, path,
1273 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001274 }
1275
1276 return sb_bp;
1277}
1278
Jim Ingham87df91b2011-09-23 00:54:11 +00001279lldb::SBBreakpoint
1280SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001281 const SBFileSpecList &module_list,
1282 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001283{
Greg Clayton5160ce52013-03-27 23:08:40 +00001284 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001285
1286 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001287 TargetSP target_sp(GetSP());
1288 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001289 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001290 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001291 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001292 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001293 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001294 }
1295
1296 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001297 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1298 static_cast<void*>(target_sp.get()), source_regex,
1299 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001300
1301 return sb_bp;
1302}
Jim Ingham969795f2011-09-21 01:17:13 +00001303
Jim Inghamfab10e82012-03-06 00:37:27 +00001304lldb::SBBreakpoint
1305SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001306 bool catch_bp,
1307 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001308{
Greg Clayton5160ce52013-03-27 23:08:40 +00001309 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001310
1311 SBBreakpoint sb_bp;
1312 TargetSP target_sp(GetSP());
1313 if (target_sp)
1314 {
1315 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001316 const bool hardware = false;
1317 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001318 }
1319
1320 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001321 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1322 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001323 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001324 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1325 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001326
1327 return sb_bp;
1328}
1329
Greg Clayton9fed0d82010-07-23 23:33:17 +00001330uint32_t
1331SBTarget::GetNumBreakpoints () const
1332{
Greg Claytonacdbe812012-01-30 09:04:36 +00001333 TargetSP target_sp(GetSP());
1334 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001335 {
1336 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001337 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001338 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001339 return 0;
1340}
1341
1342SBBreakpoint
1343SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1344{
1345 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001346 TargetSP target_sp(GetSP());
1347 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001348 {
1349 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001350 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001351 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001352 return sb_breakpoint;
1353}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354
1355bool
1356SBTarget::BreakpointDelete (break_id_t bp_id)
1357{
Greg Clayton5160ce52013-03-27 23:08:40 +00001358 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001359
Caroline Ticeceb6b132010-10-26 03:11:13 +00001360 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001361 TargetSP target_sp(GetSP());
1362 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001363 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001364 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1365 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001366 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001367
1368 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001369 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1370 static_cast<void*>(target_sp.get()),
1371 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001372
1373 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374}
1375
Johnny Chen5d043462011-09-26 22:40:50 +00001376SBBreakpoint
1377SBTarget::FindBreakpointByID (break_id_t bp_id)
1378{
Greg Clayton5160ce52013-03-27 23:08:40 +00001379 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001380
1381 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001382 TargetSP target_sp(GetSP());
1383 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001384 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001385 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1386 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001387 }
1388
1389 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001390 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1391 static_cast<void*>(target_sp.get()),
1392 static_cast<uint32_t>(bp_id),
1393 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001394
1395 return sb_breakpoint;
1396}
1397
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001398bool
1399SBTarget::EnableAllBreakpoints ()
1400{
Greg Claytonacdbe812012-01-30 09:04:36 +00001401 TargetSP target_sp(GetSP());
1402 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001403 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001404 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1405 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001406 return true;
1407 }
1408 return false;
1409}
1410
1411bool
1412SBTarget::DisableAllBreakpoints ()
1413{
Greg Claytonacdbe812012-01-30 09:04:36 +00001414 TargetSP target_sp(GetSP());
1415 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001417 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1418 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419 return true;
1420 }
1421 return false;
1422}
1423
1424bool
1425SBTarget::DeleteAllBreakpoints ()
1426{
Greg Claytonacdbe812012-01-30 09:04:36 +00001427 TargetSP target_sp(GetSP());
1428 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001430 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1431 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001432 return true;
1433 }
1434 return false;
1435}
1436
Johnny Chen5d043462011-09-26 22:40:50 +00001437uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001438SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001439{
Greg Claytonacdbe812012-01-30 09:04:36 +00001440 TargetSP target_sp(GetSP());
1441 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001442 {
Johnny Chen01a67862011-10-14 00:42:25 +00001443 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001444 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001445 }
1446 return 0;
1447}
1448
Greg Clayton1b282f92011-10-13 18:08:26 +00001449SBWatchpoint
1450SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001451{
Johnny Chen01a67862011-10-14 00:42:25 +00001452 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001453 TargetSP target_sp(GetSP());
1454 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001455 {
Johnny Chen01a67862011-10-14 00:42:25 +00001456 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001457 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001458 }
Johnny Chen01a67862011-10-14 00:42:25 +00001459 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001460}
1461
1462bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001463SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001464{
Greg Clayton5160ce52013-03-27 23:08:40 +00001465 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001466
1467 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001468 TargetSP target_sp(GetSP());
1469 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001470 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001471 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001472 Mutex::Locker locker;
1473 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001474 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001475 }
1476
1477 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001478 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1479 static_cast<void*>(target_sp.get()),
1480 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001481
1482 return result;
1483}
1484
Greg Clayton1b282f92011-10-13 18:08:26 +00001485SBWatchpoint
1486SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001487{
Greg Clayton5160ce52013-03-27 23:08:40 +00001488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001489
Greg Clayton1b282f92011-10-13 18:08:26 +00001490 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001491 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001492 TargetSP target_sp(GetSP());
1493 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001494 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001495 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001496 Mutex::Locker locker;
1497 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001498 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1499 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001500 }
1501
1502 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001503 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1504 static_cast<void*>(target_sp.get()),
1505 static_cast<uint32_t>(wp_id),
1506 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001507
Greg Clayton1b282f92011-10-13 18:08:26 +00001508 return sb_watchpoint;
1509}
1510
1511lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001512SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001513{
Greg Clayton5160ce52013-03-27 23:08:40 +00001514 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001515
Greg Clayton1b282f92011-10-13 18:08:26 +00001516 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001517 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001518 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001519 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001520 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001521 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001522 uint32_t watch_type = 0;
1523 if (read)
1524 watch_type |= LLDB_WATCH_TYPE_READ;
1525 if (write)
1526 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001527 if (watch_type == 0)
1528 {
1529 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1530 return sb_watchpoint;
1531 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001532
Johnny Chen7385a5a2012-05-31 22:56:36 +00001533 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001534 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001535 // This API doesn't take in a type, so we can't figure out what it is.
1536 ClangASTType *type = NULL;
1537 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001538 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001539 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001540 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001541
Greg Clayton1b282f92011-10-13 18:08:26 +00001542 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001543 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001544 static_cast<void*>(target_sp.get()), addr,
1545 static_cast<uint32_t>(size),
1546 static_cast<void*>(watchpoint_sp.get()));
1547
Greg Clayton1b282f92011-10-13 18:08:26 +00001548 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001549}
1550
1551bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001552SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001553{
Greg Claytonacdbe812012-01-30 09:04:36 +00001554 TargetSP target_sp(GetSP());
1555 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001556 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001557 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001558 Mutex::Locker locker;
1559 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001560 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001561 return true;
1562 }
1563 return false;
1564}
1565
1566bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001567SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001568{
Greg Claytonacdbe812012-01-30 09:04:36 +00001569 TargetSP target_sp(GetSP());
1570 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001571 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001572 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001573 Mutex::Locker locker;
1574 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001575 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001576 return true;
1577 }
1578 return false;
1579}
1580
Enrico Granata347c2aa2013-10-08 21:49:02 +00001581SBValue
1582SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1583{
1584 SBValue sb_value;
1585 lldb::ValueObjectSP new_value_sp;
1586 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1587 {
Enrico Granata972be532014-12-17 21:18:43 +00001588 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1589 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1590 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1591 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001592 }
1593 sb_value.SetSP(new_value_sp);
1594 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1595 if (log)
1596 {
1597 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001598 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1599 static_cast<void*>(m_opaque_sp.get()),
1600 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001601 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001602 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1603 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001604 }
1605 return sb_value;
1606}
1607
Enrico Granata972be532014-12-17 21:18:43 +00001608lldb::SBValue
1609SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1610{
1611 SBValue sb_value;
1612 lldb::ValueObjectSP new_value_sp;
1613 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1614 {
1615 DataExtractorSP extractor(*data);
1616 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1617 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1618 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1619 }
1620 sb_value.SetSP(new_value_sp);
1621 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1622 if (log)
1623 {
1624 if (new_value_sp)
1625 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1626 static_cast<void*>(m_opaque_sp.get()),
1627 new_value_sp->GetName().AsCString());
1628 else
1629 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1630 static_cast<void*>(m_opaque_sp.get()));
1631 }
1632 return sb_value;
1633}
1634
1635lldb::SBValue
1636SBTarget::CreateValueFromExpression (const char *name, const char* expr)
1637{
1638 SBValue sb_value;
1639 lldb::ValueObjectSP new_value_sp;
1640 if (IsValid() && name && *name && expr && *expr)
1641 {
1642 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1643 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1644 }
1645 sb_value.SetSP(new_value_sp);
1646 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1647 if (log)
1648 {
1649 if (new_value_sp)
1650 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1651 static_cast<void*>(m_opaque_sp.get()),
1652 new_value_sp->GetName().AsCString());
1653 else
1654 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
1655 static_cast<void*>(m_opaque_sp.get()));
1656 }
1657 return sb_value;
1658}
1659
Johnny Chen5d043462011-09-26 22:40:50 +00001660bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001661SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001662{
Greg Claytonacdbe812012-01-30 09:04:36 +00001663 TargetSP target_sp(GetSP());
1664 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001665 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001666 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001667 Mutex::Locker locker;
1668 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001669 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001670 return true;
1671 }
1672 return false;
1673}
1674
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001676lldb::SBModule
1677SBTarget::AddModule (const char *path,
1678 const char *triple,
1679 const char *uuid_cstr)
1680{
Greg Claytonb210aec2012-04-23 20:23:39 +00001681 return AddModule (path, triple, uuid_cstr, NULL);
1682}
1683
1684lldb::SBModule
1685SBTarget::AddModule (const char *path,
1686 const char *triple,
1687 const char *uuid_cstr,
1688 const char *symfile)
1689{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001690 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001691 TargetSP target_sp(GetSP());
1692 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001693 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001694 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001695 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001696 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001697
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001698 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001699 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001700
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001701 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001702 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001703 else
1704 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001705
1706 if (symfile)
1707 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001708
Greg Claytonb9a01b32012-02-26 05:51:37 +00001709 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001710 }
1711 return sb_module;
1712}
1713
Greg Clayton226cce22013-07-08 22:22:41 +00001714lldb::SBModule
1715SBTarget::AddModule (const SBModuleSpec &module_spec)
1716{
1717 lldb::SBModule sb_module;
1718 TargetSP target_sp(GetSP());
1719 if (target_sp)
1720 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1721 return sb_module;
1722}
1723
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001724bool
1725SBTarget::AddModule (lldb::SBModule &module)
1726{
Greg Claytonacdbe812012-01-30 09:04:36 +00001727 TargetSP target_sp(GetSP());
1728 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001729 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001730 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001731 return true;
1732 }
1733 return false;
1734}
1735
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001736uint32_t
1737SBTarget::GetNumModules () const
1738{
Greg Clayton5160ce52013-03-27 23:08:40 +00001739 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001740
Caroline Ticeceb6b132010-10-26 03:11:13 +00001741 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001742 TargetSP target_sp(GetSP());
1743 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001744 {
1745 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001746 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001747 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001748
1749 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001750 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1751 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001752
1753 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754}
1755
Greg Clayton48e42542010-07-30 20:12:55 +00001756void
1757SBTarget::Clear ()
1758{
Greg Clayton5160ce52013-03-27 23:08:40 +00001759 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001760
1761 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001762 log->Printf ("SBTarget(%p)::Clear ()",
1763 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001764
Greg Clayton48e42542010-07-30 20:12:55 +00001765 m_opaque_sp.reset();
1766}
1767
1768
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001769SBModule
1770SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1771{
1772 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001773 TargetSP target_sp(GetSP());
1774 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001775 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001776 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001777 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00001778 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001779 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001780 return sb_module;
1781}
1782
Greg Clayton13d19502012-01-29 06:07:39 +00001783lldb::ByteOrder
1784SBTarget::GetByteOrder ()
1785{
Greg Claytonacdbe812012-01-30 09:04:36 +00001786 TargetSP target_sp(GetSP());
1787 if (target_sp)
1788 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00001789 return eByteOrderInvalid;
1790}
1791
1792const char *
1793SBTarget::GetTriple ()
1794{
Greg Claytonacdbe812012-01-30 09:04:36 +00001795 TargetSP target_sp(GetSP());
1796 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00001797 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001798 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00001799 // Unique the string so we don't run into ownership issues since
1800 // the const strings put the string into the string pool once and
1801 // the strings never comes out
1802 ConstString const_triple (triple.c_str());
1803 return const_triple.GetCString();
1804 }
1805 return NULL;
1806}
1807
1808uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00001809SBTarget::GetDataByteSize ()
1810{
1811 TargetSP target_sp(GetSP());
1812 if (target_sp)
1813 {
1814 return target_sp->GetArchitecture().GetDataByteSize() ;
1815 }
1816 return 0;
1817}
1818
1819uint32_t
1820SBTarget::GetCodeByteSize ()
1821{
1822 TargetSP target_sp(GetSP());
1823 if (target_sp)
1824 {
1825 return target_sp->GetArchitecture().GetCodeByteSize() ;
1826 }
1827 return 0;
1828}
1829
1830uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00001831SBTarget::GetAddressByteSize()
1832{
Greg Claytonacdbe812012-01-30 09:04:36 +00001833 TargetSP target_sp(GetSP());
1834 if (target_sp)
1835 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00001836 return sizeof(void*);
1837}
1838
1839
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001840SBModule
1841SBTarget::GetModuleAtIndex (uint32_t idx)
1842{
Greg Clayton5160ce52013-03-27 23:08:40 +00001843 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001844
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001845 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001846 ModuleSP module_sp;
1847 TargetSP target_sp(GetSP());
1848 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001849 {
1850 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001851 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1852 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001853 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001854
1855 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001856 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1857 static_cast<void*>(target_sp.get()), idx,
1858 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001859
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860 return sb_module;
1861}
1862
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001863bool
1864SBTarget::RemoveModule (lldb::SBModule module)
1865{
Greg Claytonacdbe812012-01-30 09:04:36 +00001866 TargetSP target_sp(GetSP());
1867 if (target_sp)
1868 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001869 return false;
1870}
1871
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872
1873SBBroadcaster
1874SBTarget::GetBroadcaster () const
1875{
Greg Clayton5160ce52013-03-27 23:08:40 +00001876 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001877
Greg Claytonacdbe812012-01-30 09:04:36 +00001878 TargetSP target_sp(GetSP());
1879 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001880
Caroline Ticeceb6b132010-10-26 03:11:13 +00001881 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001882 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1883 static_cast<void*>(target_sp.get()),
1884 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001885
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886 return broadcaster;
1887}
1888
Caroline Ticedde9cff2010-09-20 05:20:02 +00001889bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001890SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001891{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001892 Stream &strm = description.ref();
1893
Greg Claytonacdbe812012-01-30 09:04:36 +00001894 TargetSP target_sp(GetSP());
1895 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00001896 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001897 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001898 }
1899 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001900 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001901
1902 return true;
1903}
1904
Greg Clayton5569e642012-02-06 01:44:54 +00001905lldb::SBSymbolContextList
1906SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00001907{
Greg Clayton5569e642012-02-06 01:44:54 +00001908 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00001909 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00001910 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001911 TargetSP target_sp(GetSP());
1912 if (target_sp)
1913 {
1914 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00001915 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00001916 const bool append = true;
1917 target_sp->GetImages().FindFunctions (ConstString(name),
1918 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001919 symbols_ok,
1920 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00001921 append,
1922 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00001923 }
Greg Claytonfe356d32011-06-21 01:34:41 +00001924 }
Greg Clayton5569e642012-02-06 01:44:54 +00001925 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00001926}
1927
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001928lldb::SBSymbolContextList
1929SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
1930{
1931 lldb::SBSymbolContextList sb_sc_list;
1932 if (name && name[0])
1933 {
1934 TargetSP target_sp(GetSP());
1935 if (target_sp)
1936 {
1937 std::string regexstr;
1938 switch (matchtype)
1939 {
1940 case eMatchTypeRegex:
1941 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
1942 break;
1943 case eMatchTypeStartsWith:
1944 regexstr = llvm::Regex::escape(name) + ".*";
1945 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1946 break;
1947 default:
1948 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
1949 break;
1950 }
1951 }
1952 }
1953 return sb_sc_list;
1954}
1955
Enrico Granata6f3533f2011-07-29 19:53:35 +00001956lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00001957SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001958{
Greg Claytonacdbe812012-01-30 09:04:36 +00001959 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001960 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001961 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001962 ConstString const_typename(typename_cstr);
1963 SymbolContext sc;
1964 const bool exact_match = false;
1965
1966 const ModuleList &module_list = target_sp->GetImages();
1967 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001968 for (size_t idx = 0; idx < count; idx++)
1969 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001970 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
1971 if (module_sp)
1972 {
1973 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
1974 if (type_sp)
1975 return SBType(type_sp);
1976 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001977 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001978
1979 // Didn't find the type in the symbols; try the Objective-C runtime
1980 // if one is installed
1981
1982 ProcessSP process_sp(target_sp->GetProcessSP());
1983
1984 if (process_sp)
1985 {
1986 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1987
1988 if (objc_language_runtime)
1989 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001990 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001991
Sean Callanan9998acd2014-12-05 01:21:59 +00001992 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001993 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001994 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001995
Sean Callanan9998acd2014-12-05 01:21:59 +00001996 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
1997 {
1998 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0]))
1999 {
2000 return SBType(type);
2001 }
2002 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002003 }
2004 }
2005 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002006
2007 // No matches, search for basic typename matches
2008 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2009 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002010 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002011 }
2012 return SBType();
2013}
2014
Greg Claytonb43165b2012-12-05 21:24:42 +00002015SBType
2016SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002017{
Greg Claytonacdbe812012-01-30 09:04:36 +00002018 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002019 if (target_sp)
2020 {
2021 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2022 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002023 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002024 }
2025 return SBType();
2026}
2027
2028
2029lldb::SBTypeList
2030SBTarget::FindTypes (const char* typename_cstr)
2031{
2032 SBTypeList sb_type_list;
2033 TargetSP target_sp(GetSP());
2034 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002035 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002036 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002037 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002038 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002039 SymbolContext sc;
2040 TypeList type_list;
2041
Greg Clayton29399a22012-04-06 17:41:13 +00002042 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002043 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002044 exact_match,
2045 UINT32_MAX,
2046 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002047
Greg Claytonb43165b2012-12-05 21:24:42 +00002048 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002049 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002050 for (size_t idx = 0; idx < num_matches; idx++)
2051 {
2052 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2053 if (type_sp)
2054 sb_type_list.Append(SBType(type_sp));
2055 }
2056 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002057
2058 // Try the Objective-C runtime if one is installed
2059
2060 ProcessSP process_sp(target_sp->GetProcessSP());
2061
2062 if (process_sp)
2063 {
2064 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2065
2066 if (objc_language_runtime)
2067 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002068 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00002069
Sean Callanan9998acd2014-12-05 01:21:59 +00002070 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00002071 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002072 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00002073
Sean Callanan9998acd2014-12-05 01:21:59 +00002074 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00002075 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002076 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00002077 {
Sean Callanan9998acd2014-12-05 01:21:59 +00002078 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl))
2079 {
2080 sb_type_list.Append(SBType(type));
2081 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002082 }
2083 }
2084 }
2085 }
2086 }
2087
2088 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002089 {
2090 // No matches, search for basic typename matches
2091 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2092 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002093 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002094 }
2095 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002096 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002097}
2098
Greg Claytondea8cb42011-06-29 22:09:02 +00002099SBValueList
2100SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2101{
2102 SBValueList sb_value_list;
2103
Greg Claytonacdbe812012-01-30 09:04:36 +00002104 TargetSP target_sp(GetSP());
2105 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002106 {
2107 VariableList variable_list;
2108 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002109 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2110 append,
2111 max_matches,
2112 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002113
2114 if (match_count > 0)
2115 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002116 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002117 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002118 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002119 for (uint32_t i=0; i<match_count; ++i)
2120 {
2121 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2122 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002123 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002124 }
2125 }
2126 }
2127
2128 return sb_value_list;
2129}
2130
Carlo Kok0fd6fd42014-09-19 19:38:19 +00002131SBValueList
2132SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
2133{
2134 SBValueList sb_value_list;
2135
2136 TargetSP target_sp(GetSP());
2137 if (name && target_sp)
2138 {
2139 VariableList variable_list;
2140 const bool append = true;
2141
2142 std::string regexstr;
2143 uint32_t match_count;
2144 switch (matchtype)
2145 {
2146 case eMatchTypeNormal:
2147 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2148 append,
2149 max_matches,
2150 variable_list);
2151 break;
2152 case eMatchTypeRegex:
2153 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2154 append,
2155 max_matches,
2156 variable_list);
2157 break;
2158 case eMatchTypeStartsWith:
2159 regexstr = llvm::Regex::escape(name) + ".*";
2160 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2161 append,
2162 max_matches,
2163 variable_list);
2164 break;
2165 }
2166
2167
2168 if (match_count > 0)
2169 {
2170 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2171 if (exe_scope == NULL)
2172 exe_scope = target_sp.get();
2173 for (uint32_t i = 0; i<match_count; ++i)
2174 {
2175 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2176 if (valobj_sp)
2177 sb_value_list.Append(SBValue(valobj_sp));
2178 }
2179 }
2180 }
2181
2182 return sb_value_list;
2183}
2184
2185
Enrico Granatabcd80b42013-01-16 18:53:52 +00002186lldb::SBValue
2187SBTarget::FindFirstGlobalVariable (const char* name)
2188{
2189 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2190 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2191 return sb_value_list.GetValueAtIndex(0);
2192 return SBValue();
2193}
2194
Jim Inghame37d6052011-09-13 00:29:56 +00002195SBSourceManager
2196SBTarget::GetSourceManager()
2197{
2198 SBSourceManager source_manager (*this);
2199 return source_manager;
2200}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002201
Sean Callanan50952e92011-12-14 23:49:37 +00002202lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002203SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2204{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002205 return ReadInstructions (base_addr, count, NULL);
2206}
2207
2208lldb::SBInstructionList
2209SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2210{
Greg Clayton9c766112012-03-06 22:24:44 +00002211 SBInstructionList sb_instructions;
2212
2213 TargetSP target_sp(GetSP());
2214 if (target_sp)
2215 {
2216 Address *addr_ptr = base_addr.get();
2217
2218 if (addr_ptr)
2219 {
2220 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2221 bool prefer_file_cache = false;
2222 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002223 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2224 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2225 prefer_file_cache,
2226 data.GetBytes(),
2227 data.GetByteSize(),
2228 error,
2229 &load_addr);
2230 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002231 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2232 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002233 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002234 *addr_ptr,
2235 data.GetBytes(),
2236 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002237 count,
2238 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002239 }
2240 }
2241
2242 return sb_instructions;
2243
2244}
2245
2246lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002247SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2248{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002249 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2250}
2251
2252lldb::SBInstructionList
2253SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2254{
Sean Callanan50952e92011-12-14 23:49:37 +00002255 SBInstructionList sb_instructions;
2256
Greg Claytonacdbe812012-01-30 09:04:36 +00002257 TargetSP target_sp(GetSP());
2258 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002259 {
2260 Address addr;
2261
2262 if (base_addr.get())
2263 addr = *base_addr.get();
2264
Greg Clayton3faf47c2013-03-28 23:42:53 +00002265 const bool data_from_file = true;
2266
Greg Claytonacdbe812012-01-30 09:04:36 +00002267 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002268 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002269 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002270 addr,
2271 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002272 size,
2273 UINT32_MAX,
2274 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002275 }
2276
2277 return sb_instructions;
2278}
2279
2280lldb::SBInstructionList
2281SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2282{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002283 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2284}
2285
2286lldb::SBInstructionList
2287SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2288{
2289 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002290}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002291
2292SBError
2293SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2294 lldb::addr_t section_base_addr)
2295{
2296 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002297 TargetSP target_sp(GetSP());
2298 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002299 {
2300 if (!section.IsValid())
2301 {
2302 sb_error.SetErrorStringWithFormat ("invalid section");
2303 }
2304 else
2305 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002306 SectionSP section_sp (section.GetSP());
2307 if (section_sp)
2308 {
2309 if (section_sp->IsThreadSpecific())
2310 {
2311 sb_error.SetErrorString ("thread specific sections are not yet supported");
2312 }
2313 else
2314 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002315 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002316 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002317 {
2318 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002319 if (process_sp)
2320 process_sp->Flush();
2321 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002322 }
2323 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002324 }
2325 }
2326 else
2327 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002328 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002329 }
2330 return sb_error;
2331}
2332
2333SBError
2334SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2335{
2336 SBError sb_error;
2337
Greg Claytonacdbe812012-01-30 09:04:36 +00002338 TargetSP target_sp(GetSP());
2339 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002340 {
2341 if (!section.IsValid())
2342 {
2343 sb_error.SetErrorStringWithFormat ("invalid section");
2344 }
2345 else
2346 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002347 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002348 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002349 {
2350 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002351 if (process_sp)
2352 process_sp->Flush();
2353 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002354 }
2355 }
2356 else
2357 {
2358 sb_error.SetErrorStringWithFormat ("invalid target");
2359 }
2360 return sb_error;
2361}
2362
2363SBError
2364SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2365{
2366 SBError sb_error;
2367
Greg Claytonacdbe812012-01-30 09:04:36 +00002368 TargetSP target_sp(GetSP());
2369 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002370 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002371 ModuleSP module_sp (module.GetSP());
2372 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002373 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002374 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002375 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002376 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002377 // The load was successful, make sure that at least some sections
2378 // changed before we notify that our module was loaded.
2379 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002380 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002381 ModuleList module_list;
2382 module_list.Append(module_sp);
2383 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002384 // Flush info in the process (stack frames, etc)
2385 ProcessSP process_sp (target_sp->GetProcessSP());
2386 if (process_sp)
2387 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002388 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002389 }
2390 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002391 else
2392 {
2393 sb_error.SetErrorStringWithFormat ("invalid module");
2394 }
2395
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002396 }
2397 else
2398 {
2399 sb_error.SetErrorStringWithFormat ("invalid target");
2400 }
2401 return sb_error;
2402}
2403
2404SBError
2405SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2406{
2407 SBError sb_error;
2408
2409 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002410 TargetSP target_sp(GetSP());
2411 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002412 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002413 ModuleSP module_sp (module.GetSP());
2414 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002415 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002416 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002417 if (objfile)
2418 {
2419 SectionList *section_list = objfile->GetSectionList();
2420 if (section_list)
2421 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002422 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002423
Greg Clayton3c947372013-01-29 01:17:09 +00002424 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002425 const size_t num_sections = section_list->GetSize();
2426 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2427 {
2428 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2429 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002430 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002431 }
2432 if (changed)
2433 {
2434 // Flush info in the process (stack frames, etc)
2435 ProcessSP process_sp (target_sp->GetProcessSP());
2436 if (process_sp)
2437 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002438 }
2439 }
2440 else
2441 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002442 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002443 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2444 }
2445 }
2446 else
2447 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002448 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002449 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2450 }
2451 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002452 else
2453 {
2454 sb_error.SetErrorStringWithFormat ("invalid module");
2455 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002456 }
2457 else
2458 {
2459 sb_error.SetErrorStringWithFormat ("invalid target");
2460 }
2461 return sb_error;
2462}
2463
2464
Greg Claytone14e1922012-12-04 02:22:16 +00002465lldb::SBSymbolContextList
2466SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2467{
2468 SBSymbolContextList sb_sc_list;
2469 if (name && name[0])
2470 {
2471 TargetSP target_sp(GetSP());
2472 if (target_sp)
2473 {
2474 bool append = true;
2475 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2476 symbol_type,
2477 *sb_sc_list,
2478 append);
2479 }
2480 }
2481 return sb_sc_list;
2482
2483}
2484
2485
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002486lldb::SBValue
2487SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2488{
Greg Clayton5160ce52013-03-27 23:08:40 +00002489 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2490 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002491 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002492 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002493 ValueObjectSP expr_value_sp;
2494 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002495 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002496 if (target_sp)
2497 {
2498 if (expr == NULL || expr[0] == '\0')
2499 {
2500 if (log)
2501 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2502 return expr_result;
2503 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002504
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002505 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2506 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002507
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002508 if (log)
2509 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002510
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002511 frame = exe_ctx.GetFramePtr();
2512 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002513
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002514 if (target)
2515 {
2516#ifdef LLDB_CONFIGURATION_DEBUG
2517 StreamString frame_description;
2518 if (frame)
2519 frame->DumpUsingSettingsFormat (&frame_description);
2520 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2521 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2522#endif
2523 exe_results = target->EvaluateExpression (expr,
2524 frame,
2525 expr_value_sp,
2526 options.ref());
2527
2528 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2529#ifdef LLDB_CONFIGURATION_DEBUG
2530 Host::SetCrashDescription (NULL);
2531#endif
2532 }
2533 else
2534 {
2535 if (log)
2536 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2537 }
2538 }
2539#ifndef LLDB_DISABLE_PYTHON
2540 if (expr_log)
2541 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002542 expr_result.GetValue(), expr_result.GetSummary());
2543
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002544 if (log)
2545 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002546 static_cast<void*>(frame), expr,
2547 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002548#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002549
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002550 return expr_result;
2551}
2552
Greg Clayton13fbb992013-02-01 00:47:49 +00002553
2554lldb::addr_t
2555SBTarget::GetStackRedZoneSize()
2556{
2557 TargetSP target_sp(GetSP());
2558 if (target_sp)
2559 {
2560 ABISP abi_sp;
2561 ProcessSP process_sp (target_sp->GetProcessSP());
2562 if (process_sp)
2563 abi_sp = process_sp->GetABI();
2564 else
2565 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2566 if (abi_sp)
2567 return abi_sp->GetRedZoneSize();
2568 }
2569 return 0;
2570}