1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Target/Target.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Breakpoint/BreakpointResolver.h"
17 #include "lldb/Breakpoint/BreakpointResolverAddress.h"
18 #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
19 #include "lldb/Breakpoint/BreakpointResolverName.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/Event.h"
22 #include "lldb/Core/Log.h"
23 #include "lldb/Core/StreamAsynchronousIO.h"
24 #include "lldb/Core/StreamString.h"
25 #include "lldb/Core/Timer.h"
26 #include "lldb/Core/ValueObject.h"
27 #include "lldb/Expression/ClangUserExpression.h"
28 #include "lldb/Host/Host.h"
29 #include "lldb/Interpreter/CommandInterpreter.h"
30 #include "lldb/Interpreter/CommandReturnObject.h"
31 #include "lldb/lldb-private-log.h"
32 #include "lldb/Symbol/ObjectFile.h"
33 #include "lldb/Target/Process.h"
34 #include "lldb/Target/StackFrame.h"
35 #include "lldb/Target/Thread.h"
36 #include "lldb/Target/ThreadSpec.h"
37 
38 using namespace lldb;
39 using namespace lldb_private;
40 
41 //----------------------------------------------------------------------
42 // Target constructor
43 //----------------------------------------------------------------------
44 Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
45     Broadcaster ("lldb.target"),
46     ExecutionContextScope (),
47     TargetInstanceSettings (*GetSettingsController()),
48     m_debugger (debugger),
49     m_platform_sp (platform_sp),
50     m_mutex (Mutex::eMutexTypeRecursive),
51     m_arch (target_arch),
52     m_images (),
53     m_section_load_list (),
54     m_breakpoint_list (false),
55     m_internal_breakpoint_list (true),
56     m_watchpoint_location_list (),
57     m_process_sp (),
58     m_search_filter_sp (),
59     m_image_search_paths (ImageSearchPathsChanged, this),
60     m_scratch_ast_context_ap (NULL),
61     m_persistent_variables (),
62     m_source_manager(*this),
63     m_stop_hooks (),
64     m_stop_hook_next_id (0),
65     m_suppress_stop_hooks (false)
66 {
67     SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
68     SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
69     SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
70 
71     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
72     if (log)
73         log->Printf ("%p Target::Target()", this);
74 }
75 
76 //----------------------------------------------------------------------
77 // Destructor
78 //----------------------------------------------------------------------
79 Target::~Target()
80 {
81     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
82     if (log)
83         log->Printf ("%p Target::~Target()", this);
84     DeleteCurrentProcess ();
85 }
86 
87 void
88 Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
89 {
90 //    s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
91     if (description_level != lldb::eDescriptionLevelBrief)
92     {
93         s->Indent();
94         s->PutCString("Target\n");
95         s->IndentMore();
96             m_images.Dump(s);
97             m_breakpoint_list.Dump(s);
98             m_internal_breakpoint_list.Dump(s);
99         s->IndentLess();
100     }
101     else
102     {
103         Module *exe_module = GetExecutableModulePointer();
104         if (exe_module)
105             s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
106         else
107             s->PutCString ("No executable module.");
108     }
109 }
110 
111 void
112 Target::DeleteCurrentProcess ()
113 {
114     if (m_process_sp.get())
115     {
116         m_section_load_list.Clear();
117         if (m_process_sp->IsAlive())
118             m_process_sp->Destroy();
119 
120         m_process_sp->Finalize();
121 
122         // Do any cleanup of the target we need to do between process instances.
123         // NB It is better to do this before destroying the process in case the
124         // clean up needs some help from the process.
125         m_breakpoint_list.ClearAllBreakpointSites();
126         m_internal_breakpoint_list.ClearAllBreakpointSites();
127         m_process_sp.reset();
128     }
129 }
130 
131 const lldb::ProcessSP &
132 Target::CreateProcess (Listener &listener, const char *plugin_name)
133 {
134     DeleteCurrentProcess ();
135     m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
136     return m_process_sp;
137 }
138 
139 const lldb::ProcessSP &
140 Target::GetProcessSP () const
141 {
142     return m_process_sp;
143 }
144 
145 lldb::TargetSP
146 Target::GetSP()
147 {
148     return m_debugger.GetTargetList().GetTargetSP(this);
149 }
150 
151 void
152 Target::Destroy()
153 {
154     Mutex::Locker locker (m_mutex);
155     DeleteCurrentProcess ();
156     m_platform_sp.reset();
157     m_arch.Clear();
158     m_images.Clear();
159     m_section_load_list.Clear();
160     const bool notify = false;
161     m_breakpoint_list.RemoveAll(notify);
162     m_internal_breakpoint_list.RemoveAll(notify);
163     m_last_created_breakpoint.reset();
164     m_search_filter_sp.reset();
165     m_image_search_paths.Clear(notify);
166     m_scratch_ast_context_ap.reset();
167     m_persistent_variables.Clear();
168     m_stop_hooks.clear();
169     m_stop_hook_next_id = 0;
170     m_suppress_stop_hooks = false;
171 }
172 
173 
174 BreakpointList &
175 Target::GetBreakpointList(bool internal)
176 {
177     if (internal)
178         return m_internal_breakpoint_list;
179     else
180         return m_breakpoint_list;
181 }
182 
183 const BreakpointList &
184 Target::GetBreakpointList(bool internal) const
185 {
186     if (internal)
187         return m_internal_breakpoint_list;
188     else
189         return m_breakpoint_list;
190 }
191 
192 BreakpointSP
193 Target::GetBreakpointByID (break_id_t break_id)
194 {
195     BreakpointSP bp_sp;
196 
197     if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
198         bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
199     else
200         bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
201 
202     return bp_sp;
203 }
204 
205 BreakpointSP
206 Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
207 {
208     SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
209     BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
210     return CreateBreakpoint (filter_sp, resolver_sp, internal);
211 }
212 
213 
214 BreakpointSP
215 Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
216 {
217     Address so_addr;
218     // Attempt to resolve our load address if possible, though it is ok if
219     // it doesn't resolve to section/offset.
220 
221     // Try and resolve as a load address if possible
222     m_section_load_list.ResolveLoadAddress(addr, so_addr);
223     if (!so_addr.IsValid())
224     {
225         // The address didn't resolve, so just set this as an absolute address
226         so_addr.SetOffset (addr);
227     }
228     BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
229     return bp_sp;
230 }
231 
232 BreakpointSP
233 Target::CreateBreakpoint (Address &addr, bool internal)
234 {
235     TargetSP target_sp = this->GetSP();
236     SearchFilterSP filter_sp(new SearchFilter (target_sp));
237     BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
238     return CreateBreakpoint (filter_sp, resolver_sp, internal);
239 }
240 
241 BreakpointSP
242 Target::CreateBreakpoint (const FileSpec *containingModule,
243                           const char *func_name,
244                           uint32_t func_name_type_mask,
245                           bool internal,
246                           LazyBool skip_prologue)
247 {
248     BreakpointSP bp_sp;
249     if (func_name)
250     {
251         SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
252 
253         BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
254                                                                       func_name,
255                                                                       func_name_type_mask,
256                                                                       Breakpoint::Exact,
257                                                                       skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
258         bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
259     }
260     return bp_sp;
261 }
262 
263 
264 SearchFilterSP
265 Target::GetSearchFilterForModule (const FileSpec *containingModule)
266 {
267     SearchFilterSP filter_sp;
268     lldb::TargetSP target_sp = this->GetSP();
269     if (containingModule != NULL)
270     {
271         // TODO: We should look into sharing module based search filters
272         // across many breakpoints like we do for the simple target based one
273         filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
274     }
275     else
276     {
277         if (m_search_filter_sp.get() == NULL)
278             m_search_filter_sp.reset (new SearchFilter (target_sp));
279         filter_sp = m_search_filter_sp;
280     }
281     return filter_sp;
282 }
283 
284 BreakpointSP
285 Target::CreateBreakpoint (const FileSpec *containingModule,
286                           RegularExpression &func_regex,
287                           bool internal,
288                           LazyBool skip_prologue)
289 {
290     SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
291     BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
292                                                                  func_regex,
293                                                                  skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
294 
295     return CreateBreakpoint (filter_sp, resolver_sp, internal);
296 }
297 
298 BreakpointSP
299 Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
300 {
301     BreakpointSP bp_sp;
302     if (filter_sp && resolver_sp)
303     {
304         bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
305         resolver_sp->SetBreakpoint (bp_sp.get());
306 
307         if (internal)
308             m_internal_breakpoint_list.Add (bp_sp, false);
309         else
310             m_breakpoint_list.Add (bp_sp, true);
311 
312         LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
313         if (log)
314         {
315             StreamString s;
316             bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
317             log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
318         }
319 
320         bp_sp->ResolveBreakpoint();
321     }
322 
323     if (!internal && bp_sp)
324     {
325         m_last_created_breakpoint = bp_sp;
326     }
327 
328     return bp_sp;
329 }
330 
331 // See also WatchpointLocation::SetWatchpointType(uint32_t type) and
332 // the OptionGroupWatchpoint::WatchType enum type.
333 WatchpointLocationSP
334 Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type)
335 {
336     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
337     if (log)
338         log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
339                     __FUNCTION__, addr, size, type);
340 
341     WatchpointLocationSP wp_loc_sp;
342     bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
343     if (!process_is_valid)
344         return wp_loc_sp;
345     if (addr == LLDB_INVALID_ADDRESS || size == 0)
346         return wp_loc_sp;
347 
348     // Currently we only support one watchpoint location per address, with total
349     // number of watchpoint locations limited by the hardware which the inferior
350     // is running on.
351     WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
352     if (matched_sp)
353     {
354         size_t old_size = matched_sp->GetByteSize();
355         uint32_t old_type =
356             (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
357             (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
358         // Return the existing watchpoint location if both size and type match.
359         if (size == old_size && type == old_type) {
360             wp_loc_sp = matched_sp;
361             wp_loc_sp->SetEnabled(false);
362         } else {
363             // Nil the matched watchpoint location; we will be creating a new one.
364             m_process_sp->DisableWatchpoint(matched_sp.get());
365             m_watchpoint_location_list.Remove(matched_sp->GetID());
366         }
367     }
368 
369     if (!wp_loc_sp) {
370         WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
371         if (!new_loc) {
372             printf("WatchpointLocation ctor failed, out of memory?\n");
373             return wp_loc_sp;
374         }
375         new_loc->SetWatchpointType(type);
376         wp_loc_sp.reset(new_loc);
377         m_watchpoint_location_list.Add(wp_loc_sp);
378     }
379 
380     Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
381     if (log)
382             log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
383                         __FUNCTION__,
384                         rc.Success() ? "succeeded" : "failed",
385                         wp_loc_sp->GetID());
386 
387     if (rc.Fail()) wp_loc_sp.reset();
388     return wp_loc_sp;
389 }
390 
391 void
392 Target::RemoveAllBreakpoints (bool internal_also)
393 {
394     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
395     if (log)
396         log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
397 
398     m_breakpoint_list.RemoveAll (true);
399     if (internal_also)
400         m_internal_breakpoint_list.RemoveAll (false);
401 
402     m_last_created_breakpoint.reset();
403 }
404 
405 void
406 Target::DisableAllBreakpoints (bool internal_also)
407 {
408     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
409     if (log)
410         log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
411 
412     m_breakpoint_list.SetEnabledAll (false);
413     if (internal_also)
414         m_internal_breakpoint_list.SetEnabledAll (false);
415 }
416 
417 void
418 Target::EnableAllBreakpoints (bool internal_also)
419 {
420     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
421     if (log)
422         log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
423 
424     m_breakpoint_list.SetEnabledAll (true);
425     if (internal_also)
426         m_internal_breakpoint_list.SetEnabledAll (true);
427 }
428 
429 bool
430 Target::RemoveBreakpointByID (break_id_t break_id)
431 {
432     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
433     if (log)
434         log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
435 
436     if (DisableBreakpointByID (break_id))
437     {
438         if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
439             m_internal_breakpoint_list.Remove(break_id, false);
440         else
441         {
442             if (m_last_created_breakpoint)
443             {
444                 if (m_last_created_breakpoint->GetID() == break_id)
445                     m_last_created_breakpoint.reset();
446             }
447             m_breakpoint_list.Remove(break_id, true);
448         }
449         return true;
450     }
451     return false;
452 }
453 
454 bool
455 Target::DisableBreakpointByID (break_id_t break_id)
456 {
457     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
458     if (log)
459         log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
460 
461     BreakpointSP bp_sp;
462 
463     if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
464         bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
465     else
466         bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
467     if (bp_sp)
468     {
469         bp_sp->SetEnabled (false);
470         return true;
471     }
472     return false;
473 }
474 
475 bool
476 Target::EnableBreakpointByID (break_id_t break_id)
477 {
478     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
479     if (log)
480         log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
481                      __FUNCTION__,
482                      break_id,
483                      LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
484 
485     BreakpointSP bp_sp;
486 
487     if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
488         bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
489     else
490         bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
491 
492     if (bp_sp)
493     {
494         bp_sp->SetEnabled (true);
495         return true;
496     }
497     return false;
498 }
499 
500 ModuleSP
501 Target::GetExecutableModule ()
502 {
503     return m_images.GetModuleAtIndex(0);
504 }
505 
506 Module*
507 Target::GetExecutableModulePointer ()
508 {
509     return m_images.GetModulePointerAtIndex(0);
510 }
511 
512 void
513 Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
514 {
515     m_images.Clear();
516     m_scratch_ast_context_ap.reset();
517 
518     if (executable_sp.get())
519     {
520         Timer scoped_timer (__PRETTY_FUNCTION__,
521                             "Target::SetExecutableModule (executable = '%s/%s')",
522                             executable_sp->GetFileSpec().GetDirectory().AsCString(),
523                             executable_sp->GetFileSpec().GetFilename().AsCString());
524 
525         m_images.Append(executable_sp); // The first image is our exectuable file
526 
527         // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
528         if (!m_arch.IsValid())
529             m_arch = executable_sp->GetArchitecture();
530 
531         FileSpecList dependent_files;
532         ObjectFile *executable_objfile = executable_sp->GetObjectFile();
533         // Let's find the file & line for main and set the default source file from there.
534         if (!m_source_manager.DefaultFileAndLineSet())
535         {
536             SymbolContextList sc_list;
537             uint32_t num_matches;
538             ConstString main_name("main");
539             bool symbols_okay = false;  // Force it to be a debug symbol.
540             bool append = false;
541             num_matches = executable_sp->FindFunctions (main_name, eFunctionNameTypeBase, symbols_okay, append, sc_list);
542             for (uint32_t idx = 0; idx < num_matches; idx++)
543             {
544                 SymbolContext sc;
545                 sc_list.GetContextAtIndex(idx, sc);
546                 if (sc.line_entry.file)
547                 {
548                     m_source_manager.SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line);
549                     break;
550                 }
551             }
552         }
553 
554         if (executable_objfile)
555         {
556             executable_objfile->GetDependentModules(dependent_files);
557             for (uint32_t i=0; i<dependent_files.GetSize(); i++)
558             {
559                 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
560                 FileSpec platform_dependent_file_spec;
561                 if (m_platform_sp)
562                     m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
563                 else
564                     platform_dependent_file_spec = dependent_file_spec;
565 
566                 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
567                                                           m_arch));
568                 if (image_module_sp.get())
569                 {
570                     ObjectFile *objfile = image_module_sp->GetObjectFile();
571                     if (objfile)
572                         objfile->GetDependentModules(dependent_files);
573                 }
574             }
575         }
576 
577     }
578 
579     UpdateInstanceName();
580 }
581 
582 
583 bool
584 Target::SetArchitecture (const ArchSpec &arch_spec)
585 {
586     if (m_arch == arch_spec)
587     {
588         // If we're setting the architecture to our current architecture, we
589         // don't need to do anything.
590         return true;
591     }
592     else if (!m_arch.IsValid())
593     {
594         // If we haven't got a valid arch spec, then we just need to set it.
595         m_arch = arch_spec;
596         return true;
597     }
598     else
599     {
600         // If we have an executable file, try to reset the executable to the desired architecture
601         m_arch = arch_spec;
602         ModuleSP executable_sp = GetExecutableModule ();
603         m_images.Clear();
604         m_scratch_ast_context_ap.reset();
605         // Need to do something about unsetting breakpoints.
606 
607         if (executable_sp)
608         {
609             FileSpec exec_file_spec = executable_sp->GetFileSpec();
610             Error error = ModuleList::GetSharedModule(exec_file_spec,
611                                                       arch_spec,
612                                                       NULL,
613                                                       NULL,
614                                                       0,
615                                                       executable_sp,
616                                                       NULL,
617                                                       NULL);
618 
619             if (!error.Fail() && executable_sp)
620             {
621                 SetExecutableModule (executable_sp, true);
622                 return true;
623             }
624             else
625             {
626                 return false;
627             }
628         }
629         else
630         {
631             return false;
632         }
633     }
634 }
635 
636 void
637 Target::ModuleAdded (ModuleSP &module_sp)
638 {
639     // A module is being added to this target for the first time
640     ModuleList module_list;
641     module_list.Append(module_sp);
642     ModulesDidLoad (module_list);
643 }
644 
645 void
646 Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
647 {
648     // A module is replacing an already added module
649     ModuleList module_list;
650     module_list.Append (old_module_sp);
651     ModulesDidUnload (module_list);
652     module_list.Clear ();
653     module_list.Append (new_module_sp);
654     ModulesDidLoad (module_list);
655 }
656 
657 void
658 Target::ModulesDidLoad (ModuleList &module_list)
659 {
660     m_breakpoint_list.UpdateBreakpoints (module_list, true);
661     // TODO: make event data that packages up the module_list
662     BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
663 }
664 
665 void
666 Target::ModulesDidUnload (ModuleList &module_list)
667 {
668     m_breakpoint_list.UpdateBreakpoints (module_list, false);
669 
670     // Remove the images from the target image list
671     m_images.Remove(module_list);
672 
673     // TODO: make event data that packages up the module_list
674     BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
675 }
676 
677 size_t
678 Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
679 {
680     const Section *section = addr.GetSection();
681     if (section && section->GetModule())
682     {
683         ObjectFile *objfile = section->GetModule()->GetObjectFile();
684         if (objfile)
685         {
686             size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
687                                                                         addr.GetOffset(),
688                                                                         dst,
689                                                                         dst_len);
690             if (bytes_read > 0)
691                 return bytes_read;
692             else
693                 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
694         }
695         else
696         {
697             error.SetErrorString("address isn't from a object file");
698         }
699     }
700     else
701     {
702         error.SetErrorString("address doesn't contain a section that points to a section in a object file");
703     }
704     return 0;
705 }
706 
707 size_t
708 Target::ReadMemory (const Address& addr,
709                     bool prefer_file_cache,
710                     void *dst,
711                     size_t dst_len,
712                     Error &error,
713                     lldb::addr_t *load_addr_ptr)
714 {
715     error.Clear();
716 
717     // if we end up reading this from process memory, we will fill this
718     // with the actual load address
719     if (load_addr_ptr)
720         *load_addr_ptr = LLDB_INVALID_ADDRESS;
721 
722     bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
723 
724     size_t bytes_read = 0;
725 
726     addr_t load_addr = LLDB_INVALID_ADDRESS;
727     addr_t file_addr = LLDB_INVALID_ADDRESS;
728     Address resolved_addr;
729     if (!addr.IsSectionOffset())
730     {
731         if (m_section_load_list.IsEmpty())
732         {
733             // No sections are loaded, so we must assume we are not running
734             // yet and anything we are given is a file address.
735             file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
736             m_images.ResolveFileAddress (file_addr, resolved_addr);
737         }
738         else
739         {
740             // We have at least one section loaded. This can be becuase
741             // we have manually loaded some sections with "target modules load ..."
742             // or because we have have a live process that has sections loaded
743             // through the dynamic loader
744             load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
745             m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
746         }
747     }
748     if (!resolved_addr.IsValid())
749         resolved_addr = addr;
750 
751 
752     if (prefer_file_cache)
753     {
754         bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
755         if (bytes_read > 0)
756             return bytes_read;
757     }
758 
759     if (process_is_valid)
760     {
761         if (load_addr == LLDB_INVALID_ADDRESS)
762             load_addr = resolved_addr.GetLoadAddress (this);
763 
764         if (load_addr == LLDB_INVALID_ADDRESS)
765         {
766             if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
767                 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
768                                                resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
769                                                resolved_addr.GetFileAddress());
770             else
771                 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
772         }
773         else
774         {
775             bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
776             if (bytes_read != dst_len)
777             {
778                 if (error.Success())
779                 {
780                     if (bytes_read == 0)
781                         error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
782                     else
783                         error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
784                 }
785             }
786             if (bytes_read)
787             {
788                 if (load_addr_ptr)
789                     *load_addr_ptr = load_addr;
790                 return bytes_read;
791             }
792             // If the address is not section offset we have an address that
793             // doesn't resolve to any address in any currently loaded shared
794             // libaries and we failed to read memory so there isn't anything
795             // more we can do. If it is section offset, we might be able to
796             // read cached memory from the object file.
797             if (!resolved_addr.IsSectionOffset())
798                 return 0;
799         }
800     }
801 
802     if (!prefer_file_cache && resolved_addr.IsSectionOffset())
803     {
804         // If we didn't already try and read from the object file cache, then
805         // try it after failing to read from the process.
806         return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
807     }
808     return 0;
809 }
810 
811 size_t
812 Target::ReadScalarIntegerFromMemory (const Address& addr,
813                                      bool prefer_file_cache,
814                                      uint32_t byte_size,
815                                      bool is_signed,
816                                      Scalar &scalar,
817                                      Error &error)
818 {
819     uint64_t uval;
820 
821     if (byte_size <= sizeof(uval))
822     {
823         size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
824         if (bytes_read == byte_size)
825         {
826             DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
827             uint32_t offset = 0;
828             if (byte_size <= 4)
829                 scalar = data.GetMaxU32 (&offset, byte_size);
830             else
831                 scalar = data.GetMaxU64 (&offset, byte_size);
832 
833             if (is_signed)
834                 scalar.SignExtend(byte_size * 8);
835             return bytes_read;
836         }
837     }
838     else
839     {
840         error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
841     }
842     return 0;
843 }
844 
845 uint64_t
846 Target::ReadUnsignedIntegerFromMemory (const Address& addr,
847                                        bool prefer_file_cache,
848                                        size_t integer_byte_size,
849                                        uint64_t fail_value,
850                                        Error &error)
851 {
852     Scalar scalar;
853     if (ReadScalarIntegerFromMemory (addr,
854                                      prefer_file_cache,
855                                      integer_byte_size,
856                                      false,
857                                      scalar,
858                                      error))
859         return scalar.ULongLong(fail_value);
860     return fail_value;
861 }
862 
863 bool
864 Target::ReadPointerFromMemory (const Address& addr,
865                                bool prefer_file_cache,
866                                Error &error,
867                                Address &pointer_addr)
868 {
869     Scalar scalar;
870     if (ReadScalarIntegerFromMemory (addr,
871                                      prefer_file_cache,
872                                      m_arch.GetAddressByteSize(),
873                                      false,
874                                      scalar,
875                                      error))
876     {
877         addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
878         if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
879         {
880             if (m_section_load_list.IsEmpty())
881             {
882                 // No sections are loaded, so we must assume we are not running
883                 // yet and anything we are given is a file address.
884                 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
885             }
886             else
887             {
888                 // We have at least one section loaded. This can be becuase
889                 // we have manually loaded some sections with "target modules load ..."
890                 // or because we have have a live process that has sections loaded
891                 // through the dynamic loader
892                 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
893             }
894             // We weren't able to resolve the pointer value, so just return
895             // an address with no section
896             if (!pointer_addr.IsValid())
897                 pointer_addr.SetOffset (pointer_vm_addr);
898             return true;
899 
900         }
901     }
902     return false;
903 }
904 
905 ModuleSP
906 Target::GetSharedModule
907 (
908     const FileSpec& file_spec,
909     const ArchSpec& arch,
910     const lldb_private::UUID *uuid_ptr,
911     const ConstString *object_name,
912     off_t object_offset,
913     Error *error_ptr
914 )
915 {
916     // Don't pass in the UUID so we can tell if we have a stale value in our list
917     ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
918     bool did_create_module = false;
919     ModuleSP module_sp;
920 
921     Error error;
922 
923     // If there are image search path entries, try to use them first to acquire a suitable image.
924     if (m_image_search_paths.GetSize())
925     {
926         FileSpec transformed_spec;
927         if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
928         {
929             transformed_spec.GetFilename() = file_spec.GetFilename();
930             error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
931         }
932     }
933 
934     // The platform is responsible for finding and caching an appropriate
935     // module in the shared module cache.
936     if (m_platform_sp)
937     {
938         FileSpec platform_file_spec;
939         error = m_platform_sp->GetSharedModule (file_spec,
940                                                 arch,
941                                                 uuid_ptr,
942                                                 object_name,
943                                                 object_offset,
944                                                 module_sp,
945                                                 &old_module_sp,
946                                                 &did_create_module);
947     }
948     else
949     {
950         error.SetErrorString("no platform is currently set");
951     }
952 
953     // If a module hasn't been found yet, use the unmodified path.
954     if (module_sp)
955     {
956         m_images.Append (module_sp);
957         if (did_create_module)
958         {
959             if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
960                 ModuleUpdated(old_module_sp, module_sp);
961             else
962                 ModuleAdded(module_sp);
963         }
964     }
965     if (error_ptr)
966         *error_ptr = error;
967     return module_sp;
968 }
969 
970 
971 Target *
972 Target::CalculateTarget ()
973 {
974     return this;
975 }
976 
977 Process *
978 Target::CalculateProcess ()
979 {
980     return NULL;
981 }
982 
983 Thread *
984 Target::CalculateThread ()
985 {
986     return NULL;
987 }
988 
989 StackFrame *
990 Target::CalculateStackFrame ()
991 {
992     return NULL;
993 }
994 
995 void
996 Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
997 {
998     exe_ctx.target = this;
999     exe_ctx.process = NULL; // Do NOT fill in process...
1000     exe_ctx.thread = NULL;
1001     exe_ctx.frame = NULL;
1002 }
1003 
1004 PathMappingList &
1005 Target::GetImageSearchPathList ()
1006 {
1007     return m_image_search_paths;
1008 }
1009 
1010 void
1011 Target::ImageSearchPathsChanged
1012 (
1013     const PathMappingList &path_list,
1014     void *baton
1015 )
1016 {
1017     Target *target = (Target *)baton;
1018     ModuleSP exe_module_sp (target->GetExecutableModule());
1019     if (exe_module_sp)
1020     {
1021         target->m_images.Clear();
1022         target->SetExecutableModule (exe_module_sp, true);
1023     }
1024 }
1025 
1026 ClangASTContext *
1027 Target::GetScratchClangASTContext()
1028 {
1029     // Now see if we know the target triple, and if so, create our scratch AST context:
1030     if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
1031         m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
1032     return m_scratch_ast_context_ap.get();
1033 }
1034 
1035 void
1036 Target::SettingsInitialize ()
1037 {
1038     UserSettingsControllerSP &usc = GetSettingsController();
1039     usc.reset (new SettingsController);
1040     UserSettingsController::InitializeSettingsController (usc,
1041                                                           SettingsController::global_settings_table,
1042                                                           SettingsController::instance_settings_table);
1043 
1044     // Now call SettingsInitialize() on each 'child' setting of Target
1045     Process::SettingsInitialize ();
1046 }
1047 
1048 void
1049 Target::SettingsTerminate ()
1050 {
1051 
1052     // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1053 
1054     Process::SettingsTerminate ();
1055 
1056     // Now terminate Target Settings.
1057 
1058     UserSettingsControllerSP &usc = GetSettingsController();
1059     UserSettingsController::FinalizeSettingsController (usc);
1060     usc.reset();
1061 }
1062 
1063 UserSettingsControllerSP &
1064 Target::GetSettingsController ()
1065 {
1066     static UserSettingsControllerSP g_settings_controller;
1067     return g_settings_controller;
1068 }
1069 
1070 ArchSpec
1071 Target::GetDefaultArchitecture ()
1072 {
1073     lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1074 
1075     if (settings_controller_sp)
1076         return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1077     return ArchSpec();
1078 }
1079 
1080 void
1081 Target::SetDefaultArchitecture (const ArchSpec& arch)
1082 {
1083     lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1084 
1085     if (settings_controller_sp)
1086         static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
1087 }
1088 
1089 Target *
1090 Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1091 {
1092     // The target can either exist in the "process" of ExecutionContext, or in
1093     // the "target_sp" member of SymbolContext. This accessor helper function
1094     // will get the target from one of these locations.
1095 
1096     Target *target = NULL;
1097     if (sc_ptr != NULL)
1098         target = sc_ptr->target_sp.get();
1099     if (target == NULL)
1100     {
1101         if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
1102             target = &exe_ctx_ptr->process->GetTarget();
1103     }
1104     return target;
1105 }
1106 
1107 
1108 void
1109 Target::UpdateInstanceName ()
1110 {
1111     StreamString sstr;
1112 
1113     Module *exe_module = GetExecutableModulePointer();
1114     if (exe_module)
1115     {
1116         sstr.Printf ("%s_%s",
1117                      exe_module->GetFileSpec().GetFilename().AsCString(),
1118                      exe_module->GetArchitecture().GetArchitectureName());
1119         GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
1120     }
1121 }
1122 
1123 const char *
1124 Target::GetExpressionPrefixContentsAsCString ()
1125 {
1126     if (m_expr_prefix_contents_sp)
1127         return (const char *)m_expr_prefix_contents_sp->GetBytes();
1128     return NULL;
1129 }
1130 
1131 ExecutionResults
1132 Target::EvaluateExpression
1133 (
1134     const char *expr_cstr,
1135     StackFrame *frame,
1136     lldb_private::ExecutionPolicy execution_policy,
1137     bool unwind_on_error,
1138     bool keep_in_memory,
1139     lldb::DynamicValueType use_dynamic,
1140     lldb::ValueObjectSP &result_valobj_sp
1141 )
1142 {
1143     ExecutionResults execution_results = eExecutionSetupError;
1144 
1145     result_valobj_sp.reset();
1146 
1147     // We shouldn't run stop hooks in expressions.
1148     // Be sure to reset this if you return anywhere within this function.
1149     bool old_suppress_value = m_suppress_stop_hooks;
1150     m_suppress_stop_hooks = true;
1151 
1152     ExecutionContext exe_ctx;
1153     if (frame)
1154     {
1155         frame->CalculateExecutionContext(exe_ctx);
1156         Error error;
1157         const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
1158                                            StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1159                                            StackFrame::eExpressionPathOptionsNoSyntheticChildren;
1160         lldb::VariableSP var_sp;
1161         result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1162                                                                      use_dynamic,
1163                                                                      expr_path_options,
1164                                                                      var_sp,
1165                                                                      error);
1166     }
1167     else if (m_process_sp)
1168     {
1169         m_process_sp->CalculateExecutionContext(exe_ctx);
1170     }
1171     else
1172     {
1173         CalculateExecutionContext(exe_ctx);
1174     }
1175 
1176     if (result_valobj_sp)
1177     {
1178         execution_results = eExecutionCompleted;
1179         // We got a result from the frame variable expression path above...
1180         ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1181 
1182         lldb::ValueObjectSP const_valobj_sp;
1183 
1184         // Check in case our value is already a constant value
1185         if (result_valobj_sp->GetIsConstant())
1186         {
1187             const_valobj_sp = result_valobj_sp;
1188             const_valobj_sp->SetName (persistent_variable_name);
1189         }
1190         else
1191         {
1192             if (use_dynamic != lldb::eNoDynamicValues)
1193             {
1194                 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
1195                 if (dynamic_sp)
1196                     result_valobj_sp = dynamic_sp;
1197             }
1198 
1199             const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
1200         }
1201 
1202         lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1203 
1204         result_valobj_sp = const_valobj_sp;
1205 
1206         ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1207         assert (clang_expr_variable_sp.get());
1208 
1209         // Set flags and live data as appropriate
1210 
1211         const Value &result_value = live_valobj_sp->GetValue();
1212 
1213         switch (result_value.GetValueType())
1214         {
1215         case Value::eValueTypeHostAddress:
1216         case Value::eValueTypeFileAddress:
1217             // we don't do anything with these for now
1218             break;
1219         case Value::eValueTypeScalar:
1220             clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1221             clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1222             break;
1223         case Value::eValueTypeLoadAddress:
1224             clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1225             clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1226             break;
1227         }
1228     }
1229     else
1230     {
1231         // Make sure we aren't just trying to see the value of a persistent
1232         // variable (something like "$0")
1233         lldb::ClangExpressionVariableSP persistent_var_sp;
1234         // Only check for persistent variables the expression starts with a '$'
1235         if (expr_cstr[0] == '$')
1236             persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1237 
1238         if (persistent_var_sp)
1239         {
1240             result_valobj_sp = persistent_var_sp->GetValueObject ();
1241             execution_results = eExecutionCompleted;
1242         }
1243         else
1244         {
1245             const char *prefix = GetExpressionPrefixContentsAsCString();
1246 
1247             execution_results = ClangUserExpression::Evaluate (exe_ctx,
1248                                                                execution_policy,
1249                                                                unwind_on_error,
1250                                                                expr_cstr,
1251                                                                prefix,
1252                                                                result_valobj_sp);
1253         }
1254     }
1255 
1256     m_suppress_stop_hooks = old_suppress_value;
1257 
1258     return execution_results;
1259 }
1260 
1261 lldb::addr_t
1262 Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1263 {
1264     addr_t code_addr = load_addr;
1265     switch (m_arch.GetMachine())
1266     {
1267     case llvm::Triple::arm:
1268     case llvm::Triple::thumb:
1269         switch (addr_class)
1270         {
1271         case eAddressClassData:
1272         case eAddressClassDebug:
1273             return LLDB_INVALID_ADDRESS;
1274 
1275         case eAddressClassUnknown:
1276         case eAddressClassInvalid:
1277         case eAddressClassCode:
1278         case eAddressClassCodeAlternateISA:
1279         case eAddressClassRuntime:
1280             // Check if bit zero it no set?
1281             if ((code_addr & 1ull) == 0)
1282             {
1283                 // Bit zero isn't set, check if the address is a multiple of 2?
1284                 if (code_addr & 2ull)
1285                 {
1286                     // The address is a multiple of 2 so it must be thumb, set bit zero
1287                     code_addr |= 1ull;
1288                 }
1289                 else if (addr_class == eAddressClassCodeAlternateISA)
1290                 {
1291                     // We checked the address and the address claims to be the alternate ISA
1292                     // which means thumb, so set bit zero.
1293                     code_addr |= 1ull;
1294                 }
1295             }
1296             break;
1297         }
1298         break;
1299 
1300     default:
1301         break;
1302     }
1303     return code_addr;
1304 }
1305 
1306 lldb::addr_t
1307 Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1308 {
1309     addr_t opcode_addr = load_addr;
1310     switch (m_arch.GetMachine())
1311     {
1312     case llvm::Triple::arm:
1313     case llvm::Triple::thumb:
1314         switch (addr_class)
1315         {
1316         case eAddressClassData:
1317         case eAddressClassDebug:
1318             return LLDB_INVALID_ADDRESS;
1319 
1320         case eAddressClassInvalid:
1321         case eAddressClassUnknown:
1322         case eAddressClassCode:
1323         case eAddressClassCodeAlternateISA:
1324         case eAddressClassRuntime:
1325             opcode_addr &= ~(1ull);
1326             break;
1327         }
1328         break;
1329 
1330     default:
1331         break;
1332     }
1333     return opcode_addr;
1334 }
1335 
1336 lldb::user_id_t
1337 Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1338 {
1339     lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1340     new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1341     m_stop_hooks[new_uid] = new_hook_sp;
1342     return new_uid;
1343 }
1344 
1345 bool
1346 Target::RemoveStopHookByID (lldb::user_id_t user_id)
1347 {
1348     size_t num_removed;
1349     num_removed = m_stop_hooks.erase (user_id);
1350     if (num_removed == 0)
1351         return false;
1352     else
1353         return true;
1354 }
1355 
1356 void
1357 Target::RemoveAllStopHooks ()
1358 {
1359     m_stop_hooks.clear();
1360 }
1361 
1362 Target::StopHookSP
1363 Target::GetStopHookByID (lldb::user_id_t user_id)
1364 {
1365     StopHookSP found_hook;
1366 
1367     StopHookCollection::iterator specified_hook_iter;
1368     specified_hook_iter = m_stop_hooks.find (user_id);
1369     if (specified_hook_iter != m_stop_hooks.end())
1370         found_hook = (*specified_hook_iter).second;
1371     return found_hook;
1372 }
1373 
1374 bool
1375 Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1376 {
1377     StopHookCollection::iterator specified_hook_iter;
1378     specified_hook_iter = m_stop_hooks.find (user_id);
1379     if (specified_hook_iter == m_stop_hooks.end())
1380         return false;
1381 
1382     (*specified_hook_iter).second->SetIsActive (active_state);
1383     return true;
1384 }
1385 
1386 void
1387 Target::SetAllStopHooksActiveState (bool active_state)
1388 {
1389     StopHookCollection::iterator pos, end = m_stop_hooks.end();
1390     for (pos = m_stop_hooks.begin(); pos != end; pos++)
1391     {
1392         (*pos).second->SetIsActive (active_state);
1393     }
1394 }
1395 
1396 void
1397 Target::RunStopHooks ()
1398 {
1399     if (m_suppress_stop_hooks)
1400         return;
1401 
1402     if (!m_process_sp)
1403         return;
1404 
1405     if (m_stop_hooks.empty())
1406         return;
1407 
1408     StopHookCollection::iterator pos, end = m_stop_hooks.end();
1409 
1410     // If there aren't any active stop hooks, don't bother either:
1411     bool any_active_hooks = false;
1412     for (pos = m_stop_hooks.begin(); pos != end; pos++)
1413     {
1414         if ((*pos).second->IsActive())
1415         {
1416             any_active_hooks = true;
1417             break;
1418         }
1419     }
1420     if (!any_active_hooks)
1421         return;
1422 
1423     CommandReturnObject result;
1424 
1425     std::vector<ExecutionContext> exc_ctx_with_reasons;
1426     std::vector<SymbolContext> sym_ctx_with_reasons;
1427 
1428     ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1429     size_t num_threads = cur_threadlist.GetSize();
1430     for (size_t i = 0; i < num_threads; i++)
1431     {
1432         lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1433         if (cur_thread_sp->ThreadStoppedForAReason())
1434         {
1435             lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1436             exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1437             sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1438         }
1439     }
1440 
1441     // If no threads stopped for a reason, don't run the stop-hooks.
1442     size_t num_exe_ctx = exc_ctx_with_reasons.size();
1443     if (num_exe_ctx == 0)
1444         return;
1445 
1446     result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1447     result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
1448 
1449     bool keep_going = true;
1450     bool hooks_ran = false;
1451     bool print_hook_header;
1452     bool print_thread_header;
1453 
1454     if (num_exe_ctx == 1)
1455         print_thread_header = false;
1456     else
1457         print_thread_header = true;
1458 
1459     if (m_stop_hooks.size() == 1)
1460         print_hook_header = false;
1461     else
1462         print_hook_header = true;
1463 
1464     for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1465     {
1466         // result.Clear();
1467         StopHookSP cur_hook_sp = (*pos).second;
1468         if (!cur_hook_sp->IsActive())
1469             continue;
1470 
1471         bool any_thread_matched = false;
1472         for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1473         {
1474             if ((cur_hook_sp->GetSpecifier () == NULL
1475                   || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1476                 && (cur_hook_sp->GetThreadSpecifier() == NULL
1477                     || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread)))
1478             {
1479                 if (!hooks_ran)
1480                 {
1481                     result.AppendMessage("\n** Stop Hooks **");
1482                     hooks_ran = true;
1483                 }
1484                 if (print_hook_header && !any_thread_matched)
1485                 {
1486                     result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
1487                     any_thread_matched = true;
1488                 }
1489 
1490                 if (print_thread_header)
1491                     result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID());
1492 
1493                 bool stop_on_continue = true;
1494                 bool stop_on_error = true;
1495                 bool echo_commands = false;
1496                 bool print_results = true;
1497                 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
1498                                                                       &exc_ctx_with_reasons[i],
1499                                                                       stop_on_continue,
1500                                                                       stop_on_error,
1501                                                                       echo_commands,
1502                                                                       print_results,
1503                                                                       result);
1504 
1505                 // If the command started the target going again, we should bag out of
1506                 // running the stop hooks.
1507                 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1508                     (result.GetStatus() == eReturnStatusSuccessContinuingResult))
1509                 {
1510                     result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
1511                     keep_going = false;
1512                 }
1513             }
1514         }
1515     }
1516     if (hooks_ran)
1517         result.AppendMessage ("\n** End Stop Hooks **\n");
1518 
1519     result.GetImmediateOutputStream()->Flush();
1520     result.GetImmediateErrorStream()->Flush();
1521 }
1522 
1523 bool
1524 Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1525 {
1526     bool changed = false;
1527     if (module)
1528     {
1529         ObjectFile *object_file = module->GetObjectFile();
1530         if (object_file)
1531         {
1532             SectionList *section_list = object_file->GetSectionList ();
1533             if (section_list)
1534             {
1535                 // All sections listed in the dyld image info structure will all
1536                 // either be fixed up already, or they will all be off by a single
1537                 // slide amount that is determined by finding the first segment
1538                 // that is at file offset zero which also has bytes (a file size
1539                 // that is greater than zero) in the object file.
1540 
1541                 // Determine the slide amount (if any)
1542                 const size_t num_sections = section_list->GetSize();
1543                 size_t sect_idx = 0;
1544                 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1545                 {
1546                     // Iterate through the object file sections to find the
1547                     // first section that starts of file offset zero and that
1548                     // has bytes in the file...
1549                     Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1550                     if (section)
1551                     {
1552                         if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1553                             changed = true;
1554                     }
1555                 }
1556             }
1557         }
1558     }
1559     return changed;
1560 }
1561 
1562 
1563 //--------------------------------------------------------------
1564 // class Target::StopHook
1565 //--------------------------------------------------------------
1566 
1567 
1568 Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1569         UserID (uid),
1570         m_target_sp (target_sp),
1571         m_commands (),
1572         m_specifier_sp (),
1573         m_thread_spec_ap(NULL),
1574         m_active (true)
1575 {
1576 }
1577 
1578 Target::StopHook::StopHook (const StopHook &rhs) :
1579         UserID (rhs.GetID()),
1580         m_target_sp (rhs.m_target_sp),
1581         m_commands (rhs.m_commands),
1582         m_specifier_sp (rhs.m_specifier_sp),
1583         m_thread_spec_ap (NULL),
1584         m_active (rhs.m_active)
1585 {
1586     if (rhs.m_thread_spec_ap.get() != NULL)
1587         m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1588 }
1589 
1590 
1591 Target::StopHook::~StopHook ()
1592 {
1593 }
1594 
1595 void
1596 Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1597 {
1598     m_thread_spec_ap.reset (specifier);
1599 }
1600 
1601 
1602 void
1603 Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1604 {
1605     int indent_level = s->GetIndentLevel();
1606 
1607     s->SetIndentLevel(indent_level + 2);
1608 
1609     s->Printf ("Hook: %d\n", GetID());
1610     if (m_active)
1611         s->Indent ("State: enabled\n");
1612     else
1613         s->Indent ("State: disabled\n");
1614 
1615     if (m_specifier_sp)
1616     {
1617         s->Indent();
1618         s->PutCString ("Specifier:\n");
1619         s->SetIndentLevel (indent_level + 4);
1620         m_specifier_sp->GetDescription (s, level);
1621         s->SetIndentLevel (indent_level + 2);
1622     }
1623 
1624     if (m_thread_spec_ap.get() != NULL)
1625     {
1626         StreamString tmp;
1627         s->Indent("Thread:\n");
1628         m_thread_spec_ap->GetDescription (&tmp, level);
1629         s->SetIndentLevel (indent_level + 4);
1630         s->Indent (tmp.GetData());
1631         s->PutCString ("\n");
1632         s->SetIndentLevel (indent_level + 2);
1633     }
1634 
1635     s->Indent ("Commands: \n");
1636     s->SetIndentLevel (indent_level + 4);
1637     uint32_t num_commands = m_commands.GetSize();
1638     for (uint32_t i = 0; i < num_commands; i++)
1639     {
1640         s->Indent(m_commands.GetStringAtIndex(i));
1641         s->PutCString ("\n");
1642     }
1643     s->SetIndentLevel (indent_level);
1644 }
1645 
1646 
1647 //--------------------------------------------------------------
1648 // class Target::SettingsController
1649 //--------------------------------------------------------------
1650 
1651 Target::SettingsController::SettingsController () :
1652     UserSettingsController ("target", Debugger::GetSettingsController()),
1653     m_default_architecture ()
1654 {
1655     m_default_settings.reset (new TargetInstanceSettings (*this, false,
1656                                                           InstanceSettings::GetDefaultName().AsCString()));
1657 }
1658 
1659 Target::SettingsController::~SettingsController ()
1660 {
1661 }
1662 
1663 lldb::InstanceSettingsSP
1664 Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1665 {
1666     TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1667                                                                        false,
1668                                                                        instance_name);
1669     lldb::InstanceSettingsSP new_settings_sp (new_settings);
1670     return new_settings_sp;
1671 }
1672 
1673 
1674 #define TSC_DEFAULT_ARCH      "default-arch"
1675 #define TSC_EXPR_PREFIX       "expr-prefix"
1676 #define TSC_PREFER_DYNAMIC    "prefer-dynamic-value"
1677 #define TSC_SKIP_PROLOGUE     "skip-prologue"
1678 #define TSC_SOURCE_MAP        "source-map"
1679 #define TSC_MAX_CHILDREN      "max-children-count"
1680 #define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
1681 
1682 
1683 static const ConstString &
1684 GetSettingNameForDefaultArch ()
1685 {
1686     static ConstString g_const_string (TSC_DEFAULT_ARCH);
1687     return g_const_string;
1688 }
1689 
1690 static const ConstString &
1691 GetSettingNameForExpressionPrefix ()
1692 {
1693     static ConstString g_const_string (TSC_EXPR_PREFIX);
1694     return g_const_string;
1695 }
1696 
1697 static const ConstString &
1698 GetSettingNameForPreferDynamicValue ()
1699 {
1700     static ConstString g_const_string (TSC_PREFER_DYNAMIC);
1701     return g_const_string;
1702 }
1703 
1704 static const ConstString &
1705 GetSettingNameForSourcePathMap ()
1706 {
1707     static ConstString g_const_string (TSC_SOURCE_MAP);
1708     return g_const_string;
1709 }
1710 
1711 static const ConstString &
1712 GetSettingNameForSkipPrologue ()
1713 {
1714     static ConstString g_const_string (TSC_SKIP_PROLOGUE);
1715     return g_const_string;
1716 }
1717 
1718 static const ConstString &
1719 GetSettingNameForMaxChildren ()
1720 {
1721     static ConstString g_const_string (TSC_MAX_CHILDREN);
1722     return g_const_string;
1723 }
1724 
1725 static const ConstString &
1726 GetSettingNameForMaxStringSummaryLength ()
1727 {
1728     static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
1729     return g_const_string;
1730 }
1731 
1732 bool
1733 Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1734                                                const char *index_value,
1735                                                const char *value,
1736                                                const SettingEntry &entry,
1737                                                const VarSetOperationType op,
1738                                                Error&err)
1739 {
1740     if (var_name == GetSettingNameForDefaultArch())
1741     {
1742         m_default_architecture.SetTriple (value, NULL);
1743         if (!m_default_architecture.IsValid())
1744             err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
1745     }
1746     return true;
1747 }
1748 
1749 
1750 bool
1751 Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1752                                                StringList &value,
1753                                                Error &err)
1754 {
1755     if (var_name == GetSettingNameForDefaultArch())
1756     {
1757         // If the arch is invalid (the default), don't show a string for it
1758         if (m_default_architecture.IsValid())
1759             value.AppendString (m_default_architecture.GetArchitectureName());
1760         return true;
1761     }
1762     else
1763         err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1764 
1765     return false;
1766 }
1767 
1768 //--------------------------------------------------------------
1769 // class TargetInstanceSettings
1770 //--------------------------------------------------------------
1771 
1772 TargetInstanceSettings::TargetInstanceSettings
1773 (
1774     UserSettingsController &owner,
1775     bool live_instance,
1776     const char *name
1777 ) :
1778     InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
1779     m_expr_prefix_file (),
1780     m_expr_prefix_contents_sp (),
1781     m_prefer_dynamic_value (2),
1782     m_skip_prologue (true, true),
1783     m_source_map (NULL, NULL),
1784     m_max_children_display(256),
1785     m_max_strlen_length(1024)
1786 {
1787     // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1788     // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1789     // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1790     // This is true for CreateInstanceName() too.
1791 
1792     if (GetInstanceName () == InstanceSettings::InvalidName())
1793     {
1794         ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1795         m_owner.RegisterInstanceSettings (this);
1796     }
1797 
1798     if (live_instance)
1799     {
1800         const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1801         CopyInstanceSettings (pending_settings,false);
1802     }
1803 }
1804 
1805 TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
1806     InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
1807     m_expr_prefix_file (rhs.m_expr_prefix_file),
1808     m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
1809     m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
1810     m_skip_prologue (rhs.m_skip_prologue),
1811     m_source_map (rhs.m_source_map),
1812     m_max_children_display(rhs.m_max_children_display),
1813     m_max_strlen_length(rhs.m_max_strlen_length)
1814 {
1815     if (m_instance_name != InstanceSettings::GetDefaultName())
1816     {
1817         const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1818         CopyInstanceSettings (pending_settings,false);
1819     }
1820 }
1821 
1822 TargetInstanceSettings::~TargetInstanceSettings ()
1823 {
1824 }
1825 
1826 TargetInstanceSettings&
1827 TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1828 {
1829     if (this != &rhs)
1830     {
1831     }
1832 
1833     return *this;
1834 }
1835 
1836 void
1837 TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1838                                                         const char *index_value,
1839                                                         const char *value,
1840                                                         const ConstString &instance_name,
1841                                                         const SettingEntry &entry,
1842                                                         VarSetOperationType op,
1843                                                         Error &err,
1844                                                         bool pending)
1845 {
1846     if (var_name == GetSettingNameForExpressionPrefix ())
1847     {
1848         err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
1849         if (err.Success())
1850         {
1851             switch (op)
1852             {
1853             default:
1854                 break;
1855             case eVarSetOperationAssign:
1856             case eVarSetOperationAppend:
1857                 {
1858                     if (!m_expr_prefix_file.GetCurrentValue().Exists())
1859                     {
1860                         err.SetErrorToGenericError ();
1861                         err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1862                         return;
1863                     }
1864 
1865                     m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
1866 
1867                     if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
1868                     {
1869                         err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
1870                         m_expr_prefix_contents_sp.reset();
1871                     }
1872                 }
1873                 break;
1874             case eVarSetOperationClear:
1875                 m_expr_prefix_contents_sp.reset();
1876             }
1877         }
1878     }
1879     else if (var_name == GetSettingNameForPreferDynamicValue())
1880     {
1881         int new_value;
1882         UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
1883         if (err.Success())
1884             m_prefer_dynamic_value = new_value;
1885     }
1886     else if (var_name == GetSettingNameForSkipPrologue())
1887     {
1888         err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
1889     }
1890     else if (var_name == GetSettingNameForMaxChildren())
1891     {
1892         bool ok;
1893         uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
1894         if (ok)
1895             m_max_children_display = new_value;
1896     }
1897     else if (var_name == GetSettingNameForMaxStringSummaryLength())
1898     {
1899         bool ok;
1900         uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
1901         if (ok)
1902             m_max_strlen_length = new_value;
1903     }
1904     else if (var_name == GetSettingNameForSourcePathMap ())
1905     {
1906         switch (op)
1907         {
1908             case eVarSetOperationReplace:
1909             case eVarSetOperationInsertBefore:
1910             case eVarSetOperationInsertAfter:
1911             case eVarSetOperationRemove:
1912             default:
1913                 break;
1914             case eVarSetOperationAssign:
1915                 m_source_map.Clear(true);
1916                 // Fall through to append....
1917             case eVarSetOperationAppend:
1918                 {
1919                     Args args(value);
1920                     const uint32_t argc = args.GetArgumentCount();
1921                     if (argc & 1 || argc == 0)
1922                     {
1923                         err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
1924                     }
1925                     else
1926                     {
1927                         char resolved_new_path[PATH_MAX];
1928                         FileSpec file_spec;
1929                         const char *old_path;
1930                         for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
1931                         {
1932                             const char *new_path = args.GetArgumentAtIndex(idx+1);
1933                             assert (new_path); // We have an even number of paths, this shouldn't happen!
1934 
1935                             file_spec.SetFile(new_path, true);
1936                             if (file_spec.Exists())
1937                             {
1938                                 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
1939                                 {
1940                                     err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
1941                                     return;
1942                                 }
1943                             }
1944                             else
1945                             {
1946                                 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
1947                                 return;
1948                             }
1949                             m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
1950                         }
1951                     }
1952                 }
1953                 break;
1954 
1955             case eVarSetOperationClear:
1956                 m_source_map.Clear(true);
1957                 break;
1958         }
1959     }
1960 }
1961 
1962 void
1963 TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
1964 {
1965     TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1966 
1967     if (!new_settings_ptr)
1968         return;
1969 
1970     m_expr_prefix_file          = new_settings_ptr->m_expr_prefix_file;
1971     m_expr_prefix_contents_sp   = new_settings_ptr->m_expr_prefix_contents_sp;
1972     m_prefer_dynamic_value      = new_settings_ptr->m_prefer_dynamic_value;
1973     m_skip_prologue             = new_settings_ptr->m_skip_prologue;
1974     m_max_children_display      = new_settings_ptr->m_max_children_display;
1975     m_max_strlen_length         = new_settings_ptr->m_max_strlen_length;
1976 }
1977 
1978 bool
1979 TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1980                                                   const ConstString &var_name,
1981                                                   StringList &value,
1982                                                   Error *err)
1983 {
1984     if (var_name == GetSettingNameForExpressionPrefix ())
1985     {
1986         char path[PATH_MAX];
1987         const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
1988         if (path_len > 0)
1989             value.AppendString (path, path_len);
1990     }
1991     else if (var_name == GetSettingNameForPreferDynamicValue())
1992     {
1993         value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
1994     }
1995     else if (var_name == GetSettingNameForSkipPrologue())
1996     {
1997         if (m_skip_prologue)
1998             value.AppendString ("true");
1999         else
2000             value.AppendString ("false");
2001     }
2002     else if (var_name == GetSettingNameForSourcePathMap ())
2003     {
2004     }
2005     else if (var_name == GetSettingNameForMaxChildren())
2006     {
2007         StreamString count_str;
2008         count_str.Printf ("%d", m_max_children_display);
2009         value.AppendString (count_str.GetData());
2010     }
2011     else if (var_name == GetSettingNameForMaxStringSummaryLength())
2012     {
2013         StreamString count_str;
2014         count_str.Printf ("%d", m_max_strlen_length);
2015         value.AppendString (count_str.GetData());
2016     }
2017     else
2018     {
2019         if (err)
2020             err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2021         return false;
2022     }
2023 
2024     return true;
2025 }
2026 
2027 const ConstString
2028 TargetInstanceSettings::CreateInstanceName ()
2029 {
2030     StreamString sstr;
2031     static int instance_count = 1;
2032 
2033     sstr.Printf ("target_%d", instance_count);
2034     ++instance_count;
2035 
2036     const ConstString ret_val (sstr.GetData());
2037     return ret_val;
2038 }
2039 
2040 //--------------------------------------------------
2041 // Target::SettingsController Variable Tables
2042 //--------------------------------------------------
2043 OptionEnumValueElement
2044 TargetInstanceSettings::g_dynamic_value_types[] =
2045 {
2046 { eNoDynamicValues,      "no-dynamic-values", "Don't calculate the dynamic type of values"},
2047 { eDynamicCanRunTarget,  "run-target",        "Calculate the dynamic type of values even if you have to run the target."},
2048 { eDynamicDontRunTarget, "no-run-target",     "Calculate the dynamic type of values, but don't run the target."},
2049 { 0, NULL, NULL }
2050 };
2051 
2052 SettingEntry
2053 Target::SettingsController::global_settings_table[] =
2054 {
2055     // var-name           var-type           default      enum  init'd hidden help-text
2056     // =================  ================== ===========  ====  ====== ====== =========================================================================
2057     { TSC_DEFAULT_ARCH  , eSetVarTypeString , NULL      , NULL, false, false, "Default architecture to choose, when there's a choice." },
2058     { NULL              , eSetVarTypeNone   , NULL      , NULL, false, false, NULL }
2059 };
2060 
2061 SettingEntry
2062 Target::SettingsController::instance_settings_table[] =
2063 {
2064     // var-name             var-type            default         enum                    init'd hidden help-text
2065     // =================    ==================  =============== ======================= ====== ====== =========================================================================
2066     { TSC_EXPR_PREFIX       , eSetVarTypeString , NULL          , NULL,                  false, false, "Path to a file containing expressions to be prepended to all expressions." },
2067     { TSC_PREFER_DYNAMIC    , eSetVarTypeEnum   , NULL          , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2068     { TSC_SKIP_PROLOGUE     , eSetVarTypeBoolean, "true"        , NULL,                  false, false, "Skip function prologues when setting breakpoints by name." },
2069     { TSC_SOURCE_MAP        , eSetVarTypeArray  , NULL          , NULL,                  false, false, "Source path remappings to use when locating source files from debug information." },
2070     { TSC_MAX_CHILDREN      , eSetVarTypeInt    , "256"         , NULL,                  true,  false, "Maximum number of children to expand in any level of depth." },
2071     { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt    , "1024"        , NULL,                  true,  false, "Maximum number of characters to show when using %s in summary strings." },
2072     { NULL                  , eSetVarTypeNone   , NULL          , NULL,                  false, false, NULL }
2073 };
2074