blob: e26692d9d8c17b9ca5ac5800c7f0f8cb54855a24 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBTarget.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytone0d378b2011-03-24 21:19:54 +000014#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Claytondea8cb42011-06-29 22:09:02 +000016#include "lldb/API/SBDebugger.h"
17#include "lldb/API/SBBreakpoint.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000018#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000020#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000022#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000023#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000024#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000025#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
41#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000042#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Greg Clayton1f746072012-08-29 21:13:06 +000050#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000051#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000052#include "lldb/Symbol/VariableList.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000053#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000055
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Target.h"
57#include "lldb/Target/TargetList.h"
58
59#include "lldb/Interpreter/CommandReturnObject.h"
60#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000061#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64using namespace lldb;
65using namespace lldb_private;
66
67#define DEFAULT_DISASM_BYTE_SIZE 32
68
Greg Clayton38d1f052012-02-24 20:59:25 +000069SBLaunchInfo::SBLaunchInfo (const char **argv) :
70 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000071{
Greg Clayton38d1f052012-02-24 20:59:25 +000072 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
73 if (argv && argv[0])
74 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0e615682012-02-24 05:03:03 +000075}
76
Greg Claytonecc7c0d2012-03-07 23:52:51 +000077SBLaunchInfo::~SBLaunchInfo()
78{
79}
80
81lldb_private::ProcessLaunchInfo &
82SBLaunchInfo::ref ()
83{
84 return *m_opaque_sp;
85}
86
87
Greg Clayton0e615682012-02-24 05:03:03 +000088uint32_t
89SBLaunchInfo::GetUserID()
90{
91 return m_opaque_sp->GetUserID();
92}
93
94uint32_t
95SBLaunchInfo::GetGroupID()
96{
97 return m_opaque_sp->GetGroupID();
98}
99
100bool
101SBLaunchInfo::UserIDIsValid ()
102{
103 return m_opaque_sp->UserIDIsValid();
104}
105
106bool
107SBLaunchInfo::GroupIDIsValid ()
108{
109 return m_opaque_sp->GroupIDIsValid();
110}
111
112void
113SBLaunchInfo::SetUserID (uint32_t uid)
114{
115 m_opaque_sp->SetUserID (uid);
116}
117
118void
119SBLaunchInfo::SetGroupID (uint32_t gid)
120{
121 m_opaque_sp->SetGroupID (gid);
122}
123
Greg Clayton3e32ad62014-05-07 20:16:06 +0000124SBFileSpec
125SBLaunchInfo::GetExecutableFile ()
126{
127 return SBFileSpec (m_opaque_sp->GetExecutableFile());
128}
129
130void
131SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg)
132{
133 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
134}
135
Greg Clayton0e615682012-02-24 05:03:03 +0000136uint32_t
137SBLaunchInfo::GetNumArguments ()
138{
139 return m_opaque_sp->GetArguments().GetArgumentCount();
140}
141
142const char *
143SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
144{
145 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
146}
147
148void
149SBLaunchInfo::SetArguments (const char **argv, bool append)
150{
151 if (append)
152 {
153 if (argv)
154 m_opaque_sp->GetArguments().AppendArguments(argv);
155 }
156 else
157 {
158 if (argv)
159 m_opaque_sp->GetArguments().SetArguments(argv);
160 else
161 m_opaque_sp->GetArguments().Clear();
162 }
163}
164
165uint32_t
166SBLaunchInfo::GetNumEnvironmentEntries ()
167{
168 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
169}
170
171const char *
172SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
173{
174 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
175}
176
177void
178SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
179{
180 if (append)
181 {
182 if (envp)
183 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
184 }
185 else
186 {
187 if (envp)
188 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
189 else
190 m_opaque_sp->GetEnvironmentEntries().Clear();
191 }
192}
193
194void
195SBLaunchInfo::Clear ()
196{
197 m_opaque_sp->Clear();
198}
199
200const char *
201SBLaunchInfo::GetWorkingDirectory () const
202{
203 return m_opaque_sp->GetWorkingDirectory();
204}
205
206void
207SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
208{
209 m_opaque_sp->SetWorkingDirectory(working_dir);
210}
211
212uint32_t
213SBLaunchInfo::GetLaunchFlags ()
214{
215 return m_opaque_sp->GetFlags().Get();
216}
217
218void
219SBLaunchInfo::SetLaunchFlags (uint32_t flags)
220{
221 m_opaque_sp->GetFlags().Reset(flags);
222}
223
224const char *
225SBLaunchInfo::GetProcessPluginName ()
226{
227 return m_opaque_sp->GetProcessPluginName();
228}
229
230void
231SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
232{
233 return m_opaque_sp->SetProcessPluginName (plugin_name);
234}
235
236const char *
237SBLaunchInfo::GetShell ()
238{
239 return m_opaque_sp->GetShell();
240}
241
242void
243SBLaunchInfo::SetShell (const char * path)
244{
245 m_opaque_sp->SetShell (path);
246}
247
248uint32_t
249SBLaunchInfo::GetResumeCount ()
250{
251 return m_opaque_sp->GetResumeCount();
252}
253
254void
255SBLaunchInfo::SetResumeCount (uint32_t c)
256{
257 m_opaque_sp->SetResumeCount (c);
258}
259
260bool
261SBLaunchInfo::AddCloseFileAction (int fd)
262{
263 return m_opaque_sp->AppendCloseFileAction(fd);
264}
265
266bool
267SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
268{
269 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
270}
271
272bool
273SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
274{
275 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
276}
277
278bool
279SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
280{
281 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
282}
283
Jason Molendaa3329782014-03-29 18:54:20 +0000284void
285SBLaunchInfo::SetLaunchEventData (const char *data)
286{
287 m_opaque_sp->SetLaunchEventData (data);
288}
289
290const char *
291SBLaunchInfo::GetLaunchEventData () const
292{
293 return m_opaque_sp->GetLaunchEventData ();
294}
Greg Clayton0e615682012-02-24 05:03:03 +0000295
Jim Ingham106d0282014-06-25 02:32:56 +0000296void
297SBLaunchInfo::SetDetachOnError (bool enable)
298{
299 m_opaque_sp->SetDetachOnError (enable);
300}
301
302bool
303SBLaunchInfo::GetDetachOnError () const
304{
305 return m_opaque_sp->GetDetachOnError ();
306}
307
Greg Clayton0e615682012-02-24 05:03:03 +0000308SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000309 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000310{
311}
312
313SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000314 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000315{
316 m_opaque_sp->SetProcessID (pid);
317}
318
319SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000320 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000321{
322 if (path && path[0])
323 m_opaque_sp->GetExecutableFile().SetFile(path, false);
324 m_opaque_sp->SetWaitForLaunch (wait_for);
325}
326
327SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000328 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000329{
330 *m_opaque_sp = *rhs.m_opaque_sp;
331}
332
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000333SBAttachInfo::~SBAttachInfo()
334{
335}
336
337lldb_private::ProcessAttachInfo &
338SBAttachInfo::ref ()
339{
340 return *m_opaque_sp;
341}
342
Greg Clayton0e615682012-02-24 05:03:03 +0000343SBAttachInfo &
344SBAttachInfo::operator = (const SBAttachInfo &rhs)
345{
346 if (this != &rhs)
347 *m_opaque_sp = *rhs.m_opaque_sp;
348 return *this;
349}
350
351lldb::pid_t
352SBAttachInfo::GetProcessID ()
353{
354 return m_opaque_sp->GetProcessID();
355}
356
357void
358SBAttachInfo::SetProcessID (lldb::pid_t pid)
359{
360 m_opaque_sp->SetProcessID (pid);
361}
362
363
364uint32_t
365SBAttachInfo::GetResumeCount ()
366{
367 return m_opaque_sp->GetResumeCount();
368}
369
370void
371SBAttachInfo::SetResumeCount (uint32_t c)
372{
373 m_opaque_sp->SetResumeCount (c);
374}
375
376const char *
377SBAttachInfo::GetProcessPluginName ()
378{
379 return m_opaque_sp->GetProcessPluginName();
380}
381
382void
383SBAttachInfo::SetProcessPluginName (const char *plugin_name)
384{
385 return m_opaque_sp->SetProcessPluginName (plugin_name);
386}
387
388void
389SBAttachInfo::SetExecutable (const char *path)
390{
391 if (path && path[0])
392 m_opaque_sp->GetExecutableFile().SetFile(path, false);
393 else
394 m_opaque_sp->GetExecutableFile().Clear();
395}
396
397void
398SBAttachInfo::SetExecutable (SBFileSpec exe_file)
399{
400 if (exe_file.IsValid())
401 m_opaque_sp->GetExecutableFile() = exe_file.ref();
402 else
403 m_opaque_sp->GetExecutableFile().Clear();
404}
405
406bool
407SBAttachInfo::GetWaitForLaunch ()
408{
409 return m_opaque_sp->GetWaitForLaunch();
410}
411
412void
413SBAttachInfo::SetWaitForLaunch (bool b)
414{
415 m_opaque_sp->SetWaitForLaunch (b);
416}
417
Jim Inghamcd16df92012-07-20 21:37:13 +0000418bool
419SBAttachInfo::GetIgnoreExisting ()
420{
421 return m_opaque_sp->GetIgnoreExisting();
422}
423
424void
425SBAttachInfo::SetIgnoreExisting (bool b)
426{
427 m_opaque_sp->SetIgnoreExisting (b);
428}
429
Greg Clayton0e615682012-02-24 05:03:03 +0000430uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000431SBAttachInfo::GetUserID()
432{
433 return m_opaque_sp->GetUserID();
434}
435
436uint32_t
437SBAttachInfo::GetGroupID()
438{
439 return m_opaque_sp->GetGroupID();
440}
441
442bool
443SBAttachInfo::UserIDIsValid ()
444{
445 return m_opaque_sp->UserIDIsValid();
446}
447
448bool
449SBAttachInfo::GroupIDIsValid ()
450{
451 return m_opaque_sp->GroupIDIsValid();
452}
453
454void
455SBAttachInfo::SetUserID (uint32_t uid)
456{
457 m_opaque_sp->SetUserID (uid);
458}
459
460void
461SBAttachInfo::SetGroupID (uint32_t gid)
462{
463 m_opaque_sp->SetGroupID (gid);
464}
465
466uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000467SBAttachInfo::GetEffectiveUserID()
468{
469 return m_opaque_sp->GetEffectiveUserID();
470}
471
472uint32_t
473SBAttachInfo::GetEffectiveGroupID()
474{
475 return m_opaque_sp->GetEffectiveGroupID();
476}
477
478bool
479SBAttachInfo::EffectiveUserIDIsValid ()
480{
481 return m_opaque_sp->EffectiveUserIDIsValid();
482}
483
484bool
485SBAttachInfo::EffectiveGroupIDIsValid ()
486{
487 return m_opaque_sp->EffectiveGroupIDIsValid ();
488}
489
490void
491SBAttachInfo::SetEffectiveUserID (uint32_t uid)
492{
493 m_opaque_sp->SetEffectiveUserID(uid);
494}
495
496void
497SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
498{
499 m_opaque_sp->SetEffectiveGroupID(gid);
500}
501
502lldb::pid_t
503SBAttachInfo::GetParentProcessID ()
504{
505 return m_opaque_sp->GetParentProcessID();
506}
507
508void
509SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
510{
511 m_opaque_sp->SetParentProcessID (pid);
512}
513
514bool
515SBAttachInfo::ParentProcessIDIsValid()
516{
517 return m_opaque_sp->ParentProcessIDIsValid();
518}
519
520
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521//----------------------------------------------------------------------
522// SBTarget constructor
523//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000524SBTarget::SBTarget () :
525 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526{
527}
528
529SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000530 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531{
532}
533
534SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000535 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536{
537}
538
Greg Claytonefabb122010-11-05 23:17:00 +0000539const SBTarget&
540SBTarget::operator = (const SBTarget& rhs)
541{
542 if (this != &rhs)
543 m_opaque_sp = rhs.m_opaque_sp;
544 return *this;
545}
546
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547//----------------------------------------------------------------------
548// Destructor
549//----------------------------------------------------------------------
550SBTarget::~SBTarget()
551{
552}
553
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000554const char *
555SBTarget::GetBroadcasterClassName ()
556{
557 return Target::GetStaticBroadcasterClass().AsCString();
558}
559
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560bool
561SBTarget::IsValid () const
562{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000563 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564}
565
566SBProcess
567SBTarget::GetProcess ()
568{
569 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000570 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000571 TargetSP target_sp(GetSP());
572 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000573 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000574 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000575 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000576 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000577
Greg Clayton5160ce52013-03-27 23:08:40 +0000578 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000579 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000580 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
581 static_cast<void*>(target_sp.get()),
582 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000583
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584 return sb_process;
585}
586
Greg Clayton66111032010-06-23 01:19:29 +0000587SBDebugger
588SBTarget::GetDebugger () const
589{
590 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000591 TargetSP target_sp(GetSP());
592 if (target_sp)
593 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000594 return debugger;
595}
596
Jim Ingham270684d2011-03-31 00:01:24 +0000597SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000598SBTarget::LoadCore (const char *core_file)
599{
600 SBProcess sb_process;
601 TargetSP target_sp(GetSP());
602 if (target_sp)
603 {
604 FileSpec filespec(core_file, true);
605 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
606 NULL,
607 &filespec));
608 if (process_sp)
609 {
610 process_sp->LoadCore();
611 sb_process.SetSP (process_sp);
612 }
613 }
614 return sb_process;
615}
616
617SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000618SBTarget::LaunchSimple
619(
620 char const **argv,
621 char const **envp,
622 const char *working_directory
623)
624{
625 char *stdin_path = NULL;
626 char *stdout_path = NULL;
627 char *stderr_path = NULL;
628 uint32_t launch_flags = 0;
629 bool stop_at_entry = false;
630 SBError error;
631 SBListener listener = GetDebugger().GetListener();
632 return Launch (listener,
633 argv,
634 envp,
635 stdin_path,
636 stdout_path,
637 stderr_path,
638 working_directory,
639 launch_flags,
640 stop_at_entry,
641 error);
642}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000643
Greg Claytonfbb76342013-11-20 21:07:01 +0000644SBError
645SBTarget::Install()
646{
647 SBError sb_error;
648 TargetSP target_sp(GetSP());
649 if (target_sp)
650 {
651 Mutex::Locker api_locker (target_sp->GetAPIMutex());
652 sb_error.ref() = target_sp->Install(NULL);
653 }
654 return sb_error;
655}
656
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000657SBProcess
658SBTarget::Launch
659(
Greg Clayton4b045622011-02-03 21:28:34 +0000660 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000661 char const **argv,
662 char const **envp,
663 const char *stdin_path,
664 const char *stdout_path,
665 const char *stderr_path,
666 const char *working_directory,
667 uint32_t launch_flags, // See LaunchFlags
668 bool stop_at_entry,
669 lldb::SBError& error
670)
671{
Greg Clayton5160ce52013-03-27 23:08:40 +0000672 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000673
Greg Claytonacdbe812012-01-30 09:04:36 +0000674 SBProcess sb_process;
675 ProcessSP process_sp;
676 TargetSP target_sp(GetSP());
677
Caroline Ticeceb6b132010-10-26 03:11:13 +0000678 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000679 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 +0000680 static_cast<void*>(target_sp.get()),
681 static_cast<void*>(argv), static_cast<void*>(envp),
682 stdin_path ? stdin_path : "NULL",
683 stdout_path ? stdout_path : "NULL",
684 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000685 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000686 launch_flags, stop_at_entry,
687 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000688
689 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000691 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000692
Greg Clayton645bf542011-01-27 01:01:10 +0000693 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
694 launch_flags |= eLaunchFlagDisableASLR;
695
Greg Clayton2289fa42011-04-30 01:09:13 +0000696 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000697 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000698 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000699 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000700 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000701
Greg Claytonb9556ac2012-01-30 07:41:31 +0000702 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000703 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000704 if (state == eStateAttaching)
705 error.SetErrorString ("process attach is in progress");
706 else
707 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000708 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000709 }
Greg Clayton931180e2011-01-27 06:44:37 +0000710 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000711
Greg Clayton2289fa42011-04-30 01:09:13 +0000712 if (state == eStateConnected)
713 {
714 // If we are already connected, then we have already specified the
715 // listener, so if a valid listener is supplied, we need to error out
716 // to let the client know.
717 if (listener.IsValid())
718 {
719 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000720 return sb_process;
721 }
722 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000723
724 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
725 launch_flags |= eLaunchFlagDisableSTDIO;
726
727 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000728
Greg Claytonb09c5382013-12-13 17:20:18 +0000729 Module *exe_module = target_sp->GetExecutableModulePointer();
730 if (exe_module)
731 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
732 if (argv)
733 launch_info.GetArguments().AppendArguments (argv);
734 if (envp)
735 launch_info.GetEnvironmentEntries ().SetArguments (envp);
736
737 if (listener.IsValid())
738 error.SetError (target_sp->Launch(listener.ref(), launch_info));
Greg Clayton2289fa42011-04-30 01:09:13 +0000739 else
Greg Claytonb09c5382013-12-13 17:20:18 +0000740 error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
Greg Clayton645bf542011-01-27 01:01:10 +0000741
Greg Claytonb09c5382013-12-13 17:20:18 +0000742 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000743 }
744 else
745 {
746 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000748
Caroline Tice20ad3c42010-10-29 21:48:37 +0000749 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000750 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000751 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
752 static_cast<void*>(target_sp.get()),
753 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000754
Greg Clayton5d5028b2010-10-06 03:53:16 +0000755 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756}
757
Greg Clayton0e615682012-02-24 05:03:03 +0000758SBProcess
759SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
760{
Greg Clayton5160ce52013-03-27 23:08:40 +0000761 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000762
Greg Clayton0e615682012-02-24 05:03:03 +0000763 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000764 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000765
Greg Clayton0e615682012-02-24 05:03:03 +0000766 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000767 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
768 static_cast<void*>(target_sp.get()));
769
Greg Clayton0e615682012-02-24 05:03:03 +0000770 if (target_sp)
771 {
772 Mutex::Locker api_locker (target_sp->GetAPIMutex());
773 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000774 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000775 ProcessSP process_sp = target_sp->GetProcessSP();
776 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000777 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000778 state = process_sp->GetState();
779
780 if (process_sp->IsAlive() && state != eStateConnected)
781 {
782 if (state == eStateAttaching)
783 error.SetErrorString ("process attach is in progress");
784 else
785 error.SetErrorString ("a process is already being debugged");
786 return sb_process;
787 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000788 }
Greg Clayton0e615682012-02-24 05:03:03 +0000789 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000790
791 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
792
Greg Clayton3e32ad62014-05-07 20:16:06 +0000793 if (!launch_info.GetExecutableFile())
794 {
795 Module *exe_module = target_sp->GetExecutableModulePointer();
796 if (exe_module)
797 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
798 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000799
800 const ArchSpec &arch_spec = target_sp->GetArchitecture();
801 if (arch_spec.IsValid())
802 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000803
Greg Claytonb09c5382013-12-13 17:20:18 +0000804 error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
805 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000806 }
807 else
808 {
809 error.SetErrorString ("SBTarget is invalid");
810 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000811
Greg Clayton0e615682012-02-24 05:03:03 +0000812 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
813 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000814 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000815 static_cast<void*>(target_sp.get()),
816 static_cast<void*>(sb_process.GetSP().get()));
817
Greg Clayton0e615682012-02-24 05:03:03 +0000818 return sb_process;
819}
820
821lldb::SBProcess
822SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
823{
Greg Clayton5160ce52013-03-27 23:08:40 +0000824 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000825
Greg Clayton0e615682012-02-24 05:03:03 +0000826 SBProcess sb_process;
827 ProcessSP process_sp;
828 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000829
Sean Callanan575a4542012-10-20 00:21:31 +0000830 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000831 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
832 static_cast<void*>(target_sp.get()));
833
Greg Clayton0e615682012-02-24 05:03:03 +0000834 if (target_sp)
835 {
836 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000837
Greg Clayton0e615682012-02-24 05:03:03 +0000838 StateType state = eStateInvalid;
839 process_sp = target_sp->GetProcessSP();
840 if (process_sp)
841 {
842 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000843
Greg Clayton0e615682012-02-24 05:03:03 +0000844 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000845 {
Greg Clayton0e615682012-02-24 05:03:03 +0000846 if (state == eStateAttaching)
847 error.SetErrorString ("process attach is in progress");
848 else
849 error.SetErrorString ("a process is already being debugged");
Sean Callanan575a4542012-10-20 00:21:31 +0000850 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000851 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000852 static_cast<void*>(target_sp.get()),
853 error.GetCString());
Greg Clayton0e615682012-02-24 05:03:03 +0000854 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000855 }
Greg Clayton0e615682012-02-24 05:03:03 +0000856 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000857
Greg Clayton0e615682012-02-24 05:03:03 +0000858 if (state != eStateConnected)
859 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
860
861 if (process_sp)
862 {
Greg Clayton0e615682012-02-24 05:03:03 +0000863 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000864 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000865 {
866 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton91e407e2012-09-27 00:03:39 +0000867 // See if we can pre-verify if a process exists or not
868 if (platform_sp && platform_sp->IsConnected())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000869 {
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000870 lldb::pid_t attach_pid = attach_info.GetProcessID();
Greg Clayton91e407e2012-09-27 00:03:39 +0000871 ProcessInstanceInfo instance_info;
872 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
873 {
874 attach_info.SetUserID(instance_info.GetEffectiveUserID());
875 }
876 else
877 {
Daniel Malead01b2952012-11-29 21:49:15 +0000878 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000879 if (log)
880 {
881 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000882 static_cast<void*>(target_sp.get()), error.GetCString());
Sean Callanan575a4542012-10-20 00:21:31 +0000883 }
Greg Clayton91e407e2012-09-27 00:03:39 +0000884 return sb_process;
885 }
Han Ming Ongcec8c902012-02-29 00:12:56 +0000886 }
887 }
Han Ming Ongbee98392012-02-29 19:16:40 +0000888 error.SetError (process_sp->Attach (attach_info));
889 if (error.Success())
890 {
891 sb_process.SetSP (process_sp);
892 // If we are doing synchronous mode, then wait for the
893 // process to stop!
894 if (target_sp->GetDebugger().GetAsyncExecution () == false)
895 process_sp->WaitForProcessToStop (NULL);
896 }
Greg Clayton0e615682012-02-24 05:03:03 +0000897 }
898 else
899 {
900 error.SetErrorString ("unable to create lldb_private::Process");
901 }
902 }
903 else
904 {
905 error.SetErrorString ("SBTarget is invalid");
906 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000907
Sean Callanan575a4542012-10-20 00:21:31 +0000908 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000909 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000910 static_cast<void*>(target_sp.get()),
911 static_cast<void*>(process_sp.get()));
912
Greg Clayton0e615682012-02-24 05:03:03 +0000913 return sb_process;
914}
915
916
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000917#if defined(__APPLE__)
918
919lldb::SBProcess
920SBTarget::AttachToProcessWithID (SBListener &listener,
921 ::pid_t pid,
922 lldb::SBError& error)
923{
924 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
925}
926
927#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000928
929lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000930SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000931(
Greg Clayton4b045622011-02-03 21:28:34 +0000932 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000933 lldb::pid_t pid,// The process ID to attach to
934 SBError& error // An error explaining what went wrong if attach fails
935)
936{
Greg Clayton5160ce52013-03-27 23:08:40 +0000937 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000938
Greg Clayton524e60b2010-10-06 22:10:17 +0000939 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000940 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000941 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000942
943 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000944 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...",
945 static_cast<void*>(target_sp.get()), pid);
946
Greg Claytonacdbe812012-01-30 09:04:36 +0000947 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000948 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000949 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0c74e782011-06-24 03:21:43 +0000950
951 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000952 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000953 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +0000954 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000955 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000956
Greg Claytonb9556ac2012-01-30 07:41:31 +0000957 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000958 {
Greg Clayton0c74e782011-06-24 03:21:43 +0000959 if (state == eStateAttaching)
960 error.SetErrorString ("process attach is in progress");
961 else
962 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +0000963 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000964 }
Greg Clayton0c74e782011-06-24 03:21:43 +0000965 }
966
967 if (state == eStateConnected)
968 {
969 // If we are already connected, then we have already specified the
970 // listener, so if a valid listener is supplied, we need to error out
971 // to let the client know.
972 if (listener.IsValid())
973 {
974 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +0000975 return sb_process;
976 }
977 }
Greg Clayton4b045622011-02-03 21:28:34 +0000978 else
Greg Clayton0c74e782011-06-24 03:21:43 +0000979 {
980 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000981 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000982 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000983 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000984 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000985 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000986 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000987 sb_process.SetSP (process_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000988
Greg Clayton144f3a92011-11-15 03:53:30 +0000989 ProcessAttachInfo attach_info;
990 attach_info.SetProcessID (pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000991
Han Ming Ong84647042012-02-25 01:07:38 +0000992 PlatformSP platform_sp = target_sp->GetPlatform();
993 ProcessInstanceInfo instance_info;
994 if (platform_sp->GetProcessInfo(pid, instance_info))
995 {
996 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ong84647042012-02-25 01:07:38 +0000997 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000998 error.SetError (process_sp->Attach (attach_info));
Greg Claytone2186ed2012-09-07 17:51:47 +0000999 if (error.Success())
1000 {
1001 // If we are doing synchronous mode, then wait for the
1002 // process to stop!
1003 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Claytonb9556ac2012-01-30 07:41:31 +00001004 process_sp->WaitForProcessToStop (NULL);
Greg Claytone2186ed2012-09-07 17:51:47 +00001005 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001006 }
1007 else
1008 {
1009 error.SetErrorString ("unable to create lldb_private::Process");
1010 }
1011 }
1012 else
1013 {
1014 error.SetErrorString ("SBTarget is invalid");
1015 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001016
Sean Callanan575a4542012-10-20 00:21:31 +00001017 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001018 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001019 static_cast<void*>(target_sp.get()),
1020 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001021 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001022}
1023
1024lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +00001025SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +00001026(
Greg Clayton4b045622011-02-03 21:28:34 +00001027 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +00001028 const char *name, // basename of process to attach to
1029 bool wait_for, // if true wait for a new instance of "name" to be launched
1030 SBError& error // An error explaining what went wrong if attach fails
1031)
1032{
Greg Clayton5160ce52013-03-27 23:08:40 +00001033 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001034
Greg Clayton524e60b2010-10-06 22:10:17 +00001035 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001036 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001037 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001038
Sean Callanan575a4542012-10-20 00:21:31 +00001039 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001040 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...",
1041 static_cast<void*>(target_sp.get()), name,
1042 wait_for ? "true" : "false");
1043
Greg Claytonacdbe812012-01-30 09:04:36 +00001044 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001045 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001046 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +00001047
Greg Clayton0c74e782011-06-24 03:21:43 +00001048 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +00001049 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001050 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +00001051 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001052 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001053
Greg Claytonb9556ac2012-01-30 07:41:31 +00001054 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001055 {
Greg Clayton0c74e782011-06-24 03:21:43 +00001056 if (state == eStateAttaching)
1057 error.SetErrorString ("process attach is in progress");
1058 else
1059 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001060 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001061 }
Greg Clayton0c74e782011-06-24 03:21:43 +00001062 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001063
Greg Clayton0c74e782011-06-24 03:21:43 +00001064 if (state == eStateConnected)
1065 {
1066 // If we are already connected, then we have already specified the
1067 // listener, so if a valid listener is supplied, we need to error out
1068 // to let the client know.
1069 if (listener.IsValid())
1070 {
1071 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001072 return sb_process;
1073 }
1074 }
Greg Clayton4b045622011-02-03 21:28:34 +00001075 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001076 {
1077 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001078 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001079 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001080 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001081 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001082
Greg Claytonb9556ac2012-01-30 07:41:31 +00001083 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001084 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001085 sb_process.SetSP (process_sp);
Greg Clayton144f3a92011-11-15 03:53:30 +00001086 ProcessAttachInfo attach_info;
1087 attach_info.GetExecutableFile().SetFile(name, false);
1088 attach_info.SetWaitForLaunch(wait_for);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001089 error.SetError (process_sp->Attach (attach_info));
Daniel Malead659dc12013-04-01 19:47:00 +00001090 if (error.Success())
1091 {
1092 // If we are doing synchronous mode, then wait for the
1093 // process to stop!
1094 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1095 process_sp->WaitForProcessToStop (NULL);
1096 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001097 }
1098 else
1099 {
1100 error.SetErrorString ("unable to create lldb_private::Process");
1101 }
1102 }
1103 else
1104 {
1105 error.SetErrorString ("SBTarget is invalid");
1106 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001107
Sean Callanan575a4542012-10-20 00:21:31 +00001108 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001109 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001110 static_cast<void*>(target_sp.get()),
1111 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001112 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001113}
1114
James McIlree9631aae2011-03-04 00:31:13 +00001115lldb::SBProcess
1116SBTarget::ConnectRemote
1117(
1118 SBListener &listener,
1119 const char *url,
1120 const char *plugin_name,
1121 SBError& error
1122)
1123{
Greg Clayton5160ce52013-03-27 23:08:40 +00001124 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001125
James McIlree9631aae2011-03-04 00:31:13 +00001126 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001127 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001128 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001129
Sean Callanan575a4542012-10-20 00:21:31 +00001130 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001131 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
1132 static_cast<void*>(target_sp.get()), url, plugin_name);
1133
Greg Claytonacdbe812012-01-30 09:04:36 +00001134 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001135 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001136 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +00001137 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001138 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001139 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001140 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001141
Greg Claytonb9556ac2012-01-30 07:41:31 +00001142 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001143 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001144 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +00001145 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +00001146 }
1147 else
1148 {
1149 error.SetErrorString ("unable to create lldb_private::Process");
1150 }
1151 }
1152 else
1153 {
1154 error.SetErrorString ("SBTarget is invalid");
1155 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001156
Sean Callanan575a4542012-10-20 00:21:31 +00001157 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001158 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001159 static_cast<void*>(target_sp.get()),
1160 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +00001161 return sb_process;
1162}
1163
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164SBFileSpec
1165SBTarget::GetExecutable ()
1166{
Caroline Ticeceb6b132010-10-26 03:11:13 +00001167
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001168 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +00001169 TargetSP target_sp(GetSP());
1170 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001172 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +00001173 if (exe_module)
1174 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001176
Greg Clayton5160ce52013-03-27 23:08:40 +00001177 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001178 if (log)
1179 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001180 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1181 static_cast<void*>(target_sp.get()),
1182 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001183 }
1184
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185 return exe_file_spec;
1186}
1187
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189SBTarget::operator == (const SBTarget &rhs) const
1190{
Greg Clayton66111032010-06-23 01:19:29 +00001191 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001192}
1193
1194bool
1195SBTarget::operator != (const SBTarget &rhs) const
1196{
Greg Clayton66111032010-06-23 01:19:29 +00001197 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001198}
1199
Greg Claytonb9556ac2012-01-30 07:41:31 +00001200lldb::TargetSP
1201SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +00001202{
1203 return m_opaque_sp;
1204}
1205
Greg Clayton66111032010-06-23 01:19:29 +00001206void
Greg Claytonb9556ac2012-01-30 07:41:31 +00001207SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001208{
1209 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210}
1211
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001212lldb::SBAddress
1213SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001214{
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001215 lldb::SBAddress sb_addr;
1216 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +00001217 TargetSP target_sp(GetSP());
1218 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001219 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001220 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +00001221 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001222 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +00001223 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001224
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001225 // We have a load address that isn't in a section, just return an address
1226 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +00001227 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001228 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001229}
1230
Greg Claytond5944cd2013-12-06 01:12:00 +00001231
1232lldb::SBAddress
1233SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1234{
1235 lldb::SBAddress sb_addr;
1236 Address &addr = sb_addr.ref();
1237 TargetSP target_sp(GetSP());
1238 if (target_sp)
1239 {
1240 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1241 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1242 return sb_addr;
1243 }
1244
1245 // We have a load address that isn't in a section, just return an address
1246 // with the offset filled in (the address) and the section set to NULL
1247 addr.SetRawAddress(vm_addr);
1248 return sb_addr;
1249}
1250
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001251SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +00001252SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1253 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001254{
1255 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +00001256 if (addr.IsValid())
1257 {
1258 TargetSP target_sp(GetSP());
1259 if (target_sp)
1260 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1261 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001262 return sc;
1263}
1264
1265
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001267SBTarget::BreakpointCreateByLocation (const char *file,
1268 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269{
Greg Clayton7481c202010-11-08 00:28:40 +00001270 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001271}
1272
1273SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001274SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1275 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276{
Greg Clayton5160ce52013-03-27 23:08:40 +00001277 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001278
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001279 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001280 TargetSP target_sp(GetSP());
1281 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001282 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001283 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001284
Greg Clayton1f746072012-08-29 21:13:06 +00001285 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001286 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001287 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001288 const bool hardware = false;
1289 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001290 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001291
1292 if (log)
1293 {
1294 SBStream sstr;
1295 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001296 char path[PATH_MAX];
1297 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001298 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1299 static_cast<void*>(target_sp.get()), path, line,
1300 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001301 }
1302
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303 return sb_bp;
1304}
1305
1306SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001307SBTarget::BreakpointCreateByName (const char *symbol_name,
1308 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001309{
Greg Clayton5160ce52013-03-27 23:08:40 +00001310 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001311
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001313 TargetSP target_sp(GetSP());
1314 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001316 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001317
Jim Inghama8558b62012-05-22 00:12:20 +00001318 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001319 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001320 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 if (module_name && module_name[0])
1322 {
Jim Ingham969795f2011-09-21 01:17:13 +00001323 FileSpecList module_spec_list;
1324 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001325 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 }
1327 else
1328 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001329 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 }
1331 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001332
Caroline Ticeceb6b132010-10-26 03:11:13 +00001333 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001334 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1335 static_cast<void*>(target_sp.get()), symbol_name,
1336 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001337
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001338 return sb_bp;
1339}
1340
Jim Ingham87df91b2011-09-23 00:54:11 +00001341lldb::SBBreakpoint
1342SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001343 const SBFileSpecList &module_list,
1344 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001345{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001346 uint32_t name_type_mask = eFunctionNameTypeAuto;
1347 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1348}
1349
1350lldb::SBBreakpoint
1351SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001352 uint32_t name_type_mask,
1353 const SBFileSpecList &module_list,
1354 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001355{
Greg Clayton5160ce52013-03-27 23:08:40 +00001356 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001357
1358 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001359 TargetSP target_sp(GetSP());
1360 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001361 {
Jim Inghama8558b62012-05-22 00:12:20 +00001362 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001363 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001364 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001365 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1366 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001367 comp_unit_list.get(),
1368 symbol_name,
1369 name_type_mask,
1370 skip_prologue,
1371 internal,
1372 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001373 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001374
Jim Ingham87df91b2011-09-23 00:54:11 +00001375 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001376 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1377 static_cast<void*>(target_sp.get()), symbol_name,
1378 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001379
1380 return sb_bp;
1381}
1382
Jim Inghamfab10e82012-03-06 00:37:27 +00001383lldb::SBBreakpoint
1384SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1385 uint32_t num_names,
1386 uint32_t name_type_mask,
1387 const SBFileSpecList &module_list,
1388 const SBFileSpecList &comp_unit_list)
1389{
Greg Clayton5160ce52013-03-27 23:08:40 +00001390 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001391
1392 SBBreakpoint sb_bp;
1393 TargetSP target_sp(GetSP());
1394 if (target_sp && num_names > 0)
1395 {
1396 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001397 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001398 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001399 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001400 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1401 comp_unit_list.get(),
1402 symbol_names,
1403 num_names,
1404 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001405 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001406 internal,
1407 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001408 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001409
Jim Inghamfab10e82012-03-06 00:37:27 +00001410 if (log)
1411 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001412 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1413 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001414 for (uint32_t i = 0 ; i < num_names; i++)
1415 {
1416 char sep;
1417 if (i < num_names - 1)
1418 sep = ',';
1419 else
1420 sep = '}';
1421 if (symbol_names[i] != NULL)
1422 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1423 else
1424 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001425 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001426 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1427 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001428 }
1429
1430 return sb_bp;
1431}
Jim Ingham87df91b2011-09-23 00:54:11 +00001432
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001433SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001434SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1435 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436{
Greg Clayton5160ce52013-03-27 23:08:40 +00001437 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001438
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001440 TargetSP target_sp(GetSP());
1441 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001443 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001445 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001446 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001447 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001448
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 if (module_name && module_name[0])
1450 {
Jim Ingham969795f2011-09-21 01:17:13 +00001451 FileSpecList module_spec_list;
1452 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001453
Greg Claytoneb023e72013-10-11 19:48:25 +00001454 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455 }
1456 else
1457 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001458 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001459 }
1460 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001461
1462 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001463 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1464 static_cast<void*>(target_sp.get()), symbol_name_regex,
1465 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001466
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001467 return sb_bp;
1468}
1469
Jim Ingham87df91b2011-09-23 00:54:11 +00001470lldb::SBBreakpoint
1471SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001472 const SBFileSpecList &module_list,
1473 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001474{
Greg Clayton5160ce52013-03-27 23:08:40 +00001475 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476
Jim Ingham87df91b2011-09-23 00:54:11 +00001477 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001478 TargetSP target_sp(GetSP());
1479 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001480 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001481 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001482 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001483 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001484 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001485 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001486
Greg Claytoneb023e72013-10-11 19:48:25 +00001487 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001488 }
1489
1490 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001491 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1492 static_cast<void*>(target_sp.get()), symbol_name_regex,
1493 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001494
1495 return sb_bp;
1496}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497
1498SBBreakpoint
1499SBTarget::BreakpointCreateByAddress (addr_t address)
1500{
Greg Clayton5160ce52013-03-27 23:08:40 +00001501 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001502
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001504 TargetSP target_sp(GetSP());
1505 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001506 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001507 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001508 const bool hardware = false;
1509 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001510 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001511
Caroline Ticeceb6b132010-10-26 03:11:13 +00001512 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001513 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1514 static_cast<void*>(target_sp.get()),
1515 static_cast<uint64_t>(address),
1516 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001517
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001518 return sb_bp;
1519}
1520
Jim Ingham969795f2011-09-21 01:17:13 +00001521lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001522SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1523 const lldb::SBFileSpec &source_file,
1524 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001525{
Greg Clayton5160ce52013-03-27 23:08:40 +00001526 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001527
1528 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001529 TargetSP target_sp(GetSP());
1530 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001531 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001532 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001533 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001534 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001535 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001536 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001537
Jim Ingham969795f2011-09-21 01:17:13 +00001538 if (module_name && module_name[0])
1539 {
1540 FileSpecList module_spec_list;
1541 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001542
Greg Claytoneb023e72013-10-11 19:48:25 +00001543 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001544 }
1545 else
1546 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001547 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001548 }
1549 }
1550
1551 if (log)
1552 {
1553 char path[PATH_MAX];
1554 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001555 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1556 static_cast<void*>(target_sp.get()), source_regex, path,
1557 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001558 }
1559
1560 return sb_bp;
1561}
1562
Jim Ingham87df91b2011-09-23 00:54:11 +00001563lldb::SBBreakpoint
1564SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001565 const SBFileSpecList &module_list,
1566 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001567{
Greg Clayton5160ce52013-03-27 23:08:40 +00001568 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001569
1570 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001571 TargetSP target_sp(GetSP());
1572 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001573 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001574 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001575 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001576 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001577 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001578 }
1579
1580 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001581 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1582 static_cast<void*>(target_sp.get()), source_regex,
1583 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001584
1585 return sb_bp;
1586}
Jim Ingham969795f2011-09-21 01:17:13 +00001587
Jim Inghamfab10e82012-03-06 00:37:27 +00001588lldb::SBBreakpoint
1589SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001590 bool catch_bp,
1591 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001592{
Greg Clayton5160ce52013-03-27 23:08:40 +00001593 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001594
1595 SBBreakpoint sb_bp;
1596 TargetSP target_sp(GetSP());
1597 if (target_sp)
1598 {
1599 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001600 const bool hardware = false;
1601 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001602 }
1603
1604 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001605 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1606 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001607 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001608 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1609 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001610
1611 return sb_bp;
1612}
1613
Greg Clayton9fed0d82010-07-23 23:33:17 +00001614uint32_t
1615SBTarget::GetNumBreakpoints () const
1616{
Greg Claytonacdbe812012-01-30 09:04:36 +00001617 TargetSP target_sp(GetSP());
1618 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001619 {
1620 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001621 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001622 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001623 return 0;
1624}
1625
1626SBBreakpoint
1627SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1628{
1629 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001630 TargetSP target_sp(GetSP());
1631 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001632 {
1633 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001634 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001635 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001636 return sb_breakpoint;
1637}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638
1639bool
1640SBTarget::BreakpointDelete (break_id_t bp_id)
1641{
Greg Clayton5160ce52013-03-27 23:08:40 +00001642 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001643
Caroline Ticeceb6b132010-10-26 03:11:13 +00001644 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001645 TargetSP target_sp(GetSP());
1646 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001647 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001648 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1649 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001650 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001651
1652 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001653 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1654 static_cast<void*>(target_sp.get()),
1655 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001656
1657 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001658}
1659
Johnny Chen5d043462011-09-26 22:40:50 +00001660SBBreakpoint
1661SBTarget::FindBreakpointByID (break_id_t bp_id)
1662{
Greg Clayton5160ce52013-03-27 23:08:40 +00001663 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001664
1665 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001666 TargetSP target_sp(GetSP());
1667 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001668 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001669 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1670 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001671 }
1672
1673 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001674 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1675 static_cast<void*>(target_sp.get()),
1676 static_cast<uint32_t>(bp_id),
1677 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001678
1679 return sb_breakpoint;
1680}
1681
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001682bool
1683SBTarget::EnableAllBreakpoints ()
1684{
Greg Claytonacdbe812012-01-30 09:04:36 +00001685 TargetSP target_sp(GetSP());
1686 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001687 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001688 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1689 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001690 return true;
1691 }
1692 return false;
1693}
1694
1695bool
1696SBTarget::DisableAllBreakpoints ()
1697{
Greg Claytonacdbe812012-01-30 09:04:36 +00001698 TargetSP target_sp(GetSP());
1699 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001701 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1702 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001703 return true;
1704 }
1705 return false;
1706}
1707
1708bool
1709SBTarget::DeleteAllBreakpoints ()
1710{
Greg Claytonacdbe812012-01-30 09:04:36 +00001711 TargetSP target_sp(GetSP());
1712 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001713 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001714 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1715 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716 return true;
1717 }
1718 return false;
1719}
1720
Johnny Chen5d043462011-09-26 22:40:50 +00001721uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001722SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001723{
Greg Claytonacdbe812012-01-30 09:04:36 +00001724 TargetSP target_sp(GetSP());
1725 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001726 {
Johnny Chen01a67862011-10-14 00:42:25 +00001727 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001728 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001729 }
1730 return 0;
1731}
1732
Greg Clayton1b282f92011-10-13 18:08:26 +00001733SBWatchpoint
1734SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001735{
Johnny Chen01a67862011-10-14 00:42:25 +00001736 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001737 TargetSP target_sp(GetSP());
1738 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001739 {
Johnny Chen01a67862011-10-14 00:42:25 +00001740 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001741 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001742 }
Johnny Chen01a67862011-10-14 00:42:25 +00001743 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001744}
1745
1746bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001747SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001748{
Greg Clayton5160ce52013-03-27 23:08:40 +00001749 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001750
1751 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001752 TargetSP target_sp(GetSP());
1753 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001754 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001755 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001756 Mutex::Locker locker;
1757 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001758 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001759 }
1760
1761 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001762 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1763 static_cast<void*>(target_sp.get()),
1764 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001765
1766 return result;
1767}
1768
Greg Clayton1b282f92011-10-13 18:08:26 +00001769SBWatchpoint
1770SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001771{
Greg Clayton5160ce52013-03-27 23:08:40 +00001772 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001773
Greg Clayton1b282f92011-10-13 18:08:26 +00001774 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001775 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001776 TargetSP target_sp(GetSP());
1777 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001778 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001779 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001780 Mutex::Locker locker;
1781 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001782 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1783 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001784 }
1785
1786 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001787 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1788 static_cast<void*>(target_sp.get()),
1789 static_cast<uint32_t>(wp_id),
1790 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001791
Greg Clayton1b282f92011-10-13 18:08:26 +00001792 return sb_watchpoint;
1793}
1794
1795lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001796SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001797{
Greg Clayton5160ce52013-03-27 23:08:40 +00001798 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001799
Greg Clayton1b282f92011-10-13 18:08:26 +00001800 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001801 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001802 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001803 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001804 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001805 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001806 uint32_t watch_type = 0;
1807 if (read)
1808 watch_type |= LLDB_WATCH_TYPE_READ;
1809 if (write)
1810 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001811 if (watch_type == 0)
1812 {
1813 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1814 return sb_watchpoint;
1815 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001816
Johnny Chen7385a5a2012-05-31 22:56:36 +00001817 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001818 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001819 // This API doesn't take in a type, so we can't figure out what it is.
1820 ClangASTType *type = NULL;
1821 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001822 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001823 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001824 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001825
Greg Clayton1b282f92011-10-13 18:08:26 +00001826 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001827 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001828 static_cast<void*>(target_sp.get()), addr,
1829 static_cast<uint32_t>(size),
1830 static_cast<void*>(watchpoint_sp.get()));
1831
Greg Clayton1b282f92011-10-13 18:08:26 +00001832 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001833}
1834
1835bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001836SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001837{
Greg Claytonacdbe812012-01-30 09:04:36 +00001838 TargetSP target_sp(GetSP());
1839 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001840 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001841 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001842 Mutex::Locker locker;
1843 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001844 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001845 return true;
1846 }
1847 return false;
1848}
1849
1850bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001851SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001852{
Greg Claytonacdbe812012-01-30 09:04:36 +00001853 TargetSP target_sp(GetSP());
1854 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001855 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001856 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001857 Mutex::Locker locker;
1858 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001859 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001860 return true;
1861 }
1862 return false;
1863}
1864
Enrico Granata347c2aa2013-10-08 21:49:02 +00001865SBValue
1866SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1867{
1868 SBValue sb_value;
1869 lldb::ValueObjectSP new_value_sp;
1870 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1871 {
1872 lldb::addr_t address(addr.GetLoadAddress(*this));
1873 lldb::TypeImplSP type_impl_sp (type.GetSP());
Enrico Granatadc4db5a2013-10-29 00:28:35 +00001874 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001875 if (pointer_ast_type)
1876 {
1877 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001878
Enrico Granata347c2aa2013-10-08 21:49:02 +00001879 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1880 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1881 pointer_ast_type,
1882 ConstString(name),
1883 buffer,
1884 exe_ctx.GetByteOrder(),
1885 exe_ctx.GetAddressByteSize()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001886
Enrico Granata347c2aa2013-10-08 21:49:02 +00001887 if (ptr_result_valobj_sp)
1888 {
1889 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1890 Error err;
1891 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1892 if (new_value_sp)
1893 new_value_sp->SetName(ConstString(name));
1894 }
1895 }
1896 }
1897 sb_value.SetSP(new_value_sp);
1898 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1899 if (log)
1900 {
1901 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001902 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1903 static_cast<void*>(m_opaque_sp.get()),
1904 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001905 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001906 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1907 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001908 }
1909 return sb_value;
1910}
1911
Johnny Chen5d043462011-09-26 22:40:50 +00001912bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001913SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001914{
Greg Claytonacdbe812012-01-30 09:04:36 +00001915 TargetSP target_sp(GetSP());
1916 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001917 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001918 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001919 Mutex::Locker locker;
1920 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001921 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001922 return true;
1923 }
1924 return false;
1925}
1926
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001927
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001928lldb::SBModule
1929SBTarget::AddModule (const char *path,
1930 const char *triple,
1931 const char *uuid_cstr)
1932{
Greg Claytonb210aec2012-04-23 20:23:39 +00001933 return AddModule (path, triple, uuid_cstr, NULL);
1934}
1935
1936lldb::SBModule
1937SBTarget::AddModule (const char *path,
1938 const char *triple,
1939 const char *uuid_cstr,
1940 const char *symfile)
1941{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001942 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001943 TargetSP target_sp(GetSP());
1944 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001945 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001946 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001947 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001948 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001949
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001950 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001951 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001952
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001953 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001954 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001955 else
1956 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001957
1958 if (symfile)
1959 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001960
Greg Claytonb9a01b32012-02-26 05:51:37 +00001961 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001962 }
1963 return sb_module;
1964}
1965
Greg Clayton226cce22013-07-08 22:22:41 +00001966lldb::SBModule
1967SBTarget::AddModule (const SBModuleSpec &module_spec)
1968{
1969 lldb::SBModule sb_module;
1970 TargetSP target_sp(GetSP());
1971 if (target_sp)
1972 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1973 return sb_module;
1974}
1975
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001976bool
1977SBTarget::AddModule (lldb::SBModule &module)
1978{
Greg Claytonacdbe812012-01-30 09:04:36 +00001979 TargetSP target_sp(GetSP());
1980 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001981 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001982 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001983 return true;
1984 }
1985 return false;
1986}
1987
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001988uint32_t
1989SBTarget::GetNumModules () const
1990{
Greg Clayton5160ce52013-03-27 23:08:40 +00001991 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001992
Caroline Ticeceb6b132010-10-26 03:11:13 +00001993 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001994 TargetSP target_sp(GetSP());
1995 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001996 {
1997 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001998 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001999 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002000
2001 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002002 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
2003 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002004
2005 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002006}
2007
Greg Clayton48e42542010-07-30 20:12:55 +00002008void
2009SBTarget::Clear ()
2010{
Greg Clayton5160ce52013-03-27 23:08:40 +00002011 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002012
2013 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002014 log->Printf ("SBTarget(%p)::Clear ()",
2015 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002016
Greg Clayton48e42542010-07-30 20:12:55 +00002017 m_opaque_sp.reset();
2018}
2019
2020
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021SBModule
2022SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2023{
2024 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002025 TargetSP target_sp(GetSP());
2026 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00002027 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002028 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002029 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00002030 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00002031 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002032 return sb_module;
2033}
2034
Greg Clayton13d19502012-01-29 06:07:39 +00002035lldb::ByteOrder
2036SBTarget::GetByteOrder ()
2037{
Greg Claytonacdbe812012-01-30 09:04:36 +00002038 TargetSP target_sp(GetSP());
2039 if (target_sp)
2040 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00002041 return eByteOrderInvalid;
2042}
2043
2044const char *
2045SBTarget::GetTriple ()
2046{
Greg Claytonacdbe812012-01-30 09:04:36 +00002047 TargetSP target_sp(GetSP());
2048 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00002049 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002050 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00002051 // Unique the string so we don't run into ownership issues since
2052 // the const strings put the string into the string pool once and
2053 // the strings never comes out
2054 ConstString const_triple (triple.c_str());
2055 return const_triple.GetCString();
2056 }
2057 return NULL;
2058}
2059
2060uint32_t
2061SBTarget::GetAddressByteSize()
2062{
Greg Claytonacdbe812012-01-30 09:04:36 +00002063 TargetSP target_sp(GetSP());
2064 if (target_sp)
2065 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00002066 return sizeof(void*);
2067}
2068
2069
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002070SBModule
2071SBTarget::GetModuleAtIndex (uint32_t idx)
2072{
Greg Clayton5160ce52013-03-27 23:08:40 +00002073 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002074
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002075 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002076 ModuleSP module_sp;
2077 TargetSP target_sp(GetSP());
2078 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002079 {
2080 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002081 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2082 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002083 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002084
2085 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002086 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2087 static_cast<void*>(target_sp.get()), idx,
2088 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002089
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090 return sb_module;
2091}
2092
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002093bool
2094SBTarget::RemoveModule (lldb::SBModule module)
2095{
Greg Claytonacdbe812012-01-30 09:04:36 +00002096 TargetSP target_sp(GetSP());
2097 if (target_sp)
2098 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002099 return false;
2100}
2101
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002102
2103SBBroadcaster
2104SBTarget::GetBroadcaster () const
2105{
Greg Clayton5160ce52013-03-27 23:08:40 +00002106 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002107
Greg Claytonacdbe812012-01-30 09:04:36 +00002108 TargetSP target_sp(GetSP());
2109 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002110
Caroline Ticeceb6b132010-10-26 03:11:13 +00002111 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002112 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2113 static_cast<void*>(target_sp.get()),
2114 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002115
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002116 return broadcaster;
2117}
2118
Caroline Ticedde9cff2010-09-20 05:20:02 +00002119bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00002120SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00002121{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002122 Stream &strm = description.ref();
2123
Greg Claytonacdbe812012-01-30 09:04:36 +00002124 TargetSP target_sp(GetSP());
2125 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00002126 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002127 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002128 }
2129 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002130 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00002131
2132 return true;
2133}
2134
Greg Clayton5569e642012-02-06 01:44:54 +00002135lldb::SBSymbolContextList
2136SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00002137{
Greg Clayton5569e642012-02-06 01:44:54 +00002138 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00002139 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00002140 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002141 TargetSP target_sp(GetSP());
2142 if (target_sp)
2143 {
2144 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00002145 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00002146 const bool append = true;
2147 target_sp->GetImages().FindFunctions (ConstString(name),
2148 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002149 symbols_ok,
2150 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00002151 append,
2152 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00002153 }
Greg Claytonfe356d32011-06-21 01:34:41 +00002154 }
Greg Clayton5569e642012-02-06 01:44:54 +00002155 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00002156}
2157
Carlo Kok0fd6fd42014-09-19 19:38:19 +00002158lldb::SBSymbolContextList
2159SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
2160{
2161 lldb::SBSymbolContextList sb_sc_list;
2162 if (name && name[0])
2163 {
2164 TargetSP target_sp(GetSP());
2165 if (target_sp)
2166 {
2167 std::string regexstr;
2168 switch (matchtype)
2169 {
2170 case eMatchTypeRegex:
2171 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
2172 break;
2173 case eMatchTypeStartsWith:
2174 regexstr = llvm::Regex::escape(name) + ".*";
2175 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
2176 break;
2177 default:
2178 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
2179 break;
2180 }
2181 }
2182 }
2183 return sb_sc_list;
2184}
2185
Enrico Granata6f3533f2011-07-29 19:53:35 +00002186lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00002187SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002188{
Greg Claytonacdbe812012-01-30 09:04:36 +00002189 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002190 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002191 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002192 ConstString const_typename(typename_cstr);
2193 SymbolContext sc;
2194 const bool exact_match = false;
2195
2196 const ModuleList &module_list = target_sp->GetImages();
2197 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002198 for (size_t idx = 0; idx < count; idx++)
2199 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002200 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2201 if (module_sp)
2202 {
2203 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2204 if (type_sp)
2205 return SBType(type_sp);
2206 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00002207 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002208
2209 // Didn't find the type in the symbols; try the Objective-C runtime
2210 // if one is installed
2211
2212 ProcessSP process_sp(target_sp->GetProcessSP());
2213
2214 if (process_sp)
2215 {
2216 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2217
2218 if (objc_language_runtime)
2219 {
2220 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2221
2222 if (objc_type_vendor)
2223 {
2224 std::vector <ClangASTType> types;
2225
2226 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2227 return SBType(types[0]);
2228 }
2229 }
2230 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002231
2232 // No matches, search for basic typename matches
2233 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2234 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002235 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002236 }
2237 return SBType();
2238}
2239
Greg Claytonb43165b2012-12-05 21:24:42 +00002240SBType
2241SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002242{
Greg Claytonacdbe812012-01-30 09:04:36 +00002243 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002244 if (target_sp)
2245 {
2246 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2247 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002248 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002249 }
2250 return SBType();
2251}
2252
2253
2254lldb::SBTypeList
2255SBTarget::FindTypes (const char* typename_cstr)
2256{
2257 SBTypeList sb_type_list;
2258 TargetSP target_sp(GetSP());
2259 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002260 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002261 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002262 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002263 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002264 SymbolContext sc;
2265 TypeList type_list;
2266
Greg Clayton29399a22012-04-06 17:41:13 +00002267 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002268 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002269 exact_match,
2270 UINT32_MAX,
2271 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002272
Greg Claytonb43165b2012-12-05 21:24:42 +00002273 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002274 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002275 for (size_t idx = 0; idx < num_matches; idx++)
2276 {
2277 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2278 if (type_sp)
2279 sb_type_list.Append(SBType(type_sp));
2280 }
2281 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002282
2283 // Try the Objective-C runtime if one is installed
2284
2285 ProcessSP process_sp(target_sp->GetProcessSP());
2286
2287 if (process_sp)
2288 {
2289 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2290
2291 if (objc_language_runtime)
2292 {
2293 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2294
2295 if (objc_type_vendor)
2296 {
2297 std::vector <ClangASTType> types;
2298
2299 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2300 {
2301 for (ClangASTType &type : types)
2302 {
2303 sb_type_list.Append(SBType(type));
2304 }
2305 }
2306 }
2307 }
2308 }
2309
2310 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002311 {
2312 // No matches, search for basic typename matches
2313 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2314 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002315 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002316 }
2317 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002318 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002319}
2320
Greg Claytondea8cb42011-06-29 22:09:02 +00002321SBValueList
2322SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2323{
2324 SBValueList sb_value_list;
2325
Greg Claytonacdbe812012-01-30 09:04:36 +00002326 TargetSP target_sp(GetSP());
2327 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002328 {
2329 VariableList variable_list;
2330 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002331 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2332 append,
2333 max_matches,
2334 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002335
2336 if (match_count > 0)
2337 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002338 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002339 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002340 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002341 for (uint32_t i=0; i<match_count; ++i)
2342 {
2343 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2344 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002345 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002346 }
2347 }
2348 }
2349
2350 return sb_value_list;
2351}
2352
Carlo Kok0fd6fd42014-09-19 19:38:19 +00002353SBValueList
2354SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
2355{
2356 SBValueList sb_value_list;
2357
2358 TargetSP target_sp(GetSP());
2359 if (name && target_sp)
2360 {
2361 VariableList variable_list;
2362 const bool append = true;
2363
2364 std::string regexstr;
2365 uint32_t match_count;
2366 switch (matchtype)
2367 {
2368 case eMatchTypeNormal:
2369 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2370 append,
2371 max_matches,
2372 variable_list);
2373 break;
2374 case eMatchTypeRegex:
2375 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2376 append,
2377 max_matches,
2378 variable_list);
2379 break;
2380 case eMatchTypeStartsWith:
2381 regexstr = llvm::Regex::escape(name) + ".*";
2382 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2383 append,
2384 max_matches,
2385 variable_list);
2386 break;
2387 }
2388
2389
2390 if (match_count > 0)
2391 {
2392 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2393 if (exe_scope == NULL)
2394 exe_scope = target_sp.get();
2395 for (uint32_t i = 0; i<match_count; ++i)
2396 {
2397 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2398 if (valobj_sp)
2399 sb_value_list.Append(SBValue(valobj_sp));
2400 }
2401 }
2402 }
2403
2404 return sb_value_list;
2405}
2406
2407
Enrico Granatabcd80b42013-01-16 18:53:52 +00002408lldb::SBValue
2409SBTarget::FindFirstGlobalVariable (const char* name)
2410{
2411 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2412 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2413 return sb_value_list.GetValueAtIndex(0);
2414 return SBValue();
2415}
2416
Jim Inghame37d6052011-09-13 00:29:56 +00002417SBSourceManager
2418SBTarget::GetSourceManager()
2419{
2420 SBSourceManager source_manager (*this);
2421 return source_manager;
2422}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002423
Sean Callanan50952e92011-12-14 23:49:37 +00002424lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002425SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2426{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002427 return ReadInstructions (base_addr, count, NULL);
2428}
2429
2430lldb::SBInstructionList
2431SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2432{
Greg Clayton9c766112012-03-06 22:24:44 +00002433 SBInstructionList sb_instructions;
2434
2435 TargetSP target_sp(GetSP());
2436 if (target_sp)
2437 {
2438 Address *addr_ptr = base_addr.get();
2439
2440 if (addr_ptr)
2441 {
2442 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2443 bool prefer_file_cache = false;
2444 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002445 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2446 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2447 prefer_file_cache,
2448 data.GetBytes(),
2449 data.GetByteSize(),
2450 error,
2451 &load_addr);
2452 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002453 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2454 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002455 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002456 *addr_ptr,
2457 data.GetBytes(),
2458 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002459 count,
2460 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002461 }
2462 }
2463
2464 return sb_instructions;
2465
2466}
2467
2468lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002469SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2470{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002471 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2472}
2473
2474lldb::SBInstructionList
2475SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2476{
Sean Callanan50952e92011-12-14 23:49:37 +00002477 SBInstructionList sb_instructions;
2478
Greg Claytonacdbe812012-01-30 09:04:36 +00002479 TargetSP target_sp(GetSP());
2480 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002481 {
2482 Address addr;
2483
2484 if (base_addr.get())
2485 addr = *base_addr.get();
2486
Greg Clayton3faf47c2013-03-28 23:42:53 +00002487 const bool data_from_file = true;
2488
Greg Claytonacdbe812012-01-30 09:04:36 +00002489 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002490 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002491 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002492 addr,
2493 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002494 size,
2495 UINT32_MAX,
2496 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002497 }
2498
2499 return sb_instructions;
2500}
2501
2502lldb::SBInstructionList
2503SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2504{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002505 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2506}
2507
2508lldb::SBInstructionList
2509SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2510{
2511 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002512}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002513
2514SBError
2515SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2516 lldb::addr_t section_base_addr)
2517{
2518 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002519 TargetSP target_sp(GetSP());
2520 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002521 {
2522 if (!section.IsValid())
2523 {
2524 sb_error.SetErrorStringWithFormat ("invalid section");
2525 }
2526 else
2527 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002528 SectionSP section_sp (section.GetSP());
2529 if (section_sp)
2530 {
2531 if (section_sp->IsThreadSpecific())
2532 {
2533 sb_error.SetErrorString ("thread specific sections are not yet supported");
2534 }
2535 else
2536 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002537 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002538 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002539 {
2540 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002541 if (process_sp)
2542 process_sp->Flush();
2543 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002544 }
2545 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002546 }
2547 }
2548 else
2549 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002550 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002551 }
2552 return sb_error;
2553}
2554
2555SBError
2556SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2557{
2558 SBError sb_error;
2559
Greg Claytonacdbe812012-01-30 09:04:36 +00002560 TargetSP target_sp(GetSP());
2561 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002562 {
2563 if (!section.IsValid())
2564 {
2565 sb_error.SetErrorStringWithFormat ("invalid section");
2566 }
2567 else
2568 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002569 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002570 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002571 {
2572 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002573 if (process_sp)
2574 process_sp->Flush();
2575 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002576 }
2577 }
2578 else
2579 {
2580 sb_error.SetErrorStringWithFormat ("invalid target");
2581 }
2582 return sb_error;
2583}
2584
2585SBError
2586SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2587{
2588 SBError sb_error;
2589
Greg Claytonacdbe812012-01-30 09:04:36 +00002590 TargetSP target_sp(GetSP());
2591 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002592 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002593 ModuleSP module_sp (module.GetSP());
2594 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002595 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002596 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002597 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002598 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002599 // The load was successful, make sure that at least some sections
2600 // changed before we notify that our module was loaded.
2601 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002602 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002603 ModuleList module_list;
2604 module_list.Append(module_sp);
2605 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002606 // Flush info in the process (stack frames, etc)
2607 ProcessSP process_sp (target_sp->GetProcessSP());
2608 if (process_sp)
2609 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002610 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002611 }
2612 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002613 else
2614 {
2615 sb_error.SetErrorStringWithFormat ("invalid module");
2616 }
2617
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002618 }
2619 else
2620 {
2621 sb_error.SetErrorStringWithFormat ("invalid target");
2622 }
2623 return sb_error;
2624}
2625
2626SBError
2627SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2628{
2629 SBError sb_error;
2630
2631 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002632 TargetSP target_sp(GetSP());
2633 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002634 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002635 ModuleSP module_sp (module.GetSP());
2636 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002637 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002638 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002639 if (objfile)
2640 {
2641 SectionList *section_list = objfile->GetSectionList();
2642 if (section_list)
2643 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002644 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002645
Greg Clayton3c947372013-01-29 01:17:09 +00002646 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002647 const size_t num_sections = section_list->GetSize();
2648 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2649 {
2650 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2651 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002652 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002653 }
2654 if (changed)
2655 {
2656 // Flush info in the process (stack frames, etc)
2657 ProcessSP process_sp (target_sp->GetProcessSP());
2658 if (process_sp)
2659 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002660 }
2661 }
2662 else
2663 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002664 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002665 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2666 }
2667 }
2668 else
2669 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002670 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002671 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2672 }
2673 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002674 else
2675 {
2676 sb_error.SetErrorStringWithFormat ("invalid module");
2677 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002678 }
2679 else
2680 {
2681 sb_error.SetErrorStringWithFormat ("invalid target");
2682 }
2683 return sb_error;
2684}
2685
2686
Greg Claytone14e1922012-12-04 02:22:16 +00002687lldb::SBSymbolContextList
2688SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2689{
2690 SBSymbolContextList sb_sc_list;
2691 if (name && name[0])
2692 {
2693 TargetSP target_sp(GetSP());
2694 if (target_sp)
2695 {
2696 bool append = true;
2697 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2698 symbol_type,
2699 *sb_sc_list,
2700 append);
2701 }
2702 }
2703 return sb_sc_list;
2704
2705}
2706
2707
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002708lldb::SBValue
2709SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2710{
Greg Clayton5160ce52013-03-27 23:08:40 +00002711 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2712 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002713 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002714 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002715 ValueObjectSP expr_value_sp;
2716 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002717 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002718 if (target_sp)
2719 {
2720 if (expr == NULL || expr[0] == '\0')
2721 {
2722 if (log)
2723 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2724 return expr_result;
2725 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002726
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002727 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2728 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002729
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002730 if (log)
2731 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002732
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002733 frame = exe_ctx.GetFramePtr();
2734 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002735
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002736 if (target)
2737 {
2738#ifdef LLDB_CONFIGURATION_DEBUG
2739 StreamString frame_description;
2740 if (frame)
2741 frame->DumpUsingSettingsFormat (&frame_description);
2742 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2743 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2744#endif
2745 exe_results = target->EvaluateExpression (expr,
2746 frame,
2747 expr_value_sp,
2748 options.ref());
2749
2750 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2751#ifdef LLDB_CONFIGURATION_DEBUG
2752 Host::SetCrashDescription (NULL);
2753#endif
2754 }
2755 else
2756 {
2757 if (log)
2758 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2759 }
2760 }
2761#ifndef LLDB_DISABLE_PYTHON
2762 if (expr_log)
2763 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002764 expr_result.GetValue(), expr_result.GetSummary());
2765
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002766 if (log)
2767 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002768 static_cast<void*>(frame), expr,
2769 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002770#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002771
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002772 return expr_result;
2773}
2774
Greg Clayton13fbb992013-02-01 00:47:49 +00002775
2776lldb::addr_t
2777SBTarget::GetStackRedZoneSize()
2778{
2779 TargetSP target_sp(GetSP());
2780 if (target_sp)
2781 {
2782 ABISP abi_sp;
2783 ProcessSP process_sp (target_sp->GetProcessSP());
2784 if (process_sp)
2785 abi_sp = process_sp->GetABI();
2786 else
2787 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2788 if (abi_sp)
2789 return abi_sp->GetRedZoneSize();
2790 }
2791 return 0;
2792}
2793