blob: a3d4ccc09317e117e764adec555fd5bd19ca6270 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBTarget.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
Greg Claytone0d378b2011-03-24 21:19:54 +000012#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytondea8cb42011-06-29 22:09:02 +000014#include "lldb/API/SBBreakpoint.h"
Ilia Keb2c19a2015-03-10 21:59:55 +000015#include "lldb/API/SBDebugger.h"
16#include "lldb/API/SBEvent.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000017#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000019#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000021#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000022#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000023#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000024#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000025#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Breakpoint/BreakpointID.h"
27#include "lldb/Breakpoint/BreakpointIDList.h"
28#include "lldb/Breakpoint/BreakpointList.h"
29#include "lldb/Breakpoint/BreakpointLocation.h"
30#include "lldb/Core/Address.h"
31#include "lldb/Core/AddressResolver.h"
32#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/ArchSpec.h"
34#include "lldb/Core/Debugger.h"
35#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000036#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000037#include "lldb/Core/Module.h"
38#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Core/RegularExpression.h"
40#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000041#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000043#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000044#include "lldb/Core/ValueObjectList.h"
45#include "lldb/Core/ValueObjectVariable.h"
46#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000047#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000048#include "lldb/Interpreter/Args.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000049#include "lldb/Symbol/ClangASTContext.h"
50#include "lldb/Symbol/DeclVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000051#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000052#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000053#include "lldb/Symbol/VariableList.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000054#include "lldb/Target/ABI.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000055#include "lldb/Target/Language.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000056#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000057#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058#include "lldb/Target/Process.h"
Enrico Granatab10e0032015-03-04 21:33:45 +000059#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Target.h"
61#include "lldb/Target/TargetList.h"
62
63#include "lldb/Interpreter/CommandReturnObject.h"
64#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000065#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
68using namespace lldb;
69using namespace lldb_private;
70
71#define DEFAULT_DISASM_BYTE_SIZE 32
72
Oleksiy Vyalov37386142015-02-10 22:49:57 +000073namespace {
74
75Error
76AttachToProcess (ProcessAttachInfo &attach_info, Target &target)
77{
78 Mutex::Locker api_locker (target.GetAPIMutex ());
79
80 auto process_sp = target.GetProcessSP ();
81 if (process_sp)
82 {
83 const auto state = process_sp->GetState ();
84 if (process_sp->IsAlive () && state == eStateConnected)
85 {
86 // If we are already connected, then we have already specified the
87 // listener, so if a valid listener is supplied, we need to error out
88 // to let the client know.
89 if (attach_info.GetListener ())
90 return Error ("process is connected and already has a listener, pass empty listener");
91 }
92 }
93
94 return target.Attach (attach_info, nullptr);
95}
96
97} // namespace
98
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099//----------------------------------------------------------------------
100// SBTarget constructor
101//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000102SBTarget::SBTarget () :
103 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104{
105}
106
107SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000108 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109{
110}
111
112SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000113 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114{
115}
116
Greg Claytonefabb122010-11-05 23:17:00 +0000117const SBTarget&
118SBTarget::operator = (const SBTarget& rhs)
119{
120 if (this != &rhs)
121 m_opaque_sp = rhs.m_opaque_sp;
122 return *this;
123}
124
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125//----------------------------------------------------------------------
126// Destructor
127//----------------------------------------------------------------------
128SBTarget::~SBTarget()
129{
130}
131
Ilia Keb2c19a2015-03-10 21:59:55 +0000132bool
133SBTarget::EventIsTargetEvent (const SBEvent &event)
134{
135 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
136}
137
138SBTarget
139SBTarget::GetTargetFromEvent (const SBEvent &event)
140{
141 return Target::TargetEventData::GetTargetFromEvent (event.get());
142}
143
144uint32_t
145SBTarget::GetNumModulesFromEvent (const SBEvent &event)
146{
147 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
148 return module_list.GetSize();
149}
150
151SBModule
152SBTarget::GetModuleAtIndexFromEvent (const uint32_t idx, const SBEvent &event)
153{
154 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
155 return SBModule(module_list.GetModuleAtIndex(idx));
156}
157
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000158const char *
159SBTarget::GetBroadcasterClassName ()
160{
161 return Target::GetStaticBroadcasterClass().AsCString();
162}
163
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164bool
165SBTarget::IsValid () const
166{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000167 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168}
169
170SBProcess
171SBTarget::GetProcess ()
172{
173 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000174 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000175 TargetSP target_sp(GetSP());
176 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000177 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000178 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000179 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000180 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000181
Greg Clayton5160ce52013-03-27 23:08:40 +0000182 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000183 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000184 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
185 static_cast<void*>(target_sp.get()),
186 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000187
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188 return sb_process;
189}
190
Matthew Gardinerc928de32014-10-22 07:22:56 +0000191SBPlatform
192SBTarget::GetPlatform ()
193{
194 TargetSP target_sp(GetSP());
195 if (!target_sp)
196 return SBPlatform();
197
198 SBPlatform platform;
199 platform.m_opaque_sp = target_sp->GetPlatform();
200
201 return platform;
202}
203
Greg Clayton66111032010-06-23 01:19:29 +0000204SBDebugger
205SBTarget::GetDebugger () const
206{
207 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000208 TargetSP target_sp(GetSP());
209 if (target_sp)
210 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000211 return debugger;
212}
213
Jim Ingham270684d2011-03-31 00:01:24 +0000214SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000215SBTarget::LoadCore (const char *core_file)
216{
217 SBProcess sb_process;
218 TargetSP target_sp(GetSP());
219 if (target_sp)
220 {
221 FileSpec filespec(core_file, true);
222 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
223 NULL,
224 &filespec));
225 if (process_sp)
226 {
227 process_sp->LoadCore();
228 sb_process.SetSP (process_sp);
229 }
230 }
231 return sb_process;
232}
233
234SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000235SBTarget::LaunchSimple
236(
237 char const **argv,
238 char const **envp,
239 const char *working_directory
240)
241{
242 char *stdin_path = NULL;
243 char *stdout_path = NULL;
244 char *stderr_path = NULL;
245 uint32_t launch_flags = 0;
246 bool stop_at_entry = false;
247 SBError error;
248 SBListener listener = GetDebugger().GetListener();
249 return Launch (listener,
250 argv,
251 envp,
252 stdin_path,
253 stdout_path,
254 stderr_path,
255 working_directory,
256 launch_flags,
257 stop_at_entry,
258 error);
259}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000260
Greg Claytonfbb76342013-11-20 21:07:01 +0000261SBError
262SBTarget::Install()
263{
264 SBError sb_error;
265 TargetSP target_sp(GetSP());
266 if (target_sp)
267 {
268 Mutex::Locker api_locker (target_sp->GetAPIMutex());
269 sb_error.ref() = target_sp->Install(NULL);
270 }
271 return sb_error;
272}
273
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000274SBProcess
275SBTarget::Launch
276(
Greg Clayton4b045622011-02-03 21:28:34 +0000277 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000278 char const **argv,
279 char const **envp,
280 const char *stdin_path,
281 const char *stdout_path,
282 const char *stderr_path,
283 const char *working_directory,
284 uint32_t launch_flags, // See LaunchFlags
285 bool stop_at_entry,
286 lldb::SBError& error
287)
288{
Greg Clayton5160ce52013-03-27 23:08:40 +0000289 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000290
Greg Claytonacdbe812012-01-30 09:04:36 +0000291 SBProcess sb_process;
292 ProcessSP process_sp;
293 TargetSP target_sp(GetSP());
294
Caroline Ticeceb6b132010-10-26 03:11:13 +0000295 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000296 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000297 static_cast<void*>(target_sp.get()),
298 static_cast<void*>(argv), static_cast<void*>(envp),
299 stdin_path ? stdin_path : "NULL",
300 stdout_path ? stdout_path : "NULL",
301 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000302 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000303 launch_flags, stop_at_entry,
304 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000305
306 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000308 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000309
Zachary Turner6fd3f342015-02-02 18:50:01 +0000310 if (stop_at_entry)
311 launch_flags |= eLaunchFlagStopAtEntry;
312
Greg Clayton645bf542011-01-27 01:01:10 +0000313 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
314 launch_flags |= eLaunchFlagDisableASLR;
315
Greg Clayton2289fa42011-04-30 01:09:13 +0000316 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000317 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000318 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000319 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000320 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000321
Greg Claytonb9556ac2012-01-30 07:41:31 +0000322 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000323 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000324 if (state == eStateAttaching)
325 error.SetErrorString ("process attach is in progress");
326 else
327 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000328 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000329 }
Greg Clayton931180e2011-01-27 06:44:37 +0000330 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000331
Greg Clayton2289fa42011-04-30 01:09:13 +0000332 if (state == eStateConnected)
333 {
334 // If we are already connected, then we have already specified the
335 // listener, so if a valid listener is supplied, we need to error out
336 // to let the client know.
337 if (listener.IsValid())
338 {
339 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000340 return sb_process;
341 }
342 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000343
344 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
345 launch_flags |= eLaunchFlagDisableSTDIO;
346
Chaoren Lind3173f32015-05-29 19:52:29 +0000347 ProcessLaunchInfo launch_info(FileSpec{stdin_path, false},
348 FileSpec{stdout_path, false},
349 FileSpec{stderr_path, false},
350 FileSpec{working_directory, false},
351 launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000352
Greg Claytonb09c5382013-12-13 17:20:18 +0000353 Module *exe_module = target_sp->GetExecutableModulePointer();
354 if (exe_module)
355 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
356 if (argv)
357 launch_info.GetArguments().AppendArguments (argv);
358 if (envp)
359 launch_info.GetEnvironmentEntries ().SetArguments (envp);
360
361 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000362 launch_info.SetListener(listener.GetSP());
363
364 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000365
Greg Claytonb09c5382013-12-13 17:20:18 +0000366 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000367 }
368 else
369 {
370 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000372
Caroline Tice20ad3c42010-10-29 21:48:37 +0000373 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000374 if (log)
Pavel Labathd2474ff2016-02-02 15:16:20 +0000375 log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p), SBError(%s)", static_cast<void *>(target_sp.get()),
376 static_cast<void *>(sb_process.GetSP().get()), error.GetCString());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000377
Greg Clayton5d5028b2010-10-06 03:53:16 +0000378 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379}
380
Greg Clayton0e615682012-02-24 05:03:03 +0000381SBProcess
382SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
383{
Greg Clayton5160ce52013-03-27 23:08:40 +0000384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000385
Greg Clayton0e615682012-02-24 05:03:03 +0000386 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000387 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000388
Greg Clayton0e615682012-02-24 05:03:03 +0000389 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000390 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
391 static_cast<void*>(target_sp.get()));
392
Greg Clayton0e615682012-02-24 05:03:03 +0000393 if (target_sp)
394 {
395 Mutex::Locker api_locker (target_sp->GetAPIMutex());
396 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000397 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000398 ProcessSP process_sp = target_sp->GetProcessSP();
399 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000400 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000401 state = process_sp->GetState();
402
403 if (process_sp->IsAlive() && state != eStateConnected)
404 {
405 if (state == eStateAttaching)
406 error.SetErrorString ("process attach is in progress");
407 else
408 error.SetErrorString ("a process is already being debugged");
409 return sb_process;
410 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000411 }
Greg Clayton0e615682012-02-24 05:03:03 +0000412 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000413
414 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
415
Greg Clayton3e32ad62014-05-07 20:16:06 +0000416 if (!launch_info.GetExecutableFile())
417 {
418 Module *exe_module = target_sp->GetExecutableModulePointer();
419 if (exe_module)
420 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
421 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000422
423 const ArchSpec &arch_spec = target_sp->GetArchitecture();
424 if (arch_spec.IsValid())
425 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000426
Greg Clayton8012cad2014-11-17 19:39:20 +0000427 error.SetError (target_sp->Launch (launch_info, NULL));
Greg Claytonb09c5382013-12-13 17:20:18 +0000428 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000429 }
430 else
431 {
432 error.SetErrorString ("SBTarget is invalid");
433 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000434
Greg Clayton0e615682012-02-24 05:03:03 +0000435 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
436 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000437 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000438 static_cast<void*>(target_sp.get()),
439 static_cast<void*>(sb_process.GetSP().get()));
440
Greg Clayton0e615682012-02-24 05:03:03 +0000441 return sb_process;
442}
443
444lldb::SBProcess
445SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
446{
Greg Clayton5160ce52013-03-27 23:08:40 +0000447 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000448
Greg Clayton0e615682012-02-24 05:03:03 +0000449 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000450 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000451
Sean Callanan575a4542012-10-20 00:21:31 +0000452 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000453 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
454 static_cast<void*>(target_sp.get()));
455
Greg Clayton0e615682012-02-24 05:03:03 +0000456 if (target_sp)
457 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000458 ProcessAttachInfo &attach_info = sb_attach_info.ref();
459 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Greg Clayton0e615682012-02-24 05:03:03 +0000460 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000461 PlatformSP platform_sp = target_sp->GetPlatform();
462 // See if we can pre-verify if a process exists or not
463 if (platform_sp && platform_sp->IsConnected())
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000464 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000465 lldb::pid_t attach_pid = attach_info.GetProcessID();
466 ProcessInstanceInfo instance_info;
467 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
Han Ming Ongcec8c902012-02-29 00:12:56 +0000468 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000469 attach_info.SetUserID(instance_info.GetEffectiveUserID());
470 }
471 else
472 {
473 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
474 if (log)
Greg Clayton91e407e2012-09-27 00:03:39 +0000475 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000476 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
477 static_cast<void*>(target_sp.get()), error.GetCString());
Greg Clayton91e407e2012-09-27 00:03:39 +0000478 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000479 return sb_process;
Han Ming Ongcec8c902012-02-29 00:12:56 +0000480 }
481 }
Greg Clayton0e615682012-02-24 05:03:03 +0000482 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000483 error.SetError(AttachToProcess(attach_info, *target_sp));
484 if (error.Success())
485 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000486 }
487 else
488 {
489 error.SetErrorString ("SBTarget is invalid");
490 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000491
Sean Callanan575a4542012-10-20 00:21:31 +0000492 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000493 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000494 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000495 static_cast<void*>(sb_process.GetSP().get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000496
Greg Clayton0e615682012-02-24 05:03:03 +0000497 return sb_process;
498}
499
500
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000501#if defined(__APPLE__)
502
503lldb::SBProcess
504SBTarget::AttachToProcessWithID (SBListener &listener,
505 ::pid_t pid,
506 lldb::SBError& error)
507{
508 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
509}
510
511#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000512
513lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000514SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000515(
Greg Clayton4b045622011-02-03 21:28:34 +0000516 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000517 lldb::pid_t pid,// The process ID to attach to
518 SBError& error // An error explaining what went wrong if attach fails
519)
520{
Greg Clayton5160ce52013-03-27 23:08:40 +0000521 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000522
Greg Clayton524e60b2010-10-06 22:10:17 +0000523 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000524 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000525
526 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000527 log->Printf ("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
528 static_cast<void*>(target_sp.get()),
529 __FUNCTION__,
530 pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000531
Greg Claytonacdbe812012-01-30 09:04:36 +0000532 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000533 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000534 ProcessAttachInfo attach_info;
535 attach_info.SetProcessID (pid);
536 if (listener.IsValid())
537 attach_info.SetListener(listener.GetSP());
Greg Clayton0c74e782011-06-24 03:21:43 +0000538
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000539 ProcessInstanceInfo instance_info;
540 if (target_sp->GetPlatform ()->GetProcessInfo (pid, instance_info))
541 attach_info.SetUserID (instance_info.GetEffectiveUserID ());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000542
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000543 error.SetError (AttachToProcess (attach_info, *target_sp));
544 if (error.Success ())
545 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000546 }
547 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000548 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000549
Sean Callanan575a4542012-10-20 00:21:31 +0000550 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000551 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
552 static_cast<void*>(target_sp.get ()),
553 __FUNCTION__,
554 static_cast<void*>(sb_process.GetSP().get ()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000555 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000556}
557
558lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000559SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +0000560(
Greg Clayton4b045622011-02-03 21:28:34 +0000561 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000562 const char *name, // basename of process to attach to
563 bool wait_for, // if true wait for a new instance of "name" to be launched
564 SBError& error // An error explaining what went wrong if attach fails
565)
566{
Greg Clayton5160ce52013-03-27 23:08:40 +0000567 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000568
Greg Clayton524e60b2010-10-06 22:10:17 +0000569 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000570 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000571
Sean Callanan575a4542012-10-20 00:21:31 +0000572 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000573 log->Printf ("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
574 static_cast<void*>(target_sp.get()),
575 __FUNCTION__,
576 name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000577 wait_for ? "true" : "false");
578
Greg Claytonacdbe812012-01-30 09:04:36 +0000579 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000580 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000581 ProcessAttachInfo attach_info;
582 attach_info.GetExecutableFile().SetFile(name, false);
583 attach_info.SetWaitForLaunch(wait_for);
584 if (listener.IsValid())
585 attach_info.SetListener(listener.GetSP());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000586
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000587 error.SetError (AttachToProcess (attach_info, *target_sp));
588 if (error.Success ())
589 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000590 }
591 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000592 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000593
Sean Callanan575a4542012-10-20 00:21:31 +0000594 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000595 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000596 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000597 __FUNCTION__,
598 static_cast<void*>(sb_process.GetSP().get()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000599 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000600}
601
James McIlree9631aae2011-03-04 00:31:13 +0000602lldb::SBProcess
603SBTarget::ConnectRemote
604(
605 SBListener &listener,
606 const char *url,
607 const char *plugin_name,
608 SBError& error
609)
610{
Greg Clayton5160ce52013-03-27 23:08:40 +0000611 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000612
James McIlree9631aae2011-03-04 00:31:13 +0000613 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000614 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000615 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000616
Sean Callanan575a4542012-10-20 00:21:31 +0000617 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000618 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
619 static_cast<void*>(target_sp.get()), url, plugin_name);
620
Greg Claytonacdbe812012-01-30 09:04:36 +0000621 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000622 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000623 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +0000624 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000625 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000626 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000627 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000628
Greg Claytonb9556ac2012-01-30 07:41:31 +0000629 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000630 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000631 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000632 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +0000633 }
634 else
635 {
636 error.SetErrorString ("unable to create lldb_private::Process");
637 }
638 }
639 else
640 {
641 error.SetErrorString ("SBTarget is invalid");
642 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000643
Sean Callanan575a4542012-10-20 00:21:31 +0000644 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000645 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000646 static_cast<void*>(target_sp.get()),
647 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +0000648 return sb_process;
649}
650
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651SBFileSpec
652SBTarget::GetExecutable ()
653{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000654
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +0000656 TargetSP target_sp(GetSP());
657 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000658 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000659 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +0000660 if (exe_module)
661 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000663
Greg Clayton5160ce52013-03-27 23:08:40 +0000664 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000665 if (log)
666 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000667 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
668 static_cast<void*>(target_sp.get()),
669 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000670 }
671
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 return exe_file_spec;
673}
674
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000675bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676SBTarget::operator == (const SBTarget &rhs) const
677{
Greg Clayton66111032010-06-23 01:19:29 +0000678 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679}
680
681bool
682SBTarget::operator != (const SBTarget &rhs) const
683{
Greg Clayton66111032010-06-23 01:19:29 +0000684 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685}
686
Greg Claytonb9556ac2012-01-30 07:41:31 +0000687lldb::TargetSP
688SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +0000689{
690 return m_opaque_sp;
691}
692
Greg Clayton66111032010-06-23 01:19:29 +0000693void
Greg Claytonb9556ac2012-01-30 07:41:31 +0000694SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +0000695{
696 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697}
698
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000699lldb::SBAddress
700SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000701{
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000702 lldb::SBAddress sb_addr;
703 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +0000704 TargetSP target_sp(GetSP());
705 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000706 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000707 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +0000708 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000709 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000710 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000711
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000712 // We have a load address that isn't in a section, just return an address
713 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +0000714 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000715 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000716}
717
Matthew Gardinerc928de32014-10-22 07:22:56 +0000718lldb::SBAddress
719SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
720{
721 lldb::SBAddress sb_addr;
722 Address &addr = sb_addr.ref();
723 TargetSP target_sp(GetSP());
724 if (target_sp)
725 {
726 Mutex::Locker api_locker (target_sp->GetAPIMutex());
727 if (target_sp->ResolveFileAddress (file_addr, addr))
728 return sb_addr;
729 }
730
731 addr.SetRawAddress(file_addr);
732 return sb_addr;
733}
Greg Claytond5944cd2013-12-06 01:12:00 +0000734
735lldb::SBAddress
736SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
737{
738 lldb::SBAddress sb_addr;
739 Address &addr = sb_addr.ref();
740 TargetSP target_sp(GetSP());
741 if (target_sp)
742 {
743 Mutex::Locker api_locker (target_sp->GetAPIMutex());
744 if (target_sp->ResolveLoadAddress (vm_addr, addr))
745 return sb_addr;
746 }
747
748 // We have a load address that isn't in a section, just return an address
749 // with the offset filled in (the address) and the section set to NULL
750 addr.SetRawAddress(vm_addr);
751 return sb_addr;
752}
753
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000754SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +0000755SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
756 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000757{
758 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +0000759 if (addr.IsValid())
760 {
761 TargetSP target_sp(GetSP());
762 if (target_sp)
763 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
764 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000765 return sc;
766}
767
Matthew Gardinerc928de32014-10-22 07:22:56 +0000768size_t
769SBTarget::ReadMemory (const SBAddress addr,
770 void *buf,
771 size_t size,
772 lldb::SBError &error)
773{
774 SBError sb_error;
775 size_t bytes_read = 0;
776 TargetSP target_sp(GetSP());
777 if (target_sp)
778 {
779 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8691dc52014-11-04 00:56:30 +0000780 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
781 }
782 else
783 {
784 sb_error.SetErrorString("invalid target");
Matthew Gardinerc928de32014-10-22 07:22:56 +0000785 }
786
787 return bytes_read;
788}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000789
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000791SBTarget::BreakpointCreateByLocation (const char *file,
792 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793{
Greg Clayton7481c202010-11-08 00:28:40 +0000794 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000795}
796
797SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000798SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
799 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800{
Greg Clayton5160ce52013-03-27 23:08:40 +0000801 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000802
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000804 TargetSP target_sp(GetSP());
805 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000806 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000807 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000808
Greg Clayton1f746072012-08-29 21:13:06 +0000809 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +0000810 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +0000811 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000812 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +0000813 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
814 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware, move_to_nearest_code);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000815 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000816
817 if (log)
818 {
819 SBStream sstr;
820 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000821 char path[PATH_MAX];
822 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000823 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
824 static_cast<void*>(target_sp.get()), path, line,
825 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000826 }
827
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828 return sb_bp;
829}
830
831SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000832SBTarget::BreakpointCreateByName (const char *symbol_name,
833 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834{
Greg Clayton5160ce52013-03-27 23:08:40 +0000835 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000836
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000838 TargetSP target_sp(GetSP());
839 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000841 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000842
Jim Inghama8558b62012-05-22 00:12:20 +0000843 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000844 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000845 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 if (module_name && module_name[0])
847 {
Jim Ingham969795f2011-09-21 01:17:13 +0000848 FileSpecList module_spec_list;
849 module_spec_list.Append (FileSpec (module_name, false));
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000850 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851 }
852 else
853 {
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000854 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 }
856 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000857
Caroline Ticeceb6b132010-10-26 03:11:13 +0000858 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000859 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
860 static_cast<void*>(target_sp.get()), symbol_name,
861 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000862
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 return sb_bp;
864}
865
Jim Ingham87df91b2011-09-23 00:54:11 +0000866lldb::SBBreakpoint
867SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000868 const SBFileSpecList &module_list,
869 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000870{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000871 uint32_t name_type_mask = eFunctionNameTypeAuto;
Jim Ingham0fcdac32015-11-06 22:48:59 +0000872 return BreakpointCreateByName (symbol_name, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list);
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000873}
874
875lldb::SBBreakpoint
876SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000877 uint32_t name_type_mask,
878 const SBFileSpecList &module_list,
879 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000880{
Jim Ingham0fcdac32015-11-06 22:48:59 +0000881 return BreakpointCreateByName (symbol_name, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list);
882}
883
884lldb::SBBreakpoint
885SBTarget::BreakpointCreateByName (const char *symbol_name,
886 uint32_t name_type_mask,
887 LanguageType symbol_language,
888 const SBFileSpecList &module_list,
889 const SBFileSpecList &comp_unit_list)
890{
Greg Clayton5160ce52013-03-27 23:08:40 +0000891 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +0000892
893 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000894 TargetSP target_sp(GetSP());
895 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +0000896 {
Jim Inghama8558b62012-05-22 00:12:20 +0000897 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000898 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000899 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +0000900 Mutex::Locker api_locker (target_sp->GetAPIMutex());
901 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +0000902 comp_unit_list.get(),
903 symbol_name,
904 name_type_mask,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000905 symbol_language,
Greg Claytoneb023e72013-10-11 19:48:25 +0000906 skip_prologue,
907 internal,
908 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +0000909 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000910
Jim Ingham87df91b2011-09-23 00:54:11 +0000911 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000912 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
913 static_cast<void*>(target_sp.get()), symbol_name,
914 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +0000915
916 return sb_bp;
917}
918
Jim Inghamfab10e82012-03-06 00:37:27 +0000919lldb::SBBreakpoint
920SBTarget::BreakpointCreateByNames (const char *symbol_names[],
921 uint32_t num_names,
922 uint32_t name_type_mask,
923 const SBFileSpecList &module_list,
924 const SBFileSpecList &comp_unit_list)
925{
Jim Ingham0fcdac32015-11-06 22:48:59 +0000926 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list);
927}
928
929lldb::SBBreakpoint
930SBTarget::BreakpointCreateByNames (const char *symbol_names[],
931 uint32_t num_names,
932 uint32_t name_type_mask,
933 LanguageType symbol_language,
934 const SBFileSpecList &module_list,
935 const SBFileSpecList &comp_unit_list)
936{
Greg Clayton5160ce52013-03-27 23:08:40 +0000937 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +0000938
939 SBBreakpoint sb_bp;
940 TargetSP target_sp(GetSP());
941 if (target_sp && num_names > 0)
942 {
943 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +0000944 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000945 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000946 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +0000947 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Ingham0fcdac32015-11-06 22:48:59 +0000948 comp_unit_list.get(),
949 symbol_names,
950 num_names,
951 name_type_mask,
952 symbol_language,
953 skip_prologue,
954 internal,
955 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +0000956 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000957
Jim Inghamfab10e82012-03-06 00:37:27 +0000958 if (log)
959 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000960 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
961 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000962 for (uint32_t i = 0 ; i < num_names; i++)
963 {
964 char sep;
965 if (i < num_names - 1)
966 sep = ',';
967 else
968 sep = '}';
969 if (symbol_names[i] != NULL)
970 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
971 else
972 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +0000973 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000974 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
975 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000976 }
977
978 return sb_bp;
979}
Jim Ingham87df91b2011-09-23 00:54:11 +0000980
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000982SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
983 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000984{
Jim Ingham0fcdac32015-11-06 22:48:59 +0000985 SBFileSpecList module_spec_list;
986 SBFileSpecList comp_unit_list;
987 if (module_name && module_name[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000988 {
Jim Ingham0fcdac32015-11-06 22:48:59 +0000989 module_spec_list.Append (FileSpec (module_name, false));
990
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991 }
Jim Ingham0fcdac32015-11-06 22:48:59 +0000992 return BreakpointCreateByRegex (symbol_name_regex, eLanguageTypeUnknown, module_spec_list, comp_unit_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000993}
994
Jim Ingham87df91b2011-09-23 00:54:11 +0000995lldb::SBBreakpoint
996SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000997 const SBFileSpecList &module_list,
998 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000999{
Jim Ingham0fcdac32015-11-06 22:48:59 +00001000 return BreakpointCreateByRegex (symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list);
1001}
1002
1003lldb::SBBreakpoint
1004SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1005 LanguageType symbol_language,
1006 const SBFileSpecList &module_list,
1007 const SBFileSpecList &comp_unit_list)
1008{
Greg Clayton5160ce52013-03-27 23:08:40 +00001009 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010
Jim Ingham87df91b2011-09-23 00:54:11 +00001011 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001012 TargetSP target_sp(GetSP());
1013 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001014 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001015 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001016 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001017 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001018 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001019 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham0fcdac32015-11-06 22:48:59 +00001020
1021 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, symbol_language, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001022 }
1023
1024 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001025 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1026 static_cast<void*>(target_sp.get()), symbol_name_regex,
1027 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001028
1029 return sb_bp;
1030}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031
1032SBBreakpoint
1033SBTarget::BreakpointCreateByAddress (addr_t address)
1034{
Greg Clayton5160ce52013-03-27 23:08:40 +00001035 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001036
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001037 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001038 TargetSP target_sp(GetSP());
1039 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001040 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001041 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001042 const bool hardware = false;
1043 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001044 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001045
Caroline Ticeceb6b132010-10-26 03:11:13 +00001046 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001047 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1048 static_cast<void*>(target_sp.get()),
1049 static_cast<uint64_t>(address),
1050 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001051
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001052 return sb_bp;
1053}
1054
Jim Ingham055a08a2015-11-17 03:39:13 +00001055SBBreakpoint
1056SBTarget::BreakpointCreateBySBAddress (SBAddress &sb_address)
1057{
1058 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1059
1060 SBBreakpoint sb_bp;
1061 TargetSP target_sp(GetSP());
1062 if (!sb_address.IsValid())
1063 {
1064 if (log)
1065 log->Printf ("SBTarget(%p)::BreakpointCreateBySBAddress called with invalid address",
1066 static_cast<void*>(target_sp.get()));
1067 return sb_bp;
1068 }
1069
1070 if (target_sp)
1071 {
1072 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1073 const bool hardware = false;
1074 *sb_bp = target_sp->CreateBreakpoint (sb_address.ref(), false, hardware);
1075 }
1076
1077 if (log)
1078 {
1079 SBStream s;
1080 sb_address.GetDescription(s);
1081 log->Printf ("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => SBBreakpoint(%p)",
1082 static_cast<void*>(target_sp.get()),
1083 s.GetData(),
1084 static_cast<void*>(sb_bp.get()));
1085 }
1086
1087 return sb_bp;
1088}
1089
Jim Ingham969795f2011-09-21 01:17:13 +00001090lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001091SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1092 const lldb::SBFileSpec &source_file,
1093 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001094{
Greg Clayton5160ce52013-03-27 23:08:40 +00001095 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001096
1097 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001098 TargetSP target_sp(GetSP());
1099 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001100 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001101 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001102 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001103 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001104 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +00001105 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham87df91b2011-09-23 00:54:11 +00001106 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001107
Jim Ingham969795f2011-09-21 01:17:13 +00001108 if (module_name && module_name[0])
1109 {
1110 FileSpecList module_spec_list;
1111 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001112
Ilia K055ad9b2015-05-18 13:41:01 +00001113 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware, move_to_nearest_code);
Jim Ingham969795f2011-09-21 01:17:13 +00001114 }
1115 else
1116 {
Ilia K055ad9b2015-05-18 13:41:01 +00001117 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware, move_to_nearest_code);
Jim Ingham969795f2011-09-21 01:17:13 +00001118 }
1119 }
1120
1121 if (log)
1122 {
1123 char path[PATH_MAX];
1124 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001125 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1126 static_cast<void*>(target_sp.get()), source_regex, path,
1127 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001128 }
1129
1130 return sb_bp;
1131}
1132
Jim Ingham87df91b2011-09-23 00:54:11 +00001133lldb::SBBreakpoint
Jim Inghame7320522015-02-12 17:37:46 +00001134SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1135 const SBFileSpecList &module_list,
1136 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001137{
Greg Clayton5160ce52013-03-27 23:08:40 +00001138 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001139
1140 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001141 TargetSP target_sp(GetSP());
1142 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001143 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001144 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001145 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +00001146 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham87df91b2011-09-23 00:54:11 +00001147 RegularExpression regexp(source_regex);
Ilia K055ad9b2015-05-18 13:41:01 +00001148 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware, move_to_nearest_code);
Jim Ingham87df91b2011-09-23 00:54:11 +00001149 }
1150
1151 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001152 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1153 static_cast<void*>(target_sp.get()), source_regex,
1154 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001155
1156 return sb_bp;
1157}
Jim Ingham969795f2011-09-21 01:17:13 +00001158
Jim Inghamfab10e82012-03-06 00:37:27 +00001159lldb::SBBreakpoint
1160SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001161 bool catch_bp,
1162 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001163{
Greg Clayton5160ce52013-03-27 23:08:40 +00001164 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001165
1166 SBBreakpoint sb_bp;
1167 TargetSP target_sp(GetSP());
1168 if (target_sp)
1169 {
1170 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001171 const bool hardware = false;
1172 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001173 }
1174
1175 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001176 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1177 static_cast<void*>(target_sp.get()),
Jim Ingham0e0984e2015-09-02 01:06:46 +00001178 Language::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001179 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1180 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001181
1182 return sb_bp;
1183}
1184
Greg Clayton9fed0d82010-07-23 23:33:17 +00001185uint32_t
1186SBTarget::GetNumBreakpoints () const
1187{
Greg Claytonacdbe812012-01-30 09:04:36 +00001188 TargetSP target_sp(GetSP());
1189 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001190 {
1191 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001192 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001193 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001194 return 0;
1195}
1196
1197SBBreakpoint
1198SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1199{
1200 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001201 TargetSP target_sp(GetSP());
1202 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001203 {
1204 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001205 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001206 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001207 return sb_breakpoint;
1208}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209
1210bool
1211SBTarget::BreakpointDelete (break_id_t bp_id)
1212{
Greg Clayton5160ce52013-03-27 23:08:40 +00001213 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001214
Caroline Ticeceb6b132010-10-26 03:11:13 +00001215 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001216 TargetSP target_sp(GetSP());
1217 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001218 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001219 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1220 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001221 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001222
1223 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001224 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1225 static_cast<void*>(target_sp.get()),
1226 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001227
1228 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229}
1230
Johnny Chen5d043462011-09-26 22:40:50 +00001231SBBreakpoint
1232SBTarget::FindBreakpointByID (break_id_t bp_id)
1233{
Greg Clayton5160ce52013-03-27 23:08:40 +00001234 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001235
1236 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001237 TargetSP target_sp(GetSP());
1238 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001239 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001240 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1241 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001242 }
1243
1244 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001245 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1246 static_cast<void*>(target_sp.get()),
1247 static_cast<uint32_t>(bp_id),
1248 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001249
1250 return sb_breakpoint;
1251}
1252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253bool
1254SBTarget::EnableAllBreakpoints ()
1255{
Greg Claytonacdbe812012-01-30 09:04:36 +00001256 TargetSP target_sp(GetSP());
1257 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001259 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1260 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 return true;
1262 }
1263 return false;
1264}
1265
1266bool
1267SBTarget::DisableAllBreakpoints ()
1268{
Greg Claytonacdbe812012-01-30 09:04:36 +00001269 TargetSP target_sp(GetSP());
1270 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001271 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001272 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1273 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274 return true;
1275 }
1276 return false;
1277}
1278
1279bool
1280SBTarget::DeleteAllBreakpoints ()
1281{
Greg Claytonacdbe812012-01-30 09:04:36 +00001282 TargetSP target_sp(GetSP());
1283 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001285 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1286 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287 return true;
1288 }
1289 return false;
1290}
1291
Johnny Chen5d043462011-09-26 22:40:50 +00001292uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001293SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001294{
Greg Claytonacdbe812012-01-30 09:04:36 +00001295 TargetSP target_sp(GetSP());
1296 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001297 {
Johnny Chen01a67862011-10-14 00:42:25 +00001298 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001299 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001300 }
1301 return 0;
1302}
1303
Greg Clayton1b282f92011-10-13 18:08:26 +00001304SBWatchpoint
1305SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001306{
Johnny Chen01a67862011-10-14 00:42:25 +00001307 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001308 TargetSP target_sp(GetSP());
1309 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001310 {
Johnny Chen01a67862011-10-14 00:42:25 +00001311 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001312 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001313 }
Johnny Chen01a67862011-10-14 00:42:25 +00001314 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001315}
1316
1317bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001318SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001319{
Greg Clayton5160ce52013-03-27 23:08:40 +00001320 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001321
1322 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001323 TargetSP target_sp(GetSP());
1324 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001325 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001326 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001327 Mutex::Locker locker;
1328 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001329 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001330 }
1331
1332 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001333 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1334 static_cast<void*>(target_sp.get()),
1335 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001336
1337 return result;
1338}
1339
Greg Clayton1b282f92011-10-13 18:08:26 +00001340SBWatchpoint
1341SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001342{
Greg Clayton5160ce52013-03-27 23:08:40 +00001343 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001344
Greg Clayton1b282f92011-10-13 18:08:26 +00001345 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001346 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001347 TargetSP target_sp(GetSP());
1348 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001349 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001350 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001351 Mutex::Locker locker;
1352 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001353 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1354 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001355 }
1356
1357 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001358 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1359 static_cast<void*>(target_sp.get()),
1360 static_cast<uint32_t>(wp_id),
1361 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001362
Greg Clayton1b282f92011-10-13 18:08:26 +00001363 return sb_watchpoint;
1364}
1365
1366lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001367SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001368{
Greg Clayton5160ce52013-03-27 23:08:40 +00001369 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001370
Greg Clayton1b282f92011-10-13 18:08:26 +00001371 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001372 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001373 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001374 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001375 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001376 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001377 uint32_t watch_type = 0;
1378 if (read)
1379 watch_type |= LLDB_WATCH_TYPE_READ;
1380 if (write)
1381 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001382 if (watch_type == 0)
1383 {
1384 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1385 return sb_watchpoint;
1386 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001387
Johnny Chen7385a5a2012-05-31 22:56:36 +00001388 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001389 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001390 // This API doesn't take in a type, so we can't figure out what it is.
Greg Claytona1e5dc82015-08-11 22:53:00 +00001391 CompilerType *type = NULL;
Jim Inghama7dfb662012-10-23 07:20:06 +00001392 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001393 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001394 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001395 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001396
Greg Clayton1b282f92011-10-13 18:08:26 +00001397 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001398 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001399 static_cast<void*>(target_sp.get()), addr,
1400 static_cast<uint32_t>(size),
1401 static_cast<void*>(watchpoint_sp.get()));
1402
Greg Clayton1b282f92011-10-13 18:08:26 +00001403 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001404}
1405
1406bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001407SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001408{
Greg Claytonacdbe812012-01-30 09:04:36 +00001409 TargetSP target_sp(GetSP());
1410 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001411 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001412 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001413 Mutex::Locker locker;
1414 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001415 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001416 return true;
1417 }
1418 return false;
1419}
1420
1421bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001422SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001423{
Greg Claytonacdbe812012-01-30 09:04:36 +00001424 TargetSP target_sp(GetSP());
1425 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001426 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001427 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001428 Mutex::Locker locker;
1429 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001430 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001431 return true;
1432 }
1433 return false;
1434}
1435
Enrico Granata347c2aa2013-10-08 21:49:02 +00001436SBValue
1437SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1438{
1439 SBValue sb_value;
1440 lldb::ValueObjectSP new_value_sp;
1441 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1442 {
Enrico Granata972be532014-12-17 21:18:43 +00001443 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1444 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
Greg Claytona1e5dc82015-08-11 22:53:00 +00001445 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +00001446 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001447 }
1448 sb_value.SetSP(new_value_sp);
1449 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1450 if (log)
1451 {
1452 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001453 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1454 static_cast<void*>(m_opaque_sp.get()),
1455 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001456 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001457 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1458 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001459 }
1460 return sb_value;
1461}
1462
Enrico Granata972be532014-12-17 21:18:43 +00001463lldb::SBValue
1464SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1465{
1466 SBValue sb_value;
1467 lldb::ValueObjectSP new_value_sp;
1468 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1469 {
1470 DataExtractorSP extractor(*data);
1471 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
Greg Claytona1e5dc82015-08-11 22:53:00 +00001472 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +00001473 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1474 }
1475 sb_value.SetSP(new_value_sp);
1476 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1477 if (log)
1478 {
1479 if (new_value_sp)
1480 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1481 static_cast<void*>(m_opaque_sp.get()),
1482 new_value_sp->GetName().AsCString());
1483 else
1484 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1485 static_cast<void*>(m_opaque_sp.get()));
1486 }
1487 return sb_value;
1488}
1489
1490lldb::SBValue
1491SBTarget::CreateValueFromExpression (const char *name, const char* expr)
1492{
1493 SBValue sb_value;
1494 lldb::ValueObjectSP new_value_sp;
1495 if (IsValid() && name && *name && expr && *expr)
1496 {
1497 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1498 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1499 }
1500 sb_value.SetSP(new_value_sp);
1501 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1502 if (log)
1503 {
1504 if (new_value_sp)
1505 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1506 static_cast<void*>(m_opaque_sp.get()),
1507 new_value_sp->GetName().AsCString());
1508 else
1509 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
1510 static_cast<void*>(m_opaque_sp.get()));
1511 }
1512 return sb_value;
1513}
1514
Johnny Chen5d043462011-09-26 22:40:50 +00001515bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001516SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001517{
Greg Claytonacdbe812012-01-30 09:04:36 +00001518 TargetSP target_sp(GetSP());
1519 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001520 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001521 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001522 Mutex::Locker locker;
1523 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001524 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001525 return true;
1526 }
1527 return false;
1528}
1529
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001530
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001531lldb::SBModule
1532SBTarget::AddModule (const char *path,
1533 const char *triple,
1534 const char *uuid_cstr)
1535{
Greg Claytonb210aec2012-04-23 20:23:39 +00001536 return AddModule (path, triple, uuid_cstr, NULL);
1537}
1538
1539lldb::SBModule
1540SBTarget::AddModule (const char *path,
1541 const char *triple,
1542 const char *uuid_cstr,
1543 const char *symfile)
1544{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001545 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001546 TargetSP target_sp(GetSP());
1547 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001548 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001549 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001550 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001551 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001552
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001553 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001554 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001555
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001556 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001557 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001558 else
1559 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001560
1561 if (symfile)
1562 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001563
Greg Claytonb9a01b32012-02-26 05:51:37 +00001564 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001565 }
1566 return sb_module;
1567}
1568
Greg Clayton226cce22013-07-08 22:22:41 +00001569lldb::SBModule
1570SBTarget::AddModule (const SBModuleSpec &module_spec)
1571{
1572 lldb::SBModule sb_module;
1573 TargetSP target_sp(GetSP());
1574 if (target_sp)
1575 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1576 return sb_module;
1577}
1578
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001579bool
1580SBTarget::AddModule (lldb::SBModule &module)
1581{
Greg Claytonacdbe812012-01-30 09:04:36 +00001582 TargetSP target_sp(GetSP());
1583 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001584 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001585 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001586 return true;
1587 }
1588 return false;
1589}
1590
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001591uint32_t
1592SBTarget::GetNumModules () const
1593{
Greg Clayton5160ce52013-03-27 23:08:40 +00001594 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001595
Caroline Ticeceb6b132010-10-26 03:11:13 +00001596 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001597 TargetSP target_sp(GetSP());
1598 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001599 {
1600 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001601 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001602 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001603
1604 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001605 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1606 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001607
1608 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001609}
1610
Greg Clayton48e42542010-07-30 20:12:55 +00001611void
1612SBTarget::Clear ()
1613{
Greg Clayton5160ce52013-03-27 23:08:40 +00001614 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001615
1616 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001617 log->Printf ("SBTarget(%p)::Clear ()",
1618 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001619
Greg Clayton48e42542010-07-30 20:12:55 +00001620 m_opaque_sp.reset();
1621}
1622
1623
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001624SBModule
1625SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1626{
1627 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001628 TargetSP target_sp(GetSP());
1629 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001630 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001631 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001632 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00001633 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001634 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001635 return sb_module;
1636}
1637
Greg Clayton13d19502012-01-29 06:07:39 +00001638lldb::ByteOrder
1639SBTarget::GetByteOrder ()
1640{
Greg Claytonacdbe812012-01-30 09:04:36 +00001641 TargetSP target_sp(GetSP());
1642 if (target_sp)
1643 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00001644 return eByteOrderInvalid;
1645}
1646
1647const char *
1648SBTarget::GetTriple ()
1649{
Greg Claytonacdbe812012-01-30 09:04:36 +00001650 TargetSP target_sp(GetSP());
1651 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00001652 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001653 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00001654 // Unique the string so we don't run into ownership issues since
1655 // the const strings put the string into the string pool once and
1656 // the strings never comes out
1657 ConstString const_triple (triple.c_str());
1658 return const_triple.GetCString();
1659 }
1660 return NULL;
1661}
1662
1663uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00001664SBTarget::GetDataByteSize ()
1665{
1666 TargetSP target_sp(GetSP());
1667 if (target_sp)
1668 {
1669 return target_sp->GetArchitecture().GetDataByteSize() ;
1670 }
1671 return 0;
1672}
1673
1674uint32_t
1675SBTarget::GetCodeByteSize ()
1676{
1677 TargetSP target_sp(GetSP());
1678 if (target_sp)
1679 {
1680 return target_sp->GetArchitecture().GetCodeByteSize() ;
1681 }
1682 return 0;
1683}
1684
1685uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00001686SBTarget::GetAddressByteSize()
1687{
Greg Claytonacdbe812012-01-30 09:04:36 +00001688 TargetSP target_sp(GetSP());
1689 if (target_sp)
1690 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00001691 return sizeof(void*);
1692}
1693
1694
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001695SBModule
1696SBTarget::GetModuleAtIndex (uint32_t idx)
1697{
Greg Clayton5160ce52013-03-27 23:08:40 +00001698 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001699
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001701 ModuleSP module_sp;
1702 TargetSP target_sp(GetSP());
1703 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001704 {
1705 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001706 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1707 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001708 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001709
1710 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001711 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1712 static_cast<void*>(target_sp.get()), idx,
1713 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001714
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715 return sb_module;
1716}
1717
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001718bool
1719SBTarget::RemoveModule (lldb::SBModule module)
1720{
Greg Claytonacdbe812012-01-30 09:04:36 +00001721 TargetSP target_sp(GetSP());
1722 if (target_sp)
1723 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001724 return false;
1725}
1726
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001727
1728SBBroadcaster
1729SBTarget::GetBroadcaster () const
1730{
Greg Clayton5160ce52013-03-27 23:08:40 +00001731 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001732
Greg Claytonacdbe812012-01-30 09:04:36 +00001733 TargetSP target_sp(GetSP());
1734 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001735
Caroline Ticeceb6b132010-10-26 03:11:13 +00001736 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001737 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1738 static_cast<void*>(target_sp.get()),
1739 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001740
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741 return broadcaster;
1742}
1743
Caroline Ticedde9cff2010-09-20 05:20:02 +00001744bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001745SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001746{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001747 Stream &strm = description.ref();
1748
Greg Claytonacdbe812012-01-30 09:04:36 +00001749 TargetSP target_sp(GetSP());
1750 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00001751 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001752 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001753 }
1754 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001755 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001756
1757 return true;
1758}
1759
Greg Clayton5569e642012-02-06 01:44:54 +00001760lldb::SBSymbolContextList
1761SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00001762{
Greg Clayton5569e642012-02-06 01:44:54 +00001763 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00001764 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00001765 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001766 TargetSP target_sp(GetSP());
1767 if (target_sp)
1768 {
1769 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00001770 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00001771 const bool append = true;
1772 target_sp->GetImages().FindFunctions (ConstString(name),
1773 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001774 symbols_ok,
1775 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00001776 append,
1777 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00001778 }
Greg Claytonfe356d32011-06-21 01:34:41 +00001779 }
Greg Clayton5569e642012-02-06 01:44:54 +00001780 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00001781}
1782
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001783lldb::SBSymbolContextList
1784SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
1785{
1786 lldb::SBSymbolContextList sb_sc_list;
1787 if (name && name[0])
1788 {
1789 TargetSP target_sp(GetSP());
1790 if (target_sp)
1791 {
1792 std::string regexstr;
1793 switch (matchtype)
1794 {
1795 case eMatchTypeRegex:
1796 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
1797 break;
1798 case eMatchTypeStartsWith:
1799 regexstr = llvm::Regex::escape(name) + ".*";
1800 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1801 break;
1802 default:
1803 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
1804 break;
1805 }
1806 }
1807 }
1808 return sb_sc_list;
1809}
1810
Enrico Granata6f3533f2011-07-29 19:53:35 +00001811lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00001812SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001813{
Greg Claytonacdbe812012-01-30 09:04:36 +00001814 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001815 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001816 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001817 ConstString const_typename(typename_cstr);
1818 SymbolContext sc;
1819 const bool exact_match = false;
1820
1821 const ModuleList &module_list = target_sp->GetImages();
1822 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001823 for (size_t idx = 0; idx < count; idx++)
1824 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001825 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
1826 if (module_sp)
1827 {
1828 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
1829 if (type_sp)
1830 return SBType(type_sp);
1831 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001832 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001833
1834 // Didn't find the type in the symbols; try the Objective-C runtime
1835 // if one is installed
1836
1837 ProcessSP process_sp(target_sp->GetProcessSP());
1838
1839 if (process_sp)
1840 {
1841 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1842
1843 if (objc_language_runtime)
1844 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001845 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001846
Sean Callanan9998acd2014-12-05 01:21:59 +00001847 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001848 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001849 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001850
Sean Callanan9998acd2014-12-05 01:21:59 +00001851 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
1852 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00001853 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0]))
Sean Callanan9998acd2014-12-05 01:21:59 +00001854 {
1855 return SBType(type);
1856 }
1857 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001858 }
1859 }
1860 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001861
1862 // No matches, search for basic typename matches
1863 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1864 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001865 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001866 }
1867 return SBType();
1868}
1869
Greg Claytonb43165b2012-12-05 21:24:42 +00001870SBType
1871SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001872{
Greg Claytonacdbe812012-01-30 09:04:36 +00001873 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001874 if (target_sp)
1875 {
1876 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1877 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001878 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00001879 }
1880 return SBType();
1881}
1882
1883
1884lldb::SBTypeList
1885SBTarget::FindTypes (const char* typename_cstr)
1886{
1887 SBTypeList sb_type_list;
1888 TargetSP target_sp(GetSP());
1889 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001890 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001891 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00001892 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00001893 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001894 SymbolContext sc;
1895 TypeList type_list;
1896
Greg Clayton29399a22012-04-06 17:41:13 +00001897 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00001898 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00001899 exact_match,
1900 UINT32_MAX,
1901 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001902
Greg Claytonb43165b2012-12-05 21:24:42 +00001903 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001904 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001905 for (size_t idx = 0; idx < num_matches; idx++)
1906 {
1907 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1908 if (type_sp)
1909 sb_type_list.Append(SBType(type_sp));
1910 }
1911 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001912
1913 // Try the Objective-C runtime if one is installed
1914
1915 ProcessSP process_sp(target_sp->GetProcessSP());
1916
1917 if (process_sp)
1918 {
1919 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1920
1921 if (objc_language_runtime)
1922 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001923 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001924
Sean Callanan9998acd2014-12-05 01:21:59 +00001925 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001926 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001927 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001928
Sean Callanan9998acd2014-12-05 01:21:59 +00001929 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00001930 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001931 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00001932 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00001933 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl))
Sean Callanan9998acd2014-12-05 01:21:59 +00001934 {
1935 sb_type_list.Append(SBType(type));
1936 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001937 }
1938 }
1939 }
1940 }
1941 }
1942
1943 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00001944 {
1945 // No matches, search for basic typename matches
1946 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1947 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001948 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001949 }
1950 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001951 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001952}
1953
Greg Claytondea8cb42011-06-29 22:09:02 +00001954SBValueList
1955SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1956{
1957 SBValueList sb_value_list;
1958
Greg Claytonacdbe812012-01-30 09:04:36 +00001959 TargetSP target_sp(GetSP());
1960 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00001961 {
1962 VariableList variable_list;
1963 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00001964 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1965 append,
1966 max_matches,
1967 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00001968
1969 if (match_count > 0)
1970 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001971 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001972 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00001973 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001974 for (uint32_t i=0; i<match_count; ++i)
1975 {
1976 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1977 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00001978 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00001979 }
1980 }
1981 }
1982
1983 return sb_value_list;
1984}
1985
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001986SBValueList
1987SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
1988{
1989 SBValueList sb_value_list;
1990
1991 TargetSP target_sp(GetSP());
1992 if (name && target_sp)
1993 {
1994 VariableList variable_list;
1995 const bool append = true;
1996
1997 std::string regexstr;
1998 uint32_t match_count;
1999 switch (matchtype)
2000 {
2001 case eMatchTypeNormal:
2002 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2003 append,
2004 max_matches,
2005 variable_list);
2006 break;
2007 case eMatchTypeRegex:
2008 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2009 append,
2010 max_matches,
2011 variable_list);
2012 break;
2013 case eMatchTypeStartsWith:
2014 regexstr = llvm::Regex::escape(name) + ".*";
2015 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2016 append,
2017 max_matches,
2018 variable_list);
2019 break;
2020 }
2021
2022
2023 if (match_count > 0)
2024 {
2025 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2026 if (exe_scope == NULL)
2027 exe_scope = target_sp.get();
2028 for (uint32_t i = 0; i<match_count; ++i)
2029 {
2030 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2031 if (valobj_sp)
2032 sb_value_list.Append(SBValue(valobj_sp));
2033 }
2034 }
2035 }
2036
2037 return sb_value_list;
2038}
2039
2040
Enrico Granatabcd80b42013-01-16 18:53:52 +00002041lldb::SBValue
2042SBTarget::FindFirstGlobalVariable (const char* name)
2043{
2044 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2045 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2046 return sb_value_list.GetValueAtIndex(0);
2047 return SBValue();
2048}
2049
Jim Inghame37d6052011-09-13 00:29:56 +00002050SBSourceManager
2051SBTarget::GetSourceManager()
2052{
2053 SBSourceManager source_manager (*this);
2054 return source_manager;
2055}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002056
Sean Callanan50952e92011-12-14 23:49:37 +00002057lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002058SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2059{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002060 return ReadInstructions (base_addr, count, NULL);
2061}
2062
2063lldb::SBInstructionList
2064SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2065{
Greg Clayton9c766112012-03-06 22:24:44 +00002066 SBInstructionList sb_instructions;
2067
2068 TargetSP target_sp(GetSP());
2069 if (target_sp)
2070 {
2071 Address *addr_ptr = base_addr.get();
2072
2073 if (addr_ptr)
2074 {
2075 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2076 bool prefer_file_cache = false;
2077 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002078 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2079 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2080 prefer_file_cache,
2081 data.GetBytes(),
2082 data.GetByteSize(),
2083 error,
2084 &load_addr);
2085 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002086 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2087 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002088 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002089 *addr_ptr,
2090 data.GetBytes(),
2091 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002092 count,
2093 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002094 }
2095 }
2096
2097 return sb_instructions;
2098
2099}
2100
2101lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002102SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2103{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002104 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2105}
2106
2107lldb::SBInstructionList
2108SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2109{
Sean Callanan50952e92011-12-14 23:49:37 +00002110 SBInstructionList sb_instructions;
2111
Greg Claytonacdbe812012-01-30 09:04:36 +00002112 TargetSP target_sp(GetSP());
2113 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002114 {
2115 Address addr;
2116
2117 if (base_addr.get())
2118 addr = *base_addr.get();
2119
Greg Clayton3faf47c2013-03-28 23:42:53 +00002120 const bool data_from_file = true;
2121
Greg Claytonacdbe812012-01-30 09:04:36 +00002122 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002123 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002124 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002125 addr,
2126 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002127 size,
2128 UINT32_MAX,
2129 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002130 }
2131
2132 return sb_instructions;
2133}
2134
2135lldb::SBInstructionList
2136SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2137{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002138 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2139}
2140
2141lldb::SBInstructionList
2142SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2143{
2144 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002145}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002146
2147SBError
2148SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2149 lldb::addr_t section_base_addr)
2150{
2151 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002152 TargetSP target_sp(GetSP());
2153 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002154 {
2155 if (!section.IsValid())
2156 {
2157 sb_error.SetErrorStringWithFormat ("invalid section");
2158 }
2159 else
2160 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002161 SectionSP section_sp (section.GetSP());
2162 if (section_sp)
2163 {
2164 if (section_sp->IsThreadSpecific())
2165 {
2166 sb_error.SetErrorString ("thread specific sections are not yet supported");
2167 }
2168 else
2169 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002170 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002171 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002172 {
2173 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002174 if (process_sp)
2175 process_sp->Flush();
2176 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002177 }
2178 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002179 }
2180 }
2181 else
2182 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002183 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002184 }
2185 return sb_error;
2186}
2187
2188SBError
2189SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2190{
2191 SBError sb_error;
2192
Greg Claytonacdbe812012-01-30 09:04:36 +00002193 TargetSP target_sp(GetSP());
2194 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002195 {
2196 if (!section.IsValid())
2197 {
2198 sb_error.SetErrorStringWithFormat ("invalid section");
2199 }
2200 else
2201 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002202 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002203 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002204 {
2205 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002206 if (process_sp)
2207 process_sp->Flush();
2208 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002209 }
2210 }
2211 else
2212 {
2213 sb_error.SetErrorStringWithFormat ("invalid target");
2214 }
2215 return sb_error;
2216}
2217
2218SBError
2219SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2220{
2221 SBError sb_error;
2222
Greg Claytonacdbe812012-01-30 09:04:36 +00002223 TargetSP target_sp(GetSP());
2224 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002225 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002226 ModuleSP module_sp (module.GetSP());
2227 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002228 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002229 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002230 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002231 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002232 // The load was successful, make sure that at least some sections
2233 // changed before we notify that our module was loaded.
2234 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002235 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002236 ModuleList module_list;
2237 module_list.Append(module_sp);
2238 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002239 // Flush info in the process (stack frames, etc)
2240 ProcessSP process_sp (target_sp->GetProcessSP());
2241 if (process_sp)
2242 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002243 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002244 }
2245 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002246 else
2247 {
2248 sb_error.SetErrorStringWithFormat ("invalid module");
2249 }
2250
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002251 }
2252 else
2253 {
2254 sb_error.SetErrorStringWithFormat ("invalid target");
2255 }
2256 return sb_error;
2257}
2258
2259SBError
2260SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2261{
2262 SBError sb_error;
2263
2264 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002265 TargetSP target_sp(GetSP());
2266 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002267 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002268 ModuleSP module_sp (module.GetSP());
2269 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002270 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002271 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002272 if (objfile)
2273 {
2274 SectionList *section_list = objfile->GetSectionList();
2275 if (section_list)
2276 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002277 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002278
Greg Clayton3c947372013-01-29 01:17:09 +00002279 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002280 const size_t num_sections = section_list->GetSize();
2281 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2282 {
2283 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2284 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002285 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002286 }
2287 if (changed)
2288 {
2289 // Flush info in the process (stack frames, etc)
2290 ProcessSP process_sp (target_sp->GetProcessSP());
2291 if (process_sp)
2292 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002293 }
2294 }
2295 else
2296 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002297 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002298 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2299 }
2300 }
2301 else
2302 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002303 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002304 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2305 }
2306 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002307 else
2308 {
2309 sb_error.SetErrorStringWithFormat ("invalid module");
2310 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002311 }
2312 else
2313 {
2314 sb_error.SetErrorStringWithFormat ("invalid target");
2315 }
2316 return sb_error;
2317}
2318
2319
Greg Claytone14e1922012-12-04 02:22:16 +00002320lldb::SBSymbolContextList
2321SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2322{
2323 SBSymbolContextList sb_sc_list;
2324 if (name && name[0])
2325 {
2326 TargetSP target_sp(GetSP());
2327 if (target_sp)
2328 {
2329 bool append = true;
2330 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2331 symbol_type,
2332 *sb_sc_list,
2333 append);
2334 }
2335 }
2336 return sb_sc_list;
2337
2338}
2339
Jim Ingham763b2b22015-07-07 22:12:17 +00002340lldb::SBValue
2341SBTarget::EvaluateExpression (const char *expr)
2342{
2343 TargetSP target_sp(GetSP());
2344 if (!target_sp)
2345 return SBValue();
2346
2347 SBExpressionOptions options;
2348 lldb::DynamicValueType fetch_dynamic_value = target_sp->GetPreferDynamicValue();
2349 options.SetFetchDynamicValue (fetch_dynamic_value);
2350 options.SetUnwindOnError (true);
2351 return EvaluateExpression(expr, options);
2352}
Greg Claytone14e1922012-12-04 02:22:16 +00002353
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002354lldb::SBValue
2355SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2356{
Greg Clayton5160ce52013-03-27 23:08:40 +00002357 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2358 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002359 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002360 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002361 ValueObjectSP expr_value_sp;
2362 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002363 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002364 if (target_sp)
2365 {
2366 if (expr == NULL || expr[0] == '\0')
2367 {
2368 if (log)
2369 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2370 return expr_result;
2371 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002372
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002373 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2374 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002375
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002376 if (log)
2377 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002378
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002379 frame = exe_ctx.GetFramePtr();
2380 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002381
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002382 if (target)
2383 {
2384#ifdef LLDB_CONFIGURATION_DEBUG
2385 StreamString frame_description;
2386 if (frame)
2387 frame->DumpUsingSettingsFormat (&frame_description);
2388 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2389 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2390#endif
2391 exe_results = target->EvaluateExpression (expr,
2392 frame,
2393 expr_value_sp,
2394 options.ref());
2395
2396 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2397#ifdef LLDB_CONFIGURATION_DEBUG
2398 Host::SetCrashDescription (NULL);
2399#endif
2400 }
2401 else
2402 {
2403 if (log)
2404 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2405 }
2406 }
2407#ifndef LLDB_DISABLE_PYTHON
2408 if (expr_log)
2409 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002410 expr_result.GetValue(), expr_result.GetSummary());
2411
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002412 if (log)
2413 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002414 static_cast<void*>(frame), expr,
2415 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002416#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002417
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002418 return expr_result;
2419}
2420
Greg Clayton13fbb992013-02-01 00:47:49 +00002421
2422lldb::addr_t
2423SBTarget::GetStackRedZoneSize()
2424{
2425 TargetSP target_sp(GetSP());
2426 if (target_sp)
2427 {
2428 ABISP abi_sp;
2429 ProcessSP process_sp (target_sp->GetProcessSP());
2430 if (process_sp)
2431 abi_sp = process_sp->GetABI();
2432 else
2433 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2434 if (abi_sp)
2435 return abi_sp->GetRedZoneSize();
2436 }
2437 return 0;
2438}
Ilia K8f37ca52015-02-13 14:31:06 +00002439
2440lldb::SBLaunchInfo
2441SBTarget::GetLaunchInfo () const
2442{
2443 lldb::SBLaunchInfo launch_info(NULL);
2444 TargetSP target_sp(GetSP());
2445 if (target_sp)
2446 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2447 return launch_info;
2448}
2449
2450void
2451SBTarget::SetLaunchInfo (const lldb::SBLaunchInfo &launch_info)
2452{
2453 TargetSP target_sp(GetSP());
2454 if (target_sp)
2455 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2456}