blob: 3a26b77ed30b4b5d8daa58b237377621e73fde44 [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
290
291SearchFilterSP
292Target::GetSearchFilterForModule (const FileSpec *containingModule)
293{
294 SearchFilterSP filter_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000295 if (containingModule != NULL)
296 {
297 // TODO: We should look into sharing module based search filters
298 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000299 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner24943d22010-06-08 16:52:24 +0000300 }
301 else
302 {
303 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000304 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000305 filter_sp = m_search_filter_sp;
306 }
307 return filter_sp;
308}
309
Jim Ingham03c8ee52011-09-21 01:17:13 +0000310SearchFilterSP
311Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
312{
313 SearchFilterSP filter_sp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000314 if (containingModules && containingModules->GetSize() != 0)
315 {
316 // TODO: We should look into sharing module based search filters
317 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000318 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000319 }
320 else
321 {
322 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000323 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000324 filter_sp = m_search_filter_sp;
325 }
326 return filter_sp;
327}
328
Jim Inghamd6d47972011-09-23 00:54:11 +0000329SearchFilterSP
330Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles)
331{
332 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
333 return GetSearchFilterForModuleList(containingModules);
334
335 SearchFilterSP filter_sp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000336 if (containingModules == NULL)
337 {
338 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
339 // but that will take a little reworking.
340
Greg Clayton13d24fb2012-01-29 20:56:30 +0000341 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000342 }
343 else
344 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000345 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000346 }
347 return filter_sp;
348}
349
Chris Lattner24943d22010-06-08 16:52:24 +0000350BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000351Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
352 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000353 RegularExpression &func_regex,
354 bool internal,
355 LazyBool skip_prologue)
Chris Lattner24943d22010-06-08 16:52:24 +0000356{
Jim Inghamd6d47972011-09-23 00:54:11 +0000357 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000358 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
359 func_regex,
360 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000361
362 return CreateBreakpoint (filter_sp, resolver_sp, internal);
363}
364
365BreakpointSP
366Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
367{
368 BreakpointSP bp_sp;
369 if (filter_sp && resolver_sp)
370 {
371 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
372 resolver_sp->SetBreakpoint (bp_sp.get());
373
374 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000375 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000376 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000377 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000378
Greg Claytone005f2c2010-11-06 01:53:30 +0000379 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000380 if (log)
381 {
382 StreamString s;
383 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
384 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
385 }
386
Chris Lattner24943d22010-06-08 16:52:24 +0000387 bp_sp->ResolveBreakpoint();
388 }
Jim Inghamd1686902010-10-14 23:45:03 +0000389
390 if (!internal && bp_sp)
391 {
392 m_last_created_breakpoint = bp_sp;
393 }
394
Chris Lattner24943d22010-06-08 16:52:24 +0000395 return bp_sp;
396}
397
Johnny Chenda5a8022011-09-20 23:28:55 +0000398bool
399Target::ProcessIsValid()
400{
401 return (m_process_sp && m_process_sp->IsAlive());
402}
403
Johnny Chenecd4feb2011-10-14 00:42:25 +0000404// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000405// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000406WatchpointSP
407Target::CreateWatchpoint(lldb::addr_t addr, size_t size, uint32_t type)
Johnny Chen34bbf852011-09-12 23:38:44 +0000408{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000409 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
410 if (log)
411 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
412 __FUNCTION__, addr, size, type);
413
Johnny Chenecd4feb2011-10-14 00:42:25 +0000414 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000415 if (!ProcessIsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000416 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000417 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chenecd4feb2011-10-14 00:42:25 +0000418 return wp_sp;
Johnny Chen9bf11992011-09-13 01:15:36 +0000419
Johnny Chenecd4feb2011-10-14 00:42:25 +0000420 // Currently we only support one watchpoint per address, with total number
421 // of watchpoints limited by the hardware which the inferior is running on.
422 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000423 if (matched_sp)
424 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000425 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000426 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000427 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
428 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000429 // Return the existing watchpoint if both size and type match.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000430 if (size == old_size && type == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000431 wp_sp = matched_sp;
432 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000433 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000434 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000435 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000436 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000437 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000438 }
439
Johnny Chenecd4feb2011-10-14 00:42:25 +0000440 if (!wp_sp) {
441 Watchpoint *new_wp = new Watchpoint(addr, size);
442 if (!new_wp) {
443 printf("Watchpoint ctor failed, out of memory?\n");
444 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000445 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000446 new_wp->SetWatchpointType(type);
447 new_wp->SetTarget(this);
448 wp_sp.reset(new_wp);
449 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000450 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000451
Johnny Chenecd4feb2011-10-14 00:42:25 +0000452 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000453 if (log)
454 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
455 __FUNCTION__,
456 rc.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000457 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000458
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000459 if (rc.Fail())
Johnny Chenecd4feb2011-10-14 00:42:25 +0000460 wp_sp.reset();
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000461 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000462 m_last_created_watchpoint = wp_sp;
463 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000464}
465
Chris Lattner24943d22010-06-08 16:52:24 +0000466void
467Target::RemoveAllBreakpoints (bool internal_also)
468{
Greg Claytone005f2c2010-11-06 01:53:30 +0000469 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000470 if (log)
471 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
472
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000473 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000474 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000475 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000476
477 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000478}
479
480void
481Target::DisableAllBreakpoints (bool internal_also)
482{
Greg Claytone005f2c2010-11-06 01:53:30 +0000483 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000484 if (log)
485 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
486
487 m_breakpoint_list.SetEnabledAll (false);
488 if (internal_also)
489 m_internal_breakpoint_list.SetEnabledAll (false);
490}
491
492void
493Target::EnableAllBreakpoints (bool internal_also)
494{
Greg Claytone005f2c2010-11-06 01:53:30 +0000495 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000496 if (log)
497 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
498
499 m_breakpoint_list.SetEnabledAll (true);
500 if (internal_also)
501 m_internal_breakpoint_list.SetEnabledAll (true);
502}
503
504bool
505Target::RemoveBreakpointByID (break_id_t break_id)
506{
Greg Claytone005f2c2010-11-06 01:53:30 +0000507 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000508 if (log)
509 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
510
511 if (DisableBreakpointByID (break_id))
512 {
513 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000514 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000515 else
Jim Inghamd1686902010-10-14 23:45:03 +0000516 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000517 if (m_last_created_breakpoint)
518 {
519 if (m_last_created_breakpoint->GetID() == break_id)
520 m_last_created_breakpoint.reset();
521 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000522 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000523 }
Chris Lattner24943d22010-06-08 16:52:24 +0000524 return true;
525 }
526 return false;
527}
528
529bool
530Target::DisableBreakpointByID (break_id_t break_id)
531{
Greg Claytone005f2c2010-11-06 01:53:30 +0000532 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000533 if (log)
534 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
535
536 BreakpointSP bp_sp;
537
538 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
539 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
540 else
541 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
542 if (bp_sp)
543 {
544 bp_sp->SetEnabled (false);
545 return true;
546 }
547 return false;
548}
549
550bool
551Target::EnableBreakpointByID (break_id_t break_id)
552{
Greg Claytone005f2c2010-11-06 01:53:30 +0000553 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000554 if (log)
555 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
556 __FUNCTION__,
557 break_id,
558 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
559
560 BreakpointSP bp_sp;
561
562 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
563 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
564 else
565 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
566
567 if (bp_sp)
568 {
569 bp_sp->SetEnabled (true);
570 return true;
571 }
572 return false;
573}
574
Johnny Chenc86582f2011-09-23 21:21:43 +0000575// The flag 'end_to_end', default to true, signifies that the operation is
576// performed end to end, for both the debugger and the debuggee.
577
Johnny Chenecd4feb2011-10-14 00:42:25 +0000578// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
579// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000580bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000581Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000582{
583 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
584 if (log)
585 log->Printf ("Target::%s\n", __FUNCTION__);
586
Johnny Chenc86582f2011-09-23 21:21:43 +0000587 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000588 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000589 return true;
590 }
591
592 // Otherwise, it's an end to end operation.
593
Johnny Chenda5a8022011-09-20 23:28:55 +0000594 if (!ProcessIsValid())
595 return false;
596
Johnny Chenecd4feb2011-10-14 00:42:25 +0000597 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000598 for (size_t i = 0; i < num_watchpoints; ++i)
599 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000600 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
601 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000602 return false;
603
Johnny Chenecd4feb2011-10-14 00:42:25 +0000604 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000605 if (rc.Fail())
606 return false;
607 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000608 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000609 return true; // Success!
610}
611
Johnny Chenecd4feb2011-10-14 00:42:25 +0000612// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
613// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000614bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000615Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000616{
617 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
618 if (log)
619 log->Printf ("Target::%s\n", __FUNCTION__);
620
Johnny Chenc86582f2011-09-23 21:21:43 +0000621 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000622 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000623 return true;
624 }
625
626 // Otherwise, it's an end to end operation.
627
Johnny Chenda5a8022011-09-20 23:28:55 +0000628 if (!ProcessIsValid())
629 return false;
630
Johnny Chenecd4feb2011-10-14 00:42:25 +0000631 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000632 for (size_t i = 0; i < num_watchpoints; ++i)
633 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000634 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
635 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000636 return false;
637
Johnny Chenecd4feb2011-10-14 00:42:25 +0000638 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000639 if (rc.Fail())
640 return false;
641 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000642 return true; // Success!
643}
644
Johnny Chenecd4feb2011-10-14 00:42:25 +0000645// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
646// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000647bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000648Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000649{
650 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
651 if (log)
652 log->Printf ("Target::%s\n", __FUNCTION__);
653
Johnny Chenc86582f2011-09-23 21:21:43 +0000654 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000655 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000656 return true;
657 }
658
659 // Otherwise, it's an end to end operation.
660
Johnny Chenda5a8022011-09-20 23:28:55 +0000661 if (!ProcessIsValid())
662 return false;
663
Johnny Chenecd4feb2011-10-14 00:42:25 +0000664 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000665 for (size_t i = 0; i < num_watchpoints; ++i)
666 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000667 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
668 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000669 return false;
670
Johnny Chenecd4feb2011-10-14 00:42:25 +0000671 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000672 if (rc.Fail())
673 return false;
674 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000675 return true; // Success!
676}
677
Johnny Chen116a5cd2012-02-25 06:44:30 +0000678// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
679bool
680Target::ClearAllWatchpointHitCounts ()
681{
682 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
683 if (log)
684 log->Printf ("Target::%s\n", __FUNCTION__);
685
686 size_t num_watchpoints = m_watchpoint_list.GetSize();
687 for (size_t i = 0; i < num_watchpoints; ++i)
688 {
689 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
690 if (!wp_sp)
691 return false;
692
693 wp_sp->ResetHitCount();
694 }
695 return true; // Success!
696}
697
Johnny Chenecd4feb2011-10-14 00:42:25 +0000698// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000699// during these operations.
700bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000701Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000702{
703 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
704 if (log)
705 log->Printf ("Target::%s\n", __FUNCTION__);
706
707 if (!ProcessIsValid())
708 return false;
709
Johnny Chenecd4feb2011-10-14 00:42:25 +0000710 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000711 for (size_t i = 0; i < num_watchpoints; ++i)
712 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000713 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
714 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000715 return false;
716
Johnny Chenecd4feb2011-10-14 00:42:25 +0000717 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000718 }
719 return true; // Success!
720}
721
Johnny Chenecd4feb2011-10-14 00:42:25 +0000722// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000723bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000724Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000725{
726 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
727 if (log)
728 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
729
730 if (!ProcessIsValid())
731 return false;
732
Johnny Chenecd4feb2011-10-14 00:42:25 +0000733 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
734 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000735 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000736 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000737 if (rc.Success())
738 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000739
Johnny Chen01acfa72011-09-22 18:04:58 +0000740 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000741 }
742 return false;
743}
744
Johnny Chenecd4feb2011-10-14 00:42:25 +0000745// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000746bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000747Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000748{
749 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
750 if (log)
751 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
752
753 if (!ProcessIsValid())
754 return false;
755
Johnny Chenecd4feb2011-10-14 00:42:25 +0000756 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
757 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000758 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000759 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000760 if (rc.Success())
761 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000762
Johnny Chen01acfa72011-09-22 18:04:58 +0000763 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000764 }
765 return false;
766}
767
Johnny Chenecd4feb2011-10-14 00:42:25 +0000768// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000769bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000770Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000771{
772 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
773 if (log)
774 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
775
Johnny Chenecd4feb2011-10-14 00:42:25 +0000776 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000777 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000778 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000779 return true;
780 }
781 return false;
782}
783
Johnny Chenecd4feb2011-10-14 00:42:25 +0000784// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000785bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000786Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000787{
788 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
789 if (log)
790 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
791
792 if (!ProcessIsValid())
793 return false;
794
Johnny Chenecd4feb2011-10-14 00:42:25 +0000795 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
796 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000797 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000798 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000799 return true;
800 }
801 return false;
802}
803
Chris Lattner24943d22010-06-08 16:52:24 +0000804ModuleSP
805Target::GetExecutableModule ()
806{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000807 return m_images.GetModuleAtIndex(0);
808}
809
810Module*
811Target::GetExecutableModulePointer ()
812{
813 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000814}
815
816void
817Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
818{
819 m_images.Clear();
820 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000821 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000822 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000823
824 if (executable_sp.get())
825 {
826 Timer scoped_timer (__PRETTY_FUNCTION__,
827 "Target::SetExecutableModule (executable = '%s/%s')",
828 executable_sp->GetFileSpec().GetDirectory().AsCString(),
829 executable_sp->GetFileSpec().GetFilename().AsCString());
830
831 m_images.Append(executable_sp); // The first image is our exectuable file
832
Jim Ingham7508e732010-08-09 23:31:02 +0000833 // 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 +0000834 if (!m_arch.IsValid())
835 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000836
Chris Lattner24943d22010-06-08 16:52:24 +0000837 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000838 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000839
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000840 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +0000841 {
842 executable_objfile->GetDependentModules(dependent_files);
843 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
844 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000845 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
846 FileSpec platform_dependent_file_spec;
847 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000848 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000849 else
850 platform_dependent_file_spec = dependent_file_spec;
851
852 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton24bc5d92011-03-30 18:16:51 +0000853 m_arch));
Chris Lattner24943d22010-06-08 16:52:24 +0000854 if (image_module_sp.get())
855 {
Chris Lattner24943d22010-06-08 16:52:24 +0000856 ObjectFile *objfile = image_module_sp->GetObjectFile();
857 if (objfile)
858 objfile->GetDependentModules(dependent_files);
859 }
860 }
861 }
Chris Lattner24943d22010-06-08 16:52:24 +0000862 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000863
864 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000865}
866
867
Jim Ingham7508e732010-08-09 23:31:02 +0000868bool
869Target::SetArchitecture (const ArchSpec &arch_spec)
870{
Greg Clayton24bc5d92011-03-30 18:16:51 +0000871 if (m_arch == arch_spec)
Jim Ingham7508e732010-08-09 23:31:02 +0000872 {
873 // If we're setting the architecture to our current architecture, we
874 // don't need to do anything.
875 return true;
876 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000877 else if (!m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000878 {
879 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000880 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000881 return true;
882 }
883 else
884 {
885 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000886 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000887 ModuleSP executable_sp = GetExecutableModule ();
888 m_images.Clear();
889 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000890 m_scratch_ast_source_ap.reset();
891 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000892 // Need to do something about unsetting breakpoints.
893
894 if (executable_sp)
895 {
896 FileSpec exec_file_spec = executable_sp->GetFileSpec();
897 Error error = ModuleList::GetSharedModule(exec_file_spec,
898 arch_spec,
899 NULL,
900 NULL,
901 0,
902 executable_sp,
Greg Clayton9ce95382012-02-13 23:10:39 +0000903 &GetExecutableSearchPaths(),
Jim Ingham7508e732010-08-09 23:31:02 +0000904 NULL,
905 NULL);
906
907 if (!error.Fail() && executable_sp)
908 {
909 SetExecutableModule (executable_sp, true);
910 return true;
911 }
912 else
913 {
914 return false;
915 }
916 }
917 else
918 {
919 return false;
920 }
921 }
922}
Chris Lattner24943d22010-06-08 16:52:24 +0000923
Chris Lattner24943d22010-06-08 16:52:24 +0000924void
925Target::ModuleAdded (ModuleSP &module_sp)
926{
927 // A module is being added to this target for the first time
928 ModuleList module_list;
929 module_list.Append(module_sp);
930 ModulesDidLoad (module_list);
931}
932
933void
934Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
935{
Jim Ingham3b8a6052011-08-03 01:00:06 +0000936 // A module is replacing an already added module
Chris Lattner24943d22010-06-08 16:52:24 +0000937 ModuleList module_list;
938 module_list.Append (old_module_sp);
939 ModulesDidUnload (module_list);
940 module_list.Clear ();
941 module_list.Append (new_module_sp);
942 ModulesDidLoad (module_list);
943}
944
945void
946Target::ModulesDidLoad (ModuleList &module_list)
947{
948 m_breakpoint_list.UpdateBreakpoints (module_list, true);
949 // TODO: make event data that packages up the module_list
950 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
951}
952
953void
954Target::ModulesDidUnload (ModuleList &module_list)
955{
956 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000957
958 // Remove the images from the target image list
959 m_images.Remove(module_list);
960
Chris Lattner24943d22010-06-08 16:52:24 +0000961 // TODO: make event data that packages up the module_list
962 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
963}
964
Jim Ingham7089d8a2011-10-28 23:14:11 +0000965
Daniel Dunbar705a0982011-10-31 22:50:37 +0000966bool
Jim Ingham7089d8a2011-10-28 23:14:11 +0000967Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec)
968{
969
970 if (!m_breakpoints_use_platform_avoid)
971 return false;
972 else
973 {
974 ModuleList matchingModules;
975 const ArchSpec *arch_ptr = NULL;
976 const lldb_private::UUID *uuid_ptr= NULL;
977 const ConstString *object_name = NULL;
978 size_t num_modules = GetImages().FindModules(&module_spec, arch_ptr, uuid_ptr, object_name, matchingModules);
979
980 // If there is more than one module for this file spec, only return true if ALL the modules are on the
981 // black list.
982 if (num_modules > 0)
983 {
984 for (int i = 0; i < num_modules; i++)
985 {
986 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
987 return false;
988 }
989 return true;
990 }
991 else
992 return false;
993 }
994}
995
Daniel Dunbar705a0982011-10-31 22:50:37 +0000996bool
Jim Ingham7089d8a2011-10-28 23:14:11 +0000997Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
998{
999 if (!m_breakpoints_use_platform_avoid)
1000 return false;
1001 else if (GetPlatform())
1002 {
1003 return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
1004 }
1005 else
1006 return false;
1007}
1008
Chris Lattner24943d22010-06-08 16:52:24 +00001009size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001010Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1011{
Greg Clayton3508c382012-02-24 01:59:29 +00001012 SectionSP section_sp (addr.GetSection());
1013 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001014 {
Greg Clayton3508c382012-02-24 01:59:29 +00001015 ModuleSP module_sp (section_sp->GetModule());
1016 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001017 {
Greg Clayton3508c382012-02-24 01:59:29 +00001018 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1019 if (objfile)
1020 {
1021 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1022 addr.GetOffset(),
1023 dst,
1024 dst_len);
1025 if (bytes_read > 0)
1026 return bytes_read;
1027 else
1028 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1029 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001030 else
Greg Clayton3508c382012-02-24 01:59:29 +00001031 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001032 }
1033 else
Greg Clayton3508c382012-02-24 01:59:29 +00001034 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001035 }
1036 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001037 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001038
Greg Clayton26100dc2011-01-07 01:57:07 +00001039 return 0;
1040}
1041
1042size_t
Enrico Granata91544802011-09-06 19:20:51 +00001043Target::ReadMemory (const Address& addr,
1044 bool prefer_file_cache,
1045 void *dst,
1046 size_t dst_len,
1047 Error &error,
1048 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001049{
Chris Lattner24943d22010-06-08 16:52:24 +00001050 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001051
Enrico Granata91544802011-09-06 19:20:51 +00001052 // if we end up reading this from process memory, we will fill this
1053 // with the actual load address
1054 if (load_addr_ptr)
1055 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1056
Greg Clayton26100dc2011-01-07 01:57:07 +00001057 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001058
1059 addr_t load_addr = LLDB_INVALID_ADDRESS;
1060 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001061 Address resolved_addr;
1062 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001063 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001064 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001065 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001066 // No sections are loaded, so we must assume we are not running
1067 // yet and anything we are given is a file address.
1068 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1069 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001070 }
Greg Clayton70436352010-06-30 23:03:03 +00001071 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001072 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001073 // We have at least one section loaded. This can be becuase
1074 // we have manually loaded some sections with "target modules load ..."
1075 // or because we have have a live process that has sections loaded
1076 // through the dynamic loader
1077 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1078 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001079 }
Greg Clayton70436352010-06-30 23:03:03 +00001080 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001081 if (!resolved_addr.IsValid())
1082 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001083
Greg Clayton9b82f862011-07-11 05:12:02 +00001084
Greg Clayton26100dc2011-01-07 01:57:07 +00001085 if (prefer_file_cache)
1086 {
1087 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1088 if (bytes_read > 0)
1089 return bytes_read;
1090 }
Greg Clayton70436352010-06-30 23:03:03 +00001091
Johnny Chenda5a8022011-09-20 23:28:55 +00001092 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001093 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001094 if (load_addr == LLDB_INVALID_ADDRESS)
1095 load_addr = resolved_addr.GetLoadAddress (this);
1096
Greg Clayton70436352010-06-30 23:03:03 +00001097 if (load_addr == LLDB_INVALID_ADDRESS)
1098 {
Greg Clayton3508c382012-02-24 01:59:29 +00001099 ModuleSP addr_module_sp (resolved_addr.GetModule());
1100 if (addr_module_sp && addr_module_sp->GetFileSpec())
Greg Clayton9c236732011-10-26 00:56:27 +00001101 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001102 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001103 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001104 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001105 else
Greg Clayton9c236732011-10-26 00:56:27 +00001106 error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001107 }
1108 else
1109 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001110 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001111 if (bytes_read != dst_len)
1112 {
1113 if (error.Success())
1114 {
1115 if (bytes_read == 0)
Greg Clayton9c236732011-10-26 00:56:27 +00001116 error.SetErrorStringWithFormat("read memory from 0x%llx failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001117 else
Greg Clayton9c236732011-10-26 00:56:27 +00001118 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 +00001119 }
1120 }
Greg Clayton70436352010-06-30 23:03:03 +00001121 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001122 {
1123 if (load_addr_ptr)
1124 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001125 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001126 }
Greg Clayton70436352010-06-30 23:03:03 +00001127 // If the address is not section offset we have an address that
1128 // doesn't resolve to any address in any currently loaded shared
1129 // libaries and we failed to read memory so there isn't anything
1130 // more we can do. If it is section offset, we might be able to
1131 // read cached memory from the object file.
1132 if (!resolved_addr.IsSectionOffset())
1133 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001134 }
Chris Lattner24943d22010-06-08 16:52:24 +00001135 }
Greg Clayton70436352010-06-30 23:03:03 +00001136
Greg Clayton9b82f862011-07-11 05:12:02 +00001137 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001138 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001139 // If we didn't already try and read from the object file cache, then
1140 // try it after failing to read from the process.
1141 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001142 }
1143 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001144}
1145
Greg Clayton7dd98df2011-07-12 17:06:17 +00001146size_t
1147Target::ReadScalarIntegerFromMemory (const Address& addr,
1148 bool prefer_file_cache,
1149 uint32_t byte_size,
1150 bool is_signed,
1151 Scalar &scalar,
1152 Error &error)
1153{
1154 uint64_t uval;
1155
1156 if (byte_size <= sizeof(uval))
1157 {
1158 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1159 if (bytes_read == byte_size)
1160 {
1161 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1162 uint32_t offset = 0;
1163 if (byte_size <= 4)
1164 scalar = data.GetMaxU32 (&offset, byte_size);
1165 else
1166 scalar = data.GetMaxU64 (&offset, byte_size);
1167
1168 if (is_signed)
1169 scalar.SignExtend(byte_size * 8);
1170 return bytes_read;
1171 }
1172 }
1173 else
1174 {
1175 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1176 }
1177 return 0;
1178}
1179
1180uint64_t
1181Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1182 bool prefer_file_cache,
1183 size_t integer_byte_size,
1184 uint64_t fail_value,
1185 Error &error)
1186{
1187 Scalar scalar;
1188 if (ReadScalarIntegerFromMemory (addr,
1189 prefer_file_cache,
1190 integer_byte_size,
1191 false,
1192 scalar,
1193 error))
1194 return scalar.ULongLong(fail_value);
1195 return fail_value;
1196}
1197
1198bool
1199Target::ReadPointerFromMemory (const Address& addr,
1200 bool prefer_file_cache,
1201 Error &error,
1202 Address &pointer_addr)
1203{
1204 Scalar scalar;
1205 if (ReadScalarIntegerFromMemory (addr,
1206 prefer_file_cache,
1207 m_arch.GetAddressByteSize(),
1208 false,
1209 scalar,
1210 error))
1211 {
1212 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1213 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1214 {
1215 if (m_section_load_list.IsEmpty())
1216 {
1217 // No sections are loaded, so we must assume we are not running
1218 // yet and anything we are given is a file address.
1219 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1220 }
1221 else
1222 {
1223 // We have at least one section loaded. This can be becuase
1224 // we have manually loaded some sections with "target modules load ..."
1225 // or because we have have a live process that has sections loaded
1226 // through the dynamic loader
1227 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1228 }
1229 // We weren't able to resolve the pointer value, so just return
1230 // an address with no section
1231 if (!pointer_addr.IsValid())
1232 pointer_addr.SetOffset (pointer_vm_addr);
1233 return true;
1234
1235 }
1236 }
1237 return false;
1238}
Chris Lattner24943d22010-06-08 16:52:24 +00001239
1240ModuleSP
1241Target::GetSharedModule
1242(
1243 const FileSpec& file_spec,
1244 const ArchSpec& arch,
Greg Clayton0467c782011-02-04 18:53:10 +00001245 const lldb_private::UUID *uuid_ptr,
Chris Lattner24943d22010-06-08 16:52:24 +00001246 const ConstString *object_name,
1247 off_t object_offset,
1248 Error *error_ptr
1249)
1250{
1251 // Don't pass in the UUID so we can tell if we have a stale value in our list
1252 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1253 bool did_create_module = false;
1254 ModuleSP module_sp;
1255
Chris Lattner24943d22010-06-08 16:52:24 +00001256 Error error;
1257
Greg Clayton24bc5d92011-03-30 18:16:51 +00001258 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +00001259 if (m_image_search_paths.GetSize())
1260 {
1261 FileSpec transformed_spec;
1262 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
1263 {
1264 transformed_spec.GetFilename() = file_spec.GetFilename();
Greg Clayton9ce95382012-02-13 23:10:39 +00001265 error = ModuleList::GetSharedModule (transformed_spec,
1266 arch,
1267 uuid_ptr,
1268 object_name,
1269 object_offset,
1270 module_sp,
1271 &GetExecutableSearchPaths(),
1272 &old_module_sp,
1273 &did_create_module);
Chris Lattner24943d22010-06-08 16:52:24 +00001274 }
1275 }
1276
Greg Clayton24bc5d92011-03-30 18:16:51 +00001277 // The platform is responsible for finding and caching an appropriate
1278 // module in the shared module cache.
1279 if (m_platform_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001280 {
Greg Clayton24bc5d92011-03-30 18:16:51 +00001281 FileSpec platform_file_spec;
1282 error = m_platform_sp->GetSharedModule (file_spec,
1283 arch,
1284 uuid_ptr,
1285 object_name,
1286 object_offset,
1287 module_sp,
Greg Clayton9ce95382012-02-13 23:10:39 +00001288 &GetExecutableSearchPaths(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001289 &old_module_sp,
1290 &did_create_module);
1291 }
1292 else
1293 {
1294 error.SetErrorString("no platform is currently set");
Chris Lattner24943d22010-06-08 16:52:24 +00001295 }
1296
Greg Clayton24bc5d92011-03-30 18:16:51 +00001297 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +00001298 if (module_sp)
1299 {
1300 m_images.Append (module_sp);
1301 if (did_create_module)
1302 {
1303 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1304 ModuleUpdated(old_module_sp, module_sp);
1305 else
1306 ModuleAdded(module_sp);
1307 }
1308 }
1309 if (error_ptr)
1310 *error_ptr = error;
1311 return module_sp;
1312}
1313
1314
Greg Clayton289afcb2012-02-18 05:35:26 +00001315TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001316Target::CalculateTarget ()
1317{
Greg Clayton289afcb2012-02-18 05:35:26 +00001318 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001319}
1320
Greg Clayton289afcb2012-02-18 05:35:26 +00001321ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001322Target::CalculateProcess ()
1323{
Greg Clayton289afcb2012-02-18 05:35:26 +00001324 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001325}
1326
Greg Clayton289afcb2012-02-18 05:35:26 +00001327ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001328Target::CalculateThread ()
1329{
Greg Clayton289afcb2012-02-18 05:35:26 +00001330 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001331}
1332
Greg Clayton289afcb2012-02-18 05:35:26 +00001333StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001334Target::CalculateStackFrame ()
1335{
Greg Clayton289afcb2012-02-18 05:35:26 +00001336 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001337}
1338
1339void
Greg Claytona830adb2010-10-04 01:05:56 +00001340Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001341{
Greg Clayton567e7f32011-09-22 04:58:26 +00001342 exe_ctx.Clear();
1343 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001344}
1345
1346PathMappingList &
1347Target::GetImageSearchPathList ()
1348{
1349 return m_image_search_paths;
1350}
1351
1352void
1353Target::ImageSearchPathsChanged
1354(
1355 const PathMappingList &path_list,
1356 void *baton
1357)
1358{
1359 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001360 ModuleSP exe_module_sp (target->GetExecutableModule());
1361 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001362 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001363 target->m_images.Clear();
1364 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001365 }
1366}
1367
1368ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001369Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001370{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001371 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001372 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001373 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001374 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001375 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001376 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1377 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1378 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1379 }
Chris Lattner24943d22010-06-08 16:52:24 +00001380 return m_scratch_ast_context_ap.get();
1381}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001382
Sean Callanan4938bd62011-11-16 18:20:47 +00001383ClangASTImporter *
1384Target::GetClangASTImporter()
1385{
1386 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1387
1388 if (!ast_importer)
1389 {
1390 ast_importer = new ClangASTImporter();
1391 m_ast_importer_ap.reset(ast_importer);
1392 }
1393
1394 return ast_importer;
1395}
1396
Greg Clayton990de7b2010-11-18 23:32:35 +00001397void
Caroline Tice2a456812011-03-10 22:14:10 +00001398Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001399{
Greg Clayton334d33a2012-01-30 07:41:31 +00001400 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001401 SettingsController::global_settings_table,
1402 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001403
1404 // Now call SettingsInitialize() on each 'child' setting of Target
1405 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001406}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001407
Greg Clayton990de7b2010-11-18 23:32:35 +00001408void
Caroline Tice2a456812011-03-10 22:14:10 +00001409Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001410{
Caroline Tice2a456812011-03-10 22:14:10 +00001411
1412 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1413
1414 Process::SettingsTerminate ();
1415
1416 // Now terminate Target Settings.
1417
Greg Clayton990de7b2010-11-18 23:32:35 +00001418 UserSettingsControllerSP &usc = GetSettingsController();
1419 UserSettingsController::FinalizeSettingsController (usc);
1420 usc.reset();
1421}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001422
Greg Clayton990de7b2010-11-18 23:32:35 +00001423UserSettingsControllerSP &
1424Target::GetSettingsController ()
1425{
Greg Clayton334d33a2012-01-30 07:41:31 +00001426 static UserSettingsControllerSP g_settings_controller_sp;
1427 if (!g_settings_controller_sp)
1428 {
1429 g_settings_controller_sp.reset (new Target::SettingsController);
1430 // The first shared pointer to Target::SettingsController in
1431 // g_settings_controller_sp must be fully created above so that
1432 // the TargetInstanceSettings can use a weak_ptr to refer back
1433 // to the master setttings controller
1434 InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp,
1435 false,
1436 InstanceSettings::GetDefaultName().AsCString()));
1437 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1438 }
1439 return g_settings_controller_sp;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001440}
1441
Greg Clayton9ce95382012-02-13 23:10:39 +00001442FileSpecList
1443Target::GetDefaultExecutableSearchPaths ()
1444{
1445 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1446 if (settings_controller_sp)
1447 {
1448 lldb::InstanceSettingsSP instance_settings_sp (settings_controller_sp->GetDefaultInstanceSettings ());
1449 if (instance_settings_sp)
1450 return static_cast<TargetInstanceSettings *>(instance_settings_sp.get())->GetExecutableSearchPaths ();
1451 }
1452 return FileSpecList();
1453}
1454
1455
Caroline Tice5bc8c972010-09-20 20:44:43 +00001456ArchSpec
1457Target::GetDefaultArchitecture ()
1458{
Greg Clayton940b1032011-02-23 00:35:02 +00001459 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1460
1461 if (settings_controller_sp)
1462 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1463 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001464}
1465
1466void
Greg Clayton940b1032011-02-23 00:35:02 +00001467Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001468{
Greg Clayton940b1032011-02-23 00:35:02 +00001469 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1470
1471 if (settings_controller_sp)
1472 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001473}
1474
Greg Claytona830adb2010-10-04 01:05:56 +00001475Target *
1476Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1477{
1478 // The target can either exist in the "process" of ExecutionContext, or in
1479 // the "target_sp" member of SymbolContext. This accessor helper function
1480 // will get the target from one of these locations.
1481
1482 Target *target = NULL;
1483 if (sc_ptr != NULL)
1484 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001485 if (target == NULL && exe_ctx_ptr)
1486 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001487 return target;
1488}
1489
1490
Caroline Tice1ebef442010-09-27 00:30:10 +00001491void
1492Target::UpdateInstanceName ()
1493{
1494 StreamString sstr;
1495
Greg Clayton5beb99d2011-08-11 02:48:45 +00001496 Module *exe_module = GetExecutableModulePointer();
1497 if (exe_module)
Caroline Tice1ebef442010-09-27 00:30:10 +00001498 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001499 sstr.Printf ("%s_%s",
Greg Clayton5beb99d2011-08-11 02:48:45 +00001500 exe_module->GetFileSpec().GetFilename().AsCString(),
1501 exe_module->GetArchitecture().GetArchitectureName());
1502 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +00001503 }
1504}
1505
Sean Callanan77e93942010-10-29 00:29:03 +00001506const char *
1507Target::GetExpressionPrefixContentsAsCString ()
1508{
Sean Callanane0b7f942011-11-16 01:54:57 +00001509 if (!m_expr_prefix_contents.empty())
1510 return m_expr_prefix_contents.c_str();
Greg Claytonff44ab42011-04-23 02:04:55 +00001511 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +00001512}
1513
Greg Clayton427f2902010-12-14 02:59:59 +00001514ExecutionResults
1515Target::EvaluateExpression
1516(
1517 const char *expr_cstr,
1518 StackFrame *frame,
Sean Callanan47dc4572011-09-15 02:13:07 +00001519 lldb_private::ExecutionPolicy execution_policy,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001520 bool coerce_to_id,
Greg Clayton427f2902010-12-14 02:59:59 +00001521 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +00001522 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +00001523 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +00001524 lldb::ValueObjectSP &result_valobj_sp
1525)
1526{
1527 ExecutionResults execution_results = eExecutionSetupError;
1528
1529 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001530
1531 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1532 return execution_results;
1533
Jim Ingham3613ae12011-05-12 02:06:14 +00001534 // We shouldn't run stop hooks in expressions.
1535 // Be sure to reset this if you return anywhere within this function.
1536 bool old_suppress_value = m_suppress_stop_hooks;
1537 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001538
1539 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001540
1541 const size_t expr_cstr_len = ::strlen (expr_cstr);
1542
Greg Clayton427f2902010-12-14 02:59:59 +00001543 if (frame)
1544 {
1545 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001546 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001547 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001548 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1549 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001550 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001551
1552 // Make sure we don't have any things that we know a variable expression
1553 // won't be able to deal with before calling into it
1554 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1555 {
1556 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1557 use_dynamic,
1558 expr_path_options,
1559 var_sp,
1560 error);
1561 }
Greg Clayton427f2902010-12-14 02:59:59 +00001562 }
1563 else if (m_process_sp)
1564 {
1565 m_process_sp->CalculateExecutionContext(exe_ctx);
1566 }
1567 else
1568 {
1569 CalculateExecutionContext(exe_ctx);
1570 }
1571
1572 if (result_valobj_sp)
1573 {
1574 execution_results = eExecutionCompleted;
1575 // We got a result from the frame variable expression path above...
1576 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1577
1578 lldb::ValueObjectSP const_valobj_sp;
1579
1580 // Check in case our value is already a constant value
1581 if (result_valobj_sp->GetIsConstant())
1582 {
1583 const_valobj_sp = result_valobj_sp;
1584 const_valobj_sp->SetName (persistent_variable_name);
1585 }
1586 else
Jim Inghame41494a2011-04-16 00:01:13 +00001587 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001588 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001589 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001590 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +00001591 if (dynamic_sp)
1592 result_valobj_sp = dynamic_sp;
1593 }
1594
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001595 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001596 }
Greg Clayton427f2902010-12-14 02:59:59 +00001597
Sean Callanan6a925532011-01-13 08:53:35 +00001598 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1599
Greg Clayton427f2902010-12-14 02:59:59 +00001600 result_valobj_sp = const_valobj_sp;
1601
Sean Callanan6a925532011-01-13 08:53:35 +00001602 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1603 assert (clang_expr_variable_sp.get());
1604
1605 // Set flags and live data as appropriate
1606
1607 const Value &result_value = live_valobj_sp->GetValue();
1608
1609 switch (result_value.GetValueType())
1610 {
1611 case Value::eValueTypeHostAddress:
1612 case Value::eValueTypeFileAddress:
1613 // we don't do anything with these for now
1614 break;
1615 case Value::eValueTypeScalar:
1616 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1617 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1618 break;
1619 case Value::eValueTypeLoadAddress:
1620 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1621 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1622 break;
1623 }
Greg Clayton427f2902010-12-14 02:59:59 +00001624 }
1625 else
1626 {
1627 // Make sure we aren't just trying to see the value of a persistent
1628 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001629 lldb::ClangExpressionVariableSP persistent_var_sp;
1630 // Only check for persistent variables the expression starts with a '$'
1631 if (expr_cstr[0] == '$')
1632 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1633
Greg Clayton427f2902010-12-14 02:59:59 +00001634 if (persistent_var_sp)
1635 {
1636 result_valobj_sp = persistent_var_sp->GetValueObject ();
1637 execution_results = eExecutionCompleted;
1638 }
1639 else
1640 {
1641 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001642
Greg Clayton427f2902010-12-14 02:59:59 +00001643 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +00001644 execution_policy,
Sean Callanan5b658cc2011-11-07 23:35:40 +00001645 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +00001646 coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
Sean Callanan6a925532011-01-13 08:53:35 +00001647 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001648 expr_cstr,
1649 prefix,
1650 result_valobj_sp);
1651 }
1652 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001653
1654 m_suppress_stop_hooks = old_suppress_value;
1655
Greg Clayton427f2902010-12-14 02:59:59 +00001656 return execution_results;
1657}
1658
Greg Claytonc0fa5332011-05-22 22:46:53 +00001659lldb::addr_t
1660Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1661{
1662 addr_t code_addr = load_addr;
1663 switch (m_arch.GetMachine())
1664 {
1665 case llvm::Triple::arm:
1666 case llvm::Triple::thumb:
1667 switch (addr_class)
1668 {
1669 case eAddressClassData:
1670 case eAddressClassDebug:
1671 return LLDB_INVALID_ADDRESS;
1672
1673 case eAddressClassUnknown:
1674 case eAddressClassInvalid:
1675 case eAddressClassCode:
1676 case eAddressClassCodeAlternateISA:
1677 case eAddressClassRuntime:
1678 // Check if bit zero it no set?
1679 if ((code_addr & 1ull) == 0)
1680 {
1681 // Bit zero isn't set, check if the address is a multiple of 2?
1682 if (code_addr & 2ull)
1683 {
1684 // The address is a multiple of 2 so it must be thumb, set bit zero
1685 code_addr |= 1ull;
1686 }
1687 else if (addr_class == eAddressClassCodeAlternateISA)
1688 {
1689 // We checked the address and the address claims to be the alternate ISA
1690 // which means thumb, so set bit zero.
1691 code_addr |= 1ull;
1692 }
1693 }
1694 break;
1695 }
1696 break;
1697
1698 default:
1699 break;
1700 }
1701 return code_addr;
1702}
1703
1704lldb::addr_t
1705Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1706{
1707 addr_t opcode_addr = load_addr;
1708 switch (m_arch.GetMachine())
1709 {
1710 case llvm::Triple::arm:
1711 case llvm::Triple::thumb:
1712 switch (addr_class)
1713 {
1714 case eAddressClassData:
1715 case eAddressClassDebug:
1716 return LLDB_INVALID_ADDRESS;
1717
1718 case eAddressClassInvalid:
1719 case eAddressClassUnknown:
1720 case eAddressClassCode:
1721 case eAddressClassCodeAlternateISA:
1722 case eAddressClassRuntime:
1723 opcode_addr &= ~(1ull);
1724 break;
1725 }
1726 break;
1727
1728 default:
1729 break;
1730 }
1731 return opcode_addr;
1732}
1733
Jim Inghamd60d94a2011-03-11 03:53:59 +00001734lldb::user_id_t
1735Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1736{
1737 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001738 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001739 m_stop_hooks[new_uid] = new_hook_sp;
1740 return new_uid;
1741}
1742
1743bool
1744Target::RemoveStopHookByID (lldb::user_id_t user_id)
1745{
1746 size_t num_removed;
1747 num_removed = m_stop_hooks.erase (user_id);
1748 if (num_removed == 0)
1749 return false;
1750 else
1751 return true;
1752}
1753
1754void
1755Target::RemoveAllStopHooks ()
1756{
1757 m_stop_hooks.clear();
1758}
1759
1760Target::StopHookSP
1761Target::GetStopHookByID (lldb::user_id_t user_id)
1762{
1763 StopHookSP found_hook;
1764
1765 StopHookCollection::iterator specified_hook_iter;
1766 specified_hook_iter = m_stop_hooks.find (user_id);
1767 if (specified_hook_iter != m_stop_hooks.end())
1768 found_hook = (*specified_hook_iter).second;
1769 return found_hook;
1770}
1771
1772bool
1773Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1774{
1775 StopHookCollection::iterator specified_hook_iter;
1776 specified_hook_iter = m_stop_hooks.find (user_id);
1777 if (specified_hook_iter == m_stop_hooks.end())
1778 return false;
1779
1780 (*specified_hook_iter).second->SetIsActive (active_state);
1781 return true;
1782}
1783
1784void
1785Target::SetAllStopHooksActiveState (bool active_state)
1786{
1787 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1788 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1789 {
1790 (*pos).second->SetIsActive (active_state);
1791 }
1792}
1793
1794void
1795Target::RunStopHooks ()
1796{
Jim Ingham3613ae12011-05-12 02:06:14 +00001797 if (m_suppress_stop_hooks)
1798 return;
1799
Jim Inghamd60d94a2011-03-11 03:53:59 +00001800 if (!m_process_sp)
1801 return;
1802
1803 if (m_stop_hooks.empty())
1804 return;
1805
1806 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1807
1808 // If there aren't any active stop hooks, don't bother either:
1809 bool any_active_hooks = false;
1810 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1811 {
1812 if ((*pos).second->IsActive())
1813 {
1814 any_active_hooks = true;
1815 break;
1816 }
1817 }
1818 if (!any_active_hooks)
1819 return;
1820
1821 CommandReturnObject result;
1822
1823 std::vector<ExecutionContext> exc_ctx_with_reasons;
1824 std::vector<SymbolContext> sym_ctx_with_reasons;
1825
1826 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1827 size_t num_threads = cur_threadlist.GetSize();
1828 for (size_t i = 0; i < num_threads; i++)
1829 {
1830 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1831 if (cur_thread_sp->ThreadStoppedForAReason())
1832 {
1833 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1834 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1835 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1836 }
1837 }
1838
1839 // If no threads stopped for a reason, don't run the stop-hooks.
1840 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1841 if (num_exe_ctx == 0)
1842 return;
1843
Jim Inghame5ed8e92011-06-02 23:58:26 +00001844 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1845 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001846
1847 bool keep_going = true;
1848 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001849 bool print_hook_header;
1850 bool print_thread_header;
1851
1852 if (num_exe_ctx == 1)
1853 print_thread_header = false;
1854 else
1855 print_thread_header = true;
1856
1857 if (m_stop_hooks.size() == 1)
1858 print_hook_header = false;
1859 else
1860 print_hook_header = true;
1861
Jim Inghamd60d94a2011-03-11 03:53:59 +00001862 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1863 {
1864 // result.Clear();
1865 StopHookSP cur_hook_sp = (*pos).second;
1866 if (!cur_hook_sp->IsActive())
1867 continue;
1868
1869 bool any_thread_matched = false;
1870 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1871 {
1872 if ((cur_hook_sp->GetSpecifier () == NULL
1873 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1874 && (cur_hook_sp->GetThreadSpecifier() == NULL
Greg Clayton567e7f32011-09-22 04:58:26 +00001875 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001876 {
1877 if (!hooks_ran)
1878 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00001879 hooks_ran = true;
1880 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001881 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001882 {
Johnny Chen4d96a742011-10-24 23:01:06 +00001883 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
1884 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
1885 NULL);
1886 if (cmd)
1887 result.AppendMessageWithFormat("\n- Hook %llu (%s)\n", cur_hook_sp->GetID(), cmd);
1888 else
1889 result.AppendMessageWithFormat("\n- Hook %llu\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001890 any_thread_matched = true;
1891 }
1892
Jim Inghamc54840c2011-03-22 01:47:27 +00001893 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00001894 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001895
1896 bool stop_on_continue = true;
1897 bool stop_on_error = true;
1898 bool echo_commands = false;
1899 bool print_results = true;
1900 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001901 &exc_ctx_with_reasons[i],
1902 stop_on_continue,
1903 stop_on_error,
1904 echo_commands,
1905 print_results,
1906 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001907
1908 // If the command started the target going again, we should bag out of
1909 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001910 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1911 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001912 {
Greg Clayton444e35b2011-10-19 18:09:39 +00001913 result.AppendMessageWithFormat ("Aborting stop hooks, hook %llu set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001914 keep_going = false;
1915 }
1916 }
1917 }
1918 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00001919
Caroline Tice4a348082011-05-02 20:41:46 +00001920 result.GetImmediateOutputStream()->Flush();
1921 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001922}
1923
Greg Claytonbbea1332011-07-08 00:48:09 +00001924bool
1925Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1926{
1927 bool changed = false;
1928 if (module)
1929 {
1930 ObjectFile *object_file = module->GetObjectFile();
1931 if (object_file)
1932 {
1933 SectionList *section_list = object_file->GetSectionList ();
1934 if (section_list)
1935 {
1936 // All sections listed in the dyld image info structure will all
1937 // either be fixed up already, or they will all be off by a single
1938 // slide amount that is determined by finding the first segment
1939 // that is at file offset zero which also has bytes (a file size
1940 // that is greater than zero) in the object file.
1941
1942 // Determine the slide amount (if any)
1943 const size_t num_sections = section_list->GetSize();
1944 size_t sect_idx = 0;
1945 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1946 {
1947 // Iterate through the object file sections to find the
1948 // first section that starts of file offset zero and that
1949 // has bytes in the file...
1950 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1951 if (section)
1952 {
1953 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1954 changed = true;
1955 }
1956 }
1957 }
1958 }
1959 }
1960 return changed;
1961}
1962
1963
Jim Inghamd60d94a2011-03-11 03:53:59 +00001964//--------------------------------------------------------------
1965// class Target::StopHook
1966//--------------------------------------------------------------
1967
1968
1969Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1970 UserID (uid),
1971 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00001972 m_commands (),
1973 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001974 m_thread_spec_ap(NULL),
1975 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001976{
1977}
1978
1979Target::StopHook::StopHook (const StopHook &rhs) :
1980 UserID (rhs.GetID()),
1981 m_target_sp (rhs.m_target_sp),
1982 m_commands (rhs.m_commands),
1983 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001984 m_thread_spec_ap (NULL),
1985 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001986{
1987 if (rhs.m_thread_spec_ap.get() != NULL)
1988 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1989}
1990
1991
1992Target::StopHook::~StopHook ()
1993{
1994}
1995
1996void
1997Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1998{
1999 m_thread_spec_ap.reset (specifier);
2000}
2001
2002
2003void
2004Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2005{
2006 int indent_level = s->GetIndentLevel();
2007
2008 s->SetIndentLevel(indent_level + 2);
2009
Greg Clayton444e35b2011-10-19 18:09:39 +00002010 s->Printf ("Hook: %llu\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002011 if (m_active)
2012 s->Indent ("State: enabled\n");
2013 else
2014 s->Indent ("State: disabled\n");
2015
2016 if (m_specifier_sp)
2017 {
2018 s->Indent();
2019 s->PutCString ("Specifier:\n");
2020 s->SetIndentLevel (indent_level + 4);
2021 m_specifier_sp->GetDescription (s, level);
2022 s->SetIndentLevel (indent_level + 2);
2023 }
2024
2025 if (m_thread_spec_ap.get() != NULL)
2026 {
2027 StreamString tmp;
2028 s->Indent("Thread:\n");
2029 m_thread_spec_ap->GetDescription (&tmp, level);
2030 s->SetIndentLevel (indent_level + 4);
2031 s->Indent (tmp.GetData());
2032 s->PutCString ("\n");
2033 s->SetIndentLevel (indent_level + 2);
2034 }
2035
2036 s->Indent ("Commands: \n");
2037 s->SetIndentLevel (indent_level + 4);
2038 uint32_t num_commands = m_commands.GetSize();
2039 for (uint32_t i = 0; i < num_commands; i++)
2040 {
2041 s->Indent(m_commands.GetStringAtIndex(i));
2042 s->PutCString ("\n");
2043 }
2044 s->SetIndentLevel (indent_level);
2045}
2046
2047
Caroline Tice5bc8c972010-09-20 20:44:43 +00002048//--------------------------------------------------------------
2049// class Target::SettingsController
2050//--------------------------------------------------------------
2051
2052Target::SettingsController::SettingsController () :
2053 UserSettingsController ("target", Debugger::GetSettingsController()),
2054 m_default_architecture ()
2055{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002056}
2057
2058Target::SettingsController::~SettingsController ()
2059{
2060}
2061
2062lldb::InstanceSettingsSP
2063Target::SettingsController::CreateInstanceSettings (const char *instance_name)
2064{
Greg Clayton334d33a2012-01-30 07:41:31 +00002065 lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
2066 false,
2067 instance_name));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002068 return new_settings_sp;
2069}
2070
Caroline Tice5bc8c972010-09-20 20:44:43 +00002071
Greg Claytonabb33022011-11-08 02:43:13 +00002072#define TSC_DEFAULT_ARCH "default-arch"
2073#define TSC_EXPR_PREFIX "expr-prefix"
2074#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
2075#define TSC_SKIP_PROLOGUE "skip-prologue"
2076#define TSC_SOURCE_MAP "source-map"
Greg Clayton9ce95382012-02-13 23:10:39 +00002077#define TSC_EXE_SEARCH_PATHS "exec-search-paths"
Greg Claytonabb33022011-11-08 02:43:13 +00002078#define TSC_MAX_CHILDREN "max-children-count"
2079#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
2080#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
2081#define TSC_RUN_ARGS "run-args"
2082#define TSC_ENV_VARS "env-vars"
2083#define TSC_INHERIT_ENV "inherit-env"
2084#define TSC_STDIN_PATH "input-path"
2085#define TSC_STDOUT_PATH "output-path"
2086#define TSC_STDERR_PATH "error-path"
2087#define TSC_DISABLE_ASLR "disable-aslr"
2088#define TSC_DISABLE_STDIO "disable-stdio"
Greg Claytond284b662011-02-18 01:44:25 +00002089
2090
2091static const ConstString &
2092GetSettingNameForDefaultArch ()
2093{
2094 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00002095 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002096}
2097
Greg Claytond284b662011-02-18 01:44:25 +00002098static const ConstString &
2099GetSettingNameForExpressionPrefix ()
2100{
2101 static ConstString g_const_string (TSC_EXPR_PREFIX);
2102 return g_const_string;
2103}
2104
2105static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00002106GetSettingNameForPreferDynamicValue ()
2107{
2108 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
2109 return g_const_string;
2110}
2111
Greg Claytonff44ab42011-04-23 02:04:55 +00002112static const ConstString &
2113GetSettingNameForSourcePathMap ()
2114{
2115 static ConstString g_const_string (TSC_SOURCE_MAP);
2116 return g_const_string;
2117}
Greg Claytond284b662011-02-18 01:44:25 +00002118
Greg Clayton17cd9952011-04-22 03:55:06 +00002119static const ConstString &
Greg Clayton9ce95382012-02-13 23:10:39 +00002120GetSettingNameForExecutableSearchPaths ()
2121{
2122 static ConstString g_const_string (TSC_EXE_SEARCH_PATHS);
2123 return g_const_string;
2124}
2125
2126static const ConstString &
Greg Clayton17cd9952011-04-22 03:55:06 +00002127GetSettingNameForSkipPrologue ()
2128{
2129 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
2130 return g_const_string;
2131}
2132
Enrico Granata018921d2011-08-12 02:00:06 +00002133static const ConstString &
2134GetSettingNameForMaxChildren ()
2135{
2136 static ConstString g_const_string (TSC_MAX_CHILDREN);
2137 return g_const_string;
2138}
Greg Clayton17cd9952011-04-22 03:55:06 +00002139
Enrico Granata91544802011-09-06 19:20:51 +00002140static const ConstString &
2141GetSettingNameForMaxStringSummaryLength ()
2142{
2143 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
2144 return g_const_string;
2145}
Greg Clayton17cd9952011-04-22 03:55:06 +00002146
Jim Ingham7089d8a2011-10-28 23:14:11 +00002147static const ConstString &
2148GetSettingNameForPlatformAvoid ()
2149{
2150 static ConstString g_const_string (TSC_PLATFORM_AVOID);
2151 return g_const_string;
2152}
2153
Greg Claytonabb33022011-11-08 02:43:13 +00002154const ConstString &
2155GetSettingNameForRunArgs ()
2156{
2157 static ConstString g_const_string (TSC_RUN_ARGS);
2158 return g_const_string;
2159}
2160
2161const ConstString &
2162GetSettingNameForEnvVars ()
2163{
2164 static ConstString g_const_string (TSC_ENV_VARS);
2165 return g_const_string;
2166}
2167
2168const ConstString &
2169GetSettingNameForInheritHostEnv ()
2170{
2171 static ConstString g_const_string (TSC_INHERIT_ENV);
2172 return g_const_string;
2173}
2174
2175const ConstString &
2176GetSettingNameForInputPath ()
2177{
2178 static ConstString g_const_string (TSC_STDIN_PATH);
2179 return g_const_string;
2180}
2181
2182const ConstString &
2183GetSettingNameForOutputPath ()
2184{
2185 static ConstString g_const_string (TSC_STDOUT_PATH);
2186 return g_const_string;
2187}
2188
2189const ConstString &
2190GetSettingNameForErrorPath ()
2191{
2192 static ConstString g_const_string (TSC_STDERR_PATH);
2193 return g_const_string;
2194}
2195
2196const ConstString &
2197GetSettingNameForDisableASLR ()
2198{
2199 static ConstString g_const_string (TSC_DISABLE_ASLR);
2200 return g_const_string;
2201}
2202
2203const ConstString &
2204GetSettingNameForDisableSTDIO ()
2205{
2206 static ConstString g_const_string (TSC_DISABLE_STDIO);
2207 return g_const_string;
2208}
Jim Ingham7089d8a2011-10-28 23:14:11 +00002209
Caroline Tice5bc8c972010-09-20 20:44:43 +00002210bool
2211Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
2212 const char *index_value,
2213 const char *value,
2214 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002215 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002216 Error&err)
2217{
Greg Claytond284b662011-02-18 01:44:25 +00002218 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002219 {
Greg Claytonf15996e2011-04-07 22:46:35 +00002220 m_default_architecture.SetTriple (value, NULL);
Greg Clayton940b1032011-02-23 00:35:02 +00002221 if (!m_default_architecture.IsValid())
2222 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002223 }
2224 return true;
2225}
2226
2227
2228bool
2229Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
2230 StringList &value,
2231 Error &err)
2232{
Greg Claytond284b662011-02-18 01:44:25 +00002233 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00002234 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00002235 // If the arch is invalid (the default), don't show a string for it
2236 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00002237 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00002238 return true;
2239 }
2240 else
2241 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2242
2243 return false;
2244}
2245
2246//--------------------------------------------------------------
2247// class TargetInstanceSettings
2248//--------------------------------------------------------------
2249
Greg Clayton638351a2010-12-04 00:10:17 +00002250TargetInstanceSettings::TargetInstanceSettings
2251(
Greg Clayton334d33a2012-01-30 07:41:31 +00002252 const lldb::UserSettingsControllerSP &owner_sp,
Greg Clayton638351a2010-12-04 00:10:17 +00002253 bool live_instance,
2254 const char *name
2255) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002256 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00002257 m_expr_prefix_file (),
Sean Callanane0b7f942011-11-16 01:54:57 +00002258 m_expr_prefix_contents (),
Jim Ingham10de7d12011-05-04 03:43:18 +00002259 m_prefer_dynamic_value (2),
Greg Claytonff44ab42011-04-23 02:04:55 +00002260 m_skip_prologue (true, true),
Enrico Granata018921d2011-08-12 02:00:06 +00002261 m_source_map (NULL, NULL),
Greg Clayton9ce95382012-02-13 23:10:39 +00002262 m_exe_search_paths (),
Enrico Granata91544802011-09-06 19:20:51 +00002263 m_max_children_display(256),
Jim Ingham7089d8a2011-10-28 23:14:11 +00002264 m_max_strlen_length(1024),
Greg Claytonabb33022011-11-08 02:43:13 +00002265 m_breakpoints_use_platform_avoid (true, true),
2266 m_run_args (),
2267 m_env_vars (),
2268 m_input_path (),
2269 m_output_path (),
2270 m_error_path (),
2271 m_disable_aslr (true),
2272 m_disable_stdio (false),
2273 m_inherit_host_env (true),
2274 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002275{
2276 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
2277 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
2278 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
2279 // This is true for CreateInstanceName() too.
2280
2281 if (GetInstanceName () == InstanceSettings::InvalidName())
2282 {
2283 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00002284 owner_sp->RegisterInstanceSettings (this);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002285 }
2286
2287 if (live_instance)
2288 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002289 const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002290 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002291 }
2292}
2293
2294TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00002295 InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
Greg Claytonff44ab42011-04-23 02:04:55 +00002296 m_expr_prefix_file (rhs.m_expr_prefix_file),
Sean Callanane0b7f942011-11-16 01:54:57 +00002297 m_expr_prefix_contents (rhs.m_expr_prefix_contents),
Greg Claytonff44ab42011-04-23 02:04:55 +00002298 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
2299 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata018921d2011-08-12 02:00:06 +00002300 m_source_map (rhs.m_source_map),
Greg Clayton9ce95382012-02-13 23:10:39 +00002301 m_exe_search_paths (rhs.m_exe_search_paths),
Greg Claytonabb33022011-11-08 02:43:13 +00002302 m_max_children_display (rhs.m_max_children_display),
2303 m_max_strlen_length (rhs.m_max_strlen_length),
2304 m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid),
2305 m_run_args (rhs.m_run_args),
2306 m_env_vars (rhs.m_env_vars),
2307 m_input_path (rhs.m_input_path),
2308 m_output_path (rhs.m_output_path),
2309 m_error_path (rhs.m_error_path),
2310 m_disable_aslr (rhs.m_disable_aslr),
2311 m_disable_stdio (rhs.m_disable_stdio),
2312 m_inherit_host_env (rhs.m_inherit_host_env)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002313{
2314 if (m_instance_name != InstanceSettings::GetDefaultName())
2315 {
Greg Clayton334d33a2012-01-30 07:41:31 +00002316 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
2317 if (owner_sp)
2318 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00002319 }
2320}
2321
2322TargetInstanceSettings::~TargetInstanceSettings ()
2323{
2324}
2325
2326TargetInstanceSettings&
2327TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2328{
2329 if (this != &rhs)
2330 {
Greg Claytonabb33022011-11-08 02:43:13 +00002331 m_expr_prefix_file = rhs.m_expr_prefix_file;
Sean Callanane0b7f942011-11-16 01:54:57 +00002332 m_expr_prefix_contents = rhs.m_expr_prefix_contents;
Greg Claytonabb33022011-11-08 02:43:13 +00002333 m_prefer_dynamic_value = rhs.m_prefer_dynamic_value;
2334 m_skip_prologue = rhs.m_skip_prologue;
2335 m_source_map = rhs.m_source_map;
Greg Clayton9ce95382012-02-13 23:10:39 +00002336 m_exe_search_paths = rhs.m_exe_search_paths;
Greg Claytonabb33022011-11-08 02:43:13 +00002337 m_max_children_display = rhs.m_max_children_display;
2338 m_max_strlen_length = rhs.m_max_strlen_length;
2339 m_breakpoints_use_platform_avoid = rhs.m_breakpoints_use_platform_avoid;
2340 m_run_args = rhs.m_run_args;
2341 m_env_vars = rhs.m_env_vars;
2342 m_input_path = rhs.m_input_path;
2343 m_output_path = rhs.m_output_path;
2344 m_error_path = rhs.m_error_path;
2345 m_disable_aslr = rhs.m_disable_aslr;
2346 m_disable_stdio = rhs.m_disable_stdio;
2347 m_inherit_host_env = rhs.m_inherit_host_env;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002348 }
2349
2350 return *this;
2351}
2352
Caroline Tice5bc8c972010-09-20 20:44:43 +00002353void
2354TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2355 const char *index_value,
2356 const char *value,
2357 const ConstString &instance_name,
2358 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00002359 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00002360 Error &err,
2361 bool pending)
2362{
Greg Claytond284b662011-02-18 01:44:25 +00002363 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002364 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002365 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2366 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00002367 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002368 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00002369 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002370 default:
2371 break;
2372 case eVarSetOperationAssign:
2373 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00002374 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002375 m_expr_prefix_contents.clear();
2376
Greg Claytonff44ab42011-04-23 02:04:55 +00002377 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2378 {
2379 err.SetErrorToGenericError ();
Greg Clayton9c236732011-10-26 00:56:27 +00002380 err.SetErrorStringWithFormat ("%s does not exist", value);
Greg Claytonff44ab42011-04-23 02:04:55 +00002381 return;
2382 }
2383
Greg Clayton4b23ab32012-01-06 02:01:06 +00002384 DataBufferSP file_data_sp (m_expr_prefix_file.GetCurrentValue().ReadFileContents(0, SIZE_MAX, &err));
Sean Callanane0b7f942011-11-16 01:54:57 +00002385
Greg Clayton4b23ab32012-01-06 02:01:06 +00002386 if (err.Success())
Greg Claytonff44ab42011-04-23 02:04:55 +00002387 {
Greg Clayton4b23ab32012-01-06 02:01:06 +00002388 if (file_data_sp && file_data_sp->GetByteSize() > 0)
2389 {
2390 m_expr_prefix_contents.assign((const char*)file_data_sp->GetBytes(), file_data_sp->GetByteSize());
2391 }
2392 else
2393 {
2394 err.SetErrorStringWithFormat ("couldn't read data from '%s'", value);
2395 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002396 }
Sean Callanan77e93942010-10-29 00:29:03 +00002397 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002398 break;
2399 case eVarSetOperationClear:
Sean Callanane0b7f942011-11-16 01:54:57 +00002400 m_expr_prefix_contents.clear();
Sean Callanan77e93942010-10-29 00:29:03 +00002401 }
Sean Callanan77e93942010-10-29 00:29:03 +00002402 }
2403 }
Jim Inghame41494a2011-04-16 00:01:13 +00002404 else if (var_name == GetSettingNameForPreferDynamicValue())
2405 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002406 int new_value;
2407 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2408 if (err.Success())
2409 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00002410 }
2411 else if (var_name == GetSettingNameForSkipPrologue())
2412 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002413 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2414 }
Enrico Granata018921d2011-08-12 02:00:06 +00002415 else if (var_name == GetSettingNameForMaxChildren())
2416 {
2417 bool ok;
2418 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2419 if (ok)
2420 m_max_children_display = new_value;
2421 }
Enrico Granata91544802011-09-06 19:20:51 +00002422 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2423 {
2424 bool ok;
2425 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2426 if (ok)
2427 m_max_strlen_length = new_value;
2428 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002429 else if (var_name == GetSettingNameForExecutableSearchPaths())
2430 {
2431 switch (op)
2432 {
2433 case eVarSetOperationReplace:
2434 case eVarSetOperationInsertBefore:
2435 case eVarSetOperationInsertAfter:
2436 case eVarSetOperationRemove:
2437 default:
2438 break;
2439 case eVarSetOperationAssign:
2440 m_exe_search_paths.Clear();
2441 // Fall through to append....
2442 case eVarSetOperationAppend:
2443 {
2444 Args args(value);
2445 const uint32_t argc = args.GetArgumentCount();
2446 if (argc > 0)
2447 {
2448 const char *exe_search_path_dir;
2449 for (uint32_t idx = 0; (exe_search_path_dir = args.GetArgumentAtIndex(idx)) != NULL; ++idx)
2450 {
2451 FileSpec file_spec;
2452 file_spec.GetDirectory().SetCString(exe_search_path_dir);
2453 FileSpec::FileType file_type = file_spec.GetFileType();
2454 if (file_type == FileSpec::eFileTypeDirectory || file_type == FileSpec::eFileTypeInvalid)
2455 {
2456 m_exe_search_paths.Append(file_spec);
2457 }
2458 else
2459 {
2460 err.SetErrorStringWithFormat("executable search path '%s' exists, but it does not resolve to a directory", exe_search_path_dir);
2461 }
2462 }
2463 }
2464 }
2465 break;
2466
2467 case eVarSetOperationClear:
2468 m_exe_search_paths.Clear();
2469 break;
2470 }
2471 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002472 else if (var_name == GetSettingNameForSourcePathMap ())
2473 {
2474 switch (op)
2475 {
2476 case eVarSetOperationReplace:
2477 case eVarSetOperationInsertBefore:
2478 case eVarSetOperationInsertAfter:
2479 case eVarSetOperationRemove:
2480 default:
2481 break;
2482 case eVarSetOperationAssign:
2483 m_source_map.Clear(true);
2484 // Fall through to append....
2485 case eVarSetOperationAppend:
2486 {
2487 Args args(value);
2488 const uint32_t argc = args.GetArgumentCount();
2489 if (argc & 1 || argc == 0)
2490 {
2491 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2492 }
2493 else
2494 {
2495 char resolved_new_path[PATH_MAX];
2496 FileSpec file_spec;
2497 const char *old_path;
2498 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2499 {
2500 const char *new_path = args.GetArgumentAtIndex(idx+1);
2501 assert (new_path); // We have an even number of paths, this shouldn't happen!
2502
2503 file_spec.SetFile(new_path, true);
2504 if (file_spec.Exists())
2505 {
2506 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2507 {
2508 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2509 return;
2510 }
2511 }
2512 else
2513 {
2514 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2515 return;
2516 }
2517 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2518 }
2519 }
2520 }
2521 break;
2522
2523 case eVarSetOperationClear:
2524 m_source_map.Clear(true);
2525 break;
2526 }
Jim Inghame41494a2011-04-16 00:01:13 +00002527 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002528 else if (var_name == GetSettingNameForPlatformAvoid ())
2529 {
2530 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
2531 }
Greg Claytonabb33022011-11-08 02:43:13 +00002532 else if (var_name == GetSettingNameForRunArgs())
2533 {
2534 UserSettingsController::UpdateStringArrayVariable (op, index_value, m_run_args, value, err);
2535 }
2536 else if (var_name == GetSettingNameForEnvVars())
2537 {
2538 // This is nice for local debugging, but it is isn't correct for
2539 // remote debugging. We need to stop process.env-vars from being
2540 // populated with the host environment and add this as a launch option
2541 // and get the correct environment from the Target's platform.
2542 // GetHostEnvironmentIfNeeded ();
2543 UserSettingsController::UpdateDictionaryVariable (op, index_value, m_env_vars, value, err);
2544 }
2545 else if (var_name == GetSettingNameForInputPath())
2546 {
2547 UserSettingsController::UpdateStringVariable (op, m_input_path, value, err);
2548 }
2549 else if (var_name == GetSettingNameForOutputPath())
2550 {
2551 UserSettingsController::UpdateStringVariable (op, m_output_path, value, err);
2552 }
2553 else if (var_name == GetSettingNameForErrorPath())
2554 {
2555 UserSettingsController::UpdateStringVariable (op, m_error_path, value, err);
2556 }
2557 else if (var_name == GetSettingNameForDisableASLR())
2558 {
2559 UserSettingsController::UpdateBooleanVariable (op, m_disable_aslr, value, true, err);
2560 }
2561 else if (var_name == GetSettingNameForDisableSTDIO ())
2562 {
2563 UserSettingsController::UpdateBooleanVariable (op, m_disable_stdio, value, false, err);
2564 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002565}
2566
2567void
Greg Claytond284b662011-02-18 01:44:25 +00002568TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002569{
Sean Callanan77e93942010-10-29 00:29:03 +00002570 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2571
2572 if (!new_settings_ptr)
2573 return;
2574
Greg Claytonabb33022011-11-08 02:43:13 +00002575 *this = *new_settings_ptr;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002576}
2577
Caroline Ticebcb5b452010-09-20 21:37:42 +00002578bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00002579TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2580 const ConstString &var_name,
2581 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00002582 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002583{
Greg Claytond284b662011-02-18 01:44:25 +00002584 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00002585 {
Greg Claytonff44ab42011-04-23 02:04:55 +00002586 char path[PATH_MAX];
2587 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2588 if (path_len > 0)
2589 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00002590 }
Jim Inghame41494a2011-04-16 00:01:13 +00002591 else if (var_name == GetSettingNameForPreferDynamicValue())
2592 {
Jim Ingham10de7d12011-05-04 03:43:18 +00002593 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00002594 }
Greg Clayton17cd9952011-04-22 03:55:06 +00002595 else if (var_name == GetSettingNameForSkipPrologue())
2596 {
2597 if (m_skip_prologue)
2598 value.AppendString ("true");
2599 else
2600 value.AppendString ("false");
2601 }
Greg Clayton9ce95382012-02-13 23:10:39 +00002602 else if (var_name == GetSettingNameForExecutableSearchPaths())
2603 {
2604 if (m_exe_search_paths.GetSize())
2605 {
2606 for (size_t i = 0, n = m_exe_search_paths.GetSize(); i < n; ++i)
2607 {
2608 value.AppendString(m_exe_search_paths.GetFileSpecAtIndex (i).GetDirectory().AsCString());
2609 }
2610 }
2611 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002612 else if (var_name == GetSettingNameForSourcePathMap ())
2613 {
Johnny Chen931449e2011-12-12 21:59:28 +00002614 if (m_source_map.GetSize())
2615 {
2616 size_t i;
2617 for (i = 0; i < m_source_map.GetSize(); ++i) {
2618 StreamString sstr;
2619 m_source_map.Dump(&sstr, i);
2620 value.AppendString(sstr.GetData());
2621 }
2622 }
Greg Claytonff44ab42011-04-23 02:04:55 +00002623 }
Enrico Granata018921d2011-08-12 02:00:06 +00002624 else if (var_name == GetSettingNameForMaxChildren())
2625 {
2626 StreamString count_str;
2627 count_str.Printf ("%d", m_max_children_display);
2628 value.AppendString (count_str.GetData());
2629 }
Enrico Granata91544802011-09-06 19:20:51 +00002630 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2631 {
2632 StreamString count_str;
2633 count_str.Printf ("%d", m_max_strlen_length);
2634 value.AppendString (count_str.GetData());
2635 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00002636 else if (var_name == GetSettingNameForPlatformAvoid())
2637 {
2638 if (m_breakpoints_use_platform_avoid)
2639 value.AppendString ("true");
2640 else
2641 value.AppendString ("false");
2642 }
Greg Claytonabb33022011-11-08 02:43:13 +00002643 else if (var_name == GetSettingNameForRunArgs())
2644 {
2645 if (m_run_args.GetArgumentCount() > 0)
2646 {
2647 for (int i = 0; i < m_run_args.GetArgumentCount(); ++i)
2648 value.AppendString (m_run_args.GetArgumentAtIndex (i));
2649 }
2650 }
2651 else if (var_name == GetSettingNameForEnvVars())
2652 {
2653 GetHostEnvironmentIfNeeded ();
2654
2655 if (m_env_vars.size() > 0)
2656 {
2657 std::map<std::string, std::string>::iterator pos;
2658 for (pos = m_env_vars.begin(); pos != m_env_vars.end(); ++pos)
2659 {
2660 StreamString value_str;
2661 value_str.Printf ("%s=%s", pos->first.c_str(), pos->second.c_str());
2662 value.AppendString (value_str.GetData());
2663 }
2664 }
2665 }
2666 else if (var_name == GetSettingNameForInputPath())
2667 {
2668 value.AppendString (m_input_path.c_str());
2669 }
2670 else if (var_name == GetSettingNameForOutputPath())
2671 {
2672 value.AppendString (m_output_path.c_str());
2673 }
2674 else if (var_name == GetSettingNameForErrorPath())
2675 {
2676 value.AppendString (m_error_path.c_str());
2677 }
2678 else if (var_name == GetSettingNameForInheritHostEnv())
2679 {
2680 if (m_inherit_host_env)
2681 value.AppendString ("true");
2682 else
2683 value.AppendString ("false");
2684 }
2685 else if (var_name == GetSettingNameForDisableASLR())
2686 {
2687 if (m_disable_aslr)
2688 value.AppendString ("true");
2689 else
2690 value.AppendString ("false");
2691 }
2692 else if (var_name == GetSettingNameForDisableSTDIO())
2693 {
2694 if (m_disable_stdio)
2695 value.AppendString ("true");
2696 else
2697 value.AppendString ("false");
2698 }
Sean Callanan77e93942010-10-29 00:29:03 +00002699 else
2700 {
2701 if (err)
2702 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2703 return false;
2704 }
Sean Callanan77e93942010-10-29 00:29:03 +00002705 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00002706}
2707
Greg Claytonabb33022011-11-08 02:43:13 +00002708void
2709Target::TargetInstanceSettings::GetHostEnvironmentIfNeeded ()
2710{
2711 if (m_inherit_host_env && !m_got_host_env)
2712 {
2713 m_got_host_env = true;
2714 StringList host_env;
2715 const size_t host_env_count = Host::GetEnvironment (host_env);
2716 for (size_t idx=0; idx<host_env_count; idx++)
2717 {
2718 const char *env_entry = host_env.GetStringAtIndex (idx);
2719 if (env_entry)
2720 {
2721 const char *equal_pos = ::strchr(env_entry, '=');
2722 if (equal_pos)
2723 {
2724 std::string key (env_entry, equal_pos - env_entry);
2725 std::string value (equal_pos + 1);
2726 if (m_env_vars.find (key) == m_env_vars.end())
2727 m_env_vars[key] = value;
2728 }
2729 }
2730 }
2731 }
2732}
2733
2734
2735size_t
2736Target::TargetInstanceSettings::GetEnvironmentAsArgs (Args &env)
2737{
2738 GetHostEnvironmentIfNeeded ();
2739
2740 dictionary::const_iterator pos, end = m_env_vars.end();
2741 for (pos = m_env_vars.begin(); pos != end; ++pos)
2742 {
2743 std::string env_var_equal_value (pos->first);
2744 env_var_equal_value.append(1, '=');
2745 env_var_equal_value.append (pos->second);
2746 env.AppendArgument (env_var_equal_value.c_str());
2747 }
2748 return env.GetArgumentCount();
2749}
2750
2751
Caroline Tice5bc8c972010-09-20 20:44:43 +00002752const ConstString
2753TargetInstanceSettings::CreateInstanceName ()
2754{
Caroline Tice5bc8c972010-09-20 20:44:43 +00002755 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00002756 static int instance_count = 1;
2757
Caroline Tice5bc8c972010-09-20 20:44:43 +00002758 sstr.Printf ("target_%d", instance_count);
2759 ++instance_count;
2760
2761 const ConstString ret_val (sstr.GetData());
2762 return ret_val;
2763}
2764
2765//--------------------------------------------------
2766// Target::SettingsController Variable Tables
2767//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00002768OptionEnumValueElement
2769TargetInstanceSettings::g_dynamic_value_types[] =
2770{
Greg Clayton577fbc32011-05-30 00:39:48 +00002771{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2772{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2773{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham10de7d12011-05-04 03:43:18 +00002774{ 0, NULL, NULL }
2775};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002776
2777SettingEntry
2778Target::SettingsController::global_settings_table[] =
2779{
Greg Claytond284b662011-02-18 01:44:25 +00002780 // var-name var-type default enum init'd hidden help-text
2781 // ================= ================== =========== ==== ====== ====== =========================================================================
2782 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2783 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2784};
2785
Caroline Tice5bc8c972010-09-20 20:44:43 +00002786SettingEntry
2787Target::SettingsController::instance_settings_table[] =
2788{
Enrico Granata91544802011-09-06 19:20:51 +00002789 // var-name var-type default enum init'd hidden help-text
2790 // ================= ================== =============== ======================= ====== ====== =========================================================================
2791 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2792 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2793 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2794 { 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 +00002795 { 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 +00002796 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2797 { 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 +00002798 { 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 +00002799 { TSC_RUN_ARGS , eSetVarTypeArray , NULL , NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." },
2800 { 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." },
2801 { TSC_INHERIT_ENV , eSetVarTypeBoolean, "true" , NULL, false, false, "Inherit the environment from the process that is running LLDB." },
2802 { TSC_STDIN_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for reading its standard input." },
2803 { TSC_STDOUT_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard output." },
2804 { TSC_STDERR_PATH , eSetVarTypeString , NULL , NULL, false, false, "The file/path to be used by the executable program for writing its standard error." },
2805// { "plugin", eSetVarTypeEnum, NULL, NULL, false, false, "The plugin to be used to run the process." },
2806 { TSC_DISABLE_ASLR , eSetVarTypeBoolean, "true" , NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" },
2807 { 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 +00002808 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002809};
Jim Ingham5a15e692012-02-16 06:50:00 +00002810
2811const ConstString &
2812Target::TargetEventData::GetFlavorString ()
2813{
2814 static ConstString g_flavor ("Target::TargetEventData");
2815 return g_flavor;
2816}
2817
2818const ConstString &
2819Target::TargetEventData::GetFlavor () const
2820{
2821 return TargetEventData::GetFlavorString ();
2822}
2823
2824Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2825 EventData(),
2826 m_target_sp (new_target_sp)
2827{
2828}
2829
2830Target::TargetEventData::~TargetEventData()
2831{
2832
2833}
2834
2835void
2836Target::TargetEventData::Dump (Stream *s) const
2837{
2838
2839}
2840
2841const TargetSP
2842Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2843{
2844 TargetSP target_sp;
2845
2846 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2847 if (data)
2848 target_sp = data->m_target_sp;
2849
2850 return target_sp;
2851}
2852
2853const Target::TargetEventData *
2854Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2855{
2856 if (event_ptr)
2857 {
2858 const EventData *event_data = event_ptr->GetData();
2859 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2860 return static_cast <const TargetEventData *> (event_ptr->GetData());
2861 }
2862 return NULL;
2863}
2864