blob: 3d5828c5fe007fa2023bcc4f8d511375b283a3cc [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"
61
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
63using namespace lldb;
64using namespace lldb_private;
65
66#define DEFAULT_DISASM_BYTE_SIZE 32
67
Greg Clayton38d1f052012-02-24 20:59:25 +000068SBLaunchInfo::SBLaunchInfo (const char **argv) :
69 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000070{
Greg Clayton38d1f052012-02-24 20:59:25 +000071 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
72 if (argv && argv[0])
73 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0e615682012-02-24 05:03:03 +000074}
75
Greg Claytonecc7c0d2012-03-07 23:52:51 +000076SBLaunchInfo::~SBLaunchInfo()
77{
78}
79
80lldb_private::ProcessLaunchInfo &
81SBLaunchInfo::ref ()
82{
83 return *m_opaque_sp;
84}
85
86
Greg Clayton0e615682012-02-24 05:03:03 +000087uint32_t
88SBLaunchInfo::GetUserID()
89{
90 return m_opaque_sp->GetUserID();
91}
92
93uint32_t
94SBLaunchInfo::GetGroupID()
95{
96 return m_opaque_sp->GetGroupID();
97}
98
99bool
100SBLaunchInfo::UserIDIsValid ()
101{
102 return m_opaque_sp->UserIDIsValid();
103}
104
105bool
106SBLaunchInfo::GroupIDIsValid ()
107{
108 return m_opaque_sp->GroupIDIsValid();
109}
110
111void
112SBLaunchInfo::SetUserID (uint32_t uid)
113{
114 m_opaque_sp->SetUserID (uid);
115}
116
117void
118SBLaunchInfo::SetGroupID (uint32_t gid)
119{
120 m_opaque_sp->SetGroupID (gid);
121}
122
Greg Clayton3e32ad62014-05-07 20:16:06 +0000123SBFileSpec
124SBLaunchInfo::GetExecutableFile ()
125{
126 return SBFileSpec (m_opaque_sp->GetExecutableFile());
127}
128
129void
130SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg)
131{
132 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
133}
134
Greg Clayton0e615682012-02-24 05:03:03 +0000135uint32_t
136SBLaunchInfo::GetNumArguments ()
137{
138 return m_opaque_sp->GetArguments().GetArgumentCount();
139}
140
141const char *
142SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
143{
144 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
145}
146
147void
148SBLaunchInfo::SetArguments (const char **argv, bool append)
149{
150 if (append)
151 {
152 if (argv)
153 m_opaque_sp->GetArguments().AppendArguments(argv);
154 }
155 else
156 {
157 if (argv)
158 m_opaque_sp->GetArguments().SetArguments(argv);
159 else
160 m_opaque_sp->GetArguments().Clear();
161 }
162}
163
164uint32_t
165SBLaunchInfo::GetNumEnvironmentEntries ()
166{
167 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
168}
169
170const char *
171SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
172{
173 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
174}
175
176void
177SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
178{
179 if (append)
180 {
181 if (envp)
182 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
183 }
184 else
185 {
186 if (envp)
187 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
188 else
189 m_opaque_sp->GetEnvironmentEntries().Clear();
190 }
191}
192
193void
194SBLaunchInfo::Clear ()
195{
196 m_opaque_sp->Clear();
197}
198
199const char *
200SBLaunchInfo::GetWorkingDirectory () const
201{
202 return m_opaque_sp->GetWorkingDirectory();
203}
204
205void
206SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
207{
208 m_opaque_sp->SetWorkingDirectory(working_dir);
209}
210
211uint32_t
212SBLaunchInfo::GetLaunchFlags ()
213{
214 return m_opaque_sp->GetFlags().Get();
215}
216
217void
218SBLaunchInfo::SetLaunchFlags (uint32_t flags)
219{
220 m_opaque_sp->GetFlags().Reset(flags);
221}
222
223const char *
224SBLaunchInfo::GetProcessPluginName ()
225{
226 return m_opaque_sp->GetProcessPluginName();
227}
228
229void
230SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
231{
232 return m_opaque_sp->SetProcessPluginName (plugin_name);
233}
234
235const char *
236SBLaunchInfo::GetShell ()
237{
238 return m_opaque_sp->GetShell();
239}
240
241void
242SBLaunchInfo::SetShell (const char * path)
243{
244 m_opaque_sp->SetShell (path);
245}
246
247uint32_t
248SBLaunchInfo::GetResumeCount ()
249{
250 return m_opaque_sp->GetResumeCount();
251}
252
253void
254SBLaunchInfo::SetResumeCount (uint32_t c)
255{
256 m_opaque_sp->SetResumeCount (c);
257}
258
259bool
260SBLaunchInfo::AddCloseFileAction (int fd)
261{
262 return m_opaque_sp->AppendCloseFileAction(fd);
263}
264
265bool
266SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
267{
268 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
269}
270
271bool
272SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
273{
274 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
275}
276
277bool
278SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
279{
280 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
281}
282
Jason Molendaa3329782014-03-29 18:54:20 +0000283void
284SBLaunchInfo::SetLaunchEventData (const char *data)
285{
286 m_opaque_sp->SetLaunchEventData (data);
287}
288
289const char *
290SBLaunchInfo::GetLaunchEventData () const
291{
292 return m_opaque_sp->GetLaunchEventData ();
293}
Greg Clayton0e615682012-02-24 05:03:03 +0000294
Jim Ingham106d0282014-06-25 02:32:56 +0000295void
296SBLaunchInfo::SetDetachOnError (bool enable)
297{
298 m_opaque_sp->SetDetachOnError (enable);
299}
300
301bool
302SBLaunchInfo::GetDetachOnError () const
303{
304 return m_opaque_sp->GetDetachOnError ();
305}
306
Greg Clayton0e615682012-02-24 05:03:03 +0000307SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000308 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000309{
310}
311
312SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000313 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000314{
315 m_opaque_sp->SetProcessID (pid);
316}
317
318SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000319 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000320{
321 if (path && path[0])
322 m_opaque_sp->GetExecutableFile().SetFile(path, false);
323 m_opaque_sp->SetWaitForLaunch (wait_for);
324}
325
326SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000327 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000328{
329 *m_opaque_sp = *rhs.m_opaque_sp;
330}
331
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000332SBAttachInfo::~SBAttachInfo()
333{
334}
335
336lldb_private::ProcessAttachInfo &
337SBAttachInfo::ref ()
338{
339 return *m_opaque_sp;
340}
341
Greg Clayton0e615682012-02-24 05:03:03 +0000342SBAttachInfo &
343SBAttachInfo::operator = (const SBAttachInfo &rhs)
344{
345 if (this != &rhs)
346 *m_opaque_sp = *rhs.m_opaque_sp;
347 return *this;
348}
349
350lldb::pid_t
351SBAttachInfo::GetProcessID ()
352{
353 return m_opaque_sp->GetProcessID();
354}
355
356void
357SBAttachInfo::SetProcessID (lldb::pid_t pid)
358{
359 m_opaque_sp->SetProcessID (pid);
360}
361
362
363uint32_t
364SBAttachInfo::GetResumeCount ()
365{
366 return m_opaque_sp->GetResumeCount();
367}
368
369void
370SBAttachInfo::SetResumeCount (uint32_t c)
371{
372 m_opaque_sp->SetResumeCount (c);
373}
374
375const char *
376SBAttachInfo::GetProcessPluginName ()
377{
378 return m_opaque_sp->GetProcessPluginName();
379}
380
381void
382SBAttachInfo::SetProcessPluginName (const char *plugin_name)
383{
384 return m_opaque_sp->SetProcessPluginName (plugin_name);
385}
386
387void
388SBAttachInfo::SetExecutable (const char *path)
389{
390 if (path && path[0])
391 m_opaque_sp->GetExecutableFile().SetFile(path, false);
392 else
393 m_opaque_sp->GetExecutableFile().Clear();
394}
395
396void
397SBAttachInfo::SetExecutable (SBFileSpec exe_file)
398{
399 if (exe_file.IsValid())
400 m_opaque_sp->GetExecutableFile() = exe_file.ref();
401 else
402 m_opaque_sp->GetExecutableFile().Clear();
403}
404
405bool
406SBAttachInfo::GetWaitForLaunch ()
407{
408 return m_opaque_sp->GetWaitForLaunch();
409}
410
411void
412SBAttachInfo::SetWaitForLaunch (bool b)
413{
414 m_opaque_sp->SetWaitForLaunch (b);
415}
416
Jim Inghamcd16df92012-07-20 21:37:13 +0000417bool
418SBAttachInfo::GetIgnoreExisting ()
419{
420 return m_opaque_sp->GetIgnoreExisting();
421}
422
423void
424SBAttachInfo::SetIgnoreExisting (bool b)
425{
426 m_opaque_sp->SetIgnoreExisting (b);
427}
428
Greg Clayton0e615682012-02-24 05:03:03 +0000429uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000430SBAttachInfo::GetUserID()
431{
432 return m_opaque_sp->GetUserID();
433}
434
435uint32_t
436SBAttachInfo::GetGroupID()
437{
438 return m_opaque_sp->GetGroupID();
439}
440
441bool
442SBAttachInfo::UserIDIsValid ()
443{
444 return m_opaque_sp->UserIDIsValid();
445}
446
447bool
448SBAttachInfo::GroupIDIsValid ()
449{
450 return m_opaque_sp->GroupIDIsValid();
451}
452
453void
454SBAttachInfo::SetUserID (uint32_t uid)
455{
456 m_opaque_sp->SetUserID (uid);
457}
458
459void
460SBAttachInfo::SetGroupID (uint32_t gid)
461{
462 m_opaque_sp->SetGroupID (gid);
463}
464
465uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000466SBAttachInfo::GetEffectiveUserID()
467{
468 return m_opaque_sp->GetEffectiveUserID();
469}
470
471uint32_t
472SBAttachInfo::GetEffectiveGroupID()
473{
474 return m_opaque_sp->GetEffectiveGroupID();
475}
476
477bool
478SBAttachInfo::EffectiveUserIDIsValid ()
479{
480 return m_opaque_sp->EffectiveUserIDIsValid();
481}
482
483bool
484SBAttachInfo::EffectiveGroupIDIsValid ()
485{
486 return m_opaque_sp->EffectiveGroupIDIsValid ();
487}
488
489void
490SBAttachInfo::SetEffectiveUserID (uint32_t uid)
491{
492 m_opaque_sp->SetEffectiveUserID(uid);
493}
494
495void
496SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
497{
498 m_opaque_sp->SetEffectiveGroupID(gid);
499}
500
501lldb::pid_t
502SBAttachInfo::GetParentProcessID ()
503{
504 return m_opaque_sp->GetParentProcessID();
505}
506
507void
508SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
509{
510 m_opaque_sp->SetParentProcessID (pid);
511}
512
513bool
514SBAttachInfo::ParentProcessIDIsValid()
515{
516 return m_opaque_sp->ParentProcessIDIsValid();
517}
518
519
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520//----------------------------------------------------------------------
521// SBTarget constructor
522//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000523SBTarget::SBTarget () :
524 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525{
526}
527
528SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000529 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530{
531}
532
533SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000534 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535{
536}
537
Greg Claytonefabb122010-11-05 23:17:00 +0000538const SBTarget&
539SBTarget::operator = (const SBTarget& rhs)
540{
541 if (this != &rhs)
542 m_opaque_sp = rhs.m_opaque_sp;
543 return *this;
544}
545
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546//----------------------------------------------------------------------
547// Destructor
548//----------------------------------------------------------------------
549SBTarget::~SBTarget()
550{
551}
552
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000553const char *
554SBTarget::GetBroadcasterClassName ()
555{
556 return Target::GetStaticBroadcasterClass().AsCString();
557}
558
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559bool
560SBTarget::IsValid () const
561{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000562 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563}
564
565SBProcess
566SBTarget::GetProcess ()
567{
568 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000569 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000570 TargetSP target_sp(GetSP());
571 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000572 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000573 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000574 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000575 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000576
Greg Clayton5160ce52013-03-27 23:08:40 +0000577 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000578 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000579 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
580 static_cast<void*>(target_sp.get()),
581 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000582
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 return sb_process;
584}
585
Greg Clayton66111032010-06-23 01:19:29 +0000586SBDebugger
587SBTarget::GetDebugger () const
588{
589 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000590 TargetSP target_sp(GetSP());
591 if (target_sp)
592 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000593 return debugger;
594}
595
Jim Ingham270684d2011-03-31 00:01:24 +0000596SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000597SBTarget::LoadCore (const char *core_file)
598{
599 SBProcess sb_process;
600 TargetSP target_sp(GetSP());
601 if (target_sp)
602 {
603 FileSpec filespec(core_file, true);
604 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
605 NULL,
606 &filespec));
607 if (process_sp)
608 {
609 process_sp->LoadCore();
610 sb_process.SetSP (process_sp);
611 }
612 }
613 return sb_process;
614}
615
616SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000617SBTarget::LaunchSimple
618(
619 char const **argv,
620 char const **envp,
621 const char *working_directory
622)
623{
624 char *stdin_path = NULL;
625 char *stdout_path = NULL;
626 char *stderr_path = NULL;
627 uint32_t launch_flags = 0;
628 bool stop_at_entry = false;
629 SBError error;
630 SBListener listener = GetDebugger().GetListener();
631 return Launch (listener,
632 argv,
633 envp,
634 stdin_path,
635 stdout_path,
636 stderr_path,
637 working_directory,
638 launch_flags,
639 stop_at_entry,
640 error);
641}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000642
Greg Claytonfbb76342013-11-20 21:07:01 +0000643SBError
644SBTarget::Install()
645{
646 SBError sb_error;
647 TargetSP target_sp(GetSP());
648 if (target_sp)
649 {
650 Mutex::Locker api_locker (target_sp->GetAPIMutex());
651 sb_error.ref() = target_sp->Install(NULL);
652 }
653 return sb_error;
654}
655
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000656SBProcess
657SBTarget::Launch
658(
Greg Clayton4b045622011-02-03 21:28:34 +0000659 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000660 char const **argv,
661 char const **envp,
662 const char *stdin_path,
663 const char *stdout_path,
664 const char *stderr_path,
665 const char *working_directory,
666 uint32_t launch_flags, // See LaunchFlags
667 bool stop_at_entry,
668 lldb::SBError& error
669)
670{
Greg Clayton5160ce52013-03-27 23:08:40 +0000671 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000672
Greg Claytonacdbe812012-01-30 09:04:36 +0000673 SBProcess sb_process;
674 ProcessSP process_sp;
675 TargetSP target_sp(GetSP());
676
Caroline Ticeceb6b132010-10-26 03:11:13 +0000677 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000678 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 +0000679 static_cast<void*>(target_sp.get()),
680 static_cast<void*>(argv), static_cast<void*>(envp),
681 stdin_path ? stdin_path : "NULL",
682 stdout_path ? stdout_path : "NULL",
683 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000684 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000685 launch_flags, stop_at_entry,
686 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000687
688 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000690 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000691
Greg Clayton645bf542011-01-27 01:01:10 +0000692 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
693 launch_flags |= eLaunchFlagDisableASLR;
694
Greg Clayton2289fa42011-04-30 01:09:13 +0000695 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000696 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000697 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000698 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000699 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000700
Greg Claytonb9556ac2012-01-30 07:41:31 +0000701 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000702 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000703 if (state == eStateAttaching)
704 error.SetErrorString ("process attach is in progress");
705 else
706 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000707 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000708 }
Greg Clayton931180e2011-01-27 06:44:37 +0000709 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000710
Greg Clayton2289fa42011-04-30 01:09:13 +0000711 if (state == eStateConnected)
712 {
713 // If we are already connected, then we have already specified the
714 // listener, so if a valid listener is supplied, we need to error out
715 // to let the client know.
716 if (listener.IsValid())
717 {
718 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000719 return sb_process;
720 }
721 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000722
723 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
724 launch_flags |= eLaunchFlagDisableSTDIO;
725
726 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000727
Greg Claytonb09c5382013-12-13 17:20:18 +0000728 Module *exe_module = target_sp->GetExecutableModulePointer();
729 if (exe_module)
730 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
731 if (argv)
732 launch_info.GetArguments().AppendArguments (argv);
733 if (envp)
734 launch_info.GetEnvironmentEntries ().SetArguments (envp);
735
736 if (listener.IsValid())
737 error.SetError (target_sp->Launch(listener.ref(), launch_info));
Greg Clayton2289fa42011-04-30 01:09:13 +0000738 else
Greg Claytonb09c5382013-12-13 17:20:18 +0000739 error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
Greg Clayton645bf542011-01-27 01:01:10 +0000740
Greg Claytonb09c5382013-12-13 17:20:18 +0000741 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000742 }
743 else
744 {
745 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000747
Caroline Tice20ad3c42010-10-29 21:48:37 +0000748 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000749 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000750 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
751 static_cast<void*>(target_sp.get()),
752 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000753
Greg Clayton5d5028b2010-10-06 03:53:16 +0000754 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755}
756
Greg Clayton0e615682012-02-24 05:03:03 +0000757SBProcess
758SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
759{
Greg Clayton5160ce52013-03-27 23:08:40 +0000760 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000761
Greg Clayton0e615682012-02-24 05:03:03 +0000762 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000763 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000764
Greg Clayton0e615682012-02-24 05:03:03 +0000765 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000766 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
767 static_cast<void*>(target_sp.get()));
768
Greg Clayton0e615682012-02-24 05:03:03 +0000769 if (target_sp)
770 {
771 Mutex::Locker api_locker (target_sp->GetAPIMutex());
772 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000773 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000774 ProcessSP process_sp = target_sp->GetProcessSP();
775 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000776 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000777 state = process_sp->GetState();
778
779 if (process_sp->IsAlive() && state != eStateConnected)
780 {
781 if (state == eStateAttaching)
782 error.SetErrorString ("process attach is in progress");
783 else
784 error.SetErrorString ("a process is already being debugged");
785 return sb_process;
786 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000787 }
Greg Clayton0e615682012-02-24 05:03:03 +0000788 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000789
790 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
791
Greg Clayton3e32ad62014-05-07 20:16:06 +0000792 if (!launch_info.GetExecutableFile())
793 {
794 Module *exe_module = target_sp->GetExecutableModulePointer();
795 if (exe_module)
796 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
797 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000798
799 const ArchSpec &arch_spec = target_sp->GetArchitecture();
800 if (arch_spec.IsValid())
801 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000802
Greg Claytonb09c5382013-12-13 17:20:18 +0000803 error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
804 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000805 }
806 else
807 {
808 error.SetErrorString ("SBTarget is invalid");
809 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000810
Greg Clayton0e615682012-02-24 05:03:03 +0000811 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
812 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000813 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000814 static_cast<void*>(target_sp.get()),
815 static_cast<void*>(sb_process.GetSP().get()));
816
Greg Clayton0e615682012-02-24 05:03:03 +0000817 return sb_process;
818}
819
820lldb::SBProcess
821SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
822{
Greg Clayton5160ce52013-03-27 23:08:40 +0000823 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000824
Greg Clayton0e615682012-02-24 05:03:03 +0000825 SBProcess sb_process;
826 ProcessSP process_sp;
827 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000828
Sean Callanan575a4542012-10-20 00:21:31 +0000829 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000830 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
831 static_cast<void*>(target_sp.get()));
832
Greg Clayton0e615682012-02-24 05:03:03 +0000833 if (target_sp)
834 {
835 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000836
Greg Clayton0e615682012-02-24 05:03:03 +0000837 StateType state = eStateInvalid;
838 process_sp = target_sp->GetProcessSP();
839 if (process_sp)
840 {
841 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000842
Greg Clayton0e615682012-02-24 05:03:03 +0000843 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000844 {
Greg Clayton0e615682012-02-24 05:03:03 +0000845 if (state == eStateAttaching)
846 error.SetErrorString ("process attach is in progress");
847 else
848 error.SetErrorString ("a process is already being debugged");
Sean Callanan575a4542012-10-20 00:21:31 +0000849 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000850 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000851 static_cast<void*>(target_sp.get()),
852 error.GetCString());
Greg Clayton0e615682012-02-24 05:03:03 +0000853 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000854 }
Greg Clayton0e615682012-02-24 05:03:03 +0000855 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000856
Greg Clayton0e615682012-02-24 05:03:03 +0000857 if (state != eStateConnected)
858 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
859
860 if (process_sp)
861 {
Greg Clayton0e615682012-02-24 05:03:03 +0000862 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000863 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000864 {
865 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton91e407e2012-09-27 00:03:39 +0000866 // See if we can pre-verify if a process exists or not
867 if (platform_sp && platform_sp->IsConnected())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000868 {
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000869 lldb::pid_t attach_pid = attach_info.GetProcessID();
Greg Clayton91e407e2012-09-27 00:03:39 +0000870 ProcessInstanceInfo instance_info;
871 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
872 {
873 attach_info.SetUserID(instance_info.GetEffectiveUserID());
874 }
875 else
876 {
Daniel Malead01b2952012-11-29 21:49:15 +0000877 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000878 if (log)
879 {
880 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000881 static_cast<void*>(target_sp.get()), error.GetCString());
Sean Callanan575a4542012-10-20 00:21:31 +0000882 }
Greg Clayton91e407e2012-09-27 00:03:39 +0000883 return sb_process;
884 }
Han Ming Ongcec8c902012-02-29 00:12:56 +0000885 }
886 }
Han Ming Ongbee98392012-02-29 19:16:40 +0000887 error.SetError (process_sp->Attach (attach_info));
888 if (error.Success())
889 {
890 sb_process.SetSP (process_sp);
891 // If we are doing synchronous mode, then wait for the
892 // process to stop!
893 if (target_sp->GetDebugger().GetAsyncExecution () == false)
894 process_sp->WaitForProcessToStop (NULL);
895 }
Greg Clayton0e615682012-02-24 05:03:03 +0000896 }
897 else
898 {
899 error.SetErrorString ("unable to create lldb_private::Process");
900 }
901 }
902 else
903 {
904 error.SetErrorString ("SBTarget is invalid");
905 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000906
Sean Callanan575a4542012-10-20 00:21:31 +0000907 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000908 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000909 static_cast<void*>(target_sp.get()),
910 static_cast<void*>(process_sp.get()));
911
Greg Clayton0e615682012-02-24 05:03:03 +0000912 return sb_process;
913}
914
915
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000916#if defined(__APPLE__)
917
918lldb::SBProcess
919SBTarget::AttachToProcessWithID (SBListener &listener,
920 ::pid_t pid,
921 lldb::SBError& error)
922{
923 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
924}
925
926#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000927
928lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000929SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000930(
Greg Clayton4b045622011-02-03 21:28:34 +0000931 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000932 lldb::pid_t pid,// The process ID to attach to
933 SBError& error // An error explaining what went wrong if attach fails
934)
935{
Greg Clayton5160ce52013-03-27 23:08:40 +0000936 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000937
Greg Clayton524e60b2010-10-06 22:10:17 +0000938 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000939 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000940 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000941
942 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000943 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...",
944 static_cast<void*>(target_sp.get()), pid);
945
Greg Claytonacdbe812012-01-30 09:04:36 +0000946 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000947 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000948 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0c74e782011-06-24 03:21:43 +0000949
950 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000951 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000952 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +0000953 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000954 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000955
Greg Claytonb9556ac2012-01-30 07:41:31 +0000956 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000957 {
Greg Clayton0c74e782011-06-24 03:21:43 +0000958 if (state == eStateAttaching)
959 error.SetErrorString ("process attach is in progress");
960 else
961 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +0000962 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000963 }
Greg Clayton0c74e782011-06-24 03:21:43 +0000964 }
965
966 if (state == eStateConnected)
967 {
968 // If we are already connected, then we have already specified the
969 // listener, so if a valid listener is supplied, we need to error out
970 // to let the client know.
971 if (listener.IsValid())
972 {
973 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +0000974 return sb_process;
975 }
976 }
Greg Clayton4b045622011-02-03 21:28:34 +0000977 else
Greg Clayton0c74e782011-06-24 03:21:43 +0000978 {
979 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000980 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000981 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000982 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000983 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000984 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000985 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000986 sb_process.SetSP (process_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000987
Greg Clayton144f3a92011-11-15 03:53:30 +0000988 ProcessAttachInfo attach_info;
989 attach_info.SetProcessID (pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000990
Han Ming Ong84647042012-02-25 01:07:38 +0000991 PlatformSP platform_sp = target_sp->GetPlatform();
992 ProcessInstanceInfo instance_info;
993 if (platform_sp->GetProcessInfo(pid, instance_info))
994 {
995 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ong84647042012-02-25 01:07:38 +0000996 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000997 error.SetError (process_sp->Attach (attach_info));
Greg Claytone2186ed2012-09-07 17:51:47 +0000998 if (error.Success())
999 {
1000 // If we are doing synchronous mode, then wait for the
1001 // process to stop!
1002 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Claytonb9556ac2012-01-30 07:41:31 +00001003 process_sp->WaitForProcessToStop (NULL);
Greg Claytone2186ed2012-09-07 17:51:47 +00001004 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001005 }
1006 else
1007 {
1008 error.SetErrorString ("unable to create lldb_private::Process");
1009 }
1010 }
1011 else
1012 {
1013 error.SetErrorString ("SBTarget is invalid");
1014 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001015
Sean Callanan575a4542012-10-20 00:21:31 +00001016 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001017 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001018 static_cast<void*>(target_sp.get()),
1019 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001020 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001021}
1022
1023lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +00001024SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +00001025(
Greg Clayton4b045622011-02-03 21:28:34 +00001026 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +00001027 const char *name, // basename of process to attach to
1028 bool wait_for, // if true wait for a new instance of "name" to be launched
1029 SBError& error // An error explaining what went wrong if attach fails
1030)
1031{
Greg Clayton5160ce52013-03-27 23:08:40 +00001032 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033
Greg Clayton524e60b2010-10-06 22:10:17 +00001034 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001035 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001036 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001037
Sean Callanan575a4542012-10-20 00:21:31 +00001038 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001039 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...",
1040 static_cast<void*>(target_sp.get()), name,
1041 wait_for ? "true" : "false");
1042
Greg Claytonacdbe812012-01-30 09:04:36 +00001043 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001044 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001045 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +00001046
Greg Clayton0c74e782011-06-24 03:21:43 +00001047 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +00001048 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001049 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +00001050 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001051 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001052
Greg Claytonb9556ac2012-01-30 07:41:31 +00001053 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001054 {
Greg Clayton0c74e782011-06-24 03:21:43 +00001055 if (state == eStateAttaching)
1056 error.SetErrorString ("process attach is in progress");
1057 else
1058 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001059 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001060 }
Greg Clayton0c74e782011-06-24 03:21:43 +00001061 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001062
Greg Clayton0c74e782011-06-24 03:21:43 +00001063 if (state == eStateConnected)
1064 {
1065 // If we are already connected, then we have already specified the
1066 // listener, so if a valid listener is supplied, we need to error out
1067 // to let the client know.
1068 if (listener.IsValid())
1069 {
1070 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001071 return sb_process;
1072 }
1073 }
Greg Clayton4b045622011-02-03 21:28:34 +00001074 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001075 {
1076 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001077 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001078 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001079 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001080 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001081
Greg Claytonb9556ac2012-01-30 07:41:31 +00001082 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001083 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001084 sb_process.SetSP (process_sp);
Greg Clayton144f3a92011-11-15 03:53:30 +00001085 ProcessAttachInfo attach_info;
1086 attach_info.GetExecutableFile().SetFile(name, false);
1087 attach_info.SetWaitForLaunch(wait_for);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001088 error.SetError (process_sp->Attach (attach_info));
Daniel Malead659dc12013-04-01 19:47:00 +00001089 if (error.Success())
1090 {
1091 // If we are doing synchronous mode, then wait for the
1092 // process to stop!
1093 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1094 process_sp->WaitForProcessToStop (NULL);
1095 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001096 }
1097 else
1098 {
1099 error.SetErrorString ("unable to create lldb_private::Process");
1100 }
1101 }
1102 else
1103 {
1104 error.SetErrorString ("SBTarget is invalid");
1105 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001106
Sean Callanan575a4542012-10-20 00:21:31 +00001107 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001108 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001109 static_cast<void*>(target_sp.get()),
1110 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001111 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001112}
1113
James McIlree9631aae2011-03-04 00:31:13 +00001114lldb::SBProcess
1115SBTarget::ConnectRemote
1116(
1117 SBListener &listener,
1118 const char *url,
1119 const char *plugin_name,
1120 SBError& error
1121)
1122{
Greg Clayton5160ce52013-03-27 23:08:40 +00001123 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001124
James McIlree9631aae2011-03-04 00:31:13 +00001125 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001126 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001127 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001128
Sean Callanan575a4542012-10-20 00:21:31 +00001129 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001130 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
1131 static_cast<void*>(target_sp.get()), url, plugin_name);
1132
Greg Claytonacdbe812012-01-30 09:04:36 +00001133 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001134 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001135 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +00001136 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001137 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001138 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001139 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001140
Greg Claytonb9556ac2012-01-30 07:41:31 +00001141 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001142 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001143 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +00001144 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +00001145 }
1146 else
1147 {
1148 error.SetErrorString ("unable to create lldb_private::Process");
1149 }
1150 }
1151 else
1152 {
1153 error.SetErrorString ("SBTarget is invalid");
1154 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001155
Sean Callanan575a4542012-10-20 00:21:31 +00001156 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001157 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001158 static_cast<void*>(target_sp.get()),
1159 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +00001160 return sb_process;
1161}
1162
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163SBFileSpec
1164SBTarget::GetExecutable ()
1165{
Caroline Ticeceb6b132010-10-26 03:11:13 +00001166
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +00001168 TargetSP target_sp(GetSP());
1169 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001170 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001171 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +00001172 if (exe_module)
1173 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001174 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001175
Greg Clayton5160ce52013-03-27 23:08:40 +00001176 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001177 if (log)
1178 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001179 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1180 static_cast<void*>(target_sp.get()),
1181 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001182 }
1183
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 return exe_file_spec;
1185}
1186
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188SBTarget::operator == (const SBTarget &rhs) const
1189{
Greg Clayton66111032010-06-23 01:19:29 +00001190 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191}
1192
1193bool
1194SBTarget::operator != (const SBTarget &rhs) const
1195{
Greg Clayton66111032010-06-23 01:19:29 +00001196 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197}
1198
Greg Claytonb9556ac2012-01-30 07:41:31 +00001199lldb::TargetSP
1200SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +00001201{
1202 return m_opaque_sp;
1203}
1204
Greg Clayton66111032010-06-23 01:19:29 +00001205void
Greg Claytonb9556ac2012-01-30 07:41:31 +00001206SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001207{
1208 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209}
1210
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001211lldb::SBAddress
1212SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001213{
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001214 lldb::SBAddress sb_addr;
1215 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +00001216 TargetSP target_sp(GetSP());
1217 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001218 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001219 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +00001220 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001221 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +00001222 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001223
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001224 // We have a load address that isn't in a section, just return an address
1225 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +00001226 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001227 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001228}
1229
Greg Claytond5944cd2013-12-06 01:12:00 +00001230
1231lldb::SBAddress
1232SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1233{
1234 lldb::SBAddress sb_addr;
1235 Address &addr = sb_addr.ref();
1236 TargetSP target_sp(GetSP());
1237 if (target_sp)
1238 {
1239 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1240 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1241 return sb_addr;
1242 }
1243
1244 // We have a load address that isn't in a section, just return an address
1245 // with the offset filled in (the address) and the section set to NULL
1246 addr.SetRawAddress(vm_addr);
1247 return sb_addr;
1248}
1249
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001250SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +00001251SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1252 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001253{
1254 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +00001255 if (addr.IsValid())
1256 {
1257 TargetSP target_sp(GetSP());
1258 if (target_sp)
1259 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1260 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001261 return sc;
1262}
1263
1264
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001266SBTarget::BreakpointCreateByLocation (const char *file,
1267 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268{
Greg Clayton7481c202010-11-08 00:28:40 +00001269 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270}
1271
1272SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001273SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1274 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275{
Greg Clayton5160ce52013-03-27 23:08:40 +00001276 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001277
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001279 TargetSP target_sp(GetSP());
1280 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001281 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001282 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001283
Greg Clayton1f746072012-08-29 21:13:06 +00001284 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001285 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001286 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001287 const bool hardware = false;
1288 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001289 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001290
1291 if (log)
1292 {
1293 SBStream sstr;
1294 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001295 char path[PATH_MAX];
1296 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001297 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1298 static_cast<void*>(target_sp.get()), path, line,
1299 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001300 }
1301
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 return sb_bp;
1303}
1304
1305SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001306SBTarget::BreakpointCreateByName (const char *symbol_name,
1307 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308{
Greg Clayton5160ce52013-03-27 23:08:40 +00001309 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001310
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001312 TargetSP target_sp(GetSP());
1313 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001315 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001316
Jim Inghama8558b62012-05-22 00:12:20 +00001317 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001318 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001319 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 if (module_name && module_name[0])
1321 {
Jim Ingham969795f2011-09-21 01:17:13 +00001322 FileSpecList module_spec_list;
1323 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001324 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325 }
1326 else
1327 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001328 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001329 }
1330 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001331
Caroline Ticeceb6b132010-10-26 03:11:13 +00001332 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001333 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1334 static_cast<void*>(target_sp.get()), symbol_name,
1335 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001336
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337 return sb_bp;
1338}
1339
Jim Ingham87df91b2011-09-23 00:54:11 +00001340lldb::SBBreakpoint
1341SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001342 const SBFileSpecList &module_list,
1343 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001344{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001345 uint32_t name_type_mask = eFunctionNameTypeAuto;
1346 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1347}
1348
1349lldb::SBBreakpoint
1350SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001351 uint32_t name_type_mask,
1352 const SBFileSpecList &module_list,
1353 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001354{
Greg Clayton5160ce52013-03-27 23:08:40 +00001355 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001356
1357 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001358 TargetSP target_sp(GetSP());
1359 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001360 {
Jim Inghama8558b62012-05-22 00:12:20 +00001361 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001362 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001363 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001364 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1365 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001366 comp_unit_list.get(),
1367 symbol_name,
1368 name_type_mask,
1369 skip_prologue,
1370 internal,
1371 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001372 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001373
Jim Ingham87df91b2011-09-23 00:54:11 +00001374 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001375 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1376 static_cast<void*>(target_sp.get()), symbol_name,
1377 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001378
1379 return sb_bp;
1380}
1381
Jim Inghamfab10e82012-03-06 00:37:27 +00001382lldb::SBBreakpoint
1383SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1384 uint32_t num_names,
1385 uint32_t name_type_mask,
1386 const SBFileSpecList &module_list,
1387 const SBFileSpecList &comp_unit_list)
1388{
Greg Clayton5160ce52013-03-27 23:08:40 +00001389 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001390
1391 SBBreakpoint sb_bp;
1392 TargetSP target_sp(GetSP());
1393 if (target_sp && num_names > 0)
1394 {
1395 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001396 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001397 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001398 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001399 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1400 comp_unit_list.get(),
1401 symbol_names,
1402 num_names,
1403 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001404 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001405 internal,
1406 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001407 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001408
Jim Inghamfab10e82012-03-06 00:37:27 +00001409 if (log)
1410 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001411 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1412 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001413 for (uint32_t i = 0 ; i < num_names; i++)
1414 {
1415 char sep;
1416 if (i < num_names - 1)
1417 sep = ',';
1418 else
1419 sep = '}';
1420 if (symbol_names[i] != NULL)
1421 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1422 else
1423 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001424 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001425 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1426 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001427 }
1428
1429 return sb_bp;
1430}
Jim Ingham87df91b2011-09-23 00:54:11 +00001431
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001432SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001433SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1434 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435{
Greg Clayton5160ce52013-03-27 23:08:40 +00001436 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001437
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001438 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001439 TargetSP target_sp(GetSP());
1440 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001442 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001444 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001445 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001446 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001447
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448 if (module_name && module_name[0])
1449 {
Jim Ingham969795f2011-09-21 01:17:13 +00001450 FileSpecList module_spec_list;
1451 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001452
Greg Claytoneb023e72013-10-11 19:48:25 +00001453 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 }
1455 else
1456 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001457 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458 }
1459 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001460
1461 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001462 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1463 static_cast<void*>(target_sp.get()), symbol_name_regex,
1464 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001465
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466 return sb_bp;
1467}
1468
Jim Ingham87df91b2011-09-23 00:54:11 +00001469lldb::SBBreakpoint
1470SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001471 const SBFileSpecList &module_list,
1472 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001473{
Greg Clayton5160ce52013-03-27 23:08:40 +00001474 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475
Jim Ingham87df91b2011-09-23 00:54:11 +00001476 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001477 TargetSP target_sp(GetSP());
1478 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001479 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001480 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001481 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001482 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001483 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001484 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001485
Greg Claytoneb023e72013-10-11 19:48:25 +00001486 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001487 }
1488
1489 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001490 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1491 static_cast<void*>(target_sp.get()), symbol_name_regex,
1492 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001493
1494 return sb_bp;
1495}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496
1497SBBreakpoint
1498SBTarget::BreakpointCreateByAddress (addr_t address)
1499{
Greg Clayton5160ce52013-03-27 23:08:40 +00001500 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001501
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001503 TargetSP target_sp(GetSP());
1504 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001505 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001506 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001507 const bool hardware = false;
1508 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001509 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001510
Caroline Ticeceb6b132010-10-26 03:11:13 +00001511 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001512 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1513 static_cast<void*>(target_sp.get()),
1514 static_cast<uint64_t>(address),
1515 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001516
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001517 return sb_bp;
1518}
1519
Jim Ingham969795f2011-09-21 01:17:13 +00001520lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001521SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1522 const lldb::SBFileSpec &source_file,
1523 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001524{
Greg Clayton5160ce52013-03-27 23:08:40 +00001525 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001526
1527 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001528 TargetSP target_sp(GetSP());
1529 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001530 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001531 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001532 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001533 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001534 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001535 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001536
Jim Ingham969795f2011-09-21 01:17:13 +00001537 if (module_name && module_name[0])
1538 {
1539 FileSpecList module_spec_list;
1540 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001541
Greg Claytoneb023e72013-10-11 19:48:25 +00001542 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001543 }
1544 else
1545 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001546 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001547 }
1548 }
1549
1550 if (log)
1551 {
1552 char path[PATH_MAX];
1553 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001554 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1555 static_cast<void*>(target_sp.get()), source_regex, path,
1556 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001557 }
1558
1559 return sb_bp;
1560}
1561
Jim Ingham87df91b2011-09-23 00:54:11 +00001562lldb::SBBreakpoint
1563SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001564 const SBFileSpecList &module_list,
1565 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001566{
Greg Clayton5160ce52013-03-27 23:08:40 +00001567 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001568
1569 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001570 TargetSP target_sp(GetSP());
1571 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001572 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001573 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001574 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001575 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001576 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001577 }
1578
1579 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001580 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1581 static_cast<void*>(target_sp.get()), source_regex,
1582 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001583
1584 return sb_bp;
1585}
Jim Ingham969795f2011-09-21 01:17:13 +00001586
Jim Inghamfab10e82012-03-06 00:37:27 +00001587lldb::SBBreakpoint
1588SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001589 bool catch_bp,
1590 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001591{
Greg Clayton5160ce52013-03-27 23:08:40 +00001592 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001593
1594 SBBreakpoint sb_bp;
1595 TargetSP target_sp(GetSP());
1596 if (target_sp)
1597 {
1598 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001599 const bool hardware = false;
1600 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001601 }
1602
1603 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001604 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1605 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001606 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001607 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1608 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001609
1610 return sb_bp;
1611}
1612
Greg Clayton9fed0d82010-07-23 23:33:17 +00001613uint32_t
1614SBTarget::GetNumBreakpoints () const
1615{
Greg Claytonacdbe812012-01-30 09:04:36 +00001616 TargetSP target_sp(GetSP());
1617 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001618 {
1619 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001620 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001621 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001622 return 0;
1623}
1624
1625SBBreakpoint
1626SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1627{
1628 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001629 TargetSP target_sp(GetSP());
1630 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001631 {
1632 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001633 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001634 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001635 return sb_breakpoint;
1636}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001637
1638bool
1639SBTarget::BreakpointDelete (break_id_t bp_id)
1640{
Greg Clayton5160ce52013-03-27 23:08:40 +00001641 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001642
Caroline Ticeceb6b132010-10-26 03:11:13 +00001643 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001644 TargetSP target_sp(GetSP());
1645 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001646 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001647 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1648 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001649 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001650
1651 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001652 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1653 static_cast<void*>(target_sp.get()),
1654 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001655
1656 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657}
1658
Johnny Chen5d043462011-09-26 22:40:50 +00001659SBBreakpoint
1660SBTarget::FindBreakpointByID (break_id_t bp_id)
1661{
Greg Clayton5160ce52013-03-27 23:08:40 +00001662 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001663
1664 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001665 TargetSP target_sp(GetSP());
1666 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001667 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001668 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1669 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001670 }
1671
1672 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001673 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1674 static_cast<void*>(target_sp.get()),
1675 static_cast<uint32_t>(bp_id),
1676 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001677
1678 return sb_breakpoint;
1679}
1680
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001681bool
1682SBTarget::EnableAllBreakpoints ()
1683{
Greg Claytonacdbe812012-01-30 09:04:36 +00001684 TargetSP target_sp(GetSP());
1685 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001687 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1688 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001689 return true;
1690 }
1691 return false;
1692}
1693
1694bool
1695SBTarget::DisableAllBreakpoints ()
1696{
Greg Claytonacdbe812012-01-30 09:04:36 +00001697 TargetSP target_sp(GetSP());
1698 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001700 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1701 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702 return true;
1703 }
1704 return false;
1705}
1706
1707bool
1708SBTarget::DeleteAllBreakpoints ()
1709{
Greg Claytonacdbe812012-01-30 09:04:36 +00001710 TargetSP target_sp(GetSP());
1711 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001712 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001713 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1714 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715 return true;
1716 }
1717 return false;
1718}
1719
Johnny Chen5d043462011-09-26 22:40:50 +00001720uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001721SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001722{
Greg Claytonacdbe812012-01-30 09:04:36 +00001723 TargetSP target_sp(GetSP());
1724 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001725 {
Johnny Chen01a67862011-10-14 00:42:25 +00001726 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001727 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001728 }
1729 return 0;
1730}
1731
Greg Clayton1b282f92011-10-13 18:08:26 +00001732SBWatchpoint
1733SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001734{
Johnny Chen01a67862011-10-14 00:42:25 +00001735 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001736 TargetSP target_sp(GetSP());
1737 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001738 {
Johnny Chen01a67862011-10-14 00:42:25 +00001739 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001740 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001741 }
Johnny Chen01a67862011-10-14 00:42:25 +00001742 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001743}
1744
1745bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001746SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001747{
Greg Clayton5160ce52013-03-27 23:08:40 +00001748 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001749
1750 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001751 TargetSP target_sp(GetSP());
1752 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001753 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001754 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001755 Mutex::Locker locker;
1756 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001757 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001758 }
1759
1760 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001761 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1762 static_cast<void*>(target_sp.get()),
1763 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001764
1765 return result;
1766}
1767
Greg Clayton1b282f92011-10-13 18:08:26 +00001768SBWatchpoint
1769SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001770{
Greg Clayton5160ce52013-03-27 23:08:40 +00001771 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001772
Greg Clayton1b282f92011-10-13 18:08:26 +00001773 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001774 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001775 TargetSP target_sp(GetSP());
1776 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001777 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001778 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001779 Mutex::Locker locker;
1780 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001781 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1782 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001783 }
1784
1785 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001786 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1787 static_cast<void*>(target_sp.get()),
1788 static_cast<uint32_t>(wp_id),
1789 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001790
Greg Clayton1b282f92011-10-13 18:08:26 +00001791 return sb_watchpoint;
1792}
1793
1794lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001795SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001796{
Greg Clayton5160ce52013-03-27 23:08:40 +00001797 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001798
Greg Clayton1b282f92011-10-13 18:08:26 +00001799 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001800 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001801 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001802 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001803 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001804 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001805 uint32_t watch_type = 0;
1806 if (read)
1807 watch_type |= LLDB_WATCH_TYPE_READ;
1808 if (write)
1809 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001810 if (watch_type == 0)
1811 {
1812 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1813 return sb_watchpoint;
1814 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001815
Johnny Chen7385a5a2012-05-31 22:56:36 +00001816 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001817 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001818 // This API doesn't take in a type, so we can't figure out what it is.
1819 ClangASTType *type = NULL;
1820 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001821 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001822 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001823 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001824
Greg Clayton1b282f92011-10-13 18:08:26 +00001825 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001826 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001827 static_cast<void*>(target_sp.get()), addr,
1828 static_cast<uint32_t>(size),
1829 static_cast<void*>(watchpoint_sp.get()));
1830
Greg Clayton1b282f92011-10-13 18:08:26 +00001831 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001832}
1833
1834bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001835SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001836{
Greg Claytonacdbe812012-01-30 09:04:36 +00001837 TargetSP target_sp(GetSP());
1838 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001839 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001840 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001841 Mutex::Locker locker;
1842 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001843 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001844 return true;
1845 }
1846 return false;
1847}
1848
1849bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001850SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001851{
Greg Claytonacdbe812012-01-30 09:04:36 +00001852 TargetSP target_sp(GetSP());
1853 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001854 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001855 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001856 Mutex::Locker locker;
1857 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001858 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001859 return true;
1860 }
1861 return false;
1862}
1863
Enrico Granata347c2aa2013-10-08 21:49:02 +00001864SBValue
1865SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1866{
1867 SBValue sb_value;
1868 lldb::ValueObjectSP new_value_sp;
1869 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1870 {
1871 lldb::addr_t address(addr.GetLoadAddress(*this));
1872 lldb::TypeImplSP type_impl_sp (type.GetSP());
Enrico Granatadc4db5a2013-10-29 00:28:35 +00001873 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001874 if (pointer_ast_type)
1875 {
1876 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001877
Enrico Granata347c2aa2013-10-08 21:49:02 +00001878 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1879 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1880 pointer_ast_type,
1881 ConstString(name),
1882 buffer,
1883 exe_ctx.GetByteOrder(),
1884 exe_ctx.GetAddressByteSize()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001885
Enrico Granata347c2aa2013-10-08 21:49:02 +00001886 if (ptr_result_valobj_sp)
1887 {
1888 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1889 Error err;
1890 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1891 if (new_value_sp)
1892 new_value_sp->SetName(ConstString(name));
1893 }
1894 }
1895 }
1896 sb_value.SetSP(new_value_sp);
1897 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1898 if (log)
1899 {
1900 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001901 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1902 static_cast<void*>(m_opaque_sp.get()),
1903 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001904 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001905 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1906 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001907 }
1908 return sb_value;
1909}
1910
Johnny Chen5d043462011-09-26 22:40:50 +00001911bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001912SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001913{
Greg Claytonacdbe812012-01-30 09:04:36 +00001914 TargetSP target_sp(GetSP());
1915 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001916 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001917 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001918 Mutex::Locker locker;
1919 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001920 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001921 return true;
1922 }
1923 return false;
1924}
1925
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001926
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001927lldb::SBModule
1928SBTarget::AddModule (const char *path,
1929 const char *triple,
1930 const char *uuid_cstr)
1931{
Greg Claytonb210aec2012-04-23 20:23:39 +00001932 return AddModule (path, triple, uuid_cstr, NULL);
1933}
1934
1935lldb::SBModule
1936SBTarget::AddModule (const char *path,
1937 const char *triple,
1938 const char *uuid_cstr,
1939 const char *symfile)
1940{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001941 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001942 TargetSP target_sp(GetSP());
1943 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001944 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001945 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001946 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001947 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001948
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001949 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001950 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001951
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001952 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001953 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001954 else
1955 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001956
1957 if (symfile)
1958 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001959
Greg Claytonb9a01b32012-02-26 05:51:37 +00001960 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001961 }
1962 return sb_module;
1963}
1964
Greg Clayton226cce22013-07-08 22:22:41 +00001965lldb::SBModule
1966SBTarget::AddModule (const SBModuleSpec &module_spec)
1967{
1968 lldb::SBModule sb_module;
1969 TargetSP target_sp(GetSP());
1970 if (target_sp)
1971 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1972 return sb_module;
1973}
1974
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001975bool
1976SBTarget::AddModule (lldb::SBModule &module)
1977{
Greg Claytonacdbe812012-01-30 09:04:36 +00001978 TargetSP target_sp(GetSP());
1979 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001980 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001981 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001982 return true;
1983 }
1984 return false;
1985}
1986
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987uint32_t
1988SBTarget::GetNumModules () const
1989{
Greg Clayton5160ce52013-03-27 23:08:40 +00001990 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001991
Caroline Ticeceb6b132010-10-26 03:11:13 +00001992 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001993 TargetSP target_sp(GetSP());
1994 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001995 {
1996 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001997 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001998 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001999
2000 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002001 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
2002 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002003
2004 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002005}
2006
Greg Clayton48e42542010-07-30 20:12:55 +00002007void
2008SBTarget::Clear ()
2009{
Greg Clayton5160ce52013-03-27 23:08:40 +00002010 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002011
2012 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002013 log->Printf ("SBTarget(%p)::Clear ()",
2014 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002015
Greg Clayton48e42542010-07-30 20:12:55 +00002016 m_opaque_sp.reset();
2017}
2018
2019
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020SBModule
2021SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2022{
2023 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002024 TargetSP target_sp(GetSP());
2025 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00002026 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002027 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002028 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00002029 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00002030 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002031 return sb_module;
2032}
2033
Greg Clayton13d19502012-01-29 06:07:39 +00002034lldb::ByteOrder
2035SBTarget::GetByteOrder ()
2036{
Greg Claytonacdbe812012-01-30 09:04:36 +00002037 TargetSP target_sp(GetSP());
2038 if (target_sp)
2039 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00002040 return eByteOrderInvalid;
2041}
2042
2043const char *
2044SBTarget::GetTriple ()
2045{
Greg Claytonacdbe812012-01-30 09:04:36 +00002046 TargetSP target_sp(GetSP());
2047 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00002048 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002049 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00002050 // Unique the string so we don't run into ownership issues since
2051 // the const strings put the string into the string pool once and
2052 // the strings never comes out
2053 ConstString const_triple (triple.c_str());
2054 return const_triple.GetCString();
2055 }
2056 return NULL;
2057}
2058
2059uint32_t
2060SBTarget::GetAddressByteSize()
2061{
Greg Claytonacdbe812012-01-30 09:04:36 +00002062 TargetSP target_sp(GetSP());
2063 if (target_sp)
2064 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00002065 return sizeof(void*);
2066}
2067
2068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069SBModule
2070SBTarget::GetModuleAtIndex (uint32_t idx)
2071{
Greg Clayton5160ce52013-03-27 23:08:40 +00002072 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002073
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002074 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002075 ModuleSP module_sp;
2076 TargetSP target_sp(GetSP());
2077 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002078 {
2079 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002080 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2081 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002082 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002083
2084 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002085 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2086 static_cast<void*>(target_sp.get()), idx,
2087 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002088
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089 return sb_module;
2090}
2091
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002092bool
2093SBTarget::RemoveModule (lldb::SBModule module)
2094{
Greg Claytonacdbe812012-01-30 09:04:36 +00002095 TargetSP target_sp(GetSP());
2096 if (target_sp)
2097 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002098 return false;
2099}
2100
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002101
2102SBBroadcaster
2103SBTarget::GetBroadcaster () const
2104{
Greg Clayton5160ce52013-03-27 23:08:40 +00002105 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002106
Greg Claytonacdbe812012-01-30 09:04:36 +00002107 TargetSP target_sp(GetSP());
2108 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002109
Caroline Ticeceb6b132010-10-26 03:11:13 +00002110 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002111 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2112 static_cast<void*>(target_sp.get()),
2113 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002114
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115 return broadcaster;
2116}
2117
Caroline Ticedde9cff2010-09-20 05:20:02 +00002118bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00002119SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00002120{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002121 Stream &strm = description.ref();
2122
Greg Claytonacdbe812012-01-30 09:04:36 +00002123 TargetSP target_sp(GetSP());
2124 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00002125 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002126 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002127 }
2128 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002129 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00002130
2131 return true;
2132}
2133
Greg Clayton5569e642012-02-06 01:44:54 +00002134lldb::SBSymbolContextList
2135SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00002136{
Greg Clayton5569e642012-02-06 01:44:54 +00002137 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00002138 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00002139 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002140 TargetSP target_sp(GetSP());
2141 if (target_sp)
2142 {
2143 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00002144 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00002145 const bool append = true;
2146 target_sp->GetImages().FindFunctions (ConstString(name),
2147 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002148 symbols_ok,
2149 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00002150 append,
2151 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00002152 }
Greg Claytonfe356d32011-06-21 01:34:41 +00002153 }
Greg Clayton5569e642012-02-06 01:44:54 +00002154 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00002155}
2156
Enrico Granata6f3533f2011-07-29 19:53:35 +00002157lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00002158SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002159{
Greg Claytonacdbe812012-01-30 09:04:36 +00002160 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002161 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002162 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002163 ConstString const_typename(typename_cstr);
2164 SymbolContext sc;
2165 const bool exact_match = false;
2166
2167 const ModuleList &module_list = target_sp->GetImages();
2168 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002169 for (size_t idx = 0; idx < count; idx++)
2170 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002171 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2172 if (module_sp)
2173 {
2174 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2175 if (type_sp)
2176 return SBType(type_sp);
2177 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00002178 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002179
2180 // Didn't find the type in the symbols; try the Objective-C runtime
2181 // if one is installed
2182
2183 ProcessSP process_sp(target_sp->GetProcessSP());
2184
2185 if (process_sp)
2186 {
2187 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2188
2189 if (objc_language_runtime)
2190 {
2191 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2192
2193 if (objc_type_vendor)
2194 {
2195 std::vector <ClangASTType> types;
2196
2197 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2198 return SBType(types[0]);
2199 }
2200 }
2201 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002202
2203 // No matches, search for basic typename matches
2204 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2205 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002206 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002207 }
2208 return SBType();
2209}
2210
Greg Claytonb43165b2012-12-05 21:24:42 +00002211SBType
2212SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002213{
Greg Claytonacdbe812012-01-30 09:04:36 +00002214 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002215 if (target_sp)
2216 {
2217 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2218 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002219 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002220 }
2221 return SBType();
2222}
2223
2224
2225lldb::SBTypeList
2226SBTarget::FindTypes (const char* typename_cstr)
2227{
2228 SBTypeList sb_type_list;
2229 TargetSP target_sp(GetSP());
2230 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002231 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002232 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002233 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002234 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002235 SymbolContext sc;
2236 TypeList type_list;
2237
Greg Clayton29399a22012-04-06 17:41:13 +00002238 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002239 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002240 exact_match,
2241 UINT32_MAX,
2242 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002243
Greg Claytonb43165b2012-12-05 21:24:42 +00002244 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002245 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002246 for (size_t idx = 0; idx < num_matches; idx++)
2247 {
2248 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2249 if (type_sp)
2250 sb_type_list.Append(SBType(type_sp));
2251 }
2252 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002253
2254 // Try the Objective-C runtime if one is installed
2255
2256 ProcessSP process_sp(target_sp->GetProcessSP());
2257
2258 if (process_sp)
2259 {
2260 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2261
2262 if (objc_language_runtime)
2263 {
2264 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2265
2266 if (objc_type_vendor)
2267 {
2268 std::vector <ClangASTType> types;
2269
2270 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2271 {
2272 for (ClangASTType &type : types)
2273 {
2274 sb_type_list.Append(SBType(type));
2275 }
2276 }
2277 }
2278 }
2279 }
2280
2281 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002282 {
2283 // No matches, search for basic typename matches
2284 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2285 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002286 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002287 }
2288 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002289 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002290}
2291
Greg Claytondea8cb42011-06-29 22:09:02 +00002292SBValueList
2293SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2294{
2295 SBValueList sb_value_list;
2296
Greg Claytonacdbe812012-01-30 09:04:36 +00002297 TargetSP target_sp(GetSP());
2298 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002299 {
2300 VariableList variable_list;
2301 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002302 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2303 append,
2304 max_matches,
2305 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002306
2307 if (match_count > 0)
2308 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002309 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002310 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002311 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002312 for (uint32_t i=0; i<match_count; ++i)
2313 {
2314 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2315 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002316 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002317 }
2318 }
2319 }
2320
2321 return sb_value_list;
2322}
2323
Enrico Granatabcd80b42013-01-16 18:53:52 +00002324lldb::SBValue
2325SBTarget::FindFirstGlobalVariable (const char* name)
2326{
2327 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2328 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2329 return sb_value_list.GetValueAtIndex(0);
2330 return SBValue();
2331}
2332
Jim Inghame37d6052011-09-13 00:29:56 +00002333SBSourceManager
2334SBTarget::GetSourceManager()
2335{
2336 SBSourceManager source_manager (*this);
2337 return source_manager;
2338}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002339
Sean Callanan50952e92011-12-14 23:49:37 +00002340lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002341SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2342{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002343 return ReadInstructions (base_addr, count, NULL);
2344}
2345
2346lldb::SBInstructionList
2347SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2348{
Greg Clayton9c766112012-03-06 22:24:44 +00002349 SBInstructionList sb_instructions;
2350
2351 TargetSP target_sp(GetSP());
2352 if (target_sp)
2353 {
2354 Address *addr_ptr = base_addr.get();
2355
2356 if (addr_ptr)
2357 {
2358 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2359 bool prefer_file_cache = false;
2360 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002361 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2362 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2363 prefer_file_cache,
2364 data.GetBytes(),
2365 data.GetByteSize(),
2366 error,
2367 &load_addr);
2368 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002369 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2370 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002371 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002372 *addr_ptr,
2373 data.GetBytes(),
2374 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002375 count,
2376 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002377 }
2378 }
2379
2380 return sb_instructions;
2381
2382}
2383
2384lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002385SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2386{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002387 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2388}
2389
2390lldb::SBInstructionList
2391SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2392{
Sean Callanan50952e92011-12-14 23:49:37 +00002393 SBInstructionList sb_instructions;
2394
Greg Claytonacdbe812012-01-30 09:04:36 +00002395 TargetSP target_sp(GetSP());
2396 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002397 {
2398 Address addr;
2399
2400 if (base_addr.get())
2401 addr = *base_addr.get();
2402
Greg Clayton3faf47c2013-03-28 23:42:53 +00002403 const bool data_from_file = true;
2404
Greg Claytonacdbe812012-01-30 09:04:36 +00002405 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002406 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002407 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002408 addr,
2409 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002410 size,
2411 UINT32_MAX,
2412 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002413 }
2414
2415 return sb_instructions;
2416}
2417
2418lldb::SBInstructionList
2419SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2420{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002421 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2422}
2423
2424lldb::SBInstructionList
2425SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2426{
2427 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002428}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002429
2430SBError
2431SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2432 lldb::addr_t section_base_addr)
2433{
2434 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002435 TargetSP target_sp(GetSP());
2436 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002437 {
2438 if (!section.IsValid())
2439 {
2440 sb_error.SetErrorStringWithFormat ("invalid section");
2441 }
2442 else
2443 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002444 SectionSP section_sp (section.GetSP());
2445 if (section_sp)
2446 {
2447 if (section_sp->IsThreadSpecific())
2448 {
2449 sb_error.SetErrorString ("thread specific sections are not yet supported");
2450 }
2451 else
2452 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002453 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002454 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002455 {
2456 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002457 if (process_sp)
2458 process_sp->Flush();
2459 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002460 }
2461 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002462 }
2463 }
2464 else
2465 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002466 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002467 }
2468 return sb_error;
2469}
2470
2471SBError
2472SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2473{
2474 SBError sb_error;
2475
Greg Claytonacdbe812012-01-30 09:04:36 +00002476 TargetSP target_sp(GetSP());
2477 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002478 {
2479 if (!section.IsValid())
2480 {
2481 sb_error.SetErrorStringWithFormat ("invalid section");
2482 }
2483 else
2484 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002485 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002486 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002487 {
2488 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002489 if (process_sp)
2490 process_sp->Flush();
2491 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002492 }
2493 }
2494 else
2495 {
2496 sb_error.SetErrorStringWithFormat ("invalid target");
2497 }
2498 return sb_error;
2499}
2500
2501SBError
2502SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2503{
2504 SBError sb_error;
2505
Greg Claytonacdbe812012-01-30 09:04:36 +00002506 TargetSP target_sp(GetSP());
2507 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002508 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002509 ModuleSP module_sp (module.GetSP());
2510 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002511 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002512 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002513 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002514 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002515 // The load was successful, make sure that at least some sections
2516 // changed before we notify that our module was loaded.
2517 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002518 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002519 ModuleList module_list;
2520 module_list.Append(module_sp);
2521 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002522 // Flush info in the process (stack frames, etc)
2523 ProcessSP process_sp (target_sp->GetProcessSP());
2524 if (process_sp)
2525 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002526 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002527 }
2528 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002529 else
2530 {
2531 sb_error.SetErrorStringWithFormat ("invalid module");
2532 }
2533
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002534 }
2535 else
2536 {
2537 sb_error.SetErrorStringWithFormat ("invalid target");
2538 }
2539 return sb_error;
2540}
2541
2542SBError
2543SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2544{
2545 SBError sb_error;
2546
2547 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002548 TargetSP target_sp(GetSP());
2549 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002550 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002551 ModuleSP module_sp (module.GetSP());
2552 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002553 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002554 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002555 if (objfile)
2556 {
2557 SectionList *section_list = objfile->GetSectionList();
2558 if (section_list)
2559 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002560 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002561
Greg Clayton3c947372013-01-29 01:17:09 +00002562 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002563 const size_t num_sections = section_list->GetSize();
2564 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2565 {
2566 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2567 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002568 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002569 }
2570 if (changed)
2571 {
2572 // Flush info in the process (stack frames, etc)
2573 ProcessSP process_sp (target_sp->GetProcessSP());
2574 if (process_sp)
2575 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002576 }
2577 }
2578 else
2579 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002580 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002581 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2582 }
2583 }
2584 else
2585 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002586 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002587 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2588 }
2589 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002590 else
2591 {
2592 sb_error.SetErrorStringWithFormat ("invalid module");
2593 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002594 }
2595 else
2596 {
2597 sb_error.SetErrorStringWithFormat ("invalid target");
2598 }
2599 return sb_error;
2600}
2601
2602
Greg Claytone14e1922012-12-04 02:22:16 +00002603lldb::SBSymbolContextList
2604SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2605{
2606 SBSymbolContextList sb_sc_list;
2607 if (name && name[0])
2608 {
2609 TargetSP target_sp(GetSP());
2610 if (target_sp)
2611 {
2612 bool append = true;
2613 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2614 symbol_type,
2615 *sb_sc_list,
2616 append);
2617 }
2618 }
2619 return sb_sc_list;
2620
2621}
2622
2623
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002624lldb::SBValue
2625SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2626{
Greg Clayton5160ce52013-03-27 23:08:40 +00002627 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2628 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002629 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002630 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002631 ValueObjectSP expr_value_sp;
2632 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002633 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002634 if (target_sp)
2635 {
2636 if (expr == NULL || expr[0] == '\0')
2637 {
2638 if (log)
2639 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2640 return expr_result;
2641 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002642
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002643 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2644 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002645
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002646 if (log)
2647 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002648
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002649 frame = exe_ctx.GetFramePtr();
2650 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002651
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002652 if (target)
2653 {
2654#ifdef LLDB_CONFIGURATION_DEBUG
2655 StreamString frame_description;
2656 if (frame)
2657 frame->DumpUsingSettingsFormat (&frame_description);
2658 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2659 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2660#endif
2661 exe_results = target->EvaluateExpression (expr,
2662 frame,
2663 expr_value_sp,
2664 options.ref());
2665
2666 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2667#ifdef LLDB_CONFIGURATION_DEBUG
2668 Host::SetCrashDescription (NULL);
2669#endif
2670 }
2671 else
2672 {
2673 if (log)
2674 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2675 }
2676 }
2677#ifndef LLDB_DISABLE_PYTHON
2678 if (expr_log)
2679 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002680 expr_result.GetValue(), expr_result.GetSummary());
2681
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002682 if (log)
2683 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002684 static_cast<void*>(frame), expr,
2685 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002686#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002687
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002688 return expr_result;
2689}
2690
Greg Clayton13fbb992013-02-01 00:47:49 +00002691
2692lldb::addr_t
2693SBTarget::GetStackRedZoneSize()
2694{
2695 TargetSP target_sp(GetSP());
2696 if (target_sp)
2697 {
2698 ABISP abi_sp;
2699 ProcessSP process_sp (target_sp->GetProcessSP());
2700 if (process_sp)
2701 abi_sp = process_sp->GetABI();
2702 else
2703 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2704 if (abi_sp)
2705 return abi_sp->GetRedZoneSize();
2706 }
2707 return 0;
2708}
2709