blob: 220e136430d70be5714bdff9ba40ca1758b0ad45 [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"
Jim Ingham76bb8d62016-04-28 01:40:57 +000025#include "lldb/API/SBStringList.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
41#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000042#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000050#include "lldb/Symbol/ClangASTContext.h"
51#include "lldb/Symbol/DeclVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000052#include "lldb/Symbol/ObjectFile.h"
Greg Claytonae088e52016-02-10 21:28:13 +000053#include "lldb/Symbol/SymbolFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000054#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000055#include "lldb/Symbol/VariableList.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000056#include "lldb/Target/ABI.h"
Jim Ingham0e0984e2015-09-02 01:06:46 +000057#include "lldb/Target/Language.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000058#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000059#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Process.h"
Enrico Granatab10e0032015-03-04 21:33:45 +000061#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062#include "lldb/Target/Target.h"
63#include "lldb/Target/TargetList.h"
64
65#include "lldb/Interpreter/CommandReturnObject.h"
66#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000067#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069
70using namespace lldb;
71using namespace lldb_private;
72
73#define DEFAULT_DISASM_BYTE_SIZE 32
74
Oleksiy Vyalov37386142015-02-10 22:49:57 +000075namespace {
76
77Error
78AttachToProcess (ProcessAttachInfo &attach_info, Target &target)
79{
80 Mutex::Locker api_locker (target.GetAPIMutex ());
81
82 auto process_sp = target.GetProcessSP ();
83 if (process_sp)
84 {
85 const auto state = process_sp->GetState ();
86 if (process_sp->IsAlive () && state == eStateConnected)
87 {
88 // If we are already connected, then we have already specified the
89 // listener, so if a valid listener is supplied, we need to error out
90 // to let the client know.
91 if (attach_info.GetListener ())
92 return Error ("process is connected and already has a listener, pass empty listener");
93 }
94 }
95
96 return target.Attach (attach_info, nullptr);
97}
98
99} // namespace
100
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101//----------------------------------------------------------------------
102// SBTarget constructor
103//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000104SBTarget::SBTarget () :
105 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106{
107}
108
109SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000110 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111{
112}
113
114SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000115 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116{
117}
118
Greg Claytonefabb122010-11-05 23:17:00 +0000119const SBTarget&
120SBTarget::operator = (const SBTarget& rhs)
121{
122 if (this != &rhs)
123 m_opaque_sp = rhs.m_opaque_sp;
124 return *this;
125}
126
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127//----------------------------------------------------------------------
128// Destructor
129//----------------------------------------------------------------------
130SBTarget::~SBTarget()
131{
132}
133
Ilia Keb2c19a2015-03-10 21:59:55 +0000134bool
135SBTarget::EventIsTargetEvent (const SBEvent &event)
136{
137 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
138}
139
140SBTarget
141SBTarget::GetTargetFromEvent (const SBEvent &event)
142{
143 return Target::TargetEventData::GetTargetFromEvent (event.get());
144}
145
146uint32_t
147SBTarget::GetNumModulesFromEvent (const SBEvent &event)
148{
149 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
150 return module_list.GetSize();
151}
152
153SBModule
154SBTarget::GetModuleAtIndexFromEvent (const uint32_t idx, const SBEvent &event)
155{
156 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
157 return SBModule(module_list.GetModuleAtIndex(idx));
158}
159
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000160const char *
161SBTarget::GetBroadcasterClassName ()
162{
163 return Target::GetStaticBroadcasterClass().AsCString();
164}
165
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166bool
167SBTarget::IsValid () const
168{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000169 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170}
171
172SBProcess
173SBTarget::GetProcess ()
174{
175 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000176 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000177 TargetSP target_sp(GetSP());
178 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000179 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000180 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000181 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000182 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000183
Greg Clayton5160ce52013-03-27 23:08:40 +0000184 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000185 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000186 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
187 static_cast<void*>(target_sp.get()),
188 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000189
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 return sb_process;
191}
192
Matthew Gardinerc928de32014-10-22 07:22:56 +0000193SBPlatform
194SBTarget::GetPlatform ()
195{
196 TargetSP target_sp(GetSP());
197 if (!target_sp)
198 return SBPlatform();
199
200 SBPlatform platform;
201 platform.m_opaque_sp = target_sp->GetPlatform();
202
203 return platform;
204}
205
Greg Clayton66111032010-06-23 01:19:29 +0000206SBDebugger
207SBTarget::GetDebugger () const
208{
209 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000210 TargetSP target_sp(GetSP());
211 if (target_sp)
212 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000213 return debugger;
214}
215
Jim Ingham270684d2011-03-31 00:01:24 +0000216SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000217SBTarget::LoadCore (const char *core_file)
218{
219 SBProcess sb_process;
220 TargetSP target_sp(GetSP());
221 if (target_sp)
222 {
223 FileSpec filespec(core_file, true);
224 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
225 NULL,
226 &filespec));
227 if (process_sp)
228 {
229 process_sp->LoadCore();
230 sb_process.SetSP (process_sp);
231 }
232 }
233 return sb_process;
234}
235
236SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000237SBTarget::LaunchSimple
238(
239 char const **argv,
240 char const **envp,
241 const char *working_directory
242)
243{
244 char *stdin_path = NULL;
245 char *stdout_path = NULL;
246 char *stderr_path = NULL;
247 uint32_t launch_flags = 0;
248 bool stop_at_entry = false;
249 SBError error;
250 SBListener listener = GetDebugger().GetListener();
251 return Launch (listener,
252 argv,
253 envp,
254 stdin_path,
255 stdout_path,
256 stderr_path,
257 working_directory,
258 launch_flags,
259 stop_at_entry,
260 error);
261}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000262
Greg Claytonfbb76342013-11-20 21:07:01 +0000263SBError
264SBTarget::Install()
265{
266 SBError sb_error;
267 TargetSP target_sp(GetSP());
268 if (target_sp)
269 {
270 Mutex::Locker api_locker (target_sp->GetAPIMutex());
271 sb_error.ref() = target_sp->Install(NULL);
272 }
273 return sb_error;
274}
275
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000276SBProcess
277SBTarget::Launch
278(
Greg Clayton4b045622011-02-03 21:28:34 +0000279 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000280 char const **argv,
281 char const **envp,
282 const char *stdin_path,
283 const char *stdout_path,
284 const char *stderr_path,
285 const char *working_directory,
286 uint32_t launch_flags, // See LaunchFlags
287 bool stop_at_entry,
288 lldb::SBError& error
289)
290{
Greg Clayton5160ce52013-03-27 23:08:40 +0000291 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000292
Greg Claytonacdbe812012-01-30 09:04:36 +0000293 SBProcess sb_process;
294 ProcessSP process_sp;
295 TargetSP target_sp(GetSP());
296
Caroline Ticeceb6b132010-10-26 03:11:13 +0000297 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000298 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 +0000299 static_cast<void*>(target_sp.get()),
300 static_cast<void*>(argv), static_cast<void*>(envp),
301 stdin_path ? stdin_path : "NULL",
302 stdout_path ? stdout_path : "NULL",
303 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000304 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000305 launch_flags, stop_at_entry,
306 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000307
308 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000310 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000311
Zachary Turner6fd3f342015-02-02 18:50:01 +0000312 if (stop_at_entry)
313 launch_flags |= eLaunchFlagStopAtEntry;
314
Greg Clayton645bf542011-01-27 01:01:10 +0000315 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
316 launch_flags |= eLaunchFlagDisableASLR;
317
Greg Clayton2289fa42011-04-30 01:09:13 +0000318 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000319 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000320 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000321 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000322 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000323
Greg Claytonb9556ac2012-01-30 07:41:31 +0000324 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000325 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000326 if (state == eStateAttaching)
327 error.SetErrorString ("process attach is in progress");
328 else
329 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000330 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000331 }
Greg Clayton931180e2011-01-27 06:44:37 +0000332 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000333
Greg Clayton2289fa42011-04-30 01:09:13 +0000334 if (state == eStateConnected)
335 {
336 // If we are already connected, then we have already specified the
337 // listener, so if a valid listener is supplied, we need to error out
338 // to let the client know.
339 if (listener.IsValid())
340 {
341 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000342 return sb_process;
343 }
344 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000345
346 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
347 launch_flags |= eLaunchFlagDisableSTDIO;
348
Chaoren Lind3173f32015-05-29 19:52:29 +0000349 ProcessLaunchInfo launch_info(FileSpec{stdin_path, false},
350 FileSpec{stdout_path, false},
351 FileSpec{stderr_path, false},
352 FileSpec{working_directory, false},
353 launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000354
Greg Claytonb09c5382013-12-13 17:20:18 +0000355 Module *exe_module = target_sp->GetExecutableModulePointer();
356 if (exe_module)
357 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
358 if (argv)
359 launch_info.GetArguments().AppendArguments (argv);
360 if (envp)
361 launch_info.GetEnvironmentEntries ().SetArguments (envp);
362
363 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000364 launch_info.SetListener(listener.GetSP());
365
366 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000367
Greg Claytonb09c5382013-12-13 17:20:18 +0000368 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000369 }
370 else
371 {
372 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000374
Caroline Tice20ad3c42010-10-29 21:48:37 +0000375 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000376 if (log)
Pavel Labathd2474ff2016-02-02 15:16:20 +0000377 log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p), SBError(%s)", static_cast<void *>(target_sp.get()),
378 static_cast<void *>(sb_process.GetSP().get()), error.GetCString());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000379
Greg Clayton5d5028b2010-10-06 03:53:16 +0000380 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381}
382
Greg Clayton0e615682012-02-24 05:03:03 +0000383SBProcess
384SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
385{
Greg Clayton5160ce52013-03-27 23:08:40 +0000386 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000387
Greg Clayton0e615682012-02-24 05:03:03 +0000388 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000389 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000390
Greg Clayton0e615682012-02-24 05:03:03 +0000391 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000392 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
393 static_cast<void*>(target_sp.get()));
394
Greg Clayton0e615682012-02-24 05:03:03 +0000395 if (target_sp)
396 {
397 Mutex::Locker api_locker (target_sp->GetAPIMutex());
398 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000399 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000400 ProcessSP process_sp = target_sp->GetProcessSP();
401 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000402 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000403 state = process_sp->GetState();
404
405 if (process_sp->IsAlive() && state != eStateConnected)
406 {
407 if (state == eStateAttaching)
408 error.SetErrorString ("process attach is in progress");
409 else
410 error.SetErrorString ("a process is already being debugged");
411 return sb_process;
412 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000413 }
Greg Clayton0e615682012-02-24 05:03:03 +0000414 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000415
416 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
417
Greg Clayton3e32ad62014-05-07 20:16:06 +0000418 if (!launch_info.GetExecutableFile())
419 {
420 Module *exe_module = target_sp->GetExecutableModulePointer();
421 if (exe_module)
422 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
423 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000424
425 const ArchSpec &arch_spec = target_sp->GetArchitecture();
426 if (arch_spec.IsValid())
427 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000428
Greg Clayton8012cad2014-11-17 19:39:20 +0000429 error.SetError (target_sp->Launch (launch_info, NULL));
Greg Claytonb09c5382013-12-13 17:20:18 +0000430 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000431 }
432 else
433 {
434 error.SetErrorString ("SBTarget is invalid");
435 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000436
Greg Clayton0e615682012-02-24 05:03:03 +0000437 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
438 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000439 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000440 static_cast<void*>(target_sp.get()),
441 static_cast<void*>(sb_process.GetSP().get()));
442
Greg Clayton0e615682012-02-24 05:03:03 +0000443 return sb_process;
444}
445
446lldb::SBProcess
447SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
448{
Greg Clayton5160ce52013-03-27 23:08:40 +0000449 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000450
Greg Clayton0e615682012-02-24 05:03:03 +0000451 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000452 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000453
Sean Callanan575a4542012-10-20 00:21:31 +0000454 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000455 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
456 static_cast<void*>(target_sp.get()));
457
Greg Clayton0e615682012-02-24 05:03:03 +0000458 if (target_sp)
459 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000460 ProcessAttachInfo &attach_info = sb_attach_info.ref();
461 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Greg Clayton0e615682012-02-24 05:03:03 +0000462 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000463 PlatformSP platform_sp = target_sp->GetPlatform();
464 // See if we can pre-verify if a process exists or not
465 if (platform_sp && platform_sp->IsConnected())
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000466 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000467 lldb::pid_t attach_pid = attach_info.GetProcessID();
468 ProcessInstanceInfo instance_info;
469 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
Han Ming Ongcec8c902012-02-29 00:12:56 +0000470 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000471 attach_info.SetUserID(instance_info.GetEffectiveUserID());
472 }
473 else
474 {
475 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
476 if (log)
Greg Clayton91e407e2012-09-27 00:03:39 +0000477 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000478 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
479 static_cast<void*>(target_sp.get()), error.GetCString());
Greg Clayton91e407e2012-09-27 00:03:39 +0000480 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000481 return sb_process;
Han Ming Ongcec8c902012-02-29 00:12:56 +0000482 }
483 }
Greg Clayton0e615682012-02-24 05:03:03 +0000484 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000485 error.SetError(AttachToProcess(attach_info, *target_sp));
486 if (error.Success())
487 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000488 }
489 else
490 {
491 error.SetErrorString ("SBTarget is invalid");
492 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000493
Sean Callanan575a4542012-10-20 00:21:31 +0000494 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000495 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000496 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000497 static_cast<void*>(sb_process.GetSP().get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000498
Greg Clayton0e615682012-02-24 05:03:03 +0000499 return sb_process;
500}
501
502
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000503#if defined(__APPLE__)
504
505lldb::SBProcess
506SBTarget::AttachToProcessWithID (SBListener &listener,
507 ::pid_t pid,
508 lldb::SBError& error)
509{
510 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
511}
512
513#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000514
515lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000516SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000517(
Greg Clayton4b045622011-02-03 21:28:34 +0000518 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000519 lldb::pid_t pid,// The process ID to attach to
520 SBError& error // An error explaining what went wrong if attach fails
521)
522{
Greg Clayton5160ce52013-03-27 23:08:40 +0000523 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000524
Greg Clayton524e60b2010-10-06 22:10:17 +0000525 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000526 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000527
528 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000529 log->Printf ("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
530 static_cast<void*>(target_sp.get()),
531 __FUNCTION__,
532 pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000533
Greg Claytonacdbe812012-01-30 09:04:36 +0000534 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000535 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000536 ProcessAttachInfo attach_info;
537 attach_info.SetProcessID (pid);
538 if (listener.IsValid())
539 attach_info.SetListener(listener.GetSP());
Greg Clayton0c74e782011-06-24 03:21:43 +0000540
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000541 ProcessInstanceInfo instance_info;
542 if (target_sp->GetPlatform ()->GetProcessInfo (pid, instance_info))
543 attach_info.SetUserID (instance_info.GetEffectiveUserID ());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000544
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000545 error.SetError (AttachToProcess (attach_info, *target_sp));
546 if (error.Success ())
547 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000548 }
549 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000550 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000551
Sean Callanan575a4542012-10-20 00:21:31 +0000552 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000553 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
554 static_cast<void*>(target_sp.get ()),
555 __FUNCTION__,
556 static_cast<void*>(sb_process.GetSP().get ()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000557 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000558}
559
560lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000561SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +0000562(
Greg Clayton4b045622011-02-03 21:28:34 +0000563 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000564 const char *name, // basename of process to attach to
565 bool wait_for, // if true wait for a new instance of "name" to be launched
566 SBError& error // An error explaining what went wrong if attach fails
567)
568{
Greg Clayton5160ce52013-03-27 23:08:40 +0000569 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000570
Greg Clayton524e60b2010-10-06 22:10:17 +0000571 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000572 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000573
Sean Callanan575a4542012-10-20 00:21:31 +0000574 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000575 log->Printf ("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
576 static_cast<void*>(target_sp.get()),
577 __FUNCTION__,
578 name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000579 wait_for ? "true" : "false");
580
Greg Claytonacdbe812012-01-30 09:04:36 +0000581 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000582 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000583 ProcessAttachInfo attach_info;
584 attach_info.GetExecutableFile().SetFile(name, false);
585 attach_info.SetWaitForLaunch(wait_for);
586 if (listener.IsValid())
587 attach_info.SetListener(listener.GetSP());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000588
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000589 error.SetError (AttachToProcess (attach_info, *target_sp));
590 if (error.Success ())
591 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000592 }
593 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000594 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000595
Sean Callanan575a4542012-10-20 00:21:31 +0000596 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000597 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000598 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000599 __FUNCTION__,
600 static_cast<void*>(sb_process.GetSP().get()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000601 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000602}
603
James McIlree9631aae2011-03-04 00:31:13 +0000604lldb::SBProcess
605SBTarget::ConnectRemote
606(
607 SBListener &listener,
608 const char *url,
609 const char *plugin_name,
610 SBError& error
611)
612{
Greg Clayton5160ce52013-03-27 23:08:40 +0000613 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000614
James McIlree9631aae2011-03-04 00:31:13 +0000615 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000616 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000617 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000618
Sean Callanan575a4542012-10-20 00:21:31 +0000619 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000620 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
621 static_cast<void*>(target_sp.get()), url, plugin_name);
622
Greg Claytonacdbe812012-01-30 09:04:36 +0000623 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000624 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000625 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +0000626 if (listener.IsValid())
Jim Ingham583bbb12016-03-07 21:50:25 +0000627 process_sp = target_sp->CreateProcess (listener.m_opaque_sp, plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000628 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000629 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000630
Greg Claytonb9556ac2012-01-30 07:41:31 +0000631 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000632 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000633 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000634 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +0000635 }
636 else
637 {
638 error.SetErrorString ("unable to create lldb_private::Process");
639 }
640 }
641 else
642 {
643 error.SetErrorString ("SBTarget is invalid");
644 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000645
Sean Callanan575a4542012-10-20 00:21:31 +0000646 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000647 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000648 static_cast<void*>(target_sp.get()),
649 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +0000650 return sb_process;
651}
652
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653SBFileSpec
654SBTarget::GetExecutable ()
655{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000656
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +0000658 TargetSP target_sp(GetSP());
659 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000661 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +0000662 if (exe_module)
663 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000665
Greg Clayton5160ce52013-03-27 23:08:40 +0000666 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000667 if (log)
668 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000669 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
670 static_cast<void*>(target_sp.get()),
671 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000672 }
673
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000674 return exe_file_spec;
675}
676
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678SBTarget::operator == (const SBTarget &rhs) const
679{
Greg Clayton66111032010-06-23 01:19:29 +0000680 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000681}
682
683bool
684SBTarget::operator != (const SBTarget &rhs) const
685{
Greg Clayton66111032010-06-23 01:19:29 +0000686 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687}
688
Greg Claytonb9556ac2012-01-30 07:41:31 +0000689lldb::TargetSP
690SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +0000691{
692 return m_opaque_sp;
693}
694
Greg Clayton66111032010-06-23 01:19:29 +0000695void
Greg Claytonb9556ac2012-01-30 07:41:31 +0000696SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +0000697{
698 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699}
700
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000701lldb::SBAddress
702SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000703{
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000704 lldb::SBAddress sb_addr;
705 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +0000706 TargetSP target_sp(GetSP());
707 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000708 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000709 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +0000710 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000711 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000712 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000713
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000714 // We have a load address that isn't in a section, just return an address
715 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +0000716 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000717 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000718}
719
Matthew Gardinerc928de32014-10-22 07:22:56 +0000720lldb::SBAddress
721SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
722{
723 lldb::SBAddress sb_addr;
724 Address &addr = sb_addr.ref();
725 TargetSP target_sp(GetSP());
726 if (target_sp)
727 {
728 Mutex::Locker api_locker (target_sp->GetAPIMutex());
729 if (target_sp->ResolveFileAddress (file_addr, addr))
730 return sb_addr;
731 }
732
733 addr.SetRawAddress(file_addr);
734 return sb_addr;
735}
Greg Claytond5944cd2013-12-06 01:12:00 +0000736
737lldb::SBAddress
738SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
739{
740 lldb::SBAddress sb_addr;
741 Address &addr = sb_addr.ref();
742 TargetSP target_sp(GetSP());
743 if (target_sp)
744 {
745 Mutex::Locker api_locker (target_sp->GetAPIMutex());
746 if (target_sp->ResolveLoadAddress (vm_addr, addr))
747 return sb_addr;
748 }
749
750 // We have a load address that isn't in a section, just return an address
751 // with the offset filled in (the address) and the section set to NULL
752 addr.SetRawAddress(vm_addr);
753 return sb_addr;
754}
755
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000756SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +0000757SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
758 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000759{
760 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +0000761 if (addr.IsValid())
762 {
763 TargetSP target_sp(GetSP());
764 if (target_sp)
765 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
766 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000767 return sc;
768}
769
Matthew Gardinerc928de32014-10-22 07:22:56 +0000770size_t
771SBTarget::ReadMemory (const SBAddress addr,
772 void *buf,
773 size_t size,
774 lldb::SBError &error)
775{
776 SBError sb_error;
777 size_t bytes_read = 0;
778 TargetSP target_sp(GetSP());
779 if (target_sp)
780 {
781 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8691dc52014-11-04 00:56:30 +0000782 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
783 }
784 else
785 {
786 sb_error.SetErrorString("invalid target");
Matthew Gardinerc928de32014-10-22 07:22:56 +0000787 }
788
789 return bytes_read;
790}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000791
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000793SBTarget::BreakpointCreateByLocation (const char *file,
794 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000795{
Greg Clayton7481c202010-11-08 00:28:40 +0000796 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797}
798
799SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000800SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
801 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802{
Jim Ingham24111672016-03-09 18:59:13 +0000803 return BreakpointCreateByLocation(sb_file_spec, line, 0);
804}
805
806SBBreakpoint
807SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
808 uint32_t line,
809 lldb::addr_t offset)
810{
Greg Clayton5160ce52013-03-27 23:08:40 +0000811 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000812
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000814 TargetSP target_sp(GetSP());
815 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000816 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000817 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000818
Greg Clayton1f746072012-08-29 21:13:06 +0000819 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +0000820 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +0000821 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000822 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +0000823 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham24111672016-03-09 18:59:13 +0000824 *sb_bp = target_sp->CreateBreakpoint (NULL,
825 *sb_file_spec,
826 line,
827 offset,
828 check_inlines,
829 skip_prologue,
830 internal,
831 hardware,
832 move_to_nearest_code);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000833 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000834
835 if (log)
836 {
837 SBStream sstr;
838 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000839 char path[PATH_MAX];
840 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000841 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
842 static_cast<void*>(target_sp.get()), path, line,
843 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000844 }
845
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 return sb_bp;
847}
848
849SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000850SBTarget::BreakpointCreateByName (const char *symbol_name,
851 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852{
Greg Clayton5160ce52013-03-27 23:08:40 +0000853 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000854
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000856 TargetSP target_sp(GetSP());
857 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000859 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000860
Jim Inghama8558b62012-05-22 00:12:20 +0000861 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000862 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000863 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham24111672016-03-09 18:59:13 +0000864 const lldb::addr_t offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865 if (module_name && module_name[0])
866 {
Jim Ingham969795f2011-09-21 01:17:13 +0000867 FileSpecList module_spec_list;
868 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham24111672016-03-09 18:59:13 +0000869 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 }
871 else
872 {
Jim Ingham24111672016-03-09 18:59:13 +0000873 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874 }
875 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000876
Caroline Ticeceb6b132010-10-26 03:11:13 +0000877 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000878 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
879 static_cast<void*>(target_sp.get()), symbol_name,
880 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000881
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882 return sb_bp;
883}
884
Jim Ingham87df91b2011-09-23 00:54:11 +0000885lldb::SBBreakpoint
886SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000887 const SBFileSpecList &module_list,
888 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000889{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000890 uint32_t name_type_mask = eFunctionNameTypeAuto;
Jim Ingham0fcdac32015-11-06 22:48:59 +0000891 return BreakpointCreateByName (symbol_name, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list);
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000892}
893
894lldb::SBBreakpoint
895SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000896 uint32_t name_type_mask,
897 const SBFileSpecList &module_list,
898 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000899{
Jim Ingham0fcdac32015-11-06 22:48:59 +0000900 return BreakpointCreateByName (symbol_name, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list);
901}
902
903lldb::SBBreakpoint
904SBTarget::BreakpointCreateByName (const char *symbol_name,
905 uint32_t name_type_mask,
906 LanguageType symbol_language,
907 const SBFileSpecList &module_list,
908 const SBFileSpecList &comp_unit_list)
909{
Greg Clayton5160ce52013-03-27 23:08:40 +0000910 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +0000911
912 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000913 TargetSP target_sp(GetSP());
914 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +0000915 {
Jim Inghama8558b62012-05-22 00:12:20 +0000916 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000917 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000918 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +0000919 Mutex::Locker api_locker (target_sp->GetAPIMutex());
920 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +0000921 comp_unit_list.get(),
922 symbol_name,
923 name_type_mask,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000924 symbol_language,
Jim Ingham24111672016-03-09 18:59:13 +0000925 0,
Greg Claytoneb023e72013-10-11 19:48:25 +0000926 skip_prologue,
927 internal,
928 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +0000929 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000930
Jim Ingham87df91b2011-09-23 00:54:11 +0000931 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000932 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
933 static_cast<void*>(target_sp.get()), symbol_name,
934 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +0000935
936 return sb_bp;
937}
938
Jim Inghamfab10e82012-03-06 00:37:27 +0000939lldb::SBBreakpoint
940SBTarget::BreakpointCreateByNames (const char *symbol_names[],
941 uint32_t num_names,
942 uint32_t name_type_mask,
943 const SBFileSpecList &module_list,
944 const SBFileSpecList &comp_unit_list)
945{
Jim Ingham0fcdac32015-11-06 22:48:59 +0000946 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list);
947}
948
949lldb::SBBreakpoint
950SBTarget::BreakpointCreateByNames (const char *symbol_names[],
951 uint32_t num_names,
952 uint32_t name_type_mask,
953 LanguageType symbol_language,
954 const SBFileSpecList &module_list,
955 const SBFileSpecList &comp_unit_list)
956{
Jim Ingham24111672016-03-09 18:59:13 +0000957 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 0, module_list, comp_unit_list);
958}
959
960lldb::SBBreakpoint
961SBTarget::BreakpointCreateByNames (const char *symbol_names[],
962 uint32_t num_names,
963 uint32_t name_type_mask,
964 LanguageType symbol_language,
965 lldb::addr_t offset,
966 const SBFileSpecList &module_list,
967 const SBFileSpecList &comp_unit_list)
968{
Greg Clayton5160ce52013-03-27 23:08:40 +0000969 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +0000970
971 SBBreakpoint sb_bp;
972 TargetSP target_sp(GetSP());
973 if (target_sp && num_names > 0)
974 {
975 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +0000976 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000977 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000978 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +0000979 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Jim Ingham0fcdac32015-11-06 22:48:59 +0000980 comp_unit_list.get(),
981 symbol_names,
982 num_names,
Jim Ingham24111672016-03-09 18:59:13 +0000983 name_type_mask,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000984 symbol_language,
Jim Ingham24111672016-03-09 18:59:13 +0000985 offset,
Jim Ingham0fcdac32015-11-06 22:48:59 +0000986 skip_prologue,
987 internal,
988 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +0000989 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000990
Jim Inghamfab10e82012-03-06 00:37:27 +0000991 if (log)
992 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000993 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
994 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000995 for (uint32_t i = 0 ; i < num_names; i++)
996 {
997 char sep;
998 if (i < num_names - 1)
999 sep = ',';
1000 else
1001 sep = '}';
1002 if (symbol_names[i] != NULL)
1003 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1004 else
1005 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +00001006 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001007 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
1008 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001009 }
1010
1011 return sb_bp;
1012}
Jim Ingham87df91b2011-09-23 00:54:11 +00001013
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001015SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1016 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017{
Jim Ingham0fcdac32015-11-06 22:48:59 +00001018 SBFileSpecList module_spec_list;
1019 SBFileSpecList comp_unit_list;
1020 if (module_name && module_name[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001021 {
Jim Ingham0fcdac32015-11-06 22:48:59 +00001022 module_spec_list.Append (FileSpec (module_name, false));
1023
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001024 }
Jim Ingham0fcdac32015-11-06 22:48:59 +00001025 return BreakpointCreateByRegex (symbol_name_regex, eLanguageTypeUnknown, module_spec_list, comp_unit_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026}
1027
Jim Ingham87df91b2011-09-23 00:54:11 +00001028lldb::SBBreakpoint
1029SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +00001030 const SBFileSpecList &module_list,
1031 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001032{
Jim Ingham0fcdac32015-11-06 22:48:59 +00001033 return BreakpointCreateByRegex (symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list);
1034}
1035
1036lldb::SBBreakpoint
1037SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1038 LanguageType symbol_language,
1039 const SBFileSpecList &module_list,
1040 const SBFileSpecList &comp_unit_list)
1041{
Greg Clayton5160ce52013-03-27 23:08:40 +00001042 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043
Jim Ingham87df91b2011-09-23 00:54:11 +00001044 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001045 TargetSP target_sp(GetSP());
1046 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001047 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001048 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001049 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001050 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001051 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001052 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Ingham0fcdac32015-11-06 22:48:59 +00001053
1054 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, symbol_language, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001055 }
1056
1057 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001058 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1059 static_cast<void*>(target_sp.get()), symbol_name_regex,
1060 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001061
1062 return sb_bp;
1063}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001064
1065SBBreakpoint
1066SBTarget::BreakpointCreateByAddress (addr_t address)
1067{
Greg Clayton5160ce52013-03-27 23:08:40 +00001068 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001069
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001070 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001071 TargetSP target_sp(GetSP());
1072 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001073 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001074 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001075 const bool hardware = false;
1076 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001077 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001078
Caroline Ticeceb6b132010-10-26 03:11:13 +00001079 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001080 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1081 static_cast<void*>(target_sp.get()),
1082 static_cast<uint64_t>(address),
1083 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001084
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 return sb_bp;
1086}
1087
Jim Ingham055a08a2015-11-17 03:39:13 +00001088SBBreakpoint
1089SBTarget::BreakpointCreateBySBAddress (SBAddress &sb_address)
1090{
1091 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1092
1093 SBBreakpoint sb_bp;
1094 TargetSP target_sp(GetSP());
1095 if (!sb_address.IsValid())
1096 {
1097 if (log)
1098 log->Printf ("SBTarget(%p)::BreakpointCreateBySBAddress called with invalid address",
1099 static_cast<void*>(target_sp.get()));
1100 return sb_bp;
1101 }
1102
1103 if (target_sp)
1104 {
1105 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1106 const bool hardware = false;
1107 *sb_bp = target_sp->CreateBreakpoint (sb_address.ref(), false, hardware);
1108 }
1109
1110 if (log)
1111 {
1112 SBStream s;
1113 sb_address.GetDescription(s);
1114 log->Printf ("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => SBBreakpoint(%p)",
1115 static_cast<void*>(target_sp.get()),
1116 s.GetData(),
1117 static_cast<void*>(sb_bp.get()));
1118 }
1119
1120 return sb_bp;
1121}
1122
Jim Ingham969795f2011-09-21 01:17:13 +00001123lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001124SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1125 const lldb::SBFileSpec &source_file,
1126 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001127{
Jim Ingham76bb8d62016-04-28 01:40:57 +00001128 SBFileSpecList module_spec_list;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001129
Jim Ingham969795f2011-09-21 01:17:13 +00001130 if (module_name && module_name[0])
1131 {
Jim Ingham969795f2011-09-21 01:17:13 +00001132 module_spec_list.Append (FileSpec (module_name, false));
Jim Ingham969795f2011-09-21 01:17:13 +00001133 }
Jim Ingham76bb8d62016-04-28 01:40:57 +00001134
1135 SBFileSpecList source_file_list;
1136 if (source_file.IsValid())
Jim Ingham969795f2011-09-21 01:17:13 +00001137 {
Jim Ingham76bb8d62016-04-28 01:40:57 +00001138 source_file_list.Append(source_file);
Jim Ingham969795f2011-09-21 01:17:13 +00001139 }
Jim Ingham76bb8d62016-04-28 01:40:57 +00001140
1141 return BreakpointCreateBySourceRegex (source_regex, module_spec_list, source_file_list);
Jim Ingham969795f2011-09-21 01:17:13 +00001142
Jim Ingham969795f2011-09-21 01:17:13 +00001143}
1144
Jim Ingham87df91b2011-09-23 00:54:11 +00001145lldb::SBBreakpoint
Jim Inghame7320522015-02-12 17:37:46 +00001146SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1147 const SBFileSpecList &module_list,
1148 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001149{
Jim Ingham76bb8d62016-04-28 01:40:57 +00001150 return BreakpointCreateBySourceRegex(source_regex, module_list, source_file_list, SBStringList());
1151}
1152
1153lldb::SBBreakpoint
1154SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1155 const SBFileSpecList &module_list,
1156 const lldb::SBFileSpecList &source_file_list,
1157 const SBStringList &func_names)
1158{
Greg Clayton5160ce52013-03-27 23:08:40 +00001159 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001160
1161 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001162 TargetSP target_sp(GetSP());
1163 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001164 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001165 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001166 const bool hardware = false;
Ilia K055ad9b2015-05-18 13:41:01 +00001167 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
Jim Ingham87df91b2011-09-23 00:54:11 +00001168 RegularExpression regexp(source_regex);
Jim Ingham76bb8d62016-04-28 01:40:57 +00001169 std::unordered_set<std::string> func_names_set;
1170 for (size_t i = 0; i < func_names.GetSize(); i++)
1171 {
1172 func_names_set.insert(func_names.GetStringAtIndex(i));
1173 }
1174
1175 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(),
1176 source_file_list.get(),
1177 func_names_set,
1178 regexp,
1179 false,
1180 hardware,
1181 move_to_nearest_code);
Jim Ingham87df91b2011-09-23 00:54:11 +00001182 }
1183
1184 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001185 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1186 static_cast<void*>(target_sp.get()), source_regex,
1187 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001188
1189 return sb_bp;
1190}
Jim Ingham969795f2011-09-21 01:17:13 +00001191
Jim Inghamfab10e82012-03-06 00:37:27 +00001192lldb::SBBreakpoint
1193SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001194 bool catch_bp,
1195 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001196{
Greg Clayton5160ce52013-03-27 23:08:40 +00001197 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001198
1199 SBBreakpoint sb_bp;
1200 TargetSP target_sp(GetSP());
1201 if (target_sp)
1202 {
1203 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001204 const bool hardware = false;
1205 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001206 }
1207
1208 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001209 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1210 static_cast<void*>(target_sp.get()),
Jim Ingham0e0984e2015-09-02 01:06:46 +00001211 Language::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001212 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1213 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001214
1215 return sb_bp;
1216}
1217
Greg Clayton9fed0d82010-07-23 23:33:17 +00001218uint32_t
1219SBTarget::GetNumBreakpoints () const
1220{
Greg Claytonacdbe812012-01-30 09:04:36 +00001221 TargetSP target_sp(GetSP());
1222 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001223 {
1224 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001225 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001226 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001227 return 0;
1228}
1229
1230SBBreakpoint
1231SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1232{
1233 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001234 TargetSP target_sp(GetSP());
1235 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001236 {
1237 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001238 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001239 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001240 return sb_breakpoint;
1241}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242
1243bool
1244SBTarget::BreakpointDelete (break_id_t bp_id)
1245{
Greg Clayton5160ce52013-03-27 23:08:40 +00001246 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001247
Caroline Ticeceb6b132010-10-26 03:11:13 +00001248 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001249 TargetSP target_sp(GetSP());
1250 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001251 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001252 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1253 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001254 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001255
1256 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001257 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1258 static_cast<void*>(target_sp.get()),
1259 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001260
1261 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262}
1263
Johnny Chen5d043462011-09-26 22:40:50 +00001264SBBreakpoint
1265SBTarget::FindBreakpointByID (break_id_t bp_id)
1266{
Greg Clayton5160ce52013-03-27 23:08:40 +00001267 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001268
1269 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001270 TargetSP target_sp(GetSP());
1271 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001272 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001273 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1274 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001275 }
1276
1277 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001278 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1279 static_cast<void*>(target_sp.get()),
1280 static_cast<uint32_t>(bp_id),
1281 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001282
1283 return sb_breakpoint;
1284}
1285
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286bool
1287SBTarget::EnableAllBreakpoints ()
1288{
Greg Claytonacdbe812012-01-30 09:04:36 +00001289 TargetSP target_sp(GetSP());
1290 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001292 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1293 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294 return true;
1295 }
1296 return false;
1297}
1298
1299bool
1300SBTarget::DisableAllBreakpoints ()
1301{
Greg Claytonacdbe812012-01-30 09:04:36 +00001302 TargetSP target_sp(GetSP());
1303 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001305 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1306 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307 return true;
1308 }
1309 return false;
1310}
1311
1312bool
1313SBTarget::DeleteAllBreakpoints ()
1314{
Greg Claytonacdbe812012-01-30 09:04:36 +00001315 TargetSP target_sp(GetSP());
1316 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001318 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1319 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 return true;
1321 }
1322 return false;
1323}
1324
Johnny Chen5d043462011-09-26 22:40:50 +00001325uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001326SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001327{
Greg Claytonacdbe812012-01-30 09:04:36 +00001328 TargetSP target_sp(GetSP());
1329 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001330 {
Johnny Chen01a67862011-10-14 00:42:25 +00001331 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001332 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001333 }
1334 return 0;
1335}
1336
Greg Clayton1b282f92011-10-13 18:08:26 +00001337SBWatchpoint
1338SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001339{
Johnny Chen01a67862011-10-14 00:42:25 +00001340 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001341 TargetSP target_sp(GetSP());
1342 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001343 {
Johnny Chen01a67862011-10-14 00:42:25 +00001344 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001345 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001346 }
Johnny Chen01a67862011-10-14 00:42:25 +00001347 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001348}
1349
1350bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001351SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001352{
Greg Clayton5160ce52013-03-27 23:08:40 +00001353 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001354
1355 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001356 TargetSP target_sp(GetSP());
1357 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001358 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001359 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001360 Mutex::Locker locker;
1361 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001362 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001363 }
1364
1365 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001366 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1367 static_cast<void*>(target_sp.get()),
1368 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001369
1370 return result;
1371}
1372
Greg Clayton1b282f92011-10-13 18:08:26 +00001373SBWatchpoint
1374SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001375{
Greg Clayton5160ce52013-03-27 23:08:40 +00001376 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001377
Greg Clayton1b282f92011-10-13 18:08:26 +00001378 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001379 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001380 TargetSP target_sp(GetSP());
1381 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001382 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001383 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001384 Mutex::Locker locker;
1385 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001386 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1387 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001388 }
1389
1390 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001391 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1392 static_cast<void*>(target_sp.get()),
1393 static_cast<uint32_t>(wp_id),
1394 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001395
Greg Clayton1b282f92011-10-13 18:08:26 +00001396 return sb_watchpoint;
1397}
1398
1399lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001400SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001401{
Greg Clayton5160ce52013-03-27 23:08:40 +00001402 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001403
Greg Clayton1b282f92011-10-13 18:08:26 +00001404 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001405 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001406 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001407 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001408 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001409 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001410 uint32_t watch_type = 0;
1411 if (read)
1412 watch_type |= LLDB_WATCH_TYPE_READ;
1413 if (write)
1414 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001415 if (watch_type == 0)
1416 {
1417 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1418 return sb_watchpoint;
1419 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001420
Johnny Chen7385a5a2012-05-31 22:56:36 +00001421 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001422 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001423 // This API doesn't take in a type, so we can't figure out what it is.
Greg Claytona1e5dc82015-08-11 22:53:00 +00001424 CompilerType *type = NULL;
Jim Inghama7dfb662012-10-23 07:20:06 +00001425 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001426 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001427 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001428 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001429
Greg Clayton1b282f92011-10-13 18:08:26 +00001430 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001431 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001432 static_cast<void*>(target_sp.get()), addr,
1433 static_cast<uint32_t>(size),
1434 static_cast<void*>(watchpoint_sp.get()));
1435
Greg Clayton1b282f92011-10-13 18:08:26 +00001436 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001437}
1438
1439bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001440SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001441{
Greg Claytonacdbe812012-01-30 09:04:36 +00001442 TargetSP target_sp(GetSP());
1443 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001444 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001445 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001446 Mutex::Locker locker;
1447 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001448 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001449 return true;
1450 }
1451 return false;
1452}
1453
1454bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001455SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001456{
Greg Claytonacdbe812012-01-30 09:04:36 +00001457 TargetSP target_sp(GetSP());
1458 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001459 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001460 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001461 Mutex::Locker locker;
1462 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001463 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001464 return true;
1465 }
1466 return false;
1467}
1468
Enrico Granata347c2aa2013-10-08 21:49:02 +00001469SBValue
1470SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1471{
1472 SBValue sb_value;
1473 lldb::ValueObjectSP new_value_sp;
1474 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1475 {
Enrico Granata972be532014-12-17 21:18:43 +00001476 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1477 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
Greg Claytona1e5dc82015-08-11 22:53:00 +00001478 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +00001479 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001480 }
1481 sb_value.SetSP(new_value_sp);
1482 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1483 if (log)
1484 {
1485 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001486 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1487 static_cast<void*>(m_opaque_sp.get()),
1488 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001489 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001490 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1491 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001492 }
1493 return sb_value;
1494}
1495
Enrico Granata972be532014-12-17 21:18:43 +00001496lldb::SBValue
1497SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1498{
1499 SBValue sb_value;
1500 lldb::ValueObjectSP new_value_sp;
1501 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1502 {
1503 DataExtractorSP extractor(*data);
1504 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
Greg Claytona1e5dc82015-08-11 22:53:00 +00001505 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +00001506 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1507 }
1508 sb_value.SetSP(new_value_sp);
1509 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1510 if (log)
1511 {
1512 if (new_value_sp)
1513 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1514 static_cast<void*>(m_opaque_sp.get()),
1515 new_value_sp->GetName().AsCString());
1516 else
1517 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1518 static_cast<void*>(m_opaque_sp.get()));
1519 }
1520 return sb_value;
1521}
1522
1523lldb::SBValue
1524SBTarget::CreateValueFromExpression (const char *name, const char* expr)
1525{
1526 SBValue sb_value;
1527 lldb::ValueObjectSP new_value_sp;
1528 if (IsValid() && name && *name && expr && *expr)
1529 {
1530 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1531 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1532 }
1533 sb_value.SetSP(new_value_sp);
1534 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1535 if (log)
1536 {
1537 if (new_value_sp)
1538 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1539 static_cast<void*>(m_opaque_sp.get()),
1540 new_value_sp->GetName().AsCString());
1541 else
1542 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
1543 static_cast<void*>(m_opaque_sp.get()));
1544 }
1545 return sb_value;
1546}
1547
Johnny Chen5d043462011-09-26 22:40:50 +00001548bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001549SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001550{
Greg Claytonacdbe812012-01-30 09:04:36 +00001551 TargetSP target_sp(GetSP());
1552 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001553 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001554 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001555 Mutex::Locker locker;
1556 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001557 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001558 return true;
1559 }
1560 return false;
1561}
1562
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001564lldb::SBModule
1565SBTarget::AddModule (const char *path,
1566 const char *triple,
1567 const char *uuid_cstr)
1568{
Greg Claytonb210aec2012-04-23 20:23:39 +00001569 return AddModule (path, triple, uuid_cstr, NULL);
1570}
1571
1572lldb::SBModule
1573SBTarget::AddModule (const char *path,
1574 const char *triple,
1575 const char *uuid_cstr,
1576 const char *symfile)
1577{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001578 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001579 TargetSP target_sp(GetSP());
1580 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001581 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001582 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001583 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001584 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001585
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001586 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001587 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001588
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001589 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001590 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001591 else
1592 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001593
1594 if (symfile)
1595 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001596
Greg Claytonb9a01b32012-02-26 05:51:37 +00001597 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001598 }
1599 return sb_module;
1600}
1601
Greg Clayton226cce22013-07-08 22:22:41 +00001602lldb::SBModule
1603SBTarget::AddModule (const SBModuleSpec &module_spec)
1604{
1605 lldb::SBModule sb_module;
1606 TargetSP target_sp(GetSP());
1607 if (target_sp)
1608 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1609 return sb_module;
1610}
1611
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001612bool
1613SBTarget::AddModule (lldb::SBModule &module)
1614{
Greg Claytonacdbe812012-01-30 09:04:36 +00001615 TargetSP target_sp(GetSP());
1616 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001617 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001618 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001619 return true;
1620 }
1621 return false;
1622}
1623
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001624uint32_t
1625SBTarget::GetNumModules () const
1626{
Greg Clayton5160ce52013-03-27 23:08:40 +00001627 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001628
Caroline Ticeceb6b132010-10-26 03:11:13 +00001629 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001630 TargetSP target_sp(GetSP());
1631 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001632 {
1633 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001634 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001635 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001636
1637 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001638 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1639 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001640
1641 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001642}
1643
Greg Clayton48e42542010-07-30 20:12:55 +00001644void
1645SBTarget::Clear ()
1646{
Greg Clayton5160ce52013-03-27 23:08:40 +00001647 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001648
1649 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001650 log->Printf ("SBTarget(%p)::Clear ()",
1651 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001652
Greg Clayton48e42542010-07-30 20:12:55 +00001653 m_opaque_sp.reset();
1654}
1655
1656
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657SBModule
1658SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1659{
1660 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001661 TargetSP target_sp(GetSP());
1662 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001663 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001664 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001665 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00001666 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001667 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001668 return sb_module;
1669}
1670
Greg Clayton13d19502012-01-29 06:07:39 +00001671lldb::ByteOrder
1672SBTarget::GetByteOrder ()
1673{
Greg Claytonacdbe812012-01-30 09:04:36 +00001674 TargetSP target_sp(GetSP());
1675 if (target_sp)
1676 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00001677 return eByteOrderInvalid;
1678}
1679
1680const char *
1681SBTarget::GetTriple ()
1682{
Greg Claytonacdbe812012-01-30 09:04:36 +00001683 TargetSP target_sp(GetSP());
1684 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00001685 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001686 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00001687 // Unique the string so we don't run into ownership issues since
1688 // the const strings put the string into the string pool once and
1689 // the strings never comes out
1690 ConstString const_triple (triple.c_str());
1691 return const_triple.GetCString();
1692 }
1693 return NULL;
1694}
1695
1696uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00001697SBTarget::GetDataByteSize ()
1698{
1699 TargetSP target_sp(GetSP());
1700 if (target_sp)
1701 {
1702 return target_sp->GetArchitecture().GetDataByteSize() ;
1703 }
1704 return 0;
1705}
1706
1707uint32_t
1708SBTarget::GetCodeByteSize ()
1709{
1710 TargetSP target_sp(GetSP());
1711 if (target_sp)
1712 {
1713 return target_sp->GetArchitecture().GetCodeByteSize() ;
1714 }
1715 return 0;
1716}
1717
1718uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00001719SBTarget::GetAddressByteSize()
1720{
Greg Claytonacdbe812012-01-30 09:04:36 +00001721 TargetSP target_sp(GetSP());
1722 if (target_sp)
1723 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00001724 return sizeof(void*);
1725}
1726
1727
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001728SBModule
1729SBTarget::GetModuleAtIndex (uint32_t idx)
1730{
Greg Clayton5160ce52013-03-27 23:08:40 +00001731 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001732
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001734 ModuleSP module_sp;
1735 TargetSP target_sp(GetSP());
1736 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001737 {
1738 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001739 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1740 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001741 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001742
1743 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001744 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1745 static_cast<void*>(target_sp.get()), idx,
1746 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001747
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001748 return sb_module;
1749}
1750
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001751bool
1752SBTarget::RemoveModule (lldb::SBModule module)
1753{
Greg Claytonacdbe812012-01-30 09:04:36 +00001754 TargetSP target_sp(GetSP());
1755 if (target_sp)
1756 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001757 return false;
1758}
1759
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001760
1761SBBroadcaster
1762SBTarget::GetBroadcaster () const
1763{
Greg Clayton5160ce52013-03-27 23:08:40 +00001764 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001765
Greg Claytonacdbe812012-01-30 09:04:36 +00001766 TargetSP target_sp(GetSP());
1767 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001768
Caroline Ticeceb6b132010-10-26 03:11:13 +00001769 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001770 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1771 static_cast<void*>(target_sp.get()),
1772 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001773
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001774 return broadcaster;
1775}
1776
Caroline Ticedde9cff2010-09-20 05:20:02 +00001777bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001778SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001779{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001780 Stream &strm = description.ref();
1781
Greg Claytonacdbe812012-01-30 09:04:36 +00001782 TargetSP target_sp(GetSP());
1783 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00001784 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001785 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001786 }
1787 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001788 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001789
1790 return true;
1791}
1792
Greg Clayton5569e642012-02-06 01:44:54 +00001793lldb::SBSymbolContextList
1794SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00001795{
Greg Clayton5569e642012-02-06 01:44:54 +00001796 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00001797 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00001798 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001799 TargetSP target_sp(GetSP());
1800 if (target_sp)
1801 {
1802 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00001803 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00001804 const bool append = true;
1805 target_sp->GetImages().FindFunctions (ConstString(name),
1806 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001807 symbols_ok,
1808 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00001809 append,
1810 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00001811 }
Greg Claytonfe356d32011-06-21 01:34:41 +00001812 }
Greg Clayton5569e642012-02-06 01:44:54 +00001813 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00001814}
1815
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001816lldb::SBSymbolContextList
1817SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
1818{
1819 lldb::SBSymbolContextList sb_sc_list;
1820 if (name && name[0])
1821 {
1822 TargetSP target_sp(GetSP());
1823 if (target_sp)
1824 {
1825 std::string regexstr;
1826 switch (matchtype)
1827 {
1828 case eMatchTypeRegex:
1829 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
1830 break;
1831 case eMatchTypeStartsWith:
1832 regexstr = llvm::Regex::escape(name) + ".*";
1833 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1834 break;
1835 default:
1836 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
1837 break;
1838 }
1839 }
1840 }
1841 return sb_sc_list;
1842}
1843
Enrico Granata6f3533f2011-07-29 19:53:35 +00001844lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00001845SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001846{
Greg Claytonacdbe812012-01-30 09:04:36 +00001847 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001848 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001849 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001850 ConstString const_typename(typename_cstr);
1851 SymbolContext sc;
1852 const bool exact_match = false;
1853
1854 const ModuleList &module_list = target_sp->GetImages();
1855 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001856 for (size_t idx = 0; idx < count; idx++)
1857 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001858 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
1859 if (module_sp)
1860 {
1861 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
1862 if (type_sp)
1863 return SBType(type_sp);
1864 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001865 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001866
1867 // Didn't find the type in the symbols; try the Objective-C runtime
1868 // if one is installed
1869
1870 ProcessSP process_sp(target_sp->GetProcessSP());
1871
1872 if (process_sp)
1873 {
1874 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1875
1876 if (objc_language_runtime)
1877 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001878 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001879
Sean Callanan9998acd2014-12-05 01:21:59 +00001880 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001881 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001882 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001883
Sean Callanan9998acd2014-12-05 01:21:59 +00001884 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
1885 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00001886 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0]))
Sean Callanan9998acd2014-12-05 01:21:59 +00001887 {
1888 return SBType(type);
1889 }
1890 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001891 }
1892 }
1893 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001894
1895 // No matches, search for basic typename matches
1896 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1897 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001898 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001899 }
1900 return SBType();
1901}
1902
Greg Claytonb43165b2012-12-05 21:24:42 +00001903SBType
1904SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001905{
Greg Claytonacdbe812012-01-30 09:04:36 +00001906 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001907 if (target_sp)
1908 {
1909 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1910 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001911 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00001912 }
1913 return SBType();
1914}
1915
1916
1917lldb::SBTypeList
1918SBTarget::FindTypes (const char* typename_cstr)
1919{
1920 SBTypeList sb_type_list;
1921 TargetSP target_sp(GetSP());
1922 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001923 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001924 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00001925 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00001926 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001927 SymbolContext sc;
1928 TypeList type_list;
Greg Claytonae088e52016-02-10 21:28:13 +00001929 llvm::DenseSet<SymbolFile *> searched_symbol_files;
Greg Clayton29399a22012-04-06 17:41:13 +00001930 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00001931 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00001932 exact_match,
1933 UINT32_MAX,
Greg Claytonae088e52016-02-10 21:28:13 +00001934 searched_symbol_files,
Greg Clayton84db9102012-03-26 23:03:23 +00001935 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001936
Greg Claytonb43165b2012-12-05 21:24:42 +00001937 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001938 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001939 for (size_t idx = 0; idx < num_matches; idx++)
1940 {
1941 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1942 if (type_sp)
1943 sb_type_list.Append(SBType(type_sp));
1944 }
1945 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001946
1947 // Try the Objective-C runtime if one is installed
1948
1949 ProcessSP process_sp(target_sp->GetProcessSP());
1950
1951 if (process_sp)
1952 {
1953 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1954
1955 if (objc_language_runtime)
1956 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001957 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001958
Sean Callanan9998acd2014-12-05 01:21:59 +00001959 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001960 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001961 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001962
Sean Callanan9998acd2014-12-05 01:21:59 +00001963 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00001964 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001965 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00001966 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00001967 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl))
Sean Callanan9998acd2014-12-05 01:21:59 +00001968 {
1969 sb_type_list.Append(SBType(type));
1970 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001971 }
1972 }
1973 }
1974 }
1975 }
1976
1977 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00001978 {
1979 // No matches, search for basic typename matches
1980 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1981 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001982 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001983 }
1984 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001985 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001986}
1987
Greg Claytondea8cb42011-06-29 22:09:02 +00001988SBValueList
1989SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1990{
1991 SBValueList sb_value_list;
1992
Greg Claytonacdbe812012-01-30 09:04:36 +00001993 TargetSP target_sp(GetSP());
1994 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00001995 {
1996 VariableList variable_list;
1997 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00001998 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1999 append,
2000 max_matches,
2001 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00002002
2003 if (match_count > 0)
2004 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002005 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002006 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00002007 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00002008 for (uint32_t i=0; i<match_count; ++i)
2009 {
2010 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2011 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00002012 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00002013 }
2014 }
2015 }
2016
2017 return sb_value_list;
2018}
2019
Carlo Kok0fd6fd42014-09-19 19:38:19 +00002020SBValueList
2021SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
2022{
2023 SBValueList sb_value_list;
2024
2025 TargetSP target_sp(GetSP());
2026 if (name && target_sp)
2027 {
2028 VariableList variable_list;
2029 const bool append = true;
2030
2031 std::string regexstr;
2032 uint32_t match_count;
2033 switch (matchtype)
2034 {
2035 case eMatchTypeNormal:
2036 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
2037 append,
2038 max_matches,
2039 variable_list);
2040 break;
2041 case eMatchTypeRegex:
2042 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
2043 append,
2044 max_matches,
2045 variable_list);
2046 break;
2047 case eMatchTypeStartsWith:
2048 regexstr = llvm::Regex::escape(name) + ".*";
2049 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
2050 append,
2051 max_matches,
2052 variable_list);
2053 break;
2054 }
2055
2056
2057 if (match_count > 0)
2058 {
2059 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2060 if (exe_scope == NULL)
2061 exe_scope = target_sp.get();
2062 for (uint32_t i = 0; i<match_count; ++i)
2063 {
2064 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
2065 if (valobj_sp)
2066 sb_value_list.Append(SBValue(valobj_sp));
2067 }
2068 }
2069 }
2070
2071 return sb_value_list;
2072}
2073
2074
Enrico Granatabcd80b42013-01-16 18:53:52 +00002075lldb::SBValue
2076SBTarget::FindFirstGlobalVariable (const char* name)
2077{
2078 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2079 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2080 return sb_value_list.GetValueAtIndex(0);
2081 return SBValue();
2082}
2083
Jim Inghame37d6052011-09-13 00:29:56 +00002084SBSourceManager
2085SBTarget::GetSourceManager()
2086{
2087 SBSourceManager source_manager (*this);
2088 return source_manager;
2089}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002090
Sean Callanan50952e92011-12-14 23:49:37 +00002091lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002092SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2093{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002094 return ReadInstructions (base_addr, count, NULL);
2095}
2096
2097lldb::SBInstructionList
2098SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2099{
Greg Clayton9c766112012-03-06 22:24:44 +00002100 SBInstructionList sb_instructions;
2101
2102 TargetSP target_sp(GetSP());
2103 if (target_sp)
2104 {
2105 Address *addr_ptr = base_addr.get();
2106
2107 if (addr_ptr)
2108 {
2109 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2110 bool prefer_file_cache = false;
2111 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002112 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2113 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2114 prefer_file_cache,
2115 data.GetBytes(),
2116 data.GetByteSize(),
2117 error,
2118 &load_addr);
2119 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002120 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2121 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002122 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002123 *addr_ptr,
2124 data.GetBytes(),
2125 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002126 count,
2127 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002128 }
2129 }
2130
2131 return sb_instructions;
2132
2133}
2134
2135lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002136SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2137{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002138 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2139}
2140
2141lldb::SBInstructionList
2142SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2143{
Sean Callanan50952e92011-12-14 23:49:37 +00002144 SBInstructionList sb_instructions;
2145
Greg Claytonacdbe812012-01-30 09:04:36 +00002146 TargetSP target_sp(GetSP());
2147 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002148 {
2149 Address addr;
2150
2151 if (base_addr.get())
2152 addr = *base_addr.get();
2153
Greg Clayton3faf47c2013-03-28 23:42:53 +00002154 const bool data_from_file = true;
2155
Greg Claytonacdbe812012-01-30 09:04:36 +00002156 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002157 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002158 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002159 addr,
2160 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002161 size,
2162 UINT32_MAX,
2163 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002164 }
2165
2166 return sb_instructions;
2167}
2168
2169lldb::SBInstructionList
2170SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2171{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002172 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2173}
2174
2175lldb::SBInstructionList
2176SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2177{
2178 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002179}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002180
2181SBError
2182SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2183 lldb::addr_t section_base_addr)
2184{
2185 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002186 TargetSP target_sp(GetSP());
2187 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002188 {
2189 if (!section.IsValid())
2190 {
2191 sb_error.SetErrorStringWithFormat ("invalid section");
2192 }
2193 else
2194 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002195 SectionSP section_sp (section.GetSP());
2196 if (section_sp)
2197 {
2198 if (section_sp->IsThreadSpecific())
2199 {
2200 sb_error.SetErrorString ("thread specific sections are not yet supported");
2201 }
2202 else
2203 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002204 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002205 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002206 {
2207 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002208 if (process_sp)
2209 process_sp->Flush();
2210 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002211 }
2212 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002213 }
2214 }
2215 else
2216 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002217 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002218 }
2219 return sb_error;
2220}
2221
2222SBError
2223SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2224{
2225 SBError sb_error;
2226
Greg Claytonacdbe812012-01-30 09:04:36 +00002227 TargetSP target_sp(GetSP());
2228 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002229 {
2230 if (!section.IsValid())
2231 {
2232 sb_error.SetErrorStringWithFormat ("invalid section");
2233 }
2234 else
2235 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002236 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002237 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002238 {
2239 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002240 if (process_sp)
2241 process_sp->Flush();
2242 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002243 }
2244 }
2245 else
2246 {
2247 sb_error.SetErrorStringWithFormat ("invalid target");
2248 }
2249 return sb_error;
2250}
2251
2252SBError
2253SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2254{
2255 SBError sb_error;
2256
Greg Claytonacdbe812012-01-30 09:04:36 +00002257 TargetSP target_sp(GetSP());
2258 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002259 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002260 ModuleSP module_sp (module.GetSP());
2261 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002262 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002263 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002264 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002265 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002266 // The load was successful, make sure that at least some sections
2267 // changed before we notify that our module was loaded.
2268 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002269 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002270 ModuleList module_list;
2271 module_list.Append(module_sp);
2272 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002273 // Flush info in the process (stack frames, etc)
2274 ProcessSP process_sp (target_sp->GetProcessSP());
2275 if (process_sp)
2276 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002277 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002278 }
2279 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002280 else
2281 {
2282 sb_error.SetErrorStringWithFormat ("invalid module");
2283 }
2284
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002285 }
2286 else
2287 {
2288 sb_error.SetErrorStringWithFormat ("invalid target");
2289 }
2290 return sb_error;
2291}
2292
2293SBError
2294SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2295{
2296 SBError sb_error;
2297
2298 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002299 TargetSP target_sp(GetSP());
2300 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002301 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002302 ModuleSP module_sp (module.GetSP());
2303 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002304 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002305 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002306 if (objfile)
2307 {
2308 SectionList *section_list = objfile->GetSectionList();
2309 if (section_list)
2310 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002311 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002312
Greg Clayton3c947372013-01-29 01:17:09 +00002313 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002314 const size_t num_sections = section_list->GetSize();
2315 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2316 {
2317 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2318 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002319 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002320 }
2321 if (changed)
2322 {
2323 // Flush info in the process (stack frames, etc)
2324 ProcessSP process_sp (target_sp->GetProcessSP());
2325 if (process_sp)
2326 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002327 }
2328 }
2329 else
2330 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002331 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002332 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2333 }
2334 }
2335 else
2336 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002337 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002338 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2339 }
2340 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002341 else
2342 {
2343 sb_error.SetErrorStringWithFormat ("invalid module");
2344 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002345 }
2346 else
2347 {
2348 sb_error.SetErrorStringWithFormat ("invalid target");
2349 }
2350 return sb_error;
2351}
2352
2353
Greg Claytone14e1922012-12-04 02:22:16 +00002354lldb::SBSymbolContextList
2355SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2356{
2357 SBSymbolContextList sb_sc_list;
2358 if (name && name[0])
2359 {
2360 TargetSP target_sp(GetSP());
2361 if (target_sp)
2362 {
2363 bool append = true;
2364 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2365 symbol_type,
2366 *sb_sc_list,
2367 append);
2368 }
2369 }
2370 return sb_sc_list;
2371
2372}
2373
Jim Ingham763b2b22015-07-07 22:12:17 +00002374lldb::SBValue
2375SBTarget::EvaluateExpression (const char *expr)
2376{
2377 TargetSP target_sp(GetSP());
2378 if (!target_sp)
2379 return SBValue();
2380
2381 SBExpressionOptions options;
2382 lldb::DynamicValueType fetch_dynamic_value = target_sp->GetPreferDynamicValue();
2383 options.SetFetchDynamicValue (fetch_dynamic_value);
2384 options.SetUnwindOnError (true);
2385 return EvaluateExpression(expr, options);
2386}
Greg Claytone14e1922012-12-04 02:22:16 +00002387
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002388lldb::SBValue
2389SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2390{
Greg Clayton5160ce52013-03-27 23:08:40 +00002391 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002392#if !defined(LLDB_DISABLE_PYTHON)
Greg Clayton5160ce52013-03-27 23:08:40 +00002393 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Saleem Abdulrasool6010f972016-04-22 23:08:34 +00002394#endif
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002395 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002396 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002397 ValueObjectSP expr_value_sp;
2398 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002399 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002400 if (target_sp)
2401 {
2402 if (expr == NULL || expr[0] == '\0')
2403 {
2404 if (log)
2405 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2406 return expr_result;
2407 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002408
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002409 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2410 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002411
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002412 if (log)
2413 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002414
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002415 frame = exe_ctx.GetFramePtr();
2416 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002417
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002418 if (target)
2419 {
2420#ifdef LLDB_CONFIGURATION_DEBUG
2421 StreamString frame_description;
2422 if (frame)
2423 frame->DumpUsingSettingsFormat (&frame_description);
2424 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2425 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2426#endif
2427 exe_results = target->EvaluateExpression (expr,
2428 frame,
2429 expr_value_sp,
2430 options.ref());
2431
2432 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2433#ifdef LLDB_CONFIGURATION_DEBUG
2434 Host::SetCrashDescription (NULL);
2435#endif
2436 }
2437 else
2438 {
2439 if (log)
2440 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2441 }
2442 }
2443#ifndef LLDB_DISABLE_PYTHON
2444 if (expr_log)
2445 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002446 expr_result.GetValue(), expr_result.GetSummary());
2447
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002448 if (log)
2449 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002450 static_cast<void*>(frame), expr,
2451 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002452#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002453
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002454 return expr_result;
2455}
2456
Greg Clayton13fbb992013-02-01 00:47:49 +00002457
2458lldb::addr_t
2459SBTarget::GetStackRedZoneSize()
2460{
2461 TargetSP target_sp(GetSP());
2462 if (target_sp)
2463 {
2464 ABISP abi_sp;
2465 ProcessSP process_sp (target_sp->GetProcessSP());
2466 if (process_sp)
2467 abi_sp = process_sp->GetABI();
2468 else
2469 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2470 if (abi_sp)
2471 return abi_sp->GetRedZoneSize();
2472 }
2473 return 0;
2474}
Ilia K8f37ca52015-02-13 14:31:06 +00002475
2476lldb::SBLaunchInfo
2477SBTarget::GetLaunchInfo () const
2478{
2479 lldb::SBLaunchInfo launch_info(NULL);
2480 TargetSP target_sp(GetSP());
2481 if (target_sp)
2482 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2483 return launch_info;
2484}
2485
2486void
2487SBTarget::SetLaunchInfo (const lldb::SBLaunchInfo &launch_info)
2488{
2489 TargetSP target_sp(GetSP());
2490 if (target_sp)
2491 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2492}