blob: ba61678375be9b4ce32aecf62217731cceea4047 [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"
Greg Clayton535f53c2013-03-19 00:20:55 +000030#include "lldb/Core/SourceManager.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000032#include "lldb/Core/Timer.h"
33#include "lldb/Core/ValueObject.h"
Sean Callanandcf03f82011-11-15 22:27:19 +000034#include "lldb/Expression/ClangASTSource.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000035#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036#include "lldb/Host/Host.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000037#include "lldb/Interpreter/CommandInterpreter.h"
38#include "lldb/Interpreter/CommandReturnObject.h"
Johnny Chen3f883492012-06-04 23:19:54 +000039#include "lldb/Interpreter/OptionGroupWatchpoint.h"
Greg Clayton73844aa2012-08-22 17:17:09 +000040#include "lldb/Interpreter/OptionValues.h"
41#include "lldb/Interpreter/Property.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042#include "lldb/lldb-private-log.h"
43#include "lldb/Symbol/ObjectFile.h"
44#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000045#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000046#include "lldb/Target/Thread.h"
47#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000048
49using namespace lldb;
50using namespace lldb_private;
51
Jim Ingham5a15e692012-02-16 06:50:00 +000052ConstString &
53Target::GetStaticBroadcasterClass ()
54{
55 static ConstString class_name ("lldb.target");
56 return class_name;
57}
58
Chris Lattner24943d22010-06-08 16:52:24 +000059//----------------------------------------------------------------------
60// Target constructor
61//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000062Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
Greg Clayton73844aa2012-08-22 17:17:09 +000063 TargetProperties (this),
Jim Ingham94a5d0d2012-10-10 18:32:14 +000064 Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()),
Greg Clayton24bc5d92011-03-30 18:16:51 +000065 ExecutionContextScope (),
Greg Clayton63094e02010-06-23 01:19:29 +000066 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000067 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000068 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000069 m_arch (target_arch),
Enrico Granata146d9522012-11-08 02:22:02 +000070 m_images (this),
Greg Claytoneea26402010-09-14 23:36:40 +000071 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000072 m_breakpoint_list (false),
73 m_internal_breakpoint_list (true),
Johnny Chenecd4feb2011-10-14 00:42:25 +000074 m_watchpoint_list (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000075 m_process_sp (),
Filipe Cabecinhasf7d782b2012-05-19 09:59:08 +000076 m_valid (true),
Greg Clayton24bc5d92011-03-30 18:16:51 +000077 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000078 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000079 m_scratch_ast_context_ap (NULL),
Sean Callanan4938bd62011-11-16 18:20:47 +000080 m_scratch_ast_source_ap (NULL),
81 m_ast_importer_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000082 m_persistent_variables (),
Greg Clayton535f53c2013-03-19 00:20:55 +000083 m_source_manager_ap(),
Greg Clayton24bc5d92011-03-30 18:16:51 +000084 m_stop_hooks (),
Jim Ingham3613ae12011-05-12 02:06:14 +000085 m_stop_hook_next_id (0),
Enrico Granatadba1de82012-03-27 02:35:13 +000086 m_suppress_stop_hooks (false),
87 m_suppress_synthetic_value(false)
Chris Lattner24943d22010-06-08 16:52:24 +000088{
Greg Clayton49ce6822010-10-31 03:01:06 +000089 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
90 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
91 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
Jim Ingham9c970a32012-12-18 02:03:49 +000092 SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed");
Jim Ingham5a15e692012-02-16 06:50:00 +000093
94 CheckInWithManager();
Greg Clayton49ce6822010-10-31 03:01:06 +000095
Greg Clayton952e9dc2013-03-27 23:08:40 +000096 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000097 if (log)
98 log->Printf ("%p Target::Target()", this);
Jason Molenda8c6cf432012-12-05 00:25:49 +000099 if (m_arch.IsValid())
100 {
Jason Molenda332dc002012-12-12 02:23:56 +0000101 LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "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 Clayton952e9dc2013-03-27 23:08:40 +0000110 Log *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 Clayton952e9dc2013-03-27 23:08:40 +0000498 Log *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{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000543 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen5b2fc572011-09-14 20:23:45 +0000544 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.
Jim Ingham9c970a32012-12-18 02:03:49 +0000567 const bool notify = false; // Don't notify about all the state changes we do on creating the watchpoint.
Johnny Chenbbf6aa52012-05-31 22:56:36 +0000568 Mutex::Locker locker;
569 this->GetWatchpointList().GetListMutex(locker);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000570 WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
Johnny Chen69b6ec82011-09-13 23:29:31 +0000571 if (matched_sp)
572 {
Johnny Chen5b2fc572011-09-14 20:23:45 +0000573 size_t old_size = matched_sp->GetByteSize();
Johnny Chen69b6ec82011-09-13 23:29:31 +0000574 uint32_t old_type =
Johnny Chen5b2fc572011-09-14 20:23:45 +0000575 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
576 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chenecd4feb2011-10-14 00:42:25 +0000577 // Return the existing watchpoint if both size and type match.
Jim Ingham9e376622012-10-23 07:20:06 +0000578 if (size == old_size && kind == old_type) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000579 wp_sp = matched_sp;
Jim Ingham9c970a32012-12-18 02:03:49 +0000580 wp_sp->SetEnabled(false, notify);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000581 } else {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000582 // Nil the matched watchpoint; we will be creating a new one.
Jim Ingham9c970a32012-12-18 02:03:49 +0000583 m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
584 m_watchpoint_list.Remove(matched_sp->GetID(), true);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000585 }
Johnny Chen69b6ec82011-09-13 23:29:31 +0000586 }
587
Jason Molendac4d49fd2012-12-05 23:07:34 +0000588 if (!wp_sp)
589 {
Jim Ingham9c970a32012-12-18 02:03:49 +0000590 wp_sp.reset(new Watchpoint(*this, addr, size, type));
591 wp_sp->SetWatchpointType(kind, notify);
592 m_watchpoint_list.Add (wp_sp, true);
Johnny Chen22a56cc2011-09-14 22:20:15 +0000593 }
Johnny Chen5b2fc572011-09-14 20:23:45 +0000594
Jim Ingham9c970a32012-12-18 02:03:49 +0000595 error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
Johnny Chen5b2fc572011-09-14 20:23:45 +0000596 if (log)
Jason Molendac4d49fd2012-12-05 23:07:34 +0000597 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
598 __FUNCTION__,
599 error.Success() ? "succeeded" : "failed",
600 wp_sp->GetID());
Johnny Chen5b2fc572011-09-14 20:23:45 +0000601
Jason Molendac4d49fd2012-12-05 23:07:34 +0000602 if (error.Fail())
603 {
Johnny Chen155599b2012-03-26 22:00:10 +0000604 // Enabling the watchpoint on the device side failed.
605 // Remove the said watchpoint from the list maintained by the target instance.
Jim Ingham9c970a32012-12-18 02:03:49 +0000606 m_watchpoint_list.Remove (wp_sp->GetID(), true);
Johnny Chen3f883492012-06-04 23:19:54 +0000607 // See if we could provide more helpful error message.
608 if (!CheckIfWatchpointsExhausted(this, error))
609 {
610 if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
611 error.SetErrorStringWithFormat("watch size of %lu is not supported", size);
612 }
Johnny Chenecd4feb2011-10-14 00:42:25 +0000613 wp_sp.reset();
Johnny Chen155599b2012-03-26 22:00:10 +0000614 }
Johnny Chen5eb54bb2011-09-27 20:29:45 +0000615 else
Johnny Chenecd4feb2011-10-14 00:42:25 +0000616 m_last_created_watchpoint = wp_sp;
617 return wp_sp;
Johnny Chen34bbf852011-09-12 23:38:44 +0000618}
619
Chris Lattner24943d22010-06-08 16:52:24 +0000620void
621Target::RemoveAllBreakpoints (bool internal_also)
622{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000623 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000624 if (log)
625 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
626
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000627 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000628 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000629 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000630
631 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000632}
633
634void
635Target::DisableAllBreakpoints (bool internal_also)
636{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000637 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000638 if (log)
639 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
640
641 m_breakpoint_list.SetEnabledAll (false);
642 if (internal_also)
643 m_internal_breakpoint_list.SetEnabledAll (false);
644}
645
646void
647Target::EnableAllBreakpoints (bool internal_also)
648{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000650 if (log)
651 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
652
653 m_breakpoint_list.SetEnabledAll (true);
654 if (internal_also)
655 m_internal_breakpoint_list.SetEnabledAll (true);
656}
657
658bool
659Target::RemoveBreakpointByID (break_id_t break_id)
660{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000661 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000662 if (log)
663 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
664
665 if (DisableBreakpointByID (break_id))
666 {
667 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000668 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000669 else
Jim Inghamd1686902010-10-14 23:45:03 +0000670 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000671 if (m_last_created_breakpoint)
672 {
673 if (m_last_created_breakpoint->GetID() == break_id)
674 m_last_created_breakpoint.reset();
675 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000676 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000677 }
Chris Lattner24943d22010-06-08 16:52:24 +0000678 return true;
679 }
680 return false;
681}
682
683bool
684Target::DisableBreakpointByID (break_id_t break_id)
685{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000686 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000687 if (log)
688 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
689
690 BreakpointSP bp_sp;
691
692 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
693 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
694 else
695 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
696 if (bp_sp)
697 {
698 bp_sp->SetEnabled (false);
699 return true;
700 }
701 return false;
702}
703
704bool
705Target::EnableBreakpointByID (break_id_t break_id)
706{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000707 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000708 if (log)
709 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
710 __FUNCTION__,
711 break_id,
712 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
713
714 BreakpointSP bp_sp;
715
716 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
717 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
718 else
719 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
720
721 if (bp_sp)
722 {
723 bp_sp->SetEnabled (true);
724 return true;
725 }
726 return false;
727}
728
Johnny Chenc86582f2011-09-23 21:21:43 +0000729// The flag 'end_to_end', default to true, signifies that the operation is
730// performed end to end, for both the debugger and the debuggee.
731
Johnny Chenecd4feb2011-10-14 00:42:25 +0000732// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
733// to end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000734bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000735Target::RemoveAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000736{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000737 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chenda5a8022011-09-20 23:28:55 +0000738 if (log)
739 log->Printf ("Target::%s\n", __FUNCTION__);
740
Johnny Chenc86582f2011-09-23 21:21:43 +0000741 if (!end_to_end) {
Jim Ingham9c970a32012-12-18 02:03:49 +0000742 m_watchpoint_list.RemoveAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000743 return true;
744 }
745
746 // Otherwise, it's an end to end operation.
747
Johnny Chenda5a8022011-09-20 23:28:55 +0000748 if (!ProcessIsValid())
749 return false;
750
Johnny Chenecd4feb2011-10-14 00:42:25 +0000751 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000752 for (size_t i = 0; i < num_watchpoints; ++i)
753 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000754 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
755 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000756 return false;
757
Johnny Chenecd4feb2011-10-14 00:42:25 +0000758 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000759 if (rc.Fail())
760 return false;
761 }
Jim Ingham9c970a32012-12-18 02:03:49 +0000762 m_watchpoint_list.RemoveAll (true);
Johnny Chenda5a8022011-09-20 23:28:55 +0000763 return true; // Success!
764}
765
Johnny Chenecd4feb2011-10-14 00:42:25 +0000766// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
767// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000768bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000769Target::DisableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000770{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000771 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chenda5a8022011-09-20 23:28:55 +0000772 if (log)
773 log->Printf ("Target::%s\n", __FUNCTION__);
774
Johnny Chenc86582f2011-09-23 21:21:43 +0000775 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000776 m_watchpoint_list.SetEnabledAll(false);
Johnny Chenc86582f2011-09-23 21:21:43 +0000777 return true;
778 }
779
780 // Otherwise, it's an end to end operation.
781
Johnny Chenda5a8022011-09-20 23:28:55 +0000782 if (!ProcessIsValid())
783 return false;
784
Johnny Chenecd4feb2011-10-14 00:42:25 +0000785 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000786 for (size_t i = 0; i < num_watchpoints; ++i)
787 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000788 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
789 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000790 return false;
791
Johnny Chenecd4feb2011-10-14 00:42:25 +0000792 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000793 if (rc.Fail())
794 return false;
795 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000796 return true; // Success!
797}
798
Johnny Chenecd4feb2011-10-14 00:42:25 +0000799// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to
800// end operations.
Johnny Chenda5a8022011-09-20 23:28:55 +0000801bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000802Target::EnableAllWatchpoints (bool end_to_end)
Johnny Chenda5a8022011-09-20 23:28:55 +0000803{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000804 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chenda5a8022011-09-20 23:28:55 +0000805 if (log)
806 log->Printf ("Target::%s\n", __FUNCTION__);
807
Johnny Chenc86582f2011-09-23 21:21:43 +0000808 if (!end_to_end) {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000809 m_watchpoint_list.SetEnabledAll(true);
Johnny Chenc86582f2011-09-23 21:21:43 +0000810 return true;
811 }
812
813 // Otherwise, it's an end to end operation.
814
Johnny Chenda5a8022011-09-20 23:28:55 +0000815 if (!ProcessIsValid())
816 return false;
817
Johnny Chenecd4feb2011-10-14 00:42:25 +0000818 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chenda5a8022011-09-20 23:28:55 +0000819 for (size_t i = 0; i < num_watchpoints; ++i)
820 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000821 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
822 if (!wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000823 return false;
824
Johnny Chenecd4feb2011-10-14 00:42:25 +0000825 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chenda5a8022011-09-20 23:28:55 +0000826 if (rc.Fail())
827 return false;
828 }
Johnny Chenda5a8022011-09-20 23:28:55 +0000829 return true; // Success!
830}
831
Johnny Chen116a5cd2012-02-25 06:44:30 +0000832// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
833bool
834Target::ClearAllWatchpointHitCounts ()
835{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000836 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chen116a5cd2012-02-25 06:44:30 +0000837 if (log)
838 log->Printf ("Target::%s\n", __FUNCTION__);
839
840 size_t num_watchpoints = m_watchpoint_list.GetSize();
841 for (size_t i = 0; i < num_watchpoints; ++i)
842 {
843 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
844 if (!wp_sp)
845 return false;
846
847 wp_sp->ResetHitCount();
848 }
849 return true; // Success!
850}
851
Johnny Chenecd4feb2011-10-14 00:42:25 +0000852// Assumption: Caller holds the list mutex lock for m_watchpoint_list
Johnny Chene14cf4e2011-10-05 21:35:46 +0000853// during these operations.
854bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000855Target::IgnoreAllWatchpoints (uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000856{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000857 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chene14cf4e2011-10-05 21:35:46 +0000858 if (log)
859 log->Printf ("Target::%s\n", __FUNCTION__);
860
861 if (!ProcessIsValid())
862 return false;
863
Johnny Chenecd4feb2011-10-14 00:42:25 +0000864 size_t num_watchpoints = m_watchpoint_list.GetSize();
Johnny Chene14cf4e2011-10-05 21:35:46 +0000865 for (size_t i = 0; i < num_watchpoints; ++i)
866 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000867 WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i);
868 if (!wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000869 return false;
870
Johnny Chenecd4feb2011-10-14 00:42:25 +0000871 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000872 }
873 return true; // Success!
874}
875
Johnny Chenecd4feb2011-10-14 00:42:25 +0000876// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000877bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000878Target::DisableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000879{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000880 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chenda5a8022011-09-20 23:28:55 +0000881 if (log)
882 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
883
884 if (!ProcessIsValid())
885 return false;
886
Johnny Chenecd4feb2011-10-14 00:42:25 +0000887 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
888 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000889 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000890 Error rc = m_process_sp->DisableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000891 if (rc.Success())
892 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000893
Johnny Chen01acfa72011-09-22 18:04:58 +0000894 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000895 }
896 return false;
897}
898
Johnny Chenecd4feb2011-10-14 00:42:25 +0000899// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000900bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000901Target::EnableWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000902{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000903 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chenda5a8022011-09-20 23:28:55 +0000904 if (log)
905 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
906
907 if (!ProcessIsValid())
908 return false;
909
Johnny Chenecd4feb2011-10-14 00:42:25 +0000910 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
911 if (wp_sp)
Johnny Chenda5a8022011-09-20 23:28:55 +0000912 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000913 Error rc = m_process_sp->EnableWatchpoint(wp_sp.get());
Johnny Chen01acfa72011-09-22 18:04:58 +0000914 if (rc.Success())
915 return true;
Johnny Chenda5a8022011-09-20 23:28:55 +0000916
Johnny Chen01acfa72011-09-22 18:04:58 +0000917 // Else, fallthrough.
Johnny Chenda5a8022011-09-20 23:28:55 +0000918 }
919 return false;
920}
921
Johnny Chenecd4feb2011-10-14 00:42:25 +0000922// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chenda5a8022011-09-20 23:28:55 +0000923bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000924Target::RemoveWatchpointByID (lldb::watch_id_t watch_id)
Johnny Chenda5a8022011-09-20 23:28:55 +0000925{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000926 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chenda5a8022011-09-20 23:28:55 +0000927 if (log)
928 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
929
Johnny Chenecd4feb2011-10-14 00:42:25 +0000930 if (DisableWatchpointByID (watch_id))
Johnny Chenda5a8022011-09-20 23:28:55 +0000931 {
Jim Ingham9c970a32012-12-18 02:03:49 +0000932 m_watchpoint_list.Remove(watch_id, true);
Johnny Chenda5a8022011-09-20 23:28:55 +0000933 return true;
934 }
935 return false;
936}
937
Johnny Chenecd4feb2011-10-14 00:42:25 +0000938// Assumption: Caller holds the list mutex lock for m_watchpoint_list.
Johnny Chene14cf4e2011-10-05 21:35:46 +0000939bool
Johnny Chenecd4feb2011-10-14 00:42:25 +0000940Target::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000941{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000942 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
Johnny Chene14cf4e2011-10-05 21:35:46 +0000943 if (log)
944 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
945
946 if (!ProcessIsValid())
947 return false;
948
Johnny Chenecd4feb2011-10-14 00:42:25 +0000949 WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id);
950 if (wp_sp)
Johnny Chene14cf4e2011-10-05 21:35:46 +0000951 {
Johnny Chenecd4feb2011-10-14 00:42:25 +0000952 wp_sp->SetIgnoreCount(ignore_count);
Johnny Chene14cf4e2011-10-05 21:35:46 +0000953 return true;
954 }
955 return false;
956}
957
Chris Lattner24943d22010-06-08 16:52:24 +0000958ModuleSP
959Target::GetExecutableModule ()
960{
Greg Clayton5beb99d2011-08-11 02:48:45 +0000961 return m_images.GetModuleAtIndex(0);
962}
963
964Module*
965Target::GetExecutableModulePointer ()
966{
967 return m_images.GetModulePointerAtIndex(0);
Chris Lattner24943d22010-06-08 16:52:24 +0000968}
969
Enrico Granata146d9522012-11-08 02:22:02 +0000970static void
971LoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target)
972{
973 Error error;
974 if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error))
975 {
976 target->GetDebugger().GetOutputStream().Printf("unable to load scripting data for module %s - error reported was %s\n",
977 module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
978 error.AsCString());
979 }
980}
981
Chris Lattner24943d22010-06-08 16:52:24 +0000982void
983Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
984{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000985 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Chris Lattner24943d22010-06-08 16:52:24 +0000986 m_images.Clear();
987 m_scratch_ast_context_ap.reset();
Sean Callanandcf03f82011-11-15 22:27:19 +0000988 m_scratch_ast_source_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +0000989 m_ast_importer_ap.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000990
991 if (executable_sp.get())
992 {
993 Timer scoped_timer (__PRETTY_FUNCTION__,
994 "Target::SetExecutableModule (executable = '%s/%s')",
995 executable_sp->GetFileSpec().GetDirectory().AsCString(),
996 executable_sp->GetFileSpec().GetFilename().AsCString());
997
998 m_images.Append(executable_sp); // The first image is our exectuable file
999
Jim Ingham7508e732010-08-09 23:31:02 +00001000 // 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 +00001001 if (!m_arch.IsValid())
Jason Molenda8c6cf432012-12-05 00:25:49 +00001002 {
Greg Clayton24bc5d92011-03-30 18:16:51 +00001003 m_arch = executable_sp->GetArchitecture();
Jason Molenda8c6cf432012-12-05 00:25:49 +00001004 if (log)
1005 log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str());
1006 }
1007
Chris Lattner24943d22010-06-08 16:52:24 +00001008 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001009 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +00001010
Greg Clayton3e8c25f2011-09-24 00:52:29 +00001011 if (executable_objfile && get_dependent_files)
Chris Lattner24943d22010-06-08 16:52:24 +00001012 {
1013 executable_objfile->GetDependentModules(dependent_files);
1014 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
1015 {
Greg Claytonb1888f22011-03-19 01:12:21 +00001016 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
1017 FileSpec platform_dependent_file_spec;
1018 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +00001019 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +00001020 else
1021 platform_dependent_file_spec = dependent_file_spec;
1022
Greg Clayton444fe992012-02-26 05:51:37 +00001023 ModuleSpec module_spec (platform_dependent_file_spec, m_arch);
1024 ModuleSP image_module_sp(GetSharedModule (module_spec));
Chris Lattner24943d22010-06-08 16:52:24 +00001025 if (image_module_sp.get())
1026 {
Chris Lattner24943d22010-06-08 16:52:24 +00001027 ObjectFile *objfile = image_module_sp->GetObjectFile();
1028 if (objfile)
1029 objfile->GetDependentModules(dependent_files);
1030 }
1031 }
1032 }
Chris Lattner24943d22010-06-08 16:52:24 +00001033 }
1034}
1035
1036
Jim Ingham7508e732010-08-09 23:31:02 +00001037bool
1038Target::SetArchitecture (const ArchSpec &arch_spec)
1039{
Greg Clayton952e9dc2013-03-27 23:08:40 +00001040 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET));
Sean Callanan40e278c2012-12-13 22:07:14 +00001041 if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +00001042 {
Greg Claytonb170aee2012-05-08 01:45:38 +00001043 // If we haven't got a valid arch spec, or the architectures are
1044 // compatible, so just update the architecture. Architectures can be
1045 // equal, yet the triple OS and vendor might change, so we need to do
1046 // the assignment here just in case.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001047 m_arch = arch_spec;
Jason Molenda8c6cf432012-12-05 00:25:49 +00001048 if (log)
1049 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 +00001050 return true;
1051 }
1052 else
1053 {
1054 // If we have an executable file, try to reset the executable to the desired architecture
Jason Molenda8c6cf432012-12-05 00:25:49 +00001055 if (log)
Jason Molendac4d49fd2012-12-05 23:07:34 +00001056 log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str());
Greg Clayton24bc5d92011-03-30 18:16:51 +00001057 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +00001058 ModuleSP executable_sp = GetExecutableModule ();
1059 m_images.Clear();
1060 m_scratch_ast_context_ap.reset();
Sean Callanan4938bd62011-11-16 18:20:47 +00001061 m_scratch_ast_source_ap.reset();
1062 m_ast_importer_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +00001063 // Need to do something about unsetting breakpoints.
1064
1065 if (executable_sp)
1066 {
Jason Molenda8c6cf432012-12-05 00:25:49 +00001067 if (log)
1068 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 +00001069 ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec);
1070 Error error = ModuleList::GetSharedModule (module_spec,
1071 executable_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001072 &GetExecutableSearchPaths(),
Greg Clayton444fe992012-02-26 05:51:37 +00001073 NULL,
1074 NULL);
Jim Ingham7508e732010-08-09 23:31:02 +00001075
1076 if (!error.Fail() && executable_sp)
1077 {
1078 SetExecutableModule (executable_sp, true);
1079 return true;
1080 }
Jim Ingham7508e732010-08-09 23:31:02 +00001081 }
1082 }
Greg Claytonb170aee2012-05-08 01:45:38 +00001083 return false;
Jim Ingham7508e732010-08-09 23:31:02 +00001084}
Chris Lattner24943d22010-06-08 16:52:24 +00001085
Chris Lattner24943d22010-06-08 16:52:24 +00001086void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001087Target::WillClearList (const ModuleList& module_list)
Enrico Granata146d9522012-11-08 02:22:02 +00001088{
1089}
1090
1091void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001092Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001093{
1094 // A module is being added to this target for the first time
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001095 ModuleList my_module_list;
1096 my_module_list.Append(module_sp);
Enrico Granata146d9522012-11-08 02:22:02 +00001097 LoadScriptingResourceForModule(module_sp, this);
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001098 ModulesDidLoad (my_module_list);
Chris Lattner24943d22010-06-08 16:52:24 +00001099}
1100
1101void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001102Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
Enrico Granata146d9522012-11-08 02:22:02 +00001103{
1104 // A module is being added to this target for the first time
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001105 ModuleList my_module_list;
1106 my_module_list.Append(module_sp);
1107 ModulesDidUnload (my_module_list);
Enrico Granata146d9522012-11-08 02:22:02 +00001108}
1109
1110void
Enrico Granata0b2f5cc2012-11-08 19:16:03 +00001111Target::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001112{
Jim Ingham3b8a6052011-08-03 01:00:06 +00001113 // A module is replacing an already added module
Jim Ingham03e5e512012-05-17 18:38:42 +00001114 m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp);
Chris Lattner24943d22010-06-08 16:52:24 +00001115}
1116
1117void
1118Target::ModulesDidLoad (ModuleList &module_list)
1119{
Enrico Granata146d9522012-11-08 02:22:02 +00001120 if (module_list.GetSize())
1121 {
1122 m_breakpoint_list.UpdateBreakpoints (module_list, true);
1123 // TODO: make event data that packages up the module_list
1124 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
1125 }
Chris Lattner24943d22010-06-08 16:52:24 +00001126}
1127
1128void
1129Target::ModulesDidUnload (ModuleList &module_list)
1130{
Enrico Granata146d9522012-11-08 02:22:02 +00001131 if (module_list.GetSize())
1132 {
1133 m_breakpoint_list.UpdateBreakpoints (module_list, false);
1134 // TODO: make event data that packages up the module_list
1135 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
1136 }
Chris Lattner24943d22010-06-08 16:52:24 +00001137}
1138
Daniel Dunbar705a0982011-10-31 22:50:37 +00001139bool
Greg Clayton444fe992012-02-26 05:51:37 +00001140Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec)
Jim Ingham7089d8a2011-10-28 23:14:11 +00001141{
Greg Clayton73844aa2012-08-22 17:17:09 +00001142 if (GetBreakpointsConsultPlatformAvoidList())
Jim Ingham7089d8a2011-10-28 23:14:11 +00001143 {
1144 ModuleList matchingModules;
Greg Clayton444fe992012-02-26 05:51:37 +00001145 ModuleSpec module_spec (module_file_spec);
1146 size_t num_modules = GetImages().FindModules(module_spec, matchingModules);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001147
1148 // If there is more than one module for this file spec, only return true if ALL the modules are on the
1149 // black list.
1150 if (num_modules > 0)
1151 {
1152 for (int i = 0; i < num_modules; i++)
1153 {
1154 if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
1155 return false;
1156 }
1157 return true;
1158 }
Jim Ingham7089d8a2011-10-28 23:14:11 +00001159 }
Greg Clayton73844aa2012-08-22 17:17:09 +00001160 return false;
Jim Ingham7089d8a2011-10-28 23:14:11 +00001161}
1162
Daniel Dunbar705a0982011-10-31 22:50:37 +00001163bool
Jim Ingham7089d8a2011-10-28 23:14:11 +00001164Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
1165{
Greg Clayton73844aa2012-08-22 17:17:09 +00001166 if (GetBreakpointsConsultPlatformAvoidList())
Jim Ingham7089d8a2011-10-28 23:14:11 +00001167 {
Greg Clayton73844aa2012-08-22 17:17:09 +00001168 if (m_platform_sp)
1169 return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
Jim Ingham7089d8a2011-10-28 23:14:11 +00001170 }
Greg Clayton73844aa2012-08-22 17:17:09 +00001171 return false;
Jim Ingham7089d8a2011-10-28 23:14:11 +00001172}
1173
Chris Lattner24943d22010-06-08 16:52:24 +00001174size_t
Greg Clayton26100dc2011-01-07 01:57:07 +00001175Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
1176{
Greg Clayton3508c382012-02-24 01:59:29 +00001177 SectionSP section_sp (addr.GetSection());
1178 if (section_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001179 {
Jason Molenda6b028d62012-04-25 00:06:56 +00001180 // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory.
1181 if (section_sp->IsEncrypted())
1182 {
Greg Clayton04e6ada2012-05-25 17:05:55 +00001183 error.SetErrorString("section is encrypted");
Jason Molenda6b028d62012-04-25 00:06:56 +00001184 return 0;
1185 }
Greg Clayton3508c382012-02-24 01:59:29 +00001186 ModuleSP module_sp (section_sp->GetModule());
1187 if (module_sp)
Greg Clayton26100dc2011-01-07 01:57:07 +00001188 {
Greg Clayton3508c382012-02-24 01:59:29 +00001189 ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
1190 if (objfile)
1191 {
1192 size_t bytes_read = objfile->ReadSectionData (section_sp.get(),
1193 addr.GetOffset(),
1194 dst,
1195 dst_len);
1196 if (bytes_read > 0)
1197 return bytes_read;
1198 else
1199 error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString());
1200 }
Greg Clayton26100dc2011-01-07 01:57:07 +00001201 else
Greg Clayton3508c382012-02-24 01:59:29 +00001202 error.SetErrorString("address isn't from a object file");
Greg Clayton26100dc2011-01-07 01:57:07 +00001203 }
1204 else
Greg Clayton3508c382012-02-24 01:59:29 +00001205 error.SetErrorString("address isn't in a module");
Greg Clayton26100dc2011-01-07 01:57:07 +00001206 }
1207 else
Greg Clayton26100dc2011-01-07 01:57:07 +00001208 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
Greg Clayton3508c382012-02-24 01:59:29 +00001209
Greg Clayton26100dc2011-01-07 01:57:07 +00001210 return 0;
1211}
1212
1213size_t
Enrico Granata91544802011-09-06 19:20:51 +00001214Target::ReadMemory (const Address& addr,
1215 bool prefer_file_cache,
1216 void *dst,
1217 size_t dst_len,
1218 Error &error,
1219 lldb::addr_t *load_addr_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001220{
Chris Lattner24943d22010-06-08 16:52:24 +00001221 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +00001222
Enrico Granata91544802011-09-06 19:20:51 +00001223 // if we end up reading this from process memory, we will fill this
1224 // with the actual load address
1225 if (load_addr_ptr)
1226 *load_addr_ptr = LLDB_INVALID_ADDRESS;
1227
Greg Clayton26100dc2011-01-07 01:57:07 +00001228 size_t bytes_read = 0;
Greg Clayton9b82f862011-07-11 05:12:02 +00001229
1230 addr_t load_addr = LLDB_INVALID_ADDRESS;
1231 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton889fbd02011-03-26 19:14:58 +00001232 Address resolved_addr;
1233 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001234 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001235 if (m_section_load_list.IsEmpty())
Greg Clayton9b82f862011-07-11 05:12:02 +00001236 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001237 // No sections are loaded, so we must assume we are not running
1238 // yet and anything we are given is a file address.
1239 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
1240 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001241 }
Greg Clayton70436352010-06-30 23:03:03 +00001242 else
Greg Clayton9b82f862011-07-11 05:12:02 +00001243 {
Greg Clayton7dd98df2011-07-12 17:06:17 +00001244 // We have at least one section loaded. This can be becuase
1245 // we have manually loaded some sections with "target modules load ..."
1246 // or because we have have a live process that has sections loaded
1247 // through the dynamic loader
1248 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
1249 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Clayton9b82f862011-07-11 05:12:02 +00001250 }
Greg Clayton70436352010-06-30 23:03:03 +00001251 }
Greg Clayton889fbd02011-03-26 19:14:58 +00001252 if (!resolved_addr.IsValid())
1253 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +00001254
Greg Clayton9b82f862011-07-11 05:12:02 +00001255
Greg Clayton26100dc2011-01-07 01:57:07 +00001256 if (prefer_file_cache)
1257 {
1258 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
1259 if (bytes_read > 0)
1260 return bytes_read;
1261 }
Greg Clayton70436352010-06-30 23:03:03 +00001262
Johnny Chenda5a8022011-09-20 23:28:55 +00001263 if (ProcessIsValid())
Greg Clayton70436352010-06-30 23:03:03 +00001264 {
Greg Clayton9b82f862011-07-11 05:12:02 +00001265 if (load_addr == LLDB_INVALID_ADDRESS)
1266 load_addr = resolved_addr.GetLoadAddress (this);
1267
Greg Clayton70436352010-06-30 23:03:03 +00001268 if (load_addr == LLDB_INVALID_ADDRESS)
1269 {
Greg Clayton3508c382012-02-24 01:59:29 +00001270 ModuleSP addr_module_sp (resolved_addr.GetModule());
1271 if (addr_module_sp && addr_module_sp->GetFileSpec())
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001272 error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded",
Greg Clayton3508c382012-02-24 01:59:29 +00001273 addr_module_sp->GetFileSpec().GetFilename().AsCString(),
Jason Molenda95b7b432011-09-20 00:26:08 +00001274 resolved_addr.GetFileAddress(),
Greg Clayton3508c382012-02-24 01:59:29 +00001275 addr_module_sp->GetFileSpec().GetFilename().AsCString());
Greg Clayton70436352010-06-30 23:03:03 +00001276 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001277 error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress());
Greg Clayton70436352010-06-30 23:03:03 +00001278 }
1279 else
1280 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001281 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +00001282 if (bytes_read != dst_len)
1283 {
1284 if (error.Success())
1285 {
1286 if (bytes_read == 0)
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001287 error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +00001288 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001289 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 +00001290 }
1291 }
Greg Clayton70436352010-06-30 23:03:03 +00001292 if (bytes_read)
Enrico Granata91544802011-09-06 19:20:51 +00001293 {
1294 if (load_addr_ptr)
1295 *load_addr_ptr = load_addr;
Greg Clayton70436352010-06-30 23:03:03 +00001296 return bytes_read;
Enrico Granata91544802011-09-06 19:20:51 +00001297 }
Greg Clayton70436352010-06-30 23:03:03 +00001298 // If the address is not section offset we have an address that
1299 // doesn't resolve to any address in any currently loaded shared
1300 // libaries and we failed to read memory so there isn't anything
1301 // more we can do. If it is section offset, we might be able to
1302 // read cached memory from the object file.
1303 if (!resolved_addr.IsSectionOffset())
1304 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001305 }
Chris Lattner24943d22010-06-08 16:52:24 +00001306 }
Greg Clayton70436352010-06-30 23:03:03 +00001307
Greg Clayton9b82f862011-07-11 05:12:02 +00001308 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +00001309 {
Greg Clayton26100dc2011-01-07 01:57:07 +00001310 // If we didn't already try and read from the object file cache, then
1311 // try it after failing to read from the process.
1312 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +00001313 }
1314 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001315}
1316
Greg Clayton7dd98df2011-07-12 17:06:17 +00001317size_t
Enrico Granata45358912013-01-21 19:20:50 +00001318Target::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error)
1319{
1320 char buf[256];
1321 out_str.clear();
1322 addr_t curr_addr = addr.GetLoadAddress(this);
1323 Address address(addr);
1324 while (1)
1325 {
1326 size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error);
1327 if (length == 0)
1328 break;
1329 out_str.append(buf, length);
1330 // If we got "length - 1" bytes, we didn't get the whole C string, we
1331 // need to read some more characters
1332 if (length == sizeof(buf) - 1)
1333 curr_addr += length;
1334 else
1335 break;
1336 address = Address(curr_addr);
1337 }
1338 return out_str.size();
1339}
1340
1341
1342size_t
1343Target::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error)
1344{
1345 size_t total_cstr_len = 0;
1346 if (dst && dst_max_len)
1347 {
1348 result_error.Clear();
1349 // NULL out everything just to be safe
1350 memset (dst, 0, dst_max_len);
1351 Error error;
1352 addr_t curr_addr = addr.GetLoadAddress(this);
1353 Address address(addr);
1354 const size_t cache_line_size = 512;
1355 size_t bytes_left = dst_max_len - 1;
1356 char *curr_dst = dst;
1357
1358 while (bytes_left > 0)
1359 {
1360 addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size);
1361 addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left);
1362 size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error);
1363
1364 if (bytes_read == 0)
1365 {
1366 result_error = error;
1367 dst[total_cstr_len] = '\0';
1368 break;
1369 }
1370 const size_t len = strlen(curr_dst);
1371
1372 total_cstr_len += len;
1373
1374 if (len < bytes_to_read)
1375 break;
1376
1377 curr_dst += bytes_read;
1378 curr_addr += bytes_read;
1379 bytes_left -= bytes_read;
1380 address = Address(curr_addr);
1381 }
1382 }
1383 else
1384 {
1385 if (dst == NULL)
1386 result_error.SetErrorString("invalid arguments");
1387 else
1388 result_error.Clear();
1389 }
1390 return total_cstr_len;
1391}
1392
1393size_t
Greg Clayton7dd98df2011-07-12 17:06:17 +00001394Target::ReadScalarIntegerFromMemory (const Address& addr,
1395 bool prefer_file_cache,
1396 uint32_t byte_size,
1397 bool is_signed,
1398 Scalar &scalar,
1399 Error &error)
1400{
1401 uint64_t uval;
1402
1403 if (byte_size <= sizeof(uval))
1404 {
1405 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1406 if (bytes_read == byte_size)
1407 {
1408 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
Greg Clayton36da2aa2013-01-25 18:06:21 +00001409 lldb::offset_t offset = 0;
Greg Clayton7dd98df2011-07-12 17:06:17 +00001410 if (byte_size <= 4)
1411 scalar = data.GetMaxU32 (&offset, byte_size);
1412 else
1413 scalar = data.GetMaxU64 (&offset, byte_size);
1414
1415 if (is_signed)
1416 scalar.SignExtend(byte_size * 8);
1417 return bytes_read;
1418 }
1419 }
1420 else
1421 {
1422 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1423 }
1424 return 0;
1425}
1426
1427uint64_t
1428Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1429 bool prefer_file_cache,
1430 size_t integer_byte_size,
1431 uint64_t fail_value,
1432 Error &error)
1433{
1434 Scalar scalar;
1435 if (ReadScalarIntegerFromMemory (addr,
1436 prefer_file_cache,
1437 integer_byte_size,
1438 false,
1439 scalar,
1440 error))
1441 return scalar.ULongLong(fail_value);
1442 return fail_value;
1443}
1444
1445bool
1446Target::ReadPointerFromMemory (const Address& addr,
1447 bool prefer_file_cache,
1448 Error &error,
1449 Address &pointer_addr)
1450{
1451 Scalar scalar;
1452 if (ReadScalarIntegerFromMemory (addr,
1453 prefer_file_cache,
1454 m_arch.GetAddressByteSize(),
1455 false,
1456 scalar,
1457 error))
1458 {
1459 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1460 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1461 {
1462 if (m_section_load_list.IsEmpty())
1463 {
1464 // No sections are loaded, so we must assume we are not running
1465 // yet and anything we are given is a file address.
1466 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1467 }
1468 else
1469 {
1470 // We have at least one section loaded. This can be becuase
1471 // we have manually loaded some sections with "target modules load ..."
1472 // or because we have have a live process that has sections loaded
1473 // through the dynamic loader
1474 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1475 }
1476 // We weren't able to resolve the pointer value, so just return
1477 // an address with no section
1478 if (!pointer_addr.IsValid())
1479 pointer_addr.SetOffset (pointer_vm_addr);
1480 return true;
1481
1482 }
1483 }
1484 return false;
1485}
Chris Lattner24943d22010-06-08 16:52:24 +00001486
1487ModuleSP
Greg Clayton444fe992012-02-26 05:51:37 +00001488Target::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +00001489{
Chris Lattner24943d22010-06-08 16:52:24 +00001490 ModuleSP module_sp;
1491
Chris Lattner24943d22010-06-08 16:52:24 +00001492 Error error;
1493
Jim Ingham03e5e512012-05-17 18:38:42 +00001494 // First see if we already have this module in our module list. If we do, then we're done, we don't need
1495 // to consult the shared modules list. But only do this if we are passed a UUID.
Greg Claytone1ef1e32012-04-27 00:58:27 +00001496
Jim Ingham03e5e512012-05-17 18:38:42 +00001497 if (module_spec.GetUUID().IsValid())
1498 module_sp = m_images.FindFirstModule(module_spec);
1499
Greg Claytone1ef1e32012-04-27 00:58:27 +00001500 if (!module_sp)
1501 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001502 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1503 bool did_create_module = false;
1504
1505 // If there are image search path entries, try to use them first to acquire a suitable image.
1506 if (m_image_search_paths.GetSize())
Greg Claytone1ef1e32012-04-27 00:58:27 +00001507 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001508 ModuleSpec transformed_spec (module_spec);
1509 if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory()))
1510 {
1511 transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename();
1512 error = ModuleList::GetSharedModule (transformed_spec,
1513 module_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001514 &GetExecutableSearchPaths(),
Jim Ingham03e5e512012-05-17 18:38:42 +00001515 &old_module_sp,
1516 &did_create_module);
1517 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001518 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001519
Greg Claytone1ef1e32012-04-27 00:58:27 +00001520 if (!module_sp)
1521 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001522 // If we have a UUID, we can check our global shared module list in case
1523 // we already have it. If we don't have a valid UUID, then we can't since
1524 // the path in "module_spec" will be a platform path, and we will need to
1525 // let the platform find that file. For example, we could be asking for
1526 // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
1527 // the local copy of "/usr/lib/dyld" since our platform could be a remote
1528 // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
1529 // cache.
1530 if (module_spec.GetUUID().IsValid())
Greg Claytone1ef1e32012-04-27 00:58:27 +00001531 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001532 // We have a UUID, it is OK to check the global module list...
1533 error = ModuleList::GetSharedModule (module_spec,
1534 module_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001535 &GetExecutableSearchPaths(),
Greg Clayton73844aa2012-08-22 17:17:09 +00001536 &old_module_sp,
Jim Ingham03e5e512012-05-17 18:38:42 +00001537 &did_create_module);
Greg Claytone1ef1e32012-04-27 00:58:27 +00001538 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001539
1540 if (!module_sp)
Greg Claytone1ef1e32012-04-27 00:58:27 +00001541 {
Jim Ingham03e5e512012-05-17 18:38:42 +00001542 // The platform is responsible for finding and caching an appropriate
1543 // module in the shared module cache.
1544 if (m_platform_sp)
1545 {
1546 FileSpec platform_file_spec;
1547 error = m_platform_sp->GetSharedModule (module_spec,
1548 module_sp,
Greg Claytonc6e82e42012-08-22 18:39:03 +00001549 &GetExecutableSearchPaths(),
Greg Clayton73844aa2012-08-22 17:17:09 +00001550 &old_module_sp,
Jim Ingham03e5e512012-05-17 18:38:42 +00001551 &did_create_module);
1552 }
1553 else
1554 {
1555 error.SetErrorString("no platform is currently set");
1556 }
Greg Claytone1ef1e32012-04-27 00:58:27 +00001557 }
1558 }
Chris Lattner24943d22010-06-08 16:52:24 +00001559
Jim Ingham03e5e512012-05-17 18:38:42 +00001560 // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent
1561 // module in the list already, and if there was, let's remove it.
1562 if (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001563 {
Greg Clayton1649a722012-11-29 22:16:27 +00001564 ObjectFile *objfile = module_sp->GetObjectFile();
1565 if (objfile)
Jim Ingham03e5e512012-05-17 18:38:42 +00001566 {
Greg Clayton1649a722012-11-29 22:16:27 +00001567 switch (objfile->GetType())
Jim Ingham03e5e512012-05-17 18:38:42 +00001568 {
Greg Clayton1649a722012-11-29 22:16:27 +00001569 case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state
1570 case ObjectFile::eTypeExecutable: /// A normal executable
1571 case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable
1572 case ObjectFile::eTypeObjectFile: /// An intermediate object file
1573 case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution
1574 break;
1575 case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information
1576 if (error_ptr)
1577 error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable");
1578 return ModuleSP();
1579 case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution
1580 if (error_ptr)
1581 error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable");
1582 return ModuleSP();
1583 default:
1584 if (error_ptr)
1585 error_ptr->SetErrorString("unsupported file type, please specify an executable");
1586 return ModuleSP();
1587 }
1588 // GetSharedModule is not guaranteed to find the old shared module, for instance
1589 // in the common case where you pass in the UUID, it is only going to find the one
1590 // module matching the UUID. In fact, it has no good way to know what the "old module"
1591 // relevant to this target is, since there might be many copies of a module with this file spec
1592 // in various running debug sessions, but only one of them will belong to this target.
1593 // So let's remove the UUID from the module list, and look in the target's module list.
1594 // Only do this if there is SOMETHING else in the module spec...
1595 if (!old_module_sp)
1596 {
1597 if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty())
Jim Ingham03e5e512012-05-17 18:38:42 +00001598 {
Greg Clayton1649a722012-11-29 22:16:27 +00001599 ModuleSpec module_spec_copy(module_spec.GetFileSpec());
1600 module_spec_copy.GetUUID().Clear();
1601
1602 ModuleList found_modules;
1603 size_t num_found = m_images.FindModules (module_spec_copy, found_modules);
1604 if (num_found == 1)
1605 {
1606 old_module_sp = found_modules.GetModuleAtIndex(0);
1607 }
Jim Ingham03e5e512012-05-17 18:38:42 +00001608 }
1609 }
Greg Clayton1649a722012-11-29 22:16:27 +00001610
1611 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1612 {
1613 m_images.ReplaceModule(old_module_sp, module_sp);
1614 Module *old_module_ptr = old_module_sp.get();
1615 old_module_sp.reset();
1616 ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr);
1617 }
1618 else
1619 m_images.Append(module_sp);
Jim Ingham03e5e512012-05-17 18:38:42 +00001620 }
Chris Lattner24943d22010-06-08 16:52:24 +00001621 }
1622 }
1623 if (error_ptr)
1624 *error_ptr = error;
1625 return module_sp;
1626}
1627
1628
Greg Clayton289afcb2012-02-18 05:35:26 +00001629TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001630Target::CalculateTarget ()
1631{
Greg Clayton289afcb2012-02-18 05:35:26 +00001632 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001633}
1634
Greg Clayton289afcb2012-02-18 05:35:26 +00001635ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001636Target::CalculateProcess ()
1637{
Greg Clayton289afcb2012-02-18 05:35:26 +00001638 return ProcessSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001639}
1640
Greg Clayton289afcb2012-02-18 05:35:26 +00001641ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001642Target::CalculateThread ()
1643{
Greg Clayton289afcb2012-02-18 05:35:26 +00001644 return ThreadSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001645}
1646
Greg Clayton289afcb2012-02-18 05:35:26 +00001647StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001648Target::CalculateStackFrame ()
1649{
Greg Clayton289afcb2012-02-18 05:35:26 +00001650 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001651}
1652
1653void
Greg Claytona830adb2010-10-04 01:05:56 +00001654Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001655{
Greg Clayton567e7f32011-09-22 04:58:26 +00001656 exe_ctx.Clear();
1657 exe_ctx.SetTargetPtr(this);
Chris Lattner24943d22010-06-08 16:52:24 +00001658}
1659
1660PathMappingList &
1661Target::GetImageSearchPathList ()
1662{
1663 return m_image_search_paths;
1664}
1665
1666void
1667Target::ImageSearchPathsChanged
1668(
1669 const PathMappingList &path_list,
1670 void *baton
1671)
1672{
1673 Target *target = (Target *)baton;
Greg Clayton5beb99d2011-08-11 02:48:45 +00001674 ModuleSP exe_module_sp (target->GetExecutableModule());
1675 if (exe_module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001676 {
Greg Clayton5beb99d2011-08-11 02:48:45 +00001677 target->m_images.Clear();
1678 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +00001679 }
1680}
1681
1682ClangASTContext *
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001683Target::GetScratchClangASTContext(bool create_on_demand)
Chris Lattner24943d22010-06-08 16:52:24 +00001684{
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001685 // Now see if we know the target triple, and if so, create our scratch AST context:
Johnny Chenfa21ffd2011-11-30 23:18:53 +00001686 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
Sean Callanandcf03f82011-11-15 22:27:19 +00001687 {
Greg Clayton34ce4ea2011-08-03 01:23:55 +00001688 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Greg Clayton13d24fb2012-01-29 20:56:30 +00001689 m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
Sean Callanandcf03f82011-11-15 22:27:19 +00001690 m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
1691 llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
1692 m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
1693 }
Chris Lattner24943d22010-06-08 16:52:24 +00001694 return m_scratch_ast_context_ap.get();
1695}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001696
Sean Callanan4938bd62011-11-16 18:20:47 +00001697ClangASTImporter *
1698Target::GetClangASTImporter()
1699{
1700 ClangASTImporter *ast_importer = m_ast_importer_ap.get();
1701
1702 if (!ast_importer)
1703 {
1704 ast_importer = new ClangASTImporter();
1705 m_ast_importer_ap.reset(ast_importer);
1706 }
1707
1708 return ast_importer;
1709}
1710
Greg Clayton990de7b2010-11-18 23:32:35 +00001711void
Caroline Tice2a456812011-03-10 22:14:10 +00001712Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +00001713{
Greg Claytonc6e82e42012-08-22 18:39:03 +00001714 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001715}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001716
Greg Clayton990de7b2010-11-18 23:32:35 +00001717void
Caroline Tice2a456812011-03-10 22:14:10 +00001718Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001719{
Greg Claytonc6e82e42012-08-22 18:39:03 +00001720 Process::SettingsTerminate ();
Greg Clayton990de7b2010-11-18 23:32:35 +00001721}
Caroline Tice5bc8c972010-09-20 20:44:43 +00001722
Greg Clayton9ce95382012-02-13 23:10:39 +00001723FileSpecList
1724Target::GetDefaultExecutableSearchPaths ()
1725{
Greg Clayton73844aa2012-08-22 17:17:09 +00001726 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1727 if (properties_sp)
1728 return properties_sp->GetExecutableSearchPaths();
Greg Clayton9ce95382012-02-13 23:10:39 +00001729 return FileSpecList();
1730}
1731
Caroline Tice5bc8c972010-09-20 20:44:43 +00001732ArchSpec
1733Target::GetDefaultArchitecture ()
1734{
Greg Clayton73844aa2012-08-22 17:17:09 +00001735 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1736 if (properties_sp)
1737 return properties_sp->GetDefaultArchitecture();
Greg Clayton469e08d2012-05-15 02:44:13 +00001738 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +00001739}
1740
1741void
Greg Clayton73844aa2012-08-22 17:17:09 +00001742Target::SetDefaultArchitecture (const ArchSpec &arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001743{
Greg Clayton73844aa2012-08-22 17:17:09 +00001744 TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
1745 if (properties_sp)
Jason Molenda332dc002012-12-12 02:23:56 +00001746 {
1747 LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::SetDefaultArchitecture setting target's default architecture to %s (%s)", arch.GetArchitectureName(), arch.GetTriple().getTriple().c_str());
Greg Clayton73844aa2012-08-22 17:17:09 +00001748 return properties_sp->SetDefaultArchitecture(arch);
Jason Molenda332dc002012-12-12 02:23:56 +00001749 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00001750}
1751
Greg Claytona830adb2010-10-04 01:05:56 +00001752Target *
1753Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1754{
1755 // The target can either exist in the "process" of ExecutionContext, or in
1756 // the "target_sp" member of SymbolContext. This accessor helper function
1757 // will get the target from one of these locations.
1758
1759 Target *target = NULL;
1760 if (sc_ptr != NULL)
1761 target = sc_ptr->target_sp.get();
Greg Clayton567e7f32011-09-22 04:58:26 +00001762 if (target == NULL && exe_ctx_ptr)
1763 target = exe_ctx_ptr->GetTargetPtr();
Greg Claytona830adb2010-10-04 01:05:56 +00001764 return target;
1765}
1766
Greg Clayton427f2902010-12-14 02:59:59 +00001767ExecutionResults
1768Target::EvaluateExpression
1769(
1770 const char *expr_cstr,
1771 StackFrame *frame,
Enrico Granata6cca9692012-07-16 23:10:35 +00001772 lldb::ValueObjectSP &result_valobj_sp,
Enrico Granatad27026e2012-09-05 20:41:26 +00001773 const EvaluateExpressionOptions& options
Greg Clayton427f2902010-12-14 02:59:59 +00001774)
1775{
Enrico Granata3a08fd12012-09-18 17:43:16 +00001776 result_valobj_sp.reset();
1777
Greg Clayton427f2902010-12-14 02:59:59 +00001778 ExecutionResults execution_results = eExecutionSetupError;
1779
Greg Clayton37bb8dd2011-12-08 02:13:16 +00001780 if (expr_cstr == NULL || expr_cstr[0] == '\0')
1781 return execution_results;
1782
Jim Ingham3613ae12011-05-12 02:06:14 +00001783 // We shouldn't run stop hooks in expressions.
1784 // Be sure to reset this if you return anywhere within this function.
1785 bool old_suppress_value = m_suppress_stop_hooks;
1786 m_suppress_stop_hooks = true;
Greg Clayton427f2902010-12-14 02:59:59 +00001787
1788 ExecutionContext exe_ctx;
Sean Callanan4ab92782013-01-12 02:04:23 +00001789
Greg Clayton427f2902010-12-14 02:59:59 +00001790 if (frame)
1791 {
1792 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton427f2902010-12-14 02:59:59 +00001793 }
1794 else if (m_process_sp)
1795 {
1796 m_process_sp->CalculateExecutionContext(exe_ctx);
1797 }
1798 else
1799 {
1800 CalculateExecutionContext(exe_ctx);
1801 }
1802
Sean Callanan4ab92782013-01-12 02:04:23 +00001803 // Make sure we aren't just trying to see the value of a persistent
1804 // variable (something like "$0")
1805 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
1810 if (persistent_var_sp)
Greg Clayton427f2902010-12-14 02:59:59 +00001811 {
Sean Callanan4ab92782013-01-12 02:04:23 +00001812 result_valobj_sp = persistent_var_sp->GetValueObject ();
Greg Clayton427f2902010-12-14 02:59:59 +00001813 execution_results = eExecutionCompleted;
Greg Clayton427f2902010-12-14 02:59:59 +00001814 }
1815 else
1816 {
Sean Callanan4ab92782013-01-12 02:04:23 +00001817 const char *prefix = GetExpressionPrefixContentsAsCString();
1818
1819 execution_results = ClangUserExpression::Evaluate (exe_ctx,
1820 options.GetExecutionPolicy(),
1821 lldb::eLanguageTypeUnknown,
1822 options.DoesCoerceToId() ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
1823 options.DoesUnwindOnError(),
Jim Inghamb7940202013-01-15 02:47:48 +00001824 options.DoesIgnoreBreakpoints(),
Sean Callanan4ab92782013-01-12 02:04:23 +00001825 expr_cstr,
1826 prefix,
1827 result_valobj_sp,
1828 options.GetRunOthers(),
1829 options.GetTimeoutUsec());
Greg Clayton427f2902010-12-14 02:59:59 +00001830 }
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
Greg Clayton535f53c2013-03-19 00:20:55 +00001912SourceManager &
1913Target::GetSourceManager ()
1914{
1915 if (m_source_manager_ap.get() == NULL)
1916 m_source_manager_ap.reset (new SourceManager(shared_from_this()));
1917 return *m_source_manager_ap;
1918}
1919
1920
Jim Inghamd60d94a2011-03-11 03:53:59 +00001921lldb::user_id_t
1922Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1923{
1924 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
Greg Clayton13d24fb2012-01-29 20:56:30 +00001925 new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
Jim Inghamd60d94a2011-03-11 03:53:59 +00001926 m_stop_hooks[new_uid] = new_hook_sp;
1927 return new_uid;
1928}
1929
1930bool
1931Target::RemoveStopHookByID (lldb::user_id_t user_id)
1932{
1933 size_t num_removed;
1934 num_removed = m_stop_hooks.erase (user_id);
1935 if (num_removed == 0)
1936 return false;
1937 else
1938 return true;
1939}
1940
1941void
1942Target::RemoveAllStopHooks ()
1943{
1944 m_stop_hooks.clear();
1945}
1946
1947Target::StopHookSP
1948Target::GetStopHookByID (lldb::user_id_t user_id)
1949{
1950 StopHookSP found_hook;
1951
1952 StopHookCollection::iterator specified_hook_iter;
1953 specified_hook_iter = m_stop_hooks.find (user_id);
1954 if (specified_hook_iter != m_stop_hooks.end())
1955 found_hook = (*specified_hook_iter).second;
1956 return found_hook;
1957}
1958
1959bool
1960Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1961{
1962 StopHookCollection::iterator specified_hook_iter;
1963 specified_hook_iter = m_stop_hooks.find (user_id);
1964 if (specified_hook_iter == m_stop_hooks.end())
1965 return false;
1966
1967 (*specified_hook_iter).second->SetIsActive (active_state);
1968 return true;
1969}
1970
1971void
1972Target::SetAllStopHooksActiveState (bool active_state)
1973{
1974 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1975 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1976 {
1977 (*pos).second->SetIsActive (active_state);
1978 }
1979}
1980
1981void
1982Target::RunStopHooks ()
1983{
Jim Ingham3613ae12011-05-12 02:06:14 +00001984 if (m_suppress_stop_hooks)
1985 return;
1986
Jim Inghamd60d94a2011-03-11 03:53:59 +00001987 if (!m_process_sp)
1988 return;
Enrico Granata5a60f5e2012-08-03 22:24:48 +00001989
1990 // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression
1991 // since in that case we do not want to run the stop-hooks
1992 if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression())
1993 return;
1994
Jim Inghamd60d94a2011-03-11 03:53:59 +00001995 if (m_stop_hooks.empty())
1996 return;
1997
1998 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1999
2000 // If there aren't any active stop hooks, don't bother either:
2001 bool any_active_hooks = false;
2002 for (pos = m_stop_hooks.begin(); pos != end; pos++)
2003 {
2004 if ((*pos).second->IsActive())
2005 {
2006 any_active_hooks = true;
2007 break;
2008 }
2009 }
2010 if (!any_active_hooks)
2011 return;
2012
2013 CommandReturnObject result;
2014
2015 std::vector<ExecutionContext> exc_ctx_with_reasons;
2016 std::vector<SymbolContext> sym_ctx_with_reasons;
2017
2018 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
2019 size_t num_threads = cur_threadlist.GetSize();
2020 for (size_t i = 0; i < num_threads; i++)
2021 {
2022 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
2023 if (cur_thread_sp->ThreadStoppedForAReason())
2024 {
2025 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
2026 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
2027 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
2028 }
2029 }
2030
2031 // If no threads stopped for a reason, don't run the stop-hooks.
2032 size_t num_exe_ctx = exc_ctx_with_reasons.size();
2033 if (num_exe_ctx == 0)
2034 return;
2035
Jim Inghame5ed8e92011-06-02 23:58:26 +00002036 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
2037 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002038
2039 bool keep_going = true;
2040 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00002041 bool print_hook_header;
2042 bool print_thread_header;
2043
2044 if (num_exe_ctx == 1)
2045 print_thread_header = false;
2046 else
2047 print_thread_header = true;
2048
2049 if (m_stop_hooks.size() == 1)
2050 print_hook_header = false;
2051 else
2052 print_hook_header = true;
2053
Jim Inghamd60d94a2011-03-11 03:53:59 +00002054 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
2055 {
2056 // result.Clear();
2057 StopHookSP cur_hook_sp = (*pos).second;
2058 if (!cur_hook_sp->IsActive())
2059 continue;
2060
2061 bool any_thread_matched = false;
2062 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
2063 {
2064 if ((cur_hook_sp->GetSpecifier () == NULL
2065 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
2066 && (cur_hook_sp->GetThreadSpecifier() == NULL
Jim Inghama2664912012-03-07 22:03:04 +00002067 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef())))
Jim Inghamd60d94a2011-03-11 03:53:59 +00002068 {
2069 if (!hooks_ran)
2070 {
Jim Inghamd60d94a2011-03-11 03:53:59 +00002071 hooks_ran = true;
2072 }
Jim Inghamc54840c2011-03-22 01:47:27 +00002073 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002074 {
Johnny Chen4d96a742011-10-24 23:01:06 +00002075 const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ?
2076 cur_hook_sp->GetCommands().GetStringAtIndex(0) :
2077 NULL);
2078 if (cmd)
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002079 result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd);
Johnny Chen4d96a742011-10-24 23:01:06 +00002080 else
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002081 result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002082 any_thread_matched = true;
2083 }
2084
Jim Inghamc54840c2011-03-22 01:47:27 +00002085 if (print_thread_header)
Greg Clayton567e7f32011-09-22 04:58:26 +00002086 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002087
2088 bool stop_on_continue = true;
2089 bool stop_on_error = true;
2090 bool echo_commands = false;
2091 bool print_results = true;
2092 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00002093 &exc_ctx_with_reasons[i],
2094 stop_on_continue,
2095 stop_on_error,
2096 echo_commands,
Enrico Granata01bc2d42012-05-31 01:09:06 +00002097 print_results,
2098 eLazyBoolNo,
Greg Clayton24bc5d92011-03-30 18:16:51 +00002099 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00002100
2101 // If the command started the target going again, we should bag out of
2102 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00002103 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
2104 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00002105 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002106 result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002107 keep_going = false;
2108 }
2109 }
2110 }
2111 }
Jason Molenda850ac6e2011-09-23 00:42:55 +00002112
Caroline Tice4a348082011-05-02 20:41:46 +00002113 result.GetImmediateOutputStream()->Flush();
2114 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00002115}
2116
Greg Claytonbbea1332011-07-08 00:48:09 +00002117
Jim Inghamd60d94a2011-03-11 03:53:59 +00002118//--------------------------------------------------------------
2119// class Target::StopHook
2120//--------------------------------------------------------------
2121
2122
2123Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
2124 UserID (uid),
2125 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00002126 m_commands (),
2127 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002128 m_thread_spec_ap(NULL),
2129 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002130{
2131}
2132
2133Target::StopHook::StopHook (const StopHook &rhs) :
2134 UserID (rhs.GetID()),
2135 m_target_sp (rhs.m_target_sp),
2136 m_commands (rhs.m_commands),
2137 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00002138 m_thread_spec_ap (NULL),
2139 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00002140{
2141 if (rhs.m_thread_spec_ap.get() != NULL)
2142 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
2143}
2144
2145
2146Target::StopHook::~StopHook ()
2147{
2148}
2149
2150void
2151Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
2152{
2153 m_thread_spec_ap.reset (specifier);
2154}
2155
2156
2157void
2158Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
2159{
2160 int indent_level = s->GetIndentLevel();
2161
2162 s->SetIndentLevel(indent_level + 2);
2163
Daniel Malea5f35a4b2012-11-29 21:49:15 +00002164 s->Printf ("Hook: %" PRIu64 "\n", GetID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00002165 if (m_active)
2166 s->Indent ("State: enabled\n");
2167 else
2168 s->Indent ("State: disabled\n");
2169
2170 if (m_specifier_sp)
2171 {
2172 s->Indent();
2173 s->PutCString ("Specifier:\n");
2174 s->SetIndentLevel (indent_level + 4);
2175 m_specifier_sp->GetDescription (s, level);
2176 s->SetIndentLevel (indent_level + 2);
2177 }
2178
2179 if (m_thread_spec_ap.get() != NULL)
2180 {
2181 StreamString tmp;
2182 s->Indent("Thread:\n");
2183 m_thread_spec_ap->GetDescription (&tmp, level);
2184 s->SetIndentLevel (indent_level + 4);
2185 s->Indent (tmp.GetData());
2186 s->PutCString ("\n");
2187 s->SetIndentLevel (indent_level + 2);
2188 }
2189
2190 s->Indent ("Commands: \n");
2191 s->SetIndentLevel (indent_level + 4);
2192 uint32_t num_commands = m_commands.GetSize();
2193 for (uint32_t i = 0; i < num_commands; i++)
2194 {
2195 s->Indent(m_commands.GetStringAtIndex(i));
2196 s->PutCString ("\n");
2197 }
2198 s->SetIndentLevel (indent_level);
2199}
2200
Greg Clayton73844aa2012-08-22 17:17:09 +00002201//--------------------------------------------------------------
2202// class TargetProperties
2203//--------------------------------------------------------------
2204
2205OptionEnumValueElement
2206lldb_private::g_dynamic_value_types[] =
Caroline Tice5bc8c972010-09-20 20:44:43 +00002207{
Greg Clayton73844aa2012-08-22 17:17:09 +00002208 { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2209 { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2210 { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
2211 { 0, NULL, NULL }
2212};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002213
Greg Clayton49ce8962012-08-29 21:13:06 +00002214static OptionEnumValueElement
2215g_inline_breakpoint_enums[] =
2216{
2217 { 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."},
2218 { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."},
2219 { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."},
2220 { 0, NULL, NULL }
2221};
2222
Jim Ingham7d408382013-03-02 00:26:47 +00002223typedef enum x86DisassemblyFlavor
2224{
2225 eX86DisFlavorDefault,
2226 eX86DisFlavorIntel,
2227 eX86DisFlavorATT
2228} x86DisassemblyFlavor;
2229
2230static OptionEnumValueElement
2231g_x86_dis_flavor_value_types[] =
2232{
2233 { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."},
2234 { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."},
2235 { eX86DisFlavorATT, "att", "AT&T disassembler flavor."},
2236 { 0, NULL, NULL }
2237};
2238
Greg Clayton73844aa2012-08-22 17:17:09 +00002239static PropertyDefinition
2240g_properties[] =
Caroline Tice5bc8c972010-09-20 20:44:43 +00002241{
Greg Clayton73844aa2012-08-22 17:17:09 +00002242 { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." },
2243 { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." },
2244 { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." },
2245 { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." },
2246 { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." },
2247 { "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 "
2248 "where it exists on the current system. It consists of an array of duples, the first element of each duple is "
2249 "some part (starting at the root) of the path to the file when it was built, "
2250 "and the second is where the remainder of the original build hierarchy is rooted on the local system. "
2251 "Each element of the array is checked in order and the first one that results in a match wins." },
2252 { "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." },
2253 { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." },
2254 { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." },
2255 { "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 +00002256 { "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." },
2257 { "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 +00002258 { "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." },
2259 { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
2260 { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
2261 { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." },
2262 { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." },
2263 { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" },
2264 { "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 +00002265 { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsHeaders , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. "
2266 "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. "
2267 "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. "
2268 "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. "
2269 "Always checking for inlined breakpoint locations can be expensive (memory and time), so we try to minimize the "
2270 "times we look for inlined locations. This setting allows you to control exactly which strategy is used when settings "
2271 "file and line breakpoints." },
Jim Ingham7d408382013-03-02 00:26:47 +00002272 // FIXME: This is the wrong way to do per-architecture settings, but we don't have a general per architecture settings system in place yet.
2273 { "x86-disassembly-flavor" , OptionValue::eTypeEnum , false, eX86DisFlavorDefault, NULL, g_x86_dis_flavor_value_types, "The default disassembly flavor to use for x86 or x86-64 targets." },
Jim Ingham4aac0962013-04-04 01:38:54 +00002274 { "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." },
Greg Clayton73844aa2012-08-22 17:17:09 +00002275 { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL }
2276};
2277enum
Caroline Tice5bc8c972010-09-20 20:44:43 +00002278{
Greg Clayton73844aa2012-08-22 17:17:09 +00002279 ePropertyDefaultArch,
2280 ePropertyExprPrefix,
2281 ePropertyPreferDynamic,
2282 ePropertyEnableSynthetic,
2283 ePropertySkipPrologue,
2284 ePropertySourceMap,
2285 ePropertyExecutableSearchPaths,
2286 ePropertyMaxChildrenCount,
2287 ePropertyMaxSummaryLength,
2288 ePropertyBreakpointUseAvoidList,
Greg Clayton0c8446c2012-10-17 22:57:12 +00002289 ePropertyArg0,
Greg Clayton73844aa2012-08-22 17:17:09 +00002290 ePropertyRunArgs,
2291 ePropertyEnvVars,
2292 ePropertyInheritEnv,
2293 ePropertyInputPath,
2294 ePropertyOutputPath,
2295 ePropertyErrorPath,
2296 ePropertyDisableASLR,
Greg Clayton49ce8962012-08-29 21:13:06 +00002297 ePropertyDisableSTDIO,
Jim Ingham7d408382013-03-02 00:26:47 +00002298 ePropertyInlineStrategy,
Jim Ingham5e0e3722013-03-13 17:58:04 +00002299 ePropertyDisassemblyFlavor,
2300 ePropertyUseFastStepping
Greg Clayton73844aa2012-08-22 17:17:09 +00002301};
Caroline Tice5bc8c972010-09-20 20:44:43 +00002302
Caroline Tice5bc8c972010-09-20 20:44:43 +00002303
Greg Clayton73844aa2012-08-22 17:17:09 +00002304class TargetOptionValueProperties : public OptionValueProperties
Greg Claytond284b662011-02-18 01:44:25 +00002305{
Greg Clayton73844aa2012-08-22 17:17:09 +00002306public:
2307 TargetOptionValueProperties (const ConstString &name) :
2308 OptionValueProperties (name),
2309 m_target (NULL),
2310 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002311 {
Caroline Tice5bc8c972010-09-20 20:44:43 +00002312 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002313
Greg Clayton73844aa2012-08-22 17:17:09 +00002314 // This constructor is used when creating TargetOptionValueProperties when it
2315 // is part of a new lldb_private::Target instance. It will copy all current
2316 // global property values as needed
2317 TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) :
2318 OptionValueProperties(*target_properties_sp->GetValueProperties()),
2319 m_target (target),
2320 m_got_host_env (false)
Caroline Tice5bc8c972010-09-20 20:44:43 +00002321 {
Greg Clayton73844aa2012-08-22 17:17:09 +00002322 }
2323
2324 virtual const Property *
2325 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
2326 {
2327 // When gettings the value for a key from the target options, we will always
2328 // try and grab the setting from the current target if there is one. Else we just
2329 // use the one from this instance.
2330 if (idx == ePropertyEnvVars)
2331 GetHostEnvironmentIfNeeded ();
2332
2333 if (exe_ctx)
2334 {
2335 Target *target = exe_ctx->GetTargetPtr();
2336 if (target)
2337 {
2338 TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get());
2339 if (this != target_properties)
2340 return target_properties->ProtectedGetPropertyAtIndex (idx);
2341 }
2342 }
2343 return ProtectedGetPropertyAtIndex (idx);
2344 }
2345protected:
2346
2347 void
2348 GetHostEnvironmentIfNeeded () const
2349 {
2350 if (!m_got_host_env)
2351 {
2352 if (m_target)
2353 {
2354 m_got_host_env = true;
2355 const uint32_t idx = ePropertyInheritEnv;
2356 if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0))
2357 {
2358 PlatformSP platform_sp (m_target->GetPlatform());
2359 if (platform_sp)
2360 {
2361 StringList env;
2362 if (platform_sp->GetEnvironment(env))
2363 {
2364 OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars);
2365 if (env_dict)
2366 {
2367 const bool can_replace = false;
2368 const size_t envc = env.GetSize();
2369 for (size_t idx=0; idx<envc; idx++)
2370 {
2371 const char *env_entry = env.GetStringAtIndex (idx);
2372 if (env_entry)
2373 {
2374 const char *equal_pos = ::strchr(env_entry, '=');
2375 ConstString key;
2376 // It is ok to have environment variables with no values
2377 const char *value = NULL;
2378 if (equal_pos)
2379 {
2380 key.SetCStringWithLength(env_entry, equal_pos - env_entry);
2381 if (equal_pos[1])
2382 value = equal_pos + 1;
2383 }
2384 else
2385 {
2386 key.SetCString(env_entry);
2387 }
2388 // Don't allow existing keys to be replaced with ones we get from the platform environment
2389 env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace);
2390 }
2391 }
2392 }
2393 }
2394 }
2395 }
2396 }
2397 }
2398 }
2399 Target *m_target;
2400 mutable bool m_got_host_env;
2401};
2402
2403TargetProperties::TargetProperties (Target *target) :
2404 Properties ()
2405{
2406 if (target)
2407 {
2408 m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties()));
Caroline Tice5bc8c972010-09-20 20:44:43 +00002409 }
2410 else
Greg Clayton73844aa2012-08-22 17:17:09 +00002411 {
2412 m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target")));
2413 m_collection_sp->Initialize(g_properties);
2414 m_collection_sp->AppendProperty(ConstString("process"),
2415 ConstString("Settings specify to processes."),
2416 true,
2417 Process::GetGlobalProperties()->GetValueProperties());
2418 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00002419}
2420
Greg Clayton73844aa2012-08-22 17:17:09 +00002421TargetProperties::~TargetProperties ()
2422{
2423}
2424ArchSpec
2425TargetProperties::GetDefaultArchitecture () const
2426{
2427 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2428 if (value)
2429 return value->GetCurrentValue();
2430 return ArchSpec();
2431}
2432
2433void
2434TargetProperties::SetDefaultArchitecture (const ArchSpec& arch)
2435{
2436 OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch);
2437 if (value)
2438 return value->SetCurrentValue(arch, true);
2439}
2440
2441lldb::DynamicValueType
2442TargetProperties::GetPreferDynamicValue() const
2443{
2444 const uint32_t idx = ePropertyPreferDynamic;
2445 return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2446}
2447
2448bool
2449TargetProperties::GetDisableASLR () const
2450{
2451 const uint32_t idx = ePropertyDisableASLR;
2452 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2453}
2454
2455void
2456TargetProperties::SetDisableASLR (bool b)
2457{
2458 const uint32_t idx = ePropertyDisableASLR;
2459 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2460}
2461
2462bool
2463TargetProperties::GetDisableSTDIO () const
2464{
2465 const uint32_t idx = ePropertyDisableSTDIO;
2466 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2467}
2468
2469void
2470TargetProperties::SetDisableSTDIO (bool b)
2471{
2472 const uint32_t idx = ePropertyDisableSTDIO;
2473 m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b);
2474}
2475
Jim Ingham7d408382013-03-02 00:26:47 +00002476const char *
2477TargetProperties::GetDisassemblyFlavor () const
2478{
2479 const uint32_t idx = ePropertyDisassemblyFlavor;
2480 const char *return_value;
2481
2482 x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2483 return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
2484 return return_value;
2485}
2486
Greg Clayton49ce8962012-08-29 21:13:06 +00002487InlineStrategy
2488TargetProperties::GetInlineStrategy () const
2489{
2490 const uint32_t idx = ePropertyInlineStrategy;
2491 return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value);
2492}
2493
Greg Clayton0c8446c2012-10-17 22:57:12 +00002494const char *
2495TargetProperties::GetArg0 () const
2496{
2497 const uint32_t idx = ePropertyArg0;
2498 return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL);
2499}
2500
2501void
2502TargetProperties::SetArg0 (const char *arg)
2503{
2504 const uint32_t idx = ePropertyArg0;
2505 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg);
2506}
2507
Greg Clayton73844aa2012-08-22 17:17:09 +00002508bool
2509TargetProperties::GetRunArguments (Args &args) const
2510{
2511 const uint32_t idx = ePropertyRunArgs;
2512 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
2513}
2514
2515void
2516TargetProperties::SetRunArguments (const Args &args)
2517{
2518 const uint32_t idx = ePropertyRunArgs;
2519 m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
2520}
2521
2522size_t
2523TargetProperties::GetEnvironmentAsArgs (Args &env) const
2524{
2525 const uint32_t idx = ePropertyEnvVars;
2526 return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env);
2527}
2528
2529bool
2530TargetProperties::GetSkipPrologue() const
2531{
2532 const uint32_t idx = ePropertySkipPrologue;
2533 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2534}
2535
2536PathMappingList &
2537TargetProperties::GetSourcePathMap () const
2538{
2539 const uint32_t idx = ePropertySourceMap;
2540 OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx);
2541 assert(option_value);
2542 return option_value->GetCurrentValue();
2543}
2544
2545FileSpecList &
Greg Claytonc6e82e42012-08-22 18:39:03 +00002546TargetProperties::GetExecutableSearchPaths ()
Greg Clayton73844aa2012-08-22 17:17:09 +00002547{
2548 const uint32_t idx = ePropertyExecutableSearchPaths;
2549 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
2550 assert(option_value);
2551 return option_value->GetCurrentValue();
2552}
2553
2554bool
2555TargetProperties::GetEnableSyntheticValue () const
2556{
2557 const uint32_t idx = ePropertyEnableSynthetic;
2558 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2559}
2560
2561uint32_t
2562TargetProperties::GetMaximumNumberOfChildrenToDisplay() const
2563{
2564 const uint32_t idx = ePropertyMaxChildrenCount;
2565 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2566}
2567
2568uint32_t
2569TargetProperties::GetMaximumSizeOfStringSummary() const
2570{
2571 const uint32_t idx = ePropertyMaxSummaryLength;
2572 return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value);
2573}
2574
2575FileSpec
2576TargetProperties::GetStandardInputPath () const
2577{
2578 const uint32_t idx = ePropertyInputPath;
2579 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2580}
2581
2582void
2583TargetProperties::SetStandardInputPath (const char *p)
2584{
2585 const uint32_t idx = ePropertyInputPath;
2586 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2587}
2588
2589FileSpec
2590TargetProperties::GetStandardOutputPath () const
2591{
2592 const uint32_t idx = ePropertyOutputPath;
2593 return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx);
2594}
2595
2596void
2597TargetProperties::SetStandardOutputPath (const char *p)
2598{
2599 const uint32_t idx = ePropertyOutputPath;
2600 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2601}
2602
2603FileSpec
2604TargetProperties::GetStandardErrorPath () const
2605{
2606 const uint32_t idx = ePropertyErrorPath;
2607 return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx);
2608}
2609
Greg Claytonc6e82e42012-08-22 18:39:03 +00002610const char *
2611TargetProperties::GetExpressionPrefixContentsAsCString ()
2612{
2613 const uint32_t idx = ePropertyExprPrefix;
2614 OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx);
2615 if (file)
Jim Ingham7021cda2012-08-22 21:21:16 +00002616 {
Greg Claytonfc04d242012-08-30 18:15:10 +00002617 const bool null_terminate = true;
2618 DataBufferSP data_sp(file->GetFileContents(null_terminate));
Jim Ingham7021cda2012-08-22 21:21:16 +00002619 if (data_sp)
2620 return (const char *) data_sp->GetBytes();
2621 }
Greg Claytonc6e82e42012-08-22 18:39:03 +00002622 return NULL;
2623}
2624
Greg Clayton73844aa2012-08-22 17:17:09 +00002625void
2626TargetProperties::SetStandardErrorPath (const char *p)
2627{
2628 const uint32_t idx = ePropertyErrorPath;
2629 m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p);
2630}
2631
2632bool
2633TargetProperties::GetBreakpointsConsultPlatformAvoidList ()
2634{
2635 const uint32_t idx = ePropertyBreakpointUseAvoidList;
2636 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2637}
2638
Jim Ingham5e0e3722013-03-13 17:58:04 +00002639bool
2640TargetProperties::GetUseFastStepping () const
2641{
2642 const uint32_t idx = ePropertyUseFastStepping;
2643 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
2644}
2645
Greg Clayton73844aa2012-08-22 17:17:09 +00002646const TargetPropertiesSP &
2647Target::GetGlobalProperties()
2648{
2649 static TargetPropertiesSP g_settings_sp;
2650 if (!g_settings_sp)
2651 {
2652 g_settings_sp.reset (new TargetProperties (NULL));
2653 }
2654 return g_settings_sp;
2655}
2656
Jim Ingham5a15e692012-02-16 06:50:00 +00002657const ConstString &
2658Target::TargetEventData::GetFlavorString ()
2659{
2660 static ConstString g_flavor ("Target::TargetEventData");
2661 return g_flavor;
2662}
2663
2664const ConstString &
2665Target::TargetEventData::GetFlavor () const
2666{
2667 return TargetEventData::GetFlavorString ();
2668}
2669
2670Target::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) :
2671 EventData(),
2672 m_target_sp (new_target_sp)
2673{
2674}
2675
2676Target::TargetEventData::~TargetEventData()
2677{
2678
2679}
2680
2681void
2682Target::TargetEventData::Dump (Stream *s) const
2683{
2684
2685}
2686
2687const TargetSP
2688Target::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp)
2689{
2690 TargetSP target_sp;
2691
2692 const TargetEventData *data = GetEventDataFromEvent (event_sp.get());
2693 if (data)
2694 target_sp = data->m_target_sp;
2695
2696 return target_sp;
2697}
2698
2699const Target::TargetEventData *
2700Target::TargetEventData::GetEventDataFromEvent (const Event *event_ptr)
2701{
2702 if (event_ptr)
2703 {
2704 const EventData *event_data = event_ptr->GetData();
2705 if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString())
2706 return static_cast <const TargetEventData *> (event_ptr->GetData());
2707 }
2708 return NULL;
2709}
2710