blob: 3cd43e1590968fd24d92005767a8ab81216cb75a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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 Callanan322f5292010-10-29 00:29:0320#include "lldb/Core/DataBufferMemoryMap.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5921#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2422#include "lldb/Core/Event.h"
23#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:2424#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5925#include "lldb/Core/Timer.h"
26#include "lldb/Core/ValueObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:2427#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 Clayton8b2fe6d2010-12-14 02:59:5931#include "lldb/Target/StackFrame.h"
Chris Lattner30fdc8d2010-06-08 16:52:2432
33using namespace lldb;
34using namespace lldb_private;
35
36//----------------------------------------------------------------------
37// Target constructor
38//----------------------------------------------------------------------
Greg Clayton66111032010-06-23 01:19:2939Target::Target(Debugger &debugger) :
Greg Claytoncfd1ace2010-10-31 03:01:0640 Broadcaster("lldb.target"),
Greg Claytondbe54502010-11-19 03:46:0141 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton66111032010-06-23 01:19:2942 m_debugger (debugger),
Greg Claytonaf67cec2010-12-20 20:49:2343 m_mutex (Mutex::eMutexTypeRecursive),
Chris Lattner30fdc8d2010-06-08 16:52:2444 m_images(),
Greg Claytonf5e56de2010-09-14 23:36:4045 m_section_load_list (),
Chris Lattner30fdc8d2010-06-08 16:52:2446 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 Clayton8b2fe6d2010-12-14 02:59:5952 m_scratch_ast_context_ap (NULL),
53 m_persistent_variables ()
Chris Lattner30fdc8d2010-06-08 16:52:2454{
Greg Claytoncfd1ace2010-10-31 03:01:0655 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
56 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
57 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
58
Greg Clayton2d4edfb2010-11-06 01:53:3059 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2460 if (log)
61 log->Printf ("%p Target::Target()", this);
62}
63
64//----------------------------------------------------------------------
65// Destructor
66//----------------------------------------------------------------------
67Target::~Target()
68{
Greg Clayton2d4edfb2010-11-06 01:53:3069 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2470 if (log)
71 log->Printf ("%p Target::~Target()", this);
72 DeleteCurrentProcess ();
73}
74
75void
Caroline Ticeceb6b132010-10-26 03:11:1376Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:2477{
Greg Clayton89411422010-10-08 00:21:0578// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:1379 if (description_level != lldb::eDescriptionLevelBrief)
80 {
81 s->Indent();
82 s->PutCString("Target\n");
83 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:3584 m_images.Dump(s);
85 m_breakpoint_list.Dump(s);
86 m_internal_breakpoint_list.Dump(s);
87 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:1388 }
89 else
90 {
Greg Clayton48381312010-10-30 04:51:4691 s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
Caroline Ticeceb6b132010-10-26 03:11:1392 }
Chris Lattner30fdc8d2010-06-08 16:52:2493}
94
95void
96Target::DeleteCurrentProcess ()
97{
98 if (m_process_sp.get())
99 {
Greg Clayton17f69202010-09-14 23:52:43100 m_section_load_list.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24101 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 Clayton66111032010-06-23 01:19:29132 return m_debugger.GetTargetList().GetTargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24133}
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 Clayton1b72fcb2010-08-24 00:45:41176Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24177{
Chris Lattner30fdc8d2010-06-08 16:52:24178 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 Clayton1b72fcb2010-08-24 00:45:41182 // Try and resolve as a load address if possible
Greg Claytonf5e56de2010-09-14 23:36:40183 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41184 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 Lattner30fdc8d2010-06-08 16:52:24190 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 Clayton0c5cd902010-06-28 21:30:43203Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24204{
Greg Clayton0c5cd902010-06-28 21:30:43205 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 Lattner30fdc8d2010-06-08 16:52:24213}
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 Clayton9fed0d82010-07-23 23:33:17255 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24256 else
Greg Clayton9fed0d82010-07-23 23:33:17257 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24258
Greg Clayton2d4edfb2010-11-06 01:53:30259 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24260 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 Lattner30fdc8d2010-06-08 16:52:24267 bp_sp->ResolveBreakpoint();
268 }
Jim Ingham36f3b362010-10-14 23:45:03269
270 if (!internal && bp_sp)
271 {
272 m_last_created_breakpoint = bp_sp;
273 }
274
Chris Lattner30fdc8d2010-06-08 16:52:24275 return bp_sp;
276}
277
278void
279Target::RemoveAllBreakpoints (bool internal_also)
280{
Greg Clayton2d4edfb2010-11-06 01:53:30281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24282 if (log)
283 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
284
Greg Clayton9fed0d82010-07-23 23:33:17285 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24286 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17287 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03288
289 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24290}
291
292void
293Target::DisableAllBreakpoints (bool internal_also)
294{
Greg Clayton2d4edfb2010-11-06 01:53:30295 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24296 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 Clayton2d4edfb2010-11-06 01:53:30307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24308 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 Clayton2d4edfb2010-11-06 01:53:30319 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24320 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 Clayton9fed0d82010-07-23 23:33:17326 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24327 else
Jim Ingham36f3b362010-10-14 23:45:03328 {
329 if (m_last_created_breakpoint->GetID() == break_id)
330 m_last_created_breakpoint.reset();
Greg Clayton9fed0d82010-07-23 23:33:17331 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03332 }
Chris Lattner30fdc8d2010-06-08 16:52:24333 return true;
334 }
335 return false;
336}
337
338bool
339Target::DisableBreakpointByID (break_id_t break_id)
340{
Greg Clayton2d4edfb2010-11-06 01:53:30341 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24342 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 Clayton2d4edfb2010-11-06 01:53:30362 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24363 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 Ingham5aee1622010-08-09 23:31:02409 // 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 Lattner30fdc8d2010-06-08 16:52:24413 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 Claytondd36def2010-10-17 22:03:32419 if (Host::ResolveExecutableInBundle (bundle_executable))
Chris Lattner30fdc8d2010-06-08 16:52:24420 {
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 Tice1559a462010-09-27 00:30:10454
455 UpdateInstanceName();
Chris Lattner30fdc8d2010-06-08 16:52:24456}
457
458
459ModuleList&
460Target::GetImages ()
461{
462 return m_images;
463}
464
465ArchSpec
466Target::GetArchitecture () const
467{
Jim Ingham5aee1622010-08-09 23:31:02468 return m_arch_spec;
Chris Lattner30fdc8d2010-06-08 16:52:24469}
470
Jim Ingham5aee1622010-08-09 23:31:02471bool
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 Lattner30fdc8d2010-06-08 16:52:24524
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 Claytona4d78302010-12-06 23:51:26583
584 // Remove the images from the target image list
585 m_images.Remove(module_list);
586
Chris Lattner30fdc8d2010-06-08 16:52:24587 // TODO: make event data that packages up the module_list
588 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
589}
590
591size_t
Greg Claytondb598232011-01-07 01:57:07592Target::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 Lattner30fdc8d2010-06-08 16:52:24623{
Chris Lattner30fdc8d2010-06-08 16:52:24624 error.Clear();
Greg Claytondb598232011-01-07 01:57:07625
Greg Claytondda4f7b2010-06-30 23:03:03626 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
627
Greg Claytondb598232011-01-07 01:57:07628 size_t bytes_read = 0;
Greg Claytondda4f7b2010-06-30 23:03:03629 Address resolved_addr(addr);
630 if (!resolved_addr.IsSectionOffset())
631 {
632 if (process_is_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24633 {
Greg Claytonf5e56de2010-09-14 23:36:40634 m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr);
Greg Claytondda4f7b2010-06-30 23:03:03635 }
636 else
637 {
638 m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
639 }
640 }
641
Greg Claytondb598232011-01-07 01:57:07642 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 Claytondda4f7b2010-06-30 23:03:03648
649 if (process_is_valid)
650 {
Greg Claytonf5e56de2010-09-14 23:36:40651 lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this);
Greg Claytondda4f7b2010-06-30 23:03:03652 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 Claytondb598232011-01-07 01:57:07663 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24664 if (bytes_read != dst_len)
665 {
666 if (error.Success())
667 {
668 if (bytes_read == 0)
Greg Claytondda4f7b2010-06-30 23:03:03669 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24670 else
Greg Claytondda4f7b2010-06-30 23:03:03671 error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24672 }
673 }
Greg Claytondda4f7b2010-06-30 23:03:03674 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 Lattner30fdc8d2010-06-08 16:52:24683 }
Chris Lattner30fdc8d2010-06-08 16:52:24684 }
Greg Claytondda4f7b2010-06-30 23:03:03685
Greg Claytondb598232011-01-07 01:57:07686 if (!prefer_file_cache)
Greg Claytondda4f7b2010-06-30 23:03:03687 {
Greg Claytondb598232011-01-07 01:57:07688 // 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 Claytondda4f7b2010-06-30 23:03:03691 }
692 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24693}
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 Clayton0603aa92010-10-04 01:05:56775Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24776{
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 Ticedaccaa92010-09-20 20:44:43813
Greg Clayton99d0faf2010-11-18 23:32:35814void
815Target::Initialize ()
Caroline Ticedaccaa92010-09-20 20:44:43816{
Greg Clayton99d0faf2010-11-18 23:32:35817 UserSettingsControllerSP &usc = GetSettingsController();
818 usc.reset (new SettingsController);
819 UserSettingsController::InitializeSettingsController (usc,
820 SettingsController::global_settings_table,
821 SettingsController::instance_settings_table);
822}
Caroline Ticedaccaa92010-09-20 20:44:43823
Greg Clayton99d0faf2010-11-18 23:32:35824void
825Target::Terminate ()
826{
827 UserSettingsControllerSP &usc = GetSettingsController();
828 UserSettingsController::FinalizeSettingsController (usc);
829 usc.reset();
830}
Caroline Ticedaccaa92010-09-20 20:44:43831
Greg Clayton99d0faf2010-11-18 23:32:35832UserSettingsControllerSP &
833Target::GetSettingsController ()
834{
835 static UserSettingsControllerSP g_settings_controller;
Caroline Ticedaccaa92010-09-20 20:44:43836 return g_settings_controller;
837}
838
839ArchSpec
840Target::GetDefaultArchitecture ()
841{
Greg Claytondbe54502010-11-19 03:46:01842 lldb::UserSettingsControllerSP &settings_controller = GetSettingsController();
Caroline Ticedaccaa92010-09-20 20:44:43843 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 Claytondbe54502010-11-19 03:46:01859 GetSettingsController ()->SetVariable ("target.default-arch",
860 new_arch.AsCString(),
861 lldb::eVarSetOperationAssign,
862 false,
863 "[]");
Caroline Ticedaccaa92010-09-20 20:44:43864}
865
Greg Clayton0603aa92010-10-04 01:05:56866Target *
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 Tice1559a462010-09-27 00:30:10885void
886Target::UpdateInstanceName ()
887{
888 StreamString sstr;
889
890 ModuleSP module_sp = GetExecutableModule();
891 if (module_sp)
892 {
Greg Clayton307de252010-10-27 02:06:37893 sstr.Printf ("%s_%s",
894 module_sp->GetFileSpec().GetFilename().AsCString(),
Caroline Tice1559a462010-09-27 00:30:10895 module_sp->GetArchitecture().AsCString());
Greg Claytondbe54502010-11-19 03:46:01896 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
897 sstr.GetData());
Caroline Tice1559a462010-09-27 00:30:10898 }
899}
900
Sean Callanan322f5292010-10-29 00:29:03901const char *
902Target::GetExpressionPrefixContentsAsCString ()
903{
904 return m_expr_prefix_contents.c_str();
905}
906
Greg Clayton8b2fe6d2010-12-14 02:59:59907ExecutionResults
908Target::EvaluateExpression
909(
910 const char *expr_cstr,
911 StackFrame *frame,
912 bool unwind_on_error,
Sean Callanan92adcac2011-01-13 08:53:35913 bool keep_in_memory,
Greg Clayton8b2fe6d2010-12-14 02:59:59914 lldb::ValueObjectSP &result_valobj_sp
915)
916{
917 ExecutionResults execution_results = eExecutionSetupError;
918
919 result_valobj_sp.reset();
920
921 ExecutionContext exe_ctx;
922 if (frame)
923 {
924 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton54979cd2010-12-15 05:08:08925 Error error;
Greg Clayton6d5e68e2011-01-20 19:27:18926 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
927 StackFrame::eExpressionPathOptionsNoFragileObjcIvar;
928 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, expr_path_options, error);
Greg Clayton8b2fe6d2010-12-14 02:59:59929 }
930 else if (m_process_sp)
931 {
932 m_process_sp->CalculateExecutionContext(exe_ctx);
933 }
934 else
935 {
936 CalculateExecutionContext(exe_ctx);
937 }
938
939 if (result_valobj_sp)
940 {
941 execution_results = eExecutionCompleted;
942 // We got a result from the frame variable expression path above...
943 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
944
945 lldb::ValueObjectSP const_valobj_sp;
946
947 // Check in case our value is already a constant value
948 if (result_valobj_sp->GetIsConstant())
949 {
950 const_valobj_sp = result_valobj_sp;
951 const_valobj_sp->SetName (persistent_variable_name);
952 }
953 else
954 const_valobj_sp = result_valobj_sp->CreateConstantValue (exe_ctx.GetBestExecutionContextScope(),
955 persistent_variable_name);
956
Sean Callanan92adcac2011-01-13 08:53:35957 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
958
Greg Clayton8b2fe6d2010-12-14 02:59:59959 result_valobj_sp = const_valobj_sp;
960
Sean Callanan92adcac2011-01-13 08:53:35961 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
962 assert (clang_expr_variable_sp.get());
963
964 // Set flags and live data as appropriate
965
966 const Value &result_value = live_valobj_sp->GetValue();
967
968 switch (result_value.GetValueType())
969 {
970 case Value::eValueTypeHostAddress:
971 case Value::eValueTypeFileAddress:
972 // we don't do anything with these for now
973 break;
974 case Value::eValueTypeScalar:
975 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
976 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
977 break;
978 case Value::eValueTypeLoadAddress:
979 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
980 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
981 break;
982 }
Greg Clayton8b2fe6d2010-12-14 02:59:59983 }
984 else
985 {
986 // Make sure we aren't just trying to see the value of a persistent
987 // variable (something like "$0")
Greg Clayton3e06bd92011-01-09 21:07:35988 lldb::ClangExpressionVariableSP persistent_var_sp;
989 // Only check for persistent variables the expression starts with a '$'
990 if (expr_cstr[0] == '$')
991 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
992
Greg Clayton8b2fe6d2010-12-14 02:59:59993 if (persistent_var_sp)
994 {
995 result_valobj_sp = persistent_var_sp->GetValueObject ();
996 execution_results = eExecutionCompleted;
997 }
998 else
999 {
1000 const char *prefix = GetExpressionPrefixContentsAsCString();
1001
1002 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan92adcac2011-01-13 08:53:351003 unwind_on_error,
1004 keep_in_memory,
Greg Clayton8b2fe6d2010-12-14 02:59:591005 expr_cstr,
1006 prefix,
1007 result_valobj_sp);
1008 }
1009 }
1010 return execution_results;
1011}
1012
Caroline Ticedaccaa92010-09-20 20:44:431013//--------------------------------------------------------------
1014// class Target::SettingsController
1015//--------------------------------------------------------------
1016
1017Target::SettingsController::SettingsController () :
1018 UserSettingsController ("target", Debugger::GetSettingsController()),
1019 m_default_architecture ()
1020{
1021 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1022 InstanceSettings::GetDefaultName().AsCString()));
1023}
1024
1025Target::SettingsController::~SettingsController ()
1026{
1027}
1028
1029lldb::InstanceSettingsSP
1030Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1031{
Greg Claytondbe54502010-11-19 03:46:011032 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1033 false,
1034 instance_name);
Caroline Ticedaccaa92010-09-20 20:44:431035 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1036 return new_settings_sp;
1037}
1038
1039const ConstString &
1040Target::SettingsController::DefArchVarName ()
1041{
1042 static ConstString def_arch_var_name ("default-arch");
1043
1044 return def_arch_var_name;
1045}
1046
1047bool
1048Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1049 const char *index_value,
1050 const char *value,
1051 const SettingEntry &entry,
1052 const lldb::VarSetOperationType op,
1053 Error&err)
1054{
1055 if (var_name == DefArchVarName())
1056 {
1057 ArchSpec tmp_spec (value);
1058 if (tmp_spec.IsValid())
1059 m_default_architecture = tmp_spec;
1060 else
1061 err.SetErrorStringWithFormat ("'%s' is not a valid architecture.", value);
1062 }
1063 return true;
1064}
1065
1066
1067bool
1068Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1069 StringList &value,
1070 Error &err)
1071{
1072 if (var_name == DefArchVarName())
1073 {
Greg Clayton307de252010-10-27 02:06:371074 // If the arch is invalid (the default), don't show a string for it
1075 if (m_default_architecture.IsValid())
1076 value.AppendString (m_default_architecture.AsCString());
Caroline Ticedaccaa92010-09-20 20:44:431077 return true;
1078 }
1079 else
1080 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1081
1082 return false;
1083}
1084
1085//--------------------------------------------------------------
1086// class TargetInstanceSettings
1087//--------------------------------------------------------------
1088
Greg Clayton85851dd2010-12-04 00:10:171089TargetInstanceSettings::TargetInstanceSettings
1090(
1091 UserSettingsController &owner,
1092 bool live_instance,
1093 const char *name
1094) :
1095 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance)
Caroline Ticedaccaa92010-09-20 20:44:431096{
1097 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1098 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1099 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1100 // This is true for CreateInstanceName() too.
1101
1102 if (GetInstanceName () == InstanceSettings::InvalidName())
1103 {
1104 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1105 m_owner.RegisterInstanceSettings (this);
1106 }
1107
1108 if (live_instance)
1109 {
1110 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1111 CopyInstanceSettings (pending_settings,false);
1112 //m_owner.RemovePendingSettings (m_instance_name);
1113 }
1114}
1115
1116TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Claytondbe54502010-11-19 03:46:011117 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString())
Caroline Ticedaccaa92010-09-20 20:44:431118{
1119 if (m_instance_name != InstanceSettings::GetDefaultName())
1120 {
1121 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1122 CopyInstanceSettings (pending_settings,false);
1123 //m_owner.RemovePendingSettings (m_instance_name);
1124 }
1125}
1126
1127TargetInstanceSettings::~TargetInstanceSettings ()
1128{
1129}
1130
1131TargetInstanceSettings&
1132TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1133{
1134 if (this != &rhs)
1135 {
1136 }
1137
1138 return *this;
1139}
1140
Sean Callanan322f5292010-10-29 00:29:031141#define EXPR_PREFIX_STRING "expr-prefix"
Caroline Ticedaccaa92010-09-20 20:44:431142
1143void
1144TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1145 const char *index_value,
1146 const char *value,
1147 const ConstString &instance_name,
1148 const SettingEntry &entry,
1149 lldb::VarSetOperationType op,
1150 Error &err,
1151 bool pending)
1152{
Sean Callanan322f5292010-10-29 00:29:031153 static ConstString expr_prefix_str (EXPR_PREFIX_STRING);
1154
1155 if (var_name == expr_prefix_str)
1156 {
1157 switch (op)
1158 {
1159 default:
1160 err.SetErrorToGenericError ();
1161 err.SetErrorString ("Unrecognized operation. Cannot update value.\n");
1162 return;
1163 case lldb::eVarSetOperationAssign:
1164 {
1165 FileSpec file_spec(value, true);
1166
1167 if (!file_spec.Exists())
1168 {
1169 err.SetErrorToGenericError ();
1170 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1171 return;
1172 }
1173
1174 DataBufferMemoryMap buf;
1175
1176 if (!buf.MemoryMapFromFileSpec(&file_spec) &&
1177 buf.GetError().Fail())
1178 {
1179 err.SetErrorToGenericError ();
1180 err.SetErrorStringWithFormat ("Couldn't read from %s: %s\n", value, buf.GetError().AsCString());
1181 return;
1182 }
1183
1184 m_expr_prefix_path = value;
1185 m_expr_prefix_contents.assign(reinterpret_cast<const char *>(buf.GetBytes()), buf.GetByteSize());
1186 }
1187 return;
1188 case lldb::eVarSetOperationAppend:
1189 err.SetErrorToGenericError ();
1190 err.SetErrorString ("Cannot append to a path.\n");
1191 return;
1192 case lldb::eVarSetOperationClear:
1193 m_expr_prefix_path.clear ();
1194 m_expr_prefix_contents.clear ();
1195 return;
1196 }
1197 }
Caroline Ticedaccaa92010-09-20 20:44:431198}
1199
1200void
1201TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
Sean Callanan322f5292010-10-29 00:29:031202 bool pending)
Caroline Ticedaccaa92010-09-20 20:44:431203{
Sean Callanan322f5292010-10-29 00:29:031204 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1205
1206 if (!new_settings_ptr)
1207 return;
1208
1209 m_expr_prefix_path = new_settings_ptr->m_expr_prefix_path;
1210 m_expr_prefix_contents = new_settings_ptr->m_expr_prefix_contents;
Caroline Ticedaccaa92010-09-20 20:44:431211}
1212
Caroline Tice12cecd72010-09-20 21:37:421213bool
Caroline Ticedaccaa92010-09-20 20:44:431214TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1215 const ConstString &var_name,
1216 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:421217 Error *err)
Caroline Ticedaccaa92010-09-20 20:44:431218{
Sean Callanan322f5292010-10-29 00:29:031219 static ConstString expr_prefix_str (EXPR_PREFIX_STRING);
1220
1221 if (var_name == expr_prefix_str)
1222 {
1223 value.AppendString (m_expr_prefix_path.c_str(), m_expr_prefix_path.size());
1224 }
1225 else
1226 {
1227 if (err)
1228 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1229 return false;
1230 }
1231
1232 return true;
Caroline Ticedaccaa92010-09-20 20:44:431233}
1234
1235const ConstString
1236TargetInstanceSettings::CreateInstanceName ()
1237{
Caroline Ticedaccaa92010-09-20 20:44:431238 StreamString sstr;
Caroline Tice1559a462010-09-27 00:30:101239 static int instance_count = 1;
1240
Caroline Ticedaccaa92010-09-20 20:44:431241 sstr.Printf ("target_%d", instance_count);
1242 ++instance_count;
1243
1244 const ConstString ret_val (sstr.GetData());
1245 return ret_val;
1246}
1247
1248//--------------------------------------------------
1249// Target::SettingsController Variable Tables
1250//--------------------------------------------------
1251
1252SettingEntry
1253Target::SettingsController::global_settings_table[] =
1254{
Sean Callanan322f5292010-10-29 00:29:031255 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1256 { "default-arch", eSetVarTypeString, NULL, NULL, false, false, "Default architecture to choose, when there's a choice." },
Caroline Ticedaccaa92010-09-20 20:44:431257 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1258};
1259
1260SettingEntry
1261Target::SettingsController::instance_settings_table[] =
1262{
Sean Callanan322f5292010-10-29 00:29:031263 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1264 { EXPR_PREFIX_STRING, eSetVarTypeString, NULL, NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
Caroline Ticedaccaa92010-09-20 20:44:431265 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1266};