1254721Semaste//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/lldb-python.h"
11254721Semaste
12254721Semaste#include "lldb/API/SBTarget.h"
13254721Semaste
14254721Semaste#include "lldb/lldb-public.h"
15254721Semaste
16254721Semaste#include "lldb/API/SBDebugger.h"
17254721Semaste#include "lldb/API/SBBreakpoint.h"
18254721Semaste#include "lldb/API/SBExpressionOptions.h"
19254721Semaste#include "lldb/API/SBFileSpec.h"
20254721Semaste#include "lldb/API/SBListener.h"
21254721Semaste#include "lldb/API/SBModule.h"
22254721Semaste#include "lldb/API/SBModuleSpec.h"
23254721Semaste#include "lldb/API/SBSourceManager.h"
24254721Semaste#include "lldb/API/SBProcess.h"
25254721Semaste#include "lldb/API/SBStream.h"
26254721Semaste#include "lldb/API/SBSymbolContextList.h"
27254721Semaste#include "lldb/Breakpoint/BreakpointID.h"
28254721Semaste#include "lldb/Breakpoint/BreakpointIDList.h"
29254721Semaste#include "lldb/Breakpoint/BreakpointList.h"
30254721Semaste#include "lldb/Breakpoint/BreakpointLocation.h"
31254721Semaste#include "lldb/Core/Address.h"
32254721Semaste#include "lldb/Core/AddressResolver.h"
33254721Semaste#include "lldb/Core/AddressResolverName.h"
34254721Semaste#include "lldb/Core/ArchSpec.h"
35254721Semaste#include "lldb/Core/Debugger.h"
36254721Semaste#include "lldb/Core/Disassembler.h"
37254721Semaste#include "lldb/Core/Log.h"
38254721Semaste#include "lldb/Core/Module.h"
39254721Semaste#include "lldb/Core/ModuleSpec.h"
40254721Semaste#include "lldb/Core/RegularExpression.h"
41254721Semaste#include "lldb/Core/SearchFilter.h"
42254721Semaste#include "lldb/Core/Section.h"
43254721Semaste#include "lldb/Core/STLUtils.h"
44263363Semaste#include "lldb/Core/ValueObjectConstResult.h"
45254721Semaste#include "lldb/Core/ValueObjectList.h"
46254721Semaste#include "lldb/Core/ValueObjectVariable.h"
47254721Semaste#include "lldb/Host/FileSpec.h"
48254721Semaste#include "lldb/Host/Host.h"
49254721Semaste#include "lldb/Interpreter/Args.h"
50254721Semaste#include "lldb/Symbol/ObjectFile.h"
51254721Semaste#include "lldb/Symbol/SymbolVendor.h"
52254721Semaste#include "lldb/Symbol/VariableList.h"
53254721Semaste#include "lldb/Target/LanguageRuntime.h"
54254721Semaste#include "lldb/Target/Process.h"
55269024Semaste
56254721Semaste#include "lldb/Target/Target.h"
57254721Semaste#include "lldb/Target/TargetList.h"
58254721Semaste
59254721Semaste#include "lldb/Interpreter/CommandReturnObject.h"
60254721Semaste#include "../source/Commands/CommandObjectBreakpoint.h"
61254721Semaste
62254721Semaste
63254721Semasteusing namespace lldb;
64254721Semasteusing namespace lldb_private;
65254721Semaste
66254721Semaste#define DEFAULT_DISASM_BYTE_SIZE 32
67254721Semaste
68254721SemasteSBLaunchInfo::SBLaunchInfo (const char **argv) :
69254721Semaste    m_opaque_sp(new ProcessLaunchInfo())
70254721Semaste{
71254721Semaste    m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
72254721Semaste    if (argv && argv[0])
73254721Semaste        m_opaque_sp->GetArguments().SetArguments(argv);
74254721Semaste}
75254721Semaste
76254721SemasteSBLaunchInfo::~SBLaunchInfo()
77254721Semaste{
78254721Semaste}
79254721Semaste
80254721Semastelldb_private::ProcessLaunchInfo &
81254721SemasteSBLaunchInfo::ref ()
82254721Semaste{
83254721Semaste    return *m_opaque_sp;
84254721Semaste}
85254721Semaste
86254721Semaste
87254721Semasteuint32_t
88254721SemasteSBLaunchInfo::GetUserID()
89254721Semaste{
90254721Semaste    return m_opaque_sp->GetUserID();
91254721Semaste}
92254721Semaste
93254721Semasteuint32_t
94254721SemasteSBLaunchInfo::GetGroupID()
95254721Semaste{
96254721Semaste    return m_opaque_sp->GetGroupID();
97254721Semaste}
98254721Semaste
99254721Semastebool
100254721SemasteSBLaunchInfo::UserIDIsValid ()
101254721Semaste{
102254721Semaste    return m_opaque_sp->UserIDIsValid();
103254721Semaste}
104254721Semaste
105254721Semastebool
106254721SemasteSBLaunchInfo::GroupIDIsValid ()
107254721Semaste{
108254721Semaste    return m_opaque_sp->GroupIDIsValid();
109254721Semaste}
110254721Semaste
111254721Semastevoid
112254721SemasteSBLaunchInfo::SetUserID (uint32_t uid)
113254721Semaste{
114254721Semaste    m_opaque_sp->SetUserID (uid);
115254721Semaste}
116254721Semaste
117254721Semastevoid
118254721SemasteSBLaunchInfo::SetGroupID (uint32_t gid)
119254721Semaste{
120254721Semaste    m_opaque_sp->SetGroupID (gid);
121254721Semaste}
122254721Semaste
123254721Semasteuint32_t
124254721SemasteSBLaunchInfo::GetNumArguments ()
125254721Semaste{
126254721Semaste    return m_opaque_sp->GetArguments().GetArgumentCount();
127254721Semaste}
128254721Semaste
129254721Semasteconst char *
130254721SemasteSBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
131254721Semaste{
132254721Semaste    return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
133254721Semaste}
134254721Semaste
135254721Semastevoid
136254721SemasteSBLaunchInfo::SetArguments (const char **argv, bool append)
137254721Semaste{
138254721Semaste    if (append)
139254721Semaste    {
140254721Semaste        if (argv)
141254721Semaste            m_opaque_sp->GetArguments().AppendArguments(argv);
142254721Semaste    }
143254721Semaste    else
144254721Semaste    {
145254721Semaste        if (argv)
146254721Semaste            m_opaque_sp->GetArguments().SetArguments(argv);
147254721Semaste        else
148254721Semaste            m_opaque_sp->GetArguments().Clear();
149254721Semaste    }
150254721Semaste}
151254721Semaste
152254721Semasteuint32_t
153254721SemasteSBLaunchInfo::GetNumEnvironmentEntries ()
154254721Semaste{
155254721Semaste    return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
156254721Semaste}
157254721Semaste
158254721Semasteconst char *
159254721SemasteSBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
160254721Semaste{
161254721Semaste    return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
162254721Semaste}
163254721Semaste
164254721Semastevoid
165254721SemasteSBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
166254721Semaste{
167254721Semaste    if (append)
168254721Semaste    {
169254721Semaste        if (envp)
170254721Semaste            m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
171254721Semaste    }
172254721Semaste    else
173254721Semaste    {
174254721Semaste        if (envp)
175254721Semaste            m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
176254721Semaste        else
177254721Semaste            m_opaque_sp->GetEnvironmentEntries().Clear();
178254721Semaste    }
179254721Semaste}
180254721Semaste
181254721Semastevoid
182254721SemasteSBLaunchInfo::Clear ()
183254721Semaste{
184254721Semaste    m_opaque_sp->Clear();
185254721Semaste}
186254721Semaste
187254721Semasteconst char *
188254721SemasteSBLaunchInfo::GetWorkingDirectory () const
189254721Semaste{
190254721Semaste    return m_opaque_sp->GetWorkingDirectory();
191254721Semaste}
192254721Semaste
193254721Semastevoid
194254721SemasteSBLaunchInfo::SetWorkingDirectory (const char *working_dir)
195254721Semaste{
196254721Semaste    m_opaque_sp->SetWorkingDirectory(working_dir);
197254721Semaste}
198254721Semaste
199254721Semasteuint32_t
200254721SemasteSBLaunchInfo::GetLaunchFlags ()
201254721Semaste{
202254721Semaste    return m_opaque_sp->GetFlags().Get();
203254721Semaste}
204254721Semaste
205254721Semastevoid
206254721SemasteSBLaunchInfo::SetLaunchFlags (uint32_t flags)
207254721Semaste{
208254721Semaste    m_opaque_sp->GetFlags().Reset(flags);
209254721Semaste}
210254721Semaste
211254721Semasteconst char *
212254721SemasteSBLaunchInfo::GetProcessPluginName ()
213254721Semaste{
214254721Semaste    return m_opaque_sp->GetProcessPluginName();
215254721Semaste}
216254721Semaste
217254721Semastevoid
218254721SemasteSBLaunchInfo::SetProcessPluginName (const char *plugin_name)
219254721Semaste{
220254721Semaste    return m_opaque_sp->SetProcessPluginName (plugin_name);
221254721Semaste}
222254721Semaste
223254721Semasteconst char *
224254721SemasteSBLaunchInfo::GetShell ()
225254721Semaste{
226254721Semaste    return m_opaque_sp->GetShell();
227254721Semaste}
228254721Semaste
229254721Semastevoid
230254721SemasteSBLaunchInfo::SetShell (const char * path)
231254721Semaste{
232254721Semaste    m_opaque_sp->SetShell (path);
233254721Semaste}
234254721Semaste
235254721Semasteuint32_t
236254721SemasteSBLaunchInfo::GetResumeCount ()
237254721Semaste{
238254721Semaste    return m_opaque_sp->GetResumeCount();
239254721Semaste}
240254721Semaste
241254721Semastevoid
242254721SemasteSBLaunchInfo::SetResumeCount (uint32_t c)
243254721Semaste{
244254721Semaste    m_opaque_sp->SetResumeCount (c);
245254721Semaste}
246254721Semaste
247254721Semastebool
248254721SemasteSBLaunchInfo::AddCloseFileAction (int fd)
249254721Semaste{
250254721Semaste    return m_opaque_sp->AppendCloseFileAction(fd);
251254721Semaste}
252254721Semaste
253254721Semastebool
254254721SemasteSBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
255254721Semaste{
256254721Semaste    return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
257254721Semaste}
258254721Semaste
259254721Semastebool
260254721SemasteSBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
261254721Semaste{
262254721Semaste    return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
263254721Semaste}
264254721Semaste
265254721Semastebool
266254721SemasteSBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
267254721Semaste{
268254721Semaste    return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
269254721Semaste}
270254721Semaste
271254721Semaste
272254721SemasteSBAttachInfo::SBAttachInfo () :
273254721Semaste    m_opaque_sp (new ProcessAttachInfo())
274254721Semaste{
275254721Semaste}
276254721Semaste
277254721SemasteSBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
278254721Semaste    m_opaque_sp (new ProcessAttachInfo())
279254721Semaste{
280254721Semaste    m_opaque_sp->SetProcessID (pid);
281254721Semaste}
282254721Semaste
283254721SemasteSBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
284254721Semaste    m_opaque_sp (new ProcessAttachInfo())
285254721Semaste{
286254721Semaste    if (path && path[0])
287254721Semaste        m_opaque_sp->GetExecutableFile().SetFile(path, false);
288254721Semaste    m_opaque_sp->SetWaitForLaunch (wait_for);
289254721Semaste}
290254721Semaste
291254721SemasteSBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
292254721Semaste    m_opaque_sp (new ProcessAttachInfo())
293254721Semaste{
294254721Semaste    *m_opaque_sp = *rhs.m_opaque_sp;
295254721Semaste}
296254721Semaste
297254721SemasteSBAttachInfo::~SBAttachInfo()
298254721Semaste{
299254721Semaste}
300254721Semaste
301254721Semastelldb_private::ProcessAttachInfo &
302254721SemasteSBAttachInfo::ref ()
303254721Semaste{
304254721Semaste    return *m_opaque_sp;
305254721Semaste}
306254721Semaste
307254721SemasteSBAttachInfo &
308254721SemasteSBAttachInfo::operator = (const SBAttachInfo &rhs)
309254721Semaste{
310254721Semaste    if (this != &rhs)
311254721Semaste        *m_opaque_sp = *rhs.m_opaque_sp;
312254721Semaste    return *this;
313254721Semaste}
314254721Semaste
315254721Semastelldb::pid_t
316254721SemasteSBAttachInfo::GetProcessID ()
317254721Semaste{
318254721Semaste    return m_opaque_sp->GetProcessID();
319254721Semaste}
320254721Semaste
321254721Semastevoid
322254721SemasteSBAttachInfo::SetProcessID (lldb::pid_t pid)
323254721Semaste{
324254721Semaste    m_opaque_sp->SetProcessID (pid);
325254721Semaste}
326254721Semaste
327254721Semaste
328254721Semasteuint32_t
329254721SemasteSBAttachInfo::GetResumeCount ()
330254721Semaste{
331254721Semaste    return m_opaque_sp->GetResumeCount();
332254721Semaste}
333254721Semaste
334254721Semastevoid
335254721SemasteSBAttachInfo::SetResumeCount (uint32_t c)
336254721Semaste{
337254721Semaste    m_opaque_sp->SetResumeCount (c);
338254721Semaste}
339254721Semaste
340254721Semasteconst char *
341254721SemasteSBAttachInfo::GetProcessPluginName ()
342254721Semaste{
343254721Semaste    return m_opaque_sp->GetProcessPluginName();
344254721Semaste}
345254721Semaste
346254721Semastevoid
347254721SemasteSBAttachInfo::SetProcessPluginName (const char *plugin_name)
348254721Semaste{
349254721Semaste    return m_opaque_sp->SetProcessPluginName (plugin_name);
350254721Semaste}
351254721Semaste
352254721Semastevoid
353254721SemasteSBAttachInfo::SetExecutable (const char *path)
354254721Semaste{
355254721Semaste    if (path && path[0])
356254721Semaste        m_opaque_sp->GetExecutableFile().SetFile(path, false);
357254721Semaste    else
358254721Semaste        m_opaque_sp->GetExecutableFile().Clear();
359254721Semaste}
360254721Semaste
361254721Semastevoid
362254721SemasteSBAttachInfo::SetExecutable (SBFileSpec exe_file)
363254721Semaste{
364254721Semaste    if (exe_file.IsValid())
365254721Semaste        m_opaque_sp->GetExecutableFile() = exe_file.ref();
366254721Semaste    else
367254721Semaste        m_opaque_sp->GetExecutableFile().Clear();
368254721Semaste}
369254721Semaste
370254721Semastebool
371254721SemasteSBAttachInfo::GetWaitForLaunch ()
372254721Semaste{
373254721Semaste    return m_opaque_sp->GetWaitForLaunch();
374254721Semaste}
375254721Semaste
376254721Semastevoid
377254721SemasteSBAttachInfo::SetWaitForLaunch (bool b)
378254721Semaste{
379254721Semaste    m_opaque_sp->SetWaitForLaunch (b);
380254721Semaste}
381254721Semaste
382254721Semastebool
383254721SemasteSBAttachInfo::GetIgnoreExisting ()
384254721Semaste{
385254721Semaste    return m_opaque_sp->GetIgnoreExisting();
386254721Semaste}
387254721Semaste
388254721Semastevoid
389254721SemasteSBAttachInfo::SetIgnoreExisting (bool b)
390254721Semaste{
391254721Semaste    m_opaque_sp->SetIgnoreExisting (b);
392254721Semaste}
393254721Semaste
394254721Semasteuint32_t
395254721SemasteSBAttachInfo::GetUserID()
396254721Semaste{
397254721Semaste    return m_opaque_sp->GetUserID();
398254721Semaste}
399254721Semaste
400254721Semasteuint32_t
401254721SemasteSBAttachInfo::GetGroupID()
402254721Semaste{
403254721Semaste    return m_opaque_sp->GetGroupID();
404254721Semaste}
405254721Semaste
406254721Semastebool
407254721SemasteSBAttachInfo::UserIDIsValid ()
408254721Semaste{
409254721Semaste    return m_opaque_sp->UserIDIsValid();
410254721Semaste}
411254721Semaste
412254721Semastebool
413254721SemasteSBAttachInfo::GroupIDIsValid ()
414254721Semaste{
415254721Semaste    return m_opaque_sp->GroupIDIsValid();
416254721Semaste}
417254721Semaste
418254721Semastevoid
419254721SemasteSBAttachInfo::SetUserID (uint32_t uid)
420254721Semaste{
421254721Semaste    m_opaque_sp->SetUserID (uid);
422254721Semaste}
423254721Semaste
424254721Semastevoid
425254721SemasteSBAttachInfo::SetGroupID (uint32_t gid)
426254721Semaste{
427254721Semaste    m_opaque_sp->SetGroupID (gid);
428254721Semaste}
429254721Semaste
430254721Semasteuint32_t
431254721SemasteSBAttachInfo::GetEffectiveUserID()
432254721Semaste{
433254721Semaste    return m_opaque_sp->GetEffectiveUserID();
434254721Semaste}
435254721Semaste
436254721Semasteuint32_t
437254721SemasteSBAttachInfo::GetEffectiveGroupID()
438254721Semaste{
439254721Semaste    return m_opaque_sp->GetEffectiveGroupID();
440254721Semaste}
441254721Semaste
442254721Semastebool
443254721SemasteSBAttachInfo::EffectiveUserIDIsValid ()
444254721Semaste{
445254721Semaste    return m_opaque_sp->EffectiveUserIDIsValid();
446254721Semaste}
447254721Semaste
448254721Semastebool
449254721SemasteSBAttachInfo::EffectiveGroupIDIsValid ()
450254721Semaste{
451254721Semaste    return m_opaque_sp->EffectiveGroupIDIsValid ();
452254721Semaste}
453254721Semaste
454254721Semastevoid
455254721SemasteSBAttachInfo::SetEffectiveUserID (uint32_t uid)
456254721Semaste{
457254721Semaste    m_opaque_sp->SetEffectiveUserID(uid);
458254721Semaste}
459254721Semaste
460254721Semastevoid
461254721SemasteSBAttachInfo::SetEffectiveGroupID (uint32_t gid)
462254721Semaste{
463254721Semaste    m_opaque_sp->SetEffectiveGroupID(gid);
464254721Semaste}
465254721Semaste
466254721Semastelldb::pid_t
467254721SemasteSBAttachInfo::GetParentProcessID ()
468254721Semaste{
469254721Semaste    return m_opaque_sp->GetParentProcessID();
470254721Semaste}
471254721Semaste
472254721Semastevoid
473254721SemasteSBAttachInfo::SetParentProcessID (lldb::pid_t pid)
474254721Semaste{
475254721Semaste    m_opaque_sp->SetParentProcessID (pid);
476254721Semaste}
477254721Semaste
478254721Semastebool
479254721SemasteSBAttachInfo::ParentProcessIDIsValid()
480254721Semaste{
481254721Semaste    return m_opaque_sp->ParentProcessIDIsValid();
482254721Semaste}
483254721Semaste
484254721Semaste
485254721Semaste//----------------------------------------------------------------------
486254721Semaste// SBTarget constructor
487254721Semaste//----------------------------------------------------------------------
488254721SemasteSBTarget::SBTarget () :
489254721Semaste    m_opaque_sp ()
490254721Semaste{
491254721Semaste}
492254721Semaste
493254721SemasteSBTarget::SBTarget (const SBTarget& rhs) :
494254721Semaste    m_opaque_sp (rhs.m_opaque_sp)
495254721Semaste{
496254721Semaste}
497254721Semaste
498254721SemasteSBTarget::SBTarget(const TargetSP& target_sp) :
499254721Semaste    m_opaque_sp (target_sp)
500254721Semaste{
501254721Semaste}
502254721Semaste
503254721Semasteconst SBTarget&
504254721SemasteSBTarget::operator = (const SBTarget& rhs)
505254721Semaste{
506254721Semaste    if (this != &rhs)
507254721Semaste        m_opaque_sp = rhs.m_opaque_sp;
508254721Semaste    return *this;
509254721Semaste}
510254721Semaste
511254721Semaste//----------------------------------------------------------------------
512254721Semaste// Destructor
513254721Semaste//----------------------------------------------------------------------
514254721SemasteSBTarget::~SBTarget()
515254721Semaste{
516254721Semaste}
517254721Semaste
518254721Semasteconst char *
519254721SemasteSBTarget::GetBroadcasterClassName ()
520254721Semaste{
521254721Semaste    return Target::GetStaticBroadcasterClass().AsCString();
522254721Semaste}
523254721Semaste
524254721Semastebool
525254721SemasteSBTarget::IsValid () const
526254721Semaste{
527254721Semaste    return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
528254721Semaste}
529254721Semaste
530254721SemasteSBProcess
531254721SemasteSBTarget::GetProcess ()
532254721Semaste{
533254721Semaste    SBProcess sb_process;
534254721Semaste    ProcessSP process_sp;
535254721Semaste    TargetSP target_sp(GetSP());
536254721Semaste    if (target_sp)
537254721Semaste    {
538254721Semaste        process_sp = target_sp->GetProcessSP();
539254721Semaste        sb_process.SetSP (process_sp);
540254721Semaste    }
541254721Semaste
542254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
543254721Semaste    if (log)
544254721Semaste    {
545254721Semaste        log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
546254721Semaste                     target_sp.get(), process_sp.get());
547254721Semaste    }
548254721Semaste
549254721Semaste    return sb_process;
550254721Semaste}
551254721Semaste
552254721SemasteSBDebugger
553254721SemasteSBTarget::GetDebugger () const
554254721Semaste{
555254721Semaste    SBDebugger debugger;
556254721Semaste    TargetSP target_sp(GetSP());
557254721Semaste    if (target_sp)
558254721Semaste        debugger.reset (target_sp->GetDebugger().shared_from_this());
559254721Semaste    return debugger;
560254721Semaste}
561254721Semaste
562254721SemasteSBProcess
563254721SemasteSBTarget::LoadCore (const char *core_file)
564254721Semaste{
565254721Semaste    SBProcess sb_process;
566254721Semaste    TargetSP target_sp(GetSP());
567254721Semaste    if (target_sp)
568254721Semaste    {
569254721Semaste        FileSpec filespec(core_file, true);
570254721Semaste        ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
571254721Semaste                                                       NULL,
572254721Semaste                                                       &filespec));
573254721Semaste        if (process_sp)
574254721Semaste        {
575254721Semaste            process_sp->LoadCore();
576254721Semaste            sb_process.SetSP (process_sp);
577254721Semaste        }
578254721Semaste    }
579254721Semaste    return sb_process;
580254721Semaste}
581254721Semaste
582254721SemasteSBProcess
583254721SemasteSBTarget::LaunchSimple
584254721Semaste(
585254721Semaste    char const **argv,
586254721Semaste    char const **envp,
587254721Semaste    const char *working_directory
588254721Semaste)
589254721Semaste{
590254721Semaste    char *stdin_path = NULL;
591254721Semaste    char *stdout_path = NULL;
592254721Semaste    char *stderr_path = NULL;
593254721Semaste    uint32_t launch_flags = 0;
594254721Semaste    bool stop_at_entry = false;
595254721Semaste    SBError error;
596254721Semaste    SBListener listener = GetDebugger().GetListener();
597254721Semaste    return Launch (listener,
598254721Semaste                   argv,
599254721Semaste                   envp,
600254721Semaste                   stdin_path,
601254721Semaste                   stdout_path,
602254721Semaste                   stderr_path,
603254721Semaste                   working_directory,
604254721Semaste                   launch_flags,
605254721Semaste                   stop_at_entry,
606254721Semaste                   error);
607254721Semaste}
608254721Semaste
609263367SemasteSBError
610263367SemasteSBTarget::Install()
611263367Semaste{
612263367Semaste    SBError sb_error;
613263367Semaste    TargetSP target_sp(GetSP());
614263367Semaste    if (target_sp)
615263367Semaste    {
616263367Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
617263367Semaste        sb_error.ref() = target_sp->Install(NULL);
618263367Semaste    }
619263367Semaste    return sb_error;
620263367Semaste}
621263367Semaste
622254721SemasteSBProcess
623254721SemasteSBTarget::Launch
624254721Semaste(
625254721Semaste    SBListener &listener,
626254721Semaste    char const **argv,
627254721Semaste    char const **envp,
628254721Semaste    const char *stdin_path,
629254721Semaste    const char *stdout_path,
630254721Semaste    const char *stderr_path,
631254721Semaste    const char *working_directory,
632254721Semaste    uint32_t launch_flags,   // See LaunchFlags
633254721Semaste    bool stop_at_entry,
634254721Semaste    lldb::SBError& error
635254721Semaste)
636254721Semaste{
637254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
638254721Semaste
639254721Semaste    SBProcess sb_process;
640254721Semaste    ProcessSP process_sp;
641254721Semaste    TargetSP target_sp(GetSP());
642254721Semaste
643254721Semaste    if (log)
644254721Semaste    {
645254721Semaste        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))...",
646254721Semaste                     target_sp.get(),
647254721Semaste                     argv,
648254721Semaste                     envp,
649254721Semaste                     stdin_path ? stdin_path : "NULL",
650254721Semaste                     stdout_path ? stdout_path : "NULL",
651254721Semaste                     stderr_path ? stderr_path : "NULL",
652254721Semaste                     working_directory ? working_directory : "NULL",
653254721Semaste                     launch_flags,
654254721Semaste                     stop_at_entry,
655254721Semaste                     error.get());
656254721Semaste    }
657254721Semaste
658254721Semaste    if (target_sp)
659254721Semaste    {
660254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
661254721Semaste
662254721Semaste        if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
663254721Semaste            launch_flags |= eLaunchFlagDisableASLR;
664254721Semaste
665254721Semaste        StateType state = eStateInvalid;
666254721Semaste        process_sp = target_sp->GetProcessSP();
667254721Semaste        if (process_sp)
668254721Semaste        {
669254721Semaste            state = process_sp->GetState();
670254721Semaste
671254721Semaste            if (process_sp->IsAlive() && state != eStateConnected)
672254721Semaste            {
673254721Semaste                if (state == eStateAttaching)
674254721Semaste                    error.SetErrorString ("process attach is in progress");
675254721Semaste                else
676254721Semaste                    error.SetErrorString ("a process is already being debugged");
677254721Semaste                return sb_process;
678254721Semaste            }
679254721Semaste        }
680254721Semaste
681254721Semaste        if (state == eStateConnected)
682254721Semaste        {
683254721Semaste            // If we are already connected, then we have already specified the
684254721Semaste            // listener, so if a valid listener is supplied, we need to error out
685254721Semaste            // to let the client know.
686254721Semaste            if (listener.IsValid())
687254721Semaste            {
688254721Semaste                error.SetErrorString ("process is connected and already has a listener, pass empty listener");
689254721Semaste                return sb_process;
690254721Semaste            }
691254721Semaste        }
692254721Semaste
693269024Semaste        if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
694269024Semaste            launch_flags |= eLaunchFlagDisableSTDIO;
695254721Semaste
696269024Semaste        ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
697269024Semaste
698269024Semaste        Module *exe_module = target_sp->GetExecutableModulePointer();
699269024Semaste        if (exe_module)
700269024Semaste            launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
701269024Semaste        if (argv)
702269024Semaste            launch_info.GetArguments().AppendArguments (argv);
703269024Semaste        if (envp)
704269024Semaste            launch_info.GetEnvironmentEntries ().SetArguments (envp);
705254721Semaste
706269024Semaste        if (listener.IsValid())
707269024Semaste            error.SetError (target_sp->Launch(listener.ref(), launch_info));
708254721Semaste        else
709269024Semaste            error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
710269024Semaste
711269024Semaste        sb_process.SetSP(target_sp->GetProcessSP());
712254721Semaste    }
713254721Semaste    else
714254721Semaste    {
715254721Semaste        error.SetErrorString ("SBTarget is invalid");
716254721Semaste    }
717254721Semaste
718254721Semaste    log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
719254721Semaste    if (log)
720254721Semaste    {
721254721Semaste        log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
722269024Semaste                     target_sp.get(), sb_process.GetSP().get());
723254721Semaste    }
724254721Semaste
725254721Semaste    return sb_process;
726254721Semaste}
727254721Semaste
728254721SemasteSBProcess
729254721SemasteSBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
730254721Semaste{
731254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
732254721Semaste
733254721Semaste    SBProcess sb_process;
734254721Semaste    TargetSP target_sp(GetSP());
735254721Semaste
736254721Semaste    if (log)
737254721Semaste    {
738254721Semaste        log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
739254721Semaste    }
740254721Semaste
741254721Semaste    if (target_sp)
742254721Semaste    {
743254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
744254721Semaste        StateType state = eStateInvalid;
745269024Semaste        {
746269024Semaste        ProcessSP process_sp = target_sp->GetProcessSP();
747254721Semaste        if (process_sp)
748254721Semaste        {
749254721Semaste            state = process_sp->GetState();
750254721Semaste
751254721Semaste            if (process_sp->IsAlive() && state != eStateConnected)
752254721Semaste            {
753254721Semaste                if (state == eStateAttaching)
754254721Semaste                    error.SetErrorString ("process attach is in progress");
755254721Semaste                else
756254721Semaste                    error.SetErrorString ("a process is already being debugged");
757254721Semaste                return sb_process;
758254721Semaste            }
759254721Semaste        }
760269024Semaste        }
761254721Semaste
762269024Semaste        lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
763254721Semaste
764269024Semaste        Module *exe_module = target_sp->GetExecutableModulePointer();
765269024Semaste        if (exe_module)
766269024Semaste            launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
767269024Semaste
768269024Semaste        const ArchSpec &arch_spec = target_sp->GetArchitecture();
769269024Semaste        if (arch_spec.IsValid())
770269024Semaste            launch_info.GetArchitecture () = arch_spec;
771269024Semaste
772269024Semaste        error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
773269024Semaste        sb_process.SetSP(target_sp->GetProcessSP());
774254721Semaste    }
775254721Semaste    else
776254721Semaste    {
777254721Semaste        error.SetErrorString ("SBTarget is invalid");
778254721Semaste    }
779254721Semaste
780254721Semaste    log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
781254721Semaste    if (log)
782254721Semaste    {
783269024Semaste        log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
784269024Semaste                     target_sp.get(), sb_process.GetSP().get());
785254721Semaste    }
786254721Semaste
787254721Semaste    return sb_process;
788254721Semaste}
789254721Semaste
790254721Semastelldb::SBProcess
791254721SemasteSBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
792254721Semaste{
793254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
794254721Semaste
795254721Semaste    SBProcess sb_process;
796254721Semaste    ProcessSP process_sp;
797254721Semaste    TargetSP target_sp(GetSP());
798254721Semaste
799254721Semaste    if (log)
800254721Semaste    {
801254721Semaste        log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get());
802254721Semaste    }
803254721Semaste
804254721Semaste    if (target_sp)
805254721Semaste    {
806254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
807254721Semaste
808254721Semaste        StateType state = eStateInvalid;
809254721Semaste        process_sp = target_sp->GetProcessSP();
810254721Semaste        if (process_sp)
811254721Semaste        {
812254721Semaste            state = process_sp->GetState();
813254721Semaste
814254721Semaste            if (process_sp->IsAlive() && state != eStateConnected)
815254721Semaste            {
816254721Semaste                if (state == eStateAttaching)
817254721Semaste                    error.SetErrorString ("process attach is in progress");
818254721Semaste                else
819254721Semaste                    error.SetErrorString ("a process is already being debugged");
820254721Semaste                if (log)
821254721Semaste                {
822254721Semaste                    log->Printf ("SBTarget(%p)::Attach (...) => error %s",
823254721Semaste                                 target_sp.get(), error.GetCString());
824254721Semaste                }
825254721Semaste                return sb_process;
826254721Semaste            }
827254721Semaste        }
828254721Semaste
829254721Semaste        if (state != eStateConnected)
830254721Semaste            process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
831254721Semaste
832254721Semaste        if (process_sp)
833254721Semaste        {
834254721Semaste            ProcessAttachInfo &attach_info = sb_attach_info.ref();
835254721Semaste            if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
836254721Semaste            {
837254721Semaste                PlatformSP platform_sp = target_sp->GetPlatform();
838254721Semaste                // See if we can pre-verify if a process exists or not
839254721Semaste                if (platform_sp && platform_sp->IsConnected())
840254721Semaste                {
841254721Semaste                    lldb::pid_t attach_pid = attach_info.GetProcessID();
842254721Semaste                    ProcessInstanceInfo instance_info;
843254721Semaste                    if (platform_sp->GetProcessInfo(attach_pid, instance_info))
844254721Semaste                    {
845254721Semaste                        attach_info.SetUserID(instance_info.GetEffectiveUserID());
846254721Semaste                    }
847254721Semaste                    else
848254721Semaste                    {
849254721Semaste                        error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
850254721Semaste                        if (log)
851254721Semaste                        {
852254721Semaste                            log->Printf ("SBTarget(%p)::Attach (...) => error %s",
853254721Semaste                                         target_sp.get(), error.GetCString());
854254721Semaste                        }
855254721Semaste                        return sb_process;
856254721Semaste                    }
857254721Semaste                }
858254721Semaste            }
859254721Semaste            error.SetError (process_sp->Attach (attach_info));
860254721Semaste            if (error.Success())
861254721Semaste            {
862254721Semaste                sb_process.SetSP (process_sp);
863254721Semaste                // If we are doing synchronous mode, then wait for the
864254721Semaste                // process to stop!
865254721Semaste                if (target_sp->GetDebugger().GetAsyncExecution () == false)
866254721Semaste                    process_sp->WaitForProcessToStop (NULL);
867254721Semaste            }
868254721Semaste        }
869254721Semaste        else
870254721Semaste        {
871254721Semaste            error.SetErrorString ("unable to create lldb_private::Process");
872254721Semaste        }
873254721Semaste    }
874254721Semaste    else
875254721Semaste    {
876254721Semaste        error.SetErrorString ("SBTarget is invalid");
877254721Semaste    }
878254721Semaste
879254721Semaste    if (log)
880254721Semaste    {
881254721Semaste        log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
882254721Semaste                     target_sp.get(), process_sp.get());
883254721Semaste    }
884254721Semaste
885254721Semaste    return sb_process;
886254721Semaste}
887254721Semaste
888254721Semaste
889254721Semaste#if defined(__APPLE__)
890254721Semaste
891254721Semastelldb::SBProcess
892254721SemasteSBTarget::AttachToProcessWithID (SBListener &listener,
893254721Semaste                                ::pid_t pid,
894254721Semaste                                 lldb::SBError& error)
895254721Semaste{
896254721Semaste    return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
897254721Semaste}
898254721Semaste
899254721Semaste#endif // #if defined(__APPLE__)
900254721Semaste
901254721Semastelldb::SBProcess
902254721SemasteSBTarget::AttachToProcessWithID
903254721Semaste(
904254721Semaste    SBListener &listener,
905254721Semaste    lldb::pid_t pid,// The process ID to attach to
906254721Semaste    SBError& error  // An error explaining what went wrong if attach fails
907254721Semaste)
908254721Semaste{
909254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
910254721Semaste
911254721Semaste    SBProcess sb_process;
912254721Semaste    ProcessSP process_sp;
913254721Semaste    TargetSP target_sp(GetSP());
914254721Semaste
915254721Semaste    if (log)
916254721Semaste    {
917254721Semaste        log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid);
918254721Semaste    }
919254721Semaste
920254721Semaste    if (target_sp)
921254721Semaste    {
922254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
923254721Semaste
924254721Semaste        StateType state = eStateInvalid;
925254721Semaste        process_sp = target_sp->GetProcessSP();
926254721Semaste        if (process_sp)
927254721Semaste        {
928254721Semaste            state = process_sp->GetState();
929254721Semaste
930254721Semaste            if (process_sp->IsAlive() && state != eStateConnected)
931254721Semaste            {
932254721Semaste                if (state == eStateAttaching)
933254721Semaste                    error.SetErrorString ("process attach is in progress");
934254721Semaste                else
935254721Semaste                    error.SetErrorString ("a process is already being debugged");
936254721Semaste                return sb_process;
937254721Semaste            }
938254721Semaste        }
939254721Semaste
940254721Semaste        if (state == eStateConnected)
941254721Semaste        {
942254721Semaste            // If we are already connected, then we have already specified the
943254721Semaste            // listener, so if a valid listener is supplied, we need to error out
944254721Semaste            // to let the client know.
945254721Semaste            if (listener.IsValid())
946254721Semaste            {
947254721Semaste                error.SetErrorString ("process is connected and already has a listener, pass empty listener");
948254721Semaste                return sb_process;
949254721Semaste            }
950254721Semaste        }
951254721Semaste        else
952254721Semaste        {
953254721Semaste            if (listener.IsValid())
954254721Semaste                process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
955254721Semaste            else
956254721Semaste                process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
957254721Semaste        }
958254721Semaste        if (process_sp)
959254721Semaste        {
960254721Semaste            sb_process.SetSP (process_sp);
961254721Semaste
962254721Semaste            ProcessAttachInfo attach_info;
963254721Semaste            attach_info.SetProcessID (pid);
964254721Semaste
965254721Semaste            PlatformSP platform_sp = target_sp->GetPlatform();
966254721Semaste            ProcessInstanceInfo instance_info;
967254721Semaste            if (platform_sp->GetProcessInfo(pid, instance_info))
968254721Semaste            {
969254721Semaste                attach_info.SetUserID(instance_info.GetEffectiveUserID());
970254721Semaste            }
971254721Semaste            error.SetError (process_sp->Attach (attach_info));
972254721Semaste            if (error.Success())
973254721Semaste            {
974254721Semaste                // If we are doing synchronous mode, then wait for the
975254721Semaste                // process to stop!
976254721Semaste                if (target_sp->GetDebugger().GetAsyncExecution () == false)
977254721Semaste                process_sp->WaitForProcessToStop (NULL);
978254721Semaste            }
979254721Semaste        }
980254721Semaste        else
981254721Semaste        {
982254721Semaste            error.SetErrorString ("unable to create lldb_private::Process");
983254721Semaste        }
984254721Semaste    }
985254721Semaste    else
986254721Semaste    {
987254721Semaste        error.SetErrorString ("SBTarget is invalid");
988254721Semaste    }
989254721Semaste
990254721Semaste    if (log)
991254721Semaste    {
992254721Semaste        log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
993254721Semaste                     target_sp.get(), process_sp.get());
994254721Semaste    }
995254721Semaste    return sb_process;
996254721Semaste}
997254721Semaste
998254721Semastelldb::SBProcess
999254721SemasteSBTarget::AttachToProcessWithName
1000254721Semaste(
1001254721Semaste    SBListener &listener,
1002254721Semaste    const char *name,   // basename of process to attach to
1003254721Semaste    bool wait_for,      // if true wait for a new instance of "name" to be launched
1004254721Semaste    SBError& error      // An error explaining what went wrong if attach fails
1005254721Semaste)
1006254721Semaste{
1007254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1008254721Semaste
1009254721Semaste    SBProcess sb_process;
1010254721Semaste    ProcessSP process_sp;
1011254721Semaste    TargetSP target_sp(GetSP());
1012254721Semaste
1013254721Semaste    if (log)
1014254721Semaste    {
1015254721Semaste        log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false");
1016254721Semaste    }
1017254721Semaste
1018254721Semaste    if (name && target_sp)
1019254721Semaste    {
1020254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1021254721Semaste
1022254721Semaste        StateType state = eStateInvalid;
1023254721Semaste        process_sp = target_sp->GetProcessSP();
1024254721Semaste        if (process_sp)
1025254721Semaste        {
1026254721Semaste            state = process_sp->GetState();
1027254721Semaste
1028254721Semaste            if (process_sp->IsAlive() && state != eStateConnected)
1029254721Semaste            {
1030254721Semaste                if (state == eStateAttaching)
1031254721Semaste                    error.SetErrorString ("process attach is in progress");
1032254721Semaste                else
1033254721Semaste                    error.SetErrorString ("a process is already being debugged");
1034254721Semaste                return sb_process;
1035254721Semaste            }
1036254721Semaste        }
1037254721Semaste
1038254721Semaste        if (state == eStateConnected)
1039254721Semaste        {
1040254721Semaste            // If we are already connected, then we have already specified the
1041254721Semaste            // listener, so if a valid listener is supplied, we need to error out
1042254721Semaste            // to let the client know.
1043254721Semaste            if (listener.IsValid())
1044254721Semaste            {
1045254721Semaste                error.SetErrorString ("process is connected and already has a listener, pass empty listener");
1046254721Semaste                return sb_process;
1047254721Semaste            }
1048254721Semaste        }
1049254721Semaste        else
1050254721Semaste        {
1051254721Semaste            if (listener.IsValid())
1052254721Semaste                process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
1053254721Semaste            else
1054254721Semaste                process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
1055254721Semaste        }
1056254721Semaste
1057254721Semaste        if (process_sp)
1058254721Semaste        {
1059254721Semaste            sb_process.SetSP (process_sp);
1060254721Semaste            ProcessAttachInfo attach_info;
1061254721Semaste            attach_info.GetExecutableFile().SetFile(name, false);
1062254721Semaste            attach_info.SetWaitForLaunch(wait_for);
1063254721Semaste            error.SetError (process_sp->Attach (attach_info));
1064254721Semaste            if (error.Success())
1065254721Semaste            {
1066254721Semaste                // If we are doing synchronous mode, then wait for the
1067254721Semaste                // process to stop!
1068254721Semaste                if (target_sp->GetDebugger().GetAsyncExecution () == false)
1069254721Semaste                    process_sp->WaitForProcessToStop (NULL);
1070254721Semaste            }
1071254721Semaste        }
1072254721Semaste        else
1073254721Semaste        {
1074254721Semaste            error.SetErrorString ("unable to create lldb_private::Process");
1075254721Semaste        }
1076254721Semaste    }
1077254721Semaste    else
1078254721Semaste    {
1079254721Semaste        error.SetErrorString ("SBTarget is invalid");
1080254721Semaste    }
1081254721Semaste
1082254721Semaste    if (log)
1083254721Semaste    {
1084254721Semaste        log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
1085254721Semaste                     target_sp.get(), process_sp.get());
1086254721Semaste    }
1087254721Semaste    return sb_process;
1088254721Semaste}
1089254721Semaste
1090254721Semastelldb::SBProcess
1091254721SemasteSBTarget::ConnectRemote
1092254721Semaste(
1093254721Semaste    SBListener &listener,
1094254721Semaste    const char *url,
1095254721Semaste    const char *plugin_name,
1096254721Semaste    SBError& error
1097254721Semaste)
1098254721Semaste{
1099254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1100254721Semaste
1101254721Semaste    SBProcess sb_process;
1102254721Semaste    ProcessSP process_sp;
1103254721Semaste    TargetSP target_sp(GetSP());
1104254721Semaste
1105254721Semaste    if (log)
1106254721Semaste    {
1107254721Semaste        log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name);
1108254721Semaste    }
1109254721Semaste
1110254721Semaste    if (target_sp)
1111254721Semaste    {
1112254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1113254721Semaste        if (listener.IsValid())
1114254721Semaste            process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
1115254721Semaste        else
1116254721Semaste            process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
1117254721Semaste
1118254721Semaste
1119254721Semaste        if (process_sp)
1120254721Semaste        {
1121254721Semaste            sb_process.SetSP (process_sp);
1122254721Semaste            error.SetError (process_sp->ConnectRemote (NULL, url));
1123254721Semaste        }
1124254721Semaste        else
1125254721Semaste        {
1126254721Semaste            error.SetErrorString ("unable to create lldb_private::Process");
1127254721Semaste        }
1128254721Semaste    }
1129254721Semaste    else
1130254721Semaste    {
1131254721Semaste        error.SetErrorString ("SBTarget is invalid");
1132254721Semaste    }
1133254721Semaste
1134254721Semaste    if (log)
1135254721Semaste    {
1136254721Semaste        log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
1137254721Semaste                     target_sp.get(), process_sp.get());
1138254721Semaste    }
1139254721Semaste    return sb_process;
1140254721Semaste}
1141254721Semaste
1142254721SemasteSBFileSpec
1143254721SemasteSBTarget::GetExecutable ()
1144254721Semaste{
1145254721Semaste
1146254721Semaste    SBFileSpec exe_file_spec;
1147254721Semaste    TargetSP target_sp(GetSP());
1148254721Semaste    if (target_sp)
1149254721Semaste    {
1150254721Semaste        Module *exe_module = target_sp->GetExecutableModulePointer();
1151254721Semaste        if (exe_module)
1152254721Semaste            exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
1153254721Semaste    }
1154254721Semaste
1155254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1156254721Semaste    if (log)
1157254721Semaste    {
1158254721Semaste        log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1159254721Semaste                     target_sp.get(), exe_file_spec.get());
1160254721Semaste    }
1161254721Semaste
1162254721Semaste    return exe_file_spec;
1163254721Semaste}
1164254721Semaste
1165254721Semastebool
1166254721SemasteSBTarget::operator == (const SBTarget &rhs) const
1167254721Semaste{
1168254721Semaste    return m_opaque_sp.get() == rhs.m_opaque_sp.get();
1169254721Semaste}
1170254721Semaste
1171254721Semastebool
1172254721SemasteSBTarget::operator != (const SBTarget &rhs) const
1173254721Semaste{
1174254721Semaste    return m_opaque_sp.get() != rhs.m_opaque_sp.get();
1175254721Semaste}
1176254721Semaste
1177254721Semastelldb::TargetSP
1178254721SemasteSBTarget::GetSP () const
1179254721Semaste{
1180254721Semaste    return m_opaque_sp;
1181254721Semaste}
1182254721Semaste
1183254721Semastevoid
1184254721SemasteSBTarget::SetSP (const lldb::TargetSP& target_sp)
1185254721Semaste{
1186254721Semaste    m_opaque_sp = target_sp;
1187254721Semaste}
1188254721Semaste
1189254721Semastelldb::SBAddress
1190254721SemasteSBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
1191254721Semaste{
1192254721Semaste    lldb::SBAddress sb_addr;
1193254721Semaste    Address &addr = sb_addr.ref();
1194254721Semaste    TargetSP target_sp(GetSP());
1195254721Semaste    if (target_sp)
1196254721Semaste    {
1197254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1198269024Semaste        if (target_sp->ResolveLoadAddress (vm_addr, addr))
1199254721Semaste            return sb_addr;
1200254721Semaste    }
1201254721Semaste
1202254721Semaste    // We have a load address that isn't in a section, just return an address
1203254721Semaste    // with the offset filled in (the address) and the section set to NULL
1204254721Semaste    addr.SetRawAddress(vm_addr);
1205254721Semaste    return sb_addr;
1206254721Semaste}
1207254721Semaste
1208269024Semaste
1209269024Semastelldb::SBAddress
1210269024SemasteSBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1211269024Semaste{
1212269024Semaste    lldb::SBAddress sb_addr;
1213269024Semaste    Address &addr = sb_addr.ref();
1214269024Semaste    TargetSP target_sp(GetSP());
1215269024Semaste    if (target_sp)
1216269024Semaste    {
1217269024Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1218269024Semaste        if (target_sp->ResolveLoadAddress (vm_addr, addr))
1219269024Semaste            return sb_addr;
1220269024Semaste    }
1221269024Semaste
1222269024Semaste    // We have a load address that isn't in a section, just return an address
1223269024Semaste    // with the offset filled in (the address) and the section set to NULL
1224269024Semaste    addr.SetRawAddress(vm_addr);
1225269024Semaste    return sb_addr;
1226269024Semaste}
1227269024Semaste
1228254721SemasteSBSymbolContext
1229263363SemasteSBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1230263363Semaste                                          uint32_t resolve_scope)
1231254721Semaste{
1232254721Semaste    SBSymbolContext sc;
1233254721Semaste    if (addr.IsValid())
1234254721Semaste    {
1235254721Semaste        TargetSP target_sp(GetSP());
1236254721Semaste        if (target_sp)
1237254721Semaste            target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1238254721Semaste    }
1239254721Semaste    return sc;
1240254721Semaste}
1241254721Semaste
1242254721Semaste
1243254721SemasteSBBreakpoint
1244263363SemasteSBTarget::BreakpointCreateByLocation (const char *file,
1245263363Semaste                                      uint32_t line)
1246254721Semaste{
1247254721Semaste    return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
1248254721Semaste}
1249254721Semaste
1250254721SemasteSBBreakpoint
1251263363SemasteSBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1252263363Semaste                                      uint32_t line)
1253254721Semaste{
1254254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1255254721Semaste
1256254721Semaste    SBBreakpoint sb_bp;
1257254721Semaste    TargetSP target_sp(GetSP());
1258254721Semaste    if (target_sp && line != 0)
1259254721Semaste    {
1260254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1261254721Semaste
1262254721Semaste        const LazyBool check_inlines = eLazyBoolCalculate;
1263254721Semaste        const LazyBool skip_prologue = eLazyBoolCalculate;
1264254721Semaste        const bool internal = false;
1265263363Semaste        const bool hardware = false;
1266263363Semaste        *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
1267254721Semaste    }
1268254721Semaste
1269254721Semaste    if (log)
1270254721Semaste    {
1271254721Semaste        SBStream sstr;
1272254721Semaste        sb_bp.GetDescription (sstr);
1273254721Semaste        char path[PATH_MAX];
1274254721Semaste        sb_file_spec->GetPath (path, sizeof(path));
1275254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1276254721Semaste                     target_sp.get(),
1277254721Semaste                     path,
1278254721Semaste                     line,
1279254721Semaste                     sb_bp.get(),
1280254721Semaste                     sstr.GetData());
1281254721Semaste    }
1282254721Semaste
1283254721Semaste    return sb_bp;
1284254721Semaste}
1285254721Semaste
1286254721SemasteSBBreakpoint
1287263363SemasteSBTarget::BreakpointCreateByName (const char *symbol_name,
1288263363Semaste                                  const char *module_name)
1289254721Semaste{
1290254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1291254721Semaste
1292254721Semaste    SBBreakpoint sb_bp;
1293254721Semaste    TargetSP target_sp(GetSP());
1294254721Semaste    if (target_sp.get())
1295254721Semaste    {
1296254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1297254721Semaste
1298254721Semaste        const bool internal = false;
1299263363Semaste        const bool hardware = false;
1300254721Semaste        const LazyBool skip_prologue = eLazyBoolCalculate;
1301254721Semaste        if (module_name && module_name[0])
1302254721Semaste        {
1303254721Semaste            FileSpecList module_spec_list;
1304254721Semaste            module_spec_list.Append (FileSpec (module_name, false));
1305263363Semaste            *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1306254721Semaste        }
1307254721Semaste        else
1308254721Semaste        {
1309263363Semaste            *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1310254721Semaste        }
1311254721Semaste    }
1312254721Semaste
1313254721Semaste    if (log)
1314254721Semaste    {
1315254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1316254721Semaste                     target_sp.get(), symbol_name, module_name, sb_bp.get());
1317254721Semaste    }
1318254721Semaste
1319254721Semaste    return sb_bp;
1320254721Semaste}
1321254721Semaste
1322254721Semastelldb::SBBreakpoint
1323254721SemasteSBTarget::BreakpointCreateByName (const char *symbol_name,
1324263363Semaste                                  const SBFileSpecList &module_list,
1325263363Semaste                                  const SBFileSpecList &comp_unit_list)
1326254721Semaste{
1327254721Semaste    uint32_t name_type_mask = eFunctionNameTypeAuto;
1328254721Semaste    return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1329254721Semaste}
1330254721Semaste
1331254721Semastelldb::SBBreakpoint
1332254721SemasteSBTarget::BreakpointCreateByName (const char *symbol_name,
1333263363Semaste                                  uint32_t name_type_mask,
1334263363Semaste                                  const SBFileSpecList &module_list,
1335263363Semaste                                  const SBFileSpecList &comp_unit_list)
1336254721Semaste{
1337254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1338254721Semaste
1339254721Semaste    SBBreakpoint sb_bp;
1340254721Semaste    TargetSP target_sp(GetSP());
1341254721Semaste    if (target_sp && symbol_name && symbol_name[0])
1342254721Semaste    {
1343254721Semaste        const bool internal = false;
1344263363Semaste        const bool hardware = false;
1345254721Semaste        const LazyBool skip_prologue = eLazyBoolCalculate;
1346254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1347254721Semaste        *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1348263363Semaste                                              comp_unit_list.get(),
1349263363Semaste                                              symbol_name,
1350263363Semaste                                              name_type_mask,
1351263363Semaste                                              skip_prologue,
1352263363Semaste                                              internal,
1353263363Semaste                                              hardware);
1354254721Semaste    }
1355254721Semaste
1356254721Semaste    if (log)
1357254721Semaste    {
1358254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1359254721Semaste                     target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
1360254721Semaste    }
1361254721Semaste
1362254721Semaste    return sb_bp;
1363254721Semaste}
1364254721Semaste
1365254721Semastelldb::SBBreakpoint
1366254721SemasteSBTarget::BreakpointCreateByNames (const char *symbol_names[],
1367254721Semaste                                   uint32_t num_names,
1368254721Semaste                                   uint32_t name_type_mask,
1369254721Semaste                                   const SBFileSpecList &module_list,
1370254721Semaste                                   const SBFileSpecList &comp_unit_list)
1371254721Semaste{
1372254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1373254721Semaste
1374254721Semaste    SBBreakpoint sb_bp;
1375254721Semaste    TargetSP target_sp(GetSP());
1376254721Semaste    if (target_sp && num_names > 0)
1377254721Semaste    {
1378254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1379254721Semaste        const bool internal = false;
1380263363Semaste        const bool hardware = false;
1381254721Semaste        const LazyBool skip_prologue = eLazyBoolCalculate;
1382254721Semaste        *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1383254721Semaste                                                comp_unit_list.get(),
1384254721Semaste                                                symbol_names,
1385254721Semaste                                                num_names,
1386254721Semaste                                                name_type_mask,
1387254721Semaste                                                skip_prologue,
1388263363Semaste                                                internal,
1389263363Semaste                                                hardware);
1390254721Semaste    }
1391254721Semaste
1392254721Semaste    if (log)
1393254721Semaste    {
1394254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1395254721Semaste        for (uint32_t i = 0 ; i < num_names; i++)
1396254721Semaste        {
1397254721Semaste            char sep;
1398254721Semaste            if (i < num_names - 1)
1399254721Semaste                sep = ',';
1400254721Semaste            else
1401254721Semaste                sep = '}';
1402254721Semaste            if (symbol_names[i] != NULL)
1403254721Semaste                log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1404254721Semaste            else
1405254721Semaste                log->Printf ("\"<NULL>\"%c ", sep);
1406254721Semaste
1407254721Semaste        }
1408254721Semaste        log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1409254721Semaste    }
1410254721Semaste
1411254721Semaste    return sb_bp;
1412254721Semaste}
1413254721Semaste
1414254721SemasteSBBreakpoint
1415263363SemasteSBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1416263363Semaste                                   const char *module_name)
1417254721Semaste{
1418254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1419254721Semaste
1420254721Semaste    SBBreakpoint sb_bp;
1421254721Semaste    TargetSP target_sp(GetSP());
1422254721Semaste    if (target_sp && symbol_name_regex && symbol_name_regex[0])
1423254721Semaste    {
1424254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1425254721Semaste        RegularExpression regexp(symbol_name_regex);
1426254721Semaste        const bool internal = false;
1427263363Semaste        const bool hardware = false;
1428254721Semaste        const LazyBool skip_prologue = eLazyBoolCalculate;
1429254721Semaste
1430254721Semaste        if (module_name && module_name[0])
1431254721Semaste        {
1432254721Semaste            FileSpecList module_spec_list;
1433254721Semaste            module_spec_list.Append (FileSpec (module_name, false));
1434254721Semaste
1435263363Semaste            *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
1436254721Semaste        }
1437254721Semaste        else
1438254721Semaste        {
1439263363Semaste            *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
1440254721Semaste        }
1441254721Semaste    }
1442254721Semaste
1443254721Semaste    if (log)
1444254721Semaste    {
1445254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1446254721Semaste                     target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
1447254721Semaste    }
1448254721Semaste
1449254721Semaste    return sb_bp;
1450254721Semaste}
1451254721Semaste
1452254721Semastelldb::SBBreakpoint
1453254721SemasteSBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1454263363Semaste                                   const SBFileSpecList &module_list,
1455263363Semaste                                   const SBFileSpecList &comp_unit_list)
1456254721Semaste{
1457254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1458254721Semaste
1459254721Semaste    SBBreakpoint sb_bp;
1460254721Semaste    TargetSP target_sp(GetSP());
1461254721Semaste    if (target_sp && symbol_name_regex && symbol_name_regex[0])
1462254721Semaste    {
1463254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1464254721Semaste        RegularExpression regexp(symbol_name_regex);
1465254721Semaste        const bool internal = false;
1466263363Semaste        const bool hardware = false;
1467254721Semaste        const LazyBool skip_prologue = eLazyBoolCalculate;
1468254721Semaste
1469263363Semaste        *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
1470254721Semaste    }
1471254721Semaste
1472254721Semaste    if (log)
1473254721Semaste    {
1474254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1475254721Semaste                     target_sp.get(), symbol_name_regex, sb_bp.get());
1476254721Semaste    }
1477254721Semaste
1478254721Semaste    return sb_bp;
1479254721Semaste}
1480254721Semaste
1481254721SemasteSBBreakpoint
1482254721SemasteSBTarget::BreakpointCreateByAddress (addr_t address)
1483254721Semaste{
1484254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1485254721Semaste
1486254721Semaste    SBBreakpoint sb_bp;
1487254721Semaste    TargetSP target_sp(GetSP());
1488254721Semaste    if (target_sp)
1489254721Semaste    {
1490254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1491263363Semaste        const bool hardware = false;
1492263363Semaste        *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
1493254721Semaste    }
1494254721Semaste
1495254721Semaste    if (log)
1496254721Semaste    {
1497254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
1498254721Semaste    }
1499254721Semaste
1500254721Semaste    return sb_bp;
1501254721Semaste}
1502254721Semaste
1503254721Semastelldb::SBBreakpoint
1504263363SemasteSBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1505263363Semaste                                         const lldb::SBFileSpec &source_file,
1506263363Semaste                                         const char *module_name)
1507254721Semaste{
1508254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1509254721Semaste
1510254721Semaste    SBBreakpoint sb_bp;
1511254721Semaste    TargetSP target_sp(GetSP());
1512254721Semaste    if (target_sp && source_regex && source_regex[0])
1513254721Semaste    {
1514254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1515254721Semaste        RegularExpression regexp(source_regex);
1516254721Semaste        FileSpecList source_file_spec_list;
1517263363Semaste        const bool hardware = false;
1518254721Semaste        source_file_spec_list.Append (source_file.ref());
1519254721Semaste
1520254721Semaste        if (module_name && module_name[0])
1521254721Semaste        {
1522254721Semaste            FileSpecList module_spec_list;
1523254721Semaste            module_spec_list.Append (FileSpec (module_name, false));
1524254721Semaste
1525263363Semaste            *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
1526254721Semaste        }
1527254721Semaste        else
1528254721Semaste        {
1529263363Semaste            *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
1530254721Semaste        }
1531254721Semaste    }
1532254721Semaste
1533254721Semaste    if (log)
1534254721Semaste    {
1535254721Semaste        char path[PATH_MAX];
1536254721Semaste        source_file->GetPath (path, sizeof(path));
1537254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1538254721Semaste                     target_sp.get(), source_regex, path, module_name, sb_bp.get());
1539254721Semaste    }
1540254721Semaste
1541254721Semaste    return sb_bp;
1542254721Semaste}
1543254721Semaste
1544254721Semastelldb::SBBreakpoint
1545254721SemasteSBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1546263363Semaste                                         const SBFileSpecList &module_list,
1547263363Semaste                                         const lldb::SBFileSpecList &source_file_list)
1548254721Semaste{
1549254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1550254721Semaste
1551254721Semaste    SBBreakpoint sb_bp;
1552254721Semaste    TargetSP target_sp(GetSP());
1553254721Semaste    if (target_sp && source_regex && source_regex[0])
1554254721Semaste    {
1555254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1556263363Semaste        const bool hardware = false;
1557254721Semaste        RegularExpression regexp(source_regex);
1558263363Semaste        *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
1559254721Semaste    }
1560254721Semaste
1561254721Semaste    if (log)
1562254721Semaste    {
1563254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1564254721Semaste                     target_sp.get(), source_regex, sb_bp.get());
1565254721Semaste    }
1566254721Semaste
1567254721Semaste    return sb_bp;
1568254721Semaste}
1569254721Semaste
1570254721Semastelldb::SBBreakpoint
1571254721SemasteSBTarget::BreakpointCreateForException  (lldb::LanguageType language,
1572263363Semaste                                         bool catch_bp,
1573263363Semaste                                         bool throw_bp)
1574254721Semaste{
1575254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1576254721Semaste
1577254721Semaste    SBBreakpoint sb_bp;
1578254721Semaste    TargetSP target_sp(GetSP());
1579254721Semaste    if (target_sp)
1580254721Semaste    {
1581254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1582263363Semaste        const bool hardware = false;
1583263363Semaste        *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
1584254721Semaste    }
1585254721Semaste
1586254721Semaste    if (log)
1587254721Semaste    {
1588254721Semaste        log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1589254721Semaste                     target_sp.get(),
1590254721Semaste                     LanguageRuntime::GetNameForLanguageType(language),
1591254721Semaste                     catch_bp ? "on" : "off",
1592254721Semaste                     throw_bp ? "on" : "off",
1593254721Semaste                     sb_bp.get());
1594254721Semaste    }
1595254721Semaste
1596254721Semaste    return sb_bp;
1597254721Semaste}
1598254721Semaste
1599254721Semasteuint32_t
1600254721SemasteSBTarget::GetNumBreakpoints () const
1601254721Semaste{
1602254721Semaste    TargetSP target_sp(GetSP());
1603254721Semaste    if (target_sp)
1604254721Semaste    {
1605254721Semaste        // The breakpoint list is thread safe, no need to lock
1606254721Semaste        return target_sp->GetBreakpointList().GetSize();
1607254721Semaste    }
1608254721Semaste    return 0;
1609254721Semaste}
1610254721Semaste
1611254721SemasteSBBreakpoint
1612254721SemasteSBTarget::GetBreakpointAtIndex (uint32_t idx) const
1613254721Semaste{
1614254721Semaste    SBBreakpoint sb_breakpoint;
1615254721Semaste    TargetSP target_sp(GetSP());
1616254721Semaste    if (target_sp)
1617254721Semaste    {
1618254721Semaste        // The breakpoint list is thread safe, no need to lock
1619254721Semaste        *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1620254721Semaste    }
1621254721Semaste    return sb_breakpoint;
1622254721Semaste}
1623254721Semaste
1624254721Semastebool
1625254721SemasteSBTarget::BreakpointDelete (break_id_t bp_id)
1626254721Semaste{
1627254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1628254721Semaste
1629254721Semaste    bool result = false;
1630254721Semaste    TargetSP target_sp(GetSP());
1631254721Semaste    if (target_sp)
1632254721Semaste    {
1633254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1634254721Semaste        result = target_sp->RemoveBreakpointByID (bp_id);
1635254721Semaste    }
1636254721Semaste
1637254721Semaste    if (log)
1638254721Semaste    {
1639254721Semaste        log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
1640254721Semaste    }
1641254721Semaste
1642254721Semaste    return result;
1643254721Semaste}
1644254721Semaste
1645254721SemasteSBBreakpoint
1646254721SemasteSBTarget::FindBreakpointByID (break_id_t bp_id)
1647254721Semaste{
1648254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1649254721Semaste
1650254721Semaste    SBBreakpoint sb_breakpoint;
1651254721Semaste    TargetSP target_sp(GetSP());
1652254721Semaste    if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
1653254721Semaste    {
1654254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1655254721Semaste        *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
1656254721Semaste    }
1657254721Semaste
1658254721Semaste    if (log)
1659254721Semaste    {
1660254721Semaste        log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1661254721Semaste                     target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
1662254721Semaste    }
1663254721Semaste
1664254721Semaste    return sb_breakpoint;
1665254721Semaste}
1666254721Semaste
1667254721Semastebool
1668254721SemasteSBTarget::EnableAllBreakpoints ()
1669254721Semaste{
1670254721Semaste    TargetSP target_sp(GetSP());
1671254721Semaste    if (target_sp)
1672254721Semaste    {
1673254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1674254721Semaste        target_sp->EnableAllBreakpoints ();
1675254721Semaste        return true;
1676254721Semaste    }
1677254721Semaste    return false;
1678254721Semaste}
1679254721Semaste
1680254721Semastebool
1681254721SemasteSBTarget::DisableAllBreakpoints ()
1682254721Semaste{
1683254721Semaste    TargetSP target_sp(GetSP());
1684254721Semaste    if (target_sp)
1685254721Semaste    {
1686254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1687254721Semaste        target_sp->DisableAllBreakpoints ();
1688254721Semaste        return true;
1689254721Semaste    }
1690254721Semaste    return false;
1691254721Semaste}
1692254721Semaste
1693254721Semastebool
1694254721SemasteSBTarget::DeleteAllBreakpoints ()
1695254721Semaste{
1696254721Semaste    TargetSP target_sp(GetSP());
1697254721Semaste    if (target_sp)
1698254721Semaste    {
1699254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1700254721Semaste        target_sp->RemoveAllBreakpoints ();
1701254721Semaste        return true;
1702254721Semaste    }
1703254721Semaste    return false;
1704254721Semaste}
1705254721Semaste
1706254721Semasteuint32_t
1707254721SemasteSBTarget::GetNumWatchpoints () const
1708254721Semaste{
1709254721Semaste    TargetSP target_sp(GetSP());
1710254721Semaste    if (target_sp)
1711254721Semaste    {
1712254721Semaste        // The watchpoint list is thread safe, no need to lock
1713254721Semaste        return target_sp->GetWatchpointList().GetSize();
1714254721Semaste    }
1715254721Semaste    return 0;
1716254721Semaste}
1717254721Semaste
1718254721SemasteSBWatchpoint
1719254721SemasteSBTarget::GetWatchpointAtIndex (uint32_t idx) const
1720254721Semaste{
1721254721Semaste    SBWatchpoint sb_watchpoint;
1722254721Semaste    TargetSP target_sp(GetSP());
1723254721Semaste    if (target_sp)
1724254721Semaste    {
1725254721Semaste        // The watchpoint list is thread safe, no need to lock
1726254721Semaste        sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
1727254721Semaste    }
1728254721Semaste    return sb_watchpoint;
1729254721Semaste}
1730254721Semaste
1731254721Semastebool
1732254721SemasteSBTarget::DeleteWatchpoint (watch_id_t wp_id)
1733254721Semaste{
1734254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1735254721Semaste
1736254721Semaste    bool result = false;
1737254721Semaste    TargetSP target_sp(GetSP());
1738254721Semaste    if (target_sp)
1739254721Semaste    {
1740254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1741254721Semaste        Mutex::Locker locker;
1742254721Semaste        target_sp->GetWatchpointList().GetListMutex(locker);
1743254721Semaste        result = target_sp->RemoveWatchpointByID (wp_id);
1744254721Semaste    }
1745254721Semaste
1746254721Semaste    if (log)
1747254721Semaste    {
1748254721Semaste        log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
1749254721Semaste    }
1750254721Semaste
1751254721Semaste    return result;
1752254721Semaste}
1753254721Semaste
1754254721SemasteSBWatchpoint
1755254721SemasteSBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
1756254721Semaste{
1757254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1758254721Semaste
1759254721Semaste    SBWatchpoint sb_watchpoint;
1760254721Semaste    lldb::WatchpointSP watchpoint_sp;
1761254721Semaste    TargetSP target_sp(GetSP());
1762254721Semaste    if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
1763254721Semaste    {
1764254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1765254721Semaste        Mutex::Locker locker;
1766254721Semaste        target_sp->GetWatchpointList().GetListMutex(locker);
1767254721Semaste        watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1768254721Semaste        sb_watchpoint.SetSP (watchpoint_sp);
1769254721Semaste    }
1770254721Semaste
1771254721Semaste    if (log)
1772254721Semaste    {
1773254721Semaste        log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1774254721Semaste                     target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
1775254721Semaste    }
1776254721Semaste
1777254721Semaste    return sb_watchpoint;
1778254721Semaste}
1779254721Semaste
1780254721Semastelldb::SBWatchpoint
1781254721SemasteSBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
1782254721Semaste{
1783254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1784254721Semaste
1785254721Semaste    SBWatchpoint sb_watchpoint;
1786254721Semaste    lldb::WatchpointSP watchpoint_sp;
1787254721Semaste    TargetSP target_sp(GetSP());
1788254721Semaste    if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
1789254721Semaste    {
1790254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1791254721Semaste        uint32_t watch_type = 0;
1792254721Semaste        if (read)
1793254721Semaste            watch_type |= LLDB_WATCH_TYPE_READ;
1794254721Semaste        if (write)
1795254721Semaste            watch_type |= LLDB_WATCH_TYPE_WRITE;
1796254721Semaste        if (watch_type == 0)
1797254721Semaste        {
1798254721Semaste            error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1799254721Semaste            return sb_watchpoint;
1800254721Semaste        }
1801254721Semaste
1802254721Semaste        // Target::CreateWatchpoint() is thread safe.
1803254721Semaste        Error cw_error;
1804254721Semaste        // This API doesn't take in a type, so we can't figure out what it is.
1805254721Semaste        ClangASTType *type = NULL;
1806254721Semaste        watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1807254721Semaste        error.SetError(cw_error);
1808254721Semaste        sb_watchpoint.SetSP (watchpoint_sp);
1809254721Semaste    }
1810254721Semaste
1811254721Semaste    if (log)
1812254721Semaste    {
1813254721Semaste        log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
1814254721Semaste                     target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
1815254721Semaste    }
1816254721Semaste
1817254721Semaste    return sb_watchpoint;
1818254721Semaste}
1819254721Semaste
1820254721Semastebool
1821254721SemasteSBTarget::EnableAllWatchpoints ()
1822254721Semaste{
1823254721Semaste    TargetSP target_sp(GetSP());
1824254721Semaste    if (target_sp)
1825254721Semaste    {
1826254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1827254721Semaste        Mutex::Locker locker;
1828254721Semaste        target_sp->GetWatchpointList().GetListMutex(locker);
1829254721Semaste        target_sp->EnableAllWatchpoints ();
1830254721Semaste        return true;
1831254721Semaste    }
1832254721Semaste    return false;
1833254721Semaste}
1834254721Semaste
1835254721Semastebool
1836254721SemasteSBTarget::DisableAllWatchpoints ()
1837254721Semaste{
1838254721Semaste    TargetSP target_sp(GetSP());
1839254721Semaste    if (target_sp)
1840254721Semaste    {
1841254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1842254721Semaste        Mutex::Locker locker;
1843254721Semaste        target_sp->GetWatchpointList().GetListMutex(locker);
1844254721Semaste        target_sp->DisableAllWatchpoints ();
1845254721Semaste        return true;
1846254721Semaste    }
1847254721Semaste    return false;
1848254721Semaste}
1849254721Semaste
1850263363SemasteSBValue
1851263363SemasteSBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1852263363Semaste{
1853263363Semaste    SBValue sb_value;
1854263363Semaste    lldb::ValueObjectSP new_value_sp;
1855263363Semaste    if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1856263363Semaste    {
1857263363Semaste        lldb::addr_t address(addr.GetLoadAddress(*this));
1858263363Semaste        lldb::TypeImplSP type_impl_sp (type.GetSP());
1859263363Semaste        ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
1860263363Semaste        if (pointer_ast_type)
1861263363Semaste        {
1862263363Semaste            lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
1863263363Semaste
1864263363Semaste            ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1865263363Semaste            ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1866263363Semaste                                                                               pointer_ast_type,
1867263363Semaste                                                                               ConstString(name),
1868263363Semaste                                                                               buffer,
1869263363Semaste                                                                               exe_ctx.GetByteOrder(),
1870263363Semaste                                                                               exe_ctx.GetAddressByteSize()));
1871263363Semaste
1872263363Semaste            if (ptr_result_valobj_sp)
1873263363Semaste            {
1874263363Semaste                ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1875263363Semaste                Error err;
1876263363Semaste                new_value_sp = ptr_result_valobj_sp->Dereference(err);
1877263363Semaste                if (new_value_sp)
1878263363Semaste                    new_value_sp->SetName(ConstString(name));
1879263363Semaste            }
1880263363Semaste        }
1881263363Semaste    }
1882263363Semaste    sb_value.SetSP(new_value_sp);
1883263363Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1884263363Semaste    if (log)
1885263363Semaste    {
1886263363Semaste        if (new_value_sp)
1887263363Semaste            log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", m_opaque_sp.get(), new_value_sp->GetName().AsCString());
1888263363Semaste        else
1889263363Semaste            log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", m_opaque_sp.get());
1890263363Semaste    }
1891263363Semaste    return sb_value;
1892263363Semaste}
1893263363Semaste
1894254721Semastebool
1895254721SemasteSBTarget::DeleteAllWatchpoints ()
1896254721Semaste{
1897254721Semaste    TargetSP target_sp(GetSP());
1898254721Semaste    if (target_sp)
1899254721Semaste    {
1900254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
1901254721Semaste        Mutex::Locker locker;
1902254721Semaste        target_sp->GetWatchpointList().GetListMutex(locker);
1903254721Semaste        target_sp->RemoveAllWatchpoints ();
1904254721Semaste        return true;
1905254721Semaste    }
1906254721Semaste    return false;
1907254721Semaste}
1908254721Semaste
1909254721Semaste
1910254721Semastelldb::SBModule
1911254721SemasteSBTarget::AddModule (const char *path,
1912254721Semaste                     const char *triple,
1913254721Semaste                     const char *uuid_cstr)
1914254721Semaste{
1915254721Semaste    return AddModule (path, triple, uuid_cstr, NULL);
1916254721Semaste}
1917254721Semaste
1918254721Semastelldb::SBModule
1919254721SemasteSBTarget::AddModule (const char *path,
1920254721Semaste                     const char *triple,
1921254721Semaste                     const char *uuid_cstr,
1922254721Semaste                     const char *symfile)
1923254721Semaste{
1924254721Semaste    lldb::SBModule sb_module;
1925254721Semaste    TargetSP target_sp(GetSP());
1926254721Semaste    if (target_sp)
1927254721Semaste    {
1928254721Semaste        ModuleSpec module_spec;
1929254721Semaste        if (path)
1930254721Semaste            module_spec.GetFileSpec().SetFile(path, false);
1931254721Semaste
1932254721Semaste        if (uuid_cstr)
1933254721Semaste            module_spec.GetUUID().SetFromCString(uuid_cstr);
1934254721Semaste
1935254721Semaste        if (triple)
1936254721Semaste            module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
1937263363Semaste        else
1938263363Semaste            module_spec.GetArchitecture() = target_sp->GetArchitecture();
1939254721Semaste
1940254721Semaste        if (symfile)
1941254721Semaste            module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
1942254721Semaste
1943254721Semaste        sb_module.SetSP(target_sp->GetSharedModule (module_spec));
1944254721Semaste    }
1945254721Semaste    return sb_module;
1946254721Semaste}
1947254721Semaste
1948254721Semastelldb::SBModule
1949254721SemasteSBTarget::AddModule (const SBModuleSpec &module_spec)
1950254721Semaste{
1951254721Semaste    lldb::SBModule sb_module;
1952254721Semaste    TargetSP target_sp(GetSP());
1953254721Semaste    if (target_sp)
1954254721Semaste        sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1955254721Semaste    return sb_module;
1956254721Semaste}
1957254721Semaste
1958254721Semastebool
1959254721SemasteSBTarget::AddModule (lldb::SBModule &module)
1960254721Semaste{
1961254721Semaste    TargetSP target_sp(GetSP());
1962254721Semaste    if (target_sp)
1963254721Semaste    {
1964254721Semaste        target_sp->GetImages().AppendIfNeeded (module.GetSP());
1965254721Semaste        return true;
1966254721Semaste    }
1967254721Semaste    return false;
1968254721Semaste}
1969254721Semaste
1970254721Semasteuint32_t
1971254721SemasteSBTarget::GetNumModules () const
1972254721Semaste{
1973254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1974254721Semaste
1975254721Semaste    uint32_t num = 0;
1976254721Semaste    TargetSP target_sp(GetSP());
1977254721Semaste    if (target_sp)
1978254721Semaste    {
1979254721Semaste        // The module list is thread safe, no need to lock
1980254721Semaste        num = target_sp->GetImages().GetSize();
1981254721Semaste    }
1982254721Semaste
1983254721Semaste    if (log)
1984254721Semaste        log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
1985254721Semaste
1986254721Semaste    return num;
1987254721Semaste}
1988254721Semaste
1989254721Semastevoid
1990254721SemasteSBTarget::Clear ()
1991254721Semaste{
1992254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1993254721Semaste
1994254721Semaste    if (log)
1995254721Semaste        log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
1996254721Semaste
1997254721Semaste    m_opaque_sp.reset();
1998254721Semaste}
1999254721Semaste
2000254721Semaste
2001254721SemasteSBModule
2002254721SemasteSBTarget::FindModule (const SBFileSpec &sb_file_spec)
2003254721Semaste{
2004254721Semaste    SBModule sb_module;
2005254721Semaste    TargetSP target_sp(GetSP());
2006254721Semaste    if (target_sp && sb_file_spec.IsValid())
2007254721Semaste    {
2008254721Semaste        ModuleSpec module_spec(*sb_file_spec);
2009254721Semaste        // The module list is thread safe, no need to lock
2010254721Semaste        sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
2011254721Semaste    }
2012254721Semaste    return sb_module;
2013254721Semaste}
2014254721Semaste
2015254721Semastelldb::ByteOrder
2016254721SemasteSBTarget::GetByteOrder ()
2017254721Semaste{
2018254721Semaste    TargetSP target_sp(GetSP());
2019254721Semaste    if (target_sp)
2020254721Semaste        return target_sp->GetArchitecture().GetByteOrder();
2021254721Semaste    return eByteOrderInvalid;
2022254721Semaste}
2023254721Semaste
2024254721Semasteconst char *
2025254721SemasteSBTarget::GetTriple ()
2026254721Semaste{
2027254721Semaste    TargetSP target_sp(GetSP());
2028254721Semaste    if (target_sp)
2029254721Semaste    {
2030254721Semaste        std::string triple (target_sp->GetArchitecture().GetTriple().str());
2031254721Semaste        // Unique the string so we don't run into ownership issues since
2032254721Semaste        // the const strings put the string into the string pool once and
2033254721Semaste        // the strings never comes out
2034254721Semaste        ConstString const_triple (triple.c_str());
2035254721Semaste        return const_triple.GetCString();
2036254721Semaste    }
2037254721Semaste    return NULL;
2038254721Semaste}
2039254721Semaste
2040254721Semasteuint32_t
2041254721SemasteSBTarget::GetAddressByteSize()
2042254721Semaste{
2043254721Semaste    TargetSP target_sp(GetSP());
2044254721Semaste    if (target_sp)
2045254721Semaste        return target_sp->GetArchitecture().GetAddressByteSize();
2046254721Semaste    return sizeof(void*);
2047254721Semaste}
2048254721Semaste
2049254721Semaste
2050254721SemasteSBModule
2051254721SemasteSBTarget::GetModuleAtIndex (uint32_t idx)
2052254721Semaste{
2053254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2054254721Semaste
2055254721Semaste    SBModule sb_module;
2056254721Semaste    ModuleSP module_sp;
2057254721Semaste    TargetSP target_sp(GetSP());
2058254721Semaste    if (target_sp)
2059254721Semaste    {
2060254721Semaste        // The module list is thread safe, no need to lock
2061254721Semaste        module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2062254721Semaste        sb_module.SetSP (module_sp);
2063254721Semaste    }
2064254721Semaste
2065254721Semaste    if (log)
2066254721Semaste    {
2067254721Semaste        log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2068254721Semaste                     target_sp.get(), idx, module_sp.get());
2069254721Semaste    }
2070254721Semaste
2071254721Semaste    return sb_module;
2072254721Semaste}
2073254721Semaste
2074254721Semastebool
2075254721SemasteSBTarget::RemoveModule (lldb::SBModule module)
2076254721Semaste{
2077254721Semaste    TargetSP target_sp(GetSP());
2078254721Semaste    if (target_sp)
2079254721Semaste        return target_sp->GetImages().Remove(module.GetSP());
2080254721Semaste    return false;
2081254721Semaste}
2082254721Semaste
2083254721Semaste
2084254721SemasteSBBroadcaster
2085254721SemasteSBTarget::GetBroadcaster () const
2086254721Semaste{
2087254721Semaste    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2088254721Semaste
2089254721Semaste    TargetSP target_sp(GetSP());
2090254721Semaste    SBBroadcaster broadcaster(target_sp.get(), false);
2091254721Semaste
2092254721Semaste    if (log)
2093254721Semaste        log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2094254721Semaste                     target_sp.get(), broadcaster.get());
2095254721Semaste
2096254721Semaste    return broadcaster;
2097254721Semaste}
2098254721Semaste
2099254721Semastebool
2100254721SemasteSBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
2101254721Semaste{
2102254721Semaste    Stream &strm = description.ref();
2103254721Semaste
2104254721Semaste    TargetSP target_sp(GetSP());
2105254721Semaste    if (target_sp)
2106254721Semaste    {
2107254721Semaste        target_sp->Dump (&strm, description_level);
2108254721Semaste    }
2109254721Semaste    else
2110254721Semaste        strm.PutCString ("No value");
2111254721Semaste
2112254721Semaste    return true;
2113254721Semaste}
2114254721Semaste
2115254721Semastelldb::SBSymbolContextList
2116254721SemasteSBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
2117254721Semaste{
2118254721Semaste    lldb::SBSymbolContextList sb_sc_list;
2119254721Semaste    if (name && name[0])
2120254721Semaste    {
2121254721Semaste        TargetSP target_sp(GetSP());
2122254721Semaste        if (target_sp)
2123254721Semaste        {
2124254721Semaste            const bool symbols_ok = true;
2125254721Semaste            const bool inlines_ok = true;
2126254721Semaste            const bool append = true;
2127254721Semaste            target_sp->GetImages().FindFunctions (ConstString(name),
2128254721Semaste                                                  name_type_mask,
2129254721Semaste                                                  symbols_ok,
2130254721Semaste                                                  inlines_ok,
2131254721Semaste                                                  append,
2132254721Semaste                                                  *sb_sc_list);
2133254721Semaste        }
2134254721Semaste    }
2135254721Semaste    return sb_sc_list;
2136254721Semaste}
2137254721Semaste
2138254721Semastelldb::SBType
2139254721SemasteSBTarget::FindFirstType (const char* typename_cstr)
2140254721Semaste{
2141254721Semaste    TargetSP target_sp(GetSP());
2142254721Semaste    if (typename_cstr && typename_cstr[0] && target_sp)
2143254721Semaste    {
2144254721Semaste        ConstString const_typename(typename_cstr);
2145254721Semaste        SymbolContext sc;
2146254721Semaste        const bool exact_match = false;
2147254721Semaste
2148254721Semaste        const ModuleList &module_list = target_sp->GetImages();
2149254721Semaste        size_t count = module_list.GetSize();
2150254721Semaste        for (size_t idx = 0; idx < count; idx++)
2151254721Semaste        {
2152254721Semaste            ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2153254721Semaste            if (module_sp)
2154254721Semaste            {
2155254721Semaste                TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2156254721Semaste                if (type_sp)
2157254721Semaste                    return SBType(type_sp);
2158254721Semaste            }
2159254721Semaste        }
2160254721Semaste
2161254721Semaste        // Didn't find the type in the symbols; try the Objective-C runtime
2162254721Semaste        // if one is installed
2163254721Semaste
2164254721Semaste        ProcessSP process_sp(target_sp->GetProcessSP());
2165254721Semaste
2166254721Semaste        if (process_sp)
2167254721Semaste        {
2168254721Semaste            ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2169254721Semaste
2170254721Semaste            if (objc_language_runtime)
2171254721Semaste            {
2172254721Semaste                TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2173254721Semaste
2174254721Semaste                if (objc_type_vendor)
2175254721Semaste                {
2176254721Semaste                    std::vector <ClangASTType> types;
2177254721Semaste
2178254721Semaste                    if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2179254721Semaste                        return SBType(types[0]);
2180254721Semaste                }
2181254721Semaste            }
2182254721Semaste        }
2183254721Semaste
2184254721Semaste        // No matches, search for basic typename matches
2185254721Semaste        ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2186254721Semaste        if (clang_ast)
2187254721Semaste            return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
2188254721Semaste    }
2189254721Semaste    return SBType();
2190254721Semaste}
2191254721Semaste
2192254721SemasteSBType
2193254721SemasteSBTarget::GetBasicType(lldb::BasicType type)
2194254721Semaste{
2195254721Semaste    TargetSP target_sp(GetSP());
2196254721Semaste    if (target_sp)
2197254721Semaste    {
2198254721Semaste        ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2199254721Semaste        if (clang_ast)
2200254721Semaste            return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
2201254721Semaste    }
2202254721Semaste    return SBType();
2203254721Semaste}
2204254721Semaste
2205254721Semaste
2206254721Semastelldb::SBTypeList
2207254721SemasteSBTarget::FindTypes (const char* typename_cstr)
2208254721Semaste{
2209254721Semaste    SBTypeList sb_type_list;
2210254721Semaste    TargetSP target_sp(GetSP());
2211254721Semaste    if (typename_cstr && typename_cstr[0] && target_sp)
2212254721Semaste    {
2213254721Semaste        ModuleList& images = target_sp->GetImages();
2214254721Semaste        ConstString const_typename(typename_cstr);
2215254721Semaste        bool exact_match = false;
2216254721Semaste        SymbolContext sc;
2217254721Semaste        TypeList type_list;
2218254721Semaste
2219254721Semaste        uint32_t num_matches = images.FindTypes (sc,
2220254721Semaste                                                 const_typename,
2221254721Semaste                                                 exact_match,
2222254721Semaste                                                 UINT32_MAX,
2223254721Semaste                                                 type_list);
2224254721Semaste
2225254721Semaste        if (num_matches > 0)
2226254721Semaste        {
2227254721Semaste            for (size_t idx = 0; idx < num_matches; idx++)
2228254721Semaste            {
2229254721Semaste                TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2230254721Semaste                if (type_sp)
2231254721Semaste                    sb_type_list.Append(SBType(type_sp));
2232254721Semaste            }
2233254721Semaste        }
2234254721Semaste
2235254721Semaste        // Try the Objective-C runtime if one is installed
2236254721Semaste
2237254721Semaste        ProcessSP process_sp(target_sp->GetProcessSP());
2238254721Semaste
2239254721Semaste        if (process_sp)
2240254721Semaste        {
2241254721Semaste            ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2242254721Semaste
2243254721Semaste            if (objc_language_runtime)
2244254721Semaste            {
2245254721Semaste                TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2246254721Semaste
2247254721Semaste                if (objc_type_vendor)
2248254721Semaste                {
2249254721Semaste                    std::vector <ClangASTType> types;
2250254721Semaste
2251254721Semaste                    if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2252254721Semaste                    {
2253254721Semaste                        for (ClangASTType &type : types)
2254254721Semaste                        {
2255254721Semaste                            sb_type_list.Append(SBType(type));
2256254721Semaste                        }
2257254721Semaste                    }
2258254721Semaste                }
2259254721Semaste            }
2260254721Semaste        }
2261254721Semaste
2262254721Semaste        if (sb_type_list.GetSize() == 0)
2263254721Semaste        {
2264254721Semaste            // No matches, search for basic typename matches
2265254721Semaste            ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2266254721Semaste            if (clang_ast)
2267254721Semaste                sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
2268254721Semaste        }
2269254721Semaste    }
2270254721Semaste    return sb_type_list;
2271254721Semaste}
2272254721Semaste
2273254721SemasteSBValueList
2274254721SemasteSBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2275254721Semaste{
2276254721Semaste    SBValueList sb_value_list;
2277254721Semaste
2278254721Semaste    TargetSP target_sp(GetSP());
2279254721Semaste    if (name && target_sp)
2280254721Semaste    {
2281254721Semaste        VariableList variable_list;
2282254721Semaste        const bool append = true;
2283254721Semaste        const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2284254721Semaste                                                                                 append,
2285254721Semaste                                                                                 max_matches,
2286254721Semaste                                                                                 variable_list);
2287254721Semaste
2288254721Semaste        if (match_count > 0)
2289254721Semaste        {
2290254721Semaste            ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2291254721Semaste            if (exe_scope == NULL)
2292254721Semaste                exe_scope = target_sp.get();
2293254721Semaste            for (uint32_t i=0; i<match_count; ++i)
2294254721Semaste            {
2295254721Semaste                lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2296254721Semaste                if (valobj_sp)
2297254721Semaste                    sb_value_list.Append(SBValue(valobj_sp));
2298254721Semaste            }
2299254721Semaste        }
2300254721Semaste    }
2301254721Semaste
2302254721Semaste    return sb_value_list;
2303254721Semaste}
2304254721Semaste
2305254721Semastelldb::SBValue
2306254721SemasteSBTarget::FindFirstGlobalVariable (const char* name)
2307254721Semaste{
2308254721Semaste    SBValueList sb_value_list(FindGlobalVariables(name, 1));
2309254721Semaste    if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2310254721Semaste        return sb_value_list.GetValueAtIndex(0);
2311254721Semaste    return SBValue();
2312254721Semaste}
2313254721Semaste
2314254721SemasteSBSourceManager
2315254721SemasteSBTarget::GetSourceManager()
2316254721Semaste{
2317254721Semaste    SBSourceManager source_manager (*this);
2318254721Semaste    return source_manager;
2319254721Semaste}
2320254721Semaste
2321254721Semastelldb::SBInstructionList
2322254721SemasteSBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2323254721Semaste{
2324254721Semaste    return ReadInstructions (base_addr, count, NULL);
2325254721Semaste}
2326254721Semaste
2327254721Semastelldb::SBInstructionList
2328254721SemasteSBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2329254721Semaste{
2330254721Semaste    SBInstructionList sb_instructions;
2331254721Semaste
2332254721Semaste    TargetSP target_sp(GetSP());
2333254721Semaste    if (target_sp)
2334254721Semaste    {
2335254721Semaste        Address *addr_ptr = base_addr.get();
2336254721Semaste
2337254721Semaste        if (addr_ptr)
2338254721Semaste        {
2339254721Semaste            DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2340254721Semaste            bool prefer_file_cache = false;
2341254721Semaste            lldb_private::Error error;
2342254721Semaste            lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2343254721Semaste            const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2344254721Semaste                                                            prefer_file_cache,
2345254721Semaste                                                            data.GetBytes(),
2346254721Semaste                                                            data.GetByteSize(),
2347254721Semaste                                                            error,
2348254721Semaste                                                            &load_addr);
2349254721Semaste            const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2350254721Semaste            sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2351254721Semaste                                                                             NULL,
2352254721Semaste                                                                             flavor_string,
2353254721Semaste                                                                             *addr_ptr,
2354254721Semaste                                                                             data.GetBytes(),
2355254721Semaste                                                                             bytes_read,
2356254721Semaste                                                                             count,
2357254721Semaste                                                                             data_from_file));
2358254721Semaste        }
2359254721Semaste    }
2360254721Semaste
2361254721Semaste    return sb_instructions;
2362254721Semaste
2363254721Semaste}
2364254721Semaste
2365254721Semastelldb::SBInstructionList
2366254721SemasteSBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2367254721Semaste{
2368254721Semaste    return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2369254721Semaste}
2370254721Semaste
2371254721Semastelldb::SBInstructionList
2372254721SemasteSBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2373254721Semaste{
2374254721Semaste    SBInstructionList sb_instructions;
2375254721Semaste
2376254721Semaste    TargetSP target_sp(GetSP());
2377254721Semaste    if (target_sp)
2378254721Semaste    {
2379254721Semaste        Address addr;
2380254721Semaste
2381254721Semaste        if (base_addr.get())
2382254721Semaste            addr = *base_addr.get();
2383254721Semaste
2384254721Semaste        const bool data_from_file = true;
2385254721Semaste
2386254721Semaste        sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2387254721Semaste                                                                         NULL,
2388254721Semaste                                                                         flavor_string,
2389254721Semaste                                                                         addr,
2390254721Semaste                                                                         buf,
2391254721Semaste                                                                         size,
2392254721Semaste                                                                         UINT32_MAX,
2393254721Semaste                                                                         data_from_file));
2394254721Semaste    }
2395254721Semaste
2396254721Semaste    return sb_instructions;
2397254721Semaste}
2398254721Semaste
2399254721Semastelldb::SBInstructionList
2400254721SemasteSBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2401254721Semaste{
2402254721Semaste    return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2403254721Semaste}
2404254721Semaste
2405254721Semastelldb::SBInstructionList
2406254721SemasteSBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2407254721Semaste{
2408254721Semaste    return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
2409254721Semaste}
2410254721Semaste
2411254721SemasteSBError
2412254721SemasteSBTarget::SetSectionLoadAddress (lldb::SBSection section,
2413254721Semaste                                 lldb::addr_t section_base_addr)
2414254721Semaste{
2415254721Semaste    SBError sb_error;
2416254721Semaste    TargetSP target_sp(GetSP());
2417254721Semaste    if (target_sp)
2418254721Semaste    {
2419254721Semaste        if (!section.IsValid())
2420254721Semaste        {
2421254721Semaste            sb_error.SetErrorStringWithFormat ("invalid section");
2422254721Semaste        }
2423254721Semaste        else
2424254721Semaste        {
2425254721Semaste            SectionSP section_sp (section.GetSP());
2426254721Semaste            if (section_sp)
2427254721Semaste            {
2428254721Semaste                if (section_sp->IsThreadSpecific())
2429254721Semaste                {
2430254721Semaste                    sb_error.SetErrorString ("thread specific sections are not yet supported");
2431254721Semaste                }
2432254721Semaste                else
2433254721Semaste                {
2434269024Semaste                    ProcessSP process_sp (target_sp->GetProcessSP());
2435269024Semaste                    uint32_t stop_id = 0;
2436269024Semaste                    if (process_sp)
2437269024Semaste                        stop_id = process_sp->GetStopID();
2438269024Semaste
2439269024Semaste                    if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
2440254721Semaste                    {
2441254721Semaste                        // Flush info in the process (stack frames, etc)
2442254721Semaste                        if (process_sp)
2443254721Semaste                            process_sp->Flush();
2444254721Semaste                    }
2445254721Semaste                }
2446254721Semaste            }
2447254721Semaste        }
2448254721Semaste    }
2449254721Semaste    else
2450254721Semaste    {
2451254721Semaste        sb_error.SetErrorString ("invalid target");
2452254721Semaste    }
2453254721Semaste    return sb_error;
2454254721Semaste}
2455254721Semaste
2456254721SemasteSBError
2457254721SemasteSBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2458254721Semaste{
2459254721Semaste    SBError sb_error;
2460254721Semaste
2461254721Semaste    TargetSP target_sp(GetSP());
2462254721Semaste    if (target_sp)
2463254721Semaste    {
2464254721Semaste        if (!section.IsValid())
2465254721Semaste        {
2466254721Semaste            sb_error.SetErrorStringWithFormat ("invalid section");
2467254721Semaste        }
2468254721Semaste        else
2469254721Semaste        {
2470269024Semaste            ProcessSP process_sp (target_sp->GetProcessSP());
2471269024Semaste            uint32_t stop_id = 0;
2472269024Semaste            if (process_sp)
2473269024Semaste                stop_id = process_sp->GetStopID();
2474269024Semaste
2475269024Semaste            if (target_sp->SetSectionUnloaded (section.GetSP()))
2476254721Semaste            {
2477254721Semaste                // Flush info in the process (stack frames, etc)
2478254721Semaste                if (process_sp)
2479254721Semaste                    process_sp->Flush();
2480254721Semaste            }
2481254721Semaste        }
2482254721Semaste    }
2483254721Semaste    else
2484254721Semaste    {
2485254721Semaste        sb_error.SetErrorStringWithFormat ("invalid target");
2486254721Semaste    }
2487254721Semaste    return sb_error;
2488254721Semaste}
2489254721Semaste
2490254721SemasteSBError
2491254721SemasteSBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2492254721Semaste{
2493254721Semaste    SBError sb_error;
2494254721Semaste
2495254721Semaste    TargetSP target_sp(GetSP());
2496254721Semaste    if (target_sp)
2497254721Semaste    {
2498254721Semaste        ModuleSP module_sp (module.GetSP());
2499254721Semaste        if (module_sp)
2500254721Semaste        {
2501254721Semaste            bool changed = false;
2502269024Semaste            if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
2503254721Semaste            {
2504254721Semaste                // The load was successful, make sure that at least some sections
2505254721Semaste                // changed before we notify that our module was loaded.
2506254721Semaste                if (changed)
2507254721Semaste                {
2508254721Semaste                    ModuleList module_list;
2509254721Semaste                    module_list.Append(module_sp);
2510254721Semaste                    target_sp->ModulesDidLoad (module_list);
2511254721Semaste                    // Flush info in the process (stack frames, etc)
2512254721Semaste                    ProcessSP process_sp (target_sp->GetProcessSP());
2513254721Semaste                    if (process_sp)
2514254721Semaste                        process_sp->Flush();
2515254721Semaste                }
2516254721Semaste            }
2517254721Semaste        }
2518254721Semaste        else
2519254721Semaste        {
2520254721Semaste            sb_error.SetErrorStringWithFormat ("invalid module");
2521254721Semaste        }
2522254721Semaste
2523254721Semaste    }
2524254721Semaste    else
2525254721Semaste    {
2526254721Semaste        sb_error.SetErrorStringWithFormat ("invalid target");
2527254721Semaste    }
2528254721Semaste    return sb_error;
2529254721Semaste}
2530254721Semaste
2531254721SemasteSBError
2532254721SemasteSBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2533254721Semaste{
2534254721Semaste    SBError sb_error;
2535254721Semaste
2536254721Semaste    char path[PATH_MAX];
2537254721Semaste    TargetSP target_sp(GetSP());
2538254721Semaste    if (target_sp)
2539254721Semaste    {
2540254721Semaste        ModuleSP module_sp (module.GetSP());
2541254721Semaste        if (module_sp)
2542254721Semaste        {
2543254721Semaste            ObjectFile *objfile = module_sp->GetObjectFile();
2544254721Semaste            if (objfile)
2545254721Semaste            {
2546254721Semaste                SectionList *section_list = objfile->GetSectionList();
2547254721Semaste                if (section_list)
2548254721Semaste                {
2549269024Semaste                    ProcessSP process_sp (target_sp->GetProcessSP());
2550269024Semaste                    uint32_t stop_id = 0;
2551269024Semaste                    if (process_sp)
2552269024Semaste                        stop_id = process_sp->GetStopID();
2553269024Semaste
2554254721Semaste                    bool changed = false;
2555254721Semaste                    const size_t num_sections = section_list->GetSize();
2556254721Semaste                    for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2557254721Semaste                    {
2558254721Semaste                        SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2559254721Semaste                        if (section_sp)
2560269024Semaste                            changed |= target_sp->SetSectionUnloaded (section_sp) > 0;
2561254721Semaste                    }
2562254721Semaste                    if (changed)
2563254721Semaste                    {
2564254721Semaste                        // Flush info in the process (stack frames, etc)
2565254721Semaste                        ProcessSP process_sp (target_sp->GetProcessSP());
2566254721Semaste                        if (process_sp)
2567254721Semaste                            process_sp->Flush();
2568254721Semaste                    }
2569254721Semaste                }
2570254721Semaste                else
2571254721Semaste                {
2572254721Semaste                    module_sp->GetFileSpec().GetPath (path, sizeof(path));
2573254721Semaste                    sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2574254721Semaste                }
2575254721Semaste            }
2576254721Semaste            else
2577254721Semaste            {
2578254721Semaste                module_sp->GetFileSpec().GetPath (path, sizeof(path));
2579254721Semaste                sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2580254721Semaste            }
2581254721Semaste        }
2582254721Semaste        else
2583254721Semaste        {
2584254721Semaste            sb_error.SetErrorStringWithFormat ("invalid module");
2585254721Semaste        }
2586254721Semaste    }
2587254721Semaste    else
2588254721Semaste    {
2589254721Semaste        sb_error.SetErrorStringWithFormat ("invalid target");
2590254721Semaste    }
2591254721Semaste    return sb_error;
2592254721Semaste}
2593254721Semaste
2594254721Semaste
2595254721Semastelldb::SBSymbolContextList
2596254721SemasteSBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2597254721Semaste{
2598254721Semaste    SBSymbolContextList sb_sc_list;
2599254721Semaste    if (name && name[0])
2600254721Semaste    {
2601254721Semaste        TargetSP target_sp(GetSP());
2602254721Semaste        if (target_sp)
2603254721Semaste        {
2604254721Semaste            bool append = true;
2605254721Semaste            target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2606254721Semaste                                                               symbol_type,
2607254721Semaste                                                               *sb_sc_list,
2608254721Semaste                                                               append);
2609254721Semaste        }
2610254721Semaste    }
2611254721Semaste    return sb_sc_list;
2612254721Semaste
2613254721Semaste}
2614254721Semaste
2615254721Semaste
2616254721Semastelldb::SBValue
2617254721SemasteSBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2618254721Semaste{
2619254721Semaste    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2620254721Semaste    Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2621254721Semaste    SBValue expr_result;
2622254721Semaste    ExecutionResults exe_results = eExecutionSetupError;
2623254721Semaste    ValueObjectSP expr_value_sp;
2624254721Semaste    TargetSP target_sp(GetSP());
2625254721Semaste    StackFrame *frame = NULL;
2626254721Semaste    if (target_sp)
2627254721Semaste    {
2628254721Semaste        if (expr == NULL || expr[0] == '\0')
2629254721Semaste        {
2630254721Semaste            if (log)
2631254721Semaste                log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2632254721Semaste            return expr_result;
2633254721Semaste        }
2634254721Semaste
2635254721Semaste        Mutex::Locker api_locker (target_sp->GetAPIMutex());
2636254721Semaste        ExecutionContext exe_ctx (m_opaque_sp.get());
2637254721Semaste
2638254721Semaste        if (log)
2639254721Semaste            log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2640254721Semaste
2641254721Semaste        frame = exe_ctx.GetFramePtr();
2642254721Semaste        Target *target = exe_ctx.GetTargetPtr();
2643254721Semaste
2644254721Semaste        if (target)
2645254721Semaste        {
2646254721Semaste#ifdef LLDB_CONFIGURATION_DEBUG
2647254721Semaste            StreamString frame_description;
2648254721Semaste            if (frame)
2649254721Semaste                frame->DumpUsingSettingsFormat (&frame_description);
2650254721Semaste            Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2651254721Semaste                                                 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2652254721Semaste#endif
2653254721Semaste            exe_results = target->EvaluateExpression (expr,
2654254721Semaste                                                      frame,
2655254721Semaste                                                      expr_value_sp,
2656254721Semaste                                                      options.ref());
2657254721Semaste
2658254721Semaste            expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2659254721Semaste#ifdef LLDB_CONFIGURATION_DEBUG
2660254721Semaste            Host::SetCrashDescription (NULL);
2661254721Semaste#endif
2662254721Semaste        }
2663254721Semaste        else
2664254721Semaste        {
2665254721Semaste            if (log)
2666254721Semaste                log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2667254721Semaste        }
2668254721Semaste    }
2669254721Semaste#ifndef LLDB_DISABLE_PYTHON
2670254721Semaste    if (expr_log)
2671254721Semaste        expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
2672254721Semaste                         expr_result.GetValue(),
2673254721Semaste                         expr_result.GetSummary());
2674254721Semaste
2675254721Semaste    if (log)
2676254721Semaste        log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
2677254721Semaste                     frame,
2678254721Semaste                     expr,
2679254721Semaste                     expr_value_sp.get(),
2680254721Semaste                     exe_results);
2681254721Semaste#endif
2682254721Semaste
2683254721Semaste    return expr_result;
2684254721Semaste}
2685254721Semaste
2686254721Semaste
2687254721Semastelldb::addr_t
2688254721SemasteSBTarget::GetStackRedZoneSize()
2689254721Semaste{
2690254721Semaste    TargetSP target_sp(GetSP());
2691254721Semaste    if (target_sp)
2692254721Semaste    {
2693254721Semaste        ABISP abi_sp;
2694254721Semaste        ProcessSP process_sp (target_sp->GetProcessSP());
2695254721Semaste        if (process_sp)
2696254721Semaste            abi_sp = process_sp->GetABI();
2697254721Semaste        else
2698254721Semaste            abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2699254721Semaste        if (abi_sp)
2700254721Semaste            return abi_sp->GetRedZoneSize();
2701254721Semaste    }
2702254721Semaste    return 0;
2703254721Semaste}
2704254721Semaste
2705