blob: e236f341846fec4bafa0a5f68a3030094212546a [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Target/Target.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Breakpoint/BreakpointResolver.h"
19#include "lldb/Breakpoint/BreakpointResolverAddress.h"
20#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Jim Ingham03c8ee52011-09-21 01:17:13 +000021#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Breakpoint/BreakpointResolverName.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000023#include "lldb/Breakpoint/Watchpoint.h"
Greg Clayton427f2902010-12-14 02:59:59 +000024#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Core/Event.h"
26#include "lldb/Core/Log.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000027#include "lldb/Core/Module.h"
28#include "lldb/Core/ModuleSpec.h"
29#include "lldb/Core/Section.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000031#include "lldb/Core/Timer.h"
32#include "lldb/Core/ValueObject.h"
Sean Callanandcf03f82011-11-15 22:27:19 +000033#include "lldb/Expression/ClangASTSource.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000034#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000035#include "lldb/Host/Host.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000036#include "lldb/Interpreter/CommandInterpreter.h"
37#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chen3f883492012-06-04 23:19:54 +000038#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton73844aa2012-08-22 17:17:09 +000039#include "lldb/Interpreter/OptionValues.h"
40#include "lldb/Interpreter/Property.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041#include "lldb/lldb-private-log.h"
42#include "lldb/Symbol/ObjectFile.h"
43#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000044#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000045#include "lldb/Target/Thread.h"
46#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000047
48using namespace lldb;
49using namespace lldb_private;
50
Jim Ingham5a15e692012-02-16 06:50:00 +000051ConstString &
52Target::GetStaticBroadcasterClass ()
53{
54 static ConstString class_name ("lldb.target");
55 return class_name;
56}
57
Chris Lattner24943d22010-06-08 16:52:24 +000058//----------------------------------------------------------------------
59// Target constructor
60//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000061Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Greg Clayton73844aa2012-08-22 17:17:09 +000062 TargetProperties (this),
Jim Ingham94a5d0d2012-10-10 18:32:14 +000063 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton24bc5d92011-03-30 18:16:51 +000064 ExecutionContextScope (),
Greg Clayton63094e02010-06-23 01:19:29 +000065 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000066 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000067 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000068 m_arch (target_arch),
Enrico Granata146d9522012-11-08 02:22:02 +000069 m_images (this),
Greg Claytoneea26402010-09-14 23:36:40 +000070 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000071 m_breakpoint_list (false),
72 m_internal_breakpoint_list (true),
Johnny Chenecd4feb2011-10-14 00:42:25 +000073 m_watchpoint_list (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000074 m_process_sp (),
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +000075 m_valid (true),
Greg Clayton24bc5d92011-03-30 18:16:51 +000076 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000077 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000078 m_scratch_ast_context_ap (NULL),
Sean Callanan4938bd62011-11-16 18:20:47 +000079 m_scratch_ast_source_ap (NULL),
80 m_ast_importer_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000081 m_persistent_variables (),
Jim Inghamcc637462011-09-13 00:29:56 +000082 m_source_manager(*this),
Greg Clayton24bc5d92011-03-30 18:16:51 +000083 m_stop_hooks (),
Jim Ingham3613ae12011-05-12 02:06:14 +000084 m_stop_hook_next_id (0),
Enrico Granatadba1de82012-03-27 02:35:13 +000085 m_suppress_stop_hooks (false),
86 m_suppress_synthetic_value(false)
Chris Lattner24943d22010-06-08 16:52:24 +000087{
Greg Clayton49ce6822010-10-31 03:01:06 +000088 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
89 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
90 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham5a15e692012-02-16 06:50:00 +000091
92 CheckInWithManager();
Greg Clayton49ce6822010-10-31 03:01:06 +000093
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);
Jason Molenda8c6cf432012-12-05 00:25:49 +000097 if (m_arch.IsValid())
98 {
99 LogSP log_target(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Clayton48eca2f2012-12-05 18:23:55 +0000100 if (log_target)
101 log_target->Printf("Target::Target created with architecture %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
Jason Molenda8c6cf432012-12-05 00:25:49 +0000102 }
Chris Lattner24943d22010-06-08 16:52:24 +0000103}
104
105//----------------------------------------------------------------------
106// Destructor
107//----------------------------------------------------------------------
108Target::~Target()
109{
Greg Claytone005f2c2010-11-06 01:53:30 +0000110 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +0000111 if (log)
112 log->Printf ("%p Target::~Target()", this);
113 DeleteCurrentProcess ();
114}
115
116void
Caroline Tice7826c882010-10-26 03:11:13 +0000117Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +0000118{
Greg Clayton3fed8b92010-10-08 00:21:05 +0000119// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +0000120 if (description_level != lldb::eDescriptionLevelBrief)
121 {
122 s->Indent();
123 s->PutCString("Target\n");
124 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000125 m_images.Dump(s);
126 m_breakpoint_list.Dump(s);
127 m_internal_breakpoint_list.Dump(s);
128 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +0000129 }
130 else
131 {
Greg Clayton5beb99d2011-08-11 02:48:45 +0000132 Module *exe_module = GetExecutableModulePointer();
133 if (exe_module)
134 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham53fe9cc2011-05-12 01:12:28 +0000135 else
136 s->PutCString ("No executable module.");
Caroline Tice7826c882010-10-26 03:11:13 +0000137 }
Chris Lattner24943d22010-06-08 16:52:24 +0000138}
139
140void
Greg Clayton0bce9a22012-12-05 00:16:59 +0000141Target::CleanupProcess ()
142{
143 // Do any cleanup of the target we need to do between process instances.
144 // NB It is better to do this before destroying the process in case the
145 // clean up needs some help from the process.
146 m_breakpoint_list.ClearAllBreakpointSites();
147 m_internal_breakpoint_list.ClearAllBreakpointSites();
148 // Disable watchpoints just on the debugger side.
149 Mutex::Locker locker;
150 this->GetWatchpointList().GetListMutex(locker);
151 DisableAllWatchpoints(false);
152 ClearAllWatchpointHitCounts();
153}
154
155void
Chris Lattner24943d22010-06-08 16:52:24 +0000156Target::DeleteCurrentProcess ()
157{
158 if (m_process_sp.get())
159 {
Greg Clayton49480b12010-09-14 23:52:43 +0000160 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000161 if (m_process_sp->IsAlive())
162 m_process_sp->Destroy();
Jim Ingham88fa7bd2011-02-16 17:54:55 +0000163
164 m_process_sp->Finalize();
Chris Lattner24943d22010-06-08 16:52:24 +0000165
Greg Clayton0bce9a22012-12-05 00:16:59 +0000166 CleanupProcess ();
167
Chris Lattner24943d22010-06-08 16:52:24 +0000168 m_process_sp.reset();
169 }
170}
171
172const lldb::ProcessSP &
Greg Clayton46c9a352012-02-09 06:16:32 +0000173Target::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file)
Chris Lattner24943d22010-06-08 16:52:24 +0000174{
175 DeleteCurrentProcess ();
Greg Clayton46c9a352012-02-09 06:16:32 +0000176 m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file);
Chris Lattner24943d22010-06-08 16:52:24 +0000177 return m_process_sp;
178}
179
180const lldb::ProcessSP &
181Target::GetProcessSP () const
182{
183 return m_process_sp;
184}
185
Greg Clayton153ccd72011-08-10 02:10:13 +0000186void
187Target::Destroy()
188{
189 Mutex::Locker locker (m_mutex);
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +0000190 m_valid = false;
Greg Clayton153ccd72011-08-10 02:10:13 +0000191 DeleteCurrentProcess ();
192 m_platform_sp.reset();
193 m_arch.Clear();
194 m_images.Clear();
195 m_section_load_list.Clear();
196 const bool notify = false;
197 m_breakpoint_list.RemoveAll(notify);
198 m_internal_breakpoint_list.RemoveAll(notify);
199 m_last_created_breakpoint.reset();
Johnny Chenecd4feb2011-10-14 00:42:25 +0000200 m_last_created_watchpoint.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000201 m_search_filter_sp.reset();
202 m_image_search_paths.Clear(notify);
203 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000204 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000205 m_ast_importer_ap.reset();
Greg Clayton153ccd72011-08-10 02:10:13 +0000206 m_persistent_variables.Clear();
207 m_stop_hooks.clear();
208 m_stop_hook_next_id = 0;
209 m_suppress_stop_hooks = false;
Enrico Granatadba1de82012-03-27 02:35:13 +0000210 m_suppress_synthetic_value = false;
Greg Clayton153ccd72011-08-10 02:10:13 +0000211}
212
213
Chris Lattner24943d22010-06-08 16:52:24 +0000214BreakpointList &
215Target::GetBreakpointList(bool internal)
216{
217 if (internal)
218 return m_internal_breakpoint_list;
219 else
220 return m_breakpoint_list;
221}
222
223const BreakpointList &
224Target::GetBreakpointList(bool internal) const
225{
226 if (internal)
227 return m_internal_breakpoint_list;
228 else
229 return m_breakpoint_list;
230}
231
232BreakpointSP
233Target::GetBreakpointByID (break_id_t break_id)
234{
235 BreakpointSP bp_sp;
236
237 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
238 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
239 else
240 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
241
242 return bp_sp;
243}
244
245BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000246Target::CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
Greg Clayton49ce8962012-08-29 21:13:06 +0000247 const FileSpecList *source_file_spec_list,
248 RegularExpression &source_regex,
249 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000250{
Jim Inghamd6d47972011-09-23 00:54:11 +0000251 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list));
252 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000253 return CreateBreakpoint (filter_sp, resolver_sp, internal);
254}
255
256
257BreakpointSP
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000258Target::CreateBreakpoint (const FileSpecList *containingModules,
259 const FileSpec &file,
260 uint32_t line_no,
Greg Clayton49ce8962012-08-29 21:13:06 +0000261 LazyBool check_inlines,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000262 LazyBool skip_prologue,
263 bool internal)
Jim Ingham03c8ee52011-09-21 01:17:13 +0000264{
Greg Clayton49ce8962012-08-29 21:13:06 +0000265 if (check_inlines == eLazyBoolCalculate)
266 {
267 const InlineStrategy inline_strategy = GetInlineStrategy();
268 switch (inline_strategy)
269 {
270 case eInlineBreakpointsNever:
271 check_inlines = eLazyBoolNo;
272 break;
273
274 case eInlineBreakpointsHeaders:
275 if (file.IsSourceImplementationFile())
276 check_inlines = eLazyBoolNo;
277 else
278 check_inlines = eLazyBoolYes;
279 break;
280
281 case eInlineBreakpointsAlways:
282 check_inlines = eLazyBoolYes;
283 break;
284 }
285 }
Greg Clayton46365522012-09-07 23:48:57 +0000286 SearchFilterSP filter_sp;
287 if (check_inlines == eLazyBoolNo)
288 {
289 // Not checking for inlines, we are looking only for matching compile units
290 FileSpecList compile_unit_list;
291 compile_unit_list.Append (file);
292 filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list);
293 }
294 else
295 {
296 filter_sp = GetSearchFilterForModuleList (containingModules);
297 }
Greg Clayton49ce8962012-08-29 21:13:06 +0000298 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL,
299 file,
300 line_no,
301 check_inlines,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000302 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000303 return CreateBreakpoint (filter_sp, resolver_sp, internal);
304}
305
306
307BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000308Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000309{
Chris Lattner24943d22010-06-08 16:52:24 +0000310 Address so_addr;
311 // Attempt to resolve our load address if possible, though it is ok if
312 // it doesn't resolve to section/offset.
313
Greg Clayton33ed1702010-08-24 00:45:41 +0000314 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000315 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000316 if (!so_addr.IsValid())
317 {
318 // The address didn't resolve, so just set this as an absolute address
319 so_addr.SetOffset (addr);
320 }
321 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000322 return bp_sp;
323}
324
325BreakpointSP
326Target::CreateBreakpoint (Address &addr, bool internal)
327{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000328 SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000329 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
330 return CreateBreakpoint (filter_sp, resolver_sp, internal);
331}
332
333BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000334Target::CreateBreakpoint (const FileSpecList *containingModules,
335 const FileSpecList *containingSourceFiles,
Greg Clayton7dd98df2011-07-12 17:06:17 +0000336 const char *func_name,
337 uint32_t func_name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000338 LazyBool skip_prologue,
339 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000340{
Greg Clayton12bec712010-06-28 21:30:43 +0000341 BreakpointSP bp_sp;
342 if (func_name)
343 {
Jim Inghamd6d47972011-09-23 00:54:11 +0000344 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000345
346 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
347 func_name,
348 func_name_type_mask,
349 Breakpoint::Exact,
350 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton12bec712010-06-28 21:30:43 +0000351 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
352 }
353 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000354}
355
Jim Ingham4722b102012-03-06 00:37:27 +0000356lldb::BreakpointSP
357Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Claytonbd5c23d2012-05-15 02:33:01 +0000358 const FileSpecList *containingSourceFiles,
359 const std::vector<std::string> &func_names,
360 uint32_t func_name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000361 LazyBool skip_prologue,
362 bool internal)
Jim Ingham4722b102012-03-06 00:37:27 +0000363{
364 BreakpointSP bp_sp;
365 size_t num_names = func_names.size();
366 if (num_names > 0)
367 {
368 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
369
370 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
371 func_names,
372 func_name_type_mask,
373 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
374 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
375 }
376 return bp_sp;
377}
378
Jim Inghamc1053622012-03-03 02:05:11 +0000379BreakpointSP
380Target::CreateBreakpoint (const FileSpecList *containingModules,
381 const FileSpecList *containingSourceFiles,
382 const char *func_names[],
383 size_t num_names,
384 uint32_t func_name_type_mask,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000385 LazyBool skip_prologue,
386 bool internal)
Jim Inghamc1053622012-03-03 02:05:11 +0000387{
388 BreakpointSP bp_sp;
389 if (num_names > 0)
390 {
391 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
392
393 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
394 func_names,
395 num_names,
Jim Ingham4722b102012-03-06 00:37:27 +0000396 func_name_type_mask,
Jim Inghamc1053622012-03-03 02:05:11 +0000397 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
398 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
399 }
400 return bp_sp;
401}
Chris Lattner24943d22010-06-08 16:52:24 +0000402
403SearchFilterSP
404Target::GetSearchFilterForModule (const FileSpec *containingModule)
405{
406 SearchFilterSP filter_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000407 if (containingModule != NULL)
408 {
409 // TODO: We should look into sharing module based search filters
410 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000411 filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
Chris Lattner24943d22010-06-08 16:52:24 +0000412 }
413 else
414 {
415 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000416 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Chris Lattner24943d22010-06-08 16:52:24 +0000417 filter_sp = m_search_filter_sp;
418 }
419 return filter_sp;
420}
421
Jim Ingham03c8ee52011-09-21 01:17:13 +0000422SearchFilterSP
423Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
424{
425 SearchFilterSP filter_sp;
Jim Ingham03c8ee52011-09-21 01:17:13 +0000426 if (containingModules && containingModules->GetSize() != 0)
427 {
428 // TODO: We should look into sharing module based search filters
429 // across many breakpoints like we do for the simple target based one
Greg Clayton13d24fb2012-01-29 20:56:30 +0000430 filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000431 }
432 else
433 {
434 if (m_search_filter_sp.get() == NULL)
Greg Clayton13d24fb2012-01-29 20:56:30 +0000435 m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
Jim Ingham03c8ee52011-09-21 01:17:13 +0000436 filter_sp = m_search_filter_sp;
437 }
438 return filter_sp;
439}
440
Jim Inghamd6d47972011-09-23 00:54:11 +0000441SearchFilterSP
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000442Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules,
443 const FileSpecList *containingSourceFiles)
Jim Inghamd6d47972011-09-23 00:54:11 +0000444{
445 if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0)
446 return GetSearchFilterForModuleList(containingModules);
447
448 SearchFilterSP filter_sp;
Jim Inghamd6d47972011-09-23 00:54:11 +0000449 if (containingModules == NULL)
450 {
451 // We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
452 // but that will take a little reworking.
453
Greg Clayton13d24fb2012-01-29 20:56:30 +0000454 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000455 }
456 else
457 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000458 filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
Jim Inghamd6d47972011-09-23 00:54:11 +0000459 }
460 return filter_sp;
461}
462
Chris Lattner24943d22010-06-08 16:52:24 +0000463BreakpointSP
Jim Inghamd6d47972011-09-23 00:54:11 +0000464Target::CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
Jim Ingham2cf5ccb2012-05-22 00:12:20 +0000465 const FileSpecList *containingSourceFiles,
466 RegularExpression &func_regex,
467 LazyBool skip_prologue,
468 bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000469{
Jim Inghamd6d47972011-09-23 00:54:11 +0000470 SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles));
Greg Clayton7dd98df2011-07-12 17:06:17 +0000471 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
472 func_regex,
473 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner24943d22010-06-08 16:52:24 +0000474
475 return CreateBreakpoint (filter_sp, resolver_sp, internal);
476}
477
Jim Ingham3df164e2012-03-05 04:47:34 +0000478lldb::BreakpointSP
479Target::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal)
480{
481 return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal);
482}
483
Chris Lattner24943d22010-06-08 16:52:24 +0000484BreakpointSP
485Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
486{
487 BreakpointSP bp_sp;
488 if (filter_sp && resolver_sp)
489 {
490 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
491 resolver_sp->SetBreakpoint (bp_sp.get());
492
493 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000494 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000495 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000496 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000497
Greg Claytone005f2c2010-11-06 01:53:30 +0000498 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000499 if (log)
500 {
501 StreamString s;
502 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
503 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
504 }
505
Chris Lattner24943d22010-06-08 16:52:24 +0000506 bp_sp->ResolveBreakpoint();
507 }
Jim Inghamd1686902010-10-14 23:45:03 +0000508
509 if (!internal && bp_sp)
510 {
511 m_last_created_breakpoint = bp_sp;
512 }
513
Chris Lattner24943d22010-06-08 16:52:24 +0000514 return bp_sp;
515}
516
Johnny Chenda5a8022011-09-20 23:28:55 +0000517bool
518Target::ProcessIsValid()
519{
520 return (m_process_sp && m_process_sp->IsAlive());
521}
522
Johnny Chen3f883492012-06-04 23:19:54 +0000523static bool
524CheckIfWatchpointsExhausted(Target *target, Error &error)
525{
526 uint32_t num_supported_hardware_watchpoints;
527 Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
528 if (rc.Success())
529 {
530 uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize();
531 if (num_current_watchpoints >= num_supported_hardware_watchpoints)
532 error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached",
533 num_supported_hardware_watchpoints);
534 }
535 return false;
536}
537
Johnny Chenecd4feb2011-10-14 00:42:25 +0000538// See also Watchpoint::SetWatchpointType(uint32_t type) and
Johnny Chen87ff53b2011-09-14 00:26:03 +0000539// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chenecd4feb2011-10-14 00:42:25 +0000540WatchpointSP
Jim Ingham9e376622012-10-23 07:20:06 +0000541Target::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error)
Johnny Chen34bbf852011-09-12 23:38:44 +0000542{
Johnny Chen5b2fc572011-09-14 20:23:45 +0000543 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
544 if (log)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000545 log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n",
Jim Ingham9e376622012-10-23 07:20:06 +0000546 __FUNCTION__, addr, (uint64_t)size, kind);
Johnny Chen5b2fc572011-09-14 20:23:45 +0000547
Johnny Chenecd4feb2011-10-14 00:42:25 +0000548 WatchpointSP wp_sp;
Johnny Chenda5a8022011-09-20 23:28:55 +0000549 if (!ProcessIsValid())
Johnny Chen3f883492012-06-04 23:19:54 +0000550 {
551 error.SetErrorString("process is not alive");
Johnny Chenecd4feb2011-10-14 00:42:25 +0000552 return wp_sp;
Johnny Chen3f883492012-06-04 23:19:54 +0000553 }
Johnny Chen22a56cc2011-09-14 22:20:15 +0000554 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chen3f883492012-06-04 23:19:54 +0000555 {
556 if (size == 0)
557 error.SetErrorString("cannot set a watchpoint with watch_size of 0");
558 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000559 error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000560 return wp_sp;
Johnny Chen3f883492012-06-04 23:19:54 +0000561 }
Johnny Chen9bf11992011-09-13 01:15:36 +0000562
Johnny Chenecd4feb2011-10-14 00:42:25 +0000563 // Currently we only support one watchpoint per address, with total number
564 // of watchpoints limited by the hardware which the inferior is running on.
Johnny Chenbbf6aa52012-05-31 22:56:36 +0000565
566 // Grab the list mutex while doing operations.
567 Mutex::Locker locker;
568 this->GetWatchpointList().GetListMutex(locker);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000569 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000570 if (matched_sp)
571 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000572 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000573 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000574 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
575 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000576 // Return the existing watchpoint if both size and type match.
Jim Ingham9e376622012-10-23 07:20:06 +0000577 if (size == old_size && kind == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000578 wp_sp = matched_sp;
579 wp_sp->SetEnabled(false);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000580 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000581 // Nil the matched watchpoint; we will be creating a new one.
Johnny Chen22a56cc2011-09-14 22:20:15 +0000582 m_process_sp->DisableWatchpoint(matched_sp.get());
Johnny Chenecd4feb2011-10-14 00:42:25 +0000583 m_watchpoint_list.Remove(matched_sp->GetID());
Johnny Chen22a56cc2011-09-14 22:20:15 +0000584 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000585 }
586
Johnny Chenecd4feb2011-10-14 00:42:25 +0000587 if (!wp_sp) {
Jim Ingham9e376622012-10-23 07:20:06 +0000588 Watchpoint *new_wp = new Watchpoint(*this, addr, size, type);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000589 if (!new_wp) {
590 printf("Watchpoint ctor failed, out of memory?\n");
591 return wp_sp;
Johnny Chen22a56cc2011-09-14 22:20:15 +0000592 }
Jim Ingham9e376622012-10-23 07:20:06 +0000593 new_wp->SetWatchpointType(kind);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000594 wp_sp.reset(new_wp);
595 m_watchpoint_list.Add(wp_sp);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000596 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000597
Johnny Chen3f883492012-06-04 23:19:54 +0000598 error = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000599 if (log)
600 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
601 __FUNCTION__,
Johnny Chen3f883492012-06-04 23:19:54 +0000602 error.Success() ? "succeeded" : "failed",
Johnny Chenecd4feb2011-10-14 00:42:25 +0000603 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000604
Johnny Chen3f883492012-06-04 23:19:54 +0000605 if (error.Fail()) {
Johnny Chen155599b2012-03-26 22:00:10 +0000606 // Enabling the watchpoint on the device side failed.
607 // Remove the said watchpoint from the list maintained by the target instance.
608 m_watchpoint_list.Remove(wp_sp->GetID());
Johnny Chen3f883492012-06-04 23:19:54 +0000609 // See if we could provide more helpful error message.
610 if (!CheckIfWatchpointsExhausted(this, error))
611 {
612 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
613 error.SetErrorStringWithFormat("watch size of %lu is not supported", size);
614 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000615 wp_sp.reset();
Johnny Chen155599b2012-03-26 22:00:10 +0000616 }
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000617 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000618 m_last_created_watchpoint = wp_sp;
619 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000620}
621
Chris Lattner24943d22010-06-08 16:52:24 +0000622void
623Target::RemoveAllBreakpoints (bool internal_also)
624{
Greg Claytone005f2c2010-11-06 01:53:30 +0000625 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000626 if (log)
627 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
628
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000629 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000630 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000631 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000632
633 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000634}
635
636void
637Target::DisableAllBreakpoints (bool internal_also)
638{
Greg Claytone005f2c2010-11-06 01:53:30 +0000639 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000640 if (log)
641 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
642
643 m_breakpoint_list.SetEnabledAll (false);
644 if (internal_also)
645 m_internal_breakpoint_list.SetEnabledAll (false);
646}
647
648void
649Target::EnableAllBreakpoints (bool internal_also)
650{
Greg Claytone005f2c2010-11-06 01:53:30 +0000651 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000652 if (log)
653 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
654
655 m_breakpoint_list.SetEnabledAll (true);
656 if (internal_also)
657 m_internal_breakpoint_list.SetEnabledAll (true);
658}
659
660bool
661Target::RemoveBreakpointByID (break_id_t break_id)
662{
Greg Claytone005f2c2010-11-06 01:53:30 +0000663 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000664 if (log)
665 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
666
667 if (DisableBreakpointByID (break_id))
668 {
669 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000670 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000671 else
Jim Inghamd1686902010-10-14 23:45:03 +0000672 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000673 if (m_last_created_breakpoint)
674 {
675 if (m_last_created_breakpoint->GetID() == break_id)
676 m_last_created_breakpoint.reset();
677 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000678 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000679 }
Chris Lattner24943d22010-06-08 16:52:24 +0000680 return true;
681 }
682 return false;
683}
684
685bool
686Target::DisableBreakpointByID (break_id_t break_id)
687{
Greg Claytone005f2c2010-11-06 01:53:30 +0000688 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000689 if (log)
690 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
691
692 BreakpointSP bp_sp;
693
694 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
695 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
696 else
697 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
698 if (bp_sp)
699 {
700 bp_sp->SetEnabled (false);
701 return true;
702 }
703 return false;
704}
705
706bool
707Target::EnableBreakpointByID (break_id_t break_id)
708{
Greg Claytone005f2c2010-11-06 01:53:30 +0000709 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000710 if (log)
711 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
712 __FUNCTION__,
713 break_id,
714 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
715
716 BreakpointSP bp_sp;
717
718 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
719 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
720 else
721 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
722
723 if (bp_sp)
724 {
725 bp_sp->SetEnabled (true);
726 return true;
727 }
728 return false;
729}
730
Johnny Chenc86582f2011-09-23 21:21:43 +0000731// The flag 'end_to_end', default to true, signifies that the operation is
732// performed end to end, for both the debugger and the debuggee.
733
Johnny Chenecd4feb2011-10-14 00:42:25 +0000734// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
735// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000736bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000737Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000738{
739 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
740 if (log)
741 log->Printf ("Target::%s\n", __FUNCTION__);
742
Johnny Chenc86582f2011-09-23 21:21:43 +0000743 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000744 m_watchpoint_list.RemoveAll();
Johnny Chenc86582f2011-09-23 21:21:43 +0000745 return true;
746 }
747
748 // Otherwise, it's an end to end operation.
749
Johnny Chenda5a8022011-09-20 23:28:55 +0000750 if (!ProcessIsValid())
751 return false;
752
Johnny Chenecd4feb2011-10-14 00:42:25 +0000753 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000754 for (size_t i = 0; i < num_watchpoints; ++i)
755 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000756 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
757 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000758 return false;
759
Johnny Chenecd4feb2011-10-14 00:42:25 +0000760 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000761 if (rc.Fail())
762 return false;
763 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000764 m_watchpoint_list.RemoveAll ();
Johnny Chenda5a8022011-09-20 23:28:55 +0000765 return true; // Success!
766}
767
Johnny Chenecd4feb2011-10-14 00:42:25 +0000768// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
769// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000770bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000771Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000772{
773 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
774 if (log)
775 log->Printf ("Target::%s\n", __FUNCTION__);
776
Johnny Chenc86582f2011-09-23 21:21:43 +0000777 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000778 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000779 return true;
780 }
781
782 // Otherwise, it's an end to end operation.
783
Johnny Chenda5a8022011-09-20 23:28:55 +0000784 if (!ProcessIsValid())
785 return false;
786
Johnny Chenecd4feb2011-10-14 00:42:25 +0000787 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000788 for (size_t i = 0; i < num_watchpoints; ++i)
789 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000790 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
791 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000792 return false;
793
Johnny Chenecd4feb2011-10-14 00:42:25 +0000794 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000795 if (rc.Fail())
796 return false;
797 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000798 return true; // Success!
799}
800
Johnny Chenecd4feb2011-10-14 00:42:25 +0000801// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
802// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000803bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000804Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000805{
806 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
807 if (log)
808 log->Printf ("Target::%s\n", __FUNCTION__);
809
Johnny Chenc86582f2011-09-23 21:21:43 +0000810 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000811 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000812 return true;
813 }
814
815 // Otherwise, it's an end to end operation.
816
Johnny Chenda5a8022011-09-20 23:28:55 +0000817 if (!ProcessIsValid())
818 return false;
819
Johnny Chenecd4feb2011-10-14 00:42:25 +0000820 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000821 for (size_t i = 0; i < num_watchpoints; ++i)
822 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000823 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
824 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000825 return false;
826
Johnny Chenecd4feb2011-10-14 00:42:25 +0000827 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000828 if (rc.Fail())
829 return false;
830 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000831 return true; // Success!
832}
833
Johnny Chen116a5cd2012-02-25 06:44:30 +0000834// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
835bool
836Target::ClearAllWatchpointHitCounts ()
837{
838 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
839 if (log)
840 log->Printf ("Target::%s\n", __FUNCTION__);
841
842 size_t num_watchpoints = m_watchpoint_list.GetSize();
843 for (size_t i = 0; i < num_watchpoints; ++i)
844 {
845 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
846 if (!wp_sp)
847 return false;
848
849 wp_sp->ResetHitCount();
850 }
851 return true; // Success!
852}
853
Johnny Chenecd4feb2011-10-14 00:42:25 +0000854// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000855// during these operations.
856bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000857Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000858{
859 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
860 if (log)
861 log->Printf ("Target::%s\n", __FUNCTION__);
862
863 if (!ProcessIsValid())
864 return false;
865
Johnny Chenecd4feb2011-10-14 00:42:25 +0000866 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000867 for (size_t i = 0; i < num_watchpoints; ++i)
868 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000869 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
870 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000871 return false;
872
Johnny Chenecd4feb2011-10-14 00:42:25 +0000873 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000874 }
875 return true; // Success!
876}
877
Johnny Chenecd4feb2011-10-14 00:42:25 +0000878// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000879bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000880Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000881{
882 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
883 if (log)
884 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
885
886 if (!ProcessIsValid())
887 return false;
888
Johnny Chenecd4feb2011-10-14 00:42:25 +0000889 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
890 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000891 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000892 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000893 if (rc.Success())
894 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000895
Johnny Chen01acfa72011-09-22 18:04:58 +0000896 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000897 }
898 return false;
899}
900
Johnny Chenecd4feb2011-10-14 00:42:25 +0000901// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000902bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000903Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000904{
905 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
906 if (log)
907 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
908
909 if (!ProcessIsValid())
910 return false;
911
Johnny Chenecd4feb2011-10-14 00:42:25 +0000912 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
913 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000914 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000915 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000916 if (rc.Success())
917 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000918
Johnny Chen01acfa72011-09-22 18:04:58 +0000919 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000920 }
921 return false;
922}
923
Johnny Chenecd4feb2011-10-14 00:42:25 +0000924// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000925bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000926Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000927{
928 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
929 if (log)
930 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
931
Johnny Chenecd4feb2011-10-14 00:42:25 +0000932 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000933 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000934 m_watchpoint_list.Remove(watch_id);
Johnny Chenda5a8022011-09-20 23:28:55 +0000935 return true;
936 }
937 return false;
938}
939
Johnny Chenecd4feb2011-10-14 00:42:25 +0000940// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000941bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000942Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000943{
944 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
945 if (log)
946 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
947
948 if (!ProcessIsValid())
949 return false;
950
Johnny Chenecd4feb2011-10-14 00:42:25 +0000951 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
952 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000953 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000954 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000955 return true;
956 }
957 return false;
958}
959
Chris Lattner24943d22010-06-08 16:52:24 +0000960ModuleSP
961Target::GetExecutableModule ()
962{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000963 return m_images.GetModuleAtIndex(0);
964}
965
966Module*
967Target::GetExecutableModulePointer ()
968{
969 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000970}
971
Enrico Granata146d9522012-11-08 02:22:02 +0000972static void
973LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
974{
975 Error error;
976 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error))
977 {
978 target->GetDebugger().GetOutputStream().Printf("unable to load scripting data for module %s - error reported was %s\n",
979 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
980 error.AsCString());
981 }
982}
983
Chris Lattner24943d22010-06-08 16:52:24 +0000984void
985Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
986{
Jason Molenda8c6cf432012-12-05 00:25:49 +0000987 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Chris Lattner24943d22010-06-08 16:52:24 +0000988 m_images.Clear();
989 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000990 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000991 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000992
993 if (executable_sp.get())
994 {
995 Timer scoped_timer (__PRETTY_FUNCTION__,
996 "Target::SetExecutableModule (executable = '%s/%s')",
997 executable_sp->GetFileSpec().GetDirectory().AsCString(),
998 executable_sp->GetFileSpec().GetFilename().AsCString());
999
1000 m_images.Append(executable_sp); // The first image is our exectuable file
1001
Jim Ingham7508e732010-08-09 23:31:02 +00001002 // 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 +00001003 if (!m_arch.IsValid())
Jason Molenda8c6cf432012-12-05 00:25:49 +00001004 {
Greg Clayton24bc5d92011-03-30 18:16:51 +00001005 m_arch = executable_sp->GetArchitecture();
Jason Molenda8c6cf432012-12-05 00:25:49 +00001006 if (log)
1007 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1008 }
1009
Chris Lattner24943d22010-06-08 16:52:24 +00001010 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001011 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +00001012
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001013 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +00001014 {
1015 executable_objfile->GetDependentModules(dependent_files);
1016 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1017 {
Greg Claytonb1888f22011-03-19 01:12:21 +00001018 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1019 FileSpec platform_dependent_file_spec;
1020 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +00001021 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +00001022 else
1023 platform_dependent_file_spec = dependent_file_spec;
1024
Greg Clayton444fe992012-02-26 05:51:37 +00001025 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1026 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +00001027 if (image_module_sp.get())
1028 {
Chris Lattner24943d22010-06-08 16:52:24 +00001029 ObjectFile *objfile = image_module_sp->GetObjectFile();
1030 if (objfile)
1031 objfile->GetDependentModules(dependent_files);
1032 }
1033 }
1034 }
Chris Lattner24943d22010-06-08 16:52:24 +00001035 }
1036}
1037
1038
Jim Ingham7508e732010-08-09 23:31:02 +00001039bool
1040Target::SetArchitecture (const ArchSpec &arch_spec)
1041{
Jason Molenda8c6cf432012-12-05 00:25:49 +00001042 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Greg Claytonb170aee2012-05-08 01:45:38 +00001043 if (m_arch == arch_spec || !m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +00001044 {
Greg Claytonb170aee2012-05-08 01:45:38 +00001045 // If we haven't got a valid arch spec, or the architectures are
1046 // compatible, so just update the architecture. Architectures can be
1047 // equal, yet the triple OS and vendor might change, so we need to do
1048 // the assignment here just in case.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001049 m_arch = arch_spec;
Jason Molenda8c6cf432012-12-05 00:25:49 +00001050 if (log)
1051 log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Jim Ingham7508e732010-08-09 23:31:02 +00001052 return true;
1053 }
1054 else
1055 {
1056 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molenda8c6cf432012-12-05 00:25:49 +00001057 if (log)
1058 printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Clayton24bc5d92011-03-30 18:16:51 +00001059 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +00001060 ModuleSP executable_sp = GetExecutableModule ();
1061 m_images.Clear();
1062 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +00001063 m_scratch_ast_source_ap.reset();
1064 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +00001065 // Need to do something about unsetting breakpoints.
1066
1067 if (executable_sp)
1068 {
Jason Molenda8c6cf432012-12-05 00:25:49 +00001069 if (log)
1070 log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Clayton444fe992012-02-26 05:51:37 +00001071 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1072 Error error = ModuleList::GetSharedModule (module_spec,
1073 executable_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001074 &GetExecutableSearchPaths(),
Greg Clayton444fe992012-02-26 05:51:37 +00001075 NULL,
1076 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +00001077
1078 if (!error.Fail() && executable_sp)
1079 {
1080 SetExecutableModule (executable_sp, true);
1081 return true;
1082 }
Jim Ingham7508e732010-08-09 23:31:02 +00001083 }
1084 }
Greg Claytonb170aee2012-05-08 01:45:38 +00001085 return false;
Jim Ingham7508e732010-08-09 23:31:02 +00001086}
Chris Lattner24943d22010-06-08 16:52:24 +00001087
Chris Lattner24943d22010-06-08 16:52:24 +00001088void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001089Target::WillClearList (const ModuleList& module_list)
Enrico Granata146d9522012-11-08 02:22:02 +00001090{
1091}
1092
1093void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001094Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001095{
1096 // A module is being added to this target for the first time
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001097 ModuleList my_module_list;
1098 my_module_list.Append(module_sp);
Enrico Granata146d9522012-11-08 02:22:02 +00001099 LoadScriptingResourceForModule(module_sp, this);
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001100 ModulesDidLoad (my_module_list);
Chris Lattner24943d22010-06-08 16:52:24 +00001101}
1102
1103void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001104Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata146d9522012-11-08 02:22:02 +00001105{
1106 // A module is being added to this target for the first time
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001107 ModuleList my_module_list;
1108 my_module_list.Append(module_sp);
1109 ModulesDidUnload (my_module_list);
Enrico Granata146d9522012-11-08 02:22:02 +00001110}
1111
1112void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001113Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001114{
Jim Ingham3b8a6052011-08-03 01:00:06 +00001115 // A module is replacing an already added module
Jim Ingham03e5e512012-05-17 18:38:42 +00001116 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner24943d22010-06-08 16:52:24 +00001117}
1118
1119void
1120Target::ModulesDidLoad (ModuleList &module_list)
1121{
Enrico Granata146d9522012-11-08 02:22:02 +00001122 if (module_list.GetSize())
1123 {
1124 m_breakpoint_list.UpdateBreakpoints (module_list, true);
1125 // TODO: make event data that packages up the module_list
1126 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1127 }
Chris Lattner24943d22010-06-08 16:52:24 +00001128}
1129
1130void
1131Target::ModulesDidUnload (ModuleList &module_list)
1132{
Enrico Granata146d9522012-11-08 02:22:02 +00001133 if (module_list.GetSize())
1134 {
1135 m_breakpoint_list.UpdateBreakpoints (module_list, false);
1136 // TODO: make event data that packages up the module_list
1137 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1138 }
Chris Lattner24943d22010-06-08 16:52:24 +00001139}
1140
Daniel Dunbar705a0982011-10-31 22:50:37 +00001141bool
Greg Clayton444fe992012-02-26 05:51:37 +00001142Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +00001143{
Greg Clayton73844aa2012-08-22 17:17:09 +00001144 if (GetBreakpointsConsultPlatformAvoidList())
Jim Ingham7089d8a2011-10-28 23:14:11 +00001145 {
1146 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +00001147 ModuleSpec module_spec (module_file_spec);
1148 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001149
1150 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1151 // black list.
1152 if (num_modules > 0)
1153 {
1154 for (int i = 0; i < num_modules; i++)
1155 {
1156 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1157 return false;
1158 }
1159 return true;
1160 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00001161 }
Greg Clayton73844aa2012-08-22 17:17:09 +00001162 return false;
Jim Ingham7089d8a2011-10-28 23:14:11 +00001163}
1164
Daniel Dunbar705a0982011-10-31 22:50:37 +00001165bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001166Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1167{
Greg Clayton73844aa2012-08-22 17:17:09 +00001168 if (GetBreakpointsConsultPlatformAvoidList())
Jim Ingham7089d8a2011-10-28 23:14:11 +00001169 {
Greg Clayton73844aa2012-08-22 17:17:09 +00001170 if (m_platform_sp)
1171 return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001172 }
Greg Clayton73844aa2012-08-22 17:17:09 +00001173 return false;
Jim Ingham7089d8a2011-10-28 23:14:11 +00001174}
1175
Chris Lattner24943d22010-06-08 16:52:24 +00001176size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001177Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1178{
Greg Clayton3508c382012-02-24 01:59:29 +00001179 SectionSP section_sp (addr.GetSection());
1180 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001181 {
Jason Molenda6b028d62012-04-25 00:06:56 +00001182 // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory.
1183 if (section_sp->IsEncrypted())
1184 {
Greg Clayton04e6ada2012-05-25 17:05:55 +00001185 error.SetErrorString("section is encrypted");
Jason Molenda6b028d62012-04-25 00:06:56 +00001186 return 0;
1187 }
Greg Clayton3508c382012-02-24 01:59:29 +00001188 ModuleSP module_sp (section_sp->GetModule());
1189 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001190 {
Greg Clayton3508c382012-02-24 01:59:29 +00001191 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1192 if (objfile)
1193 {
1194 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1195 addr.GetOffset(),
1196 dst,
1197 dst_len);
1198 if (bytes_read > 0)
1199 return bytes_read;
1200 else
1201 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1202 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001203 else
Greg Clayton3508c382012-02-24 01:59:29 +00001204 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001205 }
1206 else
Greg Clayton3508c382012-02-24 01:59:29 +00001207 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001208 }
1209 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001210 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001211
Greg Clayton26100dc2011-01-07 01:57:07 +00001212 return 0;
1213}
1214
1215size_t
Enrico Granata91544802011-09-06 19:20:51 +00001216Target::ReadMemory (const Address& addr,
1217 bool prefer_file_cache,
1218 void *dst,
1219 size_t dst_len,
1220 Error &error,
1221 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001222{
Chris Lattner24943d22010-06-08 16:52:24 +00001223 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001224
Enrico Granata91544802011-09-06 19:20:51 +00001225 // if we end up reading this from process memory, we will fill this
1226 // with the actual load address
1227 if (load_addr_ptr)
1228 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1229
Greg Clayton26100dc2011-01-07 01:57:07 +00001230 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001231
1232 addr_t load_addr = LLDB_INVALID_ADDRESS;
1233 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001234 Address resolved_addr;
1235 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001236 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001237 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001238 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001239 // No sections are loaded, so we must assume we are not running
1240 // yet and anything we are given is a file address.
1241 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1242 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001243 }
Greg Clayton70436352010-06-30 23:03:03 +00001244 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001245 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001246 // We have at least one section loaded. This can be becuase
1247 // we have manually loaded some sections with "target modules load ..."
1248 // or because we have have a live process that has sections loaded
1249 // through the dynamic loader
1250 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1251 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001252 }
Greg Clayton70436352010-06-30 23:03:03 +00001253 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001254 if (!resolved_addr.IsValid())
1255 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001256
Greg Clayton9b82f862011-07-11 05:12:02 +00001257
Greg Clayton26100dc2011-01-07 01:57:07 +00001258 if (prefer_file_cache)
1259 {
1260 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1261 if (bytes_read > 0)
1262 return bytes_read;
1263 }
Greg Clayton70436352010-06-30 23:03:03 +00001264
Johnny Chenda5a8022011-09-20 23:28:55 +00001265 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001266 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001267 if (load_addr == LLDB_INVALID_ADDRESS)
1268 load_addr = resolved_addr.GetLoadAddress (this);
1269
Greg Clayton70436352010-06-30 23:03:03 +00001270 if (load_addr == LLDB_INVALID_ADDRESS)
1271 {
Greg Clayton3508c382012-02-24 01:59:29 +00001272 ModuleSP addr_module_sp (resolved_addr.GetModule());
1273 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001274 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001275 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001276 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001277 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001278 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001279 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001280 }
1281 else
1282 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001283 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001284 if (bytes_read != dst_len)
1285 {
1286 if (error.Success())
1287 {
1288 if (bytes_read == 0)
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001289 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001290 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001291 error.SetErrorStringWithFormat("only %" PRIu64 " of %" PRIu64 " bytes were read from memory at 0x%" PRIx64, (uint64_t)bytes_read, (uint64_t)dst_len, load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001292 }
1293 }
Greg Clayton70436352010-06-30 23:03:03 +00001294 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001295 {
1296 if (load_addr_ptr)
1297 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001298 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001299 }
Greg Clayton70436352010-06-30 23:03:03 +00001300 // If the address is not section offset we have an address that
1301 // doesn't resolve to any address in any currently loaded shared
1302 // libaries and we failed to read memory so there isn't anything
1303 // more we can do. If it is section offset, we might be able to
1304 // read cached memory from the object file.
1305 if (!resolved_addr.IsSectionOffset())
1306 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001307 }
Chris Lattner24943d22010-06-08 16:52:24 +00001308 }
Greg Clayton70436352010-06-30 23:03:03 +00001309
Greg Clayton9b82f862011-07-11 05:12:02 +00001310 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001311 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001312 // If we didn't already try and read from the object file cache, then
1313 // try it after failing to read from the process.
1314 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001315 }
1316 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001317}
1318
Greg Clayton7dd98df2011-07-12 17:06:17 +00001319size_t
1320Target::ReadScalarIntegerFromMemory (const Address& addr,
1321 bool prefer_file_cache,
1322 uint32_t byte_size,
1323 bool is_signed,
1324 Scalar &scalar,
1325 Error &error)
1326{
1327 uint64_t uval;
1328
1329 if (byte_size <= sizeof(uval))
1330 {
1331 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1332 if (bytes_read == byte_size)
1333 {
1334 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1335 uint32_t offset = 0;
1336 if (byte_size <= 4)
1337 scalar = data.GetMaxU32 (&offset, byte_size);
1338 else
1339 scalar = data.GetMaxU64 (&offset, byte_size);
1340
1341 if (is_signed)
1342 scalar.SignExtend(byte_size * 8);
1343 return bytes_read;
1344 }
1345 }
1346 else
1347 {
1348 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1349 }
1350 return 0;
1351}
1352
1353uint64_t
1354Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1355 bool prefer_file_cache,
1356 size_t integer_byte_size,
1357 uint64_t fail_value,
1358 Error &error)
1359{
1360 Scalar scalar;
1361 if (ReadScalarIntegerFromMemory (addr,
1362 prefer_file_cache,
1363 integer_byte_size,
1364 false,
1365 scalar,
1366 error))
1367 return scalar.ULongLong(fail_value);
1368 return fail_value;
1369}
1370
1371bool
1372Target::ReadPointerFromMemory (const Address& addr,
1373 bool prefer_file_cache,
1374 Error &error,
1375 Address &pointer_addr)
1376{
1377 Scalar scalar;
1378 if (ReadScalarIntegerFromMemory (addr,
1379 prefer_file_cache,
1380 m_arch.GetAddressByteSize(),
1381 false,
1382 scalar,
1383 error))
1384 {
1385 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1386 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1387 {
1388 if (m_section_load_list.IsEmpty())
1389 {
1390 // No sections are loaded, so we must assume we are not running
1391 // yet and anything we are given is a file address.
1392 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1393 }
1394 else
1395 {
1396 // We have at least one section loaded. This can be becuase
1397 // we have manually loaded some sections with "target modules load ..."
1398 // or because we have have a live process that has sections loaded
1399 // through the dynamic loader
1400 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1401 }
1402 // We weren't able to resolve the pointer value, so just return
1403 // an address with no section
1404 if (!pointer_addr.IsValid())
1405 pointer_addr.SetOffset (pointer_vm_addr);
1406 return true;
1407
1408 }
1409 }
1410 return false;
1411}
Chris Lattner24943d22010-06-08 16:52:24 +00001412
1413ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001414Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001415{
Chris Lattner24943d22010-06-08 16:52:24 +00001416 ModuleSP module_sp;
1417
Chris Lattner24943d22010-06-08 16:52:24 +00001418 Error error;
1419
Jim Ingham03e5e512012-05-17 18:38:42 +00001420 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1421 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytone1ef1e32012-04-27 00:58:27 +00001422
Jim Ingham03e5e512012-05-17 18:38:42 +00001423 if (module_spec.GetUUID().IsValid())
1424 module_sp = m_images.FindFirstModule(module_spec);
1425
Greg Claytone1ef1e32012-04-27 00:58:27 +00001426 if (!module_sp)
1427 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001428 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1429 bool did_create_module = false;
1430
1431 // If there are image search path entries, try to use them first to acquire a suitable image.
1432 if (m_image_search_paths.GetSize())
Greg Claytone1ef1e32012-04-27 00:58:27 +00001433 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001434 ModuleSpec transformed_spec (module_spec);
1435 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1436 {
1437 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1438 error = ModuleList::GetSharedModule (transformed_spec,
1439 module_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001440 &GetExecutableSearchPaths(),
Jim Ingham03e5e512012-05-17 18:38:42 +00001441 &old_module_sp,
1442 &did_create_module);
1443 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001444 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001445
Greg Claytone1ef1e32012-04-27 00:58:27 +00001446 if (!module_sp)
1447 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001448 // If we have a UUID, we can check our global shared module list in case
1449 // we already have it. If we don't have a valid UUID, then we can't since
1450 // the path in "module_spec" will be a platform path, and we will need to
1451 // let the platform find that file. For example, we could be asking for
1452 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1453 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1454 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1455 // cache.
1456 if (module_spec.GetUUID().IsValid())
Greg Claytone1ef1e32012-04-27 00:58:27 +00001457 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001458 // We have a UUID, it is OK to check the global module list...
1459 error = ModuleList::GetSharedModule (module_spec,
1460 module_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001461 &GetExecutableSearchPaths(),
Greg Clayton73844aa2012-08-22 17:17:09 +00001462 &old_module_sp,
Jim Ingham03e5e512012-05-17 18:38:42 +00001463 &did_create_module);
Greg Claytone1ef1e32012-04-27 00:58:27 +00001464 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001465
1466 if (!module_sp)
Greg Claytone1ef1e32012-04-27 00:58:27 +00001467 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001468 // The platform is responsible for finding and caching an appropriate
1469 // module in the shared module cache.
1470 if (m_platform_sp)
1471 {
1472 FileSpec platform_file_spec;
1473 error = m_platform_sp->GetSharedModule (module_spec,
1474 module_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001475 &GetExecutableSearchPaths(),
Greg Clayton73844aa2012-08-22 17:17:09 +00001476 &old_module_sp,
Jim Ingham03e5e512012-05-17 18:38:42 +00001477 &did_create_module);
1478 }
1479 else
1480 {
1481 error.SetErrorString("no platform is currently set");
1482 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001483 }
1484 }
Chris Lattner24943d22010-06-08 16:52:24 +00001485
Jim Ingham03e5e512012-05-17 18:38:42 +00001486 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1487 // module in the list already, and if there was, let's remove it.
1488 if (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001489 {
Greg Clayton1649a722012-11-29 22:16:27 +00001490 ObjectFile *objfile = module_sp->GetObjectFile();
1491 if (objfile)
Jim Ingham03e5e512012-05-17 18:38:42 +00001492 {
Greg Clayton1649a722012-11-29 22:16:27 +00001493 switch (objfile->GetType())
Jim Ingham03e5e512012-05-17 18:38:42 +00001494 {
Greg Clayton1649a722012-11-29 22:16:27 +00001495 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1496 case ObjectFile::eTypeExecutable: /// A normal executable
1497 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1498 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1499 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1500 break;
1501 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1502 if (error_ptr)
1503 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1504 return ModuleSP();
1505 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1506 if (error_ptr)
1507 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1508 return ModuleSP();
1509 default:
1510 if (error_ptr)
1511 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1512 return ModuleSP();
1513 }
1514 // GetSharedModule is not guaranteed to find the old shared module, for instance
1515 // in the common case where you pass in the UUID, it is only going to find the one
1516 // module matching the UUID. In fact, it has no good way to know what the "old module"
1517 // relevant to this target is, since there might be many copies of a module with this file spec
1518 // in various running debug sessions, but only one of them will belong to this target.
1519 // So let's remove the UUID from the module list, and look in the target's module list.
1520 // Only do this if there is SOMETHING else in the module spec...
1521 if (!old_module_sp)
1522 {
1523 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham03e5e512012-05-17 18:38:42 +00001524 {
Greg Clayton1649a722012-11-29 22:16:27 +00001525 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1526 module_spec_copy.GetUUID().Clear();
1527
1528 ModuleList found_modules;
1529 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1530 if (num_found == 1)
1531 {
1532 old_module_sp = found_modules.GetModuleAtIndex(0);
1533 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001534 }
1535 }
Greg Clayton1649a722012-11-29 22:16:27 +00001536
1537 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1538 {
1539 m_images.ReplaceModule(old_module_sp, module_sp);
1540 Module *old_module_ptr = old_module_sp.get();
1541 old_module_sp.reset();
1542 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1543 }
1544 else
1545 m_images.Append(module_sp);
Jim Ingham03e5e512012-05-17 18:38:42 +00001546 }
Chris Lattner24943d22010-06-08 16:52:24 +00001547 }
1548 }
1549 if (error_ptr)
1550 *error_ptr = error;
1551 return module_sp;
1552}
1553
1554
Greg Clayton289afcb2012-02-18 05:35:26 +00001555TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001556Target::CalculateTarget ()
1557{
Greg Clayton289afcb2012-02-18 05:35:26 +00001558 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001559}
1560
Greg Clayton289afcb2012-02-18 05:35:26 +00001561ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001562Target::CalculateProcess ()
1563{
Greg Clayton289afcb2012-02-18 05:35:26 +00001564 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001565}
1566
Greg Clayton289afcb2012-02-18 05:35:26 +00001567ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001568Target::CalculateThread ()
1569{
Greg Clayton289afcb2012-02-18 05:35:26 +00001570 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001571}
1572
Greg Clayton289afcb2012-02-18 05:35:26 +00001573StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001574Target::CalculateStackFrame ()
1575{
Greg Clayton289afcb2012-02-18 05:35:26 +00001576 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001577}
1578
1579void
Greg Claytona830adb2010-10-04 01:05:56 +00001580Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001581{
Greg Clayton567e7f32011-09-22 04:58:26 +00001582 exe_ctx.Clear();
1583 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001584}
1585
1586PathMappingList &
1587Target::GetImageSearchPathList ()
1588{
1589 return m_image_search_paths;
1590}
1591
1592void
1593Target::ImageSearchPathsChanged
1594(
1595 const PathMappingList &path_list,
1596 void *baton
1597)
1598{
1599 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001600 ModuleSP exe_module_sp (target->GetExecutableModule());
1601 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001602 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001603 target->m_images.Clear();
1604 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001605 }
1606}
1607
1608ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001609Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001610{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001611 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001612 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001613 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001614 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001615 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001616 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1617 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1618 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1619 }
Chris Lattner24943d22010-06-08 16:52:24 +00001620 return m_scratch_ast_context_ap.get();
1621}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001622
Sean Callanan4938bd62011-11-16 18:20:47 +00001623ClangASTImporter *
1624Target::GetClangASTImporter()
1625{
1626 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1627
1628 if (!ast_importer)
1629 {
1630 ast_importer = new ClangASTImporter();
1631 m_ast_importer_ap.reset(ast_importer);
1632 }
1633
1634 return ast_importer;
1635}
1636
Greg Clayton990de7b2010-11-18 23:32:35 +00001637void
Caroline Tice2a456812011-03-10 22:14:10 +00001638Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001639{
Greg Claytonc6e82e42012-08-22 18:39:03 +00001640 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001641}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001642
Greg Clayton990de7b2010-11-18 23:32:35 +00001643void
Caroline Tice2a456812011-03-10 22:14:10 +00001644Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001645{
Greg Claytonc6e82e42012-08-22 18:39:03 +00001646 Process::SettingsTerminate ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001647}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001648
Greg Clayton9ce95382012-02-13 23:10:39 +00001649FileSpecList
1650Target::GetDefaultExecutableSearchPaths ()
1651{
Greg Clayton73844aa2012-08-22 17:17:09 +00001652 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1653 if (properties_sp)
1654 return properties_sp->GetExecutableSearchPaths();
Greg Clayton9ce95382012-02-13 23:10:39 +00001655 return FileSpecList();
1656}
1657
Caroline Tice5bc8c972010-09-20 20:44:43 +00001658ArchSpec
1659Target::GetDefaultArchitecture ()
1660{
Greg Clayton73844aa2012-08-22 17:17:09 +00001661 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1662 if (properties_sp)
1663 return properties_sp->GetDefaultArchitecture();
Greg Clayton469e08d2012-05-15 02:44:13 +00001664 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001665}
1666
1667void
Greg Clayton73844aa2012-08-22 17:17:09 +00001668Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001669{
Greg Clayton73844aa2012-08-22 17:17:09 +00001670 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1671 if (properties_sp)
1672 return properties_sp->SetDefaultArchitecture(arch);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001673}
1674
Greg Claytona830adb2010-10-04 01:05:56 +00001675Target *
1676Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1677{
1678 // The target can either exist in the "process" of ExecutionContext, or in
1679 // the "target_sp" member of SymbolContext. This accessor helper function
1680 // will get the target from one of these locations.
1681
1682 Target *target = NULL;
1683 if (sc_ptr != NULL)
1684 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001685 if (target == NULL && exe_ctx_ptr)
1686 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001687 return target;
1688}
1689
Greg Clayton427f2902010-12-14 02:59:59 +00001690ExecutionResults
1691Target::EvaluateExpression
1692(
1693 const char *expr_cstr,
1694 StackFrame *frame,
Enrico Granata6cca9692012-07-16 23:10:35 +00001695 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad27026e2012-09-05 20:41:26 +00001696 const EvaluateExpressionOptions& options
Greg Clayton427f2902010-12-14 02:59:59 +00001697)
1698{
Enrico Granata3a08fd12012-09-18 17:43:16 +00001699 result_valobj_sp.reset();
1700
Greg Clayton427f2902010-12-14 02:59:59 +00001701 ExecutionResults execution_results = eExecutionSetupError;
1702
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001703 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1704 return execution_results;
1705
Jim Ingham3613ae12011-05-12 02:06:14 +00001706 // We shouldn't run stop hooks in expressions.
1707 // Be sure to reset this if you return anywhere within this function.
1708 bool old_suppress_value = m_suppress_stop_hooks;
1709 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001710
1711 ExecutionContext exe_ctx;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001712
1713 const size_t expr_cstr_len = ::strlen (expr_cstr);
1714
Greg Clayton427f2902010-12-14 02:59:59 +00001715 if (frame)
1716 {
1717 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +00001718 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +00001719 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granataf6698502011-08-09 01:04:56 +00001720 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1721 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham10de7d12011-05-04 03:43:18 +00001722 lldb::VariableSP var_sp;
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001723
1724 // Make sure we don't have any things that we know a variable expression
1725 // won't be able to deal with before calling into it
1726 if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
1727 {
1728 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
Enrico Granatad27026e2012-09-05 20:41:26 +00001729 options.GetUseDynamic(),
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001730 expr_path_options,
1731 var_sp,
1732 error);
Enrico Granata4d609c92012-04-24 22:15:37 +00001733 // if this expression results in a bitfield, we give up and let the IR handle it
1734 if (result_valobj_sp && result_valobj_sp->IsBitfield())
1735 result_valobj_sp.reset();
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001736 }
Greg Clayton427f2902010-12-14 02:59:59 +00001737 }
1738 else if (m_process_sp)
1739 {
1740 m_process_sp->CalculateExecutionContext(exe_ctx);
1741 }
1742 else
1743 {
1744 CalculateExecutionContext(exe_ctx);
1745 }
1746
1747 if (result_valobj_sp)
1748 {
1749 execution_results = eExecutionCompleted;
1750 // We got a result from the frame variable expression path above...
1751 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1752
1753 lldb::ValueObjectSP const_valobj_sp;
1754
1755 // Check in case our value is already a constant value
1756 if (result_valobj_sp->GetIsConstant())
1757 {
1758 const_valobj_sp = result_valobj_sp;
1759 const_valobj_sp->SetName (persistent_variable_name);
1760 }
1761 else
Jim Inghame41494a2011-04-16 00:01:13 +00001762 {
Enrico Granatad27026e2012-09-05 20:41:26 +00001763 if (options.GetUseDynamic() != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +00001764 {
Enrico Granatad27026e2012-09-05 20:41:26 +00001765 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(options.GetUseDynamic());
Jim Inghame41494a2011-04-16 00:01:13 +00001766 if (dynamic_sp)
1767 result_valobj_sp = dynamic_sp;
1768 }
1769
Jim Inghamfa3a16a2011-03-31 00:19:25 +00001770 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +00001771 }
Greg Clayton427f2902010-12-14 02:59:59 +00001772
Sean Callanan6a925532011-01-13 08:53:35 +00001773 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1774
Greg Clayton427f2902010-12-14 02:59:59 +00001775 result_valobj_sp = const_valobj_sp;
1776
Sean Callanan6a925532011-01-13 08:53:35 +00001777 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1778 assert (clang_expr_variable_sp.get());
1779
1780 // Set flags and live data as appropriate
1781
1782 const Value &result_value = live_valobj_sp->GetValue();
1783
1784 switch (result_value.GetValueType())
1785 {
1786 case Value::eValueTypeHostAddress:
1787 case Value::eValueTypeFileAddress:
1788 // we don't do anything with these for now
1789 break;
1790 case Value::eValueTypeScalar:
Greg Claytonf0fab4f2012-10-30 23:56:14 +00001791 case Value::eValueTypeVector:
Sean Callanan6a925532011-01-13 08:53:35 +00001792 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1793 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1794 break;
1795 case Value::eValueTypeLoadAddress:
1796 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1797 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1798 break;
1799 }
Greg Clayton427f2902010-12-14 02:59:59 +00001800 }
1801 else
1802 {
1803 // Make sure we aren't just trying to see the value of a persistent
1804 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +00001805 lldb::ClangExpressionVariableSP persistent_var_sp;
1806 // Only check for persistent variables the expression starts with a '$'
1807 if (expr_cstr[0] == '$')
1808 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1809
Greg Clayton427f2902010-12-14 02:59:59 +00001810 if (persistent_var_sp)
1811 {
1812 result_valobj_sp = persistent_var_sp->GetValueObject ();
1813 execution_results = eExecutionCompleted;
1814 }
1815 else
1816 {
1817 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan47dc4572011-09-15 02:13:07 +00001818
Greg Clayton427f2902010-12-14 02:59:59 +00001819 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Enrico Granatad27026e2012-09-05 20:41:26 +00001820 options.GetExecutionPolicy(),
Sean Callanan5b658cc2011-11-07 23:35:40 +00001821 lldb::eLanguageTypeUnknown,
Enrico Granatad27026e2012-09-05 20:41:26 +00001822 options.DoesCoerceToId() ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
1823 options.DoesUnwindOnError(),
Greg Clayton427f2902010-12-14 02:59:59 +00001824 expr_cstr,
1825 prefix,
Enrico Granata6cca9692012-07-16 23:10:35 +00001826 result_valobj_sp,
Jim Ingham47beabb2012-10-16 21:41:58 +00001827 options.GetRunOthers(),
1828 options.GetTimeoutUsec());
Greg Clayton427f2902010-12-14 02:59:59 +00001829 }
1830 }
Jim Ingham3613ae12011-05-12 02:06:14 +00001831
1832 m_suppress_stop_hooks = old_suppress_value;
1833
Greg Clayton427f2902010-12-14 02:59:59 +00001834 return execution_results;
1835}
1836
Greg Claytonc0fa5332011-05-22 22:46:53 +00001837lldb::addr_t
1838Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1839{
1840 addr_t code_addr = load_addr;
1841 switch (m_arch.GetMachine())
1842 {
1843 case llvm::Triple::arm:
1844 case llvm::Triple::thumb:
1845 switch (addr_class)
1846 {
1847 case eAddressClassData:
1848 case eAddressClassDebug:
1849 return LLDB_INVALID_ADDRESS;
1850
1851 case eAddressClassUnknown:
1852 case eAddressClassInvalid:
1853 case eAddressClassCode:
1854 case eAddressClassCodeAlternateISA:
1855 case eAddressClassRuntime:
1856 // Check if bit zero it no set?
1857 if ((code_addr & 1ull) == 0)
1858 {
1859 // Bit zero isn't set, check if the address is a multiple of 2?
1860 if (code_addr & 2ull)
1861 {
1862 // The address is a multiple of 2 so it must be thumb, set bit zero
1863 code_addr |= 1ull;
1864 }
1865 else if (addr_class == eAddressClassCodeAlternateISA)
1866 {
1867 // We checked the address and the address claims to be the alternate ISA
1868 // which means thumb, so set bit zero.
1869 code_addr |= 1ull;
1870 }
1871 }
1872 break;
1873 }
1874 break;
1875
1876 default:
1877 break;
1878 }
1879 return code_addr;
1880}
1881
1882lldb::addr_t
1883Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1884{
1885 addr_t opcode_addr = load_addr;
1886 switch (m_arch.GetMachine())
1887 {
1888 case llvm::Triple::arm:
1889 case llvm::Triple::thumb:
1890 switch (addr_class)
1891 {
1892 case eAddressClassData:
1893 case eAddressClassDebug:
1894 return LLDB_INVALID_ADDRESS;
1895
1896 case eAddressClassInvalid:
1897 case eAddressClassUnknown:
1898 case eAddressClassCode:
1899 case eAddressClassCodeAlternateISA:
1900 case eAddressClassRuntime:
1901 opcode_addr &= ~(1ull);
1902 break;
1903 }
1904 break;
1905
1906 default:
1907 break;
1908 }
1909 return opcode_addr;
1910}
1911
Jim Inghamd60d94a2011-03-11 03:53:59 +00001912lldb::user_id_t
1913Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1914{
1915 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001916 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001917 m_stop_hooks[new_uid] = new_hook_sp;
1918 return new_uid;
1919}
1920
1921bool
1922Target::RemoveStopHookByID (lldb::user_id_t user_id)
1923{
1924 size_t num_removed;
1925 num_removed = m_stop_hooks.erase (user_id);
1926 if (num_removed == 0)
1927 return false;
1928 else
1929 return true;
1930}
1931
1932void
1933Target::RemoveAllStopHooks ()
1934{
1935 m_stop_hooks.clear();
1936}
1937
1938Target::StopHookSP
1939Target::GetStopHookByID (lldb::user_id_t user_id)
1940{
1941 StopHookSP found_hook;
1942
1943 StopHookCollection::iterator specified_hook_iter;
1944 specified_hook_iter = m_stop_hooks.find (user_id);
1945 if (specified_hook_iter != m_stop_hooks.end())
1946 found_hook = (*specified_hook_iter).second;
1947 return found_hook;
1948}
1949
1950bool
1951Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1952{
1953 StopHookCollection::iterator specified_hook_iter;
1954 specified_hook_iter = m_stop_hooks.find (user_id);
1955 if (specified_hook_iter == m_stop_hooks.end())
1956 return false;
1957
1958 (*specified_hook_iter).second->SetIsActive (active_state);
1959 return true;
1960}
1961
1962void
1963Target::SetAllStopHooksActiveState (bool active_state)
1964{
1965 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1966 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1967 {
1968 (*pos).second->SetIsActive (active_state);
1969 }
1970}
1971
1972void
1973Target::RunStopHooks ()
1974{
Jim Ingham3613ae12011-05-12 02:06:14 +00001975 if (m_suppress_stop_hooks)
1976 return;
1977
Jim Inghamd60d94a2011-03-11 03:53:59 +00001978 if (!m_process_sp)
1979 return;
Enrico Granata5a60f5e2012-08-03 22:24:48 +00001980
1981 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
1982 // since in that case we do not want to run the stop-hooks
1983 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
1984 return;
1985
Jim Inghamd60d94a2011-03-11 03:53:59 +00001986 if (m_stop_hooks.empty())
1987 return;
1988
1989 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1990
1991 // If there aren't any active stop hooks, don't bother either:
1992 bool any_active_hooks = false;
1993 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1994 {
1995 if ((*pos).second->IsActive())
1996 {
1997 any_active_hooks = true;
1998 break;
1999 }
2000 }
2001 if (!any_active_hooks)
2002 return;
2003
2004 CommandReturnObject result;
2005
2006 std::vector<ExecutionContext> exc_ctx_with_reasons;
2007 std::vector<SymbolContext> sym_ctx_with_reasons;
2008
2009 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2010 size_t num_threads = cur_threadlist.GetSize();
2011 for (size_t i = 0; i < num_threads; i++)
2012 {
2013 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2014 if (cur_thread_sp->ThreadStoppedForAReason())
2015 {
2016 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
2017 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2018 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2019 }
2020 }
2021
2022 // If no threads stopped for a reason, don't run the stop-hooks.
2023 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2024 if (num_exe_ctx == 0)
2025 return;
2026
Jim Inghame5ed8e92011-06-02 23:58:26 +00002027 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2028 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002029
2030 bool keep_going = true;
2031 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00002032 bool print_hook_header;
2033 bool print_thread_header;
2034
2035 if (num_exe_ctx == 1)
2036 print_thread_header = false;
2037 else
2038 print_thread_header = true;
2039
2040 if (m_stop_hooks.size() == 1)
2041 print_hook_header = false;
2042 else
2043 print_hook_header = true;
2044
Jim Inghamd60d94a2011-03-11 03:53:59 +00002045 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2046 {
2047 // result.Clear();
2048 StopHookSP cur_hook_sp = (*pos).second;
2049 if (!cur_hook_sp->IsActive())
2050 continue;
2051
2052 bool any_thread_matched = false;
2053 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2054 {
2055 if ((cur_hook_sp->GetSpecifier () == NULL
2056 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2057 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Inghama2664912012-03-07 22:03:04 +00002058 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00002059 {
2060 if (!hooks_ran)
2061 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00002062 hooks_ran = true;
2063 }
Jim Inghamc54840c2011-03-22 01:47:27 +00002064 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002065 {
Johnny Chen4d96a742011-10-24 23:01:06 +00002066 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2067 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2068 NULL);
2069 if (cmd)
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002070 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chen4d96a742011-10-24 23:01:06 +00002071 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002072 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002073 any_thread_matched = true;
2074 }
2075
Jim Inghamc54840c2011-03-22 01:47:27 +00002076 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00002077 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002078
2079 bool stop_on_continue = true;
2080 bool stop_on_error = true;
2081 bool echo_commands = false;
2082 bool print_results = true;
2083 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00002084 &exc_ctx_with_reasons[i],
2085 stop_on_continue,
2086 stop_on_error,
2087 echo_commands,
Enrico Granata01bc2d42012-05-31 01:09:06 +00002088 print_results,
2089 eLazyBoolNo,
Greg Clayton24bc5d92011-03-30 18:16:51 +00002090 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00002091
2092 // If the command started the target going again, we should bag out of
2093 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00002094 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2095 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00002096 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002097 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002098 keep_going = false;
2099 }
2100 }
2101 }
2102 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00002103
Caroline Tice4a348082011-05-02 20:41:46 +00002104 result.GetImmediateOutputStream()->Flush();
2105 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00002106}
2107
Greg Claytonbbea1332011-07-08 00:48:09 +00002108
Jim Inghamd60d94a2011-03-11 03:53:59 +00002109//--------------------------------------------------------------
2110// class Target::StopHook
2111//--------------------------------------------------------------
2112
2113
2114Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2115 UserID (uid),
2116 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00002117 m_commands (),
2118 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002119 m_thread_spec_ap(NULL),
2120 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002121{
2122}
2123
2124Target::StopHook::StopHook (const StopHook &rhs) :
2125 UserID (rhs.GetID()),
2126 m_target_sp (rhs.m_target_sp),
2127 m_commands (rhs.m_commands),
2128 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002129 m_thread_spec_ap (NULL),
2130 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002131{
2132 if (rhs.m_thread_spec_ap.get() != NULL)
2133 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2134}
2135
2136
2137Target::StopHook::~StopHook ()
2138{
2139}
2140
2141void
2142Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2143{
2144 m_thread_spec_ap.reset (specifier);
2145}
2146
2147
2148void
2149Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2150{
2151 int indent_level = s->GetIndentLevel();
2152
2153 s->SetIndentLevel(indent_level + 2);
2154
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002155 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002156 if (m_active)
2157 s->Indent ("State: enabled\n");
2158 else
2159 s->Indent ("State: disabled\n");
2160
2161 if (m_specifier_sp)
2162 {
2163 s->Indent();
2164 s->PutCString ("Specifier:\n");
2165 s->SetIndentLevel (indent_level + 4);
2166 m_specifier_sp->GetDescription (s, level);
2167 s->SetIndentLevel (indent_level + 2);
2168 }
2169
2170 if (m_thread_spec_ap.get() != NULL)
2171 {
2172 StreamString tmp;
2173 s->Indent("Thread:\n");
2174 m_thread_spec_ap->GetDescription (&tmp, level);
2175 s->SetIndentLevel (indent_level + 4);
2176 s->Indent (tmp.GetData());
2177 s->PutCString ("\n");
2178 s->SetIndentLevel (indent_level + 2);
2179 }
2180
2181 s->Indent ("Commands: \n");
2182 s->SetIndentLevel (indent_level + 4);
2183 uint32_t num_commands = m_commands.GetSize();
2184 for (uint32_t i = 0; i < num_commands; i++)
2185 {
2186 s->Indent(m_commands.GetStringAtIndex(i));
2187 s->PutCString ("\n");
2188 }
2189 s->SetIndentLevel (indent_level);
2190}
2191
Greg Clayton73844aa2012-08-22 17:17:09 +00002192//--------------------------------------------------------------
2193// class TargetProperties
2194//--------------------------------------------------------------
2195
2196OptionEnumValueElement
2197lldb_private::g_dynamic_value_types[] =
Caroline Tice5bc8c972010-09-20 20:44:43 +00002198{
Greg Clayton73844aa2012-08-22 17:17:09 +00002199 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2200 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2201 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2202 { 0, NULL, NULL }
2203};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002204
Greg Clayton49ce8962012-08-29 21:13:06 +00002205static OptionEnumValueElement
2206g_inline_breakpoint_enums[] =
2207{
2208 { eInlineBreakpointsNever, "never", "Never look for inline breakpoint locations (fastest). This setting should only be used if you know that no inlining occurs in your programs."},
2209 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2210 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2211 { 0, NULL, NULL }
2212};
2213
Greg Clayton73844aa2012-08-22 17:17:09 +00002214static PropertyDefinition
2215g_properties[] =
Caroline Tice5bc8c972010-09-20 20:44:43 +00002216{
Greg Clayton73844aa2012-08-22 17:17:09 +00002217 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2218 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
2219 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
2220 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2221 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2222 { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings used to track the change of location between a source file when built, and "
2223 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2224 "some part (starting at the root) of the path to the file when it was built, "
2225 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2226 "Each element of the array is checked in order and the first one that results in a match wins." },
2227 { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "Executable search paths to use when locating executable files whose paths don't match the local file system." },
2228 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2229 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." },
2230 { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." },
Greg Clayton0c8446c2012-10-17 22:57:12 +00002231 { "arg0" , OptionValue::eTypeString , false, 0 , NULL, NULL, "The first argument passed to the program in the argument array which can be different from the executable itself." },
2232 { "run-args" , OptionValue::eTypeArgs , false, 0 , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0." },
Greg Clayton73844aa2012-08-22 17:17:09 +00002233 { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." },
2234 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2235 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2236 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2237 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
2238 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2239 { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" },
Greg Clayton49ce8962012-08-29 21:13:06 +00002240 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsHeaders , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
2241 "Breakpoint locations can end up being inlined by the compiler, so that a compile unit 'a.c' might contain an inlined function from another source file. "
2242 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2243 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
2244 "Always checking for inlined breakpoint locations can be expensive (memory and time), so we try to minimize the "
2245 "times we look for inlined locations. This setting allows you to control exactly which strategy is used when settings "
2246 "file and line breakpoints." },
Greg Clayton73844aa2012-08-22 17:17:09 +00002247 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2248};
2249enum
Caroline Tice5bc8c972010-09-20 20:44:43 +00002250{
Greg Clayton73844aa2012-08-22 17:17:09 +00002251 ePropertyDefaultArch,
2252 ePropertyExprPrefix,
2253 ePropertyPreferDynamic,
2254 ePropertyEnableSynthetic,
2255 ePropertySkipPrologue,
2256 ePropertySourceMap,
2257 ePropertyExecutableSearchPaths,
2258 ePropertyMaxChildrenCount,
2259 ePropertyMaxSummaryLength,
2260 ePropertyBreakpointUseAvoidList,
Greg Clayton0c8446c2012-10-17 22:57:12 +00002261 ePropertyArg0,
Greg Clayton73844aa2012-08-22 17:17:09 +00002262 ePropertyRunArgs,
2263 ePropertyEnvVars,
2264 ePropertyInheritEnv,
2265 ePropertyInputPath,
2266 ePropertyOutputPath,
2267 ePropertyErrorPath,
2268 ePropertyDisableASLR,
Greg Clayton49ce8962012-08-29 21:13:06 +00002269 ePropertyDisableSTDIO,
Greg Clayton87e9d322012-10-19 18:02:49 +00002270 ePropertyInlineStrategy
Greg Clayton73844aa2012-08-22 17:17:09 +00002271};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002272
Caroline Tice5bc8c972010-09-20 20:44:43 +00002273
Greg Clayton73844aa2012-08-22 17:17:09 +00002274class TargetOptionValueProperties : public OptionValueProperties
Greg Claytond284b662011-02-18 01:44:25 +00002275{
Greg Clayton73844aa2012-08-22 17:17:09 +00002276public:
2277 TargetOptionValueProperties (const ConstString &name) :
2278 OptionValueProperties (name),
2279 m_target (NULL),
2280 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002281 {
Caroline Tice5bc8c972010-09-20 20:44:43 +00002282 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002283
Greg Clayton73844aa2012-08-22 17:17:09 +00002284 // This constructor is used when creating TargetOptionValueProperties when it
2285 // is part of a new lldb_private::Target instance. It will copy all current
2286 // global property values as needed
2287 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2288 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2289 m_target (target),
2290 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002291 {
Greg Clayton73844aa2012-08-22 17:17:09 +00002292 }
2293
2294 virtual const Property *
2295 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2296 {
2297 // When gettings the value for a key from the target options, we will always
2298 // try and grab the setting from the current target if there is one. Else we just
2299 // use the one from this instance.
2300 if (idx == ePropertyEnvVars)
2301 GetHostEnvironmentIfNeeded ();
2302
2303 if (exe_ctx)
2304 {
2305 Target *target = exe_ctx->GetTargetPtr();
2306 if (target)
2307 {
2308 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2309 if (this != target_properties)
2310 return target_properties->ProtectedGetPropertyAtIndex (idx);
2311 }
2312 }
2313 return ProtectedGetPropertyAtIndex (idx);
2314 }
2315protected:
2316
2317 void
2318 GetHostEnvironmentIfNeeded () const
2319 {
2320 if (!m_got_host_env)
2321 {
2322 if (m_target)
2323 {
2324 m_got_host_env = true;
2325 const uint32_t idx = ePropertyInheritEnv;
2326 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
2327 {
2328 PlatformSP platform_sp (m_target->GetPlatform());
2329 if (platform_sp)
2330 {
2331 StringList env;
2332 if (platform_sp->GetEnvironment(env))
2333 {
2334 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
2335 if (env_dict)
2336 {
2337 const bool can_replace = false;
2338 const size_t envc = env.GetSize();
2339 for (size_t idx=0; idx<envc; idx++)
2340 {
2341 const char *env_entry = env.GetStringAtIndex (idx);
2342 if (env_entry)
2343 {
2344 const char *equal_pos = ::strchr(env_entry, '=');
2345 ConstString key;
2346 // It is ok to have environment variables with no values
2347 const char *value = NULL;
2348 if (equal_pos)
2349 {
2350 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
2351 if (equal_pos[1])
2352 value = equal_pos + 1;
2353 }
2354 else
2355 {
2356 key.SetCString(env_entry);
2357 }
2358 // Don't allow existing keys to be replaced with ones we get from the platform environment
2359 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
2360 }
2361 }
2362 }
2363 }
2364 }
2365 }
2366 }
2367 }
2368 }
2369 Target *m_target;
2370 mutable bool m_got_host_env;
2371};
2372
2373TargetProperties::TargetProperties (Target *target) :
2374 Properties ()
2375{
2376 if (target)
2377 {
2378 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002379 }
2380 else
Greg Clayton73844aa2012-08-22 17:17:09 +00002381 {
2382 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
2383 m_collection_sp->Initialize(g_properties);
2384 m_collection_sp->AppendProperty(ConstString("process"),
2385 ConstString("Settings specify to processes."),
2386 true,
2387 Process::GetGlobalProperties()->GetValueProperties());
2388 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002389}
2390
Greg Clayton73844aa2012-08-22 17:17:09 +00002391TargetProperties::~TargetProperties ()
2392{
2393}
2394ArchSpec
2395TargetProperties::GetDefaultArchitecture () const
2396{
2397 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2398 if (value)
2399 return value->GetCurrentValue();
2400 return ArchSpec();
2401}
2402
2403void
2404TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
2405{
2406 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2407 if (value)
2408 return value->SetCurrentValue(arch, true);
2409}
2410
2411lldb::DynamicValueType
2412TargetProperties::GetPreferDynamicValue() const
2413{
2414 const uint32_t idx = ePropertyPreferDynamic;
2415 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2416}
2417
2418bool
2419TargetProperties::GetDisableASLR () const
2420{
2421 const uint32_t idx = ePropertyDisableASLR;
2422 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2423}
2424
2425void
2426TargetProperties::SetDisableASLR (bool b)
2427{
2428 const uint32_t idx = ePropertyDisableASLR;
2429 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2430}
2431
2432bool
2433TargetProperties::GetDisableSTDIO () const
2434{
2435 const uint32_t idx = ePropertyDisableSTDIO;
2436 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2437}
2438
2439void
2440TargetProperties::SetDisableSTDIO (bool b)
2441{
2442 const uint32_t idx = ePropertyDisableSTDIO;
2443 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2444}
2445
Greg Clayton49ce8962012-08-29 21:13:06 +00002446InlineStrategy
2447TargetProperties::GetInlineStrategy () const
2448{
2449 const uint32_t idx = ePropertyInlineStrategy;
2450 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2451}
2452
Greg Clayton0c8446c2012-10-17 22:57:12 +00002453const char *
2454TargetProperties::GetArg0 () const
2455{
2456 const uint32_t idx = ePropertyArg0;
2457 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
2458}
2459
2460void
2461TargetProperties::SetArg0 (const char *arg)
2462{
2463 const uint32_t idx = ePropertyArg0;
2464 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
2465}
2466
Greg Clayton73844aa2012-08-22 17:17:09 +00002467bool
2468TargetProperties::GetRunArguments (Args &args) const
2469{
2470 const uint32_t idx = ePropertyRunArgs;
2471 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
2472}
2473
2474void
2475TargetProperties::SetRunArguments (const Args &args)
2476{
2477 const uint32_t idx = ePropertyRunArgs;
2478 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
2479}
2480
2481size_t
2482TargetProperties::GetEnvironmentAsArgs (Args &env) const
2483{
2484 const uint32_t idx = ePropertyEnvVars;
2485 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
2486}
2487
2488bool
2489TargetProperties::GetSkipPrologue() const
2490{
2491 const uint32_t idx = ePropertySkipPrologue;
2492 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2493}
2494
2495PathMappingList &
2496TargetProperties::GetSourcePathMap () const
2497{
2498 const uint32_t idx = ePropertySourceMap;
2499 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
2500 assert(option_value);
2501 return option_value->GetCurrentValue();
2502}
2503
2504FileSpecList &
Greg Claytonc6e82e42012-08-22 18:39:03 +00002505TargetProperties::GetExecutableSearchPaths ()
Greg Clayton73844aa2012-08-22 17:17:09 +00002506{
2507 const uint32_t idx = ePropertyExecutableSearchPaths;
2508 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2509 assert(option_value);
2510 return option_value->GetCurrentValue();
2511}
2512
2513bool
2514TargetProperties::GetEnableSyntheticValue () const
2515{
2516 const uint32_t idx = ePropertyEnableSynthetic;
2517 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2518}
2519
2520uint32_t
2521TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
2522{
2523 const uint32_t idx = ePropertyMaxChildrenCount;
2524 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2525}
2526
2527uint32_t
2528TargetProperties::GetMaximumSizeOfStringSummary() const
2529{
2530 const uint32_t idx = ePropertyMaxSummaryLength;
2531 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2532}
2533
2534FileSpec
2535TargetProperties::GetStandardInputPath () const
2536{
2537 const uint32_t idx = ePropertyInputPath;
2538 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2539}
2540
2541void
2542TargetProperties::SetStandardInputPath (const char *p)
2543{
2544 const uint32_t idx = ePropertyInputPath;
2545 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2546}
2547
2548FileSpec
2549TargetProperties::GetStandardOutputPath () const
2550{
2551 const uint32_t idx = ePropertyOutputPath;
2552 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2553}
2554
2555void
2556TargetProperties::SetStandardOutputPath (const char *p)
2557{
2558 const uint32_t idx = ePropertyOutputPath;
2559 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2560}
2561
2562FileSpec
2563TargetProperties::GetStandardErrorPath () const
2564{
2565 const uint32_t idx = ePropertyErrorPath;
2566 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
2567}
2568
Greg Claytonc6e82e42012-08-22 18:39:03 +00002569const char *
2570TargetProperties::GetExpressionPrefixContentsAsCString ()
2571{
2572 const uint32_t idx = ePropertyExprPrefix;
2573 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
2574 if (file)
Jim Ingham7021cda2012-08-22 21:21:16 +00002575 {
Greg Claytonfc04d242012-08-30 18:15:10 +00002576 const bool null_terminate = true;
2577 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham7021cda2012-08-22 21:21:16 +00002578 if (data_sp)
2579 return (const char *) data_sp->GetBytes();
2580 }
Greg Claytonc6e82e42012-08-22 18:39:03 +00002581 return NULL;
2582}
2583
Greg Clayton73844aa2012-08-22 17:17:09 +00002584void
2585TargetProperties::SetStandardErrorPath (const char *p)
2586{
2587 const uint32_t idx = ePropertyErrorPath;
2588 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2589}
2590
2591bool
2592TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
2593{
2594 const uint32_t idx = ePropertyBreakpointUseAvoidList;
2595 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2596}
2597
2598const TargetPropertiesSP &
2599Target::GetGlobalProperties()
2600{
2601 static TargetPropertiesSP g_settings_sp;
2602 if (!g_settings_sp)
2603 {
2604 g_settings_sp.reset (new TargetProperties (NULL));
2605 }
2606 return g_settings_sp;
2607}
2608
Jim Ingham5a15e692012-02-16 06:50:00 +00002609const ConstString &
2610Target::TargetEventData::GetFlavorString ()
2611{
2612 static ConstString g_flavor ("Target::TargetEventData");
2613 return g_flavor;
2614}
2615
2616const ConstString &
2617Target::TargetEventData::GetFlavor () const
2618{
2619 return TargetEventData::GetFlavorString ();
2620}
2621
2622Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2623 EventData(),
2624 m_target_sp (new_target_sp)
2625{
2626}
2627
2628Target::TargetEventData::~TargetEventData()
2629{
2630
2631}
2632
2633void
2634Target::TargetEventData::Dump (Stream *s) const
2635{
2636
2637}
2638
2639const TargetSP
2640Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2641{
2642 TargetSP target_sp;
2643
2644 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2645 if (data)
2646 target_sp = data->m_target_sp;
2647
2648 return target_sp;
2649}
2650
2651const Target::TargetEventData *
2652Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2653{
2654 if (event_ptr)
2655 {
2656 const EventData *event_data = event_ptr->GetData();
2657 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2658 return static_cast <const TargetEventData *> (event_ptr->GetData());
2659 }
2660 return NULL;
2661}
2662