blob: 01fb9747db9711ebf7cc57fe86b3ff3985eb477f [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- Target.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
10#include "lldb/Target/Target.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Breakpoint/BreakpointResolver.h"
17#include "lldb/Breakpoint/BreakpointResolverAddress.h"
18#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham03c8ee52011-09-21 01:17:13 +000019#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000021#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton427f2902010-12-14 02:59:59 +000022#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Event.h"
24#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000026#include "lldb/Core/Timer.h"
27#include "lldb/Core/ValueObject.h"
Sean Callanandcf03f82011-11-15 22:27:19 +000028#include "lldb/Expression/ClangASTSource.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000029#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Host/Host.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000031#include "lldb/Interpreter/CommandInterpreter.h"
32#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033#include "lldb/lldb-private-log.h"
34#include "lldb/Symbol/ObjectFile.h"
35#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000036#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000037#include "lldb/Target/Thread.h"
38#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
Jim Ingham5a15e692012-02-16 06:50:00 +000043ConstString &
44Target::GetStaticBroadcasterClass ()
45{
46 static ConstString class_name ("lldb.target");
47 return class_name;
48}
49
Chris Lattner24943d22010-06-08 16:52:24 +000050//----------------------------------------------------------------------
51// Target constructor
52//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000053Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Jim Ingham5a15e692012-02-16 06:50:00 +000054 Broadcaster (&debugger, "lldb.target"),
Greg Clayton24bc5d92011-03-30 18:16:51 +000055 ExecutionContextScope (),
Greg Clayton334d33a2012-01-30 07:41:31 +000056 TargetInstanceSettings (GetSettingsController()),
Greg Clayton63094e02010-06-23 01:19:29 +000057 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000058 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000059 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000060 m_arch (target_arch),
61 m_images (),
Greg Claytoneea26402010-09-14 23:36:40 +000062 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000063 m_breakpoint_list (false),
64 m_internal_breakpoint_list (true),
Johnny Chenecd4feb2011-10-14 00:42:25 +000065 m_watchpoint_list (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000066 m_process_sp (),
67 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000068 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000069 m_scratch_ast_context_ap (NULL),
Sean Callanan4938bd62011-11-16 18:20:47 +000070 m_scratch_ast_source_ap (NULL),
71 m_ast_importer_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000072 m_persistent_variables (),
Jim Inghamcc637462011-09-13 00:29:56 +000073 m_source_manager(*this),
Greg Clayton24bc5d92011-03-30 18:16:51 +000074 m_stop_hooks (),
Jim Ingham3613ae12011-05-12 02:06:14 +000075 m_stop_hook_next_id (0),
76 m_suppress_stop_hooks (false)
Chris Lattner24943d22010-06-08 16:52:24 +000077{
Greg Clayton49ce6822010-10-31 03:01:06 +000078 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
79 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
80 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham5a15e692012-02-16 06:50:00 +000081
82 CheckInWithManager();
Greg Clayton49ce6822010-10-31 03:01:06 +000083
Greg Claytone005f2c2010-11-06 01:53:30 +000084 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000085 if (log)
86 log->Printf ("%p Target::Target()", this);
87}
88
89//----------------------------------------------------------------------
90// Destructor
91//----------------------------------------------------------------------
92Target::~Target()
93{
Greg Claytone005f2c2010-11-06 01:53:30 +000094 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000095 if (log)
96 log->Printf ("%p Target::~Target()", this);
97 DeleteCurrentProcess ();
98}
99
100void
Caroline Tice7826c882010-10-26 03:11:13 +0000101Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +0000102{
Greg Clayton3fed8b92010-10-08 00:21:05 +0000103// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +0000104 if (description_level != lldb::eDescriptionLevelBrief)
105 {
106 s->Indent();
107 s->PutCString("Target\n");
108 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000109 m_images.Dump(s);
110 m_breakpoint_list.Dump(s);
111 m_internal_breakpoint_list.Dump(s);
112 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +0000113 }
114 else
115 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000116 Module *exe_module = GetExecutableModulePointer();
117 if (exe_module)
118 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham53fe9cc2011-05-12 01:12:28 +0000119 else
120 s->PutCString ("No executable module.");
Caroline Tice7826c882010-10-26 03:11:13 +0000121 }
Chris Lattner24943d22010-06-08 16:52:24 +0000122}
123
124void
125Target::DeleteCurrentProcess ()
126{
127 if (m_process_sp.get())
128 {
Greg Clayton49480b12010-09-14 23:52:43 +0000129 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000130 if (m_process_sp->IsAlive())
131 m_process_sp->Destroy();
Jim Ingham88fa7bd2011-02-16 17:54:55 +0000132
133 m_process_sp->Finalize();
Chris Lattner24943d22010-06-08 16:52:24 +0000134
135 // Do any cleanup of the target we need to do between process instances.
136 // NB It is better to do this before destroying the process in case the
137 // clean up needs some help from the process.
138 m_breakpoint_list.ClearAllBreakpointSites();
139 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000140 // Disable watchpoints just on the debugger side.
Johnny Chen116a5cd2012-02-25 06:44:30 +0000141 Mutex::Locker locker;
142 this->GetWatchpointList().GetListMutex(locker);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000143 DisableAllWatchpoints(false);
Johnny Chen116a5cd2012-02-25 06:44:30 +0000144 ClearAllWatchpointHitCounts();
Chris Lattner24943d22010-06-08 16:52:24 +0000145 m_process_sp.reset();
146 }
147}
148
149const lldb::ProcessSP &
Greg Clayton46c9a352012-02-09 06:16:32 +0000150Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner24943d22010-06-08 16:52:24 +0000151{
152 DeleteCurrentProcess ();
Greg Clayton46c9a352012-02-09 06:16:32 +0000153 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner24943d22010-06-08 16:52:24 +0000154 return m_process_sp;
155}
156
157const lldb::ProcessSP &
158Target::GetProcessSP () const
159{
160 return m_process_sp;
161}
162
Greg Clayton153ccd72011-08-10 02:10:13 +0000163void
164Target::Destroy()
165{
166 Mutex::Locker locker (m_mutex);
167 DeleteCurrentProcess ();
168 m_platform_sp.reset();
169 m_arch.Clear();
170 m_images.Clear();
171 m_section_load_list.Clear();
172 const bool notify = false;
173 m_breakpoint_list.RemoveAll(notify);
174 m_internal_breakpoint_list.RemoveAll(notify);
175 m_last_created_breakpoint.reset();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000176 m_last_created_watchpoint.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000177 m_search_filter_sp.reset();
178 m_image_search_paths.Clear(notify);
179 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000180 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000181 m_ast_importer_ap.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000182 m_persistent_variables.Clear();
183 m_stop_hooks.clear();
184 m_stop_hook_next_id = 0;
185 m_suppress_stop_hooks = false;
186}
187
188
Chris Lattner24943d22010-06-08 16:52:24 +0000189BreakpointList &
190Target::GetBreakpointList(bool internal)
191{
192 if (internal)
193 return m_internal_breakpoint_list;
194 else
195 return m_breakpoint_list;
196}
197
198const BreakpointList &
199Target::GetBreakpointList(bool internal) const
200{
201 if (internal)
202 return m_internal_breakpoint_list;
203 else
204 return m_breakpoint_list;
205}
206
207BreakpointSP
208Target::GetBreakpointByID (break_id_t break_id)
209{
210 BreakpointSP bp_sp;
211
212 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
213 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
214 else
215 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
216
217 return bp_sp;
218}
219
220BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000221Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
222 const FileSpecList *source_file_spec_list,
Jim Ingham03c8ee52011-09-21 01:17:13 +0000223 RegularExpression &source_regex,
224 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000225{
Jim Inghamd6d47972011-09-23 00:54:11 +0000226 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
227 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000228 return CreateBreakpoint (filter_sp, resolver_sp, internal);
229}
230
231
232BreakpointSP
233Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
234{
235 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Chris Lattner24943d22010-06-08 16:52:24 +0000236 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
237 return CreateBreakpoint (filter_sp, resolver_sp, internal);
238}
239
240
241BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000242Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000243{
Chris Lattner24943d22010-06-08 16:52:24 +0000244 Address so_addr;
245 // Attempt to resolve our load address if possible, though it is ok if
246 // it doesn't resolve to section/offset.
247
Greg Clayton33ed1702010-08-24 00:45:41 +0000248 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000249 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000250 if (!so_addr.IsValid())
251 {
252 // The address didn't resolve, so just set this as an absolute address
253 so_addr.SetOffset (addr);
254 }
255 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000256 return bp_sp;
257}
258
259BreakpointSP
260Target::CreateBreakpoint (Address &addr, bool internal)
261{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000262 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000263 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
264 return CreateBreakpoint (filter_sp, resolver_sp, internal);
265}
266
267BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000268Target::CreateBreakpoint (const FileSpecList *containingModules,
269 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000270 const char *func_name,
271 uint32_t func_name_type_mask,
272 bool internal,
273 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000274{
Greg Clayton12bec712010-06-28 21:30:43 +0000275 BreakpointSP bp_sp;
276 if (func_name)
277 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000278 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000279
280 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
281 func_name,
282 func_name_type_mask,
283 Breakpoint::Exact,
284 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton12bec712010-06-28 21:30:43 +0000285 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
286 }
287 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000288}
289
Jim Inghamc1053622012-03-03 02:05:11 +0000290BreakpointSP
291Target::CreateBreakpoint (const FileSpecList *containingModules,
292 const FileSpecList *containingSourceFiles,
293 const char *func_names[],
294 size_t num_names,
295 uint32_t func_name_type_mask,
296 bool internal,
297 LazyBool skip_prologue)
298{
299 BreakpointSP bp_sp;
300 if (num_names > 0)
301 {
302 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
303
304 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
305 func_names,
306 num_names,
307 func_name_type_mask,
308 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
309 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
310 }
311 return bp_sp;
312}
Chris Lattner24943d22010-06-08 16:52:24 +0000313
314SearchFilterSP
315Target::GetSearchFilterForModule (const FileSpec *containingModule)
316{
317 SearchFilterSP filter_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000318 if (containingModule != NULL)
319 {
320 // TODO: We should look into sharing module based search filters
321 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000322 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner24943d22010-06-08 16:52:24 +0000323 }
324 else
325 {
326 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000327 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000328 filter_sp = m_search_filter_sp;
329 }
330 return filter_sp;
331}
332
Jim Ingham03c8ee52011-09-21 01:17:13 +0000333SearchFilterSP
334Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
335{
336 SearchFilterSP filter_sp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000337 if (containingModules && containingModules->GetSize() != 0)
338 {
339 // TODO: We should look into sharing module based search filters
340 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000341 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000342 }
343 else
344 {
345 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000346 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000347 filter_sp = m_search_filter_sp;
348 }
349 return filter_sp;
350}
351
Jim Inghamd6d47972011-09-23 00:54:11 +0000352SearchFilterSP
353Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles)
354{
355 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
356 return GetSearchFilterForModuleList(containingModules);
357
358 SearchFilterSP filter_sp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000359 if (containingModules == NULL)
360 {
361 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
362 // but that will take a little reworking.
363
Greg Clayton13d24fb2012-01-29 20:56:30 +0000364 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000365 }
366 else
367 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000368 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000369 }
370 return filter_sp;
371}
372
Chris Lattner24943d22010-06-08 16:52:24 +0000373BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000374Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
375 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000376 RegularExpression &func_regex,
377 bool internal,
378 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000379{
Jim Inghamd6d47972011-09-23 00:54:11 +0000380 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000381 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
382 func_regex,
383 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000384
385 return CreateBreakpoint (filter_sp, resolver_sp, internal);
386}
387
388BreakpointSP
389Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
390{
391 BreakpointSP bp_sp;
392 if (filter_sp && resolver_sp)
393 {
394 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
395 resolver_sp->SetBreakpoint (bp_sp.get());
396
397 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000398 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000399 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000400 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000401
Greg Claytone005f2c2010-11-06 01:53:30 +0000402 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000403 if (log)
404 {
405 StreamString s;
406 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
407 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
408 }
409
Chris Lattner24943d22010-06-08 16:52:24 +0000410 bp_sp->ResolveBreakpoint();
411 }
Jim Inghamd1686902010-10-14 23:45:03 +0000412
413 if (!internal && bp_sp)
414 {
415 m_last_created_breakpoint = bp_sp;
416 }
417
Chris Lattner24943d22010-06-08 16:52:24 +0000418 return bp_sp;
419}
420
Johnny Chenda5a8022011-09-20 23:28:55 +0000421bool
422Target::ProcessIsValid()
423{
424 return (m_process_sp && m_process_sp->IsAlive());
425}
426
Johnny Chenecd4feb2011-10-14 00:42:25 +0000427// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000428// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000429WatchpointSP
430Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
Johnny Chen34bbf852011-09-12 23:38:44 +0000431{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000432 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
433 if (log)
434 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
435 __FUNCTION__, addr, size, type);
436
Johnny Chenecd4feb2011-10-14 00:42:25 +0000437 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000438 if (!ProcessIsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000439 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000440 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenecd4feb2011-10-14 00:42:25 +0000441 return wp_sp;
Johnny Chen9bf11992011-09-13 01:15:36 +0000442
Johnny Chenecd4feb2011-10-14 00:42:25 +0000443 // Currently we only support one watchpoint per address, with total number
444 // of watchpoints limited by the hardware which the inferior is running on.
445 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000446 if (matched_sp)
447 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000448 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000449 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000450 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
451 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000452 // Return the existing watchpoint if both size and type match.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000453 if (size == old_size && type == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000454 wp_sp = matched_sp;
455 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000456 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000457 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000458 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000459 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000460 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000461 }
462
Johnny Chenecd4feb2011-10-14 00:42:25 +0000463 if (!wp_sp) {
464 Watchpoint *new_wp = new Watchpoint(addr, size);
465 if (!new_wp) {
466 printf("Watchpoint ctor failed, out of memory?\n");
467 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000468 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000469 new_wp->SetWatchpointType(type);
470 new_wp->SetTarget(this);
471 wp_sp.reset(new_wp);
472 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000473 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000474
Johnny Chenecd4feb2011-10-14 00:42:25 +0000475 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000476 if (log)
477 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
478 __FUNCTION__,
479 rc.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000480 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000481
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000482 if (rc.Fail())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000483 wp_sp.reset();
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000484 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000485 m_last_created_watchpoint = wp_sp;
486 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000487}
488
Chris Lattner24943d22010-06-08 16:52:24 +0000489void
490Target::RemoveAllBreakpoints (bool internal_also)
491{
Greg Claytone005f2c2010-11-06 01:53:30 +0000492 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000493 if (log)
494 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
495
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000496 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000497 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000498 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000499
500 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000501}
502
503void
504Target::DisableAllBreakpoints (bool internal_also)
505{
Greg Claytone005f2c2010-11-06 01:53:30 +0000506 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000507 if (log)
508 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
509
510 m_breakpoint_list.SetEnabledAll (false);
511 if (internal_also)
512 m_internal_breakpoint_list.SetEnabledAll (false);
513}
514
515void
516Target::EnableAllBreakpoints (bool internal_also)
517{
Greg Claytone005f2c2010-11-06 01:53:30 +0000518 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000519 if (log)
520 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
521
522 m_breakpoint_list.SetEnabledAll (true);
523 if (internal_also)
524 m_internal_breakpoint_list.SetEnabledAll (true);
525}
526
527bool
528Target::RemoveBreakpointByID (break_id_t break_id)
529{
Greg Claytone005f2c2010-11-06 01:53:30 +0000530 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000531 if (log)
532 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
533
534 if (DisableBreakpointByID (break_id))
535 {
536 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000537 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000538 else
Jim Inghamd1686902010-10-14 23:45:03 +0000539 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000540 if (m_last_created_breakpoint)
541 {
542 if (m_last_created_breakpoint->GetID() == break_id)
543 m_last_created_breakpoint.reset();
544 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000545 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000546 }
Chris Lattner24943d22010-06-08 16:52:24 +0000547 return true;
548 }
549 return false;
550}
551
552bool
553Target::DisableBreakpointByID (break_id_t break_id)
554{
Greg Claytone005f2c2010-11-06 01:53:30 +0000555 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000556 if (log)
557 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
558
559 BreakpointSP bp_sp;
560
561 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
562 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
563 else
564 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
565 if (bp_sp)
566 {
567 bp_sp->SetEnabled (false);
568 return true;
569 }
570 return false;
571}
572
573bool
574Target::EnableBreakpointByID (break_id_t break_id)
575{
Greg Claytone005f2c2010-11-06 01:53:30 +0000576 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000577 if (log)
578 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
579 __FUNCTION__,
580 break_id,
581 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
582
583 BreakpointSP bp_sp;
584
585 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
586 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
587 else
588 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
589
590 if (bp_sp)
591 {
592 bp_sp->SetEnabled (true);
593 return true;
594 }
595 return false;
596}
597
Johnny Chenc86582f2011-09-23 21:21:43 +0000598// The flag 'end_to_end', default to true, signifies that the operation is
599// performed end to end, for both the debugger and the debuggee.
600
Johnny Chenecd4feb2011-10-14 00:42:25 +0000601// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
602// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000603bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000604Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000605{
606 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
607 if (log)
608 log->Printf ("Target::%s\n", __FUNCTION__);
609
Johnny Chenc86582f2011-09-23 21:21:43 +0000610 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000611 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000612 return true;
613 }
614
615 // Otherwise, it's an end to end operation.
616
Johnny Chenda5a8022011-09-20 23:28:55 +0000617 if (!ProcessIsValid())
618 return false;
619
Johnny Chenecd4feb2011-10-14 00:42:25 +0000620 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000621 for (size_t i = 0; i < num_watchpoints; ++i)
622 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000623 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
624 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000625 return false;
626
Johnny Chenecd4feb2011-10-14 00:42:25 +0000627 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000628 if (rc.Fail())
629 return false;
630 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000631 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000632 return true; // Success!
633}
634
Johnny Chenecd4feb2011-10-14 00:42:25 +0000635// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
636// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000637bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000638Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000639{
640 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
641 if (log)
642 log->Printf ("Target::%s\n", __FUNCTION__);
643
Johnny Chenc86582f2011-09-23 21:21:43 +0000644 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000645 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000646 return true;
647 }
648
649 // Otherwise, it's an end to end operation.
650
Johnny Chenda5a8022011-09-20 23:28:55 +0000651 if (!ProcessIsValid())
652 return false;
653
Johnny Chenecd4feb2011-10-14 00:42:25 +0000654 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000655 for (size_t i = 0; i < num_watchpoints; ++i)
656 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000657 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
658 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000659 return false;
660
Johnny Chenecd4feb2011-10-14 00:42:25 +0000661 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000662 if (rc.Fail())
663 return false;
664 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000665 return true; // Success!
666}
667
Johnny Chenecd4feb2011-10-14 00:42:25 +0000668// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
669// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000670bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000671Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000672{
673 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
674 if (log)
675 log->Printf ("Target::%s\n", __FUNCTION__);
676
Johnny Chenc86582f2011-09-23 21:21:43 +0000677 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000678 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000679 return true;
680 }
681
682 // Otherwise, it's an end to end operation.
683
Johnny Chenda5a8022011-09-20 23:28:55 +0000684 if (!ProcessIsValid())
685 return false;
686
Johnny Chenecd4feb2011-10-14 00:42:25 +0000687 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000688 for (size_t i = 0; i < num_watchpoints; ++i)
689 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000690 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
691 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000692 return false;
693
Johnny Chenecd4feb2011-10-14 00:42:25 +0000694 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000695 if (rc.Fail())
696 return false;
697 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000698 return true; // Success!
699}
700
Johnny Chen116a5cd2012-02-25 06:44:30 +0000701// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
702bool
703Target::ClearAllWatchpointHitCounts ()
704{
705 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
706 if (log)
707 log->Printf ("Target::%s\n", __FUNCTION__);
708
709 size_t num_watchpoints = m_watchpoint_list.GetSize();
710 for (size_t i = 0; i < num_watchpoints; ++i)
711 {
712 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
713 if (!wp_sp)
714 return false;
715
716 wp_sp->ResetHitCount();
717 }
718 return true; // Success!
719}
720
Johnny Chenecd4feb2011-10-14 00:42:25 +0000721// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000722// during these operations.
723bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000724Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000725{
726 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
727 if (log)
728 log->Printf ("Target::%s\n", __FUNCTION__);
729
730 if (!ProcessIsValid())
731 return false;
732
Johnny Chenecd4feb2011-10-14 00:42:25 +0000733 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000734 for (size_t i = 0; i < num_watchpoints; ++i)
735 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000736 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
737 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000738 return false;
739
Johnny Chenecd4feb2011-10-14 00:42:25 +0000740 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000741 }
742 return true; // Success!
743}
744
Johnny Chenecd4feb2011-10-14 00:42:25 +0000745// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000746bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000747Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000748{
749 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
750 if (log)
751 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
752
753 if (!ProcessIsValid())
754 return false;
755
Johnny Chenecd4feb2011-10-14 00:42:25 +0000756 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
757 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000758 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000759 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000760 if (rc.Success())
761 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000762
Johnny Chen01acfa72011-09-22 18:04:58 +0000763 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000764 }
765 return false;
766}
767
Johnny Chenecd4feb2011-10-14 00:42:25 +0000768// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000769bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000770Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000771{
772 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
773 if (log)
774 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
775
776 if (!ProcessIsValid())
777 return false;
778
Johnny Chenecd4feb2011-10-14 00:42:25 +0000779 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
780 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000781 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000782 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000783 if (rc.Success())
784 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000785
Johnny Chen01acfa72011-09-22 18:04:58 +0000786 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000787 }
788 return false;
789}
790
Johnny Chenecd4feb2011-10-14 00:42:25 +0000791// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000792bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000793Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000794{
795 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
796 if (log)
797 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
798
Johnny Chenecd4feb2011-10-14 00:42:25 +0000799 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000800 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000801 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000802 return true;
803 }
804 return false;
805}
806
Johnny Chenecd4feb2011-10-14 00:42:25 +0000807// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000808bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000809Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000810{
811 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
812 if (log)
813 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
814
815 if (!ProcessIsValid())
816 return false;
817
Johnny Chenecd4feb2011-10-14 00:42:25 +0000818 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
819 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000820 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000821 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000822 return true;
823 }
824 return false;
825}
826
Chris Lattner24943d22010-06-08 16:52:24 +0000827ModuleSP
828Target::GetExecutableModule ()
829{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000830 return m_images.GetModuleAtIndex(0);
831}
832
833Module*
834Target::GetExecutableModulePointer ()
835{
836 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000837}
838
839void
840Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
841{
842 m_images.Clear();
843 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000844 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000845 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000846
847 if (executable_sp.get())
848 {
849 Timer scoped_timer (__PRETTY_FUNCTION__,
850 "Target::SetExecutableModule (executable = '%s/%s')",
851 executable_sp->GetFileSpec().GetDirectory().AsCString(),
852 executable_sp->GetFileSpec().GetFilename().AsCString());
853
854 m_images.Append(executable_sp); // The first image is our exectuable file
855
Jim Ingham7508e732010-08-09 23:31:02 +0000856 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000857 if (!m_arch.IsValid())
858 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000859
Chris Lattner24943d22010-06-08 16:52:24 +0000860 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000861 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000862
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000863 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +0000864 {
865 executable_objfile->GetDependentModules(dependent_files);
866 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
867 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000868 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
869 FileSpec platform_dependent_file_spec;
870 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000871 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000872 else
873 platform_dependent_file_spec = dependent_file_spec;
874
Greg Clayton444fe992012-02-26 05:51:37 +0000875 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
876 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +0000877 if (image_module_sp.get())
878 {
Chris Lattner24943d22010-06-08 16:52:24 +0000879 ObjectFile *objfile = image_module_sp->GetObjectFile();
880 if (objfile)
881 objfile->GetDependentModules(dependent_files);
882 }
883 }
884 }
Chris Lattner24943d22010-06-08 16:52:24 +0000885 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000886
887 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000888}
889
890
Jim Ingham7508e732010-08-09 23:31:02 +0000891bool
892Target::SetArchitecture (const ArchSpec &arch_spec)
893{
Greg Clayton24bc5d92011-03-30 18:16:51 +0000894 if (m_arch == arch_spec)
Jim Ingham7508e732010-08-09 23:31:02 +0000895 {
896 // If we're setting the architecture to our current architecture, we
897 // don't need to do anything.
898 return true;
899 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000900 else if (!m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000901 {
902 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000903 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000904 return true;
905 }
906 else
907 {
908 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000909 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000910 ModuleSP executable_sp = GetExecutableModule ();
911 m_images.Clear();
912 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000913 m_scratch_ast_source_ap.reset();
914 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000915 // Need to do something about unsetting breakpoints.
916
917 if (executable_sp)
918 {
Greg Clayton444fe992012-02-26 05:51:37 +0000919 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
920 Error error = ModuleList::GetSharedModule (module_spec,
921 executable_sp,
922 &GetExecutableSearchPaths(),
923 NULL,
924 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +0000925
926 if (!error.Fail() && executable_sp)
927 {
928 SetExecutableModule (executable_sp, true);
929 return true;
930 }
931 else
932 {
933 return false;
934 }
935 }
936 else
937 {
938 return false;
939 }
940 }
941}
Chris Lattner24943d22010-06-08 16:52:24 +0000942
Chris Lattner24943d22010-06-08 16:52:24 +0000943void
944Target::ModuleAdded (ModuleSP &module_sp)
945{
946 // A module is being added to this target for the first time
947 ModuleList module_list;
948 module_list.Append(module_sp);
949 ModulesDidLoad (module_list);
950}
951
952void
953Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
954{
Jim Ingham3b8a6052011-08-03 01:00:06 +0000955 // A module is replacing an already added module
Chris Lattner24943d22010-06-08 16:52:24 +0000956 ModuleList module_list;
957 module_list.Append (old_module_sp);
958 ModulesDidUnload (module_list);
959 module_list.Clear ();
960 module_list.Append (new_module_sp);
961 ModulesDidLoad (module_list);
962}
963
964void
965Target::ModulesDidLoad (ModuleList &module_list)
966{
967 m_breakpoint_list.UpdateBreakpoints (module_list, true);
968 // TODO: make event data that packages up the module_list
969 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
970}
971
972void
973Target::ModulesDidUnload (ModuleList &module_list)
974{
975 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000976
977 // Remove the images from the target image list
978 m_images.Remove(module_list);
979
Chris Lattner24943d22010-06-08 16:52:24 +0000980 // TODO: make event data that packages up the module_list
981 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
982}
983
Jim Ingham7089d8a2011-10-28 23:14:11 +0000984
Daniel Dunbar705a0982011-10-31 22:50:37 +0000985bool
Greg Clayton444fe992012-02-26 05:51:37 +0000986Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +0000987{
988
989 if (!m_breakpoints_use_platform_avoid)
990 return false;
991 else
992 {
993 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +0000994 ModuleSpec module_spec (module_file_spec);
995 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +0000996
997 // If there is more than one module for this file spec, only return true if ALL the modules are on the
998 // black list.
999 if (num_modules > 0)
1000 {
1001 for (int i = 0; i < num_modules; i++)
1002 {
1003 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1004 return false;
1005 }
1006 return true;
1007 }
1008 else
1009 return false;
1010 }
1011}
1012
Daniel Dunbar705a0982011-10-31 22:50:37 +00001013bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001014Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1015{
1016 if (!m_breakpoints_use_platform_avoid)
1017 return false;
1018 else if (GetPlatform())
1019 {
1020 return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
1021 }
1022 else
1023 return false;
1024}
1025
Chris Lattner24943d22010-06-08 16:52:24 +00001026size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001027Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1028{
Greg Clayton3508c382012-02-24 01:59:29 +00001029 SectionSP section_sp (addr.GetSection());
1030 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001031 {
Greg Clayton3508c382012-02-24 01:59:29 +00001032 ModuleSP module_sp (section_sp->GetModule());
1033 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001034 {
Greg Clayton3508c382012-02-24 01:59:29 +00001035 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1036 if (objfile)
1037 {
1038 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1039 addr.GetOffset(),
1040 dst,
1041 dst_len);
1042 if (bytes_read > 0)
1043 return bytes_read;
1044 else
1045 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1046 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001047 else
Greg Clayton3508c382012-02-24 01:59:29 +00001048 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001049 }
1050 else
Greg Clayton3508c382012-02-24 01:59:29 +00001051 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001052 }
1053 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001054 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001055
Greg Clayton26100dc2011-01-07 01:57:07 +00001056 return 0;
1057}
1058
1059size_t
Enrico Granata91544802011-09-06 19:20:51 +00001060Target::ReadMemory (const Address& addr,
1061 bool prefer_file_cache,
1062 void *dst,
1063 size_t dst_len,
1064 Error &error,
1065 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001066{
Chris Lattner24943d22010-06-08 16:52:24 +00001067 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001068
Enrico Granata91544802011-09-06 19:20:51 +00001069 // if we end up reading this from process memory, we will fill this
1070 // with the actual load address
1071 if (load_addr_ptr)
1072 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1073
Greg Clayton26100dc2011-01-07 01:57:07 +00001074 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001075
1076 addr_t load_addr = LLDB_INVALID_ADDRESS;
1077 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001078 Address resolved_addr;
1079 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001080 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001081 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001082 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001083 // No sections are loaded, so we must assume we are not running
1084 // yet and anything we are given is a file address.
1085 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1086 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001087 }
Greg Clayton70436352010-06-30 23:03:03 +00001088 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001089 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001090 // We have at least one section loaded. This can be becuase
1091 // we have manually loaded some sections with "target modules load ..."
1092 // or because we have have a live process that has sections loaded
1093 // through the dynamic loader
1094 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1095 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001096 }
Greg Clayton70436352010-06-30 23:03:03 +00001097 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001098 if (!resolved_addr.IsValid())
1099 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001100
Greg Clayton9b82f862011-07-11 05:12:02 +00001101
Greg Clayton26100dc2011-01-07 01:57:07 +00001102 if (prefer_file_cache)
1103 {
1104 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1105 if (bytes_read > 0)
1106 return bytes_read;
1107 }
Greg Clayton70436352010-06-30 23:03:03 +00001108
Johnny Chenda5a8022011-09-20 23:28:55 +00001109 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001110 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001111 if (load_addr == LLDB_INVALID_ADDRESS)
1112 load_addr = resolved_addr.GetLoadAddress (this);
1113
Greg Clayton70436352010-06-30 23:03:03 +00001114 if (load_addr == LLDB_INVALID_ADDRESS)
1115 {
Greg Clayton3508c382012-02-24 01:59:29 +00001116 ModuleSP addr_module_sp (resolved_addr.GetModule());
1117 if (addr_module_sp && addr_module_sp->GetFileSpec())
Greg Clayton9c236732011-10-26 00:56:27 +00001118 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001119 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001120 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001121 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001122 else
Greg Clayton9c236732011-10-26 00:56:27 +00001123 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001124 }
1125 else
1126 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001127 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001128 if (bytes_read != dst_len)
1129 {
1130 if (error.Success())
1131 {
1132 if (bytes_read == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00001133 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001134 else
Greg Clayton9c236732011-10-26 00:56:27 +00001135 error.SetErrorStringWithFormat("only %zu of %zu bytes were read from memory at 0x%llx", bytes_read, dst_len, load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001136 }
1137 }
Greg Clayton70436352010-06-30 23:03:03 +00001138 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001139 {
1140 if (load_addr_ptr)
1141 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001142 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001143 }
Greg Clayton70436352010-06-30 23:03:03 +00001144 // If the address is not section offset we have an address that
1145 // doesn't resolve to any address in any currently loaded shared
1146 // libaries and we failed to read memory so there isn't anything
1147 // more we can do. If it is section offset, we might be able to
1148 // read cached memory from the object file.
1149 if (!resolved_addr.IsSectionOffset())
1150 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001151 }
Chris Lattner24943d22010-06-08 16:52:24 +00001152 }
Greg Clayton70436352010-06-30 23:03:03 +00001153
Greg Clayton9b82f862011-07-11 05:12:02 +00001154 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001155 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001156 // If we didn't already try and read from the object file cache, then
1157 // try it after failing to read from the process.
1158 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001159 }
1160 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001161}
1162
Greg Clayton7dd98df2011-07-12 17:06:17 +00001163size_t
1164Target::ReadScalarIntegerFromMemory (const Address& addr,
1165 bool prefer_file_cache,
1166 uint32_t byte_size,
1167 bool is_signed,
1168 Scalar &scalar,
1169 Error &error)
1170{
1171 uint64_t uval;
1172
1173 if (byte_size <= sizeof(uval))
1174 {
1175 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1176 if (bytes_read == byte_size)
1177 {
1178 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1179 uint32_t offset = 0;
1180 if (byte_size <= 4)
1181 scalar = data.GetMaxU32 (&offset, byte_size);
1182 else
1183 scalar = data.GetMaxU64 (&offset, byte_size);
1184
1185 if (is_signed)
1186 scalar.SignExtend(byte_size * 8);
1187 return bytes_read;
1188 }
1189 }
1190 else
1191 {
1192 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1193 }
1194 return 0;
1195}
1196
1197uint64_t
1198Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1199 bool prefer_file_cache,
1200 size_t integer_byte_size,
1201 uint64_t fail_value,
1202 Error &error)
1203{
1204 Scalar scalar;
1205 if (ReadScalarIntegerFromMemory (addr,
1206 prefer_file_cache,
1207 integer_byte_size,
1208 false,
1209 scalar,
1210 error))
1211 return scalar.ULongLong(fail_value);
1212 return fail_value;
1213}
1214
1215bool
1216Target::ReadPointerFromMemory (const Address& addr,
1217 bool prefer_file_cache,
1218 Error &error,
1219 Address &pointer_addr)
1220{
1221 Scalar scalar;
1222 if (ReadScalarIntegerFromMemory (addr,
1223 prefer_file_cache,
1224 m_arch.GetAddressByteSize(),
1225 false,
1226 scalar,
1227 error))
1228 {
1229 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1230 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1231 {
1232 if (m_section_load_list.IsEmpty())
1233 {
1234 // No sections are loaded, so we must assume we are not running
1235 // yet and anything we are given is a file address.
1236 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1237 }
1238 else
1239 {
1240 // We have at least one section loaded. This can be becuase
1241 // we have manually loaded some sections with "target modules load ..."
1242 // or because we have have a live process that has sections loaded
1243 // through the dynamic loader
1244 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1245 }
1246 // We weren't able to resolve the pointer value, so just return
1247 // an address with no section
1248 if (!pointer_addr.IsValid())
1249 pointer_addr.SetOffset (pointer_vm_addr);
1250 return true;
1251
1252 }
1253 }
1254 return false;
1255}
Chris Lattner24943d22010-06-08 16:52:24 +00001256
1257ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001258Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001259{
1260 // Don't pass in the UUID so we can tell if we have a stale value in our list
1261 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1262 bool did_create_module = false;
1263 ModuleSP module_sp;
1264
Chris Lattner24943d22010-06-08 16:52:24 +00001265 Error error;
1266
Greg Clayton24bc5d92011-03-30 18:16:51 +00001267 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +00001268 if (m_image_search_paths.GetSize())
1269 {
Greg Clayton444fe992012-02-26 05:51:37 +00001270 ModuleSpec transformed_spec (module_spec);
1271 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
Chris Lattner24943d22010-06-08 16:52:24 +00001272 {
Greg Clayton444fe992012-02-26 05:51:37 +00001273 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
Greg Clayton9ce95382012-02-13 23:10:39 +00001274 error = ModuleList::GetSharedModule (transformed_spec,
Greg Clayton9ce95382012-02-13 23:10:39 +00001275 module_sp,
1276 &GetExecutableSearchPaths(),
1277 &old_module_sp,
1278 &did_create_module);
Chris Lattner24943d22010-06-08 16:52:24 +00001279 }
1280 }
1281
Greg Clayton24bc5d92011-03-30 18:16:51 +00001282 // The platform is responsible for finding and caching an appropriate
1283 // module in the shared module cache.
1284 if (m_platform_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001285 {
Greg Clayton24bc5d92011-03-30 18:16:51 +00001286 FileSpec platform_file_spec;
Greg Clayton444fe992012-02-26 05:51:37 +00001287 error = m_platform_sp->GetSharedModule (module_spec,
Greg Clayton24bc5d92011-03-30 18:16:51 +00001288 module_sp,
Greg Clayton9ce95382012-02-13 23:10:39 +00001289 &GetExecutableSearchPaths(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001290 &old_module_sp,
1291 &did_create_module);
1292 }
1293 else
1294 {
1295 error.SetErrorString("no platform is currently set");
Chris Lattner24943d22010-06-08 16:52:24 +00001296 }
1297
Greg Clayton24bc5d92011-03-30 18:16:51 +00001298 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +00001299 if (module_sp)
1300 {
1301 m_images.Append (module_sp);
1302 if (did_create_module)
1303 {
1304 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1305 ModuleUpdated(old_module_sp, module_sp);
1306 else
1307 ModuleAdded(module_sp);
1308 }
1309 }
1310 if (error_ptr)
1311 *error_ptr = error;
1312 return module_sp;
1313}
1314
1315
Greg Clayton289afcb2012-02-18 05:35:26 +00001316TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001317Target::CalculateTarget ()
1318{
Greg Clayton289afcb2012-02-18 05:35:26 +00001319 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001320}
1321
Greg Clayton289afcb2012-02-18 05:35:26 +00001322ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001323Target::CalculateProcess ()
1324{
Greg Clayton289afcb2012-02-18 05:35:26 +00001325 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001326}
1327
Greg Clayton289afcb2012-02-18 05:35:26 +00001328ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001329Target::CalculateThread ()
1330{
Greg Clayton289afcb2012-02-18 05:35:26 +00001331 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001332}
1333
Greg Clayton289afcb2012-02-18 05:35:26 +00001334StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001335Target::CalculateStackFrame ()
1336{
Greg Clayton289afcb2012-02-18 05:35:26 +00001337 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001338}
1339
1340void
Greg Claytona830adb2010-10-04 01:05:56 +00001341Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001342{
Greg Clayton567e7f32011-09-22 04:58:26 +00001343 exe_ctx.Clear();
1344 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001345}
1346
1347PathMappingList &
1348Target::GetImageSearchPathList ()
1349{
1350 return m_image_search_paths;
1351}
1352
1353void
1354Target::ImageSearchPathsChanged
1355(
1356 const PathMappingList &path_list,
1357 void *baton
1358)
1359{
1360 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001361 ModuleSP exe_module_sp (target->GetExecutableModule());
1362 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001363 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001364 target->m_images.Clear();
1365 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001366 }
1367}
1368
1369ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001370Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001371{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001372 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001373 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001374 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001375 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001376 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001377 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1378 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1379 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1380 }
Chris Lattner24943d22010-06-08 16:52:24 +00001381 return m_scratch_ast_context_ap.get();
1382}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001383
Sean Callanan4938bd62011-11-16 18:20:47 +00001384ClangASTImporter *
1385Target::GetClangASTImporter()
1386{
1387 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1388
1389 if (!ast_importer)
1390 {
1391 ast_importer = new ClangASTImporter();
1392 m_ast_importer_ap.reset(ast_importer);
1393 }
1394
1395 return ast_importer;
1396}
1397
Greg Clayton990de7b2010-11-18 23:32:35 +00001398void
Caroline Tice2a456812011-03-10 22:14:10 +00001399Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001400{
Greg Clayton334d33a2012-01-30 07:41:31 +00001401 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001402 SettingsController::global_settings_table,
1403 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001404
1405 // Now call SettingsInitialize() on each 'child' setting of Target
1406 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001407}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001408
Greg Clayton990de7b2010-11-18 23:32:35 +00001409void
Caroline Tice2a456812011-03-10 22:14:10 +00001410Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001411{
Caroline Tice2a456812011-03-10 22:14:10 +00001412
1413 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1414
1415 Process::SettingsTerminate ();
1416
1417 // Now terminate Target Settings.
1418
Greg Clayton990de7b2010-11-18 23:32:35 +00001419 UserSettingsControllerSP &usc = GetSettingsController();
1420 UserSettingsController::FinalizeSettingsController (usc);
1421 usc.reset();
1422}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001423
Greg Clayton990de7b2010-11-18 23:32:35 +00001424UserSettingsControllerSP &
1425Target::GetSettingsController ()
1426{
Greg Clayton334d33a2012-01-30 07:41:31 +00001427 static UserSettingsControllerSP g_settings_controller_sp;
1428 if (!g_settings_controller_sp)
1429 {
1430 g_settings_controller_sp.reset (new Target::SettingsController);
1431 // The first shared pointer to Target::SettingsController in
1432 // g_settings_controller_sp must be fully created above so that
1433 // the TargetInstanceSettings can use a weak_ptr to refer back
1434 // to the master setttings controller
1435 InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp,
1436 false,
1437 InstanceSettings::GetDefaultName().AsCString()));
1438 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1439 }
1440 return g_settings_controller_sp;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001441}
1442
Greg Clayton9ce95382012-02-13 23:10:39 +00001443FileSpecList
1444Target::GetDefaultExecutableSearchPaths ()
1445{
1446 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1447 if (settings_controller_sp)
1448 {
1449 lldb::InstanceSettingsSP instance_settings_sp (settings_controller_sp->GetDefaultInstanceSettings ());
1450 if (instance_settings_sp)
1451 return static_cast<TargetInstanceSettings *>(instance_settings_sp.get())->GetExecutableSearchPaths ();
1452 }
1453 return FileSpecList();
1454}
1455
1456
Caroline Tice5bc8c972010-09-20 20:44:43 +00001457ArchSpec
1458Target::GetDefaultArchitecture ()
1459{
Greg Clayton940b1032011-02-23 00:35:02 +00001460 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1461
1462 if (settings_controller_sp)
1463 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1464 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001465}
1466
1467void
Greg Clayton940b1032011-02-23 00:35:02 +00001468Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001469{
Greg Clayton940b1032011-02-23 00:35:02 +00001470 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1471
1472 if (settings_controller_sp)
1473 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001474}
1475
Greg Claytona830adb2010-10-04 01:05:56 +00001476Target *
1477Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1478{
1479 // The target can either exist in the "process" of ExecutionContext, or in
1480 // the "target_sp" member of SymbolContext. This accessor helper function
1481 // will get the target from one of these locations.
1482
1483 Target *target = NULL;
1484 if (sc_ptr != NULL)
1485 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001486 if (target == NULL && exe_ctx_ptr)
1487 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001488 return target;
1489}
1490
1491
Caroline Tice1ebef442010-09-27 00:30:10 +00001492void
1493Target::UpdateInstanceName ()
1494{
1495 StreamString sstr;
1496
Greg Clayton5beb99d2011-08-11 02:48:45 +00001497 Module *exe_module = GetExecutableModulePointer();
1498 if (exe_module)
Caroline Tice1ebef442010-09-27 00:30:10 +00001499 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001500 sstr.Printf ("%s_%s",
Greg Clayton5beb99d2011-08-11 02:48:45 +00001501 exe_module->GetFileSpec().GetFilename().AsCString(),
1502 exe_module->GetArchitecture().GetArchitectureName());
1503 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +00001504 }
1505}
1506
Sean Callanan77e93942010-10-29 00:29:03 +00001507const char *
1508Target::GetExpressionPrefixContentsAsCString ()
1509{
Sean Callanane0b7f942011-11-16 01:54:57 +00001510 if (!m_expr_prefix_contents.empty())
1511 return m_expr_prefix_contents.c_str();
Greg Claytonff44ab42011-04-23 02:04:55 +00001512 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001513}
1514
Greg Clayton427f2902010-12-14 02:59:59 +00001515ExecutionResults
1516Target::EvaluateExpression
1517(
1518 const char *expr_cstr,
1519 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001520 lldb_private::ExecutionPolicy execution_policy,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001521 bool coerce_to_id,
Greg Clayton427f2902010-12-14 02:59:59 +00001522 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001523 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001524 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +00001525 lldb::ValueObjectSP &result_valobj_sp
1526)
1527{
1528 ExecutionResults execution_results = eExecutionSetupError;
1529
1530 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001531
1532 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1533 return execution_results;
1534
Jim Ingham3613ae12011-05-12 02:06:14 +00001535 // We shouldn't run stop hooks in expressions.
1536 // Be sure to reset this if you return anywhere within this function.
1537 bool old_suppress_value = m_suppress_stop_hooks;
1538 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001539
1540 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001541
1542 const size_t expr_cstr_len = ::strlen (expr_cstr);
1543
Greg Clayton427f2902010-12-14 02:59:59 +00001544 if (frame)
1545 {
1546 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001547 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001548 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001549 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1550 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001551 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001552
1553 // Make sure we don't have any things that we know a variable expression
1554 // won't be able to deal with before calling into it
1555 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1556 {
1557 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1558 use_dynamic,
1559 expr_path_options,
1560 var_sp,
1561 error);
1562 }
Greg Clayton427f2902010-12-14 02:59:59 +00001563 }
1564 else if (m_process_sp)
1565 {
1566 m_process_sp->CalculateExecutionContext(exe_ctx);
1567 }
1568 else
1569 {
1570 CalculateExecutionContext(exe_ctx);
1571 }
1572
1573 if (result_valobj_sp)
1574 {
1575 execution_results = eExecutionCompleted;
1576 // We got a result from the frame variable expression path above...
1577 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1578
1579 lldb::ValueObjectSP const_valobj_sp;
1580
1581 // Check in case our value is already a constant value
1582 if (result_valobj_sp->GetIsConstant())
1583 {
1584 const_valobj_sp = result_valobj_sp;
1585 const_valobj_sp->SetName (persistent_variable_name);
1586 }
1587 else
Jim Inghame41494a2011-04-16 00:01:13 +00001588 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001589 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001590 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001591 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001592 if (dynamic_sp)
1593 result_valobj_sp = dynamic_sp;
1594 }
1595
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001596 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001597 }
Greg Clayton427f2902010-12-14 02:59:59 +00001598
Sean Callanan6a925532011-01-13 08:53:35 +00001599 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1600
Greg Clayton427f2902010-12-14 02:59:59 +00001601 result_valobj_sp = const_valobj_sp;
1602
Sean Callanan6a925532011-01-13 08:53:35 +00001603 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1604 assert (clang_expr_variable_sp.get());
1605
1606 // Set flags and live data as appropriate
1607
1608 const Value &result_value = live_valobj_sp->GetValue();
1609
1610 switch (result_value.GetValueType())
1611 {
1612 case Value::eValueTypeHostAddress:
1613 case Value::eValueTypeFileAddress:
1614 // we don't do anything with these for now
1615 break;
1616 case Value::eValueTypeScalar:
1617 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1618 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1619 break;
1620 case Value::eValueTypeLoadAddress:
1621 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1622 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1623 break;
1624 }
Greg Clayton427f2902010-12-14 02:59:59 +00001625 }
1626 else
1627 {
1628 // Make sure we aren't just trying to see the value of a persistent
1629 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001630 lldb::ClangExpressionVariableSP persistent_var_sp;
1631 // Only check for persistent variables the expression starts with a '$'
1632 if (expr_cstr[0] == '$')
1633 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1634
Greg Clayton427f2902010-12-14 02:59:59 +00001635 if (persistent_var_sp)
1636 {
1637 result_valobj_sp = persistent_var_sp->GetValueObject ();
1638 execution_results = eExecutionCompleted;
1639 }
1640 else
1641 {
1642 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001643
Greg Clayton427f2902010-12-14 02:59:59 +00001644 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001645 execution_policy,
Sean Callanan5b658cc2011-11-07 23:35:40 +00001646 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001647 coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
Sean Callanan6a925532011-01-13 08:53:35 +00001648 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001649 expr_cstr,
1650 prefix,
1651 result_valobj_sp);
1652 }
1653 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001654
1655 m_suppress_stop_hooks = old_suppress_value;
1656
Greg Clayton427f2902010-12-14 02:59:59 +00001657 return execution_results;
1658}
1659
Greg Claytonc0fa5332011-05-22 22:46:53 +00001660lldb::addr_t
1661Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1662{
1663 addr_t code_addr = load_addr;
1664 switch (m_arch.GetMachine())
1665 {
1666 case llvm::Triple::arm:
1667 case llvm::Triple::thumb:
1668 switch (addr_class)
1669 {
1670 case eAddressClassData:
1671 case eAddressClassDebug:
1672 return LLDB_INVALID_ADDRESS;
1673
1674 case eAddressClassUnknown:
1675 case eAddressClassInvalid:
1676 case eAddressClassCode:
1677 case eAddressClassCodeAlternateISA:
1678 case eAddressClassRuntime:
1679 // Check if bit zero it no set?
1680 if ((code_addr & 1ull) == 0)
1681 {
1682 // Bit zero isn't set, check if the address is a multiple of 2?
1683 if (code_addr & 2ull)
1684 {
1685 // The address is a multiple of 2 so it must be thumb, set bit zero
1686 code_addr |= 1ull;
1687 }
1688 else if (addr_class == eAddressClassCodeAlternateISA)
1689 {
1690 // We checked the address and the address claims to be the alternate ISA
1691 // which means thumb, so set bit zero.
1692 code_addr |= 1ull;
1693 }
1694 }
1695 break;
1696 }
1697 break;
1698
1699 default:
1700 break;
1701 }
1702 return code_addr;
1703}
1704
1705lldb::addr_t
1706Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1707{
1708 addr_t opcode_addr = load_addr;
1709 switch (m_arch.GetMachine())
1710 {
1711 case llvm::Triple::arm:
1712 case llvm::Triple::thumb:
1713 switch (addr_class)
1714 {
1715 case eAddressClassData:
1716 case eAddressClassDebug:
1717 return LLDB_INVALID_ADDRESS;
1718
1719 case eAddressClassInvalid:
1720 case eAddressClassUnknown:
1721 case eAddressClassCode:
1722 case eAddressClassCodeAlternateISA:
1723 case eAddressClassRuntime:
1724 opcode_addr &= ~(1ull);
1725 break;
1726 }
1727 break;
1728
1729 default:
1730 break;
1731 }
1732 return opcode_addr;
1733}
1734
Jim Inghamd60d94a2011-03-11 03:53:59 +00001735lldb::user_id_t
1736Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1737{
1738 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001739 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001740 m_stop_hooks[new_uid] = new_hook_sp;
1741 return new_uid;
1742}
1743
1744bool
1745Target::RemoveStopHookByID (lldb::user_id_t user_id)
1746{
1747 size_t num_removed;
1748 num_removed = m_stop_hooks.erase (user_id);
1749 if (num_removed == 0)
1750 return false;
1751 else
1752 return true;
1753}
1754
1755void
1756Target::RemoveAllStopHooks ()
1757{
1758 m_stop_hooks.clear();
1759}
1760
1761Target::StopHookSP
1762Target::GetStopHookByID (lldb::user_id_t user_id)
1763{
1764 StopHookSP found_hook;
1765
1766 StopHookCollection::iterator specified_hook_iter;
1767 specified_hook_iter = m_stop_hooks.find (user_id);
1768 if (specified_hook_iter != m_stop_hooks.end())
1769 found_hook = (*specified_hook_iter).second;
1770 return found_hook;
1771}
1772
1773bool
1774Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1775{
1776 StopHookCollection::iterator specified_hook_iter;
1777 specified_hook_iter = m_stop_hooks.find (user_id);
1778 if (specified_hook_iter == m_stop_hooks.end())
1779 return false;
1780
1781 (*specified_hook_iter).second->SetIsActive (active_state);
1782 return true;
1783}
1784
1785void
1786Target::SetAllStopHooksActiveState (bool active_state)
1787{
1788 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1789 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1790 {
1791 (*pos).second->SetIsActive (active_state);
1792 }
1793}
1794
1795void
1796Target::RunStopHooks ()
1797{
Jim Ingham3613ae12011-05-12 02:06:14 +00001798 if (m_suppress_stop_hooks)
1799 return;
1800
Jim Inghamd60d94a2011-03-11 03:53:59 +00001801 if (!m_process_sp)
1802 return;
1803
1804 if (m_stop_hooks.empty())
1805 return;
1806
1807 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1808
1809 // If there aren't any active stop hooks, don't bother either:
1810 bool any_active_hooks = false;
1811 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1812 {
1813 if ((*pos).second->IsActive())
1814 {
1815 any_active_hooks = true;
1816 break;
1817 }
1818 }
1819 if (!any_active_hooks)
1820 return;
1821
1822 CommandReturnObject result;
1823
1824 std::vector<ExecutionContext> exc_ctx_with_reasons;
1825 std::vector<SymbolContext> sym_ctx_with_reasons;
1826
1827 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1828 size_t num_threads = cur_threadlist.GetSize();
1829 for (size_t i = 0; i < num_threads; i++)
1830 {
1831 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1832 if (cur_thread_sp->ThreadStoppedForAReason())
1833 {
1834 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1835 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1836 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1837 }
1838 }
1839
1840 // If no threads stopped for a reason, don't run the stop-hooks.
1841 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1842 if (num_exe_ctx == 0)
1843 return;
1844
Jim Inghame5ed8e92011-06-02 23:58:26 +00001845 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1846 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001847
1848 bool keep_going = true;
1849 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001850 bool print_hook_header;
1851 bool print_thread_header;
1852
1853 if (num_exe_ctx == 1)
1854 print_thread_header = false;
1855 else
1856 print_thread_header = true;
1857
1858 if (m_stop_hooks.size() == 1)
1859 print_hook_header = false;
1860 else
1861 print_hook_header = true;
1862
Jim Inghamd60d94a2011-03-11 03:53:59 +00001863 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1864 {
1865 // result.Clear();
1866 StopHookSP cur_hook_sp = (*pos).second;
1867 if (!cur_hook_sp->IsActive())
1868 continue;
1869
1870 bool any_thread_matched = false;
1871 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1872 {
1873 if ((cur_hook_sp->GetSpecifier () == NULL
1874 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1875 && (cur_hook_sp->GetThreadSpecifier() == NULL
Greg Clayton567e7f32011-09-22 04:58:26 +00001876 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001877 {
1878 if (!hooks_ran)
1879 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00001880 hooks_ran = true;
1881 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001882 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001883 {
Johnny Chen4d96a742011-10-24 23:01:06 +00001884 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
1885 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
1886 NULL);
1887 if (cmd)
1888 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
1889 else
1890 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001891 any_thread_matched = true;
1892 }
1893
Jim Inghamc54840c2011-03-22 01:47:27 +00001894 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00001895 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001896
1897 bool stop_on_continue = true;
1898 bool stop_on_error = true;
1899 bool echo_commands = false;
1900 bool print_results = true;
1901 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001902 &exc_ctx_with_reasons[i],
1903 stop_on_continue,
1904 stop_on_error,
1905 echo_commands,
1906 print_results,
1907 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001908
1909 // If the command started the target going again, we should bag out of
1910 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001911 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1912 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001913 {
Greg Clayton444e35b2011-10-19 18:09:39 +00001914 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001915 keep_going = false;
1916 }
1917 }
1918 }
1919 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00001920
Caroline Tice4a348082011-05-02 20:41:46 +00001921 result.GetImmediateOutputStream()->Flush();
1922 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001923}
1924
Greg Claytonbbea1332011-07-08 00:48:09 +00001925bool
1926Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1927{
1928 bool changed = false;
1929 if (module)
1930 {
1931 ObjectFile *object_file = module->GetObjectFile();
1932 if (object_file)
1933 {
1934 SectionList *section_list = object_file->GetSectionList ();
1935 if (section_list)
1936 {
1937 // All sections listed in the dyld image info structure will all
1938 // either be fixed up already, or they will all be off by a single
1939 // slide amount that is determined by finding the first segment
1940 // that is at file offset zero which also has bytes (a file size
1941 // that is greater than zero) in the object file.
1942
1943 // Determine the slide amount (if any)
1944 const size_t num_sections = section_list->GetSize();
1945 size_t sect_idx = 0;
1946 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1947 {
1948 // Iterate through the object file sections to find the
1949 // first section that starts of file offset zero and that
1950 // has bytes in the file...
1951 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1952 if (section)
1953 {
1954 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1955 changed = true;
1956 }
1957 }
1958 }
1959 }
1960 }
1961 return changed;
1962}
1963
1964
Jim Inghamd60d94a2011-03-11 03:53:59 +00001965//--------------------------------------------------------------
1966// class Target::StopHook
1967//--------------------------------------------------------------
1968
1969
1970Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1971 UserID (uid),
1972 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00001973 m_commands (),
1974 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001975 m_thread_spec_ap(NULL),
1976 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001977{
1978}
1979
1980Target::StopHook::StopHook (const StopHook &rhs) :
1981 UserID (rhs.GetID()),
1982 m_target_sp (rhs.m_target_sp),
1983 m_commands (rhs.m_commands),
1984 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001985 m_thread_spec_ap (NULL),
1986 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001987{
1988 if (rhs.m_thread_spec_ap.get() != NULL)
1989 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1990}
1991
1992
1993Target::StopHook::~StopHook ()
1994{
1995}
1996
1997void
1998Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1999{
2000 m_thread_spec_ap.reset (specifier);
2001}
2002
2003
2004void
2005Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2006{
2007 int indent_level = s->GetIndentLevel();
2008
2009 s->SetIndentLevel(indent_level + 2);
2010
Greg Clayton444e35b2011-10-19 18:09:39 +00002011 s->Printf ("Hook: %llu\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002012 if (m_active)
2013 s->Indent ("State: enabled\n");
2014 else
2015 s->Indent ("State: disabled\n");
2016
2017 if (m_specifier_sp)
2018 {
2019 s->Indent();
2020 s->PutCString ("Specifier:\n");
2021 s->SetIndentLevel (indent_level + 4);
2022 m_specifier_sp->GetDescription (s, level);
2023 s->SetIndentLevel (indent_level + 2);
2024 }
2025
2026 if (m_thread_spec_ap.get() != NULL)
2027 {
2028 StreamString tmp;
2029 s->Indent("Thread:\n");
2030 m_thread_spec_ap->GetDescription (&tmp, level);
2031 s->SetIndentLevel (indent_level + 4);
2032 s->Indent (tmp.GetData());
2033 s->PutCString ("\n");
2034 s->SetIndentLevel (indent_level + 2);
2035 }
2036
2037 s->Indent ("Commands: \n");
2038 s->SetIndentLevel (indent_level + 4);
2039 uint32_t num_commands = m_commands.GetSize();
2040 for (uint32_t i = 0; i < num_commands; i++)
2041 {
2042 s->Indent(m_commands.GetStringAtIndex(i));
2043 s->PutCString ("\n");
2044 }
2045 s->SetIndentLevel (indent_level);
2046}
2047
2048
Caroline Tice5bc8c972010-09-20 20:44:43 +00002049//--------------------------------------------------------------
2050// class Target::SettingsController
2051//--------------------------------------------------------------
2052
2053Target::SettingsController::SettingsController () :
2054 UserSettingsController ("target", Debugger::GetSettingsController()),
2055 m_default_architecture ()
2056{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002057}
2058
2059Target::SettingsController::~SettingsController ()
2060{
2061}
2062
2063lldb::InstanceSettingsSP
2064Target::SettingsController::CreateInstanceSettings (const char *instance_name)
2065{
Greg Clayton334d33a2012-01-30 07:41:31 +00002066 lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
2067 false,
2068 instance_name));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002069 return new_settings_sp;
2070}
2071
Caroline Tice5bc8c972010-09-20 20:44:43 +00002072
Greg Claytonabb33022011-11-08 02:43:13 +00002073#define TSC_DEFAULT_ARCH "default-arch"
2074#define TSC_EXPR_PREFIX "expr-prefix"
2075#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
2076#define TSC_SKIP_PROLOGUE "skip-prologue"
2077#define TSC_SOURCE_MAP "source-map"
Greg Clayton9ce95382012-02-13 23:10:39 +00002078#define TSC_EXE_SEARCH_PATHS "exec-search-paths"
Greg Claytonabb33022011-11-08 02:43:13 +00002079#define TSC_MAX_CHILDREN "max-children-count"
2080#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2081#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2082#define TSC_RUN_ARGS "run-args"
2083#define TSC_ENV_VARS "env-vars"
2084#define TSC_INHERIT_ENV "inherit-env"
2085#define TSC_STDIN_PATH "input-path"
2086#define TSC_STDOUT_PATH "output-path"
2087#define TSC_STDERR_PATH "error-path"
2088#define TSC_DISABLE_ASLR "disable-aslr"
2089#define TSC_DISABLE_STDIO "disable-stdio"
Greg Claytond284b662011-02-18 01:44:25 +00002090
2091
2092static const ConstString &
2093GetSettingNameForDefaultArch ()
2094{
2095 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00002096 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002097}
2098
Greg Claytond284b662011-02-18 01:44:25 +00002099static const ConstString &
2100GetSettingNameForExpressionPrefix ()
2101{
2102 static ConstString g_const_string (TSC_EXPR_PREFIX);
2103 return g_const_string;
2104}
2105
2106static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00002107GetSettingNameForPreferDynamicValue ()
2108{
2109 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2110 return g_const_string;
2111}
2112
Greg Claytonff44ab42011-04-23 02:04:55 +00002113static const ConstString &
2114GetSettingNameForSourcePathMap ()
2115{
2116 static ConstString g_const_string (TSC_SOURCE_MAP);
2117 return g_const_string;
2118}
Greg Claytond284b662011-02-18 01:44:25 +00002119
Greg Clayton17cd9952011-04-22 03:55:06 +00002120static const ConstString &
Greg Clayton9ce95382012-02-13 23:10:39 +00002121GetSettingNameForExecutableSearchPaths ()
2122{
2123 static ConstString g_const_string (TSC_EXE_SEARCH_PATHS);
2124 return g_const_string;
2125}
2126
2127static const ConstString &
Greg Clayton17cd9952011-04-22 03:55:06 +00002128GetSettingNameForSkipPrologue ()
2129{
2130 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2131 return g_const_string;
2132}
2133
Enrico Granata018921d2011-08-12 02:00:06 +00002134static const ConstString &
2135GetSettingNameForMaxChildren ()
2136{
2137 static ConstString g_const_string (TSC_MAX_CHILDREN);
2138 return g_const_string;
2139}
Greg Clayton17cd9952011-04-22 03:55:06 +00002140
Enrico Granata91544802011-09-06 19:20:51 +00002141static const ConstString &
2142GetSettingNameForMaxStringSummaryLength ()
2143{
2144 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2145 return g_const_string;
2146}
Greg Clayton17cd9952011-04-22 03:55:06 +00002147
Jim Ingham7089d8a2011-10-28 23:14:11 +00002148static const ConstString &
2149GetSettingNameForPlatformAvoid ()
2150{
2151 static ConstString g_const_string (TSC_PLATFORM_AVOID);
2152 return g_const_string;
2153}
2154
Greg Claytonabb33022011-11-08 02:43:13 +00002155const ConstString &
2156GetSettingNameForRunArgs ()
2157{
2158 static ConstString g_const_string (TSC_RUN_ARGS);
2159 return g_const_string;
2160}
2161
2162const ConstString &
2163GetSettingNameForEnvVars ()
2164{
2165 static ConstString g_const_string (TSC_ENV_VARS);
2166 return g_const_string;
2167}
2168
2169const ConstString &
2170GetSettingNameForInheritHostEnv ()
2171{
2172 static ConstString g_const_string (TSC_INHERIT_ENV);
2173 return g_const_string;
2174}
2175
2176const ConstString &
2177GetSettingNameForInputPath ()
2178{
2179 static ConstString g_const_string (TSC_STDIN_PATH);
2180 return g_const_string;
2181}
2182
2183const ConstString &
2184GetSettingNameForOutputPath ()
2185{
2186 static ConstString g_const_string (TSC_STDOUT_PATH);
2187 return g_const_string;
2188}
2189
2190const ConstString &
2191GetSettingNameForErrorPath ()
2192{
2193 static ConstString g_const_string (TSC_STDERR_PATH);
2194 return g_const_string;
2195}
2196
2197const ConstString &
2198GetSettingNameForDisableASLR ()
2199{
2200 static ConstString g_const_string (TSC_DISABLE_ASLR);
2201 return g_const_string;
2202}
2203
2204const ConstString &
2205GetSettingNameForDisableSTDIO ()
2206{
2207 static ConstString g_const_string (TSC_DISABLE_STDIO);
2208 return g_const_string;
2209}
Jim Ingham7089d8a2011-10-28 23:14:11 +00002210
Caroline Tice5bc8c972010-09-20 20:44:43 +00002211bool
2212Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2213 const char *index_value,
2214 const char *value,
2215 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002216 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002217 Error&err)
2218{
Greg Claytond284b662011-02-18 01:44:25 +00002219 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002220 {
Greg Claytonf15996e2011-04-07 22:46:35 +00002221 m_default_architecture.SetTriple (value, NULL);
Greg Clayton940b1032011-02-23 00:35:02 +00002222 if (!m_default_architecture.IsValid())
2223 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002224 }
2225 return true;
2226}
2227
2228
2229bool
2230Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2231 StringList &value,
2232 Error &err)
2233{
Greg Claytond284b662011-02-18 01:44:25 +00002234 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002235 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00002236 // If the arch is invalid (the default), don't show a string for it
2237 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00002238 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00002239 return true;
2240 }
2241 else
2242 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2243
2244 return false;
2245}
2246
2247//--------------------------------------------------------------
2248// class TargetInstanceSettings
2249//--------------------------------------------------------------
2250
Greg Clayton638351a2010-12-04 00:10:17 +00002251TargetInstanceSettings::TargetInstanceSettings
2252(
Greg Clayton334d33a2012-01-30 07:41:31 +00002253 const lldb::UserSettingsControllerSP &owner_sp,
Greg Clayton638351a2010-12-04 00:10:17 +00002254 bool live_instance,
2255 const char *name
2256) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002257 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00002258 m_expr_prefix_file (),
Sean Callanane0b7f942011-11-16 01:54:57 +00002259 m_expr_prefix_contents (),
Jim Ingham10de7d12011-05-04 03:43:18 +00002260 m_prefer_dynamic_value (2),
Greg Claytonff44ab42011-04-23 02:04:55 +00002261 m_skip_prologue (true, true),
Enrico Granata018921d2011-08-12 02:00:06 +00002262 m_source_map (NULL, NULL),
Greg Clayton9ce95382012-02-13 23:10:39 +00002263 m_exe_search_paths (),
Enrico Granata91544802011-09-06 19:20:51 +00002264 m_max_children_display(256),
Jim Ingham7089d8a2011-10-28 23:14:11 +00002265 m_max_strlen_length(1024),
Greg Claytonabb33022011-11-08 02:43:13 +00002266 m_breakpoints_use_platform_avoid (true, true),
2267 m_run_args (),
2268 m_env_vars (),
2269 m_input_path (),
2270 m_output_path (),
2271 m_error_path (),
2272 m_disable_aslr (true),
2273 m_disable_stdio (false),
2274 m_inherit_host_env (true),
2275 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002276{
2277 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2278 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2279 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2280 // This is true for CreateInstanceName() too.
2281
2282 if (GetInstanceName () == InstanceSettings::InvalidName())
2283 {
2284 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00002285 owner_sp->RegisterInstanceSettings (this);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002286 }
2287
2288 if (live_instance)
2289 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002290 const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002291 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002292 }
2293}
2294
2295TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002296 InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
Greg Claytonff44ab42011-04-23 02:04:55 +00002297 m_expr_prefix_file (rhs.m_expr_prefix_file),
Sean Callanane0b7f942011-11-16 01:54:57 +00002298 m_expr_prefix_contents (rhs.m_expr_prefix_contents),
Greg Claytonff44ab42011-04-23 02:04:55 +00002299 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
2300 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata018921d2011-08-12 02:00:06 +00002301 m_source_map (rhs.m_source_map),
Greg Clayton9ce95382012-02-13 23:10:39 +00002302 m_exe_search_paths (rhs.m_exe_search_paths),
Greg Claytonabb33022011-11-08 02:43:13 +00002303 m_max_children_display (rhs.m_max_children_display),
2304 m_max_strlen_length (rhs.m_max_strlen_length),
2305 m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2306 m_run_args (rhs.m_run_args),
2307 m_env_vars (rhs.m_env_vars),
2308 m_input_path (rhs.m_input_path),
2309 m_output_path (rhs.m_output_path),
2310 m_error_path (rhs.m_error_path),
2311 m_disable_aslr (rhs.m_disable_aslr),
2312 m_disable_stdio (rhs.m_disable_stdio),
2313 m_inherit_host_env (rhs.m_inherit_host_env)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002314{
2315 if (m_instance_name != InstanceSettings::GetDefaultName())
2316 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002317 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2318 if (owner_sp)
2319 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002320 }
2321}
2322
2323TargetInstanceSettings::~TargetInstanceSettings ()
2324{
2325}
2326
2327TargetInstanceSettings&
2328TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2329{
2330 if (this != &rhs)
2331 {
Greg Claytonabb33022011-11-08 02:43:13 +00002332 m_expr_prefix_file = rhs.m_expr_prefix_file;
Sean Callanane0b7f942011-11-16 01:54:57 +00002333 m_expr_prefix_contents = rhs.m_expr_prefix_contents;
Greg Claytonabb33022011-11-08 02:43:13 +00002334 m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
2335 m_skip_prologue = rhs.m_skip_prologue;
2336 m_source_map = rhs.m_source_map;
Greg Clayton9ce95382012-02-13 23:10:39 +00002337 m_exe_search_paths = rhs.m_exe_search_paths;
Greg Claytonabb33022011-11-08 02:43:13 +00002338 m_max_children_display = rhs.m_max_children_display;
2339 m_max_strlen_length = rhs.m_max_strlen_length;
2340 m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2341 m_run_args = rhs.m_run_args;
2342 m_env_vars = rhs.m_env_vars;
2343 m_input_path = rhs.m_input_path;
2344 m_output_path = rhs.m_output_path;
2345 m_error_path = rhs.m_error_path;
2346 m_disable_aslr = rhs.m_disable_aslr;
2347 m_disable_stdio = rhs.m_disable_stdio;
2348 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002349 }
2350
2351 return *this;
2352}
2353
Caroline Tice5bc8c972010-09-20 20:44:43 +00002354void
2355TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2356 const char *index_value,
2357 const char *value,
2358 const ConstString &instance_name,
2359 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002360 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002361 Error &err,
2362 bool pending)
2363{
Greg Claytond284b662011-02-18 01:44:25 +00002364 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002365 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002366 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2367 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00002368 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002369 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00002370 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002371 default:
2372 break;
2373 case eVarSetOperationAssign:
2374 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00002375 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002376 m_expr_prefix_contents.clear();
2377
Greg Claytonff44ab42011-04-23 02:04:55 +00002378 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2379 {
2380 err.SetErrorToGenericError ();
Greg Clayton9c236732011-10-26 00:56:27 +00002381 err.SetErrorStringWithFormat ("%s does not exist", value);
Greg Claytonff44ab42011-04-23 02:04:55 +00002382 return;
2383 }
2384
Greg Clayton4b23ab32012-01-06 02:01:06 +00002385 DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
Sean Callanane0b7f942011-11-16 01:54:57 +00002386
Greg Clayton4b23ab32012-01-06 02:01:06 +00002387 if (err.Success())
Greg Claytonff44ab42011-04-23 02:04:55 +00002388 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002389 if (file_data_sp && file_data_sp->GetByteSize() > 0)
2390 {
2391 m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
2392 }
2393 else
2394 {
2395 err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
2396 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002397 }
Sean Callanan77e93942010-10-29 00:29:03 +00002398 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002399 break;
2400 case eVarSetOperationClear:
Sean Callanane0b7f942011-11-16 01:54:57 +00002401 m_expr_prefix_contents.clear();
Sean Callanan77e93942010-10-29 00:29:03 +00002402 }
Sean Callanan77e93942010-10-29 00:29:03 +00002403 }
2404 }
Jim Inghame41494a2011-04-16 00:01:13 +00002405 else if (var_name == GetSettingNameForPreferDynamicValue())
2406 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002407 int new_value;
2408 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2409 if (err.Success())
2410 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00002411 }
2412 else if (var_name == GetSettingNameForSkipPrologue())
2413 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002414 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2415 }
Enrico Granata018921d2011-08-12 02:00:06 +00002416 else if (var_name == GetSettingNameForMaxChildren())
2417 {
2418 bool ok;
2419 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2420 if (ok)
2421 m_max_children_display = new_value;
2422 }
Enrico Granata91544802011-09-06 19:20:51 +00002423 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2424 {
2425 bool ok;
2426 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2427 if (ok)
2428 m_max_strlen_length = new_value;
2429 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002430 else if (var_name == GetSettingNameForExecutableSearchPaths())
2431 {
2432 switch (op)
2433 {
2434 case eVarSetOperationReplace:
2435 case eVarSetOperationInsertBefore:
2436 case eVarSetOperationInsertAfter:
2437 case eVarSetOperationRemove:
2438 default:
2439 break;
2440 case eVarSetOperationAssign:
2441 m_exe_search_paths.Clear();
2442 // Fall through to append....
2443 case eVarSetOperationAppend:
2444 {
2445 Args args(value);
2446 const uint32_t argc = args.GetArgumentCount();
2447 if (argc > 0)
2448 {
2449 const char *exe_search_path_dir;
2450 for (uint32_t idx = 0; (exe_search_path_dir = args.GetArgumentAtIndex(idx)) != NULL; ++idx)
2451 {
2452 FileSpec file_spec;
2453 file_spec.GetDirectory().SetCString(exe_search_path_dir);
2454 FileSpec::FileType file_type = file_spec.GetFileType();
2455 if (file_type == FileSpec::eFileTypeDirectory || file_type == FileSpec::eFileTypeInvalid)
2456 {
2457 m_exe_search_paths.Append(file_spec);
2458 }
2459 else
2460 {
2461 err.SetErrorStringWithFormat("executable search path '%s' exists, but it does not resolve to a directory", exe_search_path_dir);
2462 }
2463 }
2464 }
2465 }
2466 break;
2467
2468 case eVarSetOperationClear:
2469 m_exe_search_paths.Clear();
2470 break;
2471 }
2472 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002473 else if (var_name == GetSettingNameForSourcePathMap ())
2474 {
2475 switch (op)
2476 {
2477 case eVarSetOperationReplace:
2478 case eVarSetOperationInsertBefore:
2479 case eVarSetOperationInsertAfter:
2480 case eVarSetOperationRemove:
2481 default:
2482 break;
2483 case eVarSetOperationAssign:
2484 m_source_map.Clear(true);
2485 // Fall through to append....
2486 case eVarSetOperationAppend:
2487 {
2488 Args args(value);
2489 const uint32_t argc = args.GetArgumentCount();
2490 if (argc & 1 || argc == 0)
2491 {
2492 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2493 }
2494 else
2495 {
2496 char resolved_new_path[PATH_MAX];
2497 FileSpec file_spec;
2498 const char *old_path;
2499 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2500 {
2501 const char *new_path = args.GetArgumentAtIndex(idx+1);
2502 assert (new_path); // We have an even number of paths, this shouldn't happen!
2503
2504 file_spec.SetFile(new_path, true);
2505 if (file_spec.Exists())
2506 {
2507 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2508 {
2509 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2510 return;
2511 }
2512 }
2513 else
2514 {
2515 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2516 return;
2517 }
2518 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2519 }
2520 }
2521 }
2522 break;
2523
2524 case eVarSetOperationClear:
2525 m_source_map.Clear(true);
2526 break;
2527 }
Jim Inghame41494a2011-04-16 00:01:13 +00002528 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002529 else if (var_name == GetSettingNameForPlatformAvoid ())
2530 {
2531 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
2532 }
Greg Claytonabb33022011-11-08 02:43:13 +00002533 else if (var_name == GetSettingNameForRunArgs())
2534 {
2535 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2536 }
2537 else if (var_name == GetSettingNameForEnvVars())
2538 {
2539 // This is nice for local debugging, but it is isn't correct for
2540 // remote debugging. We need to stop process.env-vars from being
2541 // populated with the host environment and add this as a launch option
2542 // and get the correct environment from the Target's platform.
2543 // GetHostEnvironmentIfNeeded ();
2544 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
2545 }
2546 else if (var_name == GetSettingNameForInputPath())
2547 {
2548 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2549 }
2550 else if (var_name == GetSettingNameForOutputPath())
2551 {
2552 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2553 }
2554 else if (var_name == GetSettingNameForErrorPath())
2555 {
2556 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2557 }
2558 else if (var_name == GetSettingNameForDisableASLR())
2559 {
2560 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
2561 }
2562 else if (var_name == GetSettingNameForDisableSTDIO ())
2563 {
2564 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
2565 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002566}
2567
2568void
Greg Claytond284b662011-02-18 01:44:25 +00002569TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002570{
Sean Callanan77e93942010-10-29 00:29:03 +00002571 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2572
2573 if (!new_settings_ptr)
2574 return;
2575
Greg Claytonabb33022011-11-08 02:43:13 +00002576 *this = *new_settings_ptr;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002577}
2578
Caroline Ticebcb5b452010-09-20 21:37:42 +00002579bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00002580TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2581 const ConstString &var_name,
2582 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00002583 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002584{
Greg Claytond284b662011-02-18 01:44:25 +00002585 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002586 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002587 char path[PATH_MAX];
2588 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2589 if (path_len > 0)
2590 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00002591 }
Jim Inghame41494a2011-04-16 00:01:13 +00002592 else if (var_name == GetSettingNameForPreferDynamicValue())
2593 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002594 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00002595 }
Greg Clayton17cd9952011-04-22 03:55:06 +00002596 else if (var_name == GetSettingNameForSkipPrologue())
2597 {
2598 if (m_skip_prologue)
2599 value.AppendString ("true");
2600 else
2601 value.AppendString ("false");
2602 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002603 else if (var_name == GetSettingNameForExecutableSearchPaths())
2604 {
2605 if (m_exe_search_paths.GetSize())
2606 {
2607 for (size_t i = 0, n = m_exe_search_paths.GetSize(); i < n; ++i)
2608 {
2609 value.AppendString(m_exe_search_paths.GetFileSpecAtIndex (i).GetDirectory().AsCString());
2610 }
2611 }
2612 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002613 else if (var_name == GetSettingNameForSourcePathMap ())
2614 {
Johnny Chen931449e2011-12-12 21:59:28 +00002615 if (m_source_map.GetSize())
2616 {
2617 size_t i;
2618 for (i = 0; i < m_source_map.GetSize(); ++i) {
2619 StreamString sstr;
2620 m_source_map.Dump(&sstr, i);
2621 value.AppendString(sstr.GetData());
2622 }
2623 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002624 }
Enrico Granata018921d2011-08-12 02:00:06 +00002625 else if (var_name == GetSettingNameForMaxChildren())
2626 {
2627 StreamString count_str;
2628 count_str.Printf ("%d", m_max_children_display);
2629 value.AppendString (count_str.GetData());
2630 }
Enrico Granata91544802011-09-06 19:20:51 +00002631 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2632 {
2633 StreamString count_str;
2634 count_str.Printf ("%d", m_max_strlen_length);
2635 value.AppendString (count_str.GetData());
2636 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002637 else if (var_name == GetSettingNameForPlatformAvoid())
2638 {
2639 if (m_breakpoints_use_platform_avoid)
2640 value.AppendString ("true");
2641 else
2642 value.AppendString ("false");
2643 }
Greg Claytonabb33022011-11-08 02:43:13 +00002644 else if (var_name == GetSettingNameForRunArgs())
2645 {
2646 if (m_run_args.GetArgumentCount() > 0)
2647 {
2648 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2649 value.AppendString (m_run_args.GetArgumentAtIndex (i));
2650 }
2651 }
2652 else if (var_name == GetSettingNameForEnvVars())
2653 {
2654 GetHostEnvironmentIfNeeded ();
2655
2656 if (m_env_vars.size() > 0)
2657 {
2658 std::map<std::string, std::string>::iterator pos;
2659 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2660 {
2661 StreamString value_str;
2662 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2663 value.AppendString (value_str.GetData());
2664 }
2665 }
2666 }
2667 else if (var_name == GetSettingNameForInputPath())
2668 {
2669 value.AppendString (m_input_path.c_str());
2670 }
2671 else if (var_name == GetSettingNameForOutputPath())
2672 {
2673 value.AppendString (m_output_path.c_str());
2674 }
2675 else if (var_name == GetSettingNameForErrorPath())
2676 {
2677 value.AppendString (m_error_path.c_str());
2678 }
2679 else if (var_name == GetSettingNameForInheritHostEnv())
2680 {
2681 if (m_inherit_host_env)
2682 value.AppendString ("true");
2683 else
2684 value.AppendString ("false");
2685 }
2686 else if (var_name == GetSettingNameForDisableASLR())
2687 {
2688 if (m_disable_aslr)
2689 value.AppendString ("true");
2690 else
2691 value.AppendString ("false");
2692 }
2693 else if (var_name == GetSettingNameForDisableSTDIO())
2694 {
2695 if (m_disable_stdio)
2696 value.AppendString ("true");
2697 else
2698 value.AppendString ("false");
2699 }
Sean Callanan77e93942010-10-29 00:29:03 +00002700 else
2701 {
2702 if (err)
2703 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2704 return false;
2705 }
Sean Callanan77e93942010-10-29 00:29:03 +00002706 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002707}
2708
Greg Claytonabb33022011-11-08 02:43:13 +00002709void
2710Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
2711{
2712 if (m_inherit_host_env && !m_got_host_env)
2713 {
2714 m_got_host_env = true;
2715 StringList host_env;
2716 const size_t host_env_count = Host::GetEnvironment (host_env);
2717 for (size_t idx=0; idx<host_env_count; idx++)
2718 {
2719 const char *env_entry = host_env.GetStringAtIndex (idx);
2720 if (env_entry)
2721 {
2722 const char *equal_pos = ::strchr(env_entry, '=');
2723 if (equal_pos)
2724 {
2725 std::string key (env_entry, equal_pos - env_entry);
2726 std::string value (equal_pos + 1);
2727 if (m_env_vars.find (key) == m_env_vars.end())
2728 m_env_vars[key] = value;
2729 }
2730 }
2731 }
2732 }
2733}
2734
2735
2736size_t
2737Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
2738{
2739 GetHostEnvironmentIfNeeded ();
2740
2741 dictionary::const_iterator pos, end = m_env_vars.end();
2742 for (pos = m_env_vars.begin(); pos != end; ++pos)
2743 {
2744 std::string env_var_equal_value (pos->first);
2745 env_var_equal_value.append(1, '=');
2746 env_var_equal_value.append (pos->second);
2747 env.AppendArgument (env_var_equal_value.c_str());
2748 }
2749 return env.GetArgumentCount();
2750}
2751
2752
Caroline Tice5bc8c972010-09-20 20:44:43 +00002753const ConstString
2754TargetInstanceSettings::CreateInstanceName ()
2755{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002756 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00002757 static int instance_count = 1;
2758
Caroline Tice5bc8c972010-09-20 20:44:43 +00002759 sstr.Printf ("target_%d", instance_count);
2760 ++instance_count;
2761
2762 const ConstString ret_val (sstr.GetData());
2763 return ret_val;
2764}
2765
2766//--------------------------------------------------
2767// Target::SettingsController Variable Tables
2768//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00002769OptionEnumValueElement
2770TargetInstanceSettings::g_dynamic_value_types[] =
2771{
Greg Clayton577fbc32011-05-30 00:39:48 +00002772{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2773{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2774{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham10de7d12011-05-04 03:43:18 +00002775{ 0, NULL, NULL }
2776};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002777
2778SettingEntry
2779Target::SettingsController::global_settings_table[] =
2780{
Greg Claytond284b662011-02-18 01:44:25 +00002781 // var-name var-type default enum init'd hidden help-text
2782 // ================= ================== =========== ==== ====== ====== =========================================================================
2783 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2784 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2785};
2786
Caroline Tice5bc8c972010-09-20 20:44:43 +00002787SettingEntry
2788Target::SettingsController::instance_settings_table[] =
2789{
Enrico Granata91544802011-09-06 19:20:51 +00002790 // var-name var-type default enum init'd hidden help-text
2791 // ================= ================== =============== ======================= ====== ====== =========================================================================
2792 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2793 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2794 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2795 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
Greg Clayton9ce95382012-02-13 23:10:39 +00002796 { TSC_EXE_SEARCH_PATHS , eSetVarTypeArray , NULL , NULL, false, false, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
Enrico Granata91544802011-09-06 19:20:51 +00002797 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2798 { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
Jim Ingham7089d8a2011-10-28 23:14:11 +00002799 { TSC_PLATFORM_AVOID , eSetVarTypeBoolean, "true" , NULL, false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." },
Greg Claytonabb33022011-11-08 02:43:13 +00002800 { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2801 { TSC_ENV_VARS , eSetVarTypeDictionary, NULL , NULL, false, false, "A list of all the environment variables to be passed to the executable's environment, and their values." },
2802 { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2803 { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
2804 { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
2805 { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
2806// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
2807 { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2808 { TSC_DISABLE_STDIO , eSetVarTypeBoolean, "false" , NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" },
Enrico Granata91544802011-09-06 19:20:51 +00002809 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002810};
Jim Ingham5a15e692012-02-16 06:50:00 +00002811
2812const ConstString &
2813Target::TargetEventData::GetFlavorString ()
2814{
2815 static ConstString g_flavor ("Target::TargetEventData");
2816 return g_flavor;
2817}
2818
2819const ConstString &
2820Target::TargetEventData::GetFlavor () const
2821{
2822 return TargetEventData::GetFlavorString ();
2823}
2824
2825Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2826 EventData(),
2827 m_target_sp (new_target_sp)
2828{
2829}
2830
2831Target::TargetEventData::~TargetEventData()
2832{
2833
2834}
2835
2836void
2837Target::TargetEventData::Dump (Stream *s) const
2838{
2839
2840}
2841
2842const TargetSP
2843Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2844{
2845 TargetSP target_sp;
2846
2847 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2848 if (data)
2849 target_sp = data->m_target_sp;
2850
2851 return target_sp;
2852}
2853
2854const Target::TargetEventData *
2855Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2856{
2857 if (event_ptr)
2858 {
2859 const EventData *event_data = event_ptr->GetData();
2860 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2861 return static_cast <const TargetEventData *> (event_ptr->GetData());
2862 }
2863 return NULL;
2864}
2865