blob: 6648d4c86be46aebb0b8ed4e700d9151f8fca339 [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 Ingham4722b102012-03-06 00:37:27 +0000290lldb::BreakpointSP
291Target::CreateBreakpoint (const FileSpecList *containingModules,
292 const FileSpecList *containingSourceFiles,
293 std::vector<std::string> func_names,
294 uint32_t func_name_type_mask,
295 bool internal,
296 LazyBool skip_prologue)
297{
298 BreakpointSP bp_sp;
299 size_t num_names = func_names.size();
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 func_name_type_mask,
307 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
308 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
309 }
310 return bp_sp;
311}
312
Jim Inghamc1053622012-03-03 02:05:11 +0000313BreakpointSP
314Target::CreateBreakpoint (const FileSpecList *containingModules,
315 const FileSpecList *containingSourceFiles,
316 const char *func_names[],
317 size_t num_names,
318 uint32_t func_name_type_mask,
319 bool internal,
320 LazyBool skip_prologue)
321{
322 BreakpointSP bp_sp;
323 if (num_names > 0)
324 {
325 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
326
327 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
328 func_names,
329 num_names,
Jim Ingham4722b102012-03-06 00:37:27 +0000330 func_name_type_mask,
Jim Inghamc1053622012-03-03 02:05:11 +0000331 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
332 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
333 }
334 return bp_sp;
335}
Chris Lattner24943d22010-06-08 16:52:24 +0000336
337SearchFilterSP
338Target::GetSearchFilterForModule (const FileSpec *containingModule)
339{
340 SearchFilterSP filter_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000341 if (containingModule != NULL)
342 {
343 // TODO: We should look into sharing module based search filters
344 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000345 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner24943d22010-06-08 16:52:24 +0000346 }
347 else
348 {
349 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000350 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000351 filter_sp = m_search_filter_sp;
352 }
353 return filter_sp;
354}
355
Jim Ingham03c8ee52011-09-21 01:17:13 +0000356SearchFilterSP
357Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
358{
359 SearchFilterSP filter_sp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000360 if (containingModules && containingModules->GetSize() != 0)
361 {
362 // TODO: We should look into sharing module based search filters
363 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000364 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000365 }
366 else
367 {
368 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000369 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000370 filter_sp = m_search_filter_sp;
371 }
372 return filter_sp;
373}
374
Jim Inghamd6d47972011-09-23 00:54:11 +0000375SearchFilterSP
376Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles)
377{
378 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
379 return GetSearchFilterForModuleList(containingModules);
380
381 SearchFilterSP filter_sp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000382 if (containingModules == NULL)
383 {
384 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
385 // but that will take a little reworking.
386
Greg Clayton13d24fb2012-01-29 20:56:30 +0000387 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000388 }
389 else
390 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000391 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000392 }
393 return filter_sp;
394}
395
Chris Lattner24943d22010-06-08 16:52:24 +0000396BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000397Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
398 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000399 RegularExpression &func_regex,
400 bool internal,
401 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000402{
Jim Inghamd6d47972011-09-23 00:54:11 +0000403 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000404 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
405 func_regex,
406 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000407
408 return CreateBreakpoint (filter_sp, resolver_sp, internal);
409}
410
Jim Ingham3df164e2012-03-05 04:47:34 +0000411lldb::BreakpointSP
412Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
413{
414 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
415}
416
Chris Lattner24943d22010-06-08 16:52:24 +0000417BreakpointSP
418Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
419{
420 BreakpointSP bp_sp;
421 if (filter_sp && resolver_sp)
422 {
423 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
424 resolver_sp->SetBreakpoint (bp_sp.get());
425
426 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000427 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000428 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000429 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000430
Greg Claytone005f2c2010-11-06 01:53:30 +0000431 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000432 if (log)
433 {
434 StreamString s;
435 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
436 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
437 }
438
Chris Lattner24943d22010-06-08 16:52:24 +0000439 bp_sp->ResolveBreakpoint();
440 }
Jim Inghamd1686902010-10-14 23:45:03 +0000441
442 if (!internal && bp_sp)
443 {
444 m_last_created_breakpoint = bp_sp;
445 }
446
Chris Lattner24943d22010-06-08 16:52:24 +0000447 return bp_sp;
448}
449
Johnny Chenda5a8022011-09-20 23:28:55 +0000450bool
451Target::ProcessIsValid()
452{
453 return (m_process_sp && m_process_sp->IsAlive());
454}
455
Johnny Chenecd4feb2011-10-14 00:42:25 +0000456// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000457// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000458WatchpointSP
459Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
Johnny Chen34bbf852011-09-12 23:38:44 +0000460{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000461 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
462 if (log)
463 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
464 __FUNCTION__, addr, size, type);
465
Johnny Chenecd4feb2011-10-14 00:42:25 +0000466 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000467 if (!ProcessIsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000468 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000469 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenecd4feb2011-10-14 00:42:25 +0000470 return wp_sp;
Johnny Chen9bf11992011-09-13 01:15:36 +0000471
Johnny Chenecd4feb2011-10-14 00:42:25 +0000472 // Currently we only support one watchpoint per address, with total number
473 // of watchpoints limited by the hardware which the inferior is running on.
474 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000475 if (matched_sp)
476 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000477 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000478 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000479 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
480 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000481 // Return the existing watchpoint if both size and type match.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000482 if (size == old_size && type == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000483 wp_sp = matched_sp;
484 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000485 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000486 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000487 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000488 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000489 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000490 }
491
Johnny Chenecd4feb2011-10-14 00:42:25 +0000492 if (!wp_sp) {
493 Watchpoint *new_wp = new Watchpoint(addr, size);
494 if (!new_wp) {
495 printf("Watchpoint ctor failed, out of memory?\n");
496 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000497 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000498 new_wp->SetWatchpointType(type);
499 new_wp->SetTarget(this);
500 wp_sp.reset(new_wp);
501 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000502 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000503
Johnny Chenecd4feb2011-10-14 00:42:25 +0000504 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000505 if (log)
506 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
507 __FUNCTION__,
508 rc.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000509 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000510
Johnny Chen155599b2012-03-26 22:00:10 +0000511 if (rc.Fail()) {
512 // Enabling the watchpoint on the device side failed.
513 // Remove the said watchpoint from the list maintained by the target instance.
514 m_watchpoint_list.Remove(wp_sp->GetID());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000515 wp_sp.reset();
Johnny Chen155599b2012-03-26 22:00:10 +0000516 }
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000517 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000518 m_last_created_watchpoint = wp_sp;
519 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000520}
521
Chris Lattner24943d22010-06-08 16:52:24 +0000522void
523Target::RemoveAllBreakpoints (bool internal_also)
524{
Greg Claytone005f2c2010-11-06 01:53:30 +0000525 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000526 if (log)
527 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
528
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000529 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000530 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000531 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000532
533 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000534}
535
536void
537Target::DisableAllBreakpoints (bool internal_also)
538{
Greg Claytone005f2c2010-11-06 01:53:30 +0000539 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000540 if (log)
541 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
542
543 m_breakpoint_list.SetEnabledAll (false);
544 if (internal_also)
545 m_internal_breakpoint_list.SetEnabledAll (false);
546}
547
548void
549Target::EnableAllBreakpoints (bool internal_also)
550{
Greg Claytone005f2c2010-11-06 01:53:30 +0000551 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000552 if (log)
553 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
554
555 m_breakpoint_list.SetEnabledAll (true);
556 if (internal_also)
557 m_internal_breakpoint_list.SetEnabledAll (true);
558}
559
560bool
561Target::RemoveBreakpointByID (break_id_t break_id)
562{
Greg Claytone005f2c2010-11-06 01:53:30 +0000563 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000564 if (log)
565 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
566
567 if (DisableBreakpointByID (break_id))
568 {
569 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000570 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000571 else
Jim Inghamd1686902010-10-14 23:45:03 +0000572 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000573 if (m_last_created_breakpoint)
574 {
575 if (m_last_created_breakpoint->GetID() == break_id)
576 m_last_created_breakpoint.reset();
577 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000578 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000579 }
Chris Lattner24943d22010-06-08 16:52:24 +0000580 return true;
581 }
582 return false;
583}
584
585bool
586Target::DisableBreakpointByID (break_id_t break_id)
587{
Greg Claytone005f2c2010-11-06 01:53:30 +0000588 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000589 if (log)
590 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
591
592 BreakpointSP bp_sp;
593
594 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
595 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
596 else
597 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
598 if (bp_sp)
599 {
600 bp_sp->SetEnabled (false);
601 return true;
602 }
603 return false;
604}
605
606bool
607Target::EnableBreakpointByID (break_id_t break_id)
608{
Greg Claytone005f2c2010-11-06 01:53:30 +0000609 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000610 if (log)
611 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
612 __FUNCTION__,
613 break_id,
614 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
615
616 BreakpointSP bp_sp;
617
618 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
619 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
620 else
621 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
622
623 if (bp_sp)
624 {
625 bp_sp->SetEnabled (true);
626 return true;
627 }
628 return false;
629}
630
Johnny Chenc86582f2011-09-23 21:21:43 +0000631// The flag 'end_to_end', default to true, signifies that the operation is
632// performed end to end, for both the debugger and the debuggee.
633
Johnny Chenecd4feb2011-10-14 00:42:25 +0000634// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
635// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000636bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000637Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000638{
639 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
640 if (log)
641 log->Printf ("Target::%s\n", __FUNCTION__);
642
Johnny Chenc86582f2011-09-23 21:21:43 +0000643 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000644 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000645 return true;
646 }
647
648 // Otherwise, it's an end to end operation.
649
Johnny Chenda5a8022011-09-20 23:28:55 +0000650 if (!ProcessIsValid())
651 return false;
652
Johnny Chenecd4feb2011-10-14 00:42:25 +0000653 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000654 for (size_t i = 0; i < num_watchpoints; ++i)
655 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000656 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
657 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000658 return false;
659
Johnny Chenecd4feb2011-10-14 00:42:25 +0000660 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000661 if (rc.Fail())
662 return false;
663 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000664 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000665 return true; // Success!
666}
667
Johnny Chenecd4feb2011-10-14 00:42:25 +0000668// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
669// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000670bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000671Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000672{
673 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
674 if (log)
675 log->Printf ("Target::%s\n", __FUNCTION__);
676
Johnny Chenc86582f2011-09-23 21:21:43 +0000677 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000678 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000679 return true;
680 }
681
682 // Otherwise, it's an end to end operation.
683
Johnny Chenda5a8022011-09-20 23:28:55 +0000684 if (!ProcessIsValid())
685 return false;
686
Johnny Chenecd4feb2011-10-14 00:42:25 +0000687 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000688 for (size_t i = 0; i < num_watchpoints; ++i)
689 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000690 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
691 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000692 return false;
693
Johnny Chenecd4feb2011-10-14 00:42:25 +0000694 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000695 if (rc.Fail())
696 return false;
697 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000698 return true; // Success!
699}
700
Johnny Chenecd4feb2011-10-14 00:42:25 +0000701// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
702// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000703bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000704Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000705{
706 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
707 if (log)
708 log->Printf ("Target::%s\n", __FUNCTION__);
709
Johnny Chenc86582f2011-09-23 21:21:43 +0000710 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000711 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000712 return true;
713 }
714
715 // Otherwise, it's an end to end operation.
716
Johnny Chenda5a8022011-09-20 23:28:55 +0000717 if (!ProcessIsValid())
718 return false;
719
Johnny Chenecd4feb2011-10-14 00:42:25 +0000720 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000721 for (size_t i = 0; i < num_watchpoints; ++i)
722 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000723 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
724 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000725 return false;
726
Johnny Chenecd4feb2011-10-14 00:42:25 +0000727 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000728 if (rc.Fail())
729 return false;
730 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000731 return true; // Success!
732}
733
Johnny Chen116a5cd2012-02-25 06:44:30 +0000734// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
735bool
736Target::ClearAllWatchpointHitCounts ()
737{
738 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
739 if (log)
740 log->Printf ("Target::%s\n", __FUNCTION__);
741
742 size_t num_watchpoints = m_watchpoint_list.GetSize();
743 for (size_t i = 0; i < num_watchpoints; ++i)
744 {
745 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
746 if (!wp_sp)
747 return false;
748
749 wp_sp->ResetHitCount();
750 }
751 return true; // Success!
752}
753
Johnny Chenecd4feb2011-10-14 00:42:25 +0000754// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000755// during these operations.
756bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000757Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000758{
759 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
760 if (log)
761 log->Printf ("Target::%s\n", __FUNCTION__);
762
763 if (!ProcessIsValid())
764 return false;
765
Johnny Chenecd4feb2011-10-14 00:42:25 +0000766 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000767 for (size_t i = 0; i < num_watchpoints; ++i)
768 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000769 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
770 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000771 return false;
772
Johnny Chenecd4feb2011-10-14 00:42:25 +0000773 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000774 }
775 return true; // Success!
776}
777
Johnny Chenecd4feb2011-10-14 00:42:25 +0000778// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000779bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000780Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000781{
782 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
783 if (log)
784 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
785
786 if (!ProcessIsValid())
787 return false;
788
Johnny Chenecd4feb2011-10-14 00:42:25 +0000789 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
790 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000791 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000792 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000793 if (rc.Success())
794 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000795
Johnny Chen01acfa72011-09-22 18:04:58 +0000796 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000797 }
798 return false;
799}
800
Johnny Chenecd4feb2011-10-14 00:42:25 +0000801// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000802bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000803Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000804{
805 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
806 if (log)
807 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
808
809 if (!ProcessIsValid())
810 return false;
811
Johnny Chenecd4feb2011-10-14 00:42:25 +0000812 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
813 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000814 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000815 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000816 if (rc.Success())
817 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000818
Johnny Chen01acfa72011-09-22 18:04:58 +0000819 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000820 }
821 return false;
822}
823
Johnny Chenecd4feb2011-10-14 00:42:25 +0000824// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000825bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000826Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000827{
828 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
829 if (log)
830 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
831
Johnny Chenecd4feb2011-10-14 00:42:25 +0000832 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000833 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000834 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000835 return true;
836 }
837 return false;
838}
839
Johnny Chenecd4feb2011-10-14 00:42:25 +0000840// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000841bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000842Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000843{
844 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
845 if (log)
846 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
847
848 if (!ProcessIsValid())
849 return false;
850
Johnny Chenecd4feb2011-10-14 00:42:25 +0000851 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
852 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000853 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000854 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000855 return true;
856 }
857 return false;
858}
859
Chris Lattner24943d22010-06-08 16:52:24 +0000860ModuleSP
861Target::GetExecutableModule ()
862{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000863 return m_images.GetModuleAtIndex(0);
864}
865
866Module*
867Target::GetExecutableModulePointer ()
868{
869 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000870}
871
872void
873Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
874{
875 m_images.Clear();
876 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000877 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000878 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000879
880 if (executable_sp.get())
881 {
882 Timer scoped_timer (__PRETTY_FUNCTION__,
883 "Target::SetExecutableModule (executable = '%s/%s')",
884 executable_sp->GetFileSpec().GetDirectory().AsCString(),
885 executable_sp->GetFileSpec().GetFilename().AsCString());
886
887 m_images.Append(executable_sp); // The first image is our exectuable file
888
Jim Ingham7508e732010-08-09 23:31:02 +0000889 // 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 +0000890 if (!m_arch.IsValid())
891 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000892
Chris Lattner24943d22010-06-08 16:52:24 +0000893 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000894 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000895
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000896 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +0000897 {
898 executable_objfile->GetDependentModules(dependent_files);
899 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
900 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000901 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
902 FileSpec platform_dependent_file_spec;
903 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000904 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000905 else
906 platform_dependent_file_spec = dependent_file_spec;
907
Greg Clayton444fe992012-02-26 05:51:37 +0000908 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
909 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +0000910 if (image_module_sp.get())
911 {
Chris Lattner24943d22010-06-08 16:52:24 +0000912 ObjectFile *objfile = image_module_sp->GetObjectFile();
913 if (objfile)
914 objfile->GetDependentModules(dependent_files);
915 }
916 }
917 }
Chris Lattner24943d22010-06-08 16:52:24 +0000918 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000919
920 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000921}
922
923
Jim Ingham7508e732010-08-09 23:31:02 +0000924bool
925Target::SetArchitecture (const ArchSpec &arch_spec)
926{
Greg Clayton24bc5d92011-03-30 18:16:51 +0000927 if (m_arch == arch_spec)
Jim Ingham7508e732010-08-09 23:31:02 +0000928 {
929 // If we're setting the architecture to our current architecture, we
930 // don't need to do anything.
931 return true;
932 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000933 else if (!m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000934 {
935 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000936 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000937 return true;
938 }
939 else
940 {
941 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000942 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000943 ModuleSP executable_sp = GetExecutableModule ();
944 m_images.Clear();
945 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000946 m_scratch_ast_source_ap.reset();
947 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000948 // Need to do something about unsetting breakpoints.
949
950 if (executable_sp)
951 {
Greg Clayton444fe992012-02-26 05:51:37 +0000952 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
953 Error error = ModuleList::GetSharedModule (module_spec,
954 executable_sp,
955 &GetExecutableSearchPaths(),
956 NULL,
957 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +0000958
959 if (!error.Fail() && executable_sp)
960 {
961 SetExecutableModule (executable_sp, true);
962 return true;
963 }
964 else
965 {
966 return false;
967 }
968 }
969 else
970 {
971 return false;
972 }
973 }
974}
Chris Lattner24943d22010-06-08 16:52:24 +0000975
Chris Lattner24943d22010-06-08 16:52:24 +0000976void
977Target::ModuleAdded (ModuleSP &module_sp)
978{
979 // A module is being added to this target for the first time
980 ModuleList module_list;
981 module_list.Append(module_sp);
982 ModulesDidLoad (module_list);
983}
984
985void
986Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
987{
Jim Ingham3b8a6052011-08-03 01:00:06 +0000988 // A module is replacing an already added module
Chris Lattner24943d22010-06-08 16:52:24 +0000989 ModuleList module_list;
990 module_list.Append (old_module_sp);
991 ModulesDidUnload (module_list);
992 module_list.Clear ();
993 module_list.Append (new_module_sp);
994 ModulesDidLoad (module_list);
995}
996
997void
998Target::ModulesDidLoad (ModuleList &module_list)
999{
1000 m_breakpoint_list.UpdateBreakpoints (module_list, true);
1001 // TODO: make event data that packages up the module_list
1002 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1003}
1004
1005void
1006Target::ModulesDidUnload (ModuleList &module_list)
1007{
1008 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +00001009
1010 // Remove the images from the target image list
1011 m_images.Remove(module_list);
1012
Chris Lattner24943d22010-06-08 16:52:24 +00001013 // TODO: make event data that packages up the module_list
1014 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1015}
1016
Jim Ingham7089d8a2011-10-28 23:14:11 +00001017
Daniel Dunbar705a0982011-10-31 22:50:37 +00001018bool
Greg Clayton444fe992012-02-26 05:51:37 +00001019Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +00001020{
1021
1022 if (!m_breakpoints_use_platform_avoid)
1023 return false;
1024 else
1025 {
1026 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +00001027 ModuleSpec module_spec (module_file_spec);
1028 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001029
1030 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1031 // black list.
1032 if (num_modules > 0)
1033 {
1034 for (int i = 0; i < num_modules; i++)
1035 {
1036 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1037 return false;
1038 }
1039 return true;
1040 }
1041 else
1042 return false;
1043 }
1044}
1045
Daniel Dunbar705a0982011-10-31 22:50:37 +00001046bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001047Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1048{
1049 if (!m_breakpoints_use_platform_avoid)
1050 return false;
1051 else if (GetPlatform())
1052 {
1053 return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
1054 }
1055 else
1056 return false;
1057}
1058
Chris Lattner24943d22010-06-08 16:52:24 +00001059size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001060Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1061{
Greg Clayton3508c382012-02-24 01:59:29 +00001062 SectionSP section_sp (addr.GetSection());
1063 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001064 {
Greg Clayton3508c382012-02-24 01:59:29 +00001065 ModuleSP module_sp (section_sp->GetModule());
1066 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001067 {
Greg Clayton3508c382012-02-24 01:59:29 +00001068 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1069 if (objfile)
1070 {
1071 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1072 addr.GetOffset(),
1073 dst,
1074 dst_len);
1075 if (bytes_read > 0)
1076 return bytes_read;
1077 else
1078 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1079 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001080 else
Greg Clayton3508c382012-02-24 01:59:29 +00001081 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001082 }
1083 else
Greg Clayton3508c382012-02-24 01:59:29 +00001084 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001085 }
1086 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001087 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001088
Greg Clayton26100dc2011-01-07 01:57:07 +00001089 return 0;
1090}
1091
1092size_t
Enrico Granata91544802011-09-06 19:20:51 +00001093Target::ReadMemory (const Address& addr,
1094 bool prefer_file_cache,
1095 void *dst,
1096 size_t dst_len,
1097 Error &error,
1098 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001099{
Chris Lattner24943d22010-06-08 16:52:24 +00001100 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001101
Enrico Granata91544802011-09-06 19:20:51 +00001102 // if we end up reading this from process memory, we will fill this
1103 // with the actual load address
1104 if (load_addr_ptr)
1105 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1106
Greg Clayton26100dc2011-01-07 01:57:07 +00001107 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001108
1109 addr_t load_addr = LLDB_INVALID_ADDRESS;
1110 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001111 Address resolved_addr;
1112 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001113 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001114 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001115 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001116 // No sections are loaded, so we must assume we are not running
1117 // yet and anything we are given is a file address.
1118 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1119 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001120 }
Greg Clayton70436352010-06-30 23:03:03 +00001121 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001122 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001123 // We have at least one section loaded. This can be becuase
1124 // we have manually loaded some sections with "target modules load ..."
1125 // or because we have have a live process that has sections loaded
1126 // through the dynamic loader
1127 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1128 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001129 }
Greg Clayton70436352010-06-30 23:03:03 +00001130 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001131 if (!resolved_addr.IsValid())
1132 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001133
Greg Clayton9b82f862011-07-11 05:12:02 +00001134
Greg Clayton26100dc2011-01-07 01:57:07 +00001135 if (prefer_file_cache)
1136 {
1137 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1138 if (bytes_read > 0)
1139 return bytes_read;
1140 }
Greg Clayton70436352010-06-30 23:03:03 +00001141
Johnny Chenda5a8022011-09-20 23:28:55 +00001142 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001143 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001144 if (load_addr == LLDB_INVALID_ADDRESS)
1145 load_addr = resolved_addr.GetLoadAddress (this);
1146
Greg Clayton70436352010-06-30 23:03:03 +00001147 if (load_addr == LLDB_INVALID_ADDRESS)
1148 {
Greg Clayton3508c382012-02-24 01:59:29 +00001149 ModuleSP addr_module_sp (resolved_addr.GetModule());
1150 if (addr_module_sp && addr_module_sp->GetFileSpec())
Greg Clayton9c236732011-10-26 00:56:27 +00001151 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001152 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001153 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001154 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001155 else
Greg Clayton9c236732011-10-26 00:56:27 +00001156 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001157 }
1158 else
1159 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001160 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001161 if (bytes_read != dst_len)
1162 {
1163 if (error.Success())
1164 {
1165 if (bytes_read == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00001166 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001167 else
Greg Clayton9c236732011-10-26 00:56:27 +00001168 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 +00001169 }
1170 }
Greg Clayton70436352010-06-30 23:03:03 +00001171 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001172 {
1173 if (load_addr_ptr)
1174 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001175 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001176 }
Greg Clayton70436352010-06-30 23:03:03 +00001177 // If the address is not section offset we have an address that
1178 // doesn't resolve to any address in any currently loaded shared
1179 // libaries and we failed to read memory so there isn't anything
1180 // more we can do. If it is section offset, we might be able to
1181 // read cached memory from the object file.
1182 if (!resolved_addr.IsSectionOffset())
1183 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001184 }
Chris Lattner24943d22010-06-08 16:52:24 +00001185 }
Greg Clayton70436352010-06-30 23:03:03 +00001186
Greg Clayton9b82f862011-07-11 05:12:02 +00001187 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001188 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001189 // If we didn't already try and read from the object file cache, then
1190 // try it after failing to read from the process.
1191 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001192 }
1193 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001194}
1195
Greg Clayton7dd98df2011-07-12 17:06:17 +00001196size_t
1197Target::ReadScalarIntegerFromMemory (const Address& addr,
1198 bool prefer_file_cache,
1199 uint32_t byte_size,
1200 bool is_signed,
1201 Scalar &scalar,
1202 Error &error)
1203{
1204 uint64_t uval;
1205
1206 if (byte_size <= sizeof(uval))
1207 {
1208 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1209 if (bytes_read == byte_size)
1210 {
1211 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1212 uint32_t offset = 0;
1213 if (byte_size <= 4)
1214 scalar = data.GetMaxU32 (&offset, byte_size);
1215 else
1216 scalar = data.GetMaxU64 (&offset, byte_size);
1217
1218 if (is_signed)
1219 scalar.SignExtend(byte_size * 8);
1220 return bytes_read;
1221 }
1222 }
1223 else
1224 {
1225 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1226 }
1227 return 0;
1228}
1229
1230uint64_t
1231Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1232 bool prefer_file_cache,
1233 size_t integer_byte_size,
1234 uint64_t fail_value,
1235 Error &error)
1236{
1237 Scalar scalar;
1238 if (ReadScalarIntegerFromMemory (addr,
1239 prefer_file_cache,
1240 integer_byte_size,
1241 false,
1242 scalar,
1243 error))
1244 return scalar.ULongLong(fail_value);
1245 return fail_value;
1246}
1247
1248bool
1249Target::ReadPointerFromMemory (const Address& addr,
1250 bool prefer_file_cache,
1251 Error &error,
1252 Address &pointer_addr)
1253{
1254 Scalar scalar;
1255 if (ReadScalarIntegerFromMemory (addr,
1256 prefer_file_cache,
1257 m_arch.GetAddressByteSize(),
1258 false,
1259 scalar,
1260 error))
1261 {
1262 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1263 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1264 {
1265 if (m_section_load_list.IsEmpty())
1266 {
1267 // No sections are loaded, so we must assume we are not running
1268 // yet and anything we are given is a file address.
1269 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1270 }
1271 else
1272 {
1273 // We have at least one section loaded. This can be becuase
1274 // we have manually loaded some sections with "target modules load ..."
1275 // or because we have have a live process that has sections loaded
1276 // through the dynamic loader
1277 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1278 }
1279 // We weren't able to resolve the pointer value, so just return
1280 // an address with no section
1281 if (!pointer_addr.IsValid())
1282 pointer_addr.SetOffset (pointer_vm_addr);
1283 return true;
1284
1285 }
1286 }
1287 return false;
1288}
Chris Lattner24943d22010-06-08 16:52:24 +00001289
1290ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001291Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001292{
1293 // Don't pass in the UUID so we can tell if we have a stale value in our list
1294 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1295 bool did_create_module = false;
1296 ModuleSP module_sp;
1297
Chris Lattner24943d22010-06-08 16:52:24 +00001298 Error error;
1299
Greg Clayton24bc5d92011-03-30 18:16:51 +00001300 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +00001301 if (m_image_search_paths.GetSize())
1302 {
Greg Clayton444fe992012-02-26 05:51:37 +00001303 ModuleSpec transformed_spec (module_spec);
1304 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
Chris Lattner24943d22010-06-08 16:52:24 +00001305 {
Greg Clayton444fe992012-02-26 05:51:37 +00001306 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
Greg Clayton9ce95382012-02-13 23:10:39 +00001307 error = ModuleList::GetSharedModule (transformed_spec,
Greg Clayton9ce95382012-02-13 23:10:39 +00001308 module_sp,
1309 &GetExecutableSearchPaths(),
1310 &old_module_sp,
1311 &did_create_module);
Chris Lattner24943d22010-06-08 16:52:24 +00001312 }
1313 }
1314
Greg Clayton24bc5d92011-03-30 18:16:51 +00001315 // The platform is responsible for finding and caching an appropriate
1316 // module in the shared module cache.
1317 if (m_platform_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001318 {
Greg Clayton24bc5d92011-03-30 18:16:51 +00001319 FileSpec platform_file_spec;
Greg Clayton444fe992012-02-26 05:51:37 +00001320 error = m_platform_sp->GetSharedModule (module_spec,
Greg Clayton24bc5d92011-03-30 18:16:51 +00001321 module_sp,
Greg Clayton9ce95382012-02-13 23:10:39 +00001322 &GetExecutableSearchPaths(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001323 &old_module_sp,
1324 &did_create_module);
1325 }
1326 else
1327 {
1328 error.SetErrorString("no platform is currently set");
Chris Lattner24943d22010-06-08 16:52:24 +00001329 }
1330
Greg Clayton24bc5d92011-03-30 18:16:51 +00001331 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +00001332 if (module_sp)
1333 {
1334 m_images.Append (module_sp);
1335 if (did_create_module)
1336 {
1337 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1338 ModuleUpdated(old_module_sp, module_sp);
1339 else
1340 ModuleAdded(module_sp);
1341 }
1342 }
1343 if (error_ptr)
1344 *error_ptr = error;
1345 return module_sp;
1346}
1347
1348
Greg Clayton289afcb2012-02-18 05:35:26 +00001349TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001350Target::CalculateTarget ()
1351{
Greg Clayton289afcb2012-02-18 05:35:26 +00001352 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001353}
1354
Greg Clayton289afcb2012-02-18 05:35:26 +00001355ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001356Target::CalculateProcess ()
1357{
Greg Clayton289afcb2012-02-18 05:35:26 +00001358 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001359}
1360
Greg Clayton289afcb2012-02-18 05:35:26 +00001361ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001362Target::CalculateThread ()
1363{
Greg Clayton289afcb2012-02-18 05:35:26 +00001364 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001365}
1366
Greg Clayton289afcb2012-02-18 05:35:26 +00001367StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001368Target::CalculateStackFrame ()
1369{
Greg Clayton289afcb2012-02-18 05:35:26 +00001370 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001371}
1372
1373void
Greg Claytona830adb2010-10-04 01:05:56 +00001374Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001375{
Greg Clayton567e7f32011-09-22 04:58:26 +00001376 exe_ctx.Clear();
1377 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001378}
1379
1380PathMappingList &
1381Target::GetImageSearchPathList ()
1382{
1383 return m_image_search_paths;
1384}
1385
1386void
1387Target::ImageSearchPathsChanged
1388(
1389 const PathMappingList &path_list,
1390 void *baton
1391)
1392{
1393 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001394 ModuleSP exe_module_sp (target->GetExecutableModule());
1395 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001396 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001397 target->m_images.Clear();
1398 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001399 }
1400}
1401
1402ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001403Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001404{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001405 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001406 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001407 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001408 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001409 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001410 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1411 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1412 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1413 }
Chris Lattner24943d22010-06-08 16:52:24 +00001414 return m_scratch_ast_context_ap.get();
1415}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001416
Sean Callanan4938bd62011-11-16 18:20:47 +00001417ClangASTImporter *
1418Target::GetClangASTImporter()
1419{
1420 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1421
1422 if (!ast_importer)
1423 {
1424 ast_importer = new ClangASTImporter();
1425 m_ast_importer_ap.reset(ast_importer);
1426 }
1427
1428 return ast_importer;
1429}
1430
Greg Clayton990de7b2010-11-18 23:32:35 +00001431void
Caroline Tice2a456812011-03-10 22:14:10 +00001432Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001433{
Greg Clayton334d33a2012-01-30 07:41:31 +00001434 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001435 SettingsController::global_settings_table,
1436 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001437
1438 // Now call SettingsInitialize() on each 'child' setting of Target
1439 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001440}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001441
Greg Clayton990de7b2010-11-18 23:32:35 +00001442void
Caroline Tice2a456812011-03-10 22:14:10 +00001443Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001444{
Caroline Tice2a456812011-03-10 22:14:10 +00001445
1446 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1447
1448 Process::SettingsTerminate ();
1449
1450 // Now terminate Target Settings.
1451
Greg Clayton990de7b2010-11-18 23:32:35 +00001452 UserSettingsControllerSP &usc = GetSettingsController();
1453 UserSettingsController::FinalizeSettingsController (usc);
1454 usc.reset();
1455}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001456
Greg Clayton990de7b2010-11-18 23:32:35 +00001457UserSettingsControllerSP &
1458Target::GetSettingsController ()
1459{
Greg Clayton334d33a2012-01-30 07:41:31 +00001460 static UserSettingsControllerSP g_settings_controller_sp;
1461 if (!g_settings_controller_sp)
1462 {
1463 g_settings_controller_sp.reset (new Target::SettingsController);
1464 // The first shared pointer to Target::SettingsController in
1465 // g_settings_controller_sp must be fully created above so that
1466 // the TargetInstanceSettings can use a weak_ptr to refer back
1467 // to the master setttings controller
1468 InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp,
1469 false,
1470 InstanceSettings::GetDefaultName().AsCString()));
1471 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1472 }
1473 return g_settings_controller_sp;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001474}
1475
Greg Clayton9ce95382012-02-13 23:10:39 +00001476FileSpecList
1477Target::GetDefaultExecutableSearchPaths ()
1478{
1479 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1480 if (settings_controller_sp)
1481 {
1482 lldb::InstanceSettingsSP instance_settings_sp (settings_controller_sp->GetDefaultInstanceSettings ());
1483 if (instance_settings_sp)
1484 return static_cast<TargetInstanceSettings *>(instance_settings_sp.get())->GetExecutableSearchPaths ();
1485 }
1486 return FileSpecList();
1487}
1488
1489
Caroline Tice5bc8c972010-09-20 20:44:43 +00001490ArchSpec
1491Target::GetDefaultArchitecture ()
1492{
Greg Clayton940b1032011-02-23 00:35:02 +00001493 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1494
1495 if (settings_controller_sp)
1496 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1497 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001498}
1499
1500void
Greg Clayton940b1032011-02-23 00:35:02 +00001501Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001502{
Greg Clayton940b1032011-02-23 00:35:02 +00001503 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1504
1505 if (settings_controller_sp)
1506 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001507}
1508
Greg Claytona830adb2010-10-04 01:05:56 +00001509Target *
1510Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1511{
1512 // The target can either exist in the "process" of ExecutionContext, or in
1513 // the "target_sp" member of SymbolContext. This accessor helper function
1514 // will get the target from one of these locations.
1515
1516 Target *target = NULL;
1517 if (sc_ptr != NULL)
1518 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001519 if (target == NULL && exe_ctx_ptr)
1520 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001521 return target;
1522}
1523
1524
Caroline Tice1ebef442010-09-27 00:30:10 +00001525void
1526Target::UpdateInstanceName ()
1527{
1528 StreamString sstr;
1529
Greg Clayton5beb99d2011-08-11 02:48:45 +00001530 Module *exe_module = GetExecutableModulePointer();
1531 if (exe_module)
Caroline Tice1ebef442010-09-27 00:30:10 +00001532 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001533 sstr.Printf ("%s_%s",
Greg Clayton5beb99d2011-08-11 02:48:45 +00001534 exe_module->GetFileSpec().GetFilename().AsCString(),
1535 exe_module->GetArchitecture().GetArchitectureName());
1536 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +00001537 }
1538}
1539
Sean Callanan77e93942010-10-29 00:29:03 +00001540const char *
1541Target::GetExpressionPrefixContentsAsCString ()
1542{
Sean Callanane0b7f942011-11-16 01:54:57 +00001543 if (!m_expr_prefix_contents.empty())
1544 return m_expr_prefix_contents.c_str();
Greg Claytonff44ab42011-04-23 02:04:55 +00001545 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001546}
1547
Greg Clayton427f2902010-12-14 02:59:59 +00001548ExecutionResults
1549Target::EvaluateExpression
1550(
1551 const char *expr_cstr,
1552 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001553 lldb_private::ExecutionPolicy execution_policy,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001554 bool coerce_to_id,
Greg Clayton427f2902010-12-14 02:59:59 +00001555 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001556 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001557 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +00001558 lldb::ValueObjectSP &result_valobj_sp
1559)
1560{
1561 ExecutionResults execution_results = eExecutionSetupError;
1562
1563 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001564
1565 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1566 return execution_results;
1567
Jim Ingham3613ae12011-05-12 02:06:14 +00001568 // We shouldn't run stop hooks in expressions.
1569 // Be sure to reset this if you return anywhere within this function.
1570 bool old_suppress_value = m_suppress_stop_hooks;
1571 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001572
1573 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001574
1575 const size_t expr_cstr_len = ::strlen (expr_cstr);
1576
Greg Clayton427f2902010-12-14 02:59:59 +00001577 if (frame)
1578 {
1579 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001580 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001581 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001582 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1583 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001584 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001585
1586 // Make sure we don't have any things that we know a variable expression
1587 // won't be able to deal with before calling into it
1588 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1589 {
1590 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1591 use_dynamic,
1592 expr_path_options,
1593 var_sp,
1594 error);
1595 }
Greg Clayton427f2902010-12-14 02:59:59 +00001596 }
1597 else if (m_process_sp)
1598 {
1599 m_process_sp->CalculateExecutionContext(exe_ctx);
1600 }
1601 else
1602 {
1603 CalculateExecutionContext(exe_ctx);
1604 }
1605
1606 if (result_valobj_sp)
1607 {
1608 execution_results = eExecutionCompleted;
1609 // We got a result from the frame variable expression path above...
1610 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1611
1612 lldb::ValueObjectSP const_valobj_sp;
1613
1614 // Check in case our value is already a constant value
1615 if (result_valobj_sp->GetIsConstant())
1616 {
1617 const_valobj_sp = result_valobj_sp;
1618 const_valobj_sp->SetName (persistent_variable_name);
1619 }
1620 else
Jim Inghame41494a2011-04-16 00:01:13 +00001621 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001622 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001623 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001624 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001625 if (dynamic_sp)
1626 result_valobj_sp = dynamic_sp;
1627 }
1628
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001629 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001630 }
Greg Clayton427f2902010-12-14 02:59:59 +00001631
Sean Callanan6a925532011-01-13 08:53:35 +00001632 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1633
Greg Clayton427f2902010-12-14 02:59:59 +00001634 result_valobj_sp = const_valobj_sp;
1635
Sean Callanan6a925532011-01-13 08:53:35 +00001636 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1637 assert (clang_expr_variable_sp.get());
1638
1639 // Set flags and live data as appropriate
1640
1641 const Value &result_value = live_valobj_sp->GetValue();
1642
1643 switch (result_value.GetValueType())
1644 {
1645 case Value::eValueTypeHostAddress:
1646 case Value::eValueTypeFileAddress:
1647 // we don't do anything with these for now
1648 break;
1649 case Value::eValueTypeScalar:
1650 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1651 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1652 break;
1653 case Value::eValueTypeLoadAddress:
1654 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1655 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1656 break;
1657 }
Greg Clayton427f2902010-12-14 02:59:59 +00001658 }
1659 else
1660 {
1661 // Make sure we aren't just trying to see the value of a persistent
1662 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001663 lldb::ClangExpressionVariableSP persistent_var_sp;
1664 // Only check for persistent variables the expression starts with a '$'
1665 if (expr_cstr[0] == '$')
1666 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1667
Greg Clayton427f2902010-12-14 02:59:59 +00001668 if (persistent_var_sp)
1669 {
1670 result_valobj_sp = persistent_var_sp->GetValueObject ();
1671 execution_results = eExecutionCompleted;
1672 }
1673 else
1674 {
1675 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001676
Greg Clayton427f2902010-12-14 02:59:59 +00001677 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001678 execution_policy,
Sean Callanan5b658cc2011-11-07 23:35:40 +00001679 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001680 coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
Sean Callanan6a925532011-01-13 08:53:35 +00001681 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001682 expr_cstr,
1683 prefix,
1684 result_valobj_sp);
1685 }
1686 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001687
1688 m_suppress_stop_hooks = old_suppress_value;
1689
Greg Clayton427f2902010-12-14 02:59:59 +00001690 return execution_results;
1691}
1692
Greg Claytonc0fa5332011-05-22 22:46:53 +00001693lldb::addr_t
1694Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1695{
1696 addr_t code_addr = load_addr;
1697 switch (m_arch.GetMachine())
1698 {
1699 case llvm::Triple::arm:
1700 case llvm::Triple::thumb:
1701 switch (addr_class)
1702 {
1703 case eAddressClassData:
1704 case eAddressClassDebug:
1705 return LLDB_INVALID_ADDRESS;
1706
1707 case eAddressClassUnknown:
1708 case eAddressClassInvalid:
1709 case eAddressClassCode:
1710 case eAddressClassCodeAlternateISA:
1711 case eAddressClassRuntime:
1712 // Check if bit zero it no set?
1713 if ((code_addr & 1ull) == 0)
1714 {
1715 // Bit zero isn't set, check if the address is a multiple of 2?
1716 if (code_addr & 2ull)
1717 {
1718 // The address is a multiple of 2 so it must be thumb, set bit zero
1719 code_addr |= 1ull;
1720 }
1721 else if (addr_class == eAddressClassCodeAlternateISA)
1722 {
1723 // We checked the address and the address claims to be the alternate ISA
1724 // which means thumb, so set bit zero.
1725 code_addr |= 1ull;
1726 }
1727 }
1728 break;
1729 }
1730 break;
1731
1732 default:
1733 break;
1734 }
1735 return code_addr;
1736}
1737
1738lldb::addr_t
1739Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1740{
1741 addr_t opcode_addr = load_addr;
1742 switch (m_arch.GetMachine())
1743 {
1744 case llvm::Triple::arm:
1745 case llvm::Triple::thumb:
1746 switch (addr_class)
1747 {
1748 case eAddressClassData:
1749 case eAddressClassDebug:
1750 return LLDB_INVALID_ADDRESS;
1751
1752 case eAddressClassInvalid:
1753 case eAddressClassUnknown:
1754 case eAddressClassCode:
1755 case eAddressClassCodeAlternateISA:
1756 case eAddressClassRuntime:
1757 opcode_addr &= ~(1ull);
1758 break;
1759 }
1760 break;
1761
1762 default:
1763 break;
1764 }
1765 return opcode_addr;
1766}
1767
Jim Inghamd60d94a2011-03-11 03:53:59 +00001768lldb::user_id_t
1769Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1770{
1771 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001772 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001773 m_stop_hooks[new_uid] = new_hook_sp;
1774 return new_uid;
1775}
1776
1777bool
1778Target::RemoveStopHookByID (lldb::user_id_t user_id)
1779{
1780 size_t num_removed;
1781 num_removed = m_stop_hooks.erase (user_id);
1782 if (num_removed == 0)
1783 return false;
1784 else
1785 return true;
1786}
1787
1788void
1789Target::RemoveAllStopHooks ()
1790{
1791 m_stop_hooks.clear();
1792}
1793
1794Target::StopHookSP
1795Target::GetStopHookByID (lldb::user_id_t user_id)
1796{
1797 StopHookSP found_hook;
1798
1799 StopHookCollection::iterator specified_hook_iter;
1800 specified_hook_iter = m_stop_hooks.find (user_id);
1801 if (specified_hook_iter != m_stop_hooks.end())
1802 found_hook = (*specified_hook_iter).second;
1803 return found_hook;
1804}
1805
1806bool
1807Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1808{
1809 StopHookCollection::iterator specified_hook_iter;
1810 specified_hook_iter = m_stop_hooks.find (user_id);
1811 if (specified_hook_iter == m_stop_hooks.end())
1812 return false;
1813
1814 (*specified_hook_iter).second->SetIsActive (active_state);
1815 return true;
1816}
1817
1818void
1819Target::SetAllStopHooksActiveState (bool active_state)
1820{
1821 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1822 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1823 {
1824 (*pos).second->SetIsActive (active_state);
1825 }
1826}
1827
1828void
1829Target::RunStopHooks ()
1830{
Jim Ingham3613ae12011-05-12 02:06:14 +00001831 if (m_suppress_stop_hooks)
1832 return;
1833
Jim Inghamd60d94a2011-03-11 03:53:59 +00001834 if (!m_process_sp)
1835 return;
1836
1837 if (m_stop_hooks.empty())
1838 return;
1839
1840 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1841
1842 // If there aren't any active stop hooks, don't bother either:
1843 bool any_active_hooks = false;
1844 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1845 {
1846 if ((*pos).second->IsActive())
1847 {
1848 any_active_hooks = true;
1849 break;
1850 }
1851 }
1852 if (!any_active_hooks)
1853 return;
1854
1855 CommandReturnObject result;
1856
1857 std::vector<ExecutionContext> exc_ctx_with_reasons;
1858 std::vector<SymbolContext> sym_ctx_with_reasons;
1859
1860 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1861 size_t num_threads = cur_threadlist.GetSize();
1862 for (size_t i = 0; i < num_threads; i++)
1863 {
1864 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1865 if (cur_thread_sp->ThreadStoppedForAReason())
1866 {
1867 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1868 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1869 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1870 }
1871 }
1872
1873 // If no threads stopped for a reason, don't run the stop-hooks.
1874 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1875 if (num_exe_ctx == 0)
1876 return;
1877
Jim Inghame5ed8e92011-06-02 23:58:26 +00001878 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1879 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001880
1881 bool keep_going = true;
1882 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001883 bool print_hook_header;
1884 bool print_thread_header;
1885
1886 if (num_exe_ctx == 1)
1887 print_thread_header = false;
1888 else
1889 print_thread_header = true;
1890
1891 if (m_stop_hooks.size() == 1)
1892 print_hook_header = false;
1893 else
1894 print_hook_header = true;
1895
Jim Inghamd60d94a2011-03-11 03:53:59 +00001896 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1897 {
1898 // result.Clear();
1899 StopHookSP cur_hook_sp = (*pos).second;
1900 if (!cur_hook_sp->IsActive())
1901 continue;
1902
1903 bool any_thread_matched = false;
1904 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1905 {
1906 if ((cur_hook_sp->GetSpecifier () == NULL
1907 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1908 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Inghama2664912012-03-07 22:03:04 +00001909 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001910 {
1911 if (!hooks_ran)
1912 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00001913 hooks_ran = true;
1914 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001915 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001916 {
Johnny Chen4d96a742011-10-24 23:01:06 +00001917 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
1918 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
1919 NULL);
1920 if (cmd)
1921 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
1922 else
1923 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001924 any_thread_matched = true;
1925 }
1926
Jim Inghamc54840c2011-03-22 01:47:27 +00001927 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00001928 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001929
1930 bool stop_on_continue = true;
1931 bool stop_on_error = true;
1932 bool echo_commands = false;
1933 bool print_results = true;
1934 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001935 &exc_ctx_with_reasons[i],
1936 stop_on_continue,
1937 stop_on_error,
1938 echo_commands,
1939 print_results,
1940 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001941
1942 // If the command started the target going again, we should bag out of
1943 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001944 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1945 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001946 {
Greg Clayton444e35b2011-10-19 18:09:39 +00001947 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001948 keep_going = false;
1949 }
1950 }
1951 }
1952 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00001953
Caroline Tice4a348082011-05-02 20:41:46 +00001954 result.GetImmediateOutputStream()->Flush();
1955 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001956}
1957
Greg Claytonbbea1332011-07-08 00:48:09 +00001958bool
1959Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1960{
1961 bool changed = false;
1962 if (module)
1963 {
1964 ObjectFile *object_file = module->GetObjectFile();
1965 if (object_file)
1966 {
1967 SectionList *section_list = object_file->GetSectionList ();
1968 if (section_list)
1969 {
1970 // All sections listed in the dyld image info structure will all
1971 // either be fixed up already, or they will all be off by a single
1972 // slide amount that is determined by finding the first segment
1973 // that is at file offset zero which also has bytes (a file size
1974 // that is greater than zero) in the object file.
1975
1976 // Determine the slide amount (if any)
1977 const size_t num_sections = section_list->GetSize();
1978 size_t sect_idx = 0;
1979 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1980 {
1981 // Iterate through the object file sections to find the
1982 // first section that starts of file offset zero and that
1983 // has bytes in the file...
1984 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1985 if (section)
1986 {
1987 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1988 changed = true;
1989 }
1990 }
1991 }
1992 }
1993 }
1994 return changed;
1995}
1996
1997
Jim Inghamd60d94a2011-03-11 03:53:59 +00001998//--------------------------------------------------------------
1999// class Target::StopHook
2000//--------------------------------------------------------------
2001
2002
2003Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2004 UserID (uid),
2005 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00002006 m_commands (),
2007 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002008 m_thread_spec_ap(NULL),
2009 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002010{
2011}
2012
2013Target::StopHook::StopHook (const StopHook &rhs) :
2014 UserID (rhs.GetID()),
2015 m_target_sp (rhs.m_target_sp),
2016 m_commands (rhs.m_commands),
2017 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002018 m_thread_spec_ap (NULL),
2019 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002020{
2021 if (rhs.m_thread_spec_ap.get() != NULL)
2022 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2023}
2024
2025
2026Target::StopHook::~StopHook ()
2027{
2028}
2029
2030void
2031Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2032{
2033 m_thread_spec_ap.reset (specifier);
2034}
2035
2036
2037void
2038Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2039{
2040 int indent_level = s->GetIndentLevel();
2041
2042 s->SetIndentLevel(indent_level + 2);
2043
Greg Clayton444e35b2011-10-19 18:09:39 +00002044 s->Printf ("Hook: %llu\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002045 if (m_active)
2046 s->Indent ("State: enabled\n");
2047 else
2048 s->Indent ("State: disabled\n");
2049
2050 if (m_specifier_sp)
2051 {
2052 s->Indent();
2053 s->PutCString ("Specifier:\n");
2054 s->SetIndentLevel (indent_level + 4);
2055 m_specifier_sp->GetDescription (s, level);
2056 s->SetIndentLevel (indent_level + 2);
2057 }
2058
2059 if (m_thread_spec_ap.get() != NULL)
2060 {
2061 StreamString tmp;
2062 s->Indent("Thread:\n");
2063 m_thread_spec_ap->GetDescription (&tmp, level);
2064 s->SetIndentLevel (indent_level + 4);
2065 s->Indent (tmp.GetData());
2066 s->PutCString ("\n");
2067 s->SetIndentLevel (indent_level + 2);
2068 }
2069
2070 s->Indent ("Commands: \n");
2071 s->SetIndentLevel (indent_level + 4);
2072 uint32_t num_commands = m_commands.GetSize();
2073 for (uint32_t i = 0; i < num_commands; i++)
2074 {
2075 s->Indent(m_commands.GetStringAtIndex(i));
2076 s->PutCString ("\n");
2077 }
2078 s->SetIndentLevel (indent_level);
2079}
2080
2081
Caroline Tice5bc8c972010-09-20 20:44:43 +00002082//--------------------------------------------------------------
2083// class Target::SettingsController
2084//--------------------------------------------------------------
2085
2086Target::SettingsController::SettingsController () :
2087 UserSettingsController ("target", Debugger::GetSettingsController()),
2088 m_default_architecture ()
2089{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002090}
2091
2092Target::SettingsController::~SettingsController ()
2093{
2094}
2095
2096lldb::InstanceSettingsSP
2097Target::SettingsController::CreateInstanceSettings (const char *instance_name)
2098{
Greg Clayton334d33a2012-01-30 07:41:31 +00002099 lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
2100 false,
2101 instance_name));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002102 return new_settings_sp;
2103}
2104
Caroline Tice5bc8c972010-09-20 20:44:43 +00002105
Greg Claytonabb33022011-11-08 02:43:13 +00002106#define TSC_DEFAULT_ARCH "default-arch"
2107#define TSC_EXPR_PREFIX "expr-prefix"
2108#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
2109#define TSC_SKIP_PROLOGUE "skip-prologue"
2110#define TSC_SOURCE_MAP "source-map"
Greg Clayton9ce95382012-02-13 23:10:39 +00002111#define TSC_EXE_SEARCH_PATHS "exec-search-paths"
Greg Claytonabb33022011-11-08 02:43:13 +00002112#define TSC_MAX_CHILDREN "max-children-count"
2113#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2114#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2115#define TSC_RUN_ARGS "run-args"
2116#define TSC_ENV_VARS "env-vars"
2117#define TSC_INHERIT_ENV "inherit-env"
2118#define TSC_STDIN_PATH "input-path"
2119#define TSC_STDOUT_PATH "output-path"
2120#define TSC_STDERR_PATH "error-path"
2121#define TSC_DISABLE_ASLR "disable-aslr"
2122#define TSC_DISABLE_STDIO "disable-stdio"
Greg Claytond284b662011-02-18 01:44:25 +00002123
2124
2125static const ConstString &
2126GetSettingNameForDefaultArch ()
2127{
2128 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00002129 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002130}
2131
Greg Claytond284b662011-02-18 01:44:25 +00002132static const ConstString &
2133GetSettingNameForExpressionPrefix ()
2134{
2135 static ConstString g_const_string (TSC_EXPR_PREFIX);
2136 return g_const_string;
2137}
2138
2139static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00002140GetSettingNameForPreferDynamicValue ()
2141{
2142 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2143 return g_const_string;
2144}
2145
Greg Claytonff44ab42011-04-23 02:04:55 +00002146static const ConstString &
2147GetSettingNameForSourcePathMap ()
2148{
2149 static ConstString g_const_string (TSC_SOURCE_MAP);
2150 return g_const_string;
2151}
Greg Claytond284b662011-02-18 01:44:25 +00002152
Greg Clayton17cd9952011-04-22 03:55:06 +00002153static const ConstString &
Greg Clayton9ce95382012-02-13 23:10:39 +00002154GetSettingNameForExecutableSearchPaths ()
2155{
2156 static ConstString g_const_string (TSC_EXE_SEARCH_PATHS);
2157 return g_const_string;
2158}
2159
2160static const ConstString &
Greg Clayton17cd9952011-04-22 03:55:06 +00002161GetSettingNameForSkipPrologue ()
2162{
2163 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2164 return g_const_string;
2165}
2166
Enrico Granata018921d2011-08-12 02:00:06 +00002167static const ConstString &
2168GetSettingNameForMaxChildren ()
2169{
2170 static ConstString g_const_string (TSC_MAX_CHILDREN);
2171 return g_const_string;
2172}
Greg Clayton17cd9952011-04-22 03:55:06 +00002173
Enrico Granata91544802011-09-06 19:20:51 +00002174static const ConstString &
2175GetSettingNameForMaxStringSummaryLength ()
2176{
2177 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2178 return g_const_string;
2179}
Greg Clayton17cd9952011-04-22 03:55:06 +00002180
Jim Ingham7089d8a2011-10-28 23:14:11 +00002181static const ConstString &
2182GetSettingNameForPlatformAvoid ()
2183{
2184 static ConstString g_const_string (TSC_PLATFORM_AVOID);
2185 return g_const_string;
2186}
2187
Greg Claytonabb33022011-11-08 02:43:13 +00002188const ConstString &
2189GetSettingNameForRunArgs ()
2190{
2191 static ConstString g_const_string (TSC_RUN_ARGS);
2192 return g_const_string;
2193}
2194
2195const ConstString &
2196GetSettingNameForEnvVars ()
2197{
2198 static ConstString g_const_string (TSC_ENV_VARS);
2199 return g_const_string;
2200}
2201
2202const ConstString &
2203GetSettingNameForInheritHostEnv ()
2204{
2205 static ConstString g_const_string (TSC_INHERIT_ENV);
2206 return g_const_string;
2207}
2208
2209const ConstString &
2210GetSettingNameForInputPath ()
2211{
2212 static ConstString g_const_string (TSC_STDIN_PATH);
2213 return g_const_string;
2214}
2215
2216const ConstString &
2217GetSettingNameForOutputPath ()
2218{
2219 static ConstString g_const_string (TSC_STDOUT_PATH);
2220 return g_const_string;
2221}
2222
2223const ConstString &
2224GetSettingNameForErrorPath ()
2225{
2226 static ConstString g_const_string (TSC_STDERR_PATH);
2227 return g_const_string;
2228}
2229
2230const ConstString &
2231GetSettingNameForDisableASLR ()
2232{
2233 static ConstString g_const_string (TSC_DISABLE_ASLR);
2234 return g_const_string;
2235}
2236
2237const ConstString &
2238GetSettingNameForDisableSTDIO ()
2239{
2240 static ConstString g_const_string (TSC_DISABLE_STDIO);
2241 return g_const_string;
2242}
Jim Ingham7089d8a2011-10-28 23:14:11 +00002243
Caroline Tice5bc8c972010-09-20 20:44:43 +00002244bool
2245Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2246 const char *index_value,
2247 const char *value,
2248 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002249 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002250 Error&err)
2251{
Greg Claytond284b662011-02-18 01:44:25 +00002252 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002253 {
Greg Claytonf15996e2011-04-07 22:46:35 +00002254 m_default_architecture.SetTriple (value, NULL);
Greg Clayton940b1032011-02-23 00:35:02 +00002255 if (!m_default_architecture.IsValid())
2256 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002257 }
2258 return true;
2259}
2260
2261
2262bool
2263Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2264 StringList &value,
2265 Error &err)
2266{
Greg Claytond284b662011-02-18 01:44:25 +00002267 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002268 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00002269 // If the arch is invalid (the default), don't show a string for it
2270 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00002271 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00002272 return true;
2273 }
2274 else
2275 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2276
2277 return false;
2278}
2279
2280//--------------------------------------------------------------
2281// class TargetInstanceSettings
2282//--------------------------------------------------------------
2283
Greg Clayton638351a2010-12-04 00:10:17 +00002284TargetInstanceSettings::TargetInstanceSettings
2285(
Greg Clayton334d33a2012-01-30 07:41:31 +00002286 const lldb::UserSettingsControllerSP &owner_sp,
Greg Clayton638351a2010-12-04 00:10:17 +00002287 bool live_instance,
2288 const char *name
2289) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002290 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00002291 m_expr_prefix_file (),
Sean Callanane0b7f942011-11-16 01:54:57 +00002292 m_expr_prefix_contents (),
Jim Ingham10de7d12011-05-04 03:43:18 +00002293 m_prefer_dynamic_value (2),
Greg Claytonff44ab42011-04-23 02:04:55 +00002294 m_skip_prologue (true, true),
Enrico Granata018921d2011-08-12 02:00:06 +00002295 m_source_map (NULL, NULL),
Greg Clayton9ce95382012-02-13 23:10:39 +00002296 m_exe_search_paths (),
Enrico Granata91544802011-09-06 19:20:51 +00002297 m_max_children_display(256),
Jim Ingham7089d8a2011-10-28 23:14:11 +00002298 m_max_strlen_length(1024),
Greg Claytonabb33022011-11-08 02:43:13 +00002299 m_breakpoints_use_platform_avoid (true, true),
2300 m_run_args (),
2301 m_env_vars (),
2302 m_input_path (),
2303 m_output_path (),
2304 m_error_path (),
2305 m_disable_aslr (true),
2306 m_disable_stdio (false),
2307 m_inherit_host_env (true),
2308 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002309{
2310 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2311 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2312 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2313 // This is true for CreateInstanceName() too.
2314
2315 if (GetInstanceName () == InstanceSettings::InvalidName())
2316 {
2317 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00002318 owner_sp->RegisterInstanceSettings (this);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002319 }
2320
2321 if (live_instance)
2322 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002323 const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002324 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002325 }
2326}
2327
2328TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002329 InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
Greg Claytonff44ab42011-04-23 02:04:55 +00002330 m_expr_prefix_file (rhs.m_expr_prefix_file),
Sean Callanane0b7f942011-11-16 01:54:57 +00002331 m_expr_prefix_contents (rhs.m_expr_prefix_contents),
Greg Claytonff44ab42011-04-23 02:04:55 +00002332 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
2333 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata018921d2011-08-12 02:00:06 +00002334 m_source_map (rhs.m_source_map),
Greg Clayton9ce95382012-02-13 23:10:39 +00002335 m_exe_search_paths (rhs.m_exe_search_paths),
Greg Claytonabb33022011-11-08 02:43:13 +00002336 m_max_children_display (rhs.m_max_children_display),
2337 m_max_strlen_length (rhs.m_max_strlen_length),
2338 m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2339 m_run_args (rhs.m_run_args),
2340 m_env_vars (rhs.m_env_vars),
2341 m_input_path (rhs.m_input_path),
2342 m_output_path (rhs.m_output_path),
2343 m_error_path (rhs.m_error_path),
2344 m_disable_aslr (rhs.m_disable_aslr),
2345 m_disable_stdio (rhs.m_disable_stdio),
2346 m_inherit_host_env (rhs.m_inherit_host_env)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002347{
2348 if (m_instance_name != InstanceSettings::GetDefaultName())
2349 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002350 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2351 if (owner_sp)
2352 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002353 }
2354}
2355
2356TargetInstanceSettings::~TargetInstanceSettings ()
2357{
2358}
2359
2360TargetInstanceSettings&
2361TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2362{
2363 if (this != &rhs)
2364 {
Greg Claytonabb33022011-11-08 02:43:13 +00002365 m_expr_prefix_file = rhs.m_expr_prefix_file;
Sean Callanane0b7f942011-11-16 01:54:57 +00002366 m_expr_prefix_contents = rhs.m_expr_prefix_contents;
Greg Claytonabb33022011-11-08 02:43:13 +00002367 m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
2368 m_skip_prologue = rhs.m_skip_prologue;
2369 m_source_map = rhs.m_source_map;
Greg Clayton9ce95382012-02-13 23:10:39 +00002370 m_exe_search_paths = rhs.m_exe_search_paths;
Greg Claytonabb33022011-11-08 02:43:13 +00002371 m_max_children_display = rhs.m_max_children_display;
2372 m_max_strlen_length = rhs.m_max_strlen_length;
2373 m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2374 m_run_args = rhs.m_run_args;
2375 m_env_vars = rhs.m_env_vars;
2376 m_input_path = rhs.m_input_path;
2377 m_output_path = rhs.m_output_path;
2378 m_error_path = rhs.m_error_path;
2379 m_disable_aslr = rhs.m_disable_aslr;
2380 m_disable_stdio = rhs.m_disable_stdio;
2381 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002382 }
2383
2384 return *this;
2385}
2386
Caroline Tice5bc8c972010-09-20 20:44:43 +00002387void
2388TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2389 const char *index_value,
2390 const char *value,
2391 const ConstString &instance_name,
2392 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002393 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002394 Error &err,
2395 bool pending)
2396{
Greg Claytond284b662011-02-18 01:44:25 +00002397 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002398 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002399 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2400 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00002401 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002402 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00002403 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002404 default:
2405 break;
2406 case eVarSetOperationAssign:
2407 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00002408 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002409 m_expr_prefix_contents.clear();
2410
Greg Claytonff44ab42011-04-23 02:04:55 +00002411 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2412 {
2413 err.SetErrorToGenericError ();
Greg Clayton9c236732011-10-26 00:56:27 +00002414 err.SetErrorStringWithFormat ("%s does not exist", value);
Greg Claytonff44ab42011-04-23 02:04:55 +00002415 return;
2416 }
2417
Greg Clayton4b23ab32012-01-06 02:01:06 +00002418 DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
Sean Callanane0b7f942011-11-16 01:54:57 +00002419
Greg Clayton4b23ab32012-01-06 02:01:06 +00002420 if (err.Success())
Greg Claytonff44ab42011-04-23 02:04:55 +00002421 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002422 if (file_data_sp && file_data_sp->GetByteSize() > 0)
2423 {
2424 m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
2425 }
2426 else
2427 {
2428 err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
2429 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002430 }
Sean Callanan77e93942010-10-29 00:29:03 +00002431 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002432 break;
2433 case eVarSetOperationClear:
Sean Callanane0b7f942011-11-16 01:54:57 +00002434 m_expr_prefix_contents.clear();
Sean Callanan77e93942010-10-29 00:29:03 +00002435 }
Sean Callanan77e93942010-10-29 00:29:03 +00002436 }
2437 }
Jim Inghame41494a2011-04-16 00:01:13 +00002438 else if (var_name == GetSettingNameForPreferDynamicValue())
2439 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002440 int new_value;
2441 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2442 if (err.Success())
2443 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00002444 }
2445 else if (var_name == GetSettingNameForSkipPrologue())
2446 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002447 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2448 }
Enrico Granata018921d2011-08-12 02:00:06 +00002449 else if (var_name == GetSettingNameForMaxChildren())
2450 {
2451 bool ok;
2452 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2453 if (ok)
2454 m_max_children_display = new_value;
2455 }
Enrico Granata91544802011-09-06 19:20:51 +00002456 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2457 {
2458 bool ok;
2459 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2460 if (ok)
2461 m_max_strlen_length = new_value;
2462 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002463 else if (var_name == GetSettingNameForExecutableSearchPaths())
2464 {
2465 switch (op)
2466 {
2467 case eVarSetOperationReplace:
2468 case eVarSetOperationInsertBefore:
2469 case eVarSetOperationInsertAfter:
2470 case eVarSetOperationRemove:
2471 default:
2472 break;
2473 case eVarSetOperationAssign:
2474 m_exe_search_paths.Clear();
2475 // Fall through to append....
2476 case eVarSetOperationAppend:
2477 {
2478 Args args(value);
2479 const uint32_t argc = args.GetArgumentCount();
2480 if (argc > 0)
2481 {
2482 const char *exe_search_path_dir;
2483 for (uint32_t idx = 0; (exe_search_path_dir = args.GetArgumentAtIndex(idx)) != NULL; ++idx)
2484 {
2485 FileSpec file_spec;
2486 file_spec.GetDirectory().SetCString(exe_search_path_dir);
2487 FileSpec::FileType file_type = file_spec.GetFileType();
2488 if (file_type == FileSpec::eFileTypeDirectory || file_type == FileSpec::eFileTypeInvalid)
2489 {
2490 m_exe_search_paths.Append(file_spec);
2491 }
2492 else
2493 {
2494 err.SetErrorStringWithFormat("executable search path '%s' exists, but it does not resolve to a directory", exe_search_path_dir);
2495 }
2496 }
2497 }
2498 }
2499 break;
2500
2501 case eVarSetOperationClear:
2502 m_exe_search_paths.Clear();
2503 break;
2504 }
2505 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002506 else if (var_name == GetSettingNameForSourcePathMap ())
2507 {
2508 switch (op)
2509 {
2510 case eVarSetOperationReplace:
2511 case eVarSetOperationInsertBefore:
2512 case eVarSetOperationInsertAfter:
2513 case eVarSetOperationRemove:
2514 default:
2515 break;
2516 case eVarSetOperationAssign:
2517 m_source_map.Clear(true);
2518 // Fall through to append....
2519 case eVarSetOperationAppend:
2520 {
2521 Args args(value);
2522 const uint32_t argc = args.GetArgumentCount();
2523 if (argc & 1 || argc == 0)
2524 {
2525 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2526 }
2527 else
2528 {
2529 char resolved_new_path[PATH_MAX];
2530 FileSpec file_spec;
2531 const char *old_path;
2532 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2533 {
2534 const char *new_path = args.GetArgumentAtIndex(idx+1);
2535 assert (new_path); // We have an even number of paths, this shouldn't happen!
2536
2537 file_spec.SetFile(new_path, true);
2538 if (file_spec.Exists())
2539 {
2540 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2541 {
2542 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2543 return;
2544 }
2545 }
2546 else
2547 {
2548 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2549 return;
2550 }
2551 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2552 }
2553 }
2554 }
2555 break;
2556
2557 case eVarSetOperationClear:
2558 m_source_map.Clear(true);
2559 break;
2560 }
Jim Inghame41494a2011-04-16 00:01:13 +00002561 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002562 else if (var_name == GetSettingNameForPlatformAvoid ())
2563 {
2564 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
2565 }
Greg Claytonabb33022011-11-08 02:43:13 +00002566 else if (var_name == GetSettingNameForRunArgs())
2567 {
2568 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2569 }
2570 else if (var_name == GetSettingNameForEnvVars())
2571 {
2572 // This is nice for local debugging, but it is isn't correct for
2573 // remote debugging. We need to stop process.env-vars from being
2574 // populated with the host environment and add this as a launch option
2575 // and get the correct environment from the Target's platform.
2576 // GetHostEnvironmentIfNeeded ();
2577 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
2578 }
2579 else if (var_name == GetSettingNameForInputPath())
2580 {
2581 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2582 }
2583 else if (var_name == GetSettingNameForOutputPath())
2584 {
2585 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2586 }
2587 else if (var_name == GetSettingNameForErrorPath())
2588 {
2589 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2590 }
2591 else if (var_name == GetSettingNameForDisableASLR())
2592 {
2593 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
2594 }
2595 else if (var_name == GetSettingNameForDisableSTDIO ())
2596 {
2597 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
2598 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002599}
2600
2601void
Greg Claytond284b662011-02-18 01:44:25 +00002602TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002603{
Sean Callanan77e93942010-10-29 00:29:03 +00002604 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2605
2606 if (!new_settings_ptr)
2607 return;
2608
Greg Claytonabb33022011-11-08 02:43:13 +00002609 *this = *new_settings_ptr;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002610}
2611
Caroline Ticebcb5b452010-09-20 21:37:42 +00002612bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00002613TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2614 const ConstString &var_name,
2615 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00002616 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002617{
Greg Claytond284b662011-02-18 01:44:25 +00002618 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002619 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002620 char path[PATH_MAX];
2621 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2622 if (path_len > 0)
2623 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00002624 }
Jim Inghame41494a2011-04-16 00:01:13 +00002625 else if (var_name == GetSettingNameForPreferDynamicValue())
2626 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002627 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00002628 }
Greg Clayton17cd9952011-04-22 03:55:06 +00002629 else if (var_name == GetSettingNameForSkipPrologue())
2630 {
2631 if (m_skip_prologue)
2632 value.AppendString ("true");
2633 else
2634 value.AppendString ("false");
2635 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002636 else if (var_name == GetSettingNameForExecutableSearchPaths())
2637 {
2638 if (m_exe_search_paths.GetSize())
2639 {
2640 for (size_t i = 0, n = m_exe_search_paths.GetSize(); i < n; ++i)
2641 {
2642 value.AppendString(m_exe_search_paths.GetFileSpecAtIndex (i).GetDirectory().AsCString());
2643 }
2644 }
2645 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002646 else if (var_name == GetSettingNameForSourcePathMap ())
2647 {
Johnny Chen931449e2011-12-12 21:59:28 +00002648 if (m_source_map.GetSize())
2649 {
2650 size_t i;
2651 for (i = 0; i < m_source_map.GetSize(); ++i) {
2652 StreamString sstr;
2653 m_source_map.Dump(&sstr, i);
2654 value.AppendString(sstr.GetData());
2655 }
2656 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002657 }
Enrico Granata018921d2011-08-12 02:00:06 +00002658 else if (var_name == GetSettingNameForMaxChildren())
2659 {
2660 StreamString count_str;
2661 count_str.Printf ("%d", m_max_children_display);
2662 value.AppendString (count_str.GetData());
2663 }
Enrico Granata91544802011-09-06 19:20:51 +00002664 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2665 {
2666 StreamString count_str;
2667 count_str.Printf ("%d", m_max_strlen_length);
2668 value.AppendString (count_str.GetData());
2669 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002670 else if (var_name == GetSettingNameForPlatformAvoid())
2671 {
2672 if (m_breakpoints_use_platform_avoid)
2673 value.AppendString ("true");
2674 else
2675 value.AppendString ("false");
2676 }
Greg Claytonabb33022011-11-08 02:43:13 +00002677 else if (var_name == GetSettingNameForRunArgs())
2678 {
2679 if (m_run_args.GetArgumentCount() > 0)
2680 {
2681 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2682 value.AppendString (m_run_args.GetArgumentAtIndex (i));
2683 }
2684 }
2685 else if (var_name == GetSettingNameForEnvVars())
2686 {
2687 GetHostEnvironmentIfNeeded ();
2688
2689 if (m_env_vars.size() > 0)
2690 {
2691 std::map<std::string, std::string>::iterator pos;
2692 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2693 {
2694 StreamString value_str;
2695 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2696 value.AppendString (value_str.GetData());
2697 }
2698 }
2699 }
2700 else if (var_name == GetSettingNameForInputPath())
2701 {
2702 value.AppendString (m_input_path.c_str());
2703 }
2704 else if (var_name == GetSettingNameForOutputPath())
2705 {
2706 value.AppendString (m_output_path.c_str());
2707 }
2708 else if (var_name == GetSettingNameForErrorPath())
2709 {
2710 value.AppendString (m_error_path.c_str());
2711 }
2712 else if (var_name == GetSettingNameForInheritHostEnv())
2713 {
2714 if (m_inherit_host_env)
2715 value.AppendString ("true");
2716 else
2717 value.AppendString ("false");
2718 }
2719 else if (var_name == GetSettingNameForDisableASLR())
2720 {
2721 if (m_disable_aslr)
2722 value.AppendString ("true");
2723 else
2724 value.AppendString ("false");
2725 }
2726 else if (var_name == GetSettingNameForDisableSTDIO())
2727 {
2728 if (m_disable_stdio)
2729 value.AppendString ("true");
2730 else
2731 value.AppendString ("false");
2732 }
Sean Callanan77e93942010-10-29 00:29:03 +00002733 else
2734 {
2735 if (err)
2736 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2737 return false;
2738 }
Sean Callanan77e93942010-10-29 00:29:03 +00002739 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002740}
2741
Greg Claytonabb33022011-11-08 02:43:13 +00002742void
2743Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
2744{
2745 if (m_inherit_host_env && !m_got_host_env)
2746 {
2747 m_got_host_env = true;
2748 StringList host_env;
2749 const size_t host_env_count = Host::GetEnvironment (host_env);
2750 for (size_t idx=0; idx<host_env_count; idx++)
2751 {
2752 const char *env_entry = host_env.GetStringAtIndex (idx);
2753 if (env_entry)
2754 {
2755 const char *equal_pos = ::strchr(env_entry, '=');
2756 if (equal_pos)
2757 {
2758 std::string key (env_entry, equal_pos - env_entry);
2759 std::string value (equal_pos + 1);
2760 if (m_env_vars.find (key) == m_env_vars.end())
2761 m_env_vars[key] = value;
2762 }
2763 }
2764 }
2765 }
2766}
2767
2768
2769size_t
2770Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
2771{
2772 GetHostEnvironmentIfNeeded ();
2773
2774 dictionary::const_iterator pos, end = m_env_vars.end();
2775 for (pos = m_env_vars.begin(); pos != end; ++pos)
2776 {
2777 std::string env_var_equal_value (pos->first);
2778 env_var_equal_value.append(1, '=');
2779 env_var_equal_value.append (pos->second);
2780 env.AppendArgument (env_var_equal_value.c_str());
2781 }
2782 return env.GetArgumentCount();
2783}
2784
2785
Caroline Tice5bc8c972010-09-20 20:44:43 +00002786const ConstString
2787TargetInstanceSettings::CreateInstanceName ()
2788{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002789 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00002790 static int instance_count = 1;
2791
Caroline Tice5bc8c972010-09-20 20:44:43 +00002792 sstr.Printf ("target_%d", instance_count);
2793 ++instance_count;
2794
2795 const ConstString ret_val (sstr.GetData());
2796 return ret_val;
2797}
2798
2799//--------------------------------------------------
2800// Target::SettingsController Variable Tables
2801//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00002802OptionEnumValueElement
2803TargetInstanceSettings::g_dynamic_value_types[] =
2804{
Greg Clayton577fbc32011-05-30 00:39:48 +00002805{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2806{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2807{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham10de7d12011-05-04 03:43:18 +00002808{ 0, NULL, NULL }
2809};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002810
2811SettingEntry
2812Target::SettingsController::global_settings_table[] =
2813{
Greg Claytond284b662011-02-18 01:44:25 +00002814 // var-name var-type default enum init'd hidden help-text
2815 // ================= ================== =========== ==== ====== ====== =========================================================================
2816 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2817 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2818};
2819
Caroline Tice5bc8c972010-09-20 20:44:43 +00002820SettingEntry
2821Target::SettingsController::instance_settings_table[] =
2822{
Enrico Granata91544802011-09-06 19:20:51 +00002823 // var-name var-type default enum init'd hidden help-text
2824 // ================= ================== =============== ======================= ====== ====== =========================================================================
2825 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2826 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2827 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2828 { 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 +00002829 { 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 +00002830 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2831 { 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 +00002832 { 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 +00002833 { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2834 { 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." },
2835 { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2836 { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
2837 { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
2838 { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
2839// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
2840 { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2841 { 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 +00002842 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002843};
Jim Ingham5a15e692012-02-16 06:50:00 +00002844
2845const ConstString &
2846Target::TargetEventData::GetFlavorString ()
2847{
2848 static ConstString g_flavor ("Target::TargetEventData");
2849 return g_flavor;
2850}
2851
2852const ConstString &
2853Target::TargetEventData::GetFlavor () const
2854{
2855 return TargetEventData::GetFlavorString ();
2856}
2857
2858Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2859 EventData(),
2860 m_target_sp (new_target_sp)
2861{
2862}
2863
2864Target::TargetEventData::~TargetEventData()
2865{
2866
2867}
2868
2869void
2870Target::TargetEventData::Dump (Stream *s) const
2871{
2872
2873}
2874
2875const TargetSP
2876Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2877{
2878 TargetSP target_sp;
2879
2880 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2881 if (data)
2882 target_sp = data->m_target_sp;
2883
2884 return target_sp;
2885}
2886
2887const Target::TargetEventData *
2888Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2889{
2890 if (event_ptr)
2891 {
2892 const EventData *event_data = event_ptr->GetData();
2893 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2894 return static_cast <const TargetEventData *> (event_ptr->GetData());
2895 }
2896 return NULL;
2897}
2898