blob: 6f5858a8acccb40aa53cb5c93c9c19adc99e1ebc [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/Target.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Breakpoint/BreakpointResolver.h"
17#include "lldb/Breakpoint/BreakpointResolverAddress.h"
18#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
19#include "lldb/Breakpoint/BreakpointResolverName.h"
Sean Callanan77e93942010-10-29 00:29:03 +000020#include "lldb/Core/DataBufferMemoryMap.h"
Greg Clayton427f2902010-12-14 02:59:59 +000021#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Event.h"
23#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000025#include "lldb/Core/Timer.h"
26#include "lldb/Core/ValueObject.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Host/Host.h"
28#include "lldb/lldb-private-log.h"
29#include "lldb/Symbol/ObjectFile.h"
30#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000031#include "lldb/Target/StackFrame.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032
33using namespace lldb;
34using namespace lldb_private;
35
36//----------------------------------------------------------------------
37// Target constructor
38//----------------------------------------------------------------------
Greg Clayton63094e02010-06-23 01:19:29 +000039Target::Target(Debugger &debugger) :
Greg Clayton49ce6822010-10-31 03:01:06 +000040 Broadcaster("lldb.target"),
Greg Claytonc0c1b0c2010-11-19 03:46:01 +000041 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton63094e02010-06-23 01:19:29 +000042 m_debugger (debugger),
Greg Claytonbdcda462010-12-20 20:49:23 +000043 m_mutex (Mutex::eMutexTypeRecursive),
Chris Lattner24943d22010-06-08 16:52:24 +000044 m_images(),
Greg Claytoneea26402010-09-14 23:36:40 +000045 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000046 m_breakpoint_list (false),
47 m_internal_breakpoint_list (true),
48 m_process_sp(),
49 m_triple(),
50 m_search_filter_sp(),
51 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000052 m_scratch_ast_context_ap (NULL),
53 m_persistent_variables ()
Chris Lattner24943d22010-06-08 16:52:24 +000054{
Greg Clayton49ce6822010-10-31 03:01:06 +000055 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
56 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
57 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
58
Greg Claytone005f2c2010-11-06 01:53:30 +000059 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000060 if (log)
61 log->Printf ("%p Target::Target()", this);
62}
63
64//----------------------------------------------------------------------
65// Destructor
66//----------------------------------------------------------------------
67Target::~Target()
68{
Greg Claytone005f2c2010-11-06 01:53:30 +000069 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000070 if (log)
71 log->Printf ("%p Target::~Target()", this);
72 DeleteCurrentProcess ();
73}
74
75void
Caroline Tice7826c882010-10-26 03:11:13 +000076Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +000077{
Greg Clayton3fed8b92010-10-08 00:21:05 +000078// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +000079 if (description_level != lldb::eDescriptionLevelBrief)
80 {
81 s->Indent();
82 s->PutCString("Target\n");
83 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000084 m_images.Dump(s);
85 m_breakpoint_list.Dump(s);
86 m_internal_breakpoint_list.Dump(s);
87 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +000088 }
89 else
90 {
Greg Claytona66ba462010-10-30 04:51:46 +000091 s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
Caroline Tice7826c882010-10-26 03:11:13 +000092 }
Chris Lattner24943d22010-06-08 16:52:24 +000093}
94
95void
96Target::DeleteCurrentProcess ()
97{
98 if (m_process_sp.get())
99 {
Greg Clayton49480b12010-09-14 23:52:43 +0000100 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000101 if (m_process_sp->IsAlive())
102 m_process_sp->Destroy();
103 else
104 m_process_sp->Finalize();
105
106 // Do any cleanup of the target we need to do between process instances.
107 // NB It is better to do this before destroying the process in case the
108 // clean up needs some help from the process.
109 m_breakpoint_list.ClearAllBreakpointSites();
110 m_internal_breakpoint_list.ClearAllBreakpointSites();
111 m_process_sp.reset();
112 }
113}
114
115const lldb::ProcessSP &
116Target::CreateProcess (Listener &listener, const char *plugin_name)
117{
118 DeleteCurrentProcess ();
119 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
120 return m_process_sp;
121}
122
123const lldb::ProcessSP &
124Target::GetProcessSP () const
125{
126 return m_process_sp;
127}
128
129lldb::TargetSP
130Target::GetSP()
131{
Greg Clayton63094e02010-06-23 01:19:29 +0000132 return m_debugger.GetTargetList().GetTargetSP(this);
Chris Lattner24943d22010-06-08 16:52:24 +0000133}
134
135BreakpointList &
136Target::GetBreakpointList(bool internal)
137{
138 if (internal)
139 return m_internal_breakpoint_list;
140 else
141 return m_breakpoint_list;
142}
143
144const BreakpointList &
145Target::GetBreakpointList(bool internal) const
146{
147 if (internal)
148 return m_internal_breakpoint_list;
149 else
150 return m_breakpoint_list;
151}
152
153BreakpointSP
154Target::GetBreakpointByID (break_id_t break_id)
155{
156 BreakpointSP bp_sp;
157
158 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
159 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
160 else
161 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
162
163 return bp_sp;
164}
165
166BreakpointSP
167Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
168{
169 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
170 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
171 return CreateBreakpoint (filter_sp, resolver_sp, internal);
172}
173
174
175BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000176Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000177{
Chris Lattner24943d22010-06-08 16:52:24 +0000178 Address so_addr;
179 // Attempt to resolve our load address if possible, though it is ok if
180 // it doesn't resolve to section/offset.
181
Greg Clayton33ed1702010-08-24 00:45:41 +0000182 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000183 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000184 if (!so_addr.IsValid())
185 {
186 // The address didn't resolve, so just set this as an absolute address
187 so_addr.SetOffset (addr);
188 }
189 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000190 return bp_sp;
191}
192
193BreakpointSP
194Target::CreateBreakpoint (Address &addr, bool internal)
195{
196 TargetSP target_sp = this->GetSP();
197 SearchFilterSP filter_sp(new SearchFilter (target_sp));
198 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
199 return CreateBreakpoint (filter_sp, resolver_sp, internal);
200}
201
202BreakpointSP
Greg Clayton12bec712010-06-28 21:30:43 +0000203Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000204{
Greg Clayton12bec712010-06-28 21:30:43 +0000205 BreakpointSP bp_sp;
206 if (func_name)
207 {
208 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
209 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact));
210 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
211 }
212 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000213}
214
215
216SearchFilterSP
217Target::GetSearchFilterForModule (const FileSpec *containingModule)
218{
219 SearchFilterSP filter_sp;
220 lldb::TargetSP target_sp = this->GetSP();
221 if (containingModule != NULL)
222 {
223 // TODO: We should look into sharing module based search filters
224 // across many breakpoints like we do for the simple target based one
225 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
226 }
227 else
228 {
229 if (m_search_filter_sp.get() == NULL)
230 m_search_filter_sp.reset (new SearchFilter (target_sp));
231 filter_sp = m_search_filter_sp;
232 }
233 return filter_sp;
234}
235
236BreakpointSP
237Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal)
238{
239 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
240 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex));
241
242 return CreateBreakpoint (filter_sp, resolver_sp, internal);
243}
244
245BreakpointSP
246Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
247{
248 BreakpointSP bp_sp;
249 if (filter_sp && resolver_sp)
250 {
251 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
252 resolver_sp->SetBreakpoint (bp_sp.get());
253
254 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000255 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000256 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000257 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000258
Greg Claytone005f2c2010-11-06 01:53:30 +0000259 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000260 if (log)
261 {
262 StreamString s;
263 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
264 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
265 }
266
Chris Lattner24943d22010-06-08 16:52:24 +0000267 bp_sp->ResolveBreakpoint();
268 }
Jim Inghamd1686902010-10-14 23:45:03 +0000269
270 if (!internal && bp_sp)
271 {
272 m_last_created_breakpoint = bp_sp;
273 }
274
Chris Lattner24943d22010-06-08 16:52:24 +0000275 return bp_sp;
276}
277
278void
279Target::RemoveAllBreakpoints (bool internal_also)
280{
Greg Claytone005f2c2010-11-06 01:53:30 +0000281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000282 if (log)
283 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
284
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000285 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000286 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000287 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000288
289 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000290}
291
292void
293Target::DisableAllBreakpoints (bool internal_also)
294{
Greg Claytone005f2c2010-11-06 01:53:30 +0000295 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000296 if (log)
297 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
298
299 m_breakpoint_list.SetEnabledAll (false);
300 if (internal_also)
301 m_internal_breakpoint_list.SetEnabledAll (false);
302}
303
304void
305Target::EnableAllBreakpoints (bool internal_also)
306{
Greg Claytone005f2c2010-11-06 01:53:30 +0000307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000308 if (log)
309 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
310
311 m_breakpoint_list.SetEnabledAll (true);
312 if (internal_also)
313 m_internal_breakpoint_list.SetEnabledAll (true);
314}
315
316bool
317Target::RemoveBreakpointByID (break_id_t break_id)
318{
Greg Claytone005f2c2010-11-06 01:53:30 +0000319 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000320 if (log)
321 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
322
323 if (DisableBreakpointByID (break_id))
324 {
325 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000326 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000327 else
Jim Inghamd1686902010-10-14 23:45:03 +0000328 {
329 if (m_last_created_breakpoint->GetID() == break_id)
330 m_last_created_breakpoint.reset();
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000331 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000332 }
Chris Lattner24943d22010-06-08 16:52:24 +0000333 return true;
334 }
335 return false;
336}
337
338bool
339Target::DisableBreakpointByID (break_id_t break_id)
340{
Greg Claytone005f2c2010-11-06 01:53:30 +0000341 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000342 if (log)
343 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
344
345 BreakpointSP bp_sp;
346
347 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
348 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
349 else
350 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
351 if (bp_sp)
352 {
353 bp_sp->SetEnabled (false);
354 return true;
355 }
356 return false;
357}
358
359bool
360Target::EnableBreakpointByID (break_id_t break_id)
361{
Greg Claytone005f2c2010-11-06 01:53:30 +0000362 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000363 if (log)
364 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
365 __FUNCTION__,
366 break_id,
367 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
368
369 BreakpointSP bp_sp;
370
371 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
372 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
373 else
374 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
375
376 if (bp_sp)
377 {
378 bp_sp->SetEnabled (true);
379 return true;
380 }
381 return false;
382}
383
384ModuleSP
385Target::GetExecutableModule ()
386{
387 ModuleSP executable_sp;
388 if (m_images.GetSize() > 0)
389 executable_sp = m_images.GetModuleAtIndex(0);
390 return executable_sp;
391}
392
393void
394Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
395{
396 m_images.Clear();
397 m_scratch_ast_context_ap.reset();
398
399 if (executable_sp.get())
400 {
401 Timer scoped_timer (__PRETTY_FUNCTION__,
402 "Target::SetExecutableModule (executable = '%s/%s')",
403 executable_sp->GetFileSpec().GetDirectory().AsCString(),
404 executable_sp->GetFileSpec().GetFilename().AsCString());
405
406 m_images.Append(executable_sp); // The first image is our exectuable file
407
408 ArchSpec exe_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000409 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
410 if (!m_arch_spec.IsValid())
411 m_arch_spec = exe_arch;
412
Chris Lattner24943d22010-06-08 16:52:24 +0000413 FileSpecList dependent_files;
414 ObjectFile * executable_objfile = executable_sp->GetObjectFile();
415 if (executable_objfile == NULL)
416 {
417
418 FileSpec bundle_executable(executable_sp->GetFileSpec());
Greg Clayton24b48ff2010-10-17 22:03:32 +0000419 if (Host::ResolveExecutableInBundle (bundle_executable))
Chris Lattner24943d22010-06-08 16:52:24 +0000420 {
421 ModuleSP bundle_exe_module_sp(GetSharedModule(bundle_executable,
422 exe_arch));
423 SetExecutableModule (bundle_exe_module_sp, get_dependent_files);
424 if (bundle_exe_module_sp->GetObjectFile() != NULL)
425 executable_sp = bundle_exe_module_sp;
426 return;
427 }
428 }
429
430 if (executable_objfile)
431 {
432 executable_objfile->GetDependentModules(dependent_files);
433 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
434 {
435 ModuleSP image_module_sp(GetSharedModule(dependent_files.GetFileSpecPointerAtIndex(i),
436 exe_arch));
437 if (image_module_sp.get())
438 {
439 //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY
440 ObjectFile *objfile = image_module_sp->GetObjectFile();
441 if (objfile)
442 objfile->GetDependentModules(dependent_files);
443 }
444 }
445 }
446
447 // Now see if we know the target triple, and if so, create our scratch AST context:
448 ConstString target_triple;
449 if (GetTargetTriple(target_triple))
450 {
451 m_scratch_ast_context_ap.reset (new ClangASTContext(target_triple.GetCString()));
452 }
453 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000454
455 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000456}
457
458
459ModuleList&
460Target::GetImages ()
461{
462 return m_images;
463}
464
465ArchSpec
466Target::GetArchitecture () const
467{
Jim Ingham7508e732010-08-09 23:31:02 +0000468 return m_arch_spec;
Chris Lattner24943d22010-06-08 16:52:24 +0000469}
470
Jim Ingham7508e732010-08-09 23:31:02 +0000471bool
472Target::SetArchitecture (const ArchSpec &arch_spec)
473{
474 if (m_arch_spec == arch_spec)
475 {
476 // If we're setting the architecture to our current architecture, we
477 // don't need to do anything.
478 return true;
479 }
480 else if (!m_arch_spec.IsValid())
481 {
482 // If we haven't got a valid arch spec, then we just need to set it.
483 m_arch_spec = arch_spec;
484 return true;
485 }
486 else
487 {
488 // If we have an executable file, try to reset the executable to the desired architecture
489 m_arch_spec = arch_spec;
490 ModuleSP executable_sp = GetExecutableModule ();
491 m_images.Clear();
492 m_scratch_ast_context_ap.reset();
493 m_triple.Clear();
494 // Need to do something about unsetting breakpoints.
495
496 if (executable_sp)
497 {
498 FileSpec exec_file_spec = executable_sp->GetFileSpec();
499 Error error = ModuleList::GetSharedModule(exec_file_spec,
500 arch_spec,
501 NULL,
502 NULL,
503 0,
504 executable_sp,
505 NULL,
506 NULL);
507
508 if (!error.Fail() && executable_sp)
509 {
510 SetExecutableModule (executable_sp, true);
511 return true;
512 }
513 else
514 {
515 return false;
516 }
517 }
518 else
519 {
520 return false;
521 }
522 }
523}
Chris Lattner24943d22010-06-08 16:52:24 +0000524
525bool
526Target::GetTargetTriple(ConstString &triple)
527{
528 triple.Clear();
529
530 if (m_triple)
531 {
532 triple = m_triple;
533 }
534 else
535 {
536 Module *exe_module = GetExecutableModule().get();
537 if (exe_module)
538 {
539 ObjectFile *objfile = exe_module->GetObjectFile();
540 if (objfile)
541 {
542 objfile->GetTargetTriple(m_triple);
543 triple = m_triple;
544 }
545 }
546 }
547 return !triple.IsEmpty();
548}
549
550void
551Target::ModuleAdded (ModuleSP &module_sp)
552{
553 // A module is being added to this target for the first time
554 ModuleList module_list;
555 module_list.Append(module_sp);
556 ModulesDidLoad (module_list);
557}
558
559void
560Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
561{
562 // A module is being added to this target for the first time
563 ModuleList module_list;
564 module_list.Append (old_module_sp);
565 ModulesDidUnload (module_list);
566 module_list.Clear ();
567 module_list.Append (new_module_sp);
568 ModulesDidLoad (module_list);
569}
570
571void
572Target::ModulesDidLoad (ModuleList &module_list)
573{
574 m_breakpoint_list.UpdateBreakpoints (module_list, true);
575 // TODO: make event data that packages up the module_list
576 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
577}
578
579void
580Target::ModulesDidUnload (ModuleList &module_list)
581{
582 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000583
584 // Remove the images from the target image list
585 m_images.Remove(module_list);
586
Chris Lattner24943d22010-06-08 16:52:24 +0000587 // TODO: make event data that packages up the module_list
588 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
589}
590
591size_t
Greg Clayton26100dc2011-01-07 01:57:07 +0000592Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
593{
594 const Section *section = addr.GetSection();
595 if (section && section->GetModule())
596 {
597 ObjectFile *objfile = section->GetModule()->GetObjectFile();
598 if (objfile)
599 {
600 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
601 addr.GetOffset(),
602 dst,
603 dst_len);
604 if (bytes_read > 0)
605 return bytes_read;
606 else
607 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
608 }
609 else
610 {
611 error.SetErrorString("address isn't from a object file");
612 }
613 }
614 else
615 {
616 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
617 }
618 return 0;
619}
620
621size_t
622Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size_t dst_len, Error &error)
Chris Lattner24943d22010-06-08 16:52:24 +0000623{
Chris Lattner24943d22010-06-08 16:52:24 +0000624 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +0000625
Greg Clayton70436352010-06-30 23:03:03 +0000626 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
627
Greg Clayton26100dc2011-01-07 01:57:07 +0000628 size_t bytes_read = 0;
Greg Clayton70436352010-06-30 23:03:03 +0000629 Address resolved_addr(addr);
630 if (!resolved_addr.IsSectionOffset())
631 {
632 if (process_is_valid)
Chris Lattner24943d22010-06-08 16:52:24 +0000633 {
Greg Claytoneea26402010-09-14 23:36:40 +0000634 m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr);
Greg Clayton70436352010-06-30 23:03:03 +0000635 }
636 else
637 {
638 m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
639 }
640 }
641
Greg Clayton26100dc2011-01-07 01:57:07 +0000642 if (prefer_file_cache)
643 {
644 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
645 if (bytes_read > 0)
646 return bytes_read;
647 }
Greg Clayton70436352010-06-30 23:03:03 +0000648
649 if (process_is_valid)
650 {
Greg Claytoneea26402010-09-14 23:36:40 +0000651 lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this);
Greg Clayton70436352010-06-30 23:03:03 +0000652 if (load_addr == LLDB_INVALID_ADDRESS)
653 {
654 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
655 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
656 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
657 resolved_addr.GetFileAddress());
658 else
659 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
660 }
661 else
662 {
Greg Clayton26100dc2011-01-07 01:57:07 +0000663 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +0000664 if (bytes_read != dst_len)
665 {
666 if (error.Success())
667 {
668 if (bytes_read == 0)
Greg Clayton70436352010-06-30 23:03:03 +0000669 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000670 else
Greg Clayton70436352010-06-30 23:03:03 +0000671 error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000672 }
673 }
Greg Clayton70436352010-06-30 23:03:03 +0000674 if (bytes_read)
675 return bytes_read;
676 // If the address is not section offset we have an address that
677 // doesn't resolve to any address in any currently loaded shared
678 // libaries and we failed to read memory so there isn't anything
679 // more we can do. If it is section offset, we might be able to
680 // read cached memory from the object file.
681 if (!resolved_addr.IsSectionOffset())
682 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000683 }
Chris Lattner24943d22010-06-08 16:52:24 +0000684 }
Greg Clayton70436352010-06-30 23:03:03 +0000685
Greg Clayton26100dc2011-01-07 01:57:07 +0000686 if (!prefer_file_cache)
Greg Clayton70436352010-06-30 23:03:03 +0000687 {
Greg Clayton26100dc2011-01-07 01:57:07 +0000688 // If we didn't already try and read from the object file cache, then
689 // try it after failing to read from the process.
690 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +0000691 }
692 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000693}
694
695
696ModuleSP
697Target::GetSharedModule
698(
699 const FileSpec& file_spec,
700 const ArchSpec& arch,
701 const UUID *uuid_ptr,
702 const ConstString *object_name,
703 off_t object_offset,
704 Error *error_ptr
705)
706{
707 // Don't pass in the UUID so we can tell if we have a stale value in our list
708 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
709 bool did_create_module = false;
710 ModuleSP module_sp;
711
712 // If there are image search path entries, try to use them first to acquire a suitable image.
713
714 Error error;
715
716 if (m_image_search_paths.GetSize())
717 {
718 FileSpec transformed_spec;
719 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
720 {
721 transformed_spec.GetFilename() = file_spec.GetFilename();
722 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
723 }
724 }
725
726 // If a module hasn't been found yet, use the unmodified path.
727
728 if (!module_sp)
729 {
730 error = (ModuleList::GetSharedModule (file_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module));
731 }
732
733 if (module_sp)
734 {
735 m_images.Append (module_sp);
736 if (did_create_module)
737 {
738 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
739 ModuleUpdated(old_module_sp, module_sp);
740 else
741 ModuleAdded(module_sp);
742 }
743 }
744 if (error_ptr)
745 *error_ptr = error;
746 return module_sp;
747}
748
749
750Target *
751Target::CalculateTarget ()
752{
753 return this;
754}
755
756Process *
757Target::CalculateProcess ()
758{
759 return NULL;
760}
761
762Thread *
763Target::CalculateThread ()
764{
765 return NULL;
766}
767
768StackFrame *
769Target::CalculateStackFrame ()
770{
771 return NULL;
772}
773
774void
Greg Claytona830adb2010-10-04 01:05:56 +0000775Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000776{
777 exe_ctx.target = this;
778 exe_ctx.process = NULL; // Do NOT fill in process...
779 exe_ctx.thread = NULL;
780 exe_ctx.frame = NULL;
781}
782
783PathMappingList &
784Target::GetImageSearchPathList ()
785{
786 return m_image_search_paths;
787}
788
789void
790Target::ImageSearchPathsChanged
791(
792 const PathMappingList &path_list,
793 void *baton
794)
795{
796 Target *target = (Target *)baton;
797 if (target->m_images.GetSize() > 1)
798 {
799 ModuleSP exe_module_sp (target->GetExecutableModule());
800 if (exe_module_sp)
801 {
802 target->m_images.Clear();
803 target->SetExecutableModule (exe_module_sp, true);
804 }
805 }
806}
807
808ClangASTContext *
809Target::GetScratchClangASTContext()
810{
811 return m_scratch_ast_context_ap.get();
812}
Caroline Tice5bc8c972010-09-20 20:44:43 +0000813
Greg Clayton990de7b2010-11-18 23:32:35 +0000814void
815Target::Initialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +0000816{
Greg Clayton990de7b2010-11-18 23:32:35 +0000817 UserSettingsControllerSP &usc = GetSettingsController();
818 usc.reset (new SettingsController);
819 UserSettingsController::InitializeSettingsController (usc,
820 SettingsController::global_settings_table,
821 SettingsController::instance_settings_table);
822}
Caroline Tice5bc8c972010-09-20 20:44:43 +0000823
Greg Clayton990de7b2010-11-18 23:32:35 +0000824void
825Target::Terminate ()
826{
827 UserSettingsControllerSP &usc = GetSettingsController();
828 UserSettingsController::FinalizeSettingsController (usc);
829 usc.reset();
830}
Caroline Tice5bc8c972010-09-20 20:44:43 +0000831
Greg Clayton990de7b2010-11-18 23:32:35 +0000832UserSettingsControllerSP &
833Target::GetSettingsController ()
834{
835 static UserSettingsControllerSP g_settings_controller;
Caroline Tice5bc8c972010-09-20 20:44:43 +0000836 return g_settings_controller;
837}
838
839ArchSpec
840Target::GetDefaultArchitecture ()
841{
Greg Claytonc0c1b0c2010-11-19 03:46:01 +0000842 lldb::UserSettingsControllerSP &settings_controller = GetSettingsController();
Caroline Tice5bc8c972010-09-20 20:44:43 +0000843 lldb::SettableVariableType var_type;
844 Error err;
845 StringList result = settings_controller->GetVariable ("target.default-arch", var_type, "[]", err);
846
847 const char *default_name = "";
848 if (result.GetSize() == 1 && err.Success())
849 default_name = result.GetStringAtIndex (0);
850
851 ArchSpec default_arch (default_name);
852 return default_arch;
853}
854
855void
856Target::SetDefaultArchitecture (ArchSpec new_arch)
857{
858 if (new_arch.IsValid())
Greg Claytonc0c1b0c2010-11-19 03:46:01 +0000859 GetSettingsController ()->SetVariable ("target.default-arch",
860 new_arch.AsCString(),
861 lldb::eVarSetOperationAssign,
862 false,
863 "[]");
Caroline Tice5bc8c972010-09-20 20:44:43 +0000864}
865
Greg Claytona830adb2010-10-04 01:05:56 +0000866Target *
867Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
868{
869 // The target can either exist in the "process" of ExecutionContext, or in
870 // the "target_sp" member of SymbolContext. This accessor helper function
871 // will get the target from one of these locations.
872
873 Target *target = NULL;
874 if (sc_ptr != NULL)
875 target = sc_ptr->target_sp.get();
876 if (target == NULL)
877 {
878 if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
879 target = &exe_ctx_ptr->process->GetTarget();
880 }
881 return target;
882}
883
884
Caroline Tice1ebef442010-09-27 00:30:10 +0000885void
886Target::UpdateInstanceName ()
887{
888 StreamString sstr;
889
890 ModuleSP module_sp = GetExecutableModule();
891 if (module_sp)
892 {
Greg Claytonbf6e2102010-10-27 02:06:37 +0000893 sstr.Printf ("%s_%s",
894 module_sp->GetFileSpec().GetFilename().AsCString(),
Caroline Tice1ebef442010-09-27 00:30:10 +0000895 module_sp->GetArchitecture().AsCString());
Greg Claytonc0c1b0c2010-11-19 03:46:01 +0000896 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
897 sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +0000898 }
899}
900
Sean Callanan77e93942010-10-29 00:29:03 +0000901const char *
902Target::GetExpressionPrefixContentsAsCString ()
903{
904 return m_expr_prefix_contents.c_str();
905}
906
Greg Clayton427f2902010-12-14 02:59:59 +0000907ExecutionResults
908Target::EvaluateExpression
909(
910 const char *expr_cstr,
911 StackFrame *frame,
912 bool unwind_on_error,
913 lldb::ValueObjectSP &result_valobj_sp
914)
915{
916 ExecutionResults execution_results = eExecutionSetupError;
917
918 result_valobj_sp.reset();
919
920 ExecutionContext exe_ctx;
921 if (frame)
922 {
923 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000924 Error error;
925 const bool check_ptr_vs_member = true;
926 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, check_ptr_vs_member, error);
Greg Clayton427f2902010-12-14 02:59:59 +0000927 }
928 else if (m_process_sp)
929 {
930 m_process_sp->CalculateExecutionContext(exe_ctx);
931 }
932 else
933 {
934 CalculateExecutionContext(exe_ctx);
935 }
936
937 if (result_valobj_sp)
938 {
939 execution_results = eExecutionCompleted;
940 // We got a result from the frame variable expression path above...
941 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
942
943 lldb::ValueObjectSP const_valobj_sp;
944
945 // Check in case our value is already a constant value
946 if (result_valobj_sp->GetIsConstant())
947 {
948 const_valobj_sp = result_valobj_sp;
949 const_valobj_sp->SetName (persistent_variable_name);
950 }
951 else
952 const_valobj_sp = result_valobj_sp->CreateConstantValue (exe_ctx.GetBestExecutionContextScope(),
953 persistent_variable_name);
954
955 result_valobj_sp = const_valobj_sp;
956
957 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
958 assert (clang_expr_variable_sp.get());
959 }
960 else
961 {
962 // Make sure we aren't just trying to see the value of a persistent
963 // variable (something like "$0")
964 lldb::ClangExpressionVariableSP persistent_var_sp (m_persistent_variables.GetVariable (expr_cstr));
965 if (persistent_var_sp)
966 {
967 result_valobj_sp = persistent_var_sp->GetValueObject ();
968 execution_results = eExecutionCompleted;
969 }
970 else
971 {
972 const char *prefix = GetExpressionPrefixContentsAsCString();
973
974 execution_results = ClangUserExpression::Evaluate (exe_ctx,
975 unwind_on_error,
976 expr_cstr,
977 prefix,
978 result_valobj_sp);
979 }
980 }
981 return execution_results;
982}
983
Caroline Tice5bc8c972010-09-20 20:44:43 +0000984//--------------------------------------------------------------
985// class Target::SettingsController
986//--------------------------------------------------------------
987
988Target::SettingsController::SettingsController () :
989 UserSettingsController ("target", Debugger::GetSettingsController()),
990 m_default_architecture ()
991{
992 m_default_settings.reset (new TargetInstanceSettings (*this, false,
993 InstanceSettings::GetDefaultName().AsCString()));
994}
995
996Target::SettingsController::~SettingsController ()
997{
998}
999
1000lldb::InstanceSettingsSP
1001Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1002{
Greg Claytonc0c1b0c2010-11-19 03:46:01 +00001003 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1004 false,
1005 instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001006 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1007 return new_settings_sp;
1008}
1009
1010const ConstString &
1011Target::SettingsController::DefArchVarName ()
1012{
1013 static ConstString def_arch_var_name ("default-arch");
1014
1015 return def_arch_var_name;
1016}
1017
1018bool
1019Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1020 const char *index_value,
1021 const char *value,
1022 const SettingEntry &entry,
1023 const lldb::VarSetOperationType op,
1024 Error&err)
1025{
1026 if (var_name == DefArchVarName())
1027 {
1028 ArchSpec tmp_spec (value);
1029 if (tmp_spec.IsValid())
1030 m_default_architecture = tmp_spec;
1031 else
1032 err.SetErrorStringWithFormat ("'%s' is not a valid architecture.", value);
1033 }
1034 return true;
1035}
1036
1037
1038bool
1039Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1040 StringList &value,
1041 Error &err)
1042{
1043 if (var_name == DefArchVarName())
1044 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001045 // If the arch is invalid (the default), don't show a string for it
1046 if (m_default_architecture.IsValid())
1047 value.AppendString (m_default_architecture.AsCString());
Caroline Tice5bc8c972010-09-20 20:44:43 +00001048 return true;
1049 }
1050 else
1051 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1052
1053 return false;
1054}
1055
1056//--------------------------------------------------------------
1057// class TargetInstanceSettings
1058//--------------------------------------------------------------
1059
Greg Clayton638351a2010-12-04 00:10:17 +00001060TargetInstanceSettings::TargetInstanceSettings
1061(
1062 UserSettingsController &owner,
1063 bool live_instance,
1064 const char *name
1065) :
1066 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001067{
1068 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1069 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1070 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1071 // This is true for CreateInstanceName() too.
1072
1073 if (GetInstanceName () == InstanceSettings::InvalidName())
1074 {
1075 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1076 m_owner.RegisterInstanceSettings (this);
1077 }
1078
1079 if (live_instance)
1080 {
1081 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1082 CopyInstanceSettings (pending_settings,false);
1083 //m_owner.RemovePendingSettings (m_instance_name);
1084 }
1085}
1086
1087TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Claytonc0c1b0c2010-11-19 03:46:01 +00001088 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString())
Caroline Tice5bc8c972010-09-20 20:44:43 +00001089{
1090 if (m_instance_name != InstanceSettings::GetDefaultName())
1091 {
1092 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1093 CopyInstanceSettings (pending_settings,false);
1094 //m_owner.RemovePendingSettings (m_instance_name);
1095 }
1096}
1097
1098TargetInstanceSettings::~TargetInstanceSettings ()
1099{
1100}
1101
1102TargetInstanceSettings&
1103TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1104{
1105 if (this != &rhs)
1106 {
1107 }
1108
1109 return *this;
1110}
1111
Sean Callanan77e93942010-10-29 00:29:03 +00001112#define EXPR_PREFIX_STRING "expr-prefix"
Caroline Tice5bc8c972010-09-20 20:44:43 +00001113
1114void
1115TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1116 const char *index_value,
1117 const char *value,
1118 const ConstString &instance_name,
1119 const SettingEntry &entry,
1120 lldb::VarSetOperationType op,
1121 Error &err,
1122 bool pending)
1123{
Sean Callanan77e93942010-10-29 00:29:03 +00001124 static ConstString expr_prefix_str (EXPR_PREFIX_STRING);
1125
1126 if (var_name == expr_prefix_str)
1127 {
1128 switch (op)
1129 {
1130 default:
1131 err.SetErrorToGenericError ();
1132 err.SetErrorString ("Unrecognized operation. Cannot update value.\n");
1133 return;
1134 case lldb::eVarSetOperationAssign:
1135 {
1136 FileSpec file_spec(value, true);
1137
1138 if (!file_spec.Exists())
1139 {
1140 err.SetErrorToGenericError ();
1141 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1142 return;
1143 }
1144
1145 DataBufferMemoryMap buf;
1146
1147 if (!buf.MemoryMapFromFileSpec(&file_spec) &&
1148 buf.GetError().Fail())
1149 {
1150 err.SetErrorToGenericError ();
1151 err.SetErrorStringWithFormat ("Couldn't read from %s: %s\n", value, buf.GetError().AsCString());
1152 return;
1153 }
1154
1155 m_expr_prefix_path = value;
1156 m_expr_prefix_contents.assign(reinterpret_cast<const char *>(buf.GetBytes()), buf.GetByteSize());
1157 }
1158 return;
1159 case lldb::eVarSetOperationAppend:
1160 err.SetErrorToGenericError ();
1161 err.SetErrorString ("Cannot append to a path.\n");
1162 return;
1163 case lldb::eVarSetOperationClear:
1164 m_expr_prefix_path.clear ();
1165 m_expr_prefix_contents.clear ();
1166 return;
1167 }
1168 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00001169}
1170
1171void
1172TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
Sean Callanan77e93942010-10-29 00:29:03 +00001173 bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001174{
Sean Callanan77e93942010-10-29 00:29:03 +00001175 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1176
1177 if (!new_settings_ptr)
1178 return;
1179
1180 m_expr_prefix_path = new_settings_ptr->m_expr_prefix_path;
1181 m_expr_prefix_contents = new_settings_ptr->m_expr_prefix_contents;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001182}
1183
Caroline Ticebcb5b452010-09-20 21:37:42 +00001184bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00001185TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1186 const ConstString &var_name,
1187 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00001188 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001189{
Sean Callanan77e93942010-10-29 00:29:03 +00001190 static ConstString expr_prefix_str (EXPR_PREFIX_STRING);
1191
1192 if (var_name == expr_prefix_str)
1193 {
1194 value.AppendString (m_expr_prefix_path.c_str(), m_expr_prefix_path.size());
1195 }
1196 else
1197 {
1198 if (err)
1199 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1200 return false;
1201 }
1202
1203 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001204}
1205
1206const ConstString
1207TargetInstanceSettings::CreateInstanceName ()
1208{
Caroline Tice5bc8c972010-09-20 20:44:43 +00001209 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00001210 static int instance_count = 1;
1211
Caroline Tice5bc8c972010-09-20 20:44:43 +00001212 sstr.Printf ("target_%d", instance_count);
1213 ++instance_count;
1214
1215 const ConstString ret_val (sstr.GetData());
1216 return ret_val;
1217}
1218
1219//--------------------------------------------------
1220// Target::SettingsController Variable Tables
1221//--------------------------------------------------
1222
1223SettingEntry
1224Target::SettingsController::global_settings_table[] =
1225{
Sean Callanan77e93942010-10-29 00:29:03 +00001226 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1227 { "default-arch", eSetVarTypeString, NULL, NULL, false, false, "Default architecture to choose, when there's a choice." },
Caroline Tice5bc8c972010-09-20 20:44:43 +00001228 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1229};
1230
1231SettingEntry
1232Target::SettingsController::instance_settings_table[] =
1233{
Sean Callanan77e93942010-10-29 00:29:03 +00001234 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1235 { EXPR_PREFIX_STRING, eSetVarTypeString, NULL, NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
Caroline Tice5bc8c972010-09-20 20:44:43 +00001236 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1237};