blob: 9fdd4dfe8aa757bca224f79dbdff64749aa9b419 [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 Inghamfab10e82012-03-06 00:37:27 +000055#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000056#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057#include "lldb/Target/Process.h"
Enrico Granatab10e0032015-03-04 21:33:45 +000058#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059#include "lldb/Target/Target.h"
60#include "lldb/Target/TargetList.h"
61
62#include "lldb/Interpreter/CommandReturnObject.h"
63#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000064#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67using namespace lldb;
68using namespace lldb_private;
69
70#define DEFAULT_DISASM_BYTE_SIZE 32
71
Oleksiy Vyalov37386142015-02-10 22:49:57 +000072namespace {
73
74Error
75AttachToProcess (ProcessAttachInfo &attach_info, Target &target)
76{
77 Mutex::Locker api_locker (target.GetAPIMutex ());
78
79 auto process_sp = target.GetProcessSP ();
80 if (process_sp)
81 {
82 const auto state = process_sp->GetState ();
83 if (process_sp->IsAlive () && state == eStateConnected)
84 {
85 // If we are already connected, then we have already specified the
86 // listener, so if a valid listener is supplied, we need to error out
87 // to let the client know.
88 if (attach_info.GetListener ())
89 return Error ("process is connected and already has a listener, pass empty listener");
90 }
91 }
92
93 return target.Attach (attach_info, nullptr);
94}
95
96} // namespace
97
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098//----------------------------------------------------------------------
99// SBTarget constructor
100//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000101SBTarget::SBTarget () :
102 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103{
104}
105
106SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000107 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108{
109}
110
111SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000112 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113{
114}
115
Greg Claytonefabb122010-11-05 23:17:00 +0000116const SBTarget&
117SBTarget::operator = (const SBTarget& rhs)
118{
119 if (this != &rhs)
120 m_opaque_sp = rhs.m_opaque_sp;
121 return *this;
122}
123
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124//----------------------------------------------------------------------
125// Destructor
126//----------------------------------------------------------------------
127SBTarget::~SBTarget()
128{
129}
130
Ilia Keb2c19a2015-03-10 21:59:55 +0000131bool
132SBTarget::EventIsTargetEvent (const SBEvent &event)
133{
134 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
135}
136
137SBTarget
138SBTarget::GetTargetFromEvent (const SBEvent &event)
139{
140 return Target::TargetEventData::GetTargetFromEvent (event.get());
141}
142
143uint32_t
144SBTarget::GetNumModulesFromEvent (const SBEvent &event)
145{
146 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
147 return module_list.GetSize();
148}
149
150SBModule
151SBTarget::GetModuleAtIndexFromEvent (const uint32_t idx, const SBEvent &event)
152{
153 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
154 return SBModule(module_list.GetModuleAtIndex(idx));
155}
156
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000157const char *
158SBTarget::GetBroadcasterClassName ()
159{
160 return Target::GetStaticBroadcasterClass().AsCString();
161}
162
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163bool
164SBTarget::IsValid () const
165{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000166 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
169SBProcess
170SBTarget::GetProcess ()
171{
172 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000173 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000174 TargetSP target_sp(GetSP());
175 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000176 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000177 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000178 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000179 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000180
Greg Clayton5160ce52013-03-27 23:08:40 +0000181 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000182 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000183 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
184 static_cast<void*>(target_sp.get()),
185 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000186
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 return sb_process;
188}
189
Matthew Gardinerc928de32014-10-22 07:22:56 +0000190SBPlatform
191SBTarget::GetPlatform ()
192{
193 TargetSP target_sp(GetSP());
194 if (!target_sp)
195 return SBPlatform();
196
197 SBPlatform platform;
198 platform.m_opaque_sp = target_sp->GetPlatform();
199
200 return platform;
201}
202
Greg Clayton66111032010-06-23 01:19:29 +0000203SBDebugger
204SBTarget::GetDebugger () const
205{
206 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000207 TargetSP target_sp(GetSP());
208 if (target_sp)
209 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000210 return debugger;
211}
212
Jim Ingham270684d2011-03-31 00:01:24 +0000213SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000214SBTarget::LoadCore (const char *core_file)
215{
216 SBProcess sb_process;
217 TargetSP target_sp(GetSP());
218 if (target_sp)
219 {
220 FileSpec filespec(core_file, true);
221 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
222 NULL,
223 &filespec));
224 if (process_sp)
225 {
226 process_sp->LoadCore();
227 sb_process.SetSP (process_sp);
228 }
229 }
230 return sb_process;
231}
232
233SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000234SBTarget::LaunchSimple
235(
236 char const **argv,
237 char const **envp,
238 const char *working_directory
239)
240{
241 char *stdin_path = NULL;
242 char *stdout_path = NULL;
243 char *stderr_path = NULL;
244 uint32_t launch_flags = 0;
245 bool stop_at_entry = false;
246 SBError error;
247 SBListener listener = GetDebugger().GetListener();
248 return Launch (listener,
249 argv,
250 envp,
251 stdin_path,
252 stdout_path,
253 stderr_path,
254 working_directory,
255 launch_flags,
256 stop_at_entry,
257 error);
258}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000259
Greg Claytonfbb76342013-11-20 21:07:01 +0000260SBError
261SBTarget::Install()
262{
263 SBError sb_error;
264 TargetSP target_sp(GetSP());
265 if (target_sp)
266 {
267 Mutex::Locker api_locker (target_sp->GetAPIMutex());
268 sb_error.ref() = target_sp->Install(NULL);
269 }
270 return sb_error;
271}
272
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000273SBProcess
274SBTarget::Launch
275(
Greg Clayton4b045622011-02-03 21:28:34 +0000276 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000277 char const **argv,
278 char const **envp,
279 const char *stdin_path,
280 const char *stdout_path,
281 const char *stderr_path,
282 const char *working_directory,
283 uint32_t launch_flags, // See LaunchFlags
284 bool stop_at_entry,
285 lldb::SBError& error
286)
287{
Greg Clayton5160ce52013-03-27 23:08:40 +0000288 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000289
Greg Claytonacdbe812012-01-30 09:04:36 +0000290 SBProcess sb_process;
291 ProcessSP process_sp;
292 TargetSP target_sp(GetSP());
293
Caroline Ticeceb6b132010-10-26 03:11:13 +0000294 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000295 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 +0000296 static_cast<void*>(target_sp.get()),
297 static_cast<void*>(argv), static_cast<void*>(envp),
298 stdin_path ? stdin_path : "NULL",
299 stdout_path ? stdout_path : "NULL",
300 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000301 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000302 launch_flags, stop_at_entry,
303 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000304
305 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000307 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000308
Zachary Turner6fd3f342015-02-02 18:50:01 +0000309 if (stop_at_entry)
310 launch_flags |= eLaunchFlagStopAtEntry;
311
Greg Clayton645bf542011-01-27 01:01:10 +0000312 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
313 launch_flags |= eLaunchFlagDisableASLR;
314
Greg Clayton2289fa42011-04-30 01:09:13 +0000315 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000316 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000317 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000318 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000319 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000320
Greg Claytonb9556ac2012-01-30 07:41:31 +0000321 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000322 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000323 if (state == eStateAttaching)
324 error.SetErrorString ("process attach is in progress");
325 else
326 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000327 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000328 }
Greg Clayton931180e2011-01-27 06:44:37 +0000329 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000330
Greg Clayton2289fa42011-04-30 01:09:13 +0000331 if (state == eStateConnected)
332 {
333 // If we are already connected, then we have already specified the
334 // listener, so if a valid listener is supplied, we need to error out
335 // to let the client know.
336 if (listener.IsValid())
337 {
338 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000339 return sb_process;
340 }
341 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000342
343 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
344 launch_flags |= eLaunchFlagDisableSTDIO;
345
Chaoren Lind3173f32015-05-29 19:52:29 +0000346 ProcessLaunchInfo launch_info(FileSpec{stdin_path, false},
347 FileSpec{stdout_path, false},
348 FileSpec{stderr_path, false},
349 FileSpec{working_directory, false},
350 launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000351
Greg Claytonb09c5382013-12-13 17:20:18 +0000352 Module *exe_module = target_sp->GetExecutableModulePointer();
353 if (exe_module)
354 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
355 if (argv)
356 launch_info.GetArguments().AppendArguments (argv);
357 if (envp)
358 launch_info.GetEnvironmentEntries ().SetArguments (envp);
359
360 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000361 launch_info.SetListener(listener.GetSP());
362
363 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000364
Greg Claytonb09c5382013-12-13 17:20:18 +0000365 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000366 }
367 else
368 {
369 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000371
Caroline Tice20ad3c42010-10-29 21:48:37 +0000372 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000373 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000374 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
375 static_cast<void*>(target_sp.get()),
376 static_cast<void*>(sb_process.GetSP().get()));
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;
872 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
873}
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{
Greg Clayton5160ce52013-03-27 23:08:40 +0000881 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +0000882
883 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000884 TargetSP target_sp(GetSP());
885 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +0000886 {
Jim Inghama8558b62012-05-22 00:12:20 +0000887 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000888 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000889 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +0000890 Mutex::Locker api_locker (target_sp->GetAPIMutex());
891 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +0000892 comp_unit_list.get(),
893 symbol_name,
894 name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000895 eLanguageTypeUnknown,
Greg Claytoneb023e72013-10-11 19:48:25 +0000896 skip_prologue,
897 internal,
898 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +0000899 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000900
Jim Ingham87df91b2011-09-23 00:54:11 +0000901 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000902 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
903 static_cast<void*>(target_sp.get()), symbol_name,
904 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +0000905
906 return sb_bp;
907}
908
Jim Inghamfab10e82012-03-06 00:37:27 +0000909lldb::SBBreakpoint
910SBTarget::BreakpointCreateByNames (const char *symbol_names[],
911 uint32_t num_names,
912 uint32_t name_type_mask,
913 const SBFileSpecList &module_list,
914 const SBFileSpecList &comp_unit_list)
915{
Greg Clayton5160ce52013-03-27 23:08:40 +0000916 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +0000917
918 SBBreakpoint sb_bp;
919 TargetSP target_sp(GetSP());
920 if (target_sp && num_names > 0)
921 {
922 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +0000923 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000924 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000925 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +0000926 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
927 comp_unit_list.get(),
928 symbol_names,
929 num_names,
930 name_type_mask,
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000931 eLanguageTypeUnknown,
Jim Inghama8558b62012-05-22 00:12:20 +0000932 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000933 internal,
934 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +0000935 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000936
Jim Inghamfab10e82012-03-06 00:37:27 +0000937 if (log)
938 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000939 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
940 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000941 for (uint32_t i = 0 ; i < num_names; i++)
942 {
943 char sep;
944 if (i < num_names - 1)
945 sep = ',';
946 else
947 sep = '}';
948 if (symbol_names[i] != NULL)
949 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
950 else
951 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +0000952 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000953 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
954 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000955 }
956
957 return sb_bp;
958}
Jim Ingham87df91b2011-09-23 00:54:11 +0000959
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000961SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
962 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000963{
Greg Clayton5160ce52013-03-27 23:08:40 +0000964 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000965
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000967 TargetSP target_sp(GetSP());
968 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000969 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000970 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000971 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +0000972 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000973 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000974 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000975
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000976 if (module_name && module_name[0])
977 {
Jim Ingham969795f2011-09-21 01:17:13 +0000978 FileSpecList module_spec_list;
979 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000980
Greg Claytoneb023e72013-10-11 19:48:25 +0000981 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000982 }
983 else
984 {
Greg Claytoneb023e72013-10-11 19:48:25 +0000985 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000986 }
987 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000988
989 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000990 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
991 static_cast<void*>(target_sp.get()), symbol_name_regex,
992 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000993
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000994 return sb_bp;
995}
996
Jim Ingham87df91b2011-09-23 00:54:11 +0000997lldb::SBBreakpoint
998SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000999 const SBFileSpecList &module_list,
1000 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001001{
Greg Clayton5160ce52013-03-27 23:08:40 +00001002 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001003
Jim Ingham87df91b2011-09-23 00:54:11 +00001004 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001005 TargetSP target_sp(GetSP());
1006 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001007 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001008 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001009 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001010 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001011 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001012 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001013
Greg Claytoneb023e72013-10-11 19:48:25 +00001014 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001015 }
1016
1017 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001018 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1019 static_cast<void*>(target_sp.get()), symbol_name_regex,
1020 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001021
1022 return sb_bp;
1023}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024
1025SBBreakpoint
1026SBTarget::BreakpointCreateByAddress (addr_t address)
1027{
Greg Clayton5160ce52013-03-27 23:08:40 +00001028 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001029
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001031 TargetSP target_sp(GetSP());
1032 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001033 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001034 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001035 const bool hardware = false;
1036 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001037 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001038
Caroline Ticeceb6b132010-10-26 03:11:13 +00001039 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001040 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1041 static_cast<void*>(target_sp.get()),
1042 static_cast<uint64_t>(address),
1043 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 return sb_bp;
1046}
1047
Jim Ingham969795f2011-09-21 01:17:13 +00001048lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001049SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1050 const lldb::SBFileSpec &source_file,
1051 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001052{
Greg Clayton5160ce52013-03-27 23:08:40 +00001053 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001054
1055 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001056 TargetSP target_sp(GetSP());
1057 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001058 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001059 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001060 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001061 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001062 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +00001063 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham87df91b2011-09-23 00:54:11 +00001064 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001065
Jim Ingham969795f2011-09-21 01:17:13 +00001066 if (module_name && module_name[0])
1067 {
1068 FileSpecList module_spec_list;
1069 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001070
Ilia K055ad9b2015-05-18 13:41:01 +00001071 *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 +00001072 }
1073 else
1074 {
Ilia K055ad9b2015-05-18 13:41:01 +00001075 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware, move_to_nearest_code);
Jim Ingham969795f2011-09-21 01:17:13 +00001076 }
1077 }
1078
1079 if (log)
1080 {
1081 char path[PATH_MAX];
1082 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001083 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1084 static_cast<void*>(target_sp.get()), source_regex, path,
1085 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001086 }
1087
1088 return sb_bp;
1089}
1090
Jim Ingham87df91b2011-09-23 00:54:11 +00001091lldb::SBBreakpoint
Jim Inghame7320522015-02-12 17:37:46 +00001092SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1093 const SBFileSpecList &module_list,
1094 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001095{
Greg Clayton5160ce52013-03-27 23:08:40 +00001096 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001097
1098 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001099 TargetSP target_sp(GetSP());
1100 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001101 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001102 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001103 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +00001104 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham87df91b2011-09-23 00:54:11 +00001105 RegularExpression regexp(source_regex);
Ilia K055ad9b2015-05-18 13:41:01 +00001106 *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 +00001107 }
1108
1109 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001110 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1111 static_cast<void*>(target_sp.get()), source_regex,
1112 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001113
1114 return sb_bp;
1115}
Jim Ingham969795f2011-09-21 01:17:13 +00001116
Jim Inghamfab10e82012-03-06 00:37:27 +00001117lldb::SBBreakpoint
1118SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001119 bool catch_bp,
1120 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001121{
Greg Clayton5160ce52013-03-27 23:08:40 +00001122 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001123
1124 SBBreakpoint sb_bp;
1125 TargetSP target_sp(GetSP());
1126 if (target_sp)
1127 {
1128 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001129 const bool hardware = false;
1130 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001131 }
1132
1133 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001134 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1135 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001136 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001137 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1138 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001139
1140 return sb_bp;
1141}
1142
Greg Clayton9fed0d82010-07-23 23:33:17 +00001143uint32_t
1144SBTarget::GetNumBreakpoints () const
1145{
Greg Claytonacdbe812012-01-30 09:04:36 +00001146 TargetSP target_sp(GetSP());
1147 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001148 {
1149 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001150 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001151 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001152 return 0;
1153}
1154
1155SBBreakpoint
1156SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1157{
1158 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001159 TargetSP target_sp(GetSP());
1160 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001161 {
1162 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001163 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001164 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001165 return sb_breakpoint;
1166}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167
1168bool
1169SBTarget::BreakpointDelete (break_id_t bp_id)
1170{
Greg Clayton5160ce52013-03-27 23:08:40 +00001171 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001172
Caroline Ticeceb6b132010-10-26 03:11:13 +00001173 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001174 TargetSP target_sp(GetSP());
1175 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001176 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001177 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1178 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001179 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001180
1181 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001182 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1183 static_cast<void*>(target_sp.get()),
1184 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001185
1186 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187}
1188
Johnny Chen5d043462011-09-26 22:40:50 +00001189SBBreakpoint
1190SBTarget::FindBreakpointByID (break_id_t bp_id)
1191{
Greg Clayton5160ce52013-03-27 23:08:40 +00001192 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001193
1194 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001195 TargetSP target_sp(GetSP());
1196 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001197 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001198 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1199 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001200 }
1201
1202 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001203 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1204 static_cast<void*>(target_sp.get()),
1205 static_cast<uint32_t>(bp_id),
1206 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001207
1208 return sb_breakpoint;
1209}
1210
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211bool
1212SBTarget::EnableAllBreakpoints ()
1213{
Greg Claytonacdbe812012-01-30 09:04:36 +00001214 TargetSP target_sp(GetSP());
1215 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001217 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1218 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219 return true;
1220 }
1221 return false;
1222}
1223
1224bool
1225SBTarget::DisableAllBreakpoints ()
1226{
Greg Claytonacdbe812012-01-30 09:04:36 +00001227 TargetSP target_sp(GetSP());
1228 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001230 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1231 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232 return true;
1233 }
1234 return false;
1235}
1236
1237bool
1238SBTarget::DeleteAllBreakpoints ()
1239{
Greg Claytonacdbe812012-01-30 09:04:36 +00001240 TargetSP target_sp(GetSP());
1241 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001243 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1244 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245 return true;
1246 }
1247 return false;
1248}
1249
Johnny Chen5d043462011-09-26 22:40:50 +00001250uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001251SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001252{
Greg Claytonacdbe812012-01-30 09:04:36 +00001253 TargetSP target_sp(GetSP());
1254 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001255 {
Johnny Chen01a67862011-10-14 00:42:25 +00001256 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001257 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001258 }
1259 return 0;
1260}
1261
Greg Clayton1b282f92011-10-13 18:08:26 +00001262SBWatchpoint
1263SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001264{
Johnny Chen01a67862011-10-14 00:42:25 +00001265 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001266 TargetSP target_sp(GetSP());
1267 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001268 {
Johnny Chen01a67862011-10-14 00:42:25 +00001269 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001270 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001271 }
Johnny Chen01a67862011-10-14 00:42:25 +00001272 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001273}
1274
1275bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001276SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001277{
Greg Clayton5160ce52013-03-27 23:08:40 +00001278 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001279
1280 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001281 TargetSP target_sp(GetSP());
1282 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001283 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001284 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001285 Mutex::Locker locker;
1286 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001287 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001288 }
1289
1290 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001291 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1292 static_cast<void*>(target_sp.get()),
1293 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001294
1295 return result;
1296}
1297
Greg Clayton1b282f92011-10-13 18:08:26 +00001298SBWatchpoint
1299SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001300{
Greg Clayton5160ce52013-03-27 23:08:40 +00001301 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001302
Greg Clayton1b282f92011-10-13 18:08:26 +00001303 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001304 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001305 TargetSP target_sp(GetSP());
1306 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001307 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001308 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001309 Mutex::Locker locker;
1310 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001311 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1312 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001313 }
1314
1315 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001316 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1317 static_cast<void*>(target_sp.get()),
1318 static_cast<uint32_t>(wp_id),
1319 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001320
Greg Clayton1b282f92011-10-13 18:08:26 +00001321 return sb_watchpoint;
1322}
1323
1324lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001325SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001326{
Greg Clayton5160ce52013-03-27 23:08:40 +00001327 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001328
Greg Clayton1b282f92011-10-13 18:08:26 +00001329 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001330 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001331 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001332 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001333 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001334 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001335 uint32_t watch_type = 0;
1336 if (read)
1337 watch_type |= LLDB_WATCH_TYPE_READ;
1338 if (write)
1339 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001340 if (watch_type == 0)
1341 {
1342 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1343 return sb_watchpoint;
1344 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001345
Johnny Chen7385a5a2012-05-31 22:56:36 +00001346 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001347 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001348 // This API doesn't take in a type, so we can't figure out what it is.
Greg Claytona1e5dc82015-08-11 22:53:00 +00001349 CompilerType *type = NULL;
Jim Inghama7dfb662012-10-23 07:20:06 +00001350 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001351 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001352 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001353 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001354
Greg Clayton1b282f92011-10-13 18:08:26 +00001355 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001356 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001357 static_cast<void*>(target_sp.get()), addr,
1358 static_cast<uint32_t>(size),
1359 static_cast<void*>(watchpoint_sp.get()));
1360
Greg Clayton1b282f92011-10-13 18:08:26 +00001361 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001362}
1363
1364bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001365SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001366{
Greg Claytonacdbe812012-01-30 09:04:36 +00001367 TargetSP target_sp(GetSP());
1368 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001369 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001370 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001371 Mutex::Locker locker;
1372 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001373 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001374 return true;
1375 }
1376 return false;
1377}
1378
1379bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001380SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001381{
Greg Claytonacdbe812012-01-30 09:04:36 +00001382 TargetSP target_sp(GetSP());
1383 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001384 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001385 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001386 Mutex::Locker locker;
1387 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001388 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001389 return true;
1390 }
1391 return false;
1392}
1393
Enrico Granata347c2aa2013-10-08 21:49:02 +00001394SBValue
1395SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1396{
1397 SBValue sb_value;
1398 lldb::ValueObjectSP new_value_sp;
1399 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1400 {
Enrico Granata972be532014-12-17 21:18:43 +00001401 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1402 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
Greg Claytona1e5dc82015-08-11 22:53:00 +00001403 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +00001404 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001405 }
1406 sb_value.SetSP(new_value_sp);
1407 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1408 if (log)
1409 {
1410 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001411 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1412 static_cast<void*>(m_opaque_sp.get()),
1413 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001414 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001415 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1416 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001417 }
1418 return sb_value;
1419}
1420
Enrico Granata972be532014-12-17 21:18:43 +00001421lldb::SBValue
1422SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1423{
1424 SBValue sb_value;
1425 lldb::ValueObjectSP new_value_sp;
1426 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1427 {
1428 DataExtractorSP extractor(*data);
1429 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
Greg Claytona1e5dc82015-08-11 22:53:00 +00001430 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +00001431 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1432 }
1433 sb_value.SetSP(new_value_sp);
1434 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1435 if (log)
1436 {
1437 if (new_value_sp)
1438 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1439 static_cast<void*>(m_opaque_sp.get()),
1440 new_value_sp->GetName().AsCString());
1441 else
1442 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1443 static_cast<void*>(m_opaque_sp.get()));
1444 }
1445 return sb_value;
1446}
1447
1448lldb::SBValue
1449SBTarget::CreateValueFromExpression (const char *name, const char* expr)
1450{
1451 SBValue sb_value;
1452 lldb::ValueObjectSP new_value_sp;
1453 if (IsValid() && name && *name && expr && *expr)
1454 {
1455 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1456 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1457 }
1458 sb_value.SetSP(new_value_sp);
1459 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1460 if (log)
1461 {
1462 if (new_value_sp)
1463 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1464 static_cast<void*>(m_opaque_sp.get()),
1465 new_value_sp->GetName().AsCString());
1466 else
1467 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
1468 static_cast<void*>(m_opaque_sp.get()));
1469 }
1470 return sb_value;
1471}
1472
Johnny Chen5d043462011-09-26 22:40:50 +00001473bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001474SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001475{
Greg Claytonacdbe812012-01-30 09:04:36 +00001476 TargetSP target_sp(GetSP());
1477 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001478 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001479 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001480 Mutex::Locker locker;
1481 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001482 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001483 return true;
1484 }
1485 return false;
1486}
1487
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001489lldb::SBModule
1490SBTarget::AddModule (const char *path,
1491 const char *triple,
1492 const char *uuid_cstr)
1493{
Greg Claytonb210aec2012-04-23 20:23:39 +00001494 return AddModule (path, triple, uuid_cstr, NULL);
1495}
1496
1497lldb::SBModule
1498SBTarget::AddModule (const char *path,
1499 const char *triple,
1500 const char *uuid_cstr,
1501 const char *symfile)
1502{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001503 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001504 TargetSP target_sp(GetSP());
1505 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001506 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001507 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001508 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001509 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001510
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001511 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001512 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001513
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001514 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001515 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001516 else
1517 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001518
1519 if (symfile)
1520 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001521
Greg Claytonb9a01b32012-02-26 05:51:37 +00001522 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001523 }
1524 return sb_module;
1525}
1526
Greg Clayton226cce22013-07-08 22:22:41 +00001527lldb::SBModule
1528SBTarget::AddModule (const SBModuleSpec &module_spec)
1529{
1530 lldb::SBModule sb_module;
1531 TargetSP target_sp(GetSP());
1532 if (target_sp)
1533 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1534 return sb_module;
1535}
1536
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001537bool
1538SBTarget::AddModule (lldb::SBModule &module)
1539{
Greg Claytonacdbe812012-01-30 09:04:36 +00001540 TargetSP target_sp(GetSP());
1541 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001542 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001543 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001544 return true;
1545 }
1546 return false;
1547}
1548
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001549uint32_t
1550SBTarget::GetNumModules () const
1551{
Greg Clayton5160ce52013-03-27 23:08:40 +00001552 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001553
Caroline Ticeceb6b132010-10-26 03:11:13 +00001554 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001555 TargetSP target_sp(GetSP());
1556 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001557 {
1558 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001559 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001560 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001561
1562 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001563 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1564 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001565
1566 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001567}
1568
Greg Clayton48e42542010-07-30 20:12:55 +00001569void
1570SBTarget::Clear ()
1571{
Greg Clayton5160ce52013-03-27 23:08:40 +00001572 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001573
1574 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001575 log->Printf ("SBTarget(%p)::Clear ()",
1576 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001577
Greg Clayton48e42542010-07-30 20:12:55 +00001578 m_opaque_sp.reset();
1579}
1580
1581
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582SBModule
1583SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1584{
1585 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001586 TargetSP target_sp(GetSP());
1587 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001588 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001589 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001590 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00001591 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001592 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001593 return sb_module;
1594}
1595
Greg Clayton13d19502012-01-29 06:07:39 +00001596lldb::ByteOrder
1597SBTarget::GetByteOrder ()
1598{
Greg Claytonacdbe812012-01-30 09:04:36 +00001599 TargetSP target_sp(GetSP());
1600 if (target_sp)
1601 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00001602 return eByteOrderInvalid;
1603}
1604
1605const char *
1606SBTarget::GetTriple ()
1607{
Greg Claytonacdbe812012-01-30 09:04:36 +00001608 TargetSP target_sp(GetSP());
1609 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00001610 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001611 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00001612 // Unique the string so we don't run into ownership issues since
1613 // the const strings put the string into the string pool once and
1614 // the strings never comes out
1615 ConstString const_triple (triple.c_str());
1616 return const_triple.GetCString();
1617 }
1618 return NULL;
1619}
1620
1621uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00001622SBTarget::GetDataByteSize ()
1623{
1624 TargetSP target_sp(GetSP());
1625 if (target_sp)
1626 {
1627 return target_sp->GetArchitecture().GetDataByteSize() ;
1628 }
1629 return 0;
1630}
1631
1632uint32_t
1633SBTarget::GetCodeByteSize ()
1634{
1635 TargetSP target_sp(GetSP());
1636 if (target_sp)
1637 {
1638 return target_sp->GetArchitecture().GetCodeByteSize() ;
1639 }
1640 return 0;
1641}
1642
1643uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00001644SBTarget::GetAddressByteSize()
1645{
Greg Claytonacdbe812012-01-30 09:04:36 +00001646 TargetSP target_sp(GetSP());
1647 if (target_sp)
1648 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00001649 return sizeof(void*);
1650}
1651
1652
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001653SBModule
1654SBTarget::GetModuleAtIndex (uint32_t idx)
1655{
Greg Clayton5160ce52013-03-27 23:08:40 +00001656 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001657
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001658 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001659 ModuleSP module_sp;
1660 TargetSP target_sp(GetSP());
1661 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001662 {
1663 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001664 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1665 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001666 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001667
1668 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001669 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1670 static_cast<void*>(target_sp.get()), idx,
1671 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001672
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001673 return sb_module;
1674}
1675
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001676bool
1677SBTarget::RemoveModule (lldb::SBModule module)
1678{
Greg Claytonacdbe812012-01-30 09:04:36 +00001679 TargetSP target_sp(GetSP());
1680 if (target_sp)
1681 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001682 return false;
1683}
1684
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685
1686SBBroadcaster
1687SBTarget::GetBroadcaster () const
1688{
Greg Clayton5160ce52013-03-27 23:08:40 +00001689 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001690
Greg Claytonacdbe812012-01-30 09:04:36 +00001691 TargetSP target_sp(GetSP());
1692 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001693
Caroline Ticeceb6b132010-10-26 03:11:13 +00001694 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001695 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1696 static_cast<void*>(target_sp.get()),
1697 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001698
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001699 return broadcaster;
1700}
1701
Caroline Ticedde9cff2010-09-20 05:20:02 +00001702bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001703SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001704{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001705 Stream &strm = description.ref();
1706
Greg Claytonacdbe812012-01-30 09:04:36 +00001707 TargetSP target_sp(GetSP());
1708 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00001709 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001710 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001711 }
1712 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001713 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001714
1715 return true;
1716}
1717
Greg Clayton5569e642012-02-06 01:44:54 +00001718lldb::SBSymbolContextList
1719SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00001720{
Greg Clayton5569e642012-02-06 01:44:54 +00001721 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00001722 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00001723 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001724 TargetSP target_sp(GetSP());
1725 if (target_sp)
1726 {
1727 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00001728 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00001729 const bool append = true;
1730 target_sp->GetImages().FindFunctions (ConstString(name),
1731 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001732 symbols_ok,
1733 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00001734 append,
1735 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00001736 }
Greg Claytonfe356d32011-06-21 01:34:41 +00001737 }
Greg Clayton5569e642012-02-06 01:44:54 +00001738 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00001739}
1740
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001741lldb::SBSymbolContextList
1742SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
1743{
1744 lldb::SBSymbolContextList sb_sc_list;
1745 if (name && name[0])
1746 {
1747 TargetSP target_sp(GetSP());
1748 if (target_sp)
1749 {
1750 std::string regexstr;
1751 switch (matchtype)
1752 {
1753 case eMatchTypeRegex:
1754 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
1755 break;
1756 case eMatchTypeStartsWith:
1757 regexstr = llvm::Regex::escape(name) + ".*";
1758 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1759 break;
1760 default:
1761 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
1762 break;
1763 }
1764 }
1765 }
1766 return sb_sc_list;
1767}
1768
Enrico Granata6f3533f2011-07-29 19:53:35 +00001769lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00001770SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001771{
Greg Claytonacdbe812012-01-30 09:04:36 +00001772 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001773 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001774 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001775 ConstString const_typename(typename_cstr);
1776 SymbolContext sc;
1777 const bool exact_match = false;
1778
1779 const ModuleList &module_list = target_sp->GetImages();
1780 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001781 for (size_t idx = 0; idx < count; idx++)
1782 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001783 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
1784 if (module_sp)
1785 {
1786 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
1787 if (type_sp)
1788 return SBType(type_sp);
1789 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001790 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001791
1792 // Didn't find the type in the symbols; try the Objective-C runtime
1793 // if one is installed
1794
1795 ProcessSP process_sp(target_sp->GetProcessSP());
1796
1797 if (process_sp)
1798 {
1799 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1800
1801 if (objc_language_runtime)
1802 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001803 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001804
Sean Callanan9998acd2014-12-05 01:21:59 +00001805 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001806 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001807 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001808
Sean Callanan9998acd2014-12-05 01:21:59 +00001809 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
1810 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00001811 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0]))
Sean Callanan9998acd2014-12-05 01:21:59 +00001812 {
1813 return SBType(type);
1814 }
1815 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001816 }
1817 }
1818 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001819
1820 // No matches, search for basic typename matches
1821 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1822 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001823 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001824 }
1825 return SBType();
1826}
1827
Greg Claytonb43165b2012-12-05 21:24:42 +00001828SBType
1829SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001830{
Greg Claytonacdbe812012-01-30 09:04:36 +00001831 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001832 if (target_sp)
1833 {
1834 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1835 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001836 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00001837 }
1838 return SBType();
1839}
1840
1841
1842lldb::SBTypeList
1843SBTarget::FindTypes (const char* typename_cstr)
1844{
1845 SBTypeList sb_type_list;
1846 TargetSP target_sp(GetSP());
1847 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001848 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001849 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00001850 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00001851 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001852 SymbolContext sc;
1853 TypeList type_list;
1854
Greg Clayton29399a22012-04-06 17:41:13 +00001855 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00001856 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00001857 exact_match,
1858 UINT32_MAX,
1859 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001860
Greg Claytonb43165b2012-12-05 21:24:42 +00001861 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001862 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001863 for (size_t idx = 0; idx < num_matches; idx++)
1864 {
1865 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1866 if (type_sp)
1867 sb_type_list.Append(SBType(type_sp));
1868 }
1869 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001870
1871 // Try the Objective-C runtime if one is installed
1872
1873 ProcessSP process_sp(target_sp->GetProcessSP());
1874
1875 if (process_sp)
1876 {
1877 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1878
1879 if (objc_language_runtime)
1880 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001881 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001882
Sean Callanan9998acd2014-12-05 01:21:59 +00001883 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001884 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001885 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001886
Sean Callanan9998acd2014-12-05 01:21:59 +00001887 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00001888 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001889 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00001890 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00001891 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl))
Sean Callanan9998acd2014-12-05 01:21:59 +00001892 {
1893 sb_type_list.Append(SBType(type));
1894 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001895 }
1896 }
1897 }
1898 }
1899 }
1900
1901 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00001902 {
1903 // No matches, search for basic typename matches
1904 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1905 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001906 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001907 }
1908 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001909 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001910}
1911
Greg Claytondea8cb42011-06-29 22:09:02 +00001912SBValueList
1913SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1914{
1915 SBValueList sb_value_list;
1916
Greg Claytonacdbe812012-01-30 09:04:36 +00001917 TargetSP target_sp(GetSP());
1918 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00001919 {
1920 VariableList variable_list;
1921 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00001922 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1923 append,
1924 max_matches,
1925 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00001926
1927 if (match_count > 0)
1928 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001929 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001930 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00001931 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001932 for (uint32_t i=0; i<match_count; ++i)
1933 {
1934 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1935 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00001936 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00001937 }
1938 }
1939 }
1940
1941 return sb_value_list;
1942}
1943
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001944SBValueList
1945SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
1946{
1947 SBValueList sb_value_list;
1948
1949 TargetSP target_sp(GetSP());
1950 if (name && target_sp)
1951 {
1952 VariableList variable_list;
1953 const bool append = true;
1954
1955 std::string regexstr;
1956 uint32_t match_count;
1957 switch (matchtype)
1958 {
1959 case eMatchTypeNormal:
1960 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
1961 append,
1962 max_matches,
1963 variable_list);
1964 break;
1965 case eMatchTypeRegex:
1966 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
1967 append,
1968 max_matches,
1969 variable_list);
1970 break;
1971 case eMatchTypeStartsWith:
1972 regexstr = llvm::Regex::escape(name) + ".*";
1973 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
1974 append,
1975 max_matches,
1976 variable_list);
1977 break;
1978 }
1979
1980
1981 if (match_count > 0)
1982 {
1983 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1984 if (exe_scope == NULL)
1985 exe_scope = target_sp.get();
1986 for (uint32_t i = 0; i<match_count; ++i)
1987 {
1988 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
1989 if (valobj_sp)
1990 sb_value_list.Append(SBValue(valobj_sp));
1991 }
1992 }
1993 }
1994
1995 return sb_value_list;
1996}
1997
1998
Enrico Granatabcd80b42013-01-16 18:53:52 +00001999lldb::SBValue
2000SBTarget::FindFirstGlobalVariable (const char* name)
2001{
2002 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2003 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2004 return sb_value_list.GetValueAtIndex(0);
2005 return SBValue();
2006}
2007
Jim Inghame37d6052011-09-13 00:29:56 +00002008SBSourceManager
2009SBTarget::GetSourceManager()
2010{
2011 SBSourceManager source_manager (*this);
2012 return source_manager;
2013}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002014
Sean Callanan50952e92011-12-14 23:49:37 +00002015lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002016SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2017{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002018 return ReadInstructions (base_addr, count, NULL);
2019}
2020
2021lldb::SBInstructionList
2022SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2023{
Greg Clayton9c766112012-03-06 22:24:44 +00002024 SBInstructionList sb_instructions;
2025
2026 TargetSP target_sp(GetSP());
2027 if (target_sp)
2028 {
2029 Address *addr_ptr = base_addr.get();
2030
2031 if (addr_ptr)
2032 {
2033 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2034 bool prefer_file_cache = false;
2035 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002036 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2037 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2038 prefer_file_cache,
2039 data.GetBytes(),
2040 data.GetByteSize(),
2041 error,
2042 &load_addr);
2043 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002044 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2045 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002046 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002047 *addr_ptr,
2048 data.GetBytes(),
2049 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002050 count,
2051 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002052 }
2053 }
2054
2055 return sb_instructions;
2056
2057}
2058
2059lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002060SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2061{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002062 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2063}
2064
2065lldb::SBInstructionList
2066SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2067{
Sean Callanan50952e92011-12-14 23:49:37 +00002068 SBInstructionList sb_instructions;
2069
Greg Claytonacdbe812012-01-30 09:04:36 +00002070 TargetSP target_sp(GetSP());
2071 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002072 {
2073 Address addr;
2074
2075 if (base_addr.get())
2076 addr = *base_addr.get();
2077
Greg Clayton3faf47c2013-03-28 23:42:53 +00002078 const bool data_from_file = true;
2079
Greg Claytonacdbe812012-01-30 09:04:36 +00002080 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002081 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002082 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002083 addr,
2084 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002085 size,
2086 UINT32_MAX,
2087 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002088 }
2089
2090 return sb_instructions;
2091}
2092
2093lldb::SBInstructionList
2094SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2095{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002096 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2097}
2098
2099lldb::SBInstructionList
2100SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2101{
2102 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002103}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002104
2105SBError
2106SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2107 lldb::addr_t section_base_addr)
2108{
2109 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002110 TargetSP target_sp(GetSP());
2111 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002112 {
2113 if (!section.IsValid())
2114 {
2115 sb_error.SetErrorStringWithFormat ("invalid section");
2116 }
2117 else
2118 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002119 SectionSP section_sp (section.GetSP());
2120 if (section_sp)
2121 {
2122 if (section_sp->IsThreadSpecific())
2123 {
2124 sb_error.SetErrorString ("thread specific sections are not yet supported");
2125 }
2126 else
2127 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002128 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002129 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002130 {
2131 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002132 if (process_sp)
2133 process_sp->Flush();
2134 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002135 }
2136 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002137 }
2138 }
2139 else
2140 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002141 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002142 }
2143 return sb_error;
2144}
2145
2146SBError
2147SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2148{
2149 SBError sb_error;
2150
Greg Claytonacdbe812012-01-30 09:04:36 +00002151 TargetSP target_sp(GetSP());
2152 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002153 {
2154 if (!section.IsValid())
2155 {
2156 sb_error.SetErrorStringWithFormat ("invalid section");
2157 }
2158 else
2159 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002160 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002161 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002162 {
2163 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002164 if (process_sp)
2165 process_sp->Flush();
2166 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002167 }
2168 }
2169 else
2170 {
2171 sb_error.SetErrorStringWithFormat ("invalid target");
2172 }
2173 return sb_error;
2174}
2175
2176SBError
2177SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2178{
2179 SBError sb_error;
2180
Greg Claytonacdbe812012-01-30 09:04:36 +00002181 TargetSP target_sp(GetSP());
2182 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002183 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002184 ModuleSP module_sp (module.GetSP());
2185 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002186 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002187 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002188 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002189 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002190 // The load was successful, make sure that at least some sections
2191 // changed before we notify that our module was loaded.
2192 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002193 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002194 ModuleList module_list;
2195 module_list.Append(module_sp);
2196 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002197 // Flush info in the process (stack frames, etc)
2198 ProcessSP process_sp (target_sp->GetProcessSP());
2199 if (process_sp)
2200 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002201 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002202 }
2203 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002204 else
2205 {
2206 sb_error.SetErrorStringWithFormat ("invalid module");
2207 }
2208
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002209 }
2210 else
2211 {
2212 sb_error.SetErrorStringWithFormat ("invalid target");
2213 }
2214 return sb_error;
2215}
2216
2217SBError
2218SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2219{
2220 SBError sb_error;
2221
2222 char path[PATH_MAX];
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 Claytonacdbe812012-01-30 09:04:36 +00002229 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002230 if (objfile)
2231 {
2232 SectionList *section_list = objfile->GetSectionList();
2233 if (section_list)
2234 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002235 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002236
Greg Clayton3c947372013-01-29 01:17:09 +00002237 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002238 const size_t num_sections = section_list->GetSize();
2239 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2240 {
2241 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2242 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002243 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002244 }
2245 if (changed)
2246 {
2247 // Flush info in the process (stack frames, etc)
2248 ProcessSP process_sp (target_sp->GetProcessSP());
2249 if (process_sp)
2250 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002251 }
2252 }
2253 else
2254 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002255 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002256 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2257 }
2258 }
2259 else
2260 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002261 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002262 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2263 }
2264 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002265 else
2266 {
2267 sb_error.SetErrorStringWithFormat ("invalid module");
2268 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002269 }
2270 else
2271 {
2272 sb_error.SetErrorStringWithFormat ("invalid target");
2273 }
2274 return sb_error;
2275}
2276
2277
Greg Claytone14e1922012-12-04 02:22:16 +00002278lldb::SBSymbolContextList
2279SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2280{
2281 SBSymbolContextList sb_sc_list;
2282 if (name && name[0])
2283 {
2284 TargetSP target_sp(GetSP());
2285 if (target_sp)
2286 {
2287 bool append = true;
2288 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2289 symbol_type,
2290 *sb_sc_list,
2291 append);
2292 }
2293 }
2294 return sb_sc_list;
2295
2296}
2297
Jim Ingham763b2b22015-07-07 22:12:17 +00002298lldb::SBValue
2299SBTarget::EvaluateExpression (const char *expr)
2300{
2301 TargetSP target_sp(GetSP());
2302 if (!target_sp)
2303 return SBValue();
2304
2305 SBExpressionOptions options;
2306 lldb::DynamicValueType fetch_dynamic_value = target_sp->GetPreferDynamicValue();
2307 options.SetFetchDynamicValue (fetch_dynamic_value);
2308 options.SetUnwindOnError (true);
2309 return EvaluateExpression(expr, options);
2310}
Greg Claytone14e1922012-12-04 02:22:16 +00002311
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002312lldb::SBValue
2313SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2314{
Greg Clayton5160ce52013-03-27 23:08:40 +00002315 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2316 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002317 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002318 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002319 ValueObjectSP expr_value_sp;
2320 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002321 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002322 if (target_sp)
2323 {
2324 if (expr == NULL || expr[0] == '\0')
2325 {
2326 if (log)
2327 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2328 return expr_result;
2329 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002330
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002331 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2332 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002333
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002334 if (log)
2335 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002336
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002337 frame = exe_ctx.GetFramePtr();
2338 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002339
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002340 if (target)
2341 {
2342#ifdef LLDB_CONFIGURATION_DEBUG
2343 StreamString frame_description;
2344 if (frame)
2345 frame->DumpUsingSettingsFormat (&frame_description);
2346 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2347 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2348#endif
2349 exe_results = target->EvaluateExpression (expr,
2350 frame,
2351 expr_value_sp,
2352 options.ref());
2353
2354 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2355#ifdef LLDB_CONFIGURATION_DEBUG
2356 Host::SetCrashDescription (NULL);
2357#endif
2358 }
2359 else
2360 {
2361 if (log)
2362 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2363 }
2364 }
2365#ifndef LLDB_DISABLE_PYTHON
2366 if (expr_log)
2367 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002368 expr_result.GetValue(), expr_result.GetSummary());
2369
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002370 if (log)
2371 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002372 static_cast<void*>(frame), expr,
2373 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002374#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002375
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002376 return expr_result;
2377}
2378
Greg Clayton13fbb992013-02-01 00:47:49 +00002379
2380lldb::addr_t
2381SBTarget::GetStackRedZoneSize()
2382{
2383 TargetSP target_sp(GetSP());
2384 if (target_sp)
2385 {
2386 ABISP abi_sp;
2387 ProcessSP process_sp (target_sp->GetProcessSP());
2388 if (process_sp)
2389 abi_sp = process_sp->GetABI();
2390 else
2391 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2392 if (abi_sp)
2393 return abi_sp->GetRedZoneSize();
2394 }
2395 return 0;
2396}
Ilia K8f37ca52015-02-13 14:31:06 +00002397
2398lldb::SBLaunchInfo
2399SBTarget::GetLaunchInfo () const
2400{
2401 lldb::SBLaunchInfo launch_info(NULL);
2402 TargetSP target_sp(GetSP());
2403 if (target_sp)
2404 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2405 return launch_info;
2406}
2407
2408void
2409SBTarget::SetLaunchInfo (const lldb::SBLaunchInfo &launch_info)
2410{
2411 TargetSP target_sp(GetSP());
2412 if (target_sp)
2413 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2414}