blob: 7b0f6f2fb1816c2ec2c3899ef50e9a12f340a92c [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/SBDebugger.h"
17#include "lldb/API/SBBreakpoint.h"
Greg Clayton4b63a5c2013-01-04 18:10:18 +000018#include "lldb/API/SBExpressionOptions.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/API/SBFileSpec.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000020#include "lldb/API/SBListener.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/API/SBModule.h"
Greg Clayton226cce22013-07-08 22:22:41 +000022#include "lldb/API/SBModuleSpec.h"
Jim Inghame37d6052011-09-13 00:29:56 +000023#include "lldb/API/SBSourceManager.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000024#include "lldb/API/SBProcess.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000025#include "lldb/API/SBStream.h"
Greg Claytonfe356d32011-06-21 01:34:41 +000026#include "lldb/API/SBSymbolContextList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Breakpoint/BreakpointID.h"
28#include "lldb/Breakpoint/BreakpointIDList.h"
29#include "lldb/Breakpoint/BreakpointList.h"
30#include "lldb/Breakpoint/BreakpointLocation.h"
31#include "lldb/Core/Address.h"
32#include "lldb/Core/AddressResolver.h"
33#include "lldb/Core/AddressResolverName.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Core/ArchSpec.h"
35#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Disassembler.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000037#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000038#include "lldb/Core/Module.h"
39#include "lldb/Core/ModuleSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Core/RegularExpression.h"
41#include "lldb/Core/SearchFilter.h"
Greg Clayton1f746072012-08-29 21:13:06 +000042#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Core/STLUtils.h"
Enrico Granata347c2aa2013-10-08 21:49:02 +000044#include "lldb/Core/ValueObjectConstResult.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000045#include "lldb/Core/ValueObjectList.h"
46#include "lldb/Core/ValueObjectVariable.h"
47#include "lldb/Host/FileSpec.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000048#include "lldb/Host/Host.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000049#include "lldb/Interpreter/Args.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000050#include "lldb/Symbol/ClangASTContext.h"
51#include "lldb/Symbol/DeclVendor.h"
Greg Clayton1f746072012-08-29 21:13:06 +000052#include "lldb/Symbol/ObjectFile.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000053#include "lldb/Symbol/SymbolVendor.h"
Greg Claytondea8cb42011-06-29 22:09:02 +000054#include "lldb/Symbol/VariableList.h"
Zachary Turner32abc6e2015-03-03 19:23:09 +000055#include "lldb/Target/ABI.h"
Jim Inghamfab10e82012-03-06 00:37:27 +000056#include "lldb/Target/LanguageRuntime.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000057#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058#include "lldb/Target/Process.h"
59#include "lldb/Target/Target.h"
60#include "lldb/Target/TargetList.h"
61
62#include "lldb/Interpreter/CommandReturnObject.h"
63#include "../source/Commands/CommandObjectBreakpoint.h"
Carlo Kok0fd6fd42014-09-19 19:38:19 +000064#include "llvm/Support/Regex.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066
67using namespace lldb;
68using namespace lldb_private;
69
70#define DEFAULT_DISASM_BYTE_SIZE 32
71
Oleksiy Vyalov37386142015-02-10 22:49:57 +000072namespace {
73
74Error
75AttachToProcess (ProcessAttachInfo &attach_info, Target &target)
76{
77 Mutex::Locker api_locker (target.GetAPIMutex ());
78
79 auto process_sp = target.GetProcessSP ();
80 if (process_sp)
81 {
82 const auto state = process_sp->GetState ();
83 if (process_sp->IsAlive () && state == eStateConnected)
84 {
85 // If we are already connected, then we have already specified the
86 // listener, so if a valid listener is supplied, we need to error out
87 // to let the client know.
88 if (attach_info.GetListener ())
89 return Error ("process is connected and already has a listener, pass empty listener");
90 }
91 }
92
93 return target.Attach (attach_info, nullptr);
94}
95
96} // namespace
97
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098//----------------------------------------------------------------------
99// SBTarget constructor
100//----------------------------------------------------------------------
Greg Clayton54979cd2010-12-15 05:08:08 +0000101SBTarget::SBTarget () :
102 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103{
104}
105
106SBTarget::SBTarget (const SBTarget& rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000107 m_opaque_sp (rhs.m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108{
109}
110
111SBTarget::SBTarget(const TargetSP& target_sp) :
Greg Clayton66111032010-06-23 01:19:29 +0000112 m_opaque_sp (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113{
114}
115
Greg Claytonefabb122010-11-05 23:17:00 +0000116const SBTarget&
117SBTarget::operator = (const SBTarget& rhs)
118{
119 if (this != &rhs)
120 m_opaque_sp = rhs.m_opaque_sp;
121 return *this;
122}
123
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124//----------------------------------------------------------------------
125// Destructor
126//----------------------------------------------------------------------
127SBTarget::~SBTarget()
128{
129}
130
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000131const char *
132SBTarget::GetBroadcasterClassName ()
133{
134 return Target::GetStaticBroadcasterClass().AsCString();
135}
136
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137bool
138SBTarget::IsValid () const
139{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +0000140 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141}
142
143SBProcess
144SBTarget::GetProcess ()
145{
146 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000147 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000148 TargetSP target_sp(GetSP());
149 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000150 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000151 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000152 sb_process.SetSP (process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000153 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000154
Greg Clayton5160ce52013-03-27 23:08:40 +0000155 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000156 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000157 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
158 static_cast<void*>(target_sp.get()),
159 static_cast<void*>(process_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000160
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 return sb_process;
162}
163
Matthew Gardinerc928de32014-10-22 07:22:56 +0000164SBPlatform
165SBTarget::GetPlatform ()
166{
167 TargetSP target_sp(GetSP());
168 if (!target_sp)
169 return SBPlatform();
170
171 SBPlatform platform;
172 platform.m_opaque_sp = target_sp->GetPlatform();
173
174 return platform;
175}
176
Greg Clayton66111032010-06-23 01:19:29 +0000177SBDebugger
178SBTarget::GetDebugger () const
179{
180 SBDebugger debugger;
Greg Claytonacdbe812012-01-30 09:04:36 +0000181 TargetSP target_sp(GetSP());
182 if (target_sp)
183 debugger.reset (target_sp->GetDebugger().shared_from_this());
Greg Clayton66111032010-06-23 01:19:29 +0000184 return debugger;
185}
186
Jim Ingham270684d2011-03-31 00:01:24 +0000187SBProcess
Greg Clayton4d8ad552013-03-25 22:40:51 +0000188SBTarget::LoadCore (const char *core_file)
189{
190 SBProcess sb_process;
191 TargetSP target_sp(GetSP());
192 if (target_sp)
193 {
194 FileSpec filespec(core_file, true);
195 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
196 NULL,
197 &filespec));
198 if (process_sp)
199 {
200 process_sp->LoadCore();
201 sb_process.SetSP (process_sp);
202 }
203 }
204 return sb_process;
205}
206
207SBProcess
Jim Ingham270684d2011-03-31 00:01:24 +0000208SBTarget::LaunchSimple
209(
210 char const **argv,
211 char const **envp,
212 const char *working_directory
213)
214{
215 char *stdin_path = NULL;
216 char *stdout_path = NULL;
217 char *stderr_path = NULL;
218 uint32_t launch_flags = 0;
219 bool stop_at_entry = false;
220 SBError error;
221 SBListener listener = GetDebugger().GetListener();
222 return Launch (listener,
223 argv,
224 envp,
225 stdin_path,
226 stdout_path,
227 stderr_path,
228 working_directory,
229 launch_flags,
230 stop_at_entry,
231 error);
232}
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000233
Greg Claytonfbb76342013-11-20 21:07:01 +0000234SBError
235SBTarget::Install()
236{
237 SBError sb_error;
238 TargetSP target_sp(GetSP());
239 if (target_sp)
240 {
241 Mutex::Locker api_locker (target_sp->GetAPIMutex());
242 sb_error.ref() = target_sp->Install(NULL);
243 }
244 return sb_error;
245}
246
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000247SBProcess
248SBTarget::Launch
249(
Greg Clayton4b045622011-02-03 21:28:34 +0000250 SBListener &listener,
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000251 char const **argv,
252 char const **envp,
253 const char *stdin_path,
254 const char *stdout_path,
255 const char *stderr_path,
256 const char *working_directory,
257 uint32_t launch_flags, // See LaunchFlags
258 bool stop_at_entry,
259 lldb::SBError& error
260)
261{
Greg Clayton5160ce52013-03-27 23:08:40 +0000262 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000263
Greg Claytonacdbe812012-01-30 09:04:36 +0000264 SBProcess sb_process;
265 ProcessSP process_sp;
266 TargetSP target_sp(GetSP());
267
Caroline Ticeceb6b132010-10-26 03:11:13 +0000268 if (log)
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000269 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 +0000270 static_cast<void*>(target_sp.get()),
271 static_cast<void*>(argv), static_cast<void*>(envp),
272 stdin_path ? stdin_path : "NULL",
273 stdout_path ? stdout_path : "NULL",
274 stderr_path ? stderr_path : "NULL",
Greg Claytonbd82a5d2011-01-23 05:56:20 +0000275 working_directory ? working_directory : "NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000276 launch_flags, stop_at_entry,
277 static_cast<void*>(error.get()));
Greg Claytonacdbe812012-01-30 09:04:36 +0000278
279 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000281 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton5d5028b2010-10-06 03:53:16 +0000282
Zachary Turner6fd3f342015-02-02 18:50:01 +0000283 if (stop_at_entry)
284 launch_flags |= eLaunchFlagStopAtEntry;
285
Greg Clayton645bf542011-01-27 01:01:10 +0000286 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
287 launch_flags |= eLaunchFlagDisableASLR;
288
Greg Clayton2289fa42011-04-30 01:09:13 +0000289 StateType state = eStateInvalid;
Greg Claytonacdbe812012-01-30 09:04:36 +0000290 process_sp = target_sp->GetProcessSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000291 if (process_sp)
Greg Clayton931180e2011-01-27 06:44:37 +0000292 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000293 state = process_sp->GetState();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000294
Greg Claytonb9556ac2012-01-30 07:41:31 +0000295 if (process_sp->IsAlive() && state != eStateConnected)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000296 {
Greg Clayton2289fa42011-04-30 01:09:13 +0000297 if (state == eStateAttaching)
298 error.SetErrorString ("process attach is in progress");
299 else
300 error.SetErrorString ("a process is already being debugged");
Greg Clayton2289fa42011-04-30 01:09:13 +0000301 return sb_process;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000302 }
Greg Clayton931180e2011-01-27 06:44:37 +0000303 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000304
Greg Clayton2289fa42011-04-30 01:09:13 +0000305 if (state == eStateConnected)
306 {
307 // If we are already connected, then we have already specified the
308 // listener, so if a valid listener is supplied, we need to error out
309 // to let the client know.
310 if (listener.IsValid())
311 {
312 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
Greg Clayton2289fa42011-04-30 01:09:13 +0000313 return sb_process;
314 }
315 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000316
317 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
318 launch_flags |= eLaunchFlagDisableSTDIO;
319
320 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000321
Greg Claytonb09c5382013-12-13 17:20:18 +0000322 Module *exe_module = target_sp->GetExecutableModulePointer();
323 if (exe_module)
324 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
325 if (argv)
326 launch_info.GetArguments().AppendArguments (argv);
327 if (envp)
328 launch_info.GetEnvironmentEntries ().SetArguments (envp);
329
330 if (listener.IsValid())
Greg Clayton8012cad2014-11-17 19:39:20 +0000331 launch_info.SetListener(listener.GetSP());
332
333 error.SetError (target_sp->Launch(launch_info, NULL));
Greg Clayton645bf542011-01-27 01:01:10 +0000334
Greg Claytonb09c5382013-12-13 17:20:18 +0000335 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton524e60b2010-10-06 22:10:17 +0000336 }
337 else
338 {
339 error.SetErrorString ("SBTarget is invalid");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000341
Caroline Tice20ad3c42010-10-29 21:48:37 +0000342 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000343 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000344 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
345 static_cast<void*>(target_sp.get()),
346 static_cast<void*>(sb_process.GetSP().get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000347
Greg Clayton5d5028b2010-10-06 03:53:16 +0000348 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349}
350
Greg Clayton0e615682012-02-24 05:03:03 +0000351SBProcess
352SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
353{
Greg Clayton5160ce52013-03-27 23:08:40 +0000354 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000355
Greg Clayton0e615682012-02-24 05:03:03 +0000356 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000357 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000358
Greg Clayton0e615682012-02-24 05:03:03 +0000359 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000360 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...",
361 static_cast<void*>(target_sp.get()));
362
Greg Clayton0e615682012-02-24 05:03:03 +0000363 if (target_sp)
364 {
365 Mutex::Locker api_locker (target_sp->GetAPIMutex());
366 StateType state = eStateInvalid;
Greg Claytonb09c5382013-12-13 17:20:18 +0000367 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000368 ProcessSP process_sp = target_sp->GetProcessSP();
369 if (process_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000370 {
Greg Clayton3e32ad62014-05-07 20:16:06 +0000371 state = process_sp->GetState();
372
373 if (process_sp->IsAlive() && state != eStateConnected)
374 {
375 if (state == eStateAttaching)
376 error.SetErrorString ("process attach is in progress");
377 else
378 error.SetErrorString ("a process is already being debugged");
379 return sb_process;
380 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000381 }
Greg Clayton0e615682012-02-24 05:03:03 +0000382 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000383
384 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
385
Greg Clayton3e32ad62014-05-07 20:16:06 +0000386 if (!launch_info.GetExecutableFile())
387 {
388 Module *exe_module = target_sp->GetExecutableModulePointer();
389 if (exe_module)
390 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
391 }
Greg Claytonb09c5382013-12-13 17:20:18 +0000392
393 const ArchSpec &arch_spec = target_sp->GetArchitecture();
394 if (arch_spec.IsValid())
395 launch_info.GetArchitecture () = arch_spec;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000396
Greg Clayton8012cad2014-11-17 19:39:20 +0000397 error.SetError (target_sp->Launch (launch_info, NULL));
Greg Claytonb09c5382013-12-13 17:20:18 +0000398 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000399 }
400 else
401 {
402 error.SetErrorString ("SBTarget is invalid");
403 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000404
Greg Clayton0e615682012-02-24 05:03:03 +0000405 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
406 if (log)
Greg Claytonb09c5382013-12-13 17:20:18 +0000407 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000408 static_cast<void*>(target_sp.get()),
409 static_cast<void*>(sb_process.GetSP().get()));
410
Greg Clayton0e615682012-02-24 05:03:03 +0000411 return sb_process;
412}
413
414lldb::SBProcess
415SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
416{
Greg Clayton5160ce52013-03-27 23:08:40 +0000417 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000418
Greg Clayton0e615682012-02-24 05:03:03 +0000419 SBProcess sb_process;
Greg Clayton0e615682012-02-24 05:03:03 +0000420 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000421
Sean Callanan575a4542012-10-20 00:21:31 +0000422 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000423 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...",
424 static_cast<void*>(target_sp.get()));
425
Greg Clayton0e615682012-02-24 05:03:03 +0000426 if (target_sp)
427 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000428 ProcessAttachInfo &attach_info = sb_attach_info.ref();
429 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
Greg Clayton0e615682012-02-24 05:03:03 +0000430 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000431 PlatformSP platform_sp = target_sp->GetPlatform();
432 // See if we can pre-verify if a process exists or not
433 if (platform_sp && platform_sp->IsConnected())
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000434 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000435 lldb::pid_t attach_pid = attach_info.GetProcessID();
436 ProcessInstanceInfo instance_info;
437 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
Han Ming Ongcec8c902012-02-29 00:12:56 +0000438 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000439 attach_info.SetUserID(instance_info.GetEffectiveUserID());
440 }
441 else
442 {
443 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
444 if (log)
Greg Clayton91e407e2012-09-27 00:03:39 +0000445 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000446 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
447 static_cast<void*>(target_sp.get()), error.GetCString());
Greg Clayton91e407e2012-09-27 00:03:39 +0000448 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000449 return sb_process;
Han Ming Ongcec8c902012-02-29 00:12:56 +0000450 }
451 }
Greg Clayton0e615682012-02-24 05:03:03 +0000452 }
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000453 error.SetError(AttachToProcess(attach_info, *target_sp));
454 if (error.Success())
455 sb_process.SetSP(target_sp->GetProcessSP());
Greg Clayton0e615682012-02-24 05:03:03 +0000456 }
457 else
458 {
459 error.SetErrorString ("SBTarget is invalid");
460 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000461
Sean Callanan575a4542012-10-20 00:21:31 +0000462 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000463 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000464 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000465 static_cast<void*>(sb_process.GetSP().get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000466
Greg Clayton0e615682012-02-24 05:03:03 +0000467 return sb_process;
468}
469
470
Greg Clayton1ba6cfd2011-12-02 02:10:57 +0000471#if defined(__APPLE__)
472
473lldb::SBProcess
474SBTarget::AttachToProcessWithID (SBListener &listener,
475 ::pid_t pid,
476 lldb::SBError& error)
477{
478 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
479}
480
481#endif // #if defined(__APPLE__)
Greg Clayton524e60b2010-10-06 22:10:17 +0000482
483lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000484SBTarget::AttachToProcessWithID
Greg Clayton524e60b2010-10-06 22:10:17 +0000485(
Greg Clayton4b045622011-02-03 21:28:34 +0000486 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000487 lldb::pid_t pid,// The process ID to attach to
488 SBError& error // An error explaining what went wrong if attach fails
489)
490{
Greg Clayton5160ce52013-03-27 23:08:40 +0000491 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000492
Greg Clayton524e60b2010-10-06 22:10:17 +0000493 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000494 TargetSP target_sp(GetSP());
Sean Callanan575a4542012-10-20 00:21:31 +0000495
496 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000497 log->Printf ("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
498 static_cast<void*>(target_sp.get()),
499 __FUNCTION__,
500 pid);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000501
Greg Claytonacdbe812012-01-30 09:04:36 +0000502 if (target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000503 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000504 ProcessAttachInfo attach_info;
505 attach_info.SetProcessID (pid);
506 if (listener.IsValid())
507 attach_info.SetListener(listener.GetSP());
Greg Clayton0c74e782011-06-24 03:21:43 +0000508
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000509 ProcessInstanceInfo instance_info;
510 if (target_sp->GetPlatform ()->GetProcessInfo (pid, instance_info))
511 attach_info.SetUserID (instance_info.GetEffectiveUserID ());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000512
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000513 error.SetError (AttachToProcess (attach_info, *target_sp));
514 if (error.Success ())
515 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000516 }
517 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000518 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000519
Sean Callanan575a4542012-10-20 00:21:31 +0000520 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000521 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
522 static_cast<void*>(target_sp.get ()),
523 __FUNCTION__,
524 static_cast<void*>(sb_process.GetSP().get ()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000525 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000526}
527
528lldb::SBProcess
Greg Clayton05faeb72010-10-07 04:19:01 +0000529SBTarget::AttachToProcessWithName
Greg Clayton524e60b2010-10-06 22:10:17 +0000530(
Greg Clayton4b045622011-02-03 21:28:34 +0000531 SBListener &listener,
Greg Clayton524e60b2010-10-06 22:10:17 +0000532 const char *name, // basename of process to attach to
533 bool wait_for, // if true wait for a new instance of "name" to be launched
534 SBError& error // An error explaining what went wrong if attach fails
535)
536{
Greg Clayton5160ce52013-03-27 23:08:40 +0000537 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000538
Greg Clayton524e60b2010-10-06 22:10:17 +0000539 SBProcess sb_process;
Greg Claytonacdbe812012-01-30 09:04:36 +0000540 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000541
Sean Callanan575a4542012-10-20 00:21:31 +0000542 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000543 log->Printf ("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
544 static_cast<void*>(target_sp.get()),
545 __FUNCTION__,
546 name,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000547 wait_for ? "true" : "false");
548
Greg Claytonacdbe812012-01-30 09:04:36 +0000549 if (name && target_sp)
Greg Clayton524e60b2010-10-06 22:10:17 +0000550 {
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000551 ProcessAttachInfo attach_info;
552 attach_info.GetExecutableFile().SetFile(name, false);
553 attach_info.SetWaitForLaunch(wait_for);
554 if (listener.IsValid())
555 attach_info.SetListener(listener.GetSP());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000556
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000557 error.SetError (AttachToProcess (attach_info, *target_sp));
558 if (error.Success ())
559 sb_process.SetSP (target_sp->GetProcessSP ());
Greg Clayton524e60b2010-10-06 22:10:17 +0000560 }
561 else
Greg Clayton524e60b2010-10-06 22:10:17 +0000562 error.SetErrorString ("SBTarget is invalid");
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000563
Sean Callanan575a4542012-10-20 00:21:31 +0000564 if (log)
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000565 log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000566 static_cast<void*>(target_sp.get()),
Oleksiy Vyalov37386142015-02-10 22:49:57 +0000567 __FUNCTION__,
568 static_cast<void*>(sb_process.GetSP().get()));
Greg Clayton524e60b2010-10-06 22:10:17 +0000569 return sb_process;
Greg Clayton524e60b2010-10-06 22:10:17 +0000570}
571
James McIlree9631aae2011-03-04 00:31:13 +0000572lldb::SBProcess
573SBTarget::ConnectRemote
574(
575 SBListener &listener,
576 const char *url,
577 const char *plugin_name,
578 SBError& error
579)
580{
Greg Clayton5160ce52013-03-27 23:08:40 +0000581 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan575a4542012-10-20 00:21:31 +0000582
James McIlree9631aae2011-03-04 00:31:13 +0000583 SBProcess sb_process;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000584 ProcessSP process_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000585 TargetSP target_sp(GetSP());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000586
Sean Callanan575a4542012-10-20 00:21:31 +0000587 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000588 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...",
589 static_cast<void*>(target_sp.get()), url, plugin_name);
590
Greg Claytonacdbe812012-01-30 09:04:36 +0000591 if (target_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000592 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000593 Mutex::Locker api_locker (target_sp->GetAPIMutex());
James McIlree9631aae2011-03-04 00:31:13 +0000594 if (listener.IsValid())
Greg Claytonc3776bf2012-02-09 06:16:32 +0000595 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
James McIlree9631aae2011-03-04 00:31:13 +0000596 else
Greg Claytonc3776bf2012-02-09 06:16:32 +0000597 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000598
Greg Claytonb9556ac2012-01-30 07:41:31 +0000599 if (process_sp)
James McIlree9631aae2011-03-04 00:31:13 +0000600 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000601 sb_process.SetSP (process_sp);
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000602 error.SetError (process_sp->ConnectRemote (NULL, url));
James McIlree9631aae2011-03-04 00:31:13 +0000603 }
604 else
605 {
606 error.SetErrorString ("unable to create lldb_private::Process");
607 }
608 }
609 else
610 {
611 error.SetErrorString ("SBTarget is invalid");
612 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000613
Sean Callanan575a4542012-10-20 00:21:31 +0000614 if (log)
Sean Callanan575a4542012-10-20 00:21:31 +0000615 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000616 static_cast<void*>(target_sp.get()),
617 static_cast<void*>(process_sp.get()));
James McIlree9631aae2011-03-04 00:31:13 +0000618 return sb_process;
619}
620
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621SBFileSpec
622SBTarget::GetExecutable ()
623{
Caroline Ticeceb6b132010-10-26 03:11:13 +0000624
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 SBFileSpec exe_file_spec;
Greg Claytonacdbe812012-01-30 09:04:36 +0000626 TargetSP target_sp(GetSP());
627 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000629 Module *exe_module = target_sp->GetExecutableModulePointer();
Greg Claytonaa149cb2011-08-11 02:48:45 +0000630 if (exe_module)
631 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000633
Greg Clayton5160ce52013-03-27 23:08:40 +0000634 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000635 if (log)
636 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000637 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
638 static_cast<void*>(target_sp.get()),
639 static_cast<const void*>(exe_file_spec.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000640 }
641
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642 return exe_file_spec;
643}
644
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646SBTarget::operator == (const SBTarget &rhs) const
647{
Greg Clayton66111032010-06-23 01:19:29 +0000648 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649}
650
651bool
652SBTarget::operator != (const SBTarget &rhs) const
653{
Greg Clayton66111032010-06-23 01:19:29 +0000654 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655}
656
Greg Claytonb9556ac2012-01-30 07:41:31 +0000657lldb::TargetSP
658SBTarget::GetSP () const
Greg Clayton9a377662011-10-01 02:59:24 +0000659{
660 return m_opaque_sp;
661}
662
Greg Clayton66111032010-06-23 01:19:29 +0000663void
Greg Claytonb9556ac2012-01-30 07:41:31 +0000664SBTarget::SetSP (const lldb::TargetSP& target_sp)
Greg Clayton66111032010-06-23 01:19:29 +0000665{
666 m_opaque_sp = target_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667}
668
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000669lldb::SBAddress
670SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000671{
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000672 lldb::SBAddress sb_addr;
673 Address &addr = sb_addr.ref();
Greg Claytonacdbe812012-01-30 09:04:36 +0000674 TargetSP target_sp(GetSP());
675 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000676 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000677 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytond5944cd2013-12-06 01:12:00 +0000678 if (target_sp->ResolveLoadAddress (vm_addr, addr))
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000679 return sb_addr;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000680 }
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000681
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000682 // We have a load address that isn't in a section, just return an address
683 // with the offset filled in (the address) and the section set to NULL
Greg Claytone72dfb32012-02-24 01:59:29 +0000684 addr.SetRawAddress(vm_addr);
Greg Clayton00e6fbf2011-07-22 16:46:35 +0000685 return sb_addr;
Greg Claytonac2eb9b2010-12-12 19:25:26 +0000686}
687
Matthew Gardinerc928de32014-10-22 07:22:56 +0000688lldb::SBAddress
689SBTarget::ResolveFileAddress (lldb::addr_t file_addr)
690{
691 lldb::SBAddress sb_addr;
692 Address &addr = sb_addr.ref();
693 TargetSP target_sp(GetSP());
694 if (target_sp)
695 {
696 Mutex::Locker api_locker (target_sp->GetAPIMutex());
697 if (target_sp->ResolveFileAddress (file_addr, addr))
698 return sb_addr;
699 }
700
701 addr.SetRawAddress(file_addr);
702 return sb_addr;
703}
Greg Claytond5944cd2013-12-06 01:12:00 +0000704
705lldb::SBAddress
706SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
707{
708 lldb::SBAddress sb_addr;
709 Address &addr = sb_addr.ref();
710 TargetSP target_sp(GetSP());
711 if (target_sp)
712 {
713 Mutex::Locker api_locker (target_sp->GetAPIMutex());
714 if (target_sp->ResolveLoadAddress (vm_addr, addr))
715 return sb_addr;
716 }
717
718 // We have a load address that isn't in a section, just return an address
719 // with the offset filled in (the address) and the section set to NULL
720 addr.SetRawAddress(vm_addr);
721 return sb_addr;
722}
723
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000724SBSymbolContext
Greg Claytoneb023e72013-10-11 19:48:25 +0000725SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
726 uint32_t resolve_scope)
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000727{
728 SBSymbolContext sc;
Greg Claytonacdbe812012-01-30 09:04:36 +0000729 if (addr.IsValid())
730 {
731 TargetSP target_sp(GetSP());
732 if (target_sp)
733 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
734 }
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000735 return sc;
736}
737
Matthew Gardinerc928de32014-10-22 07:22:56 +0000738size_t
739SBTarget::ReadMemory (const SBAddress addr,
740 void *buf,
741 size_t size,
742 lldb::SBError &error)
743{
744 SBError sb_error;
745 size_t bytes_read = 0;
746 TargetSP target_sp(GetSP());
747 if (target_sp)
748 {
749 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8691dc52014-11-04 00:56:30 +0000750 bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
751 }
752 else
753 {
754 sb_error.SetErrorString("invalid target");
Matthew Gardinerc928de32014-10-22 07:22:56 +0000755 }
756
757 return bytes_read;
758}
Greg Clayton5f2a4f92011-03-02 21:34:46 +0000759
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000761SBTarget::BreakpointCreateByLocation (const char *file,
762 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763{
Greg Clayton7481c202010-11-08 00:28:40 +0000764 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765}
766
767SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000768SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
769 uint32_t line)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770{
Greg Clayton5160ce52013-03-27 23:08:40 +0000771 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000772
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000774 TargetSP target_sp(GetSP());
775 if (target_sp && line != 0)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000776 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000777 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000778
Greg Clayton1f746072012-08-29 21:13:06 +0000779 const LazyBool check_inlines = eLazyBoolCalculate;
Jim Inghama8558b62012-05-22 00:12:20 +0000780 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Clayton1f746072012-08-29 21:13:06 +0000781 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000782 const bool hardware = false;
783 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000784 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000785
786 if (log)
787 {
788 SBStream sstr;
789 sb_bp.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000790 char path[PATH_MAX];
791 sb_file_spec->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000792 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
793 static_cast<void*>(target_sp.get()), path, line,
794 static_cast<void*>(sb_bp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000795 }
796
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 return sb_bp;
798}
799
800SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000801SBTarget::BreakpointCreateByName (const char *symbol_name,
802 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803{
Greg Clayton5160ce52013-03-27 23:08:40 +0000804 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000805
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000806 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000807 TargetSP target_sp(GetSP());
808 if (target_sp.get())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000810 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000811
Jim Inghama8558b62012-05-22 00:12:20 +0000812 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000813 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000814 const LazyBool skip_prologue = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815 if (module_name && module_name[0])
816 {
Jim Ingham969795f2011-09-21 01:17:13 +0000817 FileSpecList module_spec_list;
818 module_spec_list.Append (FileSpec (module_name, false));
Greg Claytoneb023e72013-10-11 19:48:25 +0000819 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820 }
821 else
822 {
Greg Claytoneb023e72013-10-11 19:48:25 +0000823 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 }
825 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000826
Caroline Ticeceb6b132010-10-26 03:11:13 +0000827 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000828 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
829 static_cast<void*>(target_sp.get()), symbol_name,
830 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000831
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000832 return sb_bp;
833}
834
Jim Ingham87df91b2011-09-23 00:54:11 +0000835lldb::SBBreakpoint
836SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000837 const SBFileSpecList &module_list,
838 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000839{
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000840 uint32_t name_type_mask = eFunctionNameTypeAuto;
841 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
842}
843
844lldb::SBBreakpoint
845SBTarget::BreakpointCreateByName (const char *symbol_name,
Greg Claytoneb023e72013-10-11 19:48:25 +0000846 uint32_t name_type_mask,
847 const SBFileSpecList &module_list,
848 const SBFileSpecList &comp_unit_list)
Jim Ingham2dd7f7f2011-10-11 01:18:55 +0000849{
Greg Clayton5160ce52013-03-27 23:08:40 +0000850 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +0000851
852 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000853 TargetSP target_sp(GetSP());
854 if (target_sp && symbol_name && symbol_name[0])
Jim Ingham87df91b2011-09-23 00:54:11 +0000855 {
Jim Inghama8558b62012-05-22 00:12:20 +0000856 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000857 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000858 const LazyBool skip_prologue = eLazyBoolCalculate;
Greg Claytonacdbe812012-01-30 09:04:36 +0000859 Mutex::Locker api_locker (target_sp->GetAPIMutex());
860 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
Greg Claytoneb023e72013-10-11 19:48:25 +0000861 comp_unit_list.get(),
862 symbol_name,
863 name_type_mask,
864 skip_prologue,
865 internal,
866 hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +0000867 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000868
Jim Ingham87df91b2011-09-23 00:54:11 +0000869 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000870 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
871 static_cast<void*>(target_sp.get()), symbol_name,
872 name_type_mask, static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +0000873
874 return sb_bp;
875}
876
Jim Inghamfab10e82012-03-06 00:37:27 +0000877lldb::SBBreakpoint
878SBTarget::BreakpointCreateByNames (const char *symbol_names[],
879 uint32_t num_names,
880 uint32_t name_type_mask,
881 const SBFileSpecList &module_list,
882 const SBFileSpecList &comp_unit_list)
883{
Greg Clayton5160ce52013-03-27 23:08:40 +0000884 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +0000885
886 SBBreakpoint sb_bp;
887 TargetSP target_sp(GetSP());
888 if (target_sp && num_names > 0)
889 {
890 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Inghama8558b62012-05-22 00:12:20 +0000891 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000892 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000893 const LazyBool skip_prologue = eLazyBoolCalculate;
Jim Inghamfab10e82012-03-06 00:37:27 +0000894 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
895 comp_unit_list.get(),
896 symbol_names,
897 num_names,
898 name_type_mask,
Jim Inghama8558b62012-05-22 00:12:20 +0000899 skip_prologue,
Greg Claytoneb023e72013-10-11 19:48:25 +0000900 internal,
901 hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +0000902 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000903
Jim Inghamfab10e82012-03-06 00:37:27 +0000904 if (log)
905 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000906 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={",
907 static_cast<void*>(target_sp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000908 for (uint32_t i = 0 ; i < num_names; i++)
909 {
910 char sep;
911 if (i < num_names - 1)
912 sep = ',';
913 else
914 sep = '}';
915 if (symbol_names[i] != NULL)
916 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
917 else
918 log->Printf ("\"<NULL>\"%c ", sep);
Jim Inghamfab10e82012-03-06 00:37:27 +0000919 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000920 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
921 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +0000922 }
923
924 return sb_bp;
925}
Jim Ingham87df91b2011-09-23 00:54:11 +0000926
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000927SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +0000928SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
929 const char *module_name)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930{
Greg Clayton5160ce52013-03-27 23:08:40 +0000931 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000932
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000933 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000934 TargetSP target_sp(GetSP());
935 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000936 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000937 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000938 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +0000939 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000940 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000941 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000942
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000943 if (module_name && module_name[0])
944 {
Jim Ingham969795f2011-09-21 01:17:13 +0000945 FileSpecList module_spec_list;
946 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000947
Greg Claytoneb023e72013-10-11 19:48:25 +0000948 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949 }
950 else
951 {
Greg Claytoneb023e72013-10-11 19:48:25 +0000952 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000953 }
954 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000955
956 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000957 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
958 static_cast<void*>(target_sp.get()), symbol_name_regex,
959 module_name, static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000960
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 return sb_bp;
962}
963
Jim Ingham87df91b2011-09-23 00:54:11 +0000964lldb::SBBreakpoint
965SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
Greg Claytoneb023e72013-10-11 19:48:25 +0000966 const SBFileSpecList &module_list,
967 const SBFileSpecList &comp_unit_list)
Jim Ingham87df91b2011-09-23 00:54:11 +0000968{
Greg Clayton5160ce52013-03-27 23:08:40 +0000969 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000970
Jim Ingham87df91b2011-09-23 00:54:11 +0000971 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000972 TargetSP target_sp(GetSP());
973 if (target_sp && symbol_name_regex && symbol_name_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +0000974 {
Greg Claytonacdbe812012-01-30 09:04:36 +0000975 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham87df91b2011-09-23 00:54:11 +0000976 RegularExpression regexp(symbol_name_regex);
Jim Inghama8558b62012-05-22 00:12:20 +0000977 const bool internal = false;
Greg Claytoneb023e72013-10-11 19:48:25 +0000978 const bool hardware = false;
Jim Inghama8558b62012-05-22 00:12:20 +0000979 const LazyBool skip_prologue = eLazyBoolCalculate;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000980
Greg Claytoneb023e72013-10-11 19:48:25 +0000981 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +0000982 }
983
984 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000985 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
986 static_cast<void*>(target_sp.get()), symbol_name_regex,
987 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +0000988
989 return sb_bp;
990}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991
992SBBreakpoint
993SBTarget::BreakpointCreateByAddress (addr_t address)
994{
Greg Clayton5160ce52013-03-27 23:08:40 +0000995 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000996
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000997 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +0000998 TargetSP target_sp(GetSP());
999 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001000 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001001 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001002 const bool hardware = false;
1003 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001004 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001005
Caroline Ticeceb6b132010-10-26 03:11:13 +00001006 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001007 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)",
1008 static_cast<void*>(target_sp.get()),
1009 static_cast<uint64_t>(address),
1010 static_cast<void*>(sb_bp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001011
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012 return sb_bp;
1013}
1014
Jim Ingham969795f2011-09-21 01:17:13 +00001015lldb::SBBreakpoint
Greg Claytoneb023e72013-10-11 19:48:25 +00001016SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1017 const lldb::SBFileSpec &source_file,
1018 const char *module_name)
Jim Ingham969795f2011-09-21 01:17:13 +00001019{
Greg Clayton5160ce52013-03-27 23:08:40 +00001020 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham969795f2011-09-21 01:17:13 +00001021
1022 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001023 TargetSP target_sp(GetSP());
1024 if (target_sp && source_regex && source_regex[0])
Jim Ingham969795f2011-09-21 01:17:13 +00001025 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001026 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Jim Ingham969795f2011-09-21 01:17:13 +00001027 RegularExpression regexp(source_regex);
Jim Ingham87df91b2011-09-23 00:54:11 +00001028 FileSpecList source_file_spec_list;
Greg Claytoneb023e72013-10-11 19:48:25 +00001029 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001030 source_file_spec_list.Append (source_file.ref());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001031
Jim Ingham969795f2011-09-21 01:17:13 +00001032 if (module_name && module_name[0])
1033 {
1034 FileSpecList module_spec_list;
1035 module_spec_list.Append (FileSpec (module_name, false));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001036
Greg Claytoneb023e72013-10-11 19:48:25 +00001037 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001038 }
1039 else
1040 {
Greg Claytoneb023e72013-10-11 19:48:25 +00001041 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
Jim Ingham969795f2011-09-21 01:17:13 +00001042 }
1043 }
1044
1045 if (log)
1046 {
1047 char path[PATH_MAX];
1048 source_file->GetPath (path, sizeof(path));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001049 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1050 static_cast<void*>(target_sp.get()), source_regex, path,
1051 module_name, static_cast<void*>(sb_bp.get()));
Jim Ingham969795f2011-09-21 01:17:13 +00001052 }
1053
1054 return sb_bp;
1055}
1056
Jim Ingham87df91b2011-09-23 00:54:11 +00001057lldb::SBBreakpoint
Jim Inghame7320522015-02-12 17:37:46 +00001058SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1059 const SBFileSpecList &module_list,
1060 const lldb::SBFileSpecList &source_file_list)
Jim Ingham87df91b2011-09-23 00:54:11 +00001061{
Greg Clayton5160ce52013-03-27 23:08:40 +00001062 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +00001063
1064 SBBreakpoint sb_bp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001065 TargetSP target_sp(GetSP());
1066 if (target_sp && source_regex && source_regex[0])
Jim Ingham87df91b2011-09-23 00:54:11 +00001067 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001068 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001069 const bool hardware = false;
Jim Ingham87df91b2011-09-23 00:54:11 +00001070 RegularExpression regexp(source_regex);
Greg Claytoneb023e72013-10-11 19:48:25 +00001071 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
Jim Ingham87df91b2011-09-23 00:54:11 +00001072 }
1073
1074 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001075 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1076 static_cast<void*>(target_sp.get()), source_regex,
1077 static_cast<void*>(sb_bp.get()));
Jim Ingham87df91b2011-09-23 00:54:11 +00001078
1079 return sb_bp;
1080}
Jim Ingham969795f2011-09-21 01:17:13 +00001081
Jim Inghamfab10e82012-03-06 00:37:27 +00001082lldb::SBBreakpoint
1083SBTarget::BreakpointCreateForException (lldb::LanguageType language,
Greg Claytoneb023e72013-10-11 19:48:25 +00001084 bool catch_bp,
1085 bool throw_bp)
Jim Inghamfab10e82012-03-06 00:37:27 +00001086{
Greg Clayton5160ce52013-03-27 23:08:40 +00001087 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamfab10e82012-03-06 00:37:27 +00001088
1089 SBBreakpoint sb_bp;
1090 TargetSP target_sp(GetSP());
1091 if (target_sp)
1092 {
1093 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytoneb023e72013-10-11 19:48:25 +00001094 const bool hardware = false;
1095 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
Jim Inghamfab10e82012-03-06 00:37:27 +00001096 }
1097
1098 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001099 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1100 static_cast<void*>(target_sp.get()),
Jim Inghamfab10e82012-03-06 00:37:27 +00001101 LanguageRuntime::GetNameForLanguageType(language),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001102 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1103 static_cast<void*>(sb_bp.get()));
Jim Inghamfab10e82012-03-06 00:37:27 +00001104
1105 return sb_bp;
1106}
1107
Greg Clayton9fed0d82010-07-23 23:33:17 +00001108uint32_t
1109SBTarget::GetNumBreakpoints () const
1110{
Greg Claytonacdbe812012-01-30 09:04:36 +00001111 TargetSP target_sp(GetSP());
1112 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001113 {
1114 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001115 return target_sp->GetBreakpointList().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001116 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001117 return 0;
1118}
1119
1120SBBreakpoint
1121SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1122{
1123 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001124 TargetSP target_sp(GetSP());
1125 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001126 {
1127 // The breakpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001128 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001129 }
Greg Clayton9fed0d82010-07-23 23:33:17 +00001130 return sb_breakpoint;
1131}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001132
1133bool
1134SBTarget::BreakpointDelete (break_id_t bp_id)
1135{
Greg Clayton5160ce52013-03-27 23:08:40 +00001136 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001137
Caroline Ticeceb6b132010-10-26 03:11:13 +00001138 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001139 TargetSP target_sp(GetSP());
1140 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001141 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001142 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1143 result = target_sp->RemoveBreakpointByID (bp_id);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001144 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001145
1146 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001147 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1148 static_cast<void*>(target_sp.get()),
1149 static_cast<uint32_t>(bp_id), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001150
1151 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152}
1153
Johnny Chen5d043462011-09-26 22:40:50 +00001154SBBreakpoint
1155SBTarget::FindBreakpointByID (break_id_t bp_id)
1156{
Greg Clayton5160ce52013-03-27 23:08:40 +00001157 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001158
1159 SBBreakpoint sb_breakpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001160 TargetSP target_sp(GetSP());
1161 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001162 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001163 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1164 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001165 }
1166
1167 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001168 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1169 static_cast<void*>(target_sp.get()),
1170 static_cast<uint32_t>(bp_id),
1171 static_cast<void*>(sb_breakpoint.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001172
1173 return sb_breakpoint;
1174}
1175
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176bool
1177SBTarget::EnableAllBreakpoints ()
1178{
Greg Claytonacdbe812012-01-30 09:04:36 +00001179 TargetSP target_sp(GetSP());
1180 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001182 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1183 target_sp->EnableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 return true;
1185 }
1186 return false;
1187}
1188
1189bool
1190SBTarget::DisableAllBreakpoints ()
1191{
Greg Claytonacdbe812012-01-30 09:04:36 +00001192 TargetSP target_sp(GetSP());
1193 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001195 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1196 target_sp->DisableAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197 return true;
1198 }
1199 return false;
1200}
1201
1202bool
1203SBTarget::DeleteAllBreakpoints ()
1204{
Greg Claytonacdbe812012-01-30 09:04:36 +00001205 TargetSP target_sp(GetSP());
1206 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001208 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1209 target_sp->RemoveAllBreakpoints ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 return true;
1211 }
1212 return false;
1213}
1214
Johnny Chen5d043462011-09-26 22:40:50 +00001215uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +00001216SBTarget::GetNumWatchpoints () const
Johnny Chen5d043462011-09-26 22:40:50 +00001217{
Greg Claytonacdbe812012-01-30 09:04:36 +00001218 TargetSP target_sp(GetSP());
1219 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001220 {
Johnny Chen01a67862011-10-14 00:42:25 +00001221 // The watchpoint list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001222 return target_sp->GetWatchpointList().GetSize();
Johnny Chen5d043462011-09-26 22:40:50 +00001223 }
1224 return 0;
1225}
1226
Greg Clayton1b282f92011-10-13 18:08:26 +00001227SBWatchpoint
1228SBTarget::GetWatchpointAtIndex (uint32_t idx) const
Johnny Chen9d954d82011-09-27 20:29:45 +00001229{
Johnny Chen01a67862011-10-14 00:42:25 +00001230 SBWatchpoint sb_watchpoint;
Greg Claytonacdbe812012-01-30 09:04:36 +00001231 TargetSP target_sp(GetSP());
1232 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001233 {
Johnny Chen01a67862011-10-14 00:42:25 +00001234 // The watchpoint list is thread safe, no need to lock
Greg Clayton81e871e2012-02-04 02:27:34 +00001235 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
Johnny Chen5d043462011-09-26 22:40:50 +00001236 }
Johnny Chen01a67862011-10-14 00:42:25 +00001237 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001238}
1239
1240bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001241SBTarget::DeleteWatchpoint (watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001242{
Greg Clayton5160ce52013-03-27 23:08:40 +00001243 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001244
1245 bool result = false;
Greg Claytonacdbe812012-01-30 09:04:36 +00001246 TargetSP target_sp(GetSP());
1247 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001248 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001249 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001250 Mutex::Locker locker;
1251 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001252 result = target_sp->RemoveWatchpointByID (wp_id);
Johnny Chen5d043462011-09-26 22:40:50 +00001253 }
1254
1255 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001256 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1257 static_cast<void*>(target_sp.get()),
1258 static_cast<uint32_t>(wp_id), result);
Johnny Chen5d043462011-09-26 22:40:50 +00001259
1260 return result;
1261}
1262
Greg Clayton1b282f92011-10-13 18:08:26 +00001263SBWatchpoint
1264SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
Johnny Chen5d043462011-09-26 22:40:50 +00001265{
Greg Clayton5160ce52013-03-27 23:08:40 +00001266 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +00001267
Greg Clayton1b282f92011-10-13 18:08:26 +00001268 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001269 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001270 TargetSP target_sp(GetSP());
1271 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
Johnny Chen5d043462011-09-26 22:40:50 +00001272 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001273 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001274 Mutex::Locker locker;
1275 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Clayton81e871e2012-02-04 02:27:34 +00001276 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1277 sb_watchpoint.SetSP (watchpoint_sp);
Johnny Chen5d043462011-09-26 22:40:50 +00001278 }
1279
1280 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001281 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1282 static_cast<void*>(target_sp.get()),
1283 static_cast<uint32_t>(wp_id),
1284 static_cast<void*>(watchpoint_sp.get()));
Johnny Chen5d043462011-09-26 22:40:50 +00001285
Greg Clayton1b282f92011-10-13 18:08:26 +00001286 return sb_watchpoint;
1287}
1288
1289lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001290SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001291{
Greg Clayton5160ce52013-03-27 23:08:40 +00001292 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001293
Greg Clayton1b282f92011-10-13 18:08:26 +00001294 SBWatchpoint sb_watchpoint;
Greg Clayton81e871e2012-02-04 02:27:34 +00001295 lldb::WatchpointSP watchpoint_sp;
Greg Claytonacdbe812012-01-30 09:04:36 +00001296 TargetSP target_sp(GetSP());
Greg Clayton81e871e2012-02-04 02:27:34 +00001297 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
Greg Clayton1b282f92011-10-13 18:08:26 +00001298 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001299 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton81e871e2012-02-04 02:27:34 +00001300 uint32_t watch_type = 0;
1301 if (read)
1302 watch_type |= LLDB_WATCH_TYPE_READ;
1303 if (write)
1304 watch_type |= LLDB_WATCH_TYPE_WRITE;
Jim Inghamc6462312013-06-18 21:52:48 +00001305 if (watch_type == 0)
1306 {
1307 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1308 return sb_watchpoint;
1309 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001310
Johnny Chen7385a5a2012-05-31 22:56:36 +00001311 // Target::CreateWatchpoint() is thread safe.
Johnny Chenb90827e2012-06-04 23:19:54 +00001312 Error cw_error;
Jim Inghama7dfb662012-10-23 07:20:06 +00001313 // This API doesn't take in a type, so we can't figure out what it is.
1314 ClangASTType *type = NULL;
1315 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
Johnny Chenb90827e2012-06-04 23:19:54 +00001316 error.SetError(cw_error);
Greg Clayton81e871e2012-02-04 02:27:34 +00001317 sb_watchpoint.SetSP (watchpoint_sp);
Greg Clayton1b282f92011-10-13 18:08:26 +00001318 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001319
Greg Clayton1b282f92011-10-13 18:08:26 +00001320 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001321 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001322 static_cast<void*>(target_sp.get()), addr,
1323 static_cast<uint32_t>(size),
1324 static_cast<void*>(watchpoint_sp.get()));
1325
Greg Clayton1b282f92011-10-13 18:08:26 +00001326 return sb_watchpoint;
Johnny Chen5d043462011-09-26 22:40:50 +00001327}
1328
1329bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001330SBTarget::EnableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001331{
Greg Claytonacdbe812012-01-30 09:04:36 +00001332 TargetSP target_sp(GetSP());
1333 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001334 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001335 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001336 Mutex::Locker locker;
1337 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001338 target_sp->EnableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001339 return true;
1340 }
1341 return false;
1342}
1343
1344bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001345SBTarget::DisableAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001346{
Greg Claytonacdbe812012-01-30 09:04:36 +00001347 TargetSP target_sp(GetSP());
1348 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001349 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001350 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001351 Mutex::Locker locker;
1352 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001353 target_sp->DisableAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001354 return true;
1355 }
1356 return false;
1357}
1358
Enrico Granata347c2aa2013-10-08 21:49:02 +00001359SBValue
1360SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1361{
1362 SBValue sb_value;
1363 lldb::ValueObjectSP new_value_sp;
1364 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1365 {
Enrico Granata972be532014-12-17 21:18:43 +00001366 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1367 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1368 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1369 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
Enrico Granata347c2aa2013-10-08 21:49:02 +00001370 }
1371 sb_value.SetSP(new_value_sp);
1372 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1373 if (log)
1374 {
1375 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001376 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1377 static_cast<void*>(m_opaque_sp.get()),
1378 new_value_sp->GetName().AsCString());
Enrico Granata347c2aa2013-10-08 21:49:02 +00001379 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001380 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL",
1381 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata347c2aa2013-10-08 21:49:02 +00001382 }
1383 return sb_value;
1384}
1385
Enrico Granata972be532014-12-17 21:18:43 +00001386lldb::SBValue
1387SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
1388{
1389 SBValue sb_value;
1390 lldb::ValueObjectSP new_value_sp;
1391 if (IsValid() && name && *name && data.IsValid() && type.IsValid())
1392 {
1393 DataExtractorSP extractor(*data);
1394 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1395 ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
1396 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
1397 }
1398 sb_value.SetSP(new_value_sp);
1399 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1400 if (log)
1401 {
1402 if (new_value_sp)
1403 log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
1404 static_cast<void*>(m_opaque_sp.get()),
1405 new_value_sp->GetName().AsCString());
1406 else
1407 log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
1408 static_cast<void*>(m_opaque_sp.get()));
1409 }
1410 return sb_value;
1411}
1412
1413lldb::SBValue
1414SBTarget::CreateValueFromExpression (const char *name, const char* expr)
1415{
1416 SBValue sb_value;
1417 lldb::ValueObjectSP new_value_sp;
1418 if (IsValid() && name && *name && expr && *expr)
1419 {
1420 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1421 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1422 }
1423 sb_value.SetSP(new_value_sp);
1424 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1425 if (log)
1426 {
1427 if (new_value_sp)
1428 log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1429 static_cast<void*>(m_opaque_sp.get()),
1430 new_value_sp->GetName().AsCString());
1431 else
1432 log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
1433 static_cast<void*>(m_opaque_sp.get()));
1434 }
1435 return sb_value;
1436}
1437
Johnny Chen5d043462011-09-26 22:40:50 +00001438bool
Greg Clayton1b282f92011-10-13 18:08:26 +00001439SBTarget::DeleteAllWatchpoints ()
Johnny Chen5d043462011-09-26 22:40:50 +00001440{
Greg Claytonacdbe812012-01-30 09:04:36 +00001441 TargetSP target_sp(GetSP());
1442 if (target_sp)
Johnny Chen5d043462011-09-26 22:40:50 +00001443 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001444 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Johnny Chen7385a5a2012-05-31 22:56:36 +00001445 Mutex::Locker locker;
1446 target_sp->GetWatchpointList().GetListMutex(locker);
Greg Claytonacdbe812012-01-30 09:04:36 +00001447 target_sp->RemoveAllWatchpoints ();
Johnny Chen5d043462011-09-26 22:40:50 +00001448 return true;
1449 }
1450 return false;
1451}
1452
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001454lldb::SBModule
1455SBTarget::AddModule (const char *path,
1456 const char *triple,
1457 const char *uuid_cstr)
1458{
Greg Claytonb210aec2012-04-23 20:23:39 +00001459 return AddModule (path, triple, uuid_cstr, NULL);
1460}
1461
1462lldb::SBModule
1463SBTarget::AddModule (const char *path,
1464 const char *triple,
1465 const char *uuid_cstr,
1466 const char *symfile)
1467{
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001468 lldb::SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001469 TargetSP target_sp(GetSP());
1470 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001471 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001472 ModuleSpec module_spec;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001473 if (path)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001474 module_spec.GetFileSpec().SetFile(path, false);
Greg Claytonb210aec2012-04-23 20:23:39 +00001475
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001476 if (uuid_cstr)
Greg Claytonb5f0fea2012-09-27 22:26:11 +00001477 module_spec.GetUUID().SetFromCString(uuid_cstr);
Greg Claytonb210aec2012-04-23 20:23:39 +00001478
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001479 if (triple)
Greg Claytonb9a01b32012-02-26 05:51:37 +00001480 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
Jason Molendab019cd92013-09-11 21:25:46 +00001481 else
1482 module_spec.GetArchitecture() = target_sp->GetArchitecture();
Greg Claytonb210aec2012-04-23 20:23:39 +00001483
1484 if (symfile)
1485 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001486
Greg Claytonb9a01b32012-02-26 05:51:37 +00001487 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001488 }
1489 return sb_module;
1490}
1491
Greg Clayton226cce22013-07-08 22:22:41 +00001492lldb::SBModule
1493SBTarget::AddModule (const SBModuleSpec &module_spec)
1494{
1495 lldb::SBModule sb_module;
1496 TargetSP target_sp(GetSP());
1497 if (target_sp)
1498 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1499 return sb_module;
1500}
1501
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001502bool
1503SBTarget::AddModule (lldb::SBModule &module)
1504{
Greg Claytonacdbe812012-01-30 09:04:36 +00001505 TargetSP target_sp(GetSP());
1506 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001507 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001508 target_sp->GetImages().AppendIfNeeded (module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001509 return true;
1510 }
1511 return false;
1512}
1513
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001514uint32_t
1515SBTarget::GetNumModules () const
1516{
Greg Clayton5160ce52013-03-27 23:08:40 +00001517 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001518
Caroline Ticeceb6b132010-10-26 03:11:13 +00001519 uint32_t num = 0;
Greg Claytonacdbe812012-01-30 09:04:36 +00001520 TargetSP target_sp(GetSP());
1521 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001522 {
1523 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001524 num = target_sp->GetImages().GetSize();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001525 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001526
1527 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001528 log->Printf ("SBTarget(%p)::GetNumModules () => %d",
1529 static_cast<void*>(target_sp.get()), num);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001530
1531 return num;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001532}
1533
Greg Clayton48e42542010-07-30 20:12:55 +00001534void
1535SBTarget::Clear ()
1536{
Greg Clayton5160ce52013-03-27 23:08:40 +00001537 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001538
1539 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001540 log->Printf ("SBTarget(%p)::Clear ()",
1541 static_cast<void*>(m_opaque_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001542
Greg Clayton48e42542010-07-30 20:12:55 +00001543 m_opaque_sp.reset();
1544}
1545
1546
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001547SBModule
1548SBTarget::FindModule (const SBFileSpec &sb_file_spec)
1549{
1550 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001551 TargetSP target_sp(GetSP());
1552 if (target_sp && sb_file_spec.IsValid())
Greg Claytonaf67cec2010-12-20 20:49:23 +00001553 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001554 ModuleSpec module_spec(*sb_file_spec);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001555 // The module list is thread safe, no need to lock
Greg Claytonb9a01b32012-02-26 05:51:37 +00001556 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
Greg Claytonaf67cec2010-12-20 20:49:23 +00001557 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001558 return sb_module;
1559}
1560
Greg Clayton13d19502012-01-29 06:07:39 +00001561lldb::ByteOrder
1562SBTarget::GetByteOrder ()
1563{
Greg Claytonacdbe812012-01-30 09:04:36 +00001564 TargetSP target_sp(GetSP());
1565 if (target_sp)
1566 return target_sp->GetArchitecture().GetByteOrder();
Greg Clayton13d19502012-01-29 06:07:39 +00001567 return eByteOrderInvalid;
1568}
1569
1570const char *
1571SBTarget::GetTriple ()
1572{
Greg Claytonacdbe812012-01-30 09:04:36 +00001573 TargetSP target_sp(GetSP());
1574 if (target_sp)
Greg Clayton13d19502012-01-29 06:07:39 +00001575 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001576 std::string triple (target_sp->GetArchitecture().GetTriple().str());
Greg Clayton13d19502012-01-29 06:07:39 +00001577 // Unique the string so we don't run into ownership issues since
1578 // the const strings put the string into the string pool once and
1579 // the strings never comes out
1580 ConstString const_triple (triple.c_str());
1581 return const_triple.GetCString();
1582 }
1583 return NULL;
1584}
1585
1586uint32_t
Matthew Gardinerc928de32014-10-22 07:22:56 +00001587SBTarget::GetDataByteSize ()
1588{
1589 TargetSP target_sp(GetSP());
1590 if (target_sp)
1591 {
1592 return target_sp->GetArchitecture().GetDataByteSize() ;
1593 }
1594 return 0;
1595}
1596
1597uint32_t
1598SBTarget::GetCodeByteSize ()
1599{
1600 TargetSP target_sp(GetSP());
1601 if (target_sp)
1602 {
1603 return target_sp->GetArchitecture().GetCodeByteSize() ;
1604 }
1605 return 0;
1606}
1607
1608uint32_t
Greg Clayton13d19502012-01-29 06:07:39 +00001609SBTarget::GetAddressByteSize()
1610{
Greg Claytonacdbe812012-01-30 09:04:36 +00001611 TargetSP target_sp(GetSP());
1612 if (target_sp)
1613 return target_sp->GetArchitecture().GetAddressByteSize();
Greg Clayton13d19502012-01-29 06:07:39 +00001614 return sizeof(void*);
1615}
1616
1617
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001618SBModule
1619SBTarget::GetModuleAtIndex (uint32_t idx)
1620{
Greg Clayton5160ce52013-03-27 23:08:40 +00001621 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001622
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623 SBModule sb_module;
Greg Claytonacdbe812012-01-30 09:04:36 +00001624 ModuleSP module_sp;
1625 TargetSP target_sp(GetSP());
1626 if (target_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001627 {
1628 // The module list is thread safe, no need to lock
Greg Claytonacdbe812012-01-30 09:04:36 +00001629 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1630 sb_module.SetSP (module_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001631 }
Caroline Ticeceb6b132010-10-26 03:11:13 +00001632
1633 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001634 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1635 static_cast<void*>(target_sp.get()), idx,
1636 static_cast<void*>(module_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001637
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638 return sb_module;
1639}
1640
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001641bool
1642SBTarget::RemoveModule (lldb::SBModule module)
1643{
Greg Claytonacdbe812012-01-30 09:04:36 +00001644 TargetSP target_sp(GetSP());
1645 if (target_sp)
1646 return target_sp->GetImages().Remove(module.GetSP());
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001647 return false;
1648}
1649
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650
1651SBBroadcaster
1652SBTarget::GetBroadcaster () const
1653{
Greg Clayton5160ce52013-03-27 23:08:40 +00001654 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001655
Greg Claytonacdbe812012-01-30 09:04:36 +00001656 TargetSP target_sp(GetSP());
1657 SBBroadcaster broadcaster(target_sp.get(), false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001658
Caroline Ticeceb6b132010-10-26 03:11:13 +00001659 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001660 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1661 static_cast<void*>(target_sp.get()),
1662 static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001663
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664 return broadcaster;
1665}
1666
Caroline Ticedde9cff2010-09-20 05:20:02 +00001667bool
Caroline Ticeceb6b132010-10-26 03:11:13 +00001668SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001669{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001670 Stream &strm = description.ref();
1671
Greg Claytonacdbe812012-01-30 09:04:36 +00001672 TargetSP target_sp(GetSP());
1673 if (target_sp)
Caroline Tice201a8852010-09-20 16:21:41 +00001674 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001675 target_sp->Dump (&strm, description_level);
Caroline Ticeceb6b132010-10-26 03:11:13 +00001676 }
1677 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001678 strm.PutCString ("No value");
Caroline Ticeceb6b132010-10-26 03:11:13 +00001679
1680 return true;
1681}
1682
Greg Clayton5569e642012-02-06 01:44:54 +00001683lldb::SBSymbolContextList
1684SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
Greg Claytonfe356d32011-06-21 01:34:41 +00001685{
Greg Clayton5569e642012-02-06 01:44:54 +00001686 lldb::SBSymbolContextList sb_sc_list;
Greg Claytonacdbe812012-01-30 09:04:36 +00001687 if (name && name[0])
Greg Claytonfe356d32011-06-21 01:34:41 +00001688 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001689 TargetSP target_sp(GetSP());
1690 if (target_sp)
1691 {
1692 const bool symbols_ok = true;
Sean Callanan9df05fb2012-02-10 22:52:19 +00001693 const bool inlines_ok = true;
Greg Clayton5569e642012-02-06 01:44:54 +00001694 const bool append = true;
1695 target_sp->GetImages().FindFunctions (ConstString(name),
1696 name_type_mask,
Sean Callanan9df05fb2012-02-10 22:52:19 +00001697 symbols_ok,
1698 inlines_ok,
Greg Clayton5569e642012-02-06 01:44:54 +00001699 append,
1700 *sb_sc_list);
Greg Claytonacdbe812012-01-30 09:04:36 +00001701 }
Greg Claytonfe356d32011-06-21 01:34:41 +00001702 }
Greg Clayton5569e642012-02-06 01:44:54 +00001703 return sb_sc_list;
Greg Claytonfe356d32011-06-21 01:34:41 +00001704}
1705
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001706lldb::SBSymbolContextList
1707SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
1708{
1709 lldb::SBSymbolContextList sb_sc_list;
1710 if (name && name[0])
1711 {
1712 TargetSP target_sp(GetSP());
1713 if (target_sp)
1714 {
1715 std::string regexstr;
1716 switch (matchtype)
1717 {
1718 case eMatchTypeRegex:
1719 target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list);
1720 break;
1721 case eMatchTypeStartsWith:
1722 regexstr = llvm::Regex::escape(name) + ".*";
1723 target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
1724 break;
1725 default:
1726 target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list);
1727 break;
1728 }
1729 }
1730 }
1731 return sb_sc_list;
1732}
1733
Enrico Granata6f3533f2011-07-29 19:53:35 +00001734lldb::SBType
Greg Claytonb43165b2012-12-05 21:24:42 +00001735SBTarget::FindFirstType (const char* typename_cstr)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001736{
Greg Claytonacdbe812012-01-30 09:04:36 +00001737 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001738 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001739 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001740 ConstString const_typename(typename_cstr);
1741 SymbolContext sc;
1742 const bool exact_match = false;
1743
1744 const ModuleList &module_list = target_sp->GetImages();
1745 size_t count = module_list.GetSize();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001746 for (size_t idx = 0; idx < count; idx++)
1747 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001748 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
1749 if (module_sp)
1750 {
1751 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
1752 if (type_sp)
1753 return SBType(type_sp);
1754 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001755 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001756
1757 // Didn't find the type in the symbols; try the Objective-C runtime
1758 // if one is installed
1759
1760 ProcessSP process_sp(target_sp->GetProcessSP());
1761
1762 if (process_sp)
1763 {
1764 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1765
1766 if (objc_language_runtime)
1767 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001768 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001769
Sean Callanan9998acd2014-12-05 01:21:59 +00001770 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001771 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001772 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001773
Sean Callanan9998acd2014-12-05 01:21:59 +00001774 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
1775 {
1776 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0]))
1777 {
1778 return SBType(type);
1779 }
1780 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001781 }
1782 }
1783 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001784
1785 // No matches, search for basic typename matches
1786 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1787 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001788 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001789 }
1790 return SBType();
1791}
1792
Greg Claytonb43165b2012-12-05 21:24:42 +00001793SBType
1794SBTarget::GetBasicType(lldb::BasicType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001795{
Greg Claytonacdbe812012-01-30 09:04:36 +00001796 TargetSP target_sp(GetSP());
Greg Claytonb43165b2012-12-05 21:24:42 +00001797 if (target_sp)
1798 {
1799 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1800 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001801 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
Greg Claytonb43165b2012-12-05 21:24:42 +00001802 }
1803 return SBType();
1804}
1805
1806
1807lldb::SBTypeList
1808SBTarget::FindTypes (const char* typename_cstr)
1809{
1810 SBTypeList sb_type_list;
1811 TargetSP target_sp(GetSP());
1812 if (typename_cstr && typename_cstr[0] && target_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001813 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001814 ModuleList& images = target_sp->GetImages();
Greg Claytonb43165b2012-12-05 21:24:42 +00001815 ConstString const_typename(typename_cstr);
Greg Clayton84db9102012-03-26 23:03:23 +00001816 bool exact_match = false;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001817 SymbolContext sc;
1818 TypeList type_list;
1819
Greg Clayton29399a22012-04-06 17:41:13 +00001820 uint32_t num_matches = images.FindTypes (sc,
Greg Claytonb43165b2012-12-05 21:24:42 +00001821 const_typename,
Greg Clayton84db9102012-03-26 23:03:23 +00001822 exact_match,
1823 UINT32_MAX,
1824 type_list);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001825
Greg Claytonb43165b2012-12-05 21:24:42 +00001826 if (num_matches > 0)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001827 {
Greg Claytonb43165b2012-12-05 21:24:42 +00001828 for (size_t idx = 0; idx < num_matches; idx++)
1829 {
1830 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
1831 if (type_sp)
1832 sb_type_list.Append(SBType(type_sp));
1833 }
1834 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001835
1836 // Try the Objective-C runtime if one is installed
1837
1838 ProcessSP process_sp(target_sp->GetProcessSP());
1839
1840 if (process_sp)
1841 {
1842 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
1843
1844 if (objc_language_runtime)
1845 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001846 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
Sean Callanan7be70e82012-12-19 23:05:01 +00001847
Sean Callanan9998acd2014-12-05 01:21:59 +00001848 if (objc_decl_vendor)
Sean Callanan7be70e82012-12-19 23:05:01 +00001849 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001850 std::vector <clang::NamedDecl *> decls;
Sean Callanan7be70e82012-12-19 23:05:01 +00001851
Sean Callanan9998acd2014-12-05 01:21:59 +00001852 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
Sean Callanan7be70e82012-12-19 23:05:01 +00001853 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001854 for (clang::NamedDecl *decl : decls)
Sean Callanan7be70e82012-12-19 23:05:01 +00001855 {
Sean Callanan9998acd2014-12-05 01:21:59 +00001856 if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl))
1857 {
1858 sb_type_list.Append(SBType(type));
1859 }
Sean Callanan7be70e82012-12-19 23:05:01 +00001860 }
1861 }
1862 }
1863 }
1864 }
1865
1866 if (sb_type_list.GetSize() == 0)
Greg Claytonb43165b2012-12-05 21:24:42 +00001867 {
1868 // No matches, search for basic typename matches
1869 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1870 if (clang_ast)
Greg Clayton57ee3062013-07-11 22:46:58 +00001871 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001872 }
1873 }
Greg Claytonb43165b2012-12-05 21:24:42 +00001874 return sb_type_list;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001875}
1876
Greg Claytondea8cb42011-06-29 22:09:02 +00001877SBValueList
1878SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
1879{
1880 SBValueList sb_value_list;
1881
Greg Claytonacdbe812012-01-30 09:04:36 +00001882 TargetSP target_sp(GetSP());
1883 if (name && target_sp)
Greg Claytondea8cb42011-06-29 22:09:02 +00001884 {
1885 VariableList variable_list;
1886 const bool append = true;
Greg Claytonacdbe812012-01-30 09:04:36 +00001887 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
1888 append,
1889 max_matches,
1890 variable_list);
Greg Claytondea8cb42011-06-29 22:09:02 +00001891
1892 if (match_count > 0)
1893 {
Greg Claytonacdbe812012-01-30 09:04:36 +00001894 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001895 if (exe_scope == NULL)
Greg Claytonacdbe812012-01-30 09:04:36 +00001896 exe_scope = target_sp.get();
Greg Claytondea8cb42011-06-29 22:09:02 +00001897 for (uint32_t i=0; i<match_count; ++i)
1898 {
1899 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
1900 if (valobj_sp)
Enrico Granata85425d72013-02-07 18:23:56 +00001901 sb_value_list.Append(SBValue(valobj_sp));
Greg Claytondea8cb42011-06-29 22:09:02 +00001902 }
1903 }
1904 }
1905
1906 return sb_value_list;
1907}
1908
Carlo Kok0fd6fd42014-09-19 19:38:19 +00001909SBValueList
1910SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype)
1911{
1912 SBValueList sb_value_list;
1913
1914 TargetSP target_sp(GetSP());
1915 if (name && target_sp)
1916 {
1917 VariableList variable_list;
1918 const bool append = true;
1919
1920 std::string regexstr;
1921 uint32_t match_count;
1922 switch (matchtype)
1923 {
1924 case eMatchTypeNormal:
1925 match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name),
1926 append,
1927 max_matches,
1928 variable_list);
1929 break;
1930 case eMatchTypeRegex:
1931 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name),
1932 append,
1933 max_matches,
1934 variable_list);
1935 break;
1936 case eMatchTypeStartsWith:
1937 regexstr = llvm::Regex::escape(name) + ".*";
1938 match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()),
1939 append,
1940 max_matches,
1941 variable_list);
1942 break;
1943 }
1944
1945
1946 if (match_count > 0)
1947 {
1948 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1949 if (exe_scope == NULL)
1950 exe_scope = target_sp.get();
1951 for (uint32_t i = 0; i<match_count; ++i)
1952 {
1953 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i)));
1954 if (valobj_sp)
1955 sb_value_list.Append(SBValue(valobj_sp));
1956 }
1957 }
1958 }
1959
1960 return sb_value_list;
1961}
1962
1963
Enrico Granatabcd80b42013-01-16 18:53:52 +00001964lldb::SBValue
1965SBTarget::FindFirstGlobalVariable (const char* name)
1966{
1967 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1968 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1969 return sb_value_list.GetValueAtIndex(0);
1970 return SBValue();
1971}
1972
Jim Inghame37d6052011-09-13 00:29:56 +00001973SBSourceManager
1974SBTarget::GetSourceManager()
1975{
1976 SBSourceManager source_manager (*this);
1977 return source_manager;
1978}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001979
Sean Callanan50952e92011-12-14 23:49:37 +00001980lldb::SBInstructionList
Greg Clayton9c766112012-03-06 22:24:44 +00001981SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
1982{
Jim Ingham0f063ba2013-03-02 00:26:47 +00001983 return ReadInstructions (base_addr, count, NULL);
1984}
1985
1986lldb::SBInstructionList
1987SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
1988{
Greg Clayton9c766112012-03-06 22:24:44 +00001989 SBInstructionList sb_instructions;
1990
1991 TargetSP target_sp(GetSP());
1992 if (target_sp)
1993 {
1994 Address *addr_ptr = base_addr.get();
1995
1996 if (addr_ptr)
1997 {
1998 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
1999 bool prefer_file_cache = false;
2000 lldb_private::Error error;
Greg Clayton3faf47c2013-03-28 23:42:53 +00002001 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2002 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2003 prefer_file_cache,
2004 data.GetBytes(),
2005 data.GetByteSize(),
2006 error,
2007 &load_addr);
2008 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
Greg Clayton9c766112012-03-06 22:24:44 +00002009 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2010 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002011 flavor_string,
Greg Clayton9c766112012-03-06 22:24:44 +00002012 *addr_ptr,
2013 data.GetBytes(),
2014 bytes_read,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002015 count,
2016 data_from_file));
Greg Clayton9c766112012-03-06 22:24:44 +00002017 }
2018 }
2019
2020 return sb_instructions;
2021
2022}
2023
2024lldb::SBInstructionList
Sean Callanan50952e92011-12-14 23:49:37 +00002025SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2026{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002027 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2028}
2029
2030lldb::SBInstructionList
2031SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2032{
Sean Callanan50952e92011-12-14 23:49:37 +00002033 SBInstructionList sb_instructions;
2034
Greg Claytonacdbe812012-01-30 09:04:36 +00002035 TargetSP target_sp(GetSP());
2036 if (target_sp)
Sean Callanan50952e92011-12-14 23:49:37 +00002037 {
2038 Address addr;
2039
2040 if (base_addr.get())
2041 addr = *base_addr.get();
2042
Greg Clayton3faf47c2013-03-28 23:42:53 +00002043 const bool data_from_file = true;
2044
Greg Claytonacdbe812012-01-30 09:04:36 +00002045 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
Sean Callanan50952e92011-12-14 23:49:37 +00002046 NULL,
Jim Ingham0f063ba2013-03-02 00:26:47 +00002047 flavor_string,
Sean Callanan50952e92011-12-14 23:49:37 +00002048 addr,
2049 buf,
Greg Clayton3faf47c2013-03-28 23:42:53 +00002050 size,
2051 UINT32_MAX,
2052 data_from_file));
Sean Callanan50952e92011-12-14 23:49:37 +00002053 }
2054
2055 return sb_instructions;
2056}
2057
2058lldb::SBInstructionList
2059SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2060{
Jim Ingham0f063ba2013-03-02 00:26:47 +00002061 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2062}
2063
2064lldb::SBInstructionList
2065SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2066{
2067 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
Sean Callanan50952e92011-12-14 23:49:37 +00002068}
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002069
2070SBError
2071SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2072 lldb::addr_t section_base_addr)
2073{
2074 SBError sb_error;
Greg Claytonacdbe812012-01-30 09:04:36 +00002075 TargetSP target_sp(GetSP());
2076 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002077 {
2078 if (!section.IsValid())
2079 {
2080 sb_error.SetErrorStringWithFormat ("invalid section");
2081 }
2082 else
2083 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002084 SectionSP section_sp (section.GetSP());
2085 if (section_sp)
2086 {
2087 if (section_sp->IsThreadSpecific())
2088 {
2089 sb_error.SetErrorString ("thread specific sections are not yet supported");
2090 }
2091 else
2092 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002093 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002094 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
Greg Clayton3c947372013-01-29 01:17:09 +00002095 {
2096 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002097 if (process_sp)
2098 process_sp->Flush();
2099 }
Greg Clayton741f3f92012-03-27 21:10:07 +00002100 }
2101 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002102 }
2103 }
2104 else
2105 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002106 sb_error.SetErrorString ("invalid target");
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002107 }
2108 return sb_error;
2109}
2110
2111SBError
2112SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2113{
2114 SBError sb_error;
2115
Greg Claytonacdbe812012-01-30 09:04:36 +00002116 TargetSP target_sp(GetSP());
2117 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002118 {
2119 if (!section.IsValid())
2120 {
2121 sb_error.SetErrorStringWithFormat ("invalid section");
2122 }
2123 else
2124 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002125 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002126 if (target_sp->SetSectionUnloaded (section.GetSP()))
Greg Clayton3c947372013-01-29 01:17:09 +00002127 {
2128 // Flush info in the process (stack frames, etc)
Greg Clayton3c947372013-01-29 01:17:09 +00002129 if (process_sp)
2130 process_sp->Flush();
2131 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002132 }
2133 }
2134 else
2135 {
2136 sb_error.SetErrorStringWithFormat ("invalid target");
2137 }
2138 return sb_error;
2139}
2140
2141SBError
2142SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2143{
2144 SBError sb_error;
2145
Greg Claytonacdbe812012-01-30 09:04:36 +00002146 TargetSP target_sp(GetSP());
2147 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002148 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002149 ModuleSP module_sp (module.GetSP());
2150 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002151 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002152 bool changed = false;
Greg Clayton751caf62014-02-07 22:54:47 +00002153 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002154 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002155 // The load was successful, make sure that at least some sections
2156 // changed before we notify that our module was loaded.
2157 if (changed)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002158 {
Greg Clayton741f3f92012-03-27 21:10:07 +00002159 ModuleList module_list;
2160 module_list.Append(module_sp);
2161 target_sp->ModulesDidLoad (module_list);
Greg Clayton3c947372013-01-29 01:17:09 +00002162 // Flush info in the process (stack frames, etc)
2163 ProcessSP process_sp (target_sp->GetProcessSP());
2164 if (process_sp)
2165 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002166 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002167 }
2168 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002169 else
2170 {
2171 sb_error.SetErrorStringWithFormat ("invalid module");
2172 }
2173
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002174 }
2175 else
2176 {
2177 sb_error.SetErrorStringWithFormat ("invalid target");
2178 }
2179 return sb_error;
2180}
2181
2182SBError
2183SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2184{
2185 SBError sb_error;
2186
2187 char path[PATH_MAX];
Greg Claytonacdbe812012-01-30 09:04:36 +00002188 TargetSP target_sp(GetSP());
2189 if (target_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002190 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002191 ModuleSP module_sp (module.GetSP());
2192 if (module_sp)
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002193 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002194 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002195 if (objfile)
2196 {
2197 SectionList *section_list = objfile->GetSectionList();
2198 if (section_list)
2199 {
Greg Claytond5944cd2013-12-06 01:12:00 +00002200 ProcessSP process_sp (target_sp->GetProcessSP());
Greg Claytond5944cd2013-12-06 01:12:00 +00002201
Greg Clayton3c947372013-01-29 01:17:09 +00002202 bool changed = false;
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002203 const size_t num_sections = section_list->GetSize();
2204 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2205 {
2206 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2207 if (section_sp)
Zachary Turner40411162014-07-16 20:28:24 +00002208 changed |= target_sp->SetSectionUnloaded (section_sp);
Greg Clayton3c947372013-01-29 01:17:09 +00002209 }
2210 if (changed)
2211 {
2212 // Flush info in the process (stack frames, etc)
2213 ProcessSP process_sp (target_sp->GetProcessSP());
2214 if (process_sp)
2215 process_sp->Flush();
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002216 }
2217 }
2218 else
2219 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002220 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002221 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2222 }
2223 }
2224 else
2225 {
Greg Claytonacdbe812012-01-30 09:04:36 +00002226 module_sp->GetFileSpec().GetPath (path, sizeof(path));
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002227 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2228 }
2229 }
Greg Claytonacdbe812012-01-30 09:04:36 +00002230 else
2231 {
2232 sb_error.SetErrorStringWithFormat ("invalid module");
2233 }
Greg Claytoncac9c5f2011-09-24 00:52:29 +00002234 }
2235 else
2236 {
2237 sb_error.SetErrorStringWithFormat ("invalid target");
2238 }
2239 return sb_error;
2240}
2241
2242
Greg Claytone14e1922012-12-04 02:22:16 +00002243lldb::SBSymbolContextList
2244SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2245{
2246 SBSymbolContextList sb_sc_list;
2247 if (name && name[0])
2248 {
2249 TargetSP target_sp(GetSP());
2250 if (target_sp)
2251 {
2252 bool append = true;
2253 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2254 symbol_type,
2255 *sb_sc_list,
2256 append);
2257 }
2258 }
2259 return sb_sc_list;
2260
2261}
2262
2263
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002264lldb::SBValue
2265SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2266{
Greg Clayton5160ce52013-03-27 23:08:40 +00002267 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2268 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002269 SBValue expr_result;
Jim Ingham8646d3c2014-05-05 02:47:44 +00002270 ExpressionResults exe_results = eExpressionSetupError;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002271 ValueObjectSP expr_value_sp;
2272 TargetSP target_sp(GetSP());
Jason Molendab57e4a12013-11-04 09:33:30 +00002273 StackFrame *frame = NULL;
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002274 if (target_sp)
2275 {
2276 if (expr == NULL || expr[0] == '\0')
2277 {
2278 if (log)
2279 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2280 return expr_result;
2281 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002282
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002283 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2284 ExecutionContext exe_ctx (m_opaque_sp.get());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002285
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002286 if (log)
2287 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002288
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002289 frame = exe_ctx.GetFramePtr();
2290 Target *target = exe_ctx.GetTargetPtr();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002291
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002292 if (target)
2293 {
2294#ifdef LLDB_CONFIGURATION_DEBUG
2295 StreamString frame_description;
2296 if (frame)
2297 frame->DumpUsingSettingsFormat (&frame_description);
2298 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2299 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2300#endif
2301 exe_results = target->EvaluateExpression (expr,
2302 frame,
2303 expr_value_sp,
2304 options.ref());
2305
2306 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2307#ifdef LLDB_CONFIGURATION_DEBUG
2308 Host::SetCrashDescription (NULL);
2309#endif
2310 }
2311 else
2312 {
2313 if (log)
2314 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2315 }
2316 }
2317#ifndef LLDB_DISABLE_PYTHON
2318 if (expr_log)
2319 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002320 expr_result.GetValue(), expr_result.GetSummary());
2321
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002322 if (log)
2323 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002324 static_cast<void*>(frame), expr,
2325 static_cast<void*>(expr_value_sp.get()), exe_results);
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002326#endif
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00002327
Greg Clayton4b63a5c2013-01-04 18:10:18 +00002328 return expr_result;
2329}
2330
Greg Clayton13fbb992013-02-01 00:47:49 +00002331
2332lldb::addr_t
2333SBTarget::GetStackRedZoneSize()
2334{
2335 TargetSP target_sp(GetSP());
2336 if (target_sp)
2337 {
2338 ABISP abi_sp;
2339 ProcessSP process_sp (target_sp->GetProcessSP());
2340 if (process_sp)
2341 abi_sp = process_sp->GetABI();
2342 else
2343 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2344 if (abi_sp)
2345 return abi_sp->GetRedZoneSize();
2346 }
2347 return 0;
2348}
Ilia K8f37ca52015-02-13 14:31:06 +00002349
2350lldb::SBLaunchInfo
2351SBTarget::GetLaunchInfo () const
2352{
2353 lldb::SBLaunchInfo launch_info(NULL);
2354 TargetSP target_sp(GetSP());
2355 if (target_sp)
2356 launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo();
2357 return launch_info;
2358}
2359
2360void
2361SBTarget::SetLaunchInfo (const lldb::SBLaunchInfo &launch_info)
2362{
2363 TargetSP target_sp(GetSP());
2364 if (target_sp)
2365 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2366}