blob: f3b8a7832ab970faf13ff1112c753be3dda3a6a4 [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
Jim Ingham3df164e2012-03-05 04:47:34 +0000388lldb::BreakpointSP
389Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
390{
391 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
392}
393
Chris Lattner24943d22010-06-08 16:52:24 +0000394BreakpointSP
395Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
396{
397 BreakpointSP bp_sp;
398 if (filter_sp && resolver_sp)
399 {
400 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
401 resolver_sp->SetBreakpoint (bp_sp.get());
402
403 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000404 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000405 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000406 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000407
Greg Claytone005f2c2010-11-06 01:53:30 +0000408 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000409 if (log)
410 {
411 StreamString s;
412 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
413 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
414 }
415
Chris Lattner24943d22010-06-08 16:52:24 +0000416 bp_sp->ResolveBreakpoint();
417 }
Jim Inghamd1686902010-10-14 23:45:03 +0000418
419 if (!internal && bp_sp)
420 {
421 m_last_created_breakpoint = bp_sp;
422 }
423
Chris Lattner24943d22010-06-08 16:52:24 +0000424 return bp_sp;
425}
426
Johnny Chenda5a8022011-09-20 23:28:55 +0000427bool
428Target::ProcessIsValid()
429{
430 return (m_process_sp && m_process_sp->IsAlive());
431}
432
Johnny Chenecd4feb2011-10-14 00:42:25 +0000433// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000434// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000435WatchpointSP
436Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
Johnny Chen34bbf852011-09-12 23:38:44 +0000437{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000438 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
439 if (log)
440 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
441 __FUNCTION__, addr, size, type);
442
Johnny Chenecd4feb2011-10-14 00:42:25 +0000443 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000444 if (!ProcessIsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000445 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000446 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenecd4feb2011-10-14 00:42:25 +0000447 return wp_sp;
Johnny Chen9bf11992011-09-13 01:15:36 +0000448
Johnny Chenecd4feb2011-10-14 00:42:25 +0000449 // Currently we only support one watchpoint per address, with total number
450 // of watchpoints limited by the hardware which the inferior is running on.
451 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000452 if (matched_sp)
453 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000454 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000455 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000456 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
457 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000458 // Return the existing watchpoint if both size and type match.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000459 if (size == old_size && type == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000460 wp_sp = matched_sp;
461 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000462 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000463 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000464 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000465 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000466 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000467 }
468
Johnny Chenecd4feb2011-10-14 00:42:25 +0000469 if (!wp_sp) {
470 Watchpoint *new_wp = new Watchpoint(addr, size);
471 if (!new_wp) {
472 printf("Watchpoint ctor failed, out of memory?\n");
473 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000474 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000475 new_wp->SetWatchpointType(type);
476 new_wp->SetTarget(this);
477 wp_sp.reset(new_wp);
478 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000479 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000480
Johnny Chenecd4feb2011-10-14 00:42:25 +0000481 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000482 if (log)
483 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
484 __FUNCTION__,
485 rc.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000486 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000487
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000488 if (rc.Fail())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000489 wp_sp.reset();
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000490 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000491 m_last_created_watchpoint = wp_sp;
492 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000493}
494
Chris Lattner24943d22010-06-08 16:52:24 +0000495void
496Target::RemoveAllBreakpoints (bool internal_also)
497{
Greg Claytone005f2c2010-11-06 01:53:30 +0000498 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000499 if (log)
500 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
501
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000502 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000503 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000504 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000505
506 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000507}
508
509void
510Target::DisableAllBreakpoints (bool internal_also)
511{
Greg Claytone005f2c2010-11-06 01:53:30 +0000512 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000513 if (log)
514 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
515
516 m_breakpoint_list.SetEnabledAll (false);
517 if (internal_also)
518 m_internal_breakpoint_list.SetEnabledAll (false);
519}
520
521void
522Target::EnableAllBreakpoints (bool internal_also)
523{
Greg Claytone005f2c2010-11-06 01:53:30 +0000524 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000525 if (log)
526 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
527
528 m_breakpoint_list.SetEnabledAll (true);
529 if (internal_also)
530 m_internal_breakpoint_list.SetEnabledAll (true);
531}
532
533bool
534Target::RemoveBreakpointByID (break_id_t break_id)
535{
Greg Claytone005f2c2010-11-06 01:53:30 +0000536 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000537 if (log)
538 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
539
540 if (DisableBreakpointByID (break_id))
541 {
542 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000543 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000544 else
Jim Inghamd1686902010-10-14 23:45:03 +0000545 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000546 if (m_last_created_breakpoint)
547 {
548 if (m_last_created_breakpoint->GetID() == break_id)
549 m_last_created_breakpoint.reset();
550 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000551 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000552 }
Chris Lattner24943d22010-06-08 16:52:24 +0000553 return true;
554 }
555 return false;
556}
557
558bool
559Target::DisableBreakpointByID (break_id_t break_id)
560{
Greg Claytone005f2c2010-11-06 01:53:30 +0000561 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000562 if (log)
563 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
564
565 BreakpointSP bp_sp;
566
567 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
568 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
569 else
570 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
571 if (bp_sp)
572 {
573 bp_sp->SetEnabled (false);
574 return true;
575 }
576 return false;
577}
578
579bool
580Target::EnableBreakpointByID (break_id_t break_id)
581{
Greg Claytone005f2c2010-11-06 01:53:30 +0000582 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000583 if (log)
584 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
585 __FUNCTION__,
586 break_id,
587 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
588
589 BreakpointSP bp_sp;
590
591 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
592 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
593 else
594 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
595
596 if (bp_sp)
597 {
598 bp_sp->SetEnabled (true);
599 return true;
600 }
601 return false;
602}
603
Johnny Chenc86582f2011-09-23 21:21:43 +0000604// The flag 'end_to_end', default to true, signifies that the operation is
605// performed end to end, for both the debugger and the debuggee.
606
Johnny Chenecd4feb2011-10-14 00:42:25 +0000607// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
608// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000609bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000610Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000611{
612 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
613 if (log)
614 log->Printf ("Target::%s\n", __FUNCTION__);
615
Johnny Chenc86582f2011-09-23 21:21:43 +0000616 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000617 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000618 return true;
619 }
620
621 // Otherwise, it's an end to end operation.
622
Johnny Chenda5a8022011-09-20 23:28:55 +0000623 if (!ProcessIsValid())
624 return false;
625
Johnny Chenecd4feb2011-10-14 00:42:25 +0000626 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000627 for (size_t i = 0; i < num_watchpoints; ++i)
628 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000629 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
630 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000631 return false;
632
Johnny Chenecd4feb2011-10-14 00:42:25 +0000633 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000634 if (rc.Fail())
635 return false;
636 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000637 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000638 return true; // Success!
639}
640
Johnny Chenecd4feb2011-10-14 00:42:25 +0000641// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
642// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000643bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000644Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000645{
646 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
647 if (log)
648 log->Printf ("Target::%s\n", __FUNCTION__);
649
Johnny Chenc86582f2011-09-23 21:21:43 +0000650 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000651 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000652 return true;
653 }
654
655 // Otherwise, it's an end to end operation.
656
Johnny Chenda5a8022011-09-20 23:28:55 +0000657 if (!ProcessIsValid())
658 return false;
659
Johnny Chenecd4feb2011-10-14 00:42:25 +0000660 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000661 for (size_t i = 0; i < num_watchpoints; ++i)
662 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000663 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
664 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000665 return false;
666
Johnny Chenecd4feb2011-10-14 00:42:25 +0000667 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000668 if (rc.Fail())
669 return false;
670 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000671 return true; // Success!
672}
673
Johnny Chenecd4feb2011-10-14 00:42:25 +0000674// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
675// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000676bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000677Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000678{
679 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
680 if (log)
681 log->Printf ("Target::%s\n", __FUNCTION__);
682
Johnny Chenc86582f2011-09-23 21:21:43 +0000683 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000684 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000685 return true;
686 }
687
688 // Otherwise, it's an end to end operation.
689
Johnny Chenda5a8022011-09-20 23:28:55 +0000690 if (!ProcessIsValid())
691 return false;
692
Johnny Chenecd4feb2011-10-14 00:42:25 +0000693 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000694 for (size_t i = 0; i < num_watchpoints; ++i)
695 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000696 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
697 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000698 return false;
699
Johnny Chenecd4feb2011-10-14 00:42:25 +0000700 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000701 if (rc.Fail())
702 return false;
703 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000704 return true; // Success!
705}
706
Johnny Chen116a5cd2012-02-25 06:44:30 +0000707// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
708bool
709Target::ClearAllWatchpointHitCounts ()
710{
711 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
712 if (log)
713 log->Printf ("Target::%s\n", __FUNCTION__);
714
715 size_t num_watchpoints = m_watchpoint_list.GetSize();
716 for (size_t i = 0; i < num_watchpoints; ++i)
717 {
718 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
719 if (!wp_sp)
720 return false;
721
722 wp_sp->ResetHitCount();
723 }
724 return true; // Success!
725}
726
Johnny Chenecd4feb2011-10-14 00:42:25 +0000727// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000728// during these operations.
729bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000730Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000731{
732 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
733 if (log)
734 log->Printf ("Target::%s\n", __FUNCTION__);
735
736 if (!ProcessIsValid())
737 return false;
738
Johnny Chenecd4feb2011-10-14 00:42:25 +0000739 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000740 for (size_t i = 0; i < num_watchpoints; ++i)
741 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000742 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
743 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000744 return false;
745
Johnny Chenecd4feb2011-10-14 00:42:25 +0000746 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000747 }
748 return true; // Success!
749}
750
Johnny Chenecd4feb2011-10-14 00:42:25 +0000751// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000752bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000753Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000754{
755 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
756 if (log)
757 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
758
759 if (!ProcessIsValid())
760 return false;
761
Johnny Chenecd4feb2011-10-14 00:42:25 +0000762 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
763 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000764 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000765 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000766 if (rc.Success())
767 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000768
Johnny Chen01acfa72011-09-22 18:04:58 +0000769 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000770 }
771 return false;
772}
773
Johnny Chenecd4feb2011-10-14 00:42:25 +0000774// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000775bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000776Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000777{
778 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
779 if (log)
780 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
781
782 if (!ProcessIsValid())
783 return false;
784
Johnny Chenecd4feb2011-10-14 00:42:25 +0000785 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
786 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000787 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000788 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000789 if (rc.Success())
790 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000791
Johnny Chen01acfa72011-09-22 18:04:58 +0000792 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000793 }
794 return false;
795}
796
Johnny Chenecd4feb2011-10-14 00:42:25 +0000797// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000798bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000799Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000800{
801 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
802 if (log)
803 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
804
Johnny Chenecd4feb2011-10-14 00:42:25 +0000805 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000806 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000807 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000808 return true;
809 }
810 return false;
811}
812
Johnny Chenecd4feb2011-10-14 00:42:25 +0000813// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000814bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000815Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000816{
817 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
818 if (log)
819 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
820
821 if (!ProcessIsValid())
822 return false;
823
Johnny Chenecd4feb2011-10-14 00:42:25 +0000824 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
825 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000826 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000827 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000828 return true;
829 }
830 return false;
831}
832
Chris Lattner24943d22010-06-08 16:52:24 +0000833ModuleSP
834Target::GetExecutableModule ()
835{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000836 return m_images.GetModuleAtIndex(0);
837}
838
839Module*
840Target::GetExecutableModulePointer ()
841{
842 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000843}
844
845void
846Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
847{
848 m_images.Clear();
849 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000850 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000851 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000852
853 if (executable_sp.get())
854 {
855 Timer scoped_timer (__PRETTY_FUNCTION__,
856 "Target::SetExecutableModule (executable = '%s/%s')",
857 executable_sp->GetFileSpec().GetDirectory().AsCString(),
858 executable_sp->GetFileSpec().GetFilename().AsCString());
859
860 m_images.Append(executable_sp); // The first image is our exectuable file
861
Jim Ingham7508e732010-08-09 23:31:02 +0000862 // 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 +0000863 if (!m_arch.IsValid())
864 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000865
Chris Lattner24943d22010-06-08 16:52:24 +0000866 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000867 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000868
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000869 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +0000870 {
871 executable_objfile->GetDependentModules(dependent_files);
872 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
873 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000874 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
875 FileSpec platform_dependent_file_spec;
876 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000877 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000878 else
879 platform_dependent_file_spec = dependent_file_spec;
880
Greg Clayton444fe992012-02-26 05:51:37 +0000881 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
882 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +0000883 if (image_module_sp.get())
884 {
Chris Lattner24943d22010-06-08 16:52:24 +0000885 ObjectFile *objfile = image_module_sp->GetObjectFile();
886 if (objfile)
887 objfile->GetDependentModules(dependent_files);
888 }
889 }
890 }
Chris Lattner24943d22010-06-08 16:52:24 +0000891 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000892
893 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000894}
895
896
Jim Ingham7508e732010-08-09 23:31:02 +0000897bool
898Target::SetArchitecture (const ArchSpec &arch_spec)
899{
Greg Clayton24bc5d92011-03-30 18:16:51 +0000900 if (m_arch == arch_spec)
Jim Ingham7508e732010-08-09 23:31:02 +0000901 {
902 // If we're setting the architecture to our current architecture, we
903 // don't need to do anything.
904 return true;
905 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000906 else if (!m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000907 {
908 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000909 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000910 return true;
911 }
912 else
913 {
914 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000915 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000916 ModuleSP executable_sp = GetExecutableModule ();
917 m_images.Clear();
918 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000919 m_scratch_ast_source_ap.reset();
920 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000921 // Need to do something about unsetting breakpoints.
922
923 if (executable_sp)
924 {
Greg Clayton444fe992012-02-26 05:51:37 +0000925 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
926 Error error = ModuleList::GetSharedModule (module_spec,
927 executable_sp,
928 &GetExecutableSearchPaths(),
929 NULL,
930 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +0000931
932 if (!error.Fail() && executable_sp)
933 {
934 SetExecutableModule (executable_sp, true);
935 return true;
936 }
937 else
938 {
939 return false;
940 }
941 }
942 else
943 {
944 return false;
945 }
946 }
947}
Chris Lattner24943d22010-06-08 16:52:24 +0000948
Chris Lattner24943d22010-06-08 16:52:24 +0000949void
950Target::ModuleAdded (ModuleSP &module_sp)
951{
952 // A module is being added to this target for the first time
953 ModuleList module_list;
954 module_list.Append(module_sp);
955 ModulesDidLoad (module_list);
956}
957
958void
959Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
960{
Jim Ingham3b8a6052011-08-03 01:00:06 +0000961 // A module is replacing an already added module
Chris Lattner24943d22010-06-08 16:52:24 +0000962 ModuleList module_list;
963 module_list.Append (old_module_sp);
964 ModulesDidUnload (module_list);
965 module_list.Clear ();
966 module_list.Append (new_module_sp);
967 ModulesDidLoad (module_list);
968}
969
970void
971Target::ModulesDidLoad (ModuleList &module_list)
972{
973 m_breakpoint_list.UpdateBreakpoints (module_list, true);
974 // TODO: make event data that packages up the module_list
975 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
976}
977
978void
979Target::ModulesDidUnload (ModuleList &module_list)
980{
981 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000982
983 // Remove the images from the target image list
984 m_images.Remove(module_list);
985
Chris Lattner24943d22010-06-08 16:52:24 +0000986 // TODO: make event data that packages up the module_list
987 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
988}
989
Jim Ingham7089d8a2011-10-28 23:14:11 +0000990
Daniel Dunbar705a0982011-10-31 22:50:37 +0000991bool
Greg Clayton444fe992012-02-26 05:51:37 +0000992Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +0000993{
994
995 if (!m_breakpoints_use_platform_avoid)
996 return false;
997 else
998 {
999 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +00001000 ModuleSpec module_spec (module_file_spec);
1001 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001002
1003 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1004 // black list.
1005 if (num_modules > 0)
1006 {
1007 for (int i = 0; i < num_modules; i++)
1008 {
1009 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1010 return false;
1011 }
1012 return true;
1013 }
1014 else
1015 return false;
1016 }
1017}
1018
Daniel Dunbar705a0982011-10-31 22:50:37 +00001019bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001020Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1021{
1022 if (!m_breakpoints_use_platform_avoid)
1023 return false;
1024 else if (GetPlatform())
1025 {
1026 return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
1027 }
1028 else
1029 return false;
1030}
1031
Chris Lattner24943d22010-06-08 16:52:24 +00001032size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001033Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1034{
Greg Clayton3508c382012-02-24 01:59:29 +00001035 SectionSP section_sp (addr.GetSection());
1036 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001037 {
Greg Clayton3508c382012-02-24 01:59:29 +00001038 ModuleSP module_sp (section_sp->GetModule());
1039 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001040 {
Greg Clayton3508c382012-02-24 01:59:29 +00001041 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1042 if (objfile)
1043 {
1044 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1045 addr.GetOffset(),
1046 dst,
1047 dst_len);
1048 if (bytes_read > 0)
1049 return bytes_read;
1050 else
1051 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1052 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001053 else
Greg Clayton3508c382012-02-24 01:59:29 +00001054 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001055 }
1056 else
Greg Clayton3508c382012-02-24 01:59:29 +00001057 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001058 }
1059 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001060 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001061
Greg Clayton26100dc2011-01-07 01:57:07 +00001062 return 0;
1063}
1064
1065size_t
Enrico Granata91544802011-09-06 19:20:51 +00001066Target::ReadMemory (const Address& addr,
1067 bool prefer_file_cache,
1068 void *dst,
1069 size_t dst_len,
1070 Error &error,
1071 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001072{
Chris Lattner24943d22010-06-08 16:52:24 +00001073 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001074
Enrico Granata91544802011-09-06 19:20:51 +00001075 // if we end up reading this from process memory, we will fill this
1076 // with the actual load address
1077 if (load_addr_ptr)
1078 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1079
Greg Clayton26100dc2011-01-07 01:57:07 +00001080 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001081
1082 addr_t load_addr = LLDB_INVALID_ADDRESS;
1083 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001084 Address resolved_addr;
1085 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001086 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001087 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001088 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001089 // No sections are loaded, so we must assume we are not running
1090 // yet and anything we are given is a file address.
1091 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1092 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001093 }
Greg Clayton70436352010-06-30 23:03:03 +00001094 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001095 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001096 // We have at least one section loaded. This can be becuase
1097 // we have manually loaded some sections with "target modules load ..."
1098 // or because we have have a live process that has sections loaded
1099 // through the dynamic loader
1100 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1101 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001102 }
Greg Clayton70436352010-06-30 23:03:03 +00001103 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001104 if (!resolved_addr.IsValid())
1105 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001106
Greg Clayton9b82f862011-07-11 05:12:02 +00001107
Greg Clayton26100dc2011-01-07 01:57:07 +00001108 if (prefer_file_cache)
1109 {
1110 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1111 if (bytes_read > 0)
1112 return bytes_read;
1113 }
Greg Clayton70436352010-06-30 23:03:03 +00001114
Johnny Chenda5a8022011-09-20 23:28:55 +00001115 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001116 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001117 if (load_addr == LLDB_INVALID_ADDRESS)
1118 load_addr = resolved_addr.GetLoadAddress (this);
1119
Greg Clayton70436352010-06-30 23:03:03 +00001120 if (load_addr == LLDB_INVALID_ADDRESS)
1121 {
Greg Clayton3508c382012-02-24 01:59:29 +00001122 ModuleSP addr_module_sp (resolved_addr.GetModule());
1123 if (addr_module_sp && addr_module_sp->GetFileSpec())
Greg Clayton9c236732011-10-26 00:56:27 +00001124 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001125 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001126 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001127 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001128 else
Greg Clayton9c236732011-10-26 00:56:27 +00001129 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001130 }
1131 else
1132 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001133 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001134 if (bytes_read != dst_len)
1135 {
1136 if (error.Success())
1137 {
1138 if (bytes_read == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00001139 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001140 else
Greg Clayton9c236732011-10-26 00:56:27 +00001141 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 +00001142 }
1143 }
Greg Clayton70436352010-06-30 23:03:03 +00001144 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001145 {
1146 if (load_addr_ptr)
1147 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001148 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001149 }
Greg Clayton70436352010-06-30 23:03:03 +00001150 // If the address is not section offset we have an address that
1151 // doesn't resolve to any address in any currently loaded shared
1152 // libaries and we failed to read memory so there isn't anything
1153 // more we can do. If it is section offset, we might be able to
1154 // read cached memory from the object file.
1155 if (!resolved_addr.IsSectionOffset())
1156 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001157 }
Chris Lattner24943d22010-06-08 16:52:24 +00001158 }
Greg Clayton70436352010-06-30 23:03:03 +00001159
Greg Clayton9b82f862011-07-11 05:12:02 +00001160 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001161 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001162 // If we didn't already try and read from the object file cache, then
1163 // try it after failing to read from the process.
1164 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001165 }
1166 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001167}
1168
Greg Clayton7dd98df2011-07-12 17:06:17 +00001169size_t
1170Target::ReadScalarIntegerFromMemory (const Address& addr,
1171 bool prefer_file_cache,
1172 uint32_t byte_size,
1173 bool is_signed,
1174 Scalar &scalar,
1175 Error &error)
1176{
1177 uint64_t uval;
1178
1179 if (byte_size <= sizeof(uval))
1180 {
1181 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1182 if (bytes_read == byte_size)
1183 {
1184 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1185 uint32_t offset = 0;
1186 if (byte_size <= 4)
1187 scalar = data.GetMaxU32 (&offset, byte_size);
1188 else
1189 scalar = data.GetMaxU64 (&offset, byte_size);
1190
1191 if (is_signed)
1192 scalar.SignExtend(byte_size * 8);
1193 return bytes_read;
1194 }
1195 }
1196 else
1197 {
1198 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1199 }
1200 return 0;
1201}
1202
1203uint64_t
1204Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1205 bool prefer_file_cache,
1206 size_t integer_byte_size,
1207 uint64_t fail_value,
1208 Error &error)
1209{
1210 Scalar scalar;
1211 if (ReadScalarIntegerFromMemory (addr,
1212 prefer_file_cache,
1213 integer_byte_size,
1214 false,
1215 scalar,
1216 error))
1217 return scalar.ULongLong(fail_value);
1218 return fail_value;
1219}
1220
1221bool
1222Target::ReadPointerFromMemory (const Address& addr,
1223 bool prefer_file_cache,
1224 Error &error,
1225 Address &pointer_addr)
1226{
1227 Scalar scalar;
1228 if (ReadScalarIntegerFromMemory (addr,
1229 prefer_file_cache,
1230 m_arch.GetAddressByteSize(),
1231 false,
1232 scalar,
1233 error))
1234 {
1235 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1236 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1237 {
1238 if (m_section_load_list.IsEmpty())
1239 {
1240 // No sections are loaded, so we must assume we are not running
1241 // yet and anything we are given is a file address.
1242 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1243 }
1244 else
1245 {
1246 // We have at least one section loaded. This can be becuase
1247 // we have manually loaded some sections with "target modules load ..."
1248 // or because we have have a live process that has sections loaded
1249 // through the dynamic loader
1250 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1251 }
1252 // We weren't able to resolve the pointer value, so just return
1253 // an address with no section
1254 if (!pointer_addr.IsValid())
1255 pointer_addr.SetOffset (pointer_vm_addr);
1256 return true;
1257
1258 }
1259 }
1260 return false;
1261}
Chris Lattner24943d22010-06-08 16:52:24 +00001262
1263ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001264Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001265{
1266 // Don't pass in the UUID so we can tell if we have a stale value in our list
1267 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1268 bool did_create_module = false;
1269 ModuleSP module_sp;
1270
Chris Lattner24943d22010-06-08 16:52:24 +00001271 Error error;
1272
Greg Clayton24bc5d92011-03-30 18:16:51 +00001273 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +00001274 if (m_image_search_paths.GetSize())
1275 {
Greg Clayton444fe992012-02-26 05:51:37 +00001276 ModuleSpec transformed_spec (module_spec);
1277 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
Chris Lattner24943d22010-06-08 16:52:24 +00001278 {
Greg Clayton444fe992012-02-26 05:51:37 +00001279 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
Greg Clayton9ce95382012-02-13 23:10:39 +00001280 error = ModuleList::GetSharedModule (transformed_spec,
Greg Clayton9ce95382012-02-13 23:10:39 +00001281 module_sp,
1282 &GetExecutableSearchPaths(),
1283 &old_module_sp,
1284 &did_create_module);
Chris Lattner24943d22010-06-08 16:52:24 +00001285 }
1286 }
1287
Greg Clayton24bc5d92011-03-30 18:16:51 +00001288 // The platform is responsible for finding and caching an appropriate
1289 // module in the shared module cache.
1290 if (m_platform_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001291 {
Greg Clayton24bc5d92011-03-30 18:16:51 +00001292 FileSpec platform_file_spec;
Greg Clayton444fe992012-02-26 05:51:37 +00001293 error = m_platform_sp->GetSharedModule (module_spec,
Greg Clayton24bc5d92011-03-30 18:16:51 +00001294 module_sp,
Greg Clayton9ce95382012-02-13 23:10:39 +00001295 &GetExecutableSearchPaths(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001296 &old_module_sp,
1297 &did_create_module);
1298 }
1299 else
1300 {
1301 error.SetErrorString("no platform is currently set");
Chris Lattner24943d22010-06-08 16:52:24 +00001302 }
1303
Greg Clayton24bc5d92011-03-30 18:16:51 +00001304 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +00001305 if (module_sp)
1306 {
1307 m_images.Append (module_sp);
1308 if (did_create_module)
1309 {
1310 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1311 ModuleUpdated(old_module_sp, module_sp);
1312 else
1313 ModuleAdded(module_sp);
1314 }
1315 }
1316 if (error_ptr)
1317 *error_ptr = error;
1318 return module_sp;
1319}
1320
1321
Greg Clayton289afcb2012-02-18 05:35:26 +00001322TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001323Target::CalculateTarget ()
1324{
Greg Clayton289afcb2012-02-18 05:35:26 +00001325 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001326}
1327
Greg Clayton289afcb2012-02-18 05:35:26 +00001328ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001329Target::CalculateProcess ()
1330{
Greg Clayton289afcb2012-02-18 05:35:26 +00001331 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001332}
1333
Greg Clayton289afcb2012-02-18 05:35:26 +00001334ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001335Target::CalculateThread ()
1336{
Greg Clayton289afcb2012-02-18 05:35:26 +00001337 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001338}
1339
Greg Clayton289afcb2012-02-18 05:35:26 +00001340StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001341Target::CalculateStackFrame ()
1342{
Greg Clayton289afcb2012-02-18 05:35:26 +00001343 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001344}
1345
1346void
Greg Claytona830adb2010-10-04 01:05:56 +00001347Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001348{
Greg Clayton567e7f32011-09-22 04:58:26 +00001349 exe_ctx.Clear();
1350 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001351}
1352
1353PathMappingList &
1354Target::GetImageSearchPathList ()
1355{
1356 return m_image_search_paths;
1357}
1358
1359void
1360Target::ImageSearchPathsChanged
1361(
1362 const PathMappingList &path_list,
1363 void *baton
1364)
1365{
1366 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001367 ModuleSP exe_module_sp (target->GetExecutableModule());
1368 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001369 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001370 target->m_images.Clear();
1371 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001372 }
1373}
1374
1375ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001376Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001377{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001378 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001379 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001380 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001381 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001382 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001383 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1384 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1385 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1386 }
Chris Lattner24943d22010-06-08 16:52:24 +00001387 return m_scratch_ast_context_ap.get();
1388}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001389
Sean Callanan4938bd62011-11-16 18:20:47 +00001390ClangASTImporter *
1391Target::GetClangASTImporter()
1392{
1393 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1394
1395 if (!ast_importer)
1396 {
1397 ast_importer = new ClangASTImporter();
1398 m_ast_importer_ap.reset(ast_importer);
1399 }
1400
1401 return ast_importer;
1402}
1403
Greg Clayton990de7b2010-11-18 23:32:35 +00001404void
Caroline Tice2a456812011-03-10 22:14:10 +00001405Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001406{
Greg Clayton334d33a2012-01-30 07:41:31 +00001407 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001408 SettingsController::global_settings_table,
1409 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001410
1411 // Now call SettingsInitialize() on each 'child' setting of Target
1412 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001413}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001414
Greg Clayton990de7b2010-11-18 23:32:35 +00001415void
Caroline Tice2a456812011-03-10 22:14:10 +00001416Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001417{
Caroline Tice2a456812011-03-10 22:14:10 +00001418
1419 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1420
1421 Process::SettingsTerminate ();
1422
1423 // Now terminate Target Settings.
1424
Greg Clayton990de7b2010-11-18 23:32:35 +00001425 UserSettingsControllerSP &usc = GetSettingsController();
1426 UserSettingsController::FinalizeSettingsController (usc);
1427 usc.reset();
1428}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001429
Greg Clayton990de7b2010-11-18 23:32:35 +00001430UserSettingsControllerSP &
1431Target::GetSettingsController ()
1432{
Greg Clayton334d33a2012-01-30 07:41:31 +00001433 static UserSettingsControllerSP g_settings_controller_sp;
1434 if (!g_settings_controller_sp)
1435 {
1436 g_settings_controller_sp.reset (new Target::SettingsController);
1437 // The first shared pointer to Target::SettingsController in
1438 // g_settings_controller_sp must be fully created above so that
1439 // the TargetInstanceSettings can use a weak_ptr to refer back
1440 // to the master setttings controller
1441 InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp,
1442 false,
1443 InstanceSettings::GetDefaultName().AsCString()));
1444 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1445 }
1446 return g_settings_controller_sp;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001447}
1448
Greg Clayton9ce95382012-02-13 23:10:39 +00001449FileSpecList
1450Target::GetDefaultExecutableSearchPaths ()
1451{
1452 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1453 if (settings_controller_sp)
1454 {
1455 lldb::InstanceSettingsSP instance_settings_sp (settings_controller_sp->GetDefaultInstanceSettings ());
1456 if (instance_settings_sp)
1457 return static_cast<TargetInstanceSettings *>(instance_settings_sp.get())->GetExecutableSearchPaths ();
1458 }
1459 return FileSpecList();
1460}
1461
1462
Caroline Tice5bc8c972010-09-20 20:44:43 +00001463ArchSpec
1464Target::GetDefaultArchitecture ()
1465{
Greg Clayton940b1032011-02-23 00:35:02 +00001466 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1467
1468 if (settings_controller_sp)
1469 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1470 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001471}
1472
1473void
Greg Clayton940b1032011-02-23 00:35:02 +00001474Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001475{
Greg Clayton940b1032011-02-23 00:35:02 +00001476 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1477
1478 if (settings_controller_sp)
1479 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001480}
1481
Greg Claytona830adb2010-10-04 01:05:56 +00001482Target *
1483Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1484{
1485 // The target can either exist in the "process" of ExecutionContext, or in
1486 // the "target_sp" member of SymbolContext. This accessor helper function
1487 // will get the target from one of these locations.
1488
1489 Target *target = NULL;
1490 if (sc_ptr != NULL)
1491 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001492 if (target == NULL && exe_ctx_ptr)
1493 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001494 return target;
1495}
1496
1497
Caroline Tice1ebef442010-09-27 00:30:10 +00001498void
1499Target::UpdateInstanceName ()
1500{
1501 StreamString sstr;
1502
Greg Clayton5beb99d2011-08-11 02:48:45 +00001503 Module *exe_module = GetExecutableModulePointer();
1504 if (exe_module)
Caroline Tice1ebef442010-09-27 00:30:10 +00001505 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001506 sstr.Printf ("%s_%s",
Greg Clayton5beb99d2011-08-11 02:48:45 +00001507 exe_module->GetFileSpec().GetFilename().AsCString(),
1508 exe_module->GetArchitecture().GetArchitectureName());
1509 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +00001510 }
1511}
1512
Sean Callanan77e93942010-10-29 00:29:03 +00001513const char *
1514Target::GetExpressionPrefixContentsAsCString ()
1515{
Sean Callanane0b7f942011-11-16 01:54:57 +00001516 if (!m_expr_prefix_contents.empty())
1517 return m_expr_prefix_contents.c_str();
Greg Claytonff44ab42011-04-23 02:04:55 +00001518 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001519}
1520
Greg Clayton427f2902010-12-14 02:59:59 +00001521ExecutionResults
1522Target::EvaluateExpression
1523(
1524 const char *expr_cstr,
1525 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001526 lldb_private::ExecutionPolicy execution_policy,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001527 bool coerce_to_id,
Greg Clayton427f2902010-12-14 02:59:59 +00001528 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001529 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001530 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +00001531 lldb::ValueObjectSP &result_valobj_sp
1532)
1533{
1534 ExecutionResults execution_results = eExecutionSetupError;
1535
1536 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001537
1538 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1539 return execution_results;
1540
Jim Ingham3613ae12011-05-12 02:06:14 +00001541 // We shouldn't run stop hooks in expressions.
1542 // Be sure to reset this if you return anywhere within this function.
1543 bool old_suppress_value = m_suppress_stop_hooks;
1544 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001545
1546 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001547
1548 const size_t expr_cstr_len = ::strlen (expr_cstr);
1549
Greg Clayton427f2902010-12-14 02:59:59 +00001550 if (frame)
1551 {
1552 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001553 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001554 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001555 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1556 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001557 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001558
1559 // Make sure we don't have any things that we know a variable expression
1560 // won't be able to deal with before calling into it
1561 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1562 {
1563 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1564 use_dynamic,
1565 expr_path_options,
1566 var_sp,
1567 error);
1568 }
Greg Clayton427f2902010-12-14 02:59:59 +00001569 }
1570 else if (m_process_sp)
1571 {
1572 m_process_sp->CalculateExecutionContext(exe_ctx);
1573 }
1574 else
1575 {
1576 CalculateExecutionContext(exe_ctx);
1577 }
1578
1579 if (result_valobj_sp)
1580 {
1581 execution_results = eExecutionCompleted;
1582 // We got a result from the frame variable expression path above...
1583 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1584
1585 lldb::ValueObjectSP const_valobj_sp;
1586
1587 // Check in case our value is already a constant value
1588 if (result_valobj_sp->GetIsConstant())
1589 {
1590 const_valobj_sp = result_valobj_sp;
1591 const_valobj_sp->SetName (persistent_variable_name);
1592 }
1593 else
Jim Inghame41494a2011-04-16 00:01:13 +00001594 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001595 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001596 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001597 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001598 if (dynamic_sp)
1599 result_valobj_sp = dynamic_sp;
1600 }
1601
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001602 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001603 }
Greg Clayton427f2902010-12-14 02:59:59 +00001604
Sean Callanan6a925532011-01-13 08:53:35 +00001605 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1606
Greg Clayton427f2902010-12-14 02:59:59 +00001607 result_valobj_sp = const_valobj_sp;
1608
Sean Callanan6a925532011-01-13 08:53:35 +00001609 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1610 assert (clang_expr_variable_sp.get());
1611
1612 // Set flags and live data as appropriate
1613
1614 const Value &result_value = live_valobj_sp->GetValue();
1615
1616 switch (result_value.GetValueType())
1617 {
1618 case Value::eValueTypeHostAddress:
1619 case Value::eValueTypeFileAddress:
1620 // we don't do anything with these for now
1621 break;
1622 case Value::eValueTypeScalar:
1623 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1624 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1625 break;
1626 case Value::eValueTypeLoadAddress:
1627 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1628 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1629 break;
1630 }
Greg Clayton427f2902010-12-14 02:59:59 +00001631 }
1632 else
1633 {
1634 // Make sure we aren't just trying to see the value of a persistent
1635 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001636 lldb::ClangExpressionVariableSP persistent_var_sp;
1637 // Only check for persistent variables the expression starts with a '$'
1638 if (expr_cstr[0] == '$')
1639 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1640
Greg Clayton427f2902010-12-14 02:59:59 +00001641 if (persistent_var_sp)
1642 {
1643 result_valobj_sp = persistent_var_sp->GetValueObject ();
1644 execution_results = eExecutionCompleted;
1645 }
1646 else
1647 {
1648 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001649
Greg Clayton427f2902010-12-14 02:59:59 +00001650 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001651 execution_policy,
Sean Callanan5b658cc2011-11-07 23:35:40 +00001652 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001653 coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
Sean Callanan6a925532011-01-13 08:53:35 +00001654 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001655 expr_cstr,
1656 prefix,
1657 result_valobj_sp);
1658 }
1659 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001660
1661 m_suppress_stop_hooks = old_suppress_value;
1662
Greg Clayton427f2902010-12-14 02:59:59 +00001663 return execution_results;
1664}
1665
Greg Claytonc0fa5332011-05-22 22:46:53 +00001666lldb::addr_t
1667Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1668{
1669 addr_t code_addr = load_addr;
1670 switch (m_arch.GetMachine())
1671 {
1672 case llvm::Triple::arm:
1673 case llvm::Triple::thumb:
1674 switch (addr_class)
1675 {
1676 case eAddressClassData:
1677 case eAddressClassDebug:
1678 return LLDB_INVALID_ADDRESS;
1679
1680 case eAddressClassUnknown:
1681 case eAddressClassInvalid:
1682 case eAddressClassCode:
1683 case eAddressClassCodeAlternateISA:
1684 case eAddressClassRuntime:
1685 // Check if bit zero it no set?
1686 if ((code_addr & 1ull) == 0)
1687 {
1688 // Bit zero isn't set, check if the address is a multiple of 2?
1689 if (code_addr & 2ull)
1690 {
1691 // The address is a multiple of 2 so it must be thumb, set bit zero
1692 code_addr |= 1ull;
1693 }
1694 else if (addr_class == eAddressClassCodeAlternateISA)
1695 {
1696 // We checked the address and the address claims to be the alternate ISA
1697 // which means thumb, so set bit zero.
1698 code_addr |= 1ull;
1699 }
1700 }
1701 break;
1702 }
1703 break;
1704
1705 default:
1706 break;
1707 }
1708 return code_addr;
1709}
1710
1711lldb::addr_t
1712Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1713{
1714 addr_t opcode_addr = load_addr;
1715 switch (m_arch.GetMachine())
1716 {
1717 case llvm::Triple::arm:
1718 case llvm::Triple::thumb:
1719 switch (addr_class)
1720 {
1721 case eAddressClassData:
1722 case eAddressClassDebug:
1723 return LLDB_INVALID_ADDRESS;
1724
1725 case eAddressClassInvalid:
1726 case eAddressClassUnknown:
1727 case eAddressClassCode:
1728 case eAddressClassCodeAlternateISA:
1729 case eAddressClassRuntime:
1730 opcode_addr &= ~(1ull);
1731 break;
1732 }
1733 break;
1734
1735 default:
1736 break;
1737 }
1738 return opcode_addr;
1739}
1740
Jim Inghamd60d94a2011-03-11 03:53:59 +00001741lldb::user_id_t
1742Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1743{
1744 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001745 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001746 m_stop_hooks[new_uid] = new_hook_sp;
1747 return new_uid;
1748}
1749
1750bool
1751Target::RemoveStopHookByID (lldb::user_id_t user_id)
1752{
1753 size_t num_removed;
1754 num_removed = m_stop_hooks.erase (user_id);
1755 if (num_removed == 0)
1756 return false;
1757 else
1758 return true;
1759}
1760
1761void
1762Target::RemoveAllStopHooks ()
1763{
1764 m_stop_hooks.clear();
1765}
1766
1767Target::StopHookSP
1768Target::GetStopHookByID (lldb::user_id_t user_id)
1769{
1770 StopHookSP found_hook;
1771
1772 StopHookCollection::iterator specified_hook_iter;
1773 specified_hook_iter = m_stop_hooks.find (user_id);
1774 if (specified_hook_iter != m_stop_hooks.end())
1775 found_hook = (*specified_hook_iter).second;
1776 return found_hook;
1777}
1778
1779bool
1780Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1781{
1782 StopHookCollection::iterator specified_hook_iter;
1783 specified_hook_iter = m_stop_hooks.find (user_id);
1784 if (specified_hook_iter == m_stop_hooks.end())
1785 return false;
1786
1787 (*specified_hook_iter).second->SetIsActive (active_state);
1788 return true;
1789}
1790
1791void
1792Target::SetAllStopHooksActiveState (bool active_state)
1793{
1794 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1795 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1796 {
1797 (*pos).second->SetIsActive (active_state);
1798 }
1799}
1800
1801void
1802Target::RunStopHooks ()
1803{
Jim Ingham3613ae12011-05-12 02:06:14 +00001804 if (m_suppress_stop_hooks)
1805 return;
1806
Jim Inghamd60d94a2011-03-11 03:53:59 +00001807 if (!m_process_sp)
1808 return;
1809
1810 if (m_stop_hooks.empty())
1811 return;
1812
1813 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1814
1815 // If there aren't any active stop hooks, don't bother either:
1816 bool any_active_hooks = false;
1817 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1818 {
1819 if ((*pos).second->IsActive())
1820 {
1821 any_active_hooks = true;
1822 break;
1823 }
1824 }
1825 if (!any_active_hooks)
1826 return;
1827
1828 CommandReturnObject result;
1829
1830 std::vector<ExecutionContext> exc_ctx_with_reasons;
1831 std::vector<SymbolContext> sym_ctx_with_reasons;
1832
1833 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1834 size_t num_threads = cur_threadlist.GetSize();
1835 for (size_t i = 0; i < num_threads; i++)
1836 {
1837 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1838 if (cur_thread_sp->ThreadStoppedForAReason())
1839 {
1840 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1841 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1842 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1843 }
1844 }
1845
1846 // If no threads stopped for a reason, don't run the stop-hooks.
1847 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1848 if (num_exe_ctx == 0)
1849 return;
1850
Jim Inghame5ed8e92011-06-02 23:58:26 +00001851 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1852 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001853
1854 bool keep_going = true;
1855 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001856 bool print_hook_header;
1857 bool print_thread_header;
1858
1859 if (num_exe_ctx == 1)
1860 print_thread_header = false;
1861 else
1862 print_thread_header = true;
1863
1864 if (m_stop_hooks.size() == 1)
1865 print_hook_header = false;
1866 else
1867 print_hook_header = true;
1868
Jim Inghamd60d94a2011-03-11 03:53:59 +00001869 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1870 {
1871 // result.Clear();
1872 StopHookSP cur_hook_sp = (*pos).second;
1873 if (!cur_hook_sp->IsActive())
1874 continue;
1875
1876 bool any_thread_matched = false;
1877 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1878 {
1879 if ((cur_hook_sp->GetSpecifier () == NULL
1880 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1881 && (cur_hook_sp->GetThreadSpecifier() == NULL
Greg Clayton567e7f32011-09-22 04:58:26 +00001882 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001883 {
1884 if (!hooks_ran)
1885 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00001886 hooks_ran = true;
1887 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001888 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001889 {
Johnny Chen4d96a742011-10-24 23:01:06 +00001890 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
1891 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
1892 NULL);
1893 if (cmd)
1894 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
1895 else
1896 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001897 any_thread_matched = true;
1898 }
1899
Jim Inghamc54840c2011-03-22 01:47:27 +00001900 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00001901 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001902
1903 bool stop_on_continue = true;
1904 bool stop_on_error = true;
1905 bool echo_commands = false;
1906 bool print_results = true;
1907 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001908 &exc_ctx_with_reasons[i],
1909 stop_on_continue,
1910 stop_on_error,
1911 echo_commands,
1912 print_results,
1913 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001914
1915 // If the command started the target going again, we should bag out of
1916 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001917 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1918 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001919 {
Greg Clayton444e35b2011-10-19 18:09:39 +00001920 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001921 keep_going = false;
1922 }
1923 }
1924 }
1925 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00001926
Caroline Tice4a348082011-05-02 20:41:46 +00001927 result.GetImmediateOutputStream()->Flush();
1928 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001929}
1930
Greg Claytonbbea1332011-07-08 00:48:09 +00001931bool
1932Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1933{
1934 bool changed = false;
1935 if (module)
1936 {
1937 ObjectFile *object_file = module->GetObjectFile();
1938 if (object_file)
1939 {
1940 SectionList *section_list = object_file->GetSectionList ();
1941 if (section_list)
1942 {
1943 // All sections listed in the dyld image info structure will all
1944 // either be fixed up already, or they will all be off by a single
1945 // slide amount that is determined by finding the first segment
1946 // that is at file offset zero which also has bytes (a file size
1947 // that is greater than zero) in the object file.
1948
1949 // Determine the slide amount (if any)
1950 const size_t num_sections = section_list->GetSize();
1951 size_t sect_idx = 0;
1952 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1953 {
1954 // Iterate through the object file sections to find the
1955 // first section that starts of file offset zero and that
1956 // has bytes in the file...
1957 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1958 if (section)
1959 {
1960 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1961 changed = true;
1962 }
1963 }
1964 }
1965 }
1966 }
1967 return changed;
1968}
1969
1970
Jim Inghamd60d94a2011-03-11 03:53:59 +00001971//--------------------------------------------------------------
1972// class Target::StopHook
1973//--------------------------------------------------------------
1974
1975
1976Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1977 UserID (uid),
1978 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00001979 m_commands (),
1980 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001981 m_thread_spec_ap(NULL),
1982 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001983{
1984}
1985
1986Target::StopHook::StopHook (const StopHook &rhs) :
1987 UserID (rhs.GetID()),
1988 m_target_sp (rhs.m_target_sp),
1989 m_commands (rhs.m_commands),
1990 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001991 m_thread_spec_ap (NULL),
1992 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001993{
1994 if (rhs.m_thread_spec_ap.get() != NULL)
1995 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1996}
1997
1998
1999Target::StopHook::~StopHook ()
2000{
2001}
2002
2003void
2004Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2005{
2006 m_thread_spec_ap.reset (specifier);
2007}
2008
2009
2010void
2011Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2012{
2013 int indent_level = s->GetIndentLevel();
2014
2015 s->SetIndentLevel(indent_level + 2);
2016
Greg Clayton444e35b2011-10-19 18:09:39 +00002017 s->Printf ("Hook: %llu\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002018 if (m_active)
2019 s->Indent ("State: enabled\n");
2020 else
2021 s->Indent ("State: disabled\n");
2022
2023 if (m_specifier_sp)
2024 {
2025 s->Indent();
2026 s->PutCString ("Specifier:\n");
2027 s->SetIndentLevel (indent_level + 4);
2028 m_specifier_sp->GetDescription (s, level);
2029 s->SetIndentLevel (indent_level + 2);
2030 }
2031
2032 if (m_thread_spec_ap.get() != NULL)
2033 {
2034 StreamString tmp;
2035 s->Indent("Thread:\n");
2036 m_thread_spec_ap->GetDescription (&tmp, level);
2037 s->SetIndentLevel (indent_level + 4);
2038 s->Indent (tmp.GetData());
2039 s->PutCString ("\n");
2040 s->SetIndentLevel (indent_level + 2);
2041 }
2042
2043 s->Indent ("Commands: \n");
2044 s->SetIndentLevel (indent_level + 4);
2045 uint32_t num_commands = m_commands.GetSize();
2046 for (uint32_t i = 0; i < num_commands; i++)
2047 {
2048 s->Indent(m_commands.GetStringAtIndex(i));
2049 s->PutCString ("\n");
2050 }
2051 s->SetIndentLevel (indent_level);
2052}
2053
2054
Caroline Tice5bc8c972010-09-20 20:44:43 +00002055//--------------------------------------------------------------
2056// class Target::SettingsController
2057//--------------------------------------------------------------
2058
2059Target::SettingsController::SettingsController () :
2060 UserSettingsController ("target", Debugger::GetSettingsController()),
2061 m_default_architecture ()
2062{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002063}
2064
2065Target::SettingsController::~SettingsController ()
2066{
2067}
2068
2069lldb::InstanceSettingsSP
2070Target::SettingsController::CreateInstanceSettings (const char *instance_name)
2071{
Greg Clayton334d33a2012-01-30 07:41:31 +00002072 lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
2073 false,
2074 instance_name));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002075 return new_settings_sp;
2076}
2077
Caroline Tice5bc8c972010-09-20 20:44:43 +00002078
Greg Claytonabb33022011-11-08 02:43:13 +00002079#define TSC_DEFAULT_ARCH "default-arch"
2080#define TSC_EXPR_PREFIX "expr-prefix"
2081#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
2082#define TSC_SKIP_PROLOGUE "skip-prologue"
2083#define TSC_SOURCE_MAP "source-map"
Greg Clayton9ce95382012-02-13 23:10:39 +00002084#define TSC_EXE_SEARCH_PATHS "exec-search-paths"
Greg Claytonabb33022011-11-08 02:43:13 +00002085#define TSC_MAX_CHILDREN "max-children-count"
2086#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2087#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2088#define TSC_RUN_ARGS "run-args"
2089#define TSC_ENV_VARS "env-vars"
2090#define TSC_INHERIT_ENV "inherit-env"
2091#define TSC_STDIN_PATH "input-path"
2092#define TSC_STDOUT_PATH "output-path"
2093#define TSC_STDERR_PATH "error-path"
2094#define TSC_DISABLE_ASLR "disable-aslr"
2095#define TSC_DISABLE_STDIO "disable-stdio"
Greg Claytond284b662011-02-18 01:44:25 +00002096
2097
2098static const ConstString &
2099GetSettingNameForDefaultArch ()
2100{
2101 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00002102 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002103}
2104
Greg Claytond284b662011-02-18 01:44:25 +00002105static const ConstString &
2106GetSettingNameForExpressionPrefix ()
2107{
2108 static ConstString g_const_string (TSC_EXPR_PREFIX);
2109 return g_const_string;
2110}
2111
2112static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00002113GetSettingNameForPreferDynamicValue ()
2114{
2115 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2116 return g_const_string;
2117}
2118
Greg Claytonff44ab42011-04-23 02:04:55 +00002119static const ConstString &
2120GetSettingNameForSourcePathMap ()
2121{
2122 static ConstString g_const_string (TSC_SOURCE_MAP);
2123 return g_const_string;
2124}
Greg Claytond284b662011-02-18 01:44:25 +00002125
Greg Clayton17cd9952011-04-22 03:55:06 +00002126static const ConstString &
Greg Clayton9ce95382012-02-13 23:10:39 +00002127GetSettingNameForExecutableSearchPaths ()
2128{
2129 static ConstString g_const_string (TSC_EXE_SEARCH_PATHS);
2130 return g_const_string;
2131}
2132
2133static const ConstString &
Greg Clayton17cd9952011-04-22 03:55:06 +00002134GetSettingNameForSkipPrologue ()
2135{
2136 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2137 return g_const_string;
2138}
2139
Enrico Granata018921d2011-08-12 02:00:06 +00002140static const ConstString &
2141GetSettingNameForMaxChildren ()
2142{
2143 static ConstString g_const_string (TSC_MAX_CHILDREN);
2144 return g_const_string;
2145}
Greg Clayton17cd9952011-04-22 03:55:06 +00002146
Enrico Granata91544802011-09-06 19:20:51 +00002147static const ConstString &
2148GetSettingNameForMaxStringSummaryLength ()
2149{
2150 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2151 return g_const_string;
2152}
Greg Clayton17cd9952011-04-22 03:55:06 +00002153
Jim Ingham7089d8a2011-10-28 23:14:11 +00002154static const ConstString &
2155GetSettingNameForPlatformAvoid ()
2156{
2157 static ConstString g_const_string (TSC_PLATFORM_AVOID);
2158 return g_const_string;
2159}
2160
Greg Claytonabb33022011-11-08 02:43:13 +00002161const ConstString &
2162GetSettingNameForRunArgs ()
2163{
2164 static ConstString g_const_string (TSC_RUN_ARGS);
2165 return g_const_string;
2166}
2167
2168const ConstString &
2169GetSettingNameForEnvVars ()
2170{
2171 static ConstString g_const_string (TSC_ENV_VARS);
2172 return g_const_string;
2173}
2174
2175const ConstString &
2176GetSettingNameForInheritHostEnv ()
2177{
2178 static ConstString g_const_string (TSC_INHERIT_ENV);
2179 return g_const_string;
2180}
2181
2182const ConstString &
2183GetSettingNameForInputPath ()
2184{
2185 static ConstString g_const_string (TSC_STDIN_PATH);
2186 return g_const_string;
2187}
2188
2189const ConstString &
2190GetSettingNameForOutputPath ()
2191{
2192 static ConstString g_const_string (TSC_STDOUT_PATH);
2193 return g_const_string;
2194}
2195
2196const ConstString &
2197GetSettingNameForErrorPath ()
2198{
2199 static ConstString g_const_string (TSC_STDERR_PATH);
2200 return g_const_string;
2201}
2202
2203const ConstString &
2204GetSettingNameForDisableASLR ()
2205{
2206 static ConstString g_const_string (TSC_DISABLE_ASLR);
2207 return g_const_string;
2208}
2209
2210const ConstString &
2211GetSettingNameForDisableSTDIO ()
2212{
2213 static ConstString g_const_string (TSC_DISABLE_STDIO);
2214 return g_const_string;
2215}
Jim Ingham7089d8a2011-10-28 23:14:11 +00002216
Caroline Tice5bc8c972010-09-20 20:44:43 +00002217bool
2218Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2219 const char *index_value,
2220 const char *value,
2221 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002222 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002223 Error&err)
2224{
Greg Claytond284b662011-02-18 01:44:25 +00002225 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002226 {
Greg Claytonf15996e2011-04-07 22:46:35 +00002227 m_default_architecture.SetTriple (value, NULL);
Greg Clayton940b1032011-02-23 00:35:02 +00002228 if (!m_default_architecture.IsValid())
2229 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002230 }
2231 return true;
2232}
2233
2234
2235bool
2236Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2237 StringList &value,
2238 Error &err)
2239{
Greg Claytond284b662011-02-18 01:44:25 +00002240 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002241 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00002242 // If the arch is invalid (the default), don't show a string for it
2243 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00002244 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00002245 return true;
2246 }
2247 else
2248 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2249
2250 return false;
2251}
2252
2253//--------------------------------------------------------------
2254// class TargetInstanceSettings
2255//--------------------------------------------------------------
2256
Greg Clayton638351a2010-12-04 00:10:17 +00002257TargetInstanceSettings::TargetInstanceSettings
2258(
Greg Clayton334d33a2012-01-30 07:41:31 +00002259 const lldb::UserSettingsControllerSP &owner_sp,
Greg Clayton638351a2010-12-04 00:10:17 +00002260 bool live_instance,
2261 const char *name
2262) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002263 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00002264 m_expr_prefix_file (),
Sean Callanane0b7f942011-11-16 01:54:57 +00002265 m_expr_prefix_contents (),
Jim Ingham10de7d12011-05-04 03:43:18 +00002266 m_prefer_dynamic_value (2),
Greg Claytonff44ab42011-04-23 02:04:55 +00002267 m_skip_prologue (true, true),
Enrico Granata018921d2011-08-12 02:00:06 +00002268 m_source_map (NULL, NULL),
Greg Clayton9ce95382012-02-13 23:10:39 +00002269 m_exe_search_paths (),
Enrico Granata91544802011-09-06 19:20:51 +00002270 m_max_children_display(256),
Jim Ingham7089d8a2011-10-28 23:14:11 +00002271 m_max_strlen_length(1024),
Greg Claytonabb33022011-11-08 02:43:13 +00002272 m_breakpoints_use_platform_avoid (true, true),
2273 m_run_args (),
2274 m_env_vars (),
2275 m_input_path (),
2276 m_output_path (),
2277 m_error_path (),
2278 m_disable_aslr (true),
2279 m_disable_stdio (false),
2280 m_inherit_host_env (true),
2281 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002282{
2283 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2284 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2285 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2286 // This is true for CreateInstanceName() too.
2287
2288 if (GetInstanceName () == InstanceSettings::InvalidName())
2289 {
2290 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00002291 owner_sp->RegisterInstanceSettings (this);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002292 }
2293
2294 if (live_instance)
2295 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002296 const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002297 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002298 }
2299}
2300
2301TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002302 InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
Greg Claytonff44ab42011-04-23 02:04:55 +00002303 m_expr_prefix_file (rhs.m_expr_prefix_file),
Sean Callanane0b7f942011-11-16 01:54:57 +00002304 m_expr_prefix_contents (rhs.m_expr_prefix_contents),
Greg Claytonff44ab42011-04-23 02:04:55 +00002305 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
2306 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata018921d2011-08-12 02:00:06 +00002307 m_source_map (rhs.m_source_map),
Greg Clayton9ce95382012-02-13 23:10:39 +00002308 m_exe_search_paths (rhs.m_exe_search_paths),
Greg Claytonabb33022011-11-08 02:43:13 +00002309 m_max_children_display (rhs.m_max_children_display),
2310 m_max_strlen_length (rhs.m_max_strlen_length),
2311 m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2312 m_run_args (rhs.m_run_args),
2313 m_env_vars (rhs.m_env_vars),
2314 m_input_path (rhs.m_input_path),
2315 m_output_path (rhs.m_output_path),
2316 m_error_path (rhs.m_error_path),
2317 m_disable_aslr (rhs.m_disable_aslr),
2318 m_disable_stdio (rhs.m_disable_stdio),
2319 m_inherit_host_env (rhs.m_inherit_host_env)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002320{
2321 if (m_instance_name != InstanceSettings::GetDefaultName())
2322 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002323 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2324 if (owner_sp)
2325 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002326 }
2327}
2328
2329TargetInstanceSettings::~TargetInstanceSettings ()
2330{
2331}
2332
2333TargetInstanceSettings&
2334TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2335{
2336 if (this != &rhs)
2337 {
Greg Claytonabb33022011-11-08 02:43:13 +00002338 m_expr_prefix_file = rhs.m_expr_prefix_file;
Sean Callanane0b7f942011-11-16 01:54:57 +00002339 m_expr_prefix_contents = rhs.m_expr_prefix_contents;
Greg Claytonabb33022011-11-08 02:43:13 +00002340 m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
2341 m_skip_prologue = rhs.m_skip_prologue;
2342 m_source_map = rhs.m_source_map;
Greg Clayton9ce95382012-02-13 23:10:39 +00002343 m_exe_search_paths = rhs.m_exe_search_paths;
Greg Claytonabb33022011-11-08 02:43:13 +00002344 m_max_children_display = rhs.m_max_children_display;
2345 m_max_strlen_length = rhs.m_max_strlen_length;
2346 m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2347 m_run_args = rhs.m_run_args;
2348 m_env_vars = rhs.m_env_vars;
2349 m_input_path = rhs.m_input_path;
2350 m_output_path = rhs.m_output_path;
2351 m_error_path = rhs.m_error_path;
2352 m_disable_aslr = rhs.m_disable_aslr;
2353 m_disable_stdio = rhs.m_disable_stdio;
2354 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002355 }
2356
2357 return *this;
2358}
2359
Caroline Tice5bc8c972010-09-20 20:44:43 +00002360void
2361TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2362 const char *index_value,
2363 const char *value,
2364 const ConstString &instance_name,
2365 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002366 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002367 Error &err,
2368 bool pending)
2369{
Greg Claytond284b662011-02-18 01:44:25 +00002370 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002371 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002372 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2373 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00002374 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002375 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00002376 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002377 default:
2378 break;
2379 case eVarSetOperationAssign:
2380 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00002381 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002382 m_expr_prefix_contents.clear();
2383
Greg Claytonff44ab42011-04-23 02:04:55 +00002384 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2385 {
2386 err.SetErrorToGenericError ();
Greg Clayton9c236732011-10-26 00:56:27 +00002387 err.SetErrorStringWithFormat ("%s does not exist", value);
Greg Claytonff44ab42011-04-23 02:04:55 +00002388 return;
2389 }
2390
Greg Clayton4b23ab32012-01-06 02:01:06 +00002391 DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
Sean Callanane0b7f942011-11-16 01:54:57 +00002392
Greg Clayton4b23ab32012-01-06 02:01:06 +00002393 if (err.Success())
Greg Claytonff44ab42011-04-23 02:04:55 +00002394 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002395 if (file_data_sp && file_data_sp->GetByteSize() > 0)
2396 {
2397 m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
2398 }
2399 else
2400 {
2401 err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
2402 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002403 }
Sean Callanan77e93942010-10-29 00:29:03 +00002404 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002405 break;
2406 case eVarSetOperationClear:
Sean Callanane0b7f942011-11-16 01:54:57 +00002407 m_expr_prefix_contents.clear();
Sean Callanan77e93942010-10-29 00:29:03 +00002408 }
Sean Callanan77e93942010-10-29 00:29:03 +00002409 }
2410 }
Jim Inghame41494a2011-04-16 00:01:13 +00002411 else if (var_name == GetSettingNameForPreferDynamicValue())
2412 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002413 int new_value;
2414 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2415 if (err.Success())
2416 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00002417 }
2418 else if (var_name == GetSettingNameForSkipPrologue())
2419 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002420 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2421 }
Enrico Granata018921d2011-08-12 02:00:06 +00002422 else if (var_name == GetSettingNameForMaxChildren())
2423 {
2424 bool ok;
2425 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2426 if (ok)
2427 m_max_children_display = new_value;
2428 }
Enrico Granata91544802011-09-06 19:20:51 +00002429 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2430 {
2431 bool ok;
2432 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2433 if (ok)
2434 m_max_strlen_length = new_value;
2435 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002436 else if (var_name == GetSettingNameForExecutableSearchPaths())
2437 {
2438 switch (op)
2439 {
2440 case eVarSetOperationReplace:
2441 case eVarSetOperationInsertBefore:
2442 case eVarSetOperationInsertAfter:
2443 case eVarSetOperationRemove:
2444 default:
2445 break;
2446 case eVarSetOperationAssign:
2447 m_exe_search_paths.Clear();
2448 // Fall through to append....
2449 case eVarSetOperationAppend:
2450 {
2451 Args args(value);
2452 const uint32_t argc = args.GetArgumentCount();
2453 if (argc > 0)
2454 {
2455 const char *exe_search_path_dir;
2456 for (uint32_t idx = 0; (exe_search_path_dir = args.GetArgumentAtIndex(idx)) != NULL; ++idx)
2457 {
2458 FileSpec file_spec;
2459 file_spec.GetDirectory().SetCString(exe_search_path_dir);
2460 FileSpec::FileType file_type = file_spec.GetFileType();
2461 if (file_type == FileSpec::eFileTypeDirectory || file_type == FileSpec::eFileTypeInvalid)
2462 {
2463 m_exe_search_paths.Append(file_spec);
2464 }
2465 else
2466 {
2467 err.SetErrorStringWithFormat("executable search path '%s' exists, but it does not resolve to a directory", exe_search_path_dir);
2468 }
2469 }
2470 }
2471 }
2472 break;
2473
2474 case eVarSetOperationClear:
2475 m_exe_search_paths.Clear();
2476 break;
2477 }
2478 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002479 else if (var_name == GetSettingNameForSourcePathMap ())
2480 {
2481 switch (op)
2482 {
2483 case eVarSetOperationReplace:
2484 case eVarSetOperationInsertBefore:
2485 case eVarSetOperationInsertAfter:
2486 case eVarSetOperationRemove:
2487 default:
2488 break;
2489 case eVarSetOperationAssign:
2490 m_source_map.Clear(true);
2491 // Fall through to append....
2492 case eVarSetOperationAppend:
2493 {
2494 Args args(value);
2495 const uint32_t argc = args.GetArgumentCount();
2496 if (argc & 1 || argc == 0)
2497 {
2498 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2499 }
2500 else
2501 {
2502 char resolved_new_path[PATH_MAX];
2503 FileSpec file_spec;
2504 const char *old_path;
2505 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2506 {
2507 const char *new_path = args.GetArgumentAtIndex(idx+1);
2508 assert (new_path); // We have an even number of paths, this shouldn't happen!
2509
2510 file_spec.SetFile(new_path, true);
2511 if (file_spec.Exists())
2512 {
2513 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2514 {
2515 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2516 return;
2517 }
2518 }
2519 else
2520 {
2521 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2522 return;
2523 }
2524 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2525 }
2526 }
2527 }
2528 break;
2529
2530 case eVarSetOperationClear:
2531 m_source_map.Clear(true);
2532 break;
2533 }
Jim Inghame41494a2011-04-16 00:01:13 +00002534 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002535 else if (var_name == GetSettingNameForPlatformAvoid ())
2536 {
2537 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
2538 }
Greg Claytonabb33022011-11-08 02:43:13 +00002539 else if (var_name == GetSettingNameForRunArgs())
2540 {
2541 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2542 }
2543 else if (var_name == GetSettingNameForEnvVars())
2544 {
2545 // This is nice for local debugging, but it is isn't correct for
2546 // remote debugging. We need to stop process.env-vars from being
2547 // populated with the host environment and add this as a launch option
2548 // and get the correct environment from the Target's platform.
2549 // GetHostEnvironmentIfNeeded ();
2550 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
2551 }
2552 else if (var_name == GetSettingNameForInputPath())
2553 {
2554 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2555 }
2556 else if (var_name == GetSettingNameForOutputPath())
2557 {
2558 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2559 }
2560 else if (var_name == GetSettingNameForErrorPath())
2561 {
2562 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2563 }
2564 else if (var_name == GetSettingNameForDisableASLR())
2565 {
2566 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
2567 }
2568 else if (var_name == GetSettingNameForDisableSTDIO ())
2569 {
2570 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
2571 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002572}
2573
2574void
Greg Claytond284b662011-02-18 01:44:25 +00002575TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002576{
Sean Callanan77e93942010-10-29 00:29:03 +00002577 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2578
2579 if (!new_settings_ptr)
2580 return;
2581
Greg Claytonabb33022011-11-08 02:43:13 +00002582 *this = *new_settings_ptr;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002583}
2584
Caroline Ticebcb5b452010-09-20 21:37:42 +00002585bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00002586TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2587 const ConstString &var_name,
2588 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00002589 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002590{
Greg Claytond284b662011-02-18 01:44:25 +00002591 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002592 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002593 char path[PATH_MAX];
2594 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2595 if (path_len > 0)
2596 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00002597 }
Jim Inghame41494a2011-04-16 00:01:13 +00002598 else if (var_name == GetSettingNameForPreferDynamicValue())
2599 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002600 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00002601 }
Greg Clayton17cd9952011-04-22 03:55:06 +00002602 else if (var_name == GetSettingNameForSkipPrologue())
2603 {
2604 if (m_skip_prologue)
2605 value.AppendString ("true");
2606 else
2607 value.AppendString ("false");
2608 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002609 else if (var_name == GetSettingNameForExecutableSearchPaths())
2610 {
2611 if (m_exe_search_paths.GetSize())
2612 {
2613 for (size_t i = 0, n = m_exe_search_paths.GetSize(); i < n; ++i)
2614 {
2615 value.AppendString(m_exe_search_paths.GetFileSpecAtIndex (i).GetDirectory().AsCString());
2616 }
2617 }
2618 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002619 else if (var_name == GetSettingNameForSourcePathMap ())
2620 {
Johnny Chen931449e2011-12-12 21:59:28 +00002621 if (m_source_map.GetSize())
2622 {
2623 size_t i;
2624 for (i = 0; i < m_source_map.GetSize(); ++i) {
2625 StreamString sstr;
2626 m_source_map.Dump(&sstr, i);
2627 value.AppendString(sstr.GetData());
2628 }
2629 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002630 }
Enrico Granata018921d2011-08-12 02:00:06 +00002631 else if (var_name == GetSettingNameForMaxChildren())
2632 {
2633 StreamString count_str;
2634 count_str.Printf ("%d", m_max_children_display);
2635 value.AppendString (count_str.GetData());
2636 }
Enrico Granata91544802011-09-06 19:20:51 +00002637 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2638 {
2639 StreamString count_str;
2640 count_str.Printf ("%d", m_max_strlen_length);
2641 value.AppendString (count_str.GetData());
2642 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002643 else if (var_name == GetSettingNameForPlatformAvoid())
2644 {
2645 if (m_breakpoints_use_platform_avoid)
2646 value.AppendString ("true");
2647 else
2648 value.AppendString ("false");
2649 }
Greg Claytonabb33022011-11-08 02:43:13 +00002650 else if (var_name == GetSettingNameForRunArgs())
2651 {
2652 if (m_run_args.GetArgumentCount() > 0)
2653 {
2654 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2655 value.AppendString (m_run_args.GetArgumentAtIndex (i));
2656 }
2657 }
2658 else if (var_name == GetSettingNameForEnvVars())
2659 {
2660 GetHostEnvironmentIfNeeded ();
2661
2662 if (m_env_vars.size() > 0)
2663 {
2664 std::map<std::string, std::string>::iterator pos;
2665 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2666 {
2667 StreamString value_str;
2668 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2669 value.AppendString (value_str.GetData());
2670 }
2671 }
2672 }
2673 else if (var_name == GetSettingNameForInputPath())
2674 {
2675 value.AppendString (m_input_path.c_str());
2676 }
2677 else if (var_name == GetSettingNameForOutputPath())
2678 {
2679 value.AppendString (m_output_path.c_str());
2680 }
2681 else if (var_name == GetSettingNameForErrorPath())
2682 {
2683 value.AppendString (m_error_path.c_str());
2684 }
2685 else if (var_name == GetSettingNameForInheritHostEnv())
2686 {
2687 if (m_inherit_host_env)
2688 value.AppendString ("true");
2689 else
2690 value.AppendString ("false");
2691 }
2692 else if (var_name == GetSettingNameForDisableASLR())
2693 {
2694 if (m_disable_aslr)
2695 value.AppendString ("true");
2696 else
2697 value.AppendString ("false");
2698 }
2699 else if (var_name == GetSettingNameForDisableSTDIO())
2700 {
2701 if (m_disable_stdio)
2702 value.AppendString ("true");
2703 else
2704 value.AppendString ("false");
2705 }
Sean Callanan77e93942010-10-29 00:29:03 +00002706 else
2707 {
2708 if (err)
2709 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2710 return false;
2711 }
Sean Callanan77e93942010-10-29 00:29:03 +00002712 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002713}
2714
Greg Claytonabb33022011-11-08 02:43:13 +00002715void
2716Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
2717{
2718 if (m_inherit_host_env && !m_got_host_env)
2719 {
2720 m_got_host_env = true;
2721 StringList host_env;
2722 const size_t host_env_count = Host::GetEnvironment (host_env);
2723 for (size_t idx=0; idx<host_env_count; idx++)
2724 {
2725 const char *env_entry = host_env.GetStringAtIndex (idx);
2726 if (env_entry)
2727 {
2728 const char *equal_pos = ::strchr(env_entry, '=');
2729 if (equal_pos)
2730 {
2731 std::string key (env_entry, equal_pos - env_entry);
2732 std::string value (equal_pos + 1);
2733 if (m_env_vars.find (key) == m_env_vars.end())
2734 m_env_vars[key] = value;
2735 }
2736 }
2737 }
2738 }
2739}
2740
2741
2742size_t
2743Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
2744{
2745 GetHostEnvironmentIfNeeded ();
2746
2747 dictionary::const_iterator pos, end = m_env_vars.end();
2748 for (pos = m_env_vars.begin(); pos != end; ++pos)
2749 {
2750 std::string env_var_equal_value (pos->first);
2751 env_var_equal_value.append(1, '=');
2752 env_var_equal_value.append (pos->second);
2753 env.AppendArgument (env_var_equal_value.c_str());
2754 }
2755 return env.GetArgumentCount();
2756}
2757
2758
Caroline Tice5bc8c972010-09-20 20:44:43 +00002759const ConstString
2760TargetInstanceSettings::CreateInstanceName ()
2761{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002762 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00002763 static int instance_count = 1;
2764
Caroline Tice5bc8c972010-09-20 20:44:43 +00002765 sstr.Printf ("target_%d", instance_count);
2766 ++instance_count;
2767
2768 const ConstString ret_val (sstr.GetData());
2769 return ret_val;
2770}
2771
2772//--------------------------------------------------
2773// Target::SettingsController Variable Tables
2774//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00002775OptionEnumValueElement
2776TargetInstanceSettings::g_dynamic_value_types[] =
2777{
Greg Clayton577fbc32011-05-30 00:39:48 +00002778{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2779{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2780{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham10de7d12011-05-04 03:43:18 +00002781{ 0, NULL, NULL }
2782};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002783
2784SettingEntry
2785Target::SettingsController::global_settings_table[] =
2786{
Greg Claytond284b662011-02-18 01:44:25 +00002787 // var-name var-type default enum init'd hidden help-text
2788 // ================= ================== =========== ==== ====== ====== =========================================================================
2789 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2790 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2791};
2792
Caroline Tice5bc8c972010-09-20 20:44:43 +00002793SettingEntry
2794Target::SettingsController::instance_settings_table[] =
2795{
Enrico Granata91544802011-09-06 19:20:51 +00002796 // var-name var-type default enum init'd hidden help-text
2797 // ================= ================== =============== ======================= ====== ====== =========================================================================
2798 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2799 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2800 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2801 { 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 +00002802 { 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 +00002803 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2804 { 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 +00002805 { 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 +00002806 { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2807 { 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." },
2808 { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2809 { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
2810 { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
2811 { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
2812// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
2813 { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2814 { 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 +00002815 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002816};
Jim Ingham5a15e692012-02-16 06:50:00 +00002817
2818const ConstString &
2819Target::TargetEventData::GetFlavorString ()
2820{
2821 static ConstString g_flavor ("Target::TargetEventData");
2822 return g_flavor;
2823}
2824
2825const ConstString &
2826Target::TargetEventData::GetFlavor () const
2827{
2828 return TargetEventData::GetFlavorString ();
2829}
2830
2831Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2832 EventData(),
2833 m_target_sp (new_target_sp)
2834{
2835}
2836
2837Target::TargetEventData::~TargetEventData()
2838{
2839
2840}
2841
2842void
2843Target::TargetEventData::Dump (Stream *s) const
2844{
2845
2846}
2847
2848const TargetSP
2849Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2850{
2851 TargetSP target_sp;
2852
2853 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2854 if (data)
2855 target_sp = data->m_target_sp;
2856
2857 return target_sp;
2858}
2859
2860const Target::TargetEventData *
2861Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2862{
2863 if (event_ptr)
2864 {
2865 const EventData *event_data = event_ptr->GetData();
2866 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2867 return static_cast <const TargetEventData *> (event_ptr->GetData());
2868 }
2869 return NULL;
2870}
2871