blob: 27a492da344779eb65784cf2dd2be85678239e51 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBTarget.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytone0d378b2011-03-24 21:19:54 +000014#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Claytondea8cb42011-06-29 22:09:02 +000016#include "lldb/API/SBDebugger.h"
17#include "lldb/API/SBBreakpoint.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000018#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000020#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000022#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000023#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000024#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000025#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
41#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000042#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Greg Clayton1f746072012-08-29 21:13:06 +000050#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000051#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000052#include "lldb/Symbol/VariableList.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000053#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054#include "lldb/Target/Process.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000055
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Target.h"
57#include "lldb/Target/TargetList.h"
58
59#include "lldb/Interpreter/CommandReturnObject.h"
60#include "../source/Commands/CommandObjectBreakpoint.h"
61
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
63using namespace lldb;
64using namespace lldb_private;
65
66#define DEFAULT_DISASM_BYTE_SIZE 32
67
Greg Clayton38d1f052012-02-24 20:59:25 +000068SBLaunchInfo::SBLaunchInfo (const char **argv) :
69 m_opaque_sp(new ProcessLaunchInfo())
Greg Clayton0e615682012-02-24 05:03:03 +000070{
Greg Clayton38d1f052012-02-24 20:59:25 +000071 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
72 if (argv && argv[0])
73 m_opaque_sp->GetArguments().SetArguments(argv);
Greg Clayton0e615682012-02-24 05:03:03 +000074}
75
Greg Claytonecc7c0d2012-03-07 23:52:51 +000076SBLaunchInfo::~SBLaunchInfo()
77{
78}
79
80lldb_private::ProcessLaunchInfo &
81SBLaunchInfo::ref ()
82{
83 return *m_opaque_sp;
84}
85
86
Greg Clayton0e615682012-02-24 05:03:03 +000087uint32_t
88SBLaunchInfo::GetUserID()
89{
90 return m_opaque_sp->GetUserID();
91}
92
93uint32_t
94SBLaunchInfo::GetGroupID()
95{
96 return m_opaque_sp->GetGroupID();
97}
98
99bool
100SBLaunchInfo::UserIDIsValid ()
101{
102 return m_opaque_sp->UserIDIsValid();
103}
104
105bool
106SBLaunchInfo::GroupIDIsValid ()
107{
108 return m_opaque_sp->GroupIDIsValid();
109}
110
111void
112SBLaunchInfo::SetUserID (uint32_t uid)
113{
114 m_opaque_sp->SetUserID (uid);
115}
116
117void
118SBLaunchInfo::SetGroupID (uint32_t gid)
119{
120 m_opaque_sp->SetGroupID (gid);
121}
122
Greg Clayton3e32ad62014-05-07 20:16:06 +0000123SBFileSpec
124SBLaunchInfo::GetExecutableFile ()
125{
126 return SBFileSpec (m_opaque_sp->GetExecutableFile());
127}
128
129void
130SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg)
131{
132 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
133}
134
Greg Clayton0e615682012-02-24 05:03:03 +0000135uint32_t
136SBLaunchInfo::GetNumArguments ()
137{
138 return m_opaque_sp->GetArguments().GetArgumentCount();
139}
140
141const char *
142SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
143{
144 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
145}
146
147void
148SBLaunchInfo::SetArguments (const char **argv, bool append)
149{
150 if (append)
151 {
152 if (argv)
153 m_opaque_sp->GetArguments().AppendArguments(argv);
154 }
155 else
156 {
157 if (argv)
158 m_opaque_sp->GetArguments().SetArguments(argv);
159 else
160 m_opaque_sp->GetArguments().Clear();
161 }
162}
163
164uint32_t
165SBLaunchInfo::GetNumEnvironmentEntries ()
166{
167 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
168}
169
170const char *
171SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
172{
173 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
174}
175
176void
177SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
178{
179 if (append)
180 {
181 if (envp)
182 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
183 }
184 else
185 {
186 if (envp)
187 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
188 else
189 m_opaque_sp->GetEnvironmentEntries().Clear();
190 }
191}
192
193void
194SBLaunchInfo::Clear ()
195{
196 m_opaque_sp->Clear();
197}
198
199const char *
200SBLaunchInfo::GetWorkingDirectory () const
201{
202 return m_opaque_sp->GetWorkingDirectory();
203}
204
205void
206SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
207{
208 m_opaque_sp->SetWorkingDirectory(working_dir);
209}
210
211uint32_t
212SBLaunchInfo::GetLaunchFlags ()
213{
214 return m_opaque_sp->GetFlags().Get();
215}
216
217void
218SBLaunchInfo::SetLaunchFlags (uint32_t flags)
219{
220 m_opaque_sp->GetFlags().Reset(flags);
221}
222
223const char *
224SBLaunchInfo::GetProcessPluginName ()
225{
226 return m_opaque_sp->GetProcessPluginName();
227}
228
229void
230SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
231{
232 return m_opaque_sp->SetProcessPluginName (plugin_name);
233}
234
235const char *
236SBLaunchInfo::GetShell ()
237{
238 return m_opaque_sp->GetShell();
239}
240
241void
242SBLaunchInfo::SetShell (const char * path)
243{
244 m_opaque_sp->SetShell (path);
245}
246
247uint32_t
248SBLaunchInfo::GetResumeCount ()
249{
250 return m_opaque_sp->GetResumeCount();
251}
252
253void
254SBLaunchInfo::SetResumeCount (uint32_t c)
255{
256 m_opaque_sp->SetResumeCount (c);
257}
258
259bool
260SBLaunchInfo::AddCloseFileAction (int fd)
261{
262 return m_opaque_sp->AppendCloseFileAction(fd);
263}
264
265bool
266SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
267{
268 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
269}
270
271bool
272SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
273{
274 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
275}
276
277bool
278SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
279{
280 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
281}
282
Jason Molendaa3329782014-03-29 18:54:20 +0000283void
284SBLaunchInfo::SetLaunchEventData (const char *data)
285{
286 m_opaque_sp->SetLaunchEventData (data);
287}
288
289const char *
290SBLaunchInfo::GetLaunchEventData () const
291{
292 return m_opaque_sp->GetLaunchEventData ();
293}
Greg Clayton0e615682012-02-24 05:03:03 +0000294
295SBAttachInfo::SBAttachInfo () :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000296 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000297{
298}
299
300SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000301 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000302{
303 m_opaque_sp->SetProcessID (pid);
304}
305
306SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000307 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000308{
309 if (path && path[0])
310 m_opaque_sp->GetExecutableFile().SetFile(path, false);
311 m_opaque_sp->SetWaitForLaunch (wait_for);
312}
313
314SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000315 m_opaque_sp (new ProcessAttachInfo())
Greg Clayton0e615682012-02-24 05:03:03 +0000316{
317 *m_opaque_sp = *rhs.m_opaque_sp;
318}
319
Greg Claytonecc7c0d2012-03-07 23:52:51 +0000320SBAttachInfo::~SBAttachInfo()
321{
322}
323
324lldb_private::ProcessAttachInfo &
325SBAttachInfo::ref ()
326{
327 return *m_opaque_sp;
328}
329
Greg Clayton0e615682012-02-24 05:03:03 +0000330SBAttachInfo &
331SBAttachInfo::operator = (const SBAttachInfo &rhs)
332{
333 if (this != &rhs)
334 *m_opaque_sp = *rhs.m_opaque_sp;
335 return *this;
336}
337
338lldb::pid_t
339SBAttachInfo::GetProcessID ()
340{
341 return m_opaque_sp->GetProcessID();
342}
343
344void
345SBAttachInfo::SetProcessID (lldb::pid_t pid)
346{
347 m_opaque_sp->SetProcessID (pid);
348}
349
350
351uint32_t
352SBAttachInfo::GetResumeCount ()
353{
354 return m_opaque_sp->GetResumeCount();
355}
356
357void
358SBAttachInfo::SetResumeCount (uint32_t c)
359{
360 m_opaque_sp->SetResumeCount (c);
361}
362
363const char *
364SBAttachInfo::GetProcessPluginName ()
365{
366 return m_opaque_sp->GetProcessPluginName();
367}
368
369void
370SBAttachInfo::SetProcessPluginName (const char *plugin_name)
371{
372 return m_opaque_sp->SetProcessPluginName (plugin_name);
373}
374
375void
376SBAttachInfo::SetExecutable (const char *path)
377{
378 if (path && path[0])
379 m_opaque_sp->GetExecutableFile().SetFile(path, false);
380 else
381 m_opaque_sp->GetExecutableFile().Clear();
382}
383
384void
385SBAttachInfo::SetExecutable (SBFileSpec exe_file)
386{
387 if (exe_file.IsValid())
388 m_opaque_sp->GetExecutableFile() = exe_file.ref();
389 else
390 m_opaque_sp->GetExecutableFile().Clear();
391}
392
393bool
394SBAttachInfo::GetWaitForLaunch ()
395{
396 return m_opaque_sp->GetWaitForLaunch();
397}
398
399void
400SBAttachInfo::SetWaitForLaunch (bool b)
401{
402 m_opaque_sp->SetWaitForLaunch (b);
403}
404
Jim Inghamcd16df92012-07-20 21:37:13 +0000405bool
406SBAttachInfo::GetIgnoreExisting ()
407{
408 return m_opaque_sp->GetIgnoreExisting();
409}
410
411void
412SBAttachInfo::SetIgnoreExisting (bool b)
413{
414 m_opaque_sp->SetIgnoreExisting (b);
415}
416
Greg Clayton0e615682012-02-24 05:03:03 +0000417uint32_t
Greg Clayton41bd8ac2012-02-24 23:56:06 +0000418SBAttachInfo::GetUserID()
419{
420 return m_opaque_sp->GetUserID();
421}
422
423uint32_t
424SBAttachInfo::GetGroupID()
425{
426 return m_opaque_sp->GetGroupID();
427}
428
429bool
430SBAttachInfo::UserIDIsValid ()
431{
432 return m_opaque_sp->UserIDIsValid();
433}
434
435bool
436SBAttachInfo::GroupIDIsValid ()
437{
438 return m_opaque_sp->GroupIDIsValid();
439}
440
441void
442SBAttachInfo::SetUserID (uint32_t uid)
443{
444 m_opaque_sp->SetUserID (uid);
445}
446
447void
448SBAttachInfo::SetGroupID (uint32_t gid)
449{
450 m_opaque_sp->SetGroupID (gid);
451}
452
453uint32_t
Greg Clayton0e615682012-02-24 05:03:03 +0000454SBAttachInfo::GetEffectiveUserID()
455{
456 return m_opaque_sp->GetEffectiveUserID();
457}
458
459uint32_t
460SBAttachInfo::GetEffectiveGroupID()
461{
462 return m_opaque_sp->GetEffectiveGroupID();
463}
464
465bool
466SBAttachInfo::EffectiveUserIDIsValid ()
467{
468 return m_opaque_sp->EffectiveUserIDIsValid();
469}
470
471bool
472SBAttachInfo::EffectiveGroupIDIsValid ()
473{
474 return m_opaque_sp->EffectiveGroupIDIsValid ();
475}
476
477void
478SBAttachInfo::SetEffectiveUserID (uint32_t uid)
479{
480 m_opaque_sp->SetEffectiveUserID(uid);
481}
482
483void
484SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
485{
486 m_opaque_sp->SetEffectiveGroupID(gid);
487}
488
489lldb::pid_t
490SBAttachInfo::GetParentProcessID ()
491{
492 return m_opaque_sp->GetParentProcessID();
493}
494
495void
496SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
497{
498 m_opaque_sp->SetParentProcessID (pid);
499}
500
501bool
502SBAttachInfo::ParentProcessIDIsValid()
503{
504 return m_opaque_sp->ParentProcessIDIsValid();
505}
506
507
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508//----------------------------------------------------------------------
509// SBTarget constructor
510//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000511SBTarget::SBTarget () :
512 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513{
514}
515
516SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000517 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518{
519}
520
521SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000522 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523{
524}
525
Greg Claytonefabb122010-11-05 23:17:00 +0000526const SBTarget&
527SBTarget::operator = (const SBTarget& rhs)
528{
529 if (this != &rhs)
530 m_opaque_sp = rhs.m_opaque_sp;
531 return *this;
532}
533
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534//----------------------------------------------------------------------
535// Destructor
536//----------------------------------------------------------------------
537SBTarget::~SBTarget()
538{
539}
540
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000541const char *
542SBTarget::GetBroadcasterClassName ()
543{
544 return Target::GetStaticBroadcasterClass().AsCString();
545}
546
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547bool
548SBTarget::IsValid () const
549{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000550 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551}
552
553SBProcess
554SBTarget::GetProcess ()
555{
556 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000557 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000558 TargetSP target_sp(GetSP());
559 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000560 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000561 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000562 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000563 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000564
Greg Clayton5160ce52013-03-27 23:08:40 +0000565 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000566 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000567 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
568 static_cast<void*>(target_sp.get()),
569 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000570
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 return sb_process;
572}
573
Greg Clayton66111032010-06-23 01:19:29 +0000574SBDebugger
575SBTarget::GetDebugger () const
576{
577 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000578 TargetSP target_sp(GetSP());
579 if (target_sp)
580 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000581 return debugger;
582}
583
Jim Ingham270684d2011-03-31 00:01:24 +0000584SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000585SBTarget::LoadCore (const char *core_file)
586{
587 SBProcess sb_process;
588 TargetSP target_sp(GetSP());
589 if (target_sp)
590 {
591 FileSpec filespec(core_file, true);
592 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
593 NULL,
594 &filespec));
595 if (process_sp)
596 {
597 process_sp->LoadCore();
598 sb_process.SetSP (process_sp);
599 }
600 }
601 return sb_process;
602}
603
604SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000605SBTarget::LaunchSimple
606(
607 char const **argv,
608 char const **envp,
609 const char *working_directory
610)
611{
612 char *stdin_path = NULL;
613 char *stdout_path = NULL;
614 char *stderr_path = NULL;
615 uint32_t launch_flags = 0;
616 bool stop_at_entry = false;
617 SBError error;
618 SBListener listener = GetDebugger().GetListener();
619 return Launch (listener,
620 argv,
621 envp,
622 stdin_path,
623 stdout_path,
624 stderr_path,
625 working_directory,
626 launch_flags,
627 stop_at_entry,
628 error);
629}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000630
Greg Claytonfbb76342013-11-20 21:07:01 +0000631SBError
632SBTarget::Install()
633{
634 SBError sb_error;
635 TargetSP target_sp(GetSP());
636 if (target_sp)
637 {
638 Mutex::Locker api_locker (target_sp->GetAPIMutex());
639 sb_error.ref() = target_sp->Install(NULL);
640 }
641 return sb_error;
642}
643
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000644SBProcess
645SBTarget::Launch
646(
Greg Clayton4b045622011-02-03 21:28:34 +0000647 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000648 char const **argv,
649 char const **envp,
650 const char *stdin_path,
651 const char *stdout_path,
652 const char *stderr_path,
653 const char *working_directory,
654 uint32_t launch_flags, // See LaunchFlags
655 bool stop_at_entry,
656 lldb::SBError& error
657)
658{
Greg Clayton5160ce52013-03-27 23:08:40 +0000659 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000660
Greg Claytonacdbe812012-01-30 09:04:36 +0000661 SBProcess sb_process;
662 ProcessSP process_sp;
663 TargetSP target_sp(GetSP());
664
Caroline Ticeceb6b132010-10-26 03:11:13 +0000665 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000666 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 +0000667 static_cast<void*>(target_sp.get()),
668 static_cast<void*>(argv), static_cast<void*>(envp),
669 stdin_path ? stdin_path : "NULL",
670 stdout_path ? stdout_path : "NULL",
671 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000672 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000673 launch_flags, stop_at_entry,
674 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000675
676 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000678 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000679
Greg Clayton645bf542011-01-27 01:01:10 +0000680 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
681 launch_flags |= eLaunchFlagDisableASLR;
682
Greg Clayton2289fa42011-04-30 01:09:13 +0000683 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000684 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000685 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000686 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000687 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000688
Greg Claytonb9556ac2012-01-30 07:41:31 +0000689 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000690 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000691 if (state == eStateAttaching)
692 error.SetErrorString ("process attach is in progress");
693 else
694 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000695 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000696 }
Greg Clayton931180e2011-01-27 06:44:37 +0000697 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000698
Greg Clayton2289fa42011-04-30 01:09:13 +0000699 if (state == eStateConnected)
700 {
701 // If we are already connected, then we have already specified the
702 // listener, so if a valid listener is supplied, we need to error out
703 // to let the client know.
704 if (listener.IsValid())
705 {
706 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000707 return sb_process;
708 }
709 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000710
711 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
712 launch_flags |= eLaunchFlagDisableSTDIO;
713
714 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000715
Greg Claytonb09c5382013-12-13 17:20:18 +0000716 Module *exe_module = target_sp->GetExecutableModulePointer();
717 if (exe_module)
718 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
719 if (argv)
720 launch_info.GetArguments().AppendArguments (argv);
721 if (envp)
722 launch_info.GetEnvironmentEntries ().SetArguments (envp);
723
724 if (listener.IsValid())
725 error.SetError (target_sp->Launch(listener.ref(), launch_info));
Greg Clayton2289fa42011-04-30 01:09:13 +0000726 else
Greg Claytonb09c5382013-12-13 17:20:18 +0000727 error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
Greg Clayton645bf542011-01-27 01:01:10 +0000728
Greg Claytonb09c5382013-12-13 17:20:18 +0000729 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000730 }
731 else
732 {
733 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000734 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000735
Caroline Tice20ad3c42010-10-29 21:48:37 +0000736 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000737 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000738 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
739 static_cast<void*>(target_sp.get()),
740 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000741
Greg Clayton5d5028b2010-10-06 03:53:16 +0000742 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743}
744
Greg Clayton0e615682012-02-24 05:03:03 +0000745SBProcess
746SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
747{
Greg Clayton5160ce52013-03-27 23:08:40 +0000748 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000749
Greg Clayton0e615682012-02-24 05:03:03 +0000750 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000751 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000752
Greg Clayton0e615682012-02-24 05:03:03 +0000753 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000754 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
755 static_cast<void*>(target_sp.get()));
756
Greg Clayton0e615682012-02-24 05:03:03 +0000757 if (target_sp)
758 {
759 Mutex::Locker api_locker (target_sp->GetAPIMutex());
760 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000761 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000762 ProcessSP process_sp = target_sp->GetProcessSP();
763 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000764 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000765 state = process_sp->GetState();
766
767 if (process_sp->IsAlive() && state != eStateConnected)
768 {
769 if (state == eStateAttaching)
770 error.SetErrorString ("process attach is in progress");
771 else
772 error.SetErrorString ("a process is already being debugged");
773 return sb_process;
774 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000775 }
Greg Clayton0e615682012-02-24 05:03:03 +0000776 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000777
778 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
779
Greg Clayton3e32ad62014-05-07 20:16:06 +0000780 if (!launch_info.GetExecutableFile())
781 {
782 Module *exe_module = target_sp->GetExecutableModulePointer();
783 if (exe_module)
784 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
785 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000786
787 const ArchSpec &arch_spec = target_sp->GetArchitecture();
788 if (arch_spec.IsValid())
789 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000790
Greg Claytonb09c5382013-12-13 17:20:18 +0000791 error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
792 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000793 }
794 else
795 {
796 error.SetErrorString ("SBTarget is invalid");
797 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000798
Greg Clayton0e615682012-02-24 05:03:03 +0000799 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
800 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000801 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000802 static_cast<void*>(target_sp.get()),
803 static_cast<void*>(sb_process.GetSP().get()));
804
Greg Clayton0e615682012-02-24 05:03:03 +0000805 return sb_process;
806}
807
808lldb::SBProcess
809SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
810{
Greg Clayton5160ce52013-03-27 23:08:40 +0000811 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000812
Greg Clayton0e615682012-02-24 05:03:03 +0000813 SBProcess sb_process;
814 ProcessSP process_sp;
815 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000816
Sean Callanan575a4542012-10-20 00:21:31 +0000817 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000818 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
819 static_cast<void*>(target_sp.get()));
820
Greg Clayton0e615682012-02-24 05:03:03 +0000821 if (target_sp)
822 {
823 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000824
Greg Clayton0e615682012-02-24 05:03:03 +0000825 StateType state = eStateInvalid;
826 process_sp = target_sp->GetProcessSP();
827 if (process_sp)
828 {
829 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000830
Greg Clayton0e615682012-02-24 05:03:03 +0000831 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000832 {
Greg Clayton0e615682012-02-24 05:03:03 +0000833 if (state == eStateAttaching)
834 error.SetErrorString ("process attach is in progress");
835 else
836 error.SetErrorString ("a process is already being debugged");
Sean Callanan575a4542012-10-20 00:21:31 +0000837 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000838 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000839 static_cast<void*>(target_sp.get()),
840 error.GetCString());
Greg Clayton0e615682012-02-24 05:03:03 +0000841 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000842 }
Greg Clayton0e615682012-02-24 05:03:03 +0000843 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000844
Greg Clayton0e615682012-02-24 05:03:03 +0000845 if (state != eStateConnected)
846 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
847
848 if (process_sp)
849 {
Greg Clayton0e615682012-02-24 05:03:03 +0000850 ProcessAttachInfo &attach_info = sb_attach_info.ref();
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000851 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000852 {
853 PlatformSP platform_sp = target_sp->GetPlatform();
Greg Clayton91e407e2012-09-27 00:03:39 +0000854 // See if we can pre-verify if a process exists or not
855 if (platform_sp && platform_sp->IsConnected())
Han Ming Ongcec8c902012-02-29 00:12:56 +0000856 {
Han Ming Ongfbd8de82013-03-25 20:11:18 +0000857 lldb::pid_t attach_pid = attach_info.GetProcessID();
Greg Clayton91e407e2012-09-27 00:03:39 +0000858 ProcessInstanceInfo instance_info;
859 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
860 {
861 attach_info.SetUserID(instance_info.GetEffectiveUserID());
862 }
863 else
864 {
Daniel Malead01b2952012-11-29 21:49:15 +0000865 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
Sean Callanan575a4542012-10-20 00:21:31 +0000866 if (log)
867 {
868 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000869 static_cast<void*>(target_sp.get()), error.GetCString());
Sean Callanan575a4542012-10-20 00:21:31 +0000870 }
Greg Clayton91e407e2012-09-27 00:03:39 +0000871 return sb_process;
872 }
Han Ming Ongcec8c902012-02-29 00:12:56 +0000873 }
874 }
Han Ming Ongbee98392012-02-29 19:16:40 +0000875 error.SetError (process_sp->Attach (attach_info));
876 if (error.Success())
877 {
878 sb_process.SetSP (process_sp);
879 // If we are doing synchronous mode, then wait for the
880 // process to stop!
881 if (target_sp->GetDebugger().GetAsyncExecution () == false)
882 process_sp->WaitForProcessToStop (NULL);
883 }
Greg Clayton0e615682012-02-24 05:03:03 +0000884 }
885 else
886 {
887 error.SetErrorString ("unable to create lldb_private::Process");
888 }
889 }
890 else
891 {
892 error.SetErrorString ("SBTarget is invalid");
893 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000894
Sean Callanan575a4542012-10-20 00:21:31 +0000895 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000896 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000897 static_cast<void*>(target_sp.get()),
898 static_cast<void*>(process_sp.get()));
899
Greg Clayton0e615682012-02-24 05:03:03 +0000900 return sb_process;
901}
902
903
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000904#if defined(__APPLE__)
905
906lldb::SBProcess
907SBTarget::AttachToProcessWithID (SBListener &listener,
908 ::pid_t pid,
909 lldb::SBError& error)
910{
911 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
912}
913
914#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000915
916lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000917SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000918(
Greg Clayton4b045622011-02-03 21:28:34 +0000919 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000920 lldb::pid_t pid,// The process ID to attach to
921 SBError& error // An error explaining what went wrong if attach fails
922)
923{
Greg Clayton5160ce52013-03-27 23:08:40 +0000924 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000925
Greg Clayton524e60b2010-10-06 22:10:17 +0000926 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000927 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000928 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000929
930 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000931 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...",
932 static_cast<void*>(target_sp.get()), pid);
933
Greg Claytonacdbe812012-01-30 09:04:36 +0000934 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000935 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000936 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0c74e782011-06-24 03:21:43 +0000937
938 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000939 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000940 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +0000941 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000942 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000943
Greg Claytonb9556ac2012-01-30 07:41:31 +0000944 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000945 {
Greg Clayton0c74e782011-06-24 03:21:43 +0000946 if (state == eStateAttaching)
947 error.SetErrorString ("process attach is in progress");
948 else
949 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +0000950 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000951 }
Greg Clayton0c74e782011-06-24 03:21:43 +0000952 }
953
954 if (state == eStateConnected)
955 {
956 // If we are already connected, then we have already specified the
957 // listener, so if a valid listener is supplied, we need to error out
958 // to let the client know.
959 if (listener.IsValid())
960 {
961 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +0000962 return sb_process;
963 }
964 }
Greg Clayton4b045622011-02-03 21:28:34 +0000965 else
Greg Clayton0c74e782011-06-24 03:21:43 +0000966 {
967 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000968 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000969 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000970 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +0000971 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000972 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000973 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000974 sb_process.SetSP (process_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000975
Greg Clayton144f3a92011-11-15 03:53:30 +0000976 ProcessAttachInfo attach_info;
977 attach_info.SetProcessID (pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000978
Han Ming Ong84647042012-02-25 01:07:38 +0000979 PlatformSP platform_sp = target_sp->GetPlatform();
980 ProcessInstanceInfo instance_info;
981 if (platform_sp->GetProcessInfo(pid, instance_info))
982 {
983 attach_info.SetUserID(instance_info.GetEffectiveUserID());
Han Ming Ong84647042012-02-25 01:07:38 +0000984 }
Greg Claytonb9556ac2012-01-30 07:41:31 +0000985 error.SetError (process_sp->Attach (attach_info));
Greg Claytone2186ed2012-09-07 17:51:47 +0000986 if (error.Success())
987 {
988 // If we are doing synchronous mode, then wait for the
989 // process to stop!
990 if (target_sp->GetDebugger().GetAsyncExecution () == false)
Greg Claytonb9556ac2012-01-30 07:41:31 +0000991 process_sp->WaitForProcessToStop (NULL);
Greg Claytone2186ed2012-09-07 17:51:47 +0000992 }
Greg Clayton524e60b2010-10-06 22:10:17 +0000993 }
994 else
995 {
996 error.SetErrorString ("unable to create lldb_private::Process");
997 }
998 }
999 else
1000 {
1001 error.SetErrorString ("SBTarget is invalid");
1002 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001003
Sean Callanan575a4542012-10-20 00:21:31 +00001004 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001005 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001006 static_cast<void*>(target_sp.get()),
1007 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001008 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001009}
1010
1011lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +00001012SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +00001013(
Greg Clayton4b045622011-02-03 21:28:34 +00001014 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +00001015 const char *name, // basename of process to attach to
1016 bool wait_for, // if true wait for a new instance of "name" to be launched
1017 SBError& error // An error explaining what went wrong if attach fails
1018)
1019{
Greg Clayton5160ce52013-03-27 23:08:40 +00001020 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001021
Greg Clayton524e60b2010-10-06 22:10:17 +00001022 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001023 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001024 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001025
Sean Callanan575a4542012-10-20 00:21:31 +00001026 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001027 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...",
1028 static_cast<void*>(target_sp.get()), name,
1029 wait_for ? "true" : "false");
1030
Greg Claytonacdbe812012-01-30 09:04:36 +00001031 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001032 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001033 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +00001034
Greg Clayton0c74e782011-06-24 03:21:43 +00001035 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +00001036 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001037 if (process_sp)
Greg Clayton0c74e782011-06-24 03:21:43 +00001038 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001039 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001040
Greg Claytonb9556ac2012-01-30 07:41:31 +00001041 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001042 {
Greg Clayton0c74e782011-06-24 03:21:43 +00001043 if (state == eStateAttaching)
1044 error.SetErrorString ("process attach is in progress");
1045 else
1046 error.SetErrorString ("a process is already being debugged");
Greg Clayton0c74e782011-06-24 03:21:43 +00001047 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001048 }
Greg Clayton0c74e782011-06-24 03:21:43 +00001049 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001050
Greg Clayton0c74e782011-06-24 03:21:43 +00001051 if (state == eStateConnected)
1052 {
1053 // If we are already connected, then we have already specified the
1054 // listener, so if a valid listener is supplied, we need to error out
1055 // to let the client know.
1056 if (listener.IsValid())
1057 {
1058 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton0c74e782011-06-24 03:21:43 +00001059 return sb_process;
1060 }
1061 }
Greg Clayton4b045622011-02-03 21:28:34 +00001062 else
Greg Clayton0c74e782011-06-24 03:21:43 +00001063 {
1064 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001065 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001066 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001067 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
Greg Clayton0c74e782011-06-24 03:21:43 +00001068 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001069
Greg Claytonb9556ac2012-01-30 07:41:31 +00001070 if (process_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +00001071 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001072 sb_process.SetSP (process_sp);
Greg Clayton144f3a92011-11-15 03:53:30 +00001073 ProcessAttachInfo attach_info;
1074 attach_info.GetExecutableFile().SetFile(name, false);
1075 attach_info.SetWaitForLaunch(wait_for);
Greg Claytonb9556ac2012-01-30 07:41:31 +00001076 error.SetError (process_sp->Attach (attach_info));
Daniel Malead659dc12013-04-01 19:47:00 +00001077 if (error.Success())
1078 {
1079 // If we are doing synchronous mode, then wait for the
1080 // process to stop!
1081 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1082 process_sp->WaitForProcessToStop (NULL);
1083 }
Greg Clayton524e60b2010-10-06 22:10:17 +00001084 }
1085 else
1086 {
1087 error.SetErrorString ("unable to create lldb_private::Process");
1088 }
1089 }
1090 else
1091 {
1092 error.SetErrorString ("SBTarget is invalid");
1093 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001094
Sean Callanan575a4542012-10-20 00:21:31 +00001095 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001096 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001097 static_cast<void*>(target_sp.get()),
1098 static_cast<void*>(process_sp.get()));
Greg Clayton524e60b2010-10-06 22:10:17 +00001099 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +00001100}
1101
James McIlree9631aae2011-03-04 00:31:13 +00001102lldb::SBProcess
1103SBTarget::ConnectRemote
1104(
1105 SBListener &listener,
1106 const char *url,
1107 const char *plugin_name,
1108 SBError& error
1109)
1110{
Greg Clayton5160ce52013-03-27 23:08:40 +00001111 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +00001112
James McIlree9631aae2011-03-04 00:31:13 +00001113 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +00001114 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001115 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001116
Sean Callanan575a4542012-10-20 00:21:31 +00001117 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001118 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
1119 static_cast<void*>(target_sp.get()), url, plugin_name);
1120
Greg Claytonacdbe812012-01-30 09:04:36 +00001121 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001122 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001123 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +00001124 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +00001125 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +00001126 else
Greg Claytonc3776bf2012-02-09 06:16:32 +00001127 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001128
Greg Claytonb9556ac2012-01-30 07:41:31 +00001129 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +00001130 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001131 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +00001132 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +00001133 }
1134 else
1135 {
1136 error.SetErrorString ("unable to create lldb_private::Process");
1137 }
1138 }
1139 else
1140 {
1141 error.SetErrorString ("SBTarget is invalid");
1142 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001143
Sean Callanan575a4542012-10-20 00:21:31 +00001144 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +00001145 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001146 static_cast<void*>(target_sp.get()),
1147 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +00001148 return sb_process;
1149}
1150
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151SBFileSpec
1152SBTarget::GetExecutable ()
1153{
Caroline Ticeceb6b132010-10-26 03:11:13 +00001154
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +00001156 TargetSP target_sp(GetSP());
1157 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001158 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001159 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +00001160 if (exe_module)
1161 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001163
Greg Clayton5160ce52013-03-27 23:08:40 +00001164 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001165 if (log)
1166 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001167 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1168 static_cast<void*>(target_sp.get()),
1169 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001170 }
1171
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001172 return exe_file_spec;
1173}
1174
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001175bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176SBTarget::operator == (const SBTarget &rhs) const
1177{
Greg Clayton66111032010-06-23 01:19:29 +00001178 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001179}
1180
1181bool
1182SBTarget::operator != (const SBTarget &rhs) const
1183{
Greg Clayton66111032010-06-23 01:19:29 +00001184 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185}
1186
Greg Claytonb9556ac2012-01-30 07:41:31 +00001187lldb::TargetSP
1188SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +00001189{
1190 return m_opaque_sp;
1191}
1192
Greg Clayton66111032010-06-23 01:19:29 +00001193void
Greg Claytonb9556ac2012-01-30 07:41:31 +00001194SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001195{
1196 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197}
1198
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001199lldb::SBAddress
1200SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001201{
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001202 lldb::SBAddress sb_addr;
1203 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +00001204 TargetSP target_sp(GetSP());
1205 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001206 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001207 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +00001208 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001209 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +00001210 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001211
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001212 // We have a load address that isn't in a section, just return an address
1213 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +00001214 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +00001215 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +00001216}
1217
Greg Claytond5944cd2013-12-06 01:12:00 +00001218
1219lldb::SBAddress
1220SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1221{
1222 lldb::SBAddress sb_addr;
1223 Address &addr = sb_addr.ref();
1224 TargetSP target_sp(GetSP());
1225 if (target_sp)
1226 {
1227 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1228 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1229 return sb_addr;
1230 }
1231
1232 // We have a load address that isn't in a section, just return an address
1233 // with the offset filled in (the address) and the section set to NULL
1234 addr.SetRawAddress(vm_addr);
1235 return sb_addr;
1236}
1237
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001238SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +00001239SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1240 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001241{
1242 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +00001243 if (addr.IsValid())
1244 {
1245 TargetSP target_sp(GetSP());
1246 if (target_sp)
1247 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1248 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +00001249 return sc;
1250}
1251
1252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001254SBTarget::BreakpointCreateByLocation (const char *file,
1255 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256{
Greg Clayton7481c202010-11-08 00:28:40 +00001257 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258}
1259
1260SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001261SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1262 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263{
Greg Clayton5160ce52013-03-27 23:08:40 +00001264 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001265
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001267 TargetSP target_sp(GetSP());
1268 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001269 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001270 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001271
Greg Clayton1f746072012-08-29 21:13:06 +00001272 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +00001273 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +00001274 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001275 const bool hardware = false;
1276 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001277 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001278
1279 if (log)
1280 {
1281 SBStream sstr;
1282 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001283 char path[PATH_MAX];
1284 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001285 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1286 static_cast<void*>(target_sp.get()), path, line,
1287 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +00001288 }
1289
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290 return sb_bp;
1291}
1292
1293SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001294SBTarget::BreakpointCreateByName (const char *symbol_name,
1295 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296{
Greg Clayton5160ce52013-03-27 23:08:40 +00001297 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001298
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001300 TargetSP target_sp(GetSP());
1301 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001303 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001304
Jim Inghama8558b62012-05-22 00:12:20 +00001305 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001306 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001307 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 if (module_name && module_name[0])
1309 {
Jim Ingham969795f2011-09-21 01:17:13 +00001310 FileSpecList module_spec_list;
1311 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +00001312 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001313 }
1314 else
1315 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001316 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317 }
1318 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001319
Caroline Ticeceb6b132010-10-26 03:11:13 +00001320 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001321 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1322 static_cast<void*>(target_sp.get()), symbol_name,
1323 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001324
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325 return sb_bp;
1326}
1327
Jim Ingham87df91b2011-09-23 00:54:11 +00001328lldb::SBBreakpoint
1329SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001330 const SBFileSpecList &module_list,
1331 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001332{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001333 uint32_t name_type_mask = eFunctionNameTypeAuto;
1334 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1335}
1336
1337lldb::SBBreakpoint
1338SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +00001339 uint32_t name_type_mask,
1340 const SBFileSpecList &module_list,
1341 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +00001342{
Greg Clayton5160ce52013-03-27 23:08:40 +00001343 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001344
1345 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001346 TargetSP target_sp(GetSP());
1347 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001348 {
Jim Inghama8558b62012-05-22 00:12:20 +00001349 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001350 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001351 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +00001352 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1353 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +00001354 comp_unit_list.get(),
1355 symbol_name,
1356 name_type_mask,
1357 skip_prologue,
1358 internal,
1359 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001360 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001361
Jim Ingham87df91b2011-09-23 00:54:11 +00001362 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001363 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1364 static_cast<void*>(target_sp.get()), symbol_name,
1365 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001366
1367 return sb_bp;
1368}
1369
Jim Inghamfab10e82012-03-06 00:37:27 +00001370lldb::SBBreakpoint
1371SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1372 uint32_t num_names,
1373 uint32_t name_type_mask,
1374 const SBFileSpecList &module_list,
1375 const SBFileSpecList &comp_unit_list)
1376{
Greg Clayton5160ce52013-03-27 23:08:40 +00001377 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001378
1379 SBBreakpoint sb_bp;
1380 TargetSP target_sp(GetSP());
1381 if (target_sp && num_names > 0)
1382 {
1383 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +00001384 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001385 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001386 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +00001387 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1388 comp_unit_list.get(),
1389 symbol_names,
1390 num_names,
1391 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +00001392 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +00001393 internal,
1394 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001395 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001396
Jim Inghamfab10e82012-03-06 00:37:27 +00001397 if (log)
1398 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001399 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
1400 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001401 for (uint32_t i = 0 ; i < num_names; i++)
1402 {
1403 char sep;
1404 if (i < num_names - 1)
1405 sep = ',';
1406 else
1407 sep = '}';
1408 if (symbol_names[i] != NULL)
1409 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1410 else
1411 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001412 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001413 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1414 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001415 }
1416
1417 return sb_bp;
1418}
Jim Ingham87df91b2011-09-23 00:54:11 +00001419
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001420SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001421SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1422 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423{
Greg Clayton5160ce52013-03-27 23:08:40 +00001424 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001425
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001427 TargetSP target_sp(GetSP());
1428 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001430 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001432 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001433 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001434 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001435
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436 if (module_name && module_name[0])
1437 {
Jim Ingham969795f2011-09-21 01:17:13 +00001438 FileSpecList module_spec_list;
1439 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001440
Greg Claytoneb023e72013-10-11 19:48:25 +00001441 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 }
1443 else
1444 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001445 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446 }
1447 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001448
1449 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001450 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1451 static_cast<void*>(target_sp.get()), symbol_name_regex,
1452 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001453
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 return sb_bp;
1455}
1456
Jim Ingham87df91b2011-09-23 00:54:11 +00001457lldb::SBBreakpoint
1458SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001459 const SBFileSpecList &module_list,
1460 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001461{
Greg Clayton5160ce52013-03-27 23:08:40 +00001462 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463
Jim Ingham87df91b2011-09-23 00:54:11 +00001464 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001465 TargetSP target_sp(GetSP());
1466 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001467 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001468 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001469 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001470 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001471 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001472 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001473
Greg Claytoneb023e72013-10-11 19:48:25 +00001474 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001475 }
1476
1477 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001478 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1479 static_cast<void*>(target_sp.get()), symbol_name_regex,
1480 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001481
1482 return sb_bp;
1483}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484
1485SBBreakpoint
1486SBTarget::BreakpointCreateByAddress (addr_t address)
1487{
Greg Clayton5160ce52013-03-27 23:08:40 +00001488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001489
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001491 TargetSP target_sp(GetSP());
1492 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001493 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001494 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001495 const bool hardware = false;
1496 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001497 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001498
Caroline Ticeceb6b132010-10-26 03:11:13 +00001499 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001500 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1501 static_cast<void*>(target_sp.get()),
1502 static_cast<uint64_t>(address),
1503 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001504
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001505 return sb_bp;
1506}
1507
Jim Ingham969795f2011-09-21 01:17:13 +00001508lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001509SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1510 const lldb::SBFileSpec &source_file,
1511 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001512{
Greg Clayton5160ce52013-03-27 23:08:40 +00001513 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001514
1515 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001516 TargetSP target_sp(GetSP());
1517 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001518 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001519 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001520 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001521 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001522 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001523 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001524
Jim Ingham969795f2011-09-21 01:17:13 +00001525 if (module_name && module_name[0])
1526 {
1527 FileSpecList module_spec_list;
1528 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001529
Greg Claytoneb023e72013-10-11 19:48:25 +00001530 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001531 }
1532 else
1533 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001534 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001535 }
1536 }
1537
1538 if (log)
1539 {
1540 char path[PATH_MAX];
1541 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001542 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1543 static_cast<void*>(target_sp.get()), source_regex, path,
1544 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001545 }
1546
1547 return sb_bp;
1548}
1549
Jim Ingham87df91b2011-09-23 00:54:11 +00001550lldb::SBBreakpoint
1551SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001552 const SBFileSpecList &module_list,
1553 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001554{
Greg Clayton5160ce52013-03-27 23:08:40 +00001555 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001556
1557 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001558 TargetSP target_sp(GetSP());
1559 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001560 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001561 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001562 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001563 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001564 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001565 }
1566
1567 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001568 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1569 static_cast<void*>(target_sp.get()), source_regex,
1570 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001571
1572 return sb_bp;
1573}
Jim Ingham969795f2011-09-21 01:17:13 +00001574
Jim Inghamfab10e82012-03-06 00:37:27 +00001575lldb::SBBreakpoint
1576SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001577 bool catch_bp,
1578 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001579{
Greg Clayton5160ce52013-03-27 23:08:40 +00001580 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001581
1582 SBBreakpoint sb_bp;
1583 TargetSP target_sp(GetSP());
1584 if (target_sp)
1585 {
1586 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001587 const bool hardware = false;
1588 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001589 }
1590
1591 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001592 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1593 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001594 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001595 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1596 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001597
1598 return sb_bp;
1599}
1600
Greg Clayton9fed0d82010-07-23 23:33:17 +00001601uint32_t
1602SBTarget::GetNumBreakpoints () const
1603{
Greg Claytonacdbe812012-01-30 09:04:36 +00001604 TargetSP target_sp(GetSP());
1605 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001606 {
1607 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001608 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001609 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001610 return 0;
1611}
1612
1613SBBreakpoint
1614SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1615{
1616 SBBreakpoint sb_breakpoint;
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 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001622 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001623 return sb_breakpoint;
1624}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001625
1626bool
1627SBTarget::BreakpointDelete (break_id_t bp_id)
1628{
Greg Clayton5160ce52013-03-27 23:08:40 +00001629 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001630
Caroline Ticeceb6b132010-10-26 03:11:13 +00001631 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001632 TargetSP target_sp(GetSP());
1633 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001634 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001635 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1636 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001637 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001638
1639 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001640 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1641 static_cast<void*>(target_sp.get()),
1642 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001643
1644 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001645}
1646
Johnny Chen5d043462011-09-26 22:40:50 +00001647SBBreakpoint
1648SBTarget::FindBreakpointByID (break_id_t bp_id)
1649{
Greg Clayton5160ce52013-03-27 23:08:40 +00001650 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001651
1652 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001653 TargetSP target_sp(GetSP());
1654 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001655 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001656 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1657 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001658 }
1659
1660 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001661 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1662 static_cast<void*>(target_sp.get()),
1663 static_cast<uint32_t>(bp_id),
1664 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001665
1666 return sb_breakpoint;
1667}
1668
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001669bool
1670SBTarget::EnableAllBreakpoints ()
1671{
Greg Claytonacdbe812012-01-30 09:04:36 +00001672 TargetSP target_sp(GetSP());
1673 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001674 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001675 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1676 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677 return true;
1678 }
1679 return false;
1680}
1681
1682bool
1683SBTarget::DisableAllBreakpoints ()
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->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001690 return true;
1691 }
1692 return false;
1693}
1694
1695bool
1696SBTarget::DeleteAllBreakpoints ()
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->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001703 return true;
1704 }
1705 return false;
1706}
1707
Johnny Chen5d043462011-09-26 22:40:50 +00001708uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001709SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001710{
Greg Claytonacdbe812012-01-30 09:04:36 +00001711 TargetSP target_sp(GetSP());
1712 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001713 {
Johnny Chen01a67862011-10-14 00:42:25 +00001714 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001715 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001716 }
1717 return 0;
1718}
1719
Greg Clayton1b282f92011-10-13 18:08:26 +00001720SBWatchpoint
1721SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001722{
Johnny Chen01a67862011-10-14 00:42:25 +00001723 SBWatchpoint sb_watchpoint;
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 Clayton81e871e2012-02-04 02:27:34 +00001728 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001729 }
Johnny Chen01a67862011-10-14 00:42:25 +00001730 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001731}
1732
1733bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001734SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001735{
Greg Clayton5160ce52013-03-27 23:08:40 +00001736 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001737
1738 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001739 TargetSP target_sp(GetSP());
1740 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001741 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001742 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001743 Mutex::Locker locker;
1744 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001745 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001746 }
1747
1748 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001749 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1750 static_cast<void*>(target_sp.get()),
1751 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001752
1753 return result;
1754}
1755
Greg Clayton1b282f92011-10-13 18:08:26 +00001756SBWatchpoint
1757SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001758{
Greg Clayton5160ce52013-03-27 23:08:40 +00001759 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001760
Greg Clayton1b282f92011-10-13 18:08:26 +00001761 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001762 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001763 TargetSP target_sp(GetSP());
1764 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001765 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001766 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001767 Mutex::Locker locker;
1768 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001769 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1770 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001771 }
1772
1773 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001774 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1775 static_cast<void*>(target_sp.get()),
1776 static_cast<uint32_t>(wp_id),
1777 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001778
Greg Clayton1b282f92011-10-13 18:08:26 +00001779 return sb_watchpoint;
1780}
1781
1782lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001783SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001784{
Greg Clayton5160ce52013-03-27 23:08:40 +00001785 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001786
Greg Clayton1b282f92011-10-13 18:08:26 +00001787 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001788 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001789 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001790 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001791 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001792 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001793 uint32_t watch_type = 0;
1794 if (read)
1795 watch_type |= LLDB_WATCH_TYPE_READ;
1796 if (write)
1797 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001798 if (watch_type == 0)
1799 {
1800 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1801 return sb_watchpoint;
1802 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001803
Johnny Chen7385a5a2012-05-31 22:56:36 +00001804 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001805 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001806 // This API doesn't take in a type, so we can't figure out what it is.
1807 ClangASTType *type = NULL;
1808 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001809 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001810 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001811 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001812
Greg Clayton1b282f92011-10-13 18:08:26 +00001813 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001814 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001815 static_cast<void*>(target_sp.get()), addr,
1816 static_cast<uint32_t>(size),
1817 static_cast<void*>(watchpoint_sp.get()));
1818
Greg Clayton1b282f92011-10-13 18:08:26 +00001819 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001820}
1821
1822bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001823SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001824{
Greg Claytonacdbe812012-01-30 09:04:36 +00001825 TargetSP target_sp(GetSP());
1826 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001827 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001828 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001829 Mutex::Locker locker;
1830 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001831 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001832 return true;
1833 }
1834 return false;
1835}
1836
1837bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001838SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001839{
Greg Claytonacdbe812012-01-30 09:04:36 +00001840 TargetSP target_sp(GetSP());
1841 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001842 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001843 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001844 Mutex::Locker locker;
1845 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001846 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001847 return true;
1848 }
1849 return false;
1850}
1851
Enrico Granata347c2aa2013-10-08 21:49:02 +00001852SBValue
1853SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1854{
1855 SBValue sb_value;
1856 lldb::ValueObjectSP new_value_sp;
1857 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1858 {
1859 lldb::addr_t address(addr.GetLoadAddress(*this));
1860 lldb::TypeImplSP type_impl_sp (type.GetSP());
Enrico Granatadc4db5a2013-10-29 00:28:35 +00001861 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001862 if (pointer_ast_type)
1863 {
1864 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001865
Enrico Granata347c2aa2013-10-08 21:49:02 +00001866 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1867 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1868 pointer_ast_type,
1869 ConstString(name),
1870 buffer,
1871 exe_ctx.GetByteOrder(),
1872 exe_ctx.GetAddressByteSize()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001873
Enrico Granata347c2aa2013-10-08 21:49:02 +00001874 if (ptr_result_valobj_sp)
1875 {
1876 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1877 Error err;
1878 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1879 if (new_value_sp)
1880 new_value_sp->SetName(ConstString(name));
1881 }
1882 }
1883 }
1884 sb_value.SetSP(new_value_sp);
1885 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1886 if (log)
1887 {
1888 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001889 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1890 static_cast<void*>(m_opaque_sp.get()),
1891 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001892 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001893 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1894 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001895 }
1896 return sb_value;
1897}
1898
Johnny Chen5d043462011-09-26 22:40:50 +00001899bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001900SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001901{
Greg Claytonacdbe812012-01-30 09:04:36 +00001902 TargetSP target_sp(GetSP());
1903 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001904 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001905 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001906 Mutex::Locker locker;
1907 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001908 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001909 return true;
1910 }
1911 return false;
1912}
1913
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001914
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001915lldb::SBModule
1916SBTarget::AddModule (const char *path,
1917 const char *triple,
1918 const char *uuid_cstr)
1919{
Greg Claytonb210aec2012-04-23 20:23:39 +00001920 return AddModule (path, triple, uuid_cstr, NULL);
1921}
1922
1923lldb::SBModule
1924SBTarget::AddModule (const char *path,
1925 const char *triple,
1926 const char *uuid_cstr,
1927 const char *symfile)
1928{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001929 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001930 TargetSP target_sp(GetSP());
1931 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001932 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001933 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001934 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001935 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001936
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001937 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001938 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001939
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001940 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001941 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001942 else
1943 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001944
1945 if (symfile)
1946 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001947
Greg Claytonb9a01b32012-02-26 05:51:37 +00001948 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001949 }
1950 return sb_module;
1951}
1952
Greg Clayton226cce22013-07-08 22:22:41 +00001953lldb::SBModule
1954SBTarget::AddModule (const SBModuleSpec &module_spec)
1955{
1956 lldb::SBModule sb_module;
1957 TargetSP target_sp(GetSP());
1958 if (target_sp)
1959 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1960 return sb_module;
1961}
1962
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001963bool
1964SBTarget::AddModule (lldb::SBModule &module)
1965{
Greg Claytonacdbe812012-01-30 09:04:36 +00001966 TargetSP target_sp(GetSP());
1967 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001968 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001969 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001970 return true;
1971 }
1972 return false;
1973}
1974
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975uint32_t
1976SBTarget::GetNumModules () const
1977{
Greg Clayton5160ce52013-03-27 23:08:40 +00001978 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001979
Caroline Ticeceb6b132010-10-26 03:11:13 +00001980 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001981 TargetSP target_sp(GetSP());
1982 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001983 {
1984 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001985 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001986 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001987
1988 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001989 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1990 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001991
1992 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993}
1994
Greg Clayton48e42542010-07-30 20:12:55 +00001995void
1996SBTarget::Clear ()
1997{
Greg Clayton5160ce52013-03-27 23:08:40 +00001998 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001999
2000 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002001 log->Printf ("SBTarget(%p)::Clear ()",
2002 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002003
Greg Clayton48e42542010-07-30 20:12:55 +00002004 m_opaque_sp.reset();
2005}
2006
2007
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002008SBModule
2009SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2010{
2011 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002012 TargetSP target_sp(GetSP());
2013 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00002014 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00002015 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002016 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00002017 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00002018 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019 return sb_module;
2020}
2021
Greg Clayton13d19502012-01-29 06:07:39 +00002022lldb::ByteOrder
2023SBTarget::GetByteOrder ()
2024{
Greg Claytonacdbe812012-01-30 09:04:36 +00002025 TargetSP target_sp(GetSP());
2026 if (target_sp)
2027 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00002028 return eByteOrderInvalid;
2029}
2030
2031const char *
2032SBTarget::GetTriple ()
2033{
Greg Claytonacdbe812012-01-30 09:04:36 +00002034 TargetSP target_sp(GetSP());
2035 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00002036 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002037 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00002038 // Unique the string so we don't run into ownership issues since
2039 // the const strings put the string into the string pool once and
2040 // the strings never comes out
2041 ConstString const_triple (triple.c_str());
2042 return const_triple.GetCString();
2043 }
2044 return NULL;
2045}
2046
2047uint32_t
2048SBTarget::GetAddressByteSize()
2049{
Greg Claytonacdbe812012-01-30 09:04:36 +00002050 TargetSP target_sp(GetSP());
2051 if (target_sp)
2052 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00002053 return sizeof(void*);
2054}
2055
2056
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002057SBModule
2058SBTarget::GetModuleAtIndex (uint32_t idx)
2059{
Greg Clayton5160ce52013-03-27 23:08:40 +00002060 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002061
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002062 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00002063 ModuleSP module_sp;
2064 TargetSP target_sp(GetSP());
2065 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00002066 {
2067 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00002068 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2069 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00002070 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00002071
2072 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002073 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2074 static_cast<void*>(target_sp.get()), idx,
2075 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002076
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002077 return sb_module;
2078}
2079
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002080bool
2081SBTarget::RemoveModule (lldb::SBModule module)
2082{
Greg Claytonacdbe812012-01-30 09:04:36 +00002083 TargetSP target_sp(GetSP());
2084 if (target_sp)
2085 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002086 return false;
2087}
2088
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089
2090SBBroadcaster
2091SBTarget::GetBroadcaster () const
2092{
Greg Clayton5160ce52013-03-27 23:08:40 +00002093 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002094
Greg Claytonacdbe812012-01-30 09:04:36 +00002095 TargetSP target_sp(GetSP());
2096 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002097
Caroline Ticeceb6b132010-10-26 03:11:13 +00002098 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002099 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2100 static_cast<void*>(target_sp.get()),
2101 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00002102
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002103 return broadcaster;
2104}
2105
Caroline Ticedde9cff2010-09-20 05:20:02 +00002106bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00002107SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00002108{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002109 Stream &strm = description.ref();
2110
Greg Claytonacdbe812012-01-30 09:04:36 +00002111 TargetSP target_sp(GetSP());
2112 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00002113 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002114 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00002115 }
2116 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00002117 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00002118
2119 return true;
2120}
2121
Greg Clayton5569e642012-02-06 01:44:54 +00002122lldb::SBSymbolContextList
2123SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00002124{
Greg Clayton5569e642012-02-06 01:44:54 +00002125 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00002126 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00002127 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002128 TargetSP target_sp(GetSP());
2129 if (target_sp)
2130 {
2131 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00002132 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00002133 const bool append = true;
2134 target_sp->GetImages().FindFunctions (ConstString(name),
2135 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00002136 symbols_ok,
2137 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00002138 append,
2139 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00002140 }
Greg Claytonfe356d32011-06-21 01:34:41 +00002141 }
Greg Clayton5569e642012-02-06 01:44:54 +00002142 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00002143}
2144
Enrico Granata6f3533f2011-07-29 19:53:35 +00002145lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00002146SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002147{
Greg Claytonacdbe812012-01-30 09:04:36 +00002148 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002149 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002150 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002151 ConstString const_typename(typename_cstr);
2152 SymbolContext sc;
2153 const bool exact_match = false;
2154
2155 const ModuleList &module_list = target_sp->GetImages();
2156 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002157 for (size_t idx = 0; idx < count; idx++)
2158 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002159 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2160 if (module_sp)
2161 {
2162 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2163 if (type_sp)
2164 return SBType(type_sp);
2165 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00002166 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002167
2168 // Didn't find the type in the symbols; try the Objective-C runtime
2169 // if one is installed
2170
2171 ProcessSP process_sp(target_sp->GetProcessSP());
2172
2173 if (process_sp)
2174 {
2175 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2176
2177 if (objc_language_runtime)
2178 {
2179 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2180
2181 if (objc_type_vendor)
2182 {
2183 std::vector <ClangASTType> types;
2184
2185 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2186 return SBType(types[0]);
2187 }
2188 }
2189 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002190
2191 // No matches, search for basic typename matches
2192 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2193 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002194 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002195 }
2196 return SBType();
2197}
2198
Greg Claytonb43165b2012-12-05 21:24:42 +00002199SBType
2200SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002201{
Greg Claytonacdbe812012-01-30 09:04:36 +00002202 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00002203 if (target_sp)
2204 {
2205 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2206 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002207 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00002208 }
2209 return SBType();
2210}
2211
2212
2213lldb::SBTypeList
2214SBTarget::FindTypes (const char* typename_cstr)
2215{
2216 SBTypeList sb_type_list;
2217 TargetSP target_sp(GetSP());
2218 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002219 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002220 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00002221 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00002222 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002223 SymbolContext sc;
2224 TypeList type_list;
2225
Greg Clayton29399a22012-04-06 17:41:13 +00002226 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00002227 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00002228 exact_match,
2229 UINT32_MAX,
2230 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002231
Greg Claytonb43165b2012-12-05 21:24:42 +00002232 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002233 {
Greg Claytonb43165b2012-12-05 21:24:42 +00002234 for (size_t idx = 0; idx < num_matches; idx++)
2235 {
2236 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2237 if (type_sp)
2238 sb_type_list.Append(SBType(type_sp));
2239 }
2240 }
Sean Callanan7be70e82012-12-19 23:05:01 +00002241
2242 // Try the Objective-C runtime if one is installed
2243
2244 ProcessSP process_sp(target_sp->GetProcessSP());
2245
2246 if (process_sp)
2247 {
2248 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2249
2250 if (objc_language_runtime)
2251 {
2252 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2253
2254 if (objc_type_vendor)
2255 {
2256 std::vector <ClangASTType> types;
2257
2258 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2259 {
2260 for (ClangASTType &type : types)
2261 {
2262 sb_type_list.Append(SBType(type));
2263 }
2264 }
2265 }
2266 }
2267 }
2268
2269 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00002270 {
2271 // No matches, search for basic typename matches
2272 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2273 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00002274 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00002275 }
2276 }
Greg Claytonb43165b2012-12-05 21:24:42 +00002277 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00002278}
2279
Greg Claytondea8cb42011-06-29 22:09:02 +00002280SBValueList
2281SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2282{
2283 SBValueList sb_value_list;
2284
Greg Claytonacdbe812012-01-30 09:04:36 +00002285 TargetSP target_sp(GetSP());
2286 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00002287 {
2288 VariableList variable_list;
2289 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00002290 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2291 append,
2292 max_matches,
2293 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002294
2295 if (match_count > 0)
2296 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002297 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002298 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002299 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002300 for (uint32_t i=0; i<match_count; ++i)
2301 {
2302 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2303 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002304 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002305 }
2306 }
2307 }
2308
2309 return sb_value_list;
2310}
2311
Enrico Granatabcd80b42013-01-16 18:53:52 +00002312lldb::SBValue
2313SBTarget::FindFirstGlobalVariable (const char* name)
2314{
2315 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2316 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2317 return sb_value_list.GetValueAtIndex(0);
2318 return SBValue();
2319}
2320
Jim Inghame37d6052011-09-13 00:29:56 +00002321SBSourceManager
2322SBTarget::GetSourceManager()
2323{
2324 SBSourceManager source_manager (*this);
2325 return source_manager;
2326}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002327
Sean Callanan50952e92011-12-14 23:49:37 +00002328lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002329SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2330{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002331 return ReadInstructions (base_addr, count, NULL);
2332}
2333
2334lldb::SBInstructionList
2335SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2336{
Greg Clayton9c766112012-03-06 22:24:44 +00002337 SBInstructionList sb_instructions;
2338
2339 TargetSP target_sp(GetSP());
2340 if (target_sp)
2341 {
2342 Address *addr_ptr = base_addr.get();
2343
2344 if (addr_ptr)
2345 {
2346 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2347 bool prefer_file_cache = false;
2348 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002349 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2350 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2351 prefer_file_cache,
2352 data.GetBytes(),
2353 data.GetByteSize(),
2354 error,
2355 &load_addr);
2356 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002357 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2358 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002359 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002360 *addr_ptr,
2361 data.GetBytes(),
2362 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002363 count,
2364 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002365 }
2366 }
2367
2368 return sb_instructions;
2369
2370}
2371
2372lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002373SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2374{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002375 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2376}
2377
2378lldb::SBInstructionList
2379SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2380{
Sean Callanan50952e92011-12-14 23:49:37 +00002381 SBInstructionList sb_instructions;
2382
Greg Claytonacdbe812012-01-30 09:04:36 +00002383 TargetSP target_sp(GetSP());
2384 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002385 {
2386 Address addr;
2387
2388 if (base_addr.get())
2389 addr = *base_addr.get();
2390
Greg Clayton3faf47c2013-03-28 23:42:53 +00002391 const bool data_from_file = true;
2392
Greg Claytonacdbe812012-01-30 09:04:36 +00002393 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002394 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002395 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002396 addr,
2397 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002398 size,
2399 UINT32_MAX,
2400 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002401 }
2402
2403 return sb_instructions;
2404}
2405
2406lldb::SBInstructionList
2407SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2408{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002409 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2410}
2411
2412lldb::SBInstructionList
2413SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2414{
2415 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002416}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002417
2418SBError
2419SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2420 lldb::addr_t section_base_addr)
2421{
2422 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002423 TargetSP target_sp(GetSP());
2424 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002425 {
2426 if (!section.IsValid())
2427 {
2428 sb_error.SetErrorStringWithFormat ("invalid section");
2429 }
2430 else
2431 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002432 SectionSP section_sp (section.GetSP());
2433 if (section_sp)
2434 {
2435 if (section_sp->IsThreadSpecific())
2436 {
2437 sb_error.SetErrorString ("thread specific sections are not yet supported");
2438 }
2439 else
2440 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002441 ProcessSP process_sp (target_sp->GetProcessSP());
2442 uint32_t stop_id = 0;
2443 if (process_sp)
2444 stop_id = process_sp->GetStopID();
2445
2446 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002447 {
2448 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002449 if (process_sp)
2450 process_sp->Flush();
2451 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002452 }
2453 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002454 }
2455 }
2456 else
2457 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002458 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002459 }
2460 return sb_error;
2461}
2462
2463SBError
2464SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2465{
2466 SBError sb_error;
2467
Greg Claytonacdbe812012-01-30 09:04:36 +00002468 TargetSP target_sp(GetSP());
2469 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002470 {
2471 if (!section.IsValid())
2472 {
2473 sb_error.SetErrorStringWithFormat ("invalid section");
2474 }
2475 else
2476 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002477 ProcessSP process_sp (target_sp->GetProcessSP());
2478 uint32_t stop_id = 0;
2479 if (process_sp)
2480 stop_id = process_sp->GetStopID();
2481
2482 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002483 {
2484 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002485 if (process_sp)
2486 process_sp->Flush();
2487 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002488 }
2489 }
2490 else
2491 {
2492 sb_error.SetErrorStringWithFormat ("invalid target");
2493 }
2494 return sb_error;
2495}
2496
2497SBError
2498SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2499{
2500 SBError sb_error;
2501
Greg Claytonacdbe812012-01-30 09:04:36 +00002502 TargetSP target_sp(GetSP());
2503 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002504 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002505 ModuleSP module_sp (module.GetSP());
2506 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002507 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002508 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002509 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002510 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002511 // The load was successful, make sure that at least some sections
2512 // changed before we notify that our module was loaded.
2513 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002514 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002515 ModuleList module_list;
2516 module_list.Append(module_sp);
2517 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002518 // Flush info in the process (stack frames, etc)
2519 ProcessSP process_sp (target_sp->GetProcessSP());
2520 if (process_sp)
2521 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002522 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002523 }
2524 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002525 else
2526 {
2527 sb_error.SetErrorStringWithFormat ("invalid module");
2528 }
2529
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002530 }
2531 else
2532 {
2533 sb_error.SetErrorStringWithFormat ("invalid target");
2534 }
2535 return sb_error;
2536}
2537
2538SBError
2539SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2540{
2541 SBError sb_error;
2542
2543 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002544 TargetSP target_sp(GetSP());
2545 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002546 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002547 ModuleSP module_sp (module.GetSP());
2548 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002549 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002550 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002551 if (objfile)
2552 {
2553 SectionList *section_list = objfile->GetSectionList();
2554 if (section_list)
2555 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002556 ProcessSP process_sp (target_sp->GetProcessSP());
2557 uint32_t stop_id = 0;
2558 if (process_sp)
2559 stop_id = process_sp->GetStopID();
2560
Greg Clayton3c947372013-01-29 01:17:09 +00002561 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002562 const size_t num_sections = section_list->GetSize();
2563 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2564 {
2565 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2566 if (section_sp)
Greg Claytond5944cd2013-12-06 01:12:00 +00002567 changed |= target_sp->SetSectionUnloaded (section_sp) > 0;
Greg Clayton3c947372013-01-29 01:17:09 +00002568 }
2569 if (changed)
2570 {
2571 // Flush info in the process (stack frames, etc)
2572 ProcessSP process_sp (target_sp->GetProcessSP());
2573 if (process_sp)
2574 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002575 }
2576 }
2577 else
2578 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002579 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002580 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2581 }
2582 }
2583 else
2584 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002585 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002586 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2587 }
2588 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002589 else
2590 {
2591 sb_error.SetErrorStringWithFormat ("invalid module");
2592 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002593 }
2594 else
2595 {
2596 sb_error.SetErrorStringWithFormat ("invalid target");
2597 }
2598 return sb_error;
2599}
2600
2601
Greg Claytone14e1922012-12-04 02:22:16 +00002602lldb::SBSymbolContextList
2603SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2604{
2605 SBSymbolContextList sb_sc_list;
2606 if (name && name[0])
2607 {
2608 TargetSP target_sp(GetSP());
2609 if (target_sp)
2610 {
2611 bool append = true;
2612 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2613 symbol_type,
2614 *sb_sc_list,
2615 append);
2616 }
2617 }
2618 return sb_sc_list;
2619
2620}
2621
2622
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002623lldb::SBValue
2624SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2625{
Greg Clayton5160ce52013-03-27 23:08:40 +00002626 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2627 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002628 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002629 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002630 ValueObjectSP expr_value_sp;
2631 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002632 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002633 if (target_sp)
2634 {
2635 if (expr == NULL || expr[0] == '\0')
2636 {
2637 if (log)
2638 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2639 return expr_result;
2640 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002641
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002642 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2643 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002644
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002645 if (log)
2646 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002647
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002648 frame = exe_ctx.GetFramePtr();
2649 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002650
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002651 if (target)
2652 {
2653#ifdef LLDB_CONFIGURATION_DEBUG
2654 StreamString frame_description;
2655 if (frame)
2656 frame->DumpUsingSettingsFormat (&frame_description);
2657 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2658 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2659#endif
2660 exe_results = target->EvaluateExpression (expr,
2661 frame,
2662 expr_value_sp,
2663 options.ref());
2664
2665 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2666#ifdef LLDB_CONFIGURATION_DEBUG
2667 Host::SetCrashDescription (NULL);
2668#endif
2669 }
2670 else
2671 {
2672 if (log)
2673 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2674 }
2675 }
2676#ifndef LLDB_DISABLE_PYTHON
2677 if (expr_log)
2678 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002679 expr_result.GetValue(), expr_result.GetSummary());
2680
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002681 if (log)
2682 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002683 static_cast<void*>(frame), expr,
2684 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002685#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002686
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002687 return expr_result;
2688}
2689
Greg Clayton13fbb992013-02-01 00:47:49 +00002690
2691lldb::addr_t
2692SBTarget::GetStackRedZoneSize()
2693{
2694 TargetSP target_sp(GetSP());
2695 if (target_sp)
2696 {
2697 ABISP abi_sp;
2698 ProcessSP process_sp (target_sp->GetProcessSP());
2699 if (process_sp)
2700 abi_sp = process_sp->GetABI();
2701 else
2702 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2703 if (abi_sp)
2704 return abi_sp->GetRedZoneSize();
2705 }
2706 return 0;
2707}
2708