blob: b7e53d79d3809a8c022c6b02c2f2bbdc3fda054a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBTarget.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytone0d378b2011-03-24 21:19:54 +000014#include "lldb/lldb-public.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Greg Claytondea8cb42011-06-29 22:09:02 +000016#include "lldb/API/SBBreakpoint.h"
Ilia Keb2c19a2015-03-10 21:59:55 +000017#include "lldb/API/SBDebugger.h"
18#include "lldb/API/SBEvent.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000019#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000021#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000023#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000024#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000025#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000026#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000027#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Breakpoint/BreakpointID.h"
29#include "lldb/Breakpoint/BreakpointIDList.h"
30#include "lldb/Breakpoint/BreakpointList.h"
31#include "lldb/Breakpoint/BreakpointLocation.h"
32#include "lldb/Core/Address.h"
33#include "lldb/Core/AddressResolver.h"
34#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Core/ArchSpec.h"
36#include "lldb/Core/Debugger.h"
37#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000038#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000039#include "lldb/Core/Module.h"
40#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Core/RegularExpression.h"
42#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000043#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000045#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000046#include "lldb/Core/ValueObjectList.h"
47#include "lldb/Core/ValueObjectVariable.h"
48#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000049#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000050#include "lldb/Interpreter/Args.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000051#include "lldb/Symbol/ClangASTContext.h"
52#include "lldb/Symbol/DeclVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000053#include "lldb/Symbol/ObjectFile.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 Inghamfab10e82012-03-06 00:37:27 +000057#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000058#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059#include "lldb/Target/Process.h"
Enrico Granatab10e0032015-03-04 21:33:45 +000060#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061#include "lldb/Target/Target.h"
62#include "lldb/Target/TargetList.h"
63
64#include "lldb/Interpreter/CommandReturnObject.h"
65#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000066#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068
69using namespace lldb;
70using namespace lldb_private;
71
72#define DEFAULT_DISASM_BYTE_SIZE 32
73
Oleksiy Vyalov37386142015-02-10 22:49:57 +000074namespace {
75
76Error
77AttachToProcess (ProcessAttachInfo &attach_info, Target &target)
78{
79 Mutex::Locker api_locker (target.GetAPIMutex ());
80
81 auto process_sp = target.GetProcessSP ();
82 if (process_sp)
83 {
84 const auto state = process_sp->GetState ();
85 if (process_sp->IsAlive () && state == eStateConnected)
86 {
87 // If we are already connected, then we have already specified the
88 // listener, so if a valid listener is supplied, we need to error out
89 // to let the client know.
90 if (attach_info.GetListener ())
91 return Error ("process is connected and already has a listener, pass empty listener");
92 }
93 }
94
95 return target.Attach (attach_info, nullptr);
96}
97
98} // namespace
99
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100//----------------------------------------------------------------------
101// SBTarget constructor
102//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000103SBTarget::SBTarget () :
104 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105{
106}
107
108SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000109 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110{
111}
112
113SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000114 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115{
116}
117
Greg Claytonefabb122010-11-05 23:17:00 +0000118const SBTarget&
119SBTarget::operator = (const SBTarget& rhs)
120{
121 if (this != &rhs)
122 m_opaque_sp = rhs.m_opaque_sp;
123 return *this;
124}
125
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126//----------------------------------------------------------------------
127// Destructor
128//----------------------------------------------------------------------
129SBTarget::~SBTarget()
130{
131}
132
Ilia Keb2c19a2015-03-10 21:59:55 +0000133bool
134SBTarget::EventIsTargetEvent (const SBEvent &event)
135{
136 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
137}
138
139SBTarget
140SBTarget::GetTargetFromEvent (const SBEvent &event)
141{
142 return Target::TargetEventData::GetTargetFromEvent (event.get());
143}
144
145uint32_t
146SBTarget::GetNumModulesFromEvent (const SBEvent &event)
147{
148 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
149 return module_list.GetSize();
150}
151
152SBModule
153SBTarget::GetModuleAtIndexFromEvent (const uint32_t idx, const SBEvent &event)
154{
155 const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get());
156 return SBModule(module_list.GetModuleAtIndex(idx));
157}
158
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000159const char *
160SBTarget::GetBroadcasterClassName ()
161{
162 return Target::GetStaticBroadcasterClass().AsCString();
163}
164
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165bool
166SBTarget::IsValid () const
167{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000168 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169}
170
171SBProcess
172SBTarget::GetProcess ()
173{
174 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000175 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000176 TargetSP target_sp(GetSP());
177 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000178 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000179 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000180 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000181 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000182
Greg Clayton5160ce52013-03-27 23:08:40 +0000183 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000184 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000185 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
186 static_cast<void*>(target_sp.get()),
187 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000188
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 return sb_process;
190}
191
Matthew Gardinerc928de32014-10-22 07:22:56 +0000192SBPlatform
193SBTarget::GetPlatform ()
194{
195 TargetSP target_sp(GetSP());
196 if (!target_sp)
197 return SBPlatform();
198
199 SBPlatform platform;
200 platform.m_opaque_sp = target_sp->GetPlatform();
201
202 return platform;
203}
204
Greg Clayton66111032010-06-23 01:19:29 +0000205SBDebugger
206SBTarget::GetDebugger () const
207{
208 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000209 TargetSP target_sp(GetSP());
210 if (target_sp)
211 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000212 return debugger;
213}
214
Jim Ingham270684d2011-03-31 00:01:24 +0000215SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000216SBTarget::LoadCore (const char *core_file)
217{
218 SBProcess sb_process;
219 TargetSP target_sp(GetSP());
220 if (target_sp)
221 {
222 FileSpec filespec(core_file, true);
223 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
224 NULL,
225 &filespec));
226 if (process_sp)
227 {
228 process_sp->LoadCore();
229 sb_process.SetSP (process_sp);
230 }
231 }
232 return sb_process;
233}
234
235SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000236SBTarget::LaunchSimple
237(
238 char const **argv,
239 char const **envp,
240 const char *working_directory
241)
242{
243 char *stdin_path = NULL;
244 char *stdout_path = NULL;
245 char *stderr_path = NULL;
246 uint32_t launch_flags = 0;
247 bool stop_at_entry = false;
248 SBError error;
249 SBListener listener = GetDebugger().GetListener();
250 return Launch (listener,
251 argv,
252 envp,
253 stdin_path,
254 stdout_path,
255 stderr_path,
256 working_directory,
257 launch_flags,
258 stop_at_entry,
259 error);
260}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000261
Greg Claytonfbb76342013-11-20 21:07:01 +0000262SBError
263SBTarget::Install()
264{
265 SBError sb_error;
266 TargetSP target_sp(GetSP());
267 if (target_sp)
268 {
269 Mutex::Locker api_locker (target_sp->GetAPIMutex());
270 sb_error.ref() = target_sp->Install(NULL);
271 }
272 return sb_error;
273}
274
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000275SBProcess
276SBTarget::Launch
277(
Greg Clayton4b045622011-02-03 21:28:34 +0000278 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000279 char const **argv,
280 char const **envp,
281 const char *stdin_path,
282 const char *stdout_path,
283 const char *stderr_path,
284 const char *working_directory,
285 uint32_t launch_flags, // See LaunchFlags
286 bool stop_at_entry,
287 lldb::SBError& error
288)
289{
Greg Clayton5160ce52013-03-27 23:08:40 +0000290 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000291
Greg Claytonacdbe812012-01-30 09:04:36 +0000292 SBProcess sb_process;
293 ProcessSP process_sp;
294 TargetSP target_sp(GetSP());
295
Caroline Ticeceb6b132010-10-26 03:11:13 +0000296 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000297 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 +0000298 static_cast<void*>(target_sp.get()),
299 static_cast<void*>(argv), static_cast<void*>(envp),
300 stdin_path ? stdin_path : "NULL",
301 stdout_path ? stdout_path : "NULL",
302 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000303 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000304 launch_flags, stop_at_entry,
305 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000306
307 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000309 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000310
Zachary Turner6fd3f342015-02-02 18:50:01 +0000311 if (stop_at_entry)
312 launch_flags |= eLaunchFlagStopAtEntry;
313
Greg Clayton645bf542011-01-27 01:01:10 +0000314 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
315 launch_flags |= eLaunchFlagDisableASLR;
316
Greg Clayton2289fa42011-04-30 01:09:13 +0000317 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000318 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000319 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000320 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000321 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000322
Greg Claytonb9556ac2012-01-30 07:41:31 +0000323 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000324 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000325 if (state == eStateAttaching)
326 error.SetErrorString ("process attach is in progress");
327 else
328 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000329 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000330 }
Greg Clayton931180e2011-01-27 06:44:37 +0000331 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000332
Greg Clayton2289fa42011-04-30 01:09:13 +0000333 if (state == eStateConnected)
334 {
335 // If we are already connected, then we have already specified the
336 // listener, so if a valid listener is supplied, we need to error out
337 // to let the client know.
338 if (listener.IsValid())
339 {
340 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000341 return sb_process;
342 }
343 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000344
345 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
346 launch_flags |= eLaunchFlagDisableSTDIO;
347
348 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000349
Greg Claytonb09c5382013-12-13 17:20:18 +0000350 Module *exe_module = target_sp->GetExecutableModulePointer();
351 if (exe_module)
352 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
353 if (argv)
354 launch_info.GetArguments().AppendArguments (argv);
355 if (envp)
356 launch_info.GetEnvironmentEntries ().SetArguments (envp);
357
358 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000359 launch_info.SetListener(listener.GetSP());
360
361 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000362
Greg Claytonb09c5382013-12-13 17:20:18 +0000363 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000364 }
365 else
366 {
367 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000369
Caroline Tice20ad3c42010-10-29 21:48:37 +0000370 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000371 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000372 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
373 static_cast<void*>(target_sp.get()),
374 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000375
Greg Clayton5d5028b2010-10-06 03:53:16 +0000376 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377}
378
Greg Clayton0e615682012-02-24 05:03:03 +0000379SBProcess
380SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
381{
Greg Clayton5160ce52013-03-27 23:08:40 +0000382 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000383
Greg Clayton0e615682012-02-24 05:03:03 +0000384 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000385 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000386
Greg Clayton0e615682012-02-24 05:03:03 +0000387 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000388 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
389 static_cast<void*>(target_sp.get()));
390
Greg Clayton0e615682012-02-24 05:03:03 +0000391 if (target_sp)
392 {
393 Mutex::Locker api_locker (target_sp->GetAPIMutex());
394 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000395 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000396 ProcessSP process_sp = target_sp->GetProcessSP();
397 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000398 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000399 state = process_sp->GetState();
400
401 if (process_sp->IsAlive() && state != eStateConnected)
402 {
403 if (state == eStateAttaching)
404 error.SetErrorString ("process attach is in progress");
405 else
406 error.SetErrorString ("a process is already being debugged");
407 return sb_process;
408 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000409 }
Greg Clayton0e615682012-02-24 05:03:03 +0000410 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000411
412 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
413
Greg Clayton3e32ad62014-05-07 20:16:06 +0000414 if (!launch_info.GetExecutableFile())
415 {
416 Module *exe_module = target_sp->GetExecutableModulePointer();
417 if (exe_module)
418 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
419 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000420
421 const ArchSpec &arch_spec = target_sp->GetArchitecture();
422 if (arch_spec.IsValid())
423 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000424
Greg Clayton8012cad2014-11-17 19:39:20 +0000425 error.SetError (target_sp->Launch (launch_info, NULL));
Greg Claytonb09c5382013-12-13 17:20:18 +0000426 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000427 }
428 else
429 {
430 error.SetErrorString ("SBTarget is invalid");
431 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000432
Greg Clayton0e615682012-02-24 05:03:03 +0000433 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
434 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000435 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000436 static_cast<void*>(target_sp.get()),
437 static_cast<void*>(sb_process.GetSP().get()));
438
Greg Clayton0e615682012-02-24 05:03:03 +0000439 return sb_process;
440}
441
442lldb::SBProcess
443SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
444{
Greg Clayton5160ce52013-03-27 23:08:40 +0000445 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000446
Greg Clayton0e615682012-02-24 05:03:03 +0000447 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000448 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000449
Sean Callanan575a4542012-10-20 00:21:31 +0000450 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000451 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
452 static_cast<void*>(target_sp.get()));
453
Greg Clayton0e615682012-02-24 05:03:03 +0000454 if (target_sp)
455 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000456 ProcessAttachInfo &attach_info = sb_attach_info.ref();
457 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Greg Clayton0e615682012-02-24 05:03:03 +0000458 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000459 PlatformSP platform_sp = target_sp->GetPlatform();
460 // See if we can pre-verify if a process exists or not
461 if (platform_sp && platform_sp->IsConnected())
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000462 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000463 lldb::pid_t attach_pid = attach_info.GetProcessID();
464 ProcessInstanceInfo instance_info;
465 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
Han Ming Ongcec8c902012-02-29 00:12:56 +0000466 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000467 attach_info.SetUserID(instance_info.GetEffectiveUserID());
468 }
469 else
470 {
471 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
472 if (log)
Greg Clayton91e407e2012-09-27 00:03:39 +0000473 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000474 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
475 static_cast<void*>(target_sp.get()), error.GetCString());
Greg Clayton91e407e2012-09-27 00:03:39 +0000476 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000477 return sb_process;
Han Ming Ongcec8c902012-02-29 00:12:56 +0000478 }
479 }
Greg Clayton0e615682012-02-24 05:03:03 +0000480 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000481 error.SetError(AttachToProcess(attach_info, *target_sp));
482 if (error.Success())
483 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000484 }
485 else
486 {
487 error.SetErrorString ("SBTarget is invalid");
488 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000489
Sean Callanan575a4542012-10-20 00:21:31 +0000490 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000491 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000492 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000493 static_cast<void*>(sb_process.GetSP().get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000494
Greg Clayton0e615682012-02-24 05:03:03 +0000495 return sb_process;
496}
497
498
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000499#if defined(__APPLE__)
500
501lldb::SBProcess
502SBTarget::AttachToProcessWithID (SBListener &listener,
503 ::pid_t pid,
504 lldb::SBError& error)
505{
506 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
507}
508
509#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000510
511lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000512SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000513(
Greg Clayton4b045622011-02-03 21:28:34 +0000514 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000515 lldb::pid_t pid,// The process ID to attach to
516 SBError& error // An error explaining what went wrong if attach fails
517)
518{
Greg Clayton5160ce52013-03-27 23:08:40 +0000519 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000520
Greg Clayton524e60b2010-10-06 22:10:17 +0000521 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000522 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000523
524 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000525 log->Printf ("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
526 static_cast<void*>(target_sp.get()),
527 __FUNCTION__,
528 pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000529
Greg Claytonacdbe812012-01-30 09:04:36 +0000530 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000531 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000532 ProcessAttachInfo attach_info;
533 attach_info.SetProcessID (pid);
534 if (listener.IsValid())
535 attach_info.SetListener(listener.GetSP());
Greg Clayton0c74e782011-06-24 03:21:43 +0000536
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000537 ProcessInstanceInfo instance_info;
538 if (target_sp->GetPlatform ()->GetProcessInfo (pid, instance_info))
539 attach_info.SetUserID (instance_info.GetEffectiveUserID ());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000540
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000541 error.SetError (AttachToProcess (attach_info, *target_sp));
542 if (error.Success ())
543 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000544 }
545 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000546 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000547
Sean Callanan575a4542012-10-20 00:21:31 +0000548 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000549 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
550 static_cast<void*>(target_sp.get ()),
551 __FUNCTION__,
552 static_cast<void*>(sb_process.GetSP().get ()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000553 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000554}
555
556lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000557SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +0000558(
Greg Clayton4b045622011-02-03 21:28:34 +0000559 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000560 const char *name, // basename of process to attach to
561 bool wait_for, // if true wait for a new instance of "name" to be launched
562 SBError& error // An error explaining what went wrong if attach fails
563)
564{
Greg Clayton5160ce52013-03-27 23:08:40 +0000565 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000566
Greg Clayton524e60b2010-10-06 22:10:17 +0000567 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000568 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000569
Sean Callanan575a4542012-10-20 00:21:31 +0000570 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000571 log->Printf ("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
572 static_cast<void*>(target_sp.get()),
573 __FUNCTION__,
574 name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000575 wait_for ? "true" : "false");
576
Greg Claytonacdbe812012-01-30 09:04:36 +0000577 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000578 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000579 ProcessAttachInfo attach_info;
580 attach_info.GetExecutableFile().SetFile(name, false);
581 attach_info.SetWaitForLaunch(wait_for);
582 if (listener.IsValid())
583 attach_info.SetListener(listener.GetSP());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000584
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000585 error.SetError (AttachToProcess (attach_info, *target_sp));
586 if (error.Success ())
587 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000588 }
589 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000590 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000591
Sean Callanan575a4542012-10-20 00:21:31 +0000592 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000593 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000594 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000595 __FUNCTION__,
596 static_cast<void*>(sb_process.GetSP().get()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000597 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000598}
599
James McIlree9631aae2011-03-04 00:31:13 +0000600lldb::SBProcess
601SBTarget::ConnectRemote
602(
603 SBListener &listener,
604 const char *url,
605 const char *plugin_name,
606 SBError& error
607)
608{
Greg Clayton5160ce52013-03-27 23:08:40 +0000609 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000610
James McIlree9631aae2011-03-04 00:31:13 +0000611 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000612 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000613 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000614
Sean Callanan575a4542012-10-20 00:21:31 +0000615 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000616 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
617 static_cast<void*>(target_sp.get()), url, plugin_name);
618
Greg Claytonacdbe812012-01-30 09:04:36 +0000619 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000620 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000621 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +0000622 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000623 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000624 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000625 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000626
Greg Claytonb9556ac2012-01-30 07:41:31 +0000627 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000628 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000629 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000630 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +0000631 }
632 else
633 {
634 error.SetErrorString ("unable to create lldb_private::Process");
635 }
636 }
637 else
638 {
639 error.SetErrorString ("SBTarget is invalid");
640 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000641
Sean Callanan575a4542012-10-20 00:21:31 +0000642 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000643 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000644 static_cast<void*>(target_sp.get()),
645 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +0000646 return sb_process;
647}
648
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649SBFileSpec
650SBTarget::GetExecutable ()
651{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000652
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +0000654 TargetSP target_sp(GetSP());
655 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000657 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +0000658 if (exe_module)
659 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000661
Greg Clayton5160ce52013-03-27 23:08:40 +0000662 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000663 if (log)
664 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000665 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
666 static_cast<void*>(target_sp.get()),
667 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000668 }
669
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670 return exe_file_spec;
671}
672
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000674SBTarget::operator == (const SBTarget &rhs) const
675{
Greg Clayton66111032010-06-23 01:19:29 +0000676 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677}
678
679bool
680SBTarget::operator != (const SBTarget &rhs) const
681{
Greg Clayton66111032010-06-23 01:19:29 +0000682 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683}
684
Greg Claytonb9556ac2012-01-30 07:41:31 +0000685lldb::TargetSP
686SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +0000687{
688 return m_opaque_sp;
689}
690
Greg Clayton66111032010-06-23 01:19:29 +0000691void
Greg Claytonb9556ac2012-01-30 07:41:31 +0000692SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +0000693{
694 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695}
696
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000697lldb::SBAddress
698SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000699{
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000700 lldb::SBAddress sb_addr;
701 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +0000702 TargetSP target_sp(GetSP());
703 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000704 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000705 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +0000706 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000707 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000708 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000709
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000710 // We have a load address that isn't in a section, just return an address
711 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +0000712 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000713 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000714}
715
Matthew Gardinerc928de32014-10-22 07:22:56 +0000716lldb::SBAddress
717SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
718{
719 lldb::SBAddress sb_addr;
720 Address &addr = sb_addr.ref();
721 TargetSP target_sp(GetSP());
722 if (target_sp)
723 {
724 Mutex::Locker api_locker (target_sp->GetAPIMutex());
725 if (target_sp->ResolveFileAddress (file_addr, addr))
726 return sb_addr;
727 }
728
729 addr.SetRawAddress(file_addr);
730 return sb_addr;
731}
Greg Claytond5944cd2013-12-06 01:12:00 +0000732
733lldb::SBAddress
734SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
735{
736 lldb::SBAddress sb_addr;
737 Address &addr = sb_addr.ref();
738 TargetSP target_sp(GetSP());
739 if (target_sp)
740 {
741 Mutex::Locker api_locker (target_sp->GetAPIMutex());
742 if (target_sp->ResolveLoadAddress (vm_addr, addr))
743 return sb_addr;
744 }
745
746 // We have a load address that isn't in a section, just return an address
747 // with the offset filled in (the address) and the section set to NULL
748 addr.SetRawAddress(vm_addr);
749 return sb_addr;
750}
751
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000752SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +0000753SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
754 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000755{
756 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +0000757 if (addr.IsValid())
758 {
759 TargetSP target_sp(GetSP());
760 if (target_sp)
761 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
762 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000763 return sc;
764}
765
Matthew Gardinerc928de32014-10-22 07:22:56 +0000766size_t
767SBTarget::ReadMemory (const SBAddress addr,
768 void *buf,
769 size_t size,
770 lldb::SBError &error)
771{
772 SBError sb_error;
773 size_t bytes_read = 0;
774 TargetSP target_sp(GetSP());
775 if (target_sp)
776 {
777 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8691dc52014-11-04 00:56:30 +0000778 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
779 }
780 else
781 {
782 sb_error.SetErrorString("invalid target");
Matthew Gardinerc928de32014-10-22 07:22:56 +0000783 }
784
785 return bytes_read;
786}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000787
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000789SBTarget::BreakpointCreateByLocation (const char *file,
790 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791{
Greg Clayton7481c202010-11-08 00:28:40 +0000792 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793}
794
795SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000796SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
797 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798{
Greg Clayton5160ce52013-03-27 23:08:40 +0000799 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000800
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000802 TargetSP target_sp(GetSP());
803 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000804 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000805 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000806
Greg Clayton1f746072012-08-29 21:13:06 +0000807 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +0000808 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +0000809 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000810 const bool hardware = false;
811 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000812 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000813
814 if (log)
815 {
816 SBStream sstr;
817 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000818 char path[PATH_MAX];
819 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000820 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
821 static_cast<void*>(target_sp.get()), path, line,
822 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000823 }
824
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825 return sb_bp;
826}
827
828SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000829SBTarget::BreakpointCreateByName (const char *symbol_name,
830 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000831{
Greg Clayton5160ce52013-03-27 23:08:40 +0000832 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000833
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000834 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000835 TargetSP target_sp(GetSP());
836 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000838 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000839
Jim Inghama8558b62012-05-22 00:12:20 +0000840 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000841 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000842 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843 if (module_name && module_name[0])
844 {
Jim Ingham969795f2011-09-21 01:17:13 +0000845 FileSpecList module_spec_list;
846 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +0000847 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848 }
849 else
850 {
Greg Claytoneb023e72013-10-11 19:48:25 +0000851 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852 }
853 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000854
Caroline Ticeceb6b132010-10-26 03:11:13 +0000855 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000856 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
857 static_cast<void*>(target_sp.get()), symbol_name,
858 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000859
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 return sb_bp;
861}
862
Jim Ingham87df91b2011-09-23 00:54:11 +0000863lldb::SBBreakpoint
864SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000865 const SBFileSpecList &module_list,
866 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000867{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000868 uint32_t name_type_mask = eFunctionNameTypeAuto;
869 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
870}
871
872lldb::SBBreakpoint
873SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000874 uint32_t name_type_mask,
875 const SBFileSpecList &module_list,
876 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000877{
Greg Clayton5160ce52013-03-27 23:08:40 +0000878 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +0000879
880 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000881 TargetSP target_sp(GetSP());
882 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +0000883 {
Jim Inghama8558b62012-05-22 00:12:20 +0000884 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000885 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000886 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +0000887 Mutex::Locker api_locker (target_sp->GetAPIMutex());
888 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +0000889 comp_unit_list.get(),
890 symbol_name,
891 name_type_mask,
892 skip_prologue,
893 internal,
894 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +0000895 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000896
Jim Ingham87df91b2011-09-23 00:54:11 +0000897 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000898 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
899 static_cast<void*>(target_sp.get()), symbol_name,
900 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +0000901
902 return sb_bp;
903}
904
Jim Inghamfab10e82012-03-06 00:37:27 +0000905lldb::SBBreakpoint
906SBTarget::BreakpointCreateByNames (const char *symbol_names[],
907 uint32_t num_names,
908 uint32_t name_type_mask,
909 const SBFileSpecList &module_list,
910 const SBFileSpecList &comp_unit_list)
911{
Greg Clayton5160ce52013-03-27 23:08:40 +0000912 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +0000913
914 SBBreakpoint sb_bp;
915 TargetSP target_sp(GetSP());
916 if (target_sp && num_names > 0)
917 {
918 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +0000919 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000920 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000921 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +0000922 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
923 comp_unit_list.get(),
924 symbol_names,
925 num_names,
926 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000927 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000928 internal,
929 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +0000930 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000931
Jim Inghamfab10e82012-03-06 00:37:27 +0000932 if (log)
933 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000934 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
935 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000936 for (uint32_t i = 0 ; i < num_names; i++)
937 {
938 char sep;
939 if (i < num_names - 1)
940 sep = ',';
941 else
942 sep = '}';
943 if (symbol_names[i] != NULL)
944 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
945 else
946 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +0000947 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000948 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
949 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000950 }
951
952 return sb_bp;
953}
Jim Ingham87df91b2011-09-23 00:54:11 +0000954
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000955SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000956SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
957 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958{
Greg Clayton5160ce52013-03-27 23:08:40 +0000959 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000960
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000962 TargetSP target_sp(GetSP());
963 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000964 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000965 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +0000967 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000968 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000969 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000970
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000971 if (module_name && module_name[0])
972 {
Jim Ingham969795f2011-09-21 01:17:13 +0000973 FileSpecList module_spec_list;
974 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000975
Greg Claytoneb023e72013-10-11 19:48:25 +0000976 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 }
978 else
979 {
Greg Claytoneb023e72013-10-11 19:48:25 +0000980 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 }
982 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000983
984 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000985 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
986 static_cast<void*>(target_sp.get()), symbol_name_regex,
987 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000988
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989 return sb_bp;
990}
991
Jim Ingham87df91b2011-09-23 00:54:11 +0000992lldb::SBBreakpoint
993SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000994 const SBFileSpecList &module_list,
995 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000996{
Greg Clayton5160ce52013-03-27 23:08:40 +0000997 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000998
Jim Ingham87df91b2011-09-23 00:54:11 +0000999 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001000 TargetSP target_sp(GetSP());
1001 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001002 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001003 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +00001004 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +00001005 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +00001006 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +00001007 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001008
Greg Claytoneb023e72013-10-11 19:48:25 +00001009 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001010 }
1011
1012 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001013 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1014 static_cast<void*>(target_sp.get()), symbol_name_regex,
1015 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001016
1017 return sb_bp;
1018}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001019
1020SBBreakpoint
1021SBTarget::BreakpointCreateByAddress (addr_t address)
1022{
Greg Clayton5160ce52013-03-27 23:08:40 +00001023 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001024
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001026 TargetSP target_sp(GetSP());
1027 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001028 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001029 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001030 const bool hardware = false;
1031 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001032 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033
Caroline Ticeceb6b132010-10-26 03:11:13 +00001034 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001035 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1036 static_cast<void*>(target_sp.get()),
1037 static_cast<uint64_t>(address),
1038 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001039
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040 return sb_bp;
1041}
1042
Jim Ingham969795f2011-09-21 01:17:13 +00001043lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001044SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1045 const lldb::SBFileSpec &source_file,
1046 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001047{
Greg Clayton5160ce52013-03-27 23:08:40 +00001048 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001049
1050 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001051 TargetSP target_sp(GetSP());
1052 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001053 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001054 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001055 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001056 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001057 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001058 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001059
Jim Ingham969795f2011-09-21 01:17:13 +00001060 if (module_name && module_name[0])
1061 {
1062 FileSpecList module_spec_list;
1063 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001064
Greg Claytoneb023e72013-10-11 19:48:25 +00001065 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001066 }
1067 else
1068 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001069 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001070 }
1071 }
1072
1073 if (log)
1074 {
1075 char path[PATH_MAX];
1076 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001077 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1078 static_cast<void*>(target_sp.get()), source_regex, path,
1079 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001080 }
1081
1082 return sb_bp;
1083}
1084
Jim Ingham87df91b2011-09-23 00:54:11 +00001085lldb::SBBreakpoint
Jim Inghame7320522015-02-12 17:37:46 +00001086SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1087 const SBFileSpecList &module_list,
1088 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001089{
Greg Clayton5160ce52013-03-27 23:08:40 +00001090 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001091
1092 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001093 TargetSP target_sp(GetSP());
1094 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001095 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001096 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001097 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001098 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001099 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001100 }
1101
1102 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001103 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1104 static_cast<void*>(target_sp.get()), source_regex,
1105 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001106
1107 return sb_bp;
1108}
Jim Ingham969795f2011-09-21 01:17:13 +00001109
Jim Inghamfab10e82012-03-06 00:37:27 +00001110lldb::SBBreakpoint
1111SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001112 bool catch_bp,
1113 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001114{
Greg Clayton5160ce52013-03-27 23:08:40 +00001115 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001116
1117 SBBreakpoint sb_bp;
1118 TargetSP target_sp(GetSP());
1119 if (target_sp)
1120 {
1121 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001122 const bool hardware = false;
1123 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001124 }
1125
1126 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001127 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1128 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001129 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001130 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1131 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001132
1133 return sb_bp;
1134}
1135
Greg Clayton9fed0d82010-07-23 23:33:17 +00001136uint32_t
1137SBTarget::GetNumBreakpoints () const
1138{
Greg Claytonacdbe812012-01-30 09:04:36 +00001139 TargetSP target_sp(GetSP());
1140 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001141 {
1142 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001143 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001144 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001145 return 0;
1146}
1147
1148SBBreakpoint
1149SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1150{
1151 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001152 TargetSP target_sp(GetSP());
1153 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001154 {
1155 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001156 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001157 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001158 return sb_breakpoint;
1159}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160
1161bool
1162SBTarget::BreakpointDelete (break_id_t bp_id)
1163{
Greg Clayton5160ce52013-03-27 23:08:40 +00001164 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001165
Caroline Ticeceb6b132010-10-26 03:11:13 +00001166 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001167 TargetSP target_sp(GetSP());
1168 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001169 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001170 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1171 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001172 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001173
1174 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001175 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1176 static_cast<void*>(target_sp.get()),
1177 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001178
1179 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180}
1181
Johnny Chen5d043462011-09-26 22:40:50 +00001182SBBreakpoint
1183SBTarget::FindBreakpointByID (break_id_t bp_id)
1184{
Greg Clayton5160ce52013-03-27 23:08:40 +00001185 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001186
1187 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001188 TargetSP target_sp(GetSP());
1189 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001190 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001191 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1192 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001193 }
1194
1195 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001196 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1197 static_cast<void*>(target_sp.get()),
1198 static_cast<uint32_t>(bp_id),
1199 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001200
1201 return sb_breakpoint;
1202}
1203
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204bool
1205SBTarget::EnableAllBreakpoints ()
1206{
Greg Claytonacdbe812012-01-30 09:04:36 +00001207 TargetSP target_sp(GetSP());
1208 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001210 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1211 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 return true;
1213 }
1214 return false;
1215}
1216
1217bool
1218SBTarget::DisableAllBreakpoints ()
1219{
Greg Claytonacdbe812012-01-30 09:04:36 +00001220 TargetSP target_sp(GetSP());
1221 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001223 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1224 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225 return true;
1226 }
1227 return false;
1228}
1229
1230bool
1231SBTarget::DeleteAllBreakpoints ()
1232{
Greg Claytonacdbe812012-01-30 09:04:36 +00001233 TargetSP target_sp(GetSP());
1234 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001235 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001236 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1237 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238 return true;
1239 }
1240 return false;
1241}
1242
Johnny Chen5d043462011-09-26 22:40:50 +00001243uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001244SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001245{
Greg Claytonacdbe812012-01-30 09:04:36 +00001246 TargetSP target_sp(GetSP());
1247 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001248 {
Johnny Chen01a67862011-10-14 00:42:25 +00001249 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001250 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001251 }
1252 return 0;
1253}
1254
Greg Clayton1b282f92011-10-13 18:08:26 +00001255SBWatchpoint
1256SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001257{
Johnny Chen01a67862011-10-14 00:42:25 +00001258 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001259 TargetSP target_sp(GetSP());
1260 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001261 {
Johnny Chen01a67862011-10-14 00:42:25 +00001262 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001263 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001264 }
Johnny Chen01a67862011-10-14 00:42:25 +00001265 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001266}
1267
1268bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001269SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001270{
Greg Clayton5160ce52013-03-27 23:08:40 +00001271 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001272
1273 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001274 TargetSP target_sp(GetSP());
1275 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001276 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001277 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001278 Mutex::Locker locker;
1279 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001280 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001281 }
1282
1283 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001284 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1285 static_cast<void*>(target_sp.get()),
1286 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001287
1288 return result;
1289}
1290
Greg Clayton1b282f92011-10-13 18:08:26 +00001291SBWatchpoint
1292SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001293{
Greg Clayton5160ce52013-03-27 23:08:40 +00001294 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001295
Greg Clayton1b282f92011-10-13 18:08:26 +00001296 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001297 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001298 TargetSP target_sp(GetSP());
1299 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001300 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001301 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001302 Mutex::Locker locker;
1303 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001304 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1305 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001306 }
1307
1308 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001309 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1310 static_cast<void*>(target_sp.get()),
1311 static_cast<uint32_t>(wp_id),
1312 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001313
Greg Clayton1b282f92011-10-13 18:08:26 +00001314 return sb_watchpoint;
1315}
1316
1317lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001318SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001319{
Greg Clayton5160ce52013-03-27 23:08:40 +00001320 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001321
Greg Clayton1b282f92011-10-13 18:08:26 +00001322 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001323 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001324 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001325 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001326 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001327 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001328 uint32_t watch_type = 0;
1329 if (read)
1330 watch_type |= LLDB_WATCH_TYPE_READ;
1331 if (write)
1332 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001333 if (watch_type == 0)
1334 {
1335 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1336 return sb_watchpoint;
1337 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001338
Johnny Chen7385a5a2012-05-31 22:56:36 +00001339 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001340 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001341 // This API doesn't take in a type, so we can't figure out what it is.
1342 ClangASTType *type = NULL;
1343 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001344 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001345 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001346 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001347
Greg Clayton1b282f92011-10-13 18:08:26 +00001348 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001349 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001350 static_cast<void*>(target_sp.get()), addr,
1351 static_cast<uint32_t>(size),
1352 static_cast<void*>(watchpoint_sp.get()));
1353
Greg Clayton1b282f92011-10-13 18:08:26 +00001354 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001355}
1356
1357bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001358SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001359{
Greg Claytonacdbe812012-01-30 09:04:36 +00001360 TargetSP target_sp(GetSP());
1361 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001362 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001363 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001364 Mutex::Locker locker;
1365 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001366 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001367 return true;
1368 }
1369 return false;
1370}
1371
1372bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001373SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001374{
Greg Claytonacdbe812012-01-30 09:04:36 +00001375 TargetSP target_sp(GetSP());
1376 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001377 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001378 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001379 Mutex::Locker locker;
1380 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001381 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001382 return true;
1383 }
1384 return false;
1385}
1386
Enrico Granata347c2aa2013-10-08 21:49:02 +00001387SBValue
1388SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1389{
1390 SBValue sb_value;
1391 lldb::ValueObjectSP new_value_sp;
1392 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1393 {
Enrico Granata972be532014-12-17 21:18:43 +00001394 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1395 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1396 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1397 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001398 }
1399 sb_value.SetSP(new_value_sp);
1400 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1401 if (log)
1402 {
1403 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001404 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1405 static_cast<void*>(m_opaque_sp.get()),
1406 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001407 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001408 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1409 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001410 }
1411 return sb_value;
1412}
1413
Enrico Granata972be532014-12-17 21:18:43 +00001414lldb::SBValue
1415SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1416{
1417 SBValue sb_value;
1418 lldb::ValueObjectSP new_value_sp;
1419 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1420 {
1421 DataExtractorSP extractor(*data);
1422 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1423 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1424 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1425 }
1426 sb_value.SetSP(new_value_sp);
1427 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1428 if (log)
1429 {
1430 if (new_value_sp)
1431 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1432 static_cast<void*>(m_opaque_sp.get()),
1433 new_value_sp->GetName().AsCString());
1434 else
1435 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1436 static_cast<void*>(m_opaque_sp.get()));
1437 }
1438 return sb_value;
1439}
1440
1441lldb::SBValue
1442SBTarget::CreateValueFromExpression (const char *name, const char* expr)
1443{
1444 SBValue sb_value;
1445 lldb::ValueObjectSP new_value_sp;
1446 if (IsValid() && name && *name && expr && *expr)
1447 {
1448 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1449 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1450 }
1451 sb_value.SetSP(new_value_sp);
1452 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1453 if (log)
1454 {
1455 if (new_value_sp)
1456 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1457 static_cast<void*>(m_opaque_sp.get()),
1458 new_value_sp->GetName().AsCString());
1459 else
1460 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
1461 static_cast<void*>(m_opaque_sp.get()));
1462 }
1463 return sb_value;
1464}
1465
Johnny Chen5d043462011-09-26 22:40:50 +00001466bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001467SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001468{
Greg Claytonacdbe812012-01-30 09:04:36 +00001469 TargetSP target_sp(GetSP());
1470 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001471 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001472 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001473 Mutex::Locker locker;
1474 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001475 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001476 return true;
1477 }
1478 return false;
1479}
1480
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001481
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001482lldb::SBModule
1483SBTarget::AddModule (const char *path,
1484 const char *triple,
1485 const char *uuid_cstr)
1486{
Greg Claytonb210aec2012-04-23 20:23:39 +00001487 return AddModule (path, triple, uuid_cstr, NULL);
1488}
1489
1490lldb::SBModule
1491SBTarget::AddModule (const char *path,
1492 const char *triple,
1493 const char *uuid_cstr,
1494 const char *symfile)
1495{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001496 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001497 TargetSP target_sp(GetSP());
1498 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001499 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001500 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001501 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001502 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001503
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001504 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001505 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001506
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001507 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001508 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001509 else
1510 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001511
1512 if (symfile)
1513 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001514
Greg Claytonb9a01b32012-02-26 05:51:37 +00001515 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001516 }
1517 return sb_module;
1518}
1519
Greg Clayton226cce22013-07-08 22:22:41 +00001520lldb::SBModule
1521SBTarget::AddModule (const SBModuleSpec &module_spec)
1522{
1523 lldb::SBModule sb_module;
1524 TargetSP target_sp(GetSP());
1525 if (target_sp)
1526 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1527 return sb_module;
1528}
1529
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001530bool
1531SBTarget::AddModule (lldb::SBModule &module)
1532{
Greg Claytonacdbe812012-01-30 09:04:36 +00001533 TargetSP target_sp(GetSP());
1534 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001535 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001536 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001537 return true;
1538 }
1539 return false;
1540}
1541
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001542uint32_t
1543SBTarget::GetNumModules () const
1544{
Greg Clayton5160ce52013-03-27 23:08:40 +00001545 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001546
Caroline Ticeceb6b132010-10-26 03:11:13 +00001547 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001548 TargetSP target_sp(GetSP());
1549 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001550 {
1551 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001552 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001553 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001554
1555 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001556 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1557 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001558
1559 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001560}
1561
Greg Clayton48e42542010-07-30 20:12:55 +00001562void
1563SBTarget::Clear ()
1564{
Greg Clayton5160ce52013-03-27 23:08:40 +00001565 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001566
1567 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001568 log->Printf ("SBTarget(%p)::Clear ()",
1569 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001570
Greg Clayton48e42542010-07-30 20:12:55 +00001571 m_opaque_sp.reset();
1572}
1573
1574
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575SBModule
1576SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1577{
1578 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001579 TargetSP target_sp(GetSP());
1580 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001581 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001582 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001583 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00001584 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001585 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001586 return sb_module;
1587}
1588
Greg Clayton13d19502012-01-29 06:07:39 +00001589lldb::ByteOrder
1590SBTarget::GetByteOrder ()
1591{
Greg Claytonacdbe812012-01-30 09:04:36 +00001592 TargetSP target_sp(GetSP());
1593 if (target_sp)
1594 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00001595 return eByteOrderInvalid;
1596}
1597
1598const char *
1599SBTarget::GetTriple ()
1600{
Greg Claytonacdbe812012-01-30 09:04:36 +00001601 TargetSP target_sp(GetSP());
1602 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00001603 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001604 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00001605 // Unique the string so we don't run into ownership issues since
1606 // the const strings put the string into the string pool once and
1607 // the strings never comes out
1608 ConstString const_triple (triple.c_str());
1609 return const_triple.GetCString();
1610 }
1611 return NULL;
1612}
1613
1614uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00001615SBTarget::GetDataByteSize ()
1616{
1617 TargetSP target_sp(GetSP());
1618 if (target_sp)
1619 {
1620 return target_sp->GetArchitecture().GetDataByteSize() ;
1621 }
1622 return 0;
1623}
1624
1625uint32_t
1626SBTarget::GetCodeByteSize ()
1627{
1628 TargetSP target_sp(GetSP());
1629 if (target_sp)
1630 {
1631 return target_sp->GetArchitecture().GetCodeByteSize() ;
1632 }
1633 return 0;
1634}
1635
1636uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00001637SBTarget::GetAddressByteSize()
1638{
Greg Claytonacdbe812012-01-30 09:04:36 +00001639 TargetSP target_sp(GetSP());
1640 if (target_sp)
1641 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00001642 return sizeof(void*);
1643}
1644
1645
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646SBModule
1647SBTarget::GetModuleAtIndex (uint32_t idx)
1648{
Greg Clayton5160ce52013-03-27 23:08:40 +00001649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001650
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001651 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001652 ModuleSP module_sp;
1653 TargetSP target_sp(GetSP());
1654 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001655 {
1656 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001657 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1658 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001659 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001660
1661 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001662 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1663 static_cast<void*>(target_sp.get()), idx,
1664 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001665
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666 return sb_module;
1667}
1668
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001669bool
1670SBTarget::RemoveModule (lldb::SBModule module)
1671{
Greg Claytonacdbe812012-01-30 09:04:36 +00001672 TargetSP target_sp(GetSP());
1673 if (target_sp)
1674 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001675 return false;
1676}
1677
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001678
1679SBBroadcaster
1680SBTarget::GetBroadcaster () const
1681{
Greg Clayton5160ce52013-03-27 23:08:40 +00001682 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001683
Greg Claytonacdbe812012-01-30 09:04:36 +00001684 TargetSP target_sp(GetSP());
1685 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001686
Caroline Ticeceb6b132010-10-26 03:11:13 +00001687 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001688 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1689 static_cast<void*>(target_sp.get()),
1690 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001691
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001692 return broadcaster;
1693}
1694
Caroline Ticedde9cff2010-09-20 05:20:02 +00001695bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001696SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001697{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001698 Stream &strm = description.ref();
1699
Greg Claytonacdbe812012-01-30 09:04:36 +00001700 TargetSP target_sp(GetSP());
1701 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00001702 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001703 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001704 }
1705 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001706 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001707
1708 return true;
1709}
1710
Greg Clayton5569e642012-02-06 01:44:54 +00001711lldb::SBSymbolContextList
1712SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00001713{
Greg Clayton5569e642012-02-06 01:44:54 +00001714 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00001715 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00001716 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001717 TargetSP target_sp(GetSP());
1718 if (target_sp)
1719 {
1720 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00001721 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00001722 const bool append = true;
1723 target_sp->GetImages().FindFunctions (ConstString(name),
1724 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001725 symbols_ok,
1726 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00001727 append,
1728 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00001729 }
Greg Claytonfe356d32011-06-21 01:34:41 +00001730 }
Greg Clayton5569e642012-02-06 01:44:54 +00001731 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00001732}
1733
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001734lldb::SBSymbolContextList
1735SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
1736{
1737 lldb::SBSymbolContextList sb_sc_list;
1738 if (name && name[0])
1739 {
1740 TargetSP target_sp(GetSP());
1741 if (target_sp)
1742 {
1743 std::string regexstr;
1744 switch (matchtype)
1745 {
1746 case eMatchTypeRegex:
1747 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
1748 break;
1749 case eMatchTypeStartsWith:
1750 regexstr = llvm::Regex::escape(name) + ".*";
1751 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1752 break;
1753 default:
1754 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
1755 break;
1756 }
1757 }
1758 }
1759 return sb_sc_list;
1760}
1761
Enrico Granata6f3533f2011-07-29 19:53:35 +00001762lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00001763SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001764{
Greg Claytonacdbe812012-01-30 09:04:36 +00001765 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001766 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001767 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001768 ConstString const_typename(typename_cstr);
1769 SymbolContext sc;
1770 const bool exact_match = false;
1771
1772 const ModuleList &module_list = target_sp->GetImages();
1773 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001774 for (size_t idx = 0; idx < count; idx++)
1775 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001776 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
1777 if (module_sp)
1778 {
1779 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
1780 if (type_sp)
1781 return SBType(type_sp);
1782 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001783 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001784
1785 // Didn't find the type in the symbols; try the Objective-C runtime
1786 // if one is installed
1787
1788 ProcessSP process_sp(target_sp->GetProcessSP());
1789
1790 if (process_sp)
1791 {
1792 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1793
1794 if (objc_language_runtime)
1795 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001796 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001797
Sean Callanan9998acd2014-12-05 01:21:59 +00001798 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001799 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001800 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001801
Sean Callanan9998acd2014-12-05 01:21:59 +00001802 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
1803 {
1804 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0]))
1805 {
1806 return SBType(type);
1807 }
1808 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001809 }
1810 }
1811 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001812
1813 // No matches, search for basic typename matches
1814 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1815 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001816 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001817 }
1818 return SBType();
1819}
1820
Greg Claytonb43165b2012-12-05 21:24:42 +00001821SBType
1822SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001823{
Greg Claytonacdbe812012-01-30 09:04:36 +00001824 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001825 if (target_sp)
1826 {
1827 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1828 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001829 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00001830 }
1831 return SBType();
1832}
1833
1834
1835lldb::SBTypeList
1836SBTarget::FindTypes (const char* typename_cstr)
1837{
1838 SBTypeList sb_type_list;
1839 TargetSP target_sp(GetSP());
1840 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001841 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001842 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00001843 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00001844 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001845 SymbolContext sc;
1846 TypeList type_list;
1847
Greg Clayton29399a22012-04-06 17:41:13 +00001848 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00001849 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00001850 exact_match,
1851 UINT32_MAX,
1852 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001853
Greg Claytonb43165b2012-12-05 21:24:42 +00001854 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001855 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001856 for (size_t idx = 0; idx < num_matches; idx++)
1857 {
1858 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1859 if (type_sp)
1860 sb_type_list.Append(SBType(type_sp));
1861 }
1862 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001863
1864 // Try the Objective-C runtime if one is installed
1865
1866 ProcessSP process_sp(target_sp->GetProcessSP());
1867
1868 if (process_sp)
1869 {
1870 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1871
1872 if (objc_language_runtime)
1873 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001874 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001875
Sean Callanan9998acd2014-12-05 01:21:59 +00001876 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001877 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001878 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001879
Sean Callanan9998acd2014-12-05 01:21:59 +00001880 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00001881 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001882 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00001883 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001884 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl))
1885 {
1886 sb_type_list.Append(SBType(type));
1887 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001888 }
1889 }
1890 }
1891 }
1892 }
1893
1894 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00001895 {
1896 // No matches, search for basic typename matches
1897 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1898 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001899 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001900 }
1901 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001902 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001903}
1904
Greg Claytondea8cb42011-06-29 22:09:02 +00001905SBValueList
1906SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1907{
1908 SBValueList sb_value_list;
1909
Greg Claytonacdbe812012-01-30 09:04:36 +00001910 TargetSP target_sp(GetSP());
1911 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00001912 {
1913 VariableList variable_list;
1914 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00001915 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1916 append,
1917 max_matches,
1918 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00001919
1920 if (match_count > 0)
1921 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001922 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001923 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00001924 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001925 for (uint32_t i=0; i<match_count; ++i)
1926 {
1927 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1928 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00001929 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00001930 }
1931 }
1932 }
1933
1934 return sb_value_list;
1935}
1936
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001937SBValueList
1938SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
1939{
1940 SBValueList sb_value_list;
1941
1942 TargetSP target_sp(GetSP());
1943 if (name && target_sp)
1944 {
1945 VariableList variable_list;
1946 const bool append = true;
1947
1948 std::string regexstr;
1949 uint32_t match_count;
1950 switch (matchtype)
1951 {
1952 case eMatchTypeNormal:
1953 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
1954 append,
1955 max_matches,
1956 variable_list);
1957 break;
1958 case eMatchTypeRegex:
1959 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
1960 append,
1961 max_matches,
1962 variable_list);
1963 break;
1964 case eMatchTypeStartsWith:
1965 regexstr = llvm::Regex::escape(name) + ".*";
1966 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
1967 append,
1968 max_matches,
1969 variable_list);
1970 break;
1971 }
1972
1973
1974 if (match_count > 0)
1975 {
1976 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1977 if (exe_scope == NULL)
1978 exe_scope = target_sp.get();
1979 for (uint32_t i = 0; i<match_count; ++i)
1980 {
1981 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
1982 if (valobj_sp)
1983 sb_value_list.Append(SBValue(valobj_sp));
1984 }
1985 }
1986 }
1987
1988 return sb_value_list;
1989}
1990
1991
Enrico Granatabcd80b42013-01-16 18:53:52 +00001992lldb::SBValue
1993SBTarget::FindFirstGlobalVariable (const char* name)
1994{
1995 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1996 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1997 return sb_value_list.GetValueAtIndex(0);
1998 return SBValue();
1999}
2000
Jim Inghame37d6052011-09-13 00:29:56 +00002001SBSourceManager
2002SBTarget::GetSourceManager()
2003{
2004 SBSourceManager source_manager (*this);
2005 return source_manager;
2006}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002007
Sean Callanan50952e92011-12-14 23:49:37 +00002008lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00002009SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2010{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002011 return ReadInstructions (base_addr, count, NULL);
2012}
2013
2014lldb::SBInstructionList
2015SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2016{
Greg Clayton9c766112012-03-06 22:24:44 +00002017 SBInstructionList sb_instructions;
2018
2019 TargetSP target_sp(GetSP());
2020 if (target_sp)
2021 {
2022 Address *addr_ptr = base_addr.get();
2023
2024 if (addr_ptr)
2025 {
2026 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2027 bool prefer_file_cache = false;
2028 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002029 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2030 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2031 prefer_file_cache,
2032 data.GetBytes(),
2033 data.GetByteSize(),
2034 error,
2035 &load_addr);
2036 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002037 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2038 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002039 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002040 *addr_ptr,
2041 data.GetBytes(),
2042 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002043 count,
2044 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002045 }
2046 }
2047
2048 return sb_instructions;
2049
2050}
2051
2052lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002053SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2054{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002055 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2056}
2057
2058lldb::SBInstructionList
2059SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2060{
Sean Callanan50952e92011-12-14 23:49:37 +00002061 SBInstructionList sb_instructions;
2062
Greg Claytonacdbe812012-01-30 09:04:36 +00002063 TargetSP target_sp(GetSP());
2064 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002065 {
2066 Address addr;
2067
2068 if (base_addr.get())
2069 addr = *base_addr.get();
2070
Greg Clayton3faf47c2013-03-28 23:42:53 +00002071 const bool data_from_file = true;
2072
Greg Claytonacdbe812012-01-30 09:04:36 +00002073 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002074 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002075 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002076 addr,
2077 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002078 size,
2079 UINT32_MAX,
2080 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002081 }
2082
2083 return sb_instructions;
2084}
2085
2086lldb::SBInstructionList
2087SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2088{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002089 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2090}
2091
2092lldb::SBInstructionList
2093SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2094{
2095 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002096}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002097
2098SBError
2099SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2100 lldb::addr_t section_base_addr)
2101{
2102 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002103 TargetSP target_sp(GetSP());
2104 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002105 {
2106 if (!section.IsValid())
2107 {
2108 sb_error.SetErrorStringWithFormat ("invalid section");
2109 }
2110 else
2111 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002112 SectionSP section_sp (section.GetSP());
2113 if (section_sp)
2114 {
2115 if (section_sp->IsThreadSpecific())
2116 {
2117 sb_error.SetErrorString ("thread specific sections are not yet supported");
2118 }
2119 else
2120 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002121 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002122 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002123 {
2124 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002125 if (process_sp)
2126 process_sp->Flush();
2127 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002128 }
2129 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002130 }
2131 }
2132 else
2133 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002134 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002135 }
2136 return sb_error;
2137}
2138
2139SBError
2140SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2141{
2142 SBError sb_error;
2143
Greg Claytonacdbe812012-01-30 09:04:36 +00002144 TargetSP target_sp(GetSP());
2145 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002146 {
2147 if (!section.IsValid())
2148 {
2149 sb_error.SetErrorStringWithFormat ("invalid section");
2150 }
2151 else
2152 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002153 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002154 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002155 {
2156 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002157 if (process_sp)
2158 process_sp->Flush();
2159 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002160 }
2161 }
2162 else
2163 {
2164 sb_error.SetErrorStringWithFormat ("invalid target");
2165 }
2166 return sb_error;
2167}
2168
2169SBError
2170SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2171{
2172 SBError sb_error;
2173
Greg Claytonacdbe812012-01-30 09:04:36 +00002174 TargetSP target_sp(GetSP());
2175 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002176 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002177 ModuleSP module_sp (module.GetSP());
2178 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002179 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002180 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002181 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002182 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002183 // The load was successful, make sure that at least some sections
2184 // changed before we notify that our module was loaded.
2185 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002186 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002187 ModuleList module_list;
2188 module_list.Append(module_sp);
2189 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002190 // Flush info in the process (stack frames, etc)
2191 ProcessSP process_sp (target_sp->GetProcessSP());
2192 if (process_sp)
2193 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002194 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002195 }
2196 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002197 else
2198 {
2199 sb_error.SetErrorStringWithFormat ("invalid module");
2200 }
2201
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002202 }
2203 else
2204 {
2205 sb_error.SetErrorStringWithFormat ("invalid target");
2206 }
2207 return sb_error;
2208}
2209
2210SBError
2211SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2212{
2213 SBError sb_error;
2214
2215 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002216 TargetSP target_sp(GetSP());
2217 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002218 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002219 ModuleSP module_sp (module.GetSP());
2220 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002221 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002222 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002223 if (objfile)
2224 {
2225 SectionList *section_list = objfile->GetSectionList();
2226 if (section_list)
2227 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002228 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002229
Greg Clayton3c947372013-01-29 01:17:09 +00002230 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002231 const size_t num_sections = section_list->GetSize();
2232 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2233 {
2234 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2235 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002236 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002237 }
2238 if (changed)
2239 {
2240 // Flush info in the process (stack frames, etc)
2241 ProcessSP process_sp (target_sp->GetProcessSP());
2242 if (process_sp)
2243 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002244 }
2245 }
2246 else
2247 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002248 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002249 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2250 }
2251 }
2252 else
2253 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002254 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002255 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2256 }
2257 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002258 else
2259 {
2260 sb_error.SetErrorStringWithFormat ("invalid module");
2261 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002262 }
2263 else
2264 {
2265 sb_error.SetErrorStringWithFormat ("invalid target");
2266 }
2267 return sb_error;
2268}
2269
2270
Greg Claytone14e1922012-12-04 02:22:16 +00002271lldb::SBSymbolContextList
2272SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2273{
2274 SBSymbolContextList sb_sc_list;
2275 if (name && name[0])
2276 {
2277 TargetSP target_sp(GetSP());
2278 if (target_sp)
2279 {
2280 bool append = true;
2281 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2282 symbol_type,
2283 *sb_sc_list,
2284 append);
2285 }
2286 }
2287 return sb_sc_list;
2288
2289}
2290
2291
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002292lldb::SBValue
2293SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2294{
Greg Clayton5160ce52013-03-27 23:08:40 +00002295 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2296 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002297 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002298 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002299 ValueObjectSP expr_value_sp;
2300 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002301 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002302 if (target_sp)
2303 {
2304 if (expr == NULL || expr[0] == '\0')
2305 {
2306 if (log)
2307 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2308 return expr_result;
2309 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002310
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002311 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2312 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002313
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002314 if (log)
2315 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002316
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002317 frame = exe_ctx.GetFramePtr();
2318 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002319
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002320 if (target)
2321 {
2322#ifdef LLDB_CONFIGURATION_DEBUG
2323 StreamString frame_description;
2324 if (frame)
2325 frame->DumpUsingSettingsFormat (&frame_description);
2326 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2327 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2328#endif
2329 exe_results = target->EvaluateExpression (expr,
2330 frame,
2331 expr_value_sp,
2332 options.ref());
2333
2334 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2335#ifdef LLDB_CONFIGURATION_DEBUG
2336 Host::SetCrashDescription (NULL);
2337#endif
2338 }
2339 else
2340 {
2341 if (log)
2342 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2343 }
2344 }
2345#ifndef LLDB_DISABLE_PYTHON
2346 if (expr_log)
2347 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002348 expr_result.GetValue(), expr_result.GetSummary());
2349
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002350 if (log)
2351 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002352 static_cast<void*>(frame), expr,
2353 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002354#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002355
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002356 return expr_result;
2357}
2358
Greg Clayton13fbb992013-02-01 00:47:49 +00002359
2360lldb::addr_t
2361SBTarget::GetStackRedZoneSize()
2362{
2363 TargetSP target_sp(GetSP());
2364 if (target_sp)
2365 {
2366 ABISP abi_sp;
2367 ProcessSP process_sp (target_sp->GetProcessSP());
2368 if (process_sp)
2369 abi_sp = process_sp->GetABI();
2370 else
2371 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2372 if (abi_sp)
2373 return abi_sp->GetRedZoneSize();
2374 }
2375 return 0;
2376}
Ilia K8f37ca52015-02-13 14:31:06 +00002377
2378lldb::SBLaunchInfo
2379SBTarget::GetLaunchInfo () const
2380{
2381 lldb::SBLaunchInfo launch_info(NULL);
2382 TargetSP target_sp(GetSP());
2383 if (target_sp)
2384 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2385 return launch_info;
2386}
2387
2388void
2389SBTarget::SetLaunchInfo (const lldb::SBLaunchInfo &launch_info)
2390{
2391 TargetSP target_sp(GetSP());
2392 if (target_sp)
2393 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2394}