blob: b199b05ac1ffda634f9496c2ee1d73b5f58bedae [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"
Greg Clayton8b2fe6d2010-12-14 02:59:5920#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2421#include "lldb/Core/Event.h"
22#include "lldb/Core/Log.h"
Caroline Tice969ed3d12011-05-02 20:41:4623#include "lldb/Core/StreamAsynchronousIO.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"
Greg Claytoneb0103f2011-04-07 22:46:3527#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:2428#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:5929#include "lldb/Interpreter/CommandInterpreter.h"
30#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:2431#include "lldb/lldb-private-log.h"
32#include "lldb/Symbol/ObjectFile.h"
33#include "lldb/Target/Process.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5934#include "lldb/Target/StackFrame.h"
Jim Ingham9575d842011-03-11 03:53:5935#include "lldb/Target/Thread.h"
36#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:2437
38using namespace lldb;
39using namespace lldb_private;
40
41//----------------------------------------------------------------------
42// Target constructor
43//----------------------------------------------------------------------
Greg Clayton32e0a752011-03-30 18:16:5144Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
45 Broadcaster ("lldb.target"),
46 ExecutionContextScope (),
Greg Claytondbe54502010-11-19 03:46:0147 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton66111032010-06-23 01:19:2948 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:5149 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:2350 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:5151 m_arch (target_arch),
52 m_images (),
Greg Claytonf5e56de2010-09-14 23:36:4053 m_section_load_list (),
Chris Lattner30fdc8d2010-06-08 16:52:2454 m_breakpoint_list (false),
55 m_internal_breakpoint_list (true),
Greg Clayton32e0a752011-03-30 18:16:5156 m_process_sp (),
57 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:2458 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton8b2fe6d2010-12-14 02:59:5959 m_scratch_ast_context_ap (NULL),
Jim Ingham9575d842011-03-11 03:53:5960 m_persistent_variables (),
Greg Clayton32e0a752011-03-30 18:16:5161 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:1462 m_stop_hook_next_id (0),
63 m_suppress_stop_hooks (false)
Chris Lattner30fdc8d2010-06-08 16:52:2464{
Greg Claytoncfd1ace2010-10-31 03:01:0665 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
66 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
67 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
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}
73
74//----------------------------------------------------------------------
75// Destructor
76//----------------------------------------------------------------------
77Target::~Target()
78{
Greg Clayton2d4edfb2010-11-06 01:53:3079 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2480 if (log)
81 log->Printf ("%p Target::~Target()", this);
82 DeleteCurrentProcess ();
83}
84
85void
Caroline Ticeceb6b132010-10-26 03:11:1386Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:2487{
Greg Clayton89411422010-10-08 00:21:0588// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:1389 if (description_level != lldb::eDescriptionLevelBrief)
90 {
91 s->Indent();
92 s->PutCString("Target\n");
93 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:3594 m_images.Dump(s);
95 m_breakpoint_list.Dump(s);
96 m_internal_breakpoint_list.Dump(s);
97 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:1398 }
99 else
100 {
Jim Ingham48028b62011-05-12 01:12:28101 if (GetExecutableModule())
102 s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
103 else
104 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13105 }
Chris Lattner30fdc8d2010-06-08 16:52:24106}
107
108void
109Target::DeleteCurrentProcess ()
110{
111 if (m_process_sp.get())
112 {
Greg Clayton17f69202010-09-14 23:52:43113 m_section_load_list.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24114 if (m_process_sp->IsAlive())
115 m_process_sp->Destroy();
Jim Inghamd0a3e12b2011-02-16 17:54:55116
117 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24118
119 // Do any cleanup of the target we need to do between process instances.
120 // NB It is better to do this before destroying the process in case the
121 // clean up needs some help from the process.
122 m_breakpoint_list.ClearAllBreakpointSites();
123 m_internal_breakpoint_list.ClearAllBreakpointSites();
124 m_process_sp.reset();
125 }
126}
127
128const lldb::ProcessSP &
129Target::CreateProcess (Listener &listener, const char *plugin_name)
130{
131 DeleteCurrentProcess ();
132 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
133 return m_process_sp;
134}
135
136const lldb::ProcessSP &
137Target::GetProcessSP () const
138{
139 return m_process_sp;
140}
141
142lldb::TargetSP
143Target::GetSP()
144{
Greg Clayton66111032010-06-23 01:19:29145 return m_debugger.GetTargetList().GetTargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24146}
147
148BreakpointList &
149Target::GetBreakpointList(bool internal)
150{
151 if (internal)
152 return m_internal_breakpoint_list;
153 else
154 return m_breakpoint_list;
155}
156
157const BreakpointList &
158Target::GetBreakpointList(bool internal) const
159{
160 if (internal)
161 return m_internal_breakpoint_list;
162 else
163 return m_breakpoint_list;
164}
165
166BreakpointSP
167Target::GetBreakpointByID (break_id_t break_id)
168{
169 BreakpointSP bp_sp;
170
171 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
172 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
173 else
174 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
175
176 return bp_sp;
177}
178
179BreakpointSP
180Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
181{
182 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
183 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
184 return CreateBreakpoint (filter_sp, resolver_sp, internal);
185}
186
187
188BreakpointSP
Greg Clayton1b72fcb2010-08-24 00:45:41189Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24190{
Chris Lattner30fdc8d2010-06-08 16:52:24191 Address so_addr;
192 // Attempt to resolve our load address if possible, though it is ok if
193 // it doesn't resolve to section/offset.
194
Greg Clayton1b72fcb2010-08-24 00:45:41195 // Try and resolve as a load address if possible
Greg Claytonf5e56de2010-09-14 23:36:40196 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41197 if (!so_addr.IsValid())
198 {
199 // The address didn't resolve, so just set this as an absolute address
200 so_addr.SetOffset (addr);
201 }
202 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner30fdc8d2010-06-08 16:52:24203 return bp_sp;
204}
205
206BreakpointSP
207Target::CreateBreakpoint (Address &addr, bool internal)
208{
209 TargetSP target_sp = this->GetSP();
210 SearchFilterSP filter_sp(new SearchFilter (target_sp));
211 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
212 return CreateBreakpoint (filter_sp, resolver_sp, internal);
213}
214
215BreakpointSP
Greg Clayton0c5cd902010-06-28 21:30:43216Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24217{
Greg Clayton0c5cd902010-06-28 21:30:43218 BreakpointSP bp_sp;
219 if (func_name)
220 {
221 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
222 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact));
223 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
224 }
225 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24226}
227
228
229SearchFilterSP
230Target::GetSearchFilterForModule (const FileSpec *containingModule)
231{
232 SearchFilterSP filter_sp;
233 lldb::TargetSP target_sp = this->GetSP();
234 if (containingModule != NULL)
235 {
236 // TODO: We should look into sharing module based search filters
237 // across many breakpoints like we do for the simple target based one
238 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
239 }
240 else
241 {
242 if (m_search_filter_sp.get() == NULL)
243 m_search_filter_sp.reset (new SearchFilter (target_sp));
244 filter_sp = m_search_filter_sp;
245 }
246 return filter_sp;
247}
248
249BreakpointSP
250Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal)
251{
252 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
253 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex));
254
255 return CreateBreakpoint (filter_sp, resolver_sp, internal);
256}
257
258BreakpointSP
259Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
260{
261 BreakpointSP bp_sp;
262 if (filter_sp && resolver_sp)
263 {
264 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
265 resolver_sp->SetBreakpoint (bp_sp.get());
266
267 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17268 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24269 else
Greg Clayton9fed0d82010-07-23 23:33:17270 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24271
Greg Clayton2d4edfb2010-11-06 01:53:30272 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24273 if (log)
274 {
275 StreamString s;
276 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
277 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
278 }
279
Chris Lattner30fdc8d2010-06-08 16:52:24280 bp_sp->ResolveBreakpoint();
281 }
Jim Ingham36f3b362010-10-14 23:45:03282
283 if (!internal && bp_sp)
284 {
285 m_last_created_breakpoint = bp_sp;
286 }
287
Chris Lattner30fdc8d2010-06-08 16:52:24288 return bp_sp;
289}
290
291void
292Target::RemoveAllBreakpoints (bool internal_also)
293{
Greg Clayton2d4edfb2010-11-06 01:53:30294 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24295 if (log)
296 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
297
Greg Clayton9fed0d82010-07-23 23:33:17298 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24299 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17300 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03301
302 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24303}
304
305void
306Target::DisableAllBreakpoints (bool internal_also)
307{
Greg Clayton2d4edfb2010-11-06 01:53:30308 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24309 if (log)
310 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
311
312 m_breakpoint_list.SetEnabledAll (false);
313 if (internal_also)
314 m_internal_breakpoint_list.SetEnabledAll (false);
315}
316
317void
318Target::EnableAllBreakpoints (bool internal_also)
319{
Greg Clayton2d4edfb2010-11-06 01:53:30320 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24321 if (log)
322 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
323
324 m_breakpoint_list.SetEnabledAll (true);
325 if (internal_also)
326 m_internal_breakpoint_list.SetEnabledAll (true);
327}
328
329bool
330Target::RemoveBreakpointByID (break_id_t break_id)
331{
Greg Clayton2d4edfb2010-11-06 01:53:30332 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24333 if (log)
334 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
335
336 if (DisableBreakpointByID (break_id))
337 {
338 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17339 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24340 else
Jim Ingham36f3b362010-10-14 23:45:03341 {
Greg Claytonaa1c5872011-01-24 23:35:47342 if (m_last_created_breakpoint)
343 {
344 if (m_last_created_breakpoint->GetID() == break_id)
345 m_last_created_breakpoint.reset();
346 }
Greg Clayton9fed0d82010-07-23 23:33:17347 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03348 }
Chris Lattner30fdc8d2010-06-08 16:52:24349 return true;
350 }
351 return false;
352}
353
354bool
355Target::DisableBreakpointByID (break_id_t break_id)
356{
Greg Clayton2d4edfb2010-11-06 01:53:30357 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24358 if (log)
359 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
360
361 BreakpointSP bp_sp;
362
363 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
364 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
365 else
366 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
367 if (bp_sp)
368 {
369 bp_sp->SetEnabled (false);
370 return true;
371 }
372 return false;
373}
374
375bool
376Target::EnableBreakpointByID (break_id_t break_id)
377{
Greg Clayton2d4edfb2010-11-06 01:53:30378 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24379 if (log)
380 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
381 __FUNCTION__,
382 break_id,
383 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
384
385 BreakpointSP bp_sp;
386
387 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
388 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
389 else
390 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
391
392 if (bp_sp)
393 {
394 bp_sp->SetEnabled (true);
395 return true;
396 }
397 return false;
398}
399
400ModuleSP
401Target::GetExecutableModule ()
402{
403 ModuleSP executable_sp;
404 if (m_images.GetSize() > 0)
405 executable_sp = m_images.GetModuleAtIndex(0);
406 return executable_sp;
407}
408
409void
410Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
411{
412 m_images.Clear();
413 m_scratch_ast_context_ap.reset();
414
415 if (executable_sp.get())
416 {
417 Timer scoped_timer (__PRETTY_FUNCTION__,
418 "Target::SetExecutableModule (executable = '%s/%s')",
419 executable_sp->GetFileSpec().GetDirectory().AsCString(),
420 executable_sp->GetFileSpec().GetFilename().AsCString());
421
422 m_images.Append(executable_sp); // The first image is our exectuable file
423
Jim Ingham5aee1622010-08-09 23:31:02424 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton32e0a752011-03-30 18:16:51425 if (!m_arch.IsValid())
426 m_arch = executable_sp->GetArchitecture();
Jim Ingham5aee1622010-08-09 23:31:02427
Chris Lattner30fdc8d2010-06-08 16:52:24428 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15429 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner30fdc8d2010-06-08 16:52:24430
431 if (executable_objfile)
432 {
433 executable_objfile->GetDependentModules(dependent_files);
434 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
435 {
Greg Claytonded470d2011-03-19 01:12:21436 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
437 FileSpec platform_dependent_file_spec;
438 if (m_platform_sp)
Greg Claytond314e812011-03-23 00:09:55439 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21440 else
441 platform_dependent_file_spec = dependent_file_spec;
442
443 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton32e0a752011-03-30 18:16:51444 m_arch));
Chris Lattner30fdc8d2010-06-08 16:52:24445 if (image_module_sp.get())
446 {
447 //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY
448 ObjectFile *objfile = image_module_sp->GetObjectFile();
449 if (objfile)
450 objfile->GetDependentModules(dependent_files);
451 }
452 }
453 }
454
455 // Now see if we know the target triple, and if so, create our scratch AST context:
Greg Clayton32e0a752011-03-30 18:16:51456 if (m_arch.IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24457 {
Greg Clayton32e0a752011-03-30 18:16:51458 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Chris Lattner30fdc8d2010-06-08 16:52:24459 }
460 }
Caroline Tice1559a462010-09-27 00:30:10461
462 UpdateInstanceName();
Chris Lattner30fdc8d2010-06-08 16:52:24463}
464
465
Jim Ingham5aee1622010-08-09 23:31:02466bool
467Target::SetArchitecture (const ArchSpec &arch_spec)
468{
Greg Clayton32e0a752011-03-30 18:16:51469 if (m_arch == arch_spec)
Jim Ingham5aee1622010-08-09 23:31:02470 {
471 // If we're setting the architecture to our current architecture, we
472 // don't need to do anything.
473 return true;
474 }
Greg Clayton32e0a752011-03-30 18:16:51475 else if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02476 {
477 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton32e0a752011-03-30 18:16:51478 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02479 return true;
480 }
481 else
482 {
483 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton32e0a752011-03-30 18:16:51484 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02485 ModuleSP executable_sp = GetExecutableModule ();
486 m_images.Clear();
487 m_scratch_ast_context_ap.reset();
Jim Ingham5aee1622010-08-09 23:31:02488 // Need to do something about unsetting breakpoints.
489
490 if (executable_sp)
491 {
492 FileSpec exec_file_spec = executable_sp->GetFileSpec();
493 Error error = ModuleList::GetSharedModule(exec_file_spec,
494 arch_spec,
495 NULL,
496 NULL,
497 0,
498 executable_sp,
499 NULL,
500 NULL);
501
502 if (!error.Fail() && executable_sp)
503 {
504 SetExecutableModule (executable_sp, true);
505 return true;
506 }
507 else
508 {
509 return false;
510 }
511 }
512 else
513 {
514 return false;
515 }
516 }
517}
Chris Lattner30fdc8d2010-06-08 16:52:24518
Chris Lattner30fdc8d2010-06-08 16:52:24519void
520Target::ModuleAdded (ModuleSP &module_sp)
521{
522 // A module is being added to this target for the first time
523 ModuleList module_list;
524 module_list.Append(module_sp);
525 ModulesDidLoad (module_list);
526}
527
528void
529Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
530{
531 // A module is being added to this target for the first time
532 ModuleList module_list;
533 module_list.Append (old_module_sp);
534 ModulesDidUnload (module_list);
535 module_list.Clear ();
536 module_list.Append (new_module_sp);
537 ModulesDidLoad (module_list);
538}
539
540void
541Target::ModulesDidLoad (ModuleList &module_list)
542{
543 m_breakpoint_list.UpdateBreakpoints (module_list, true);
544 // TODO: make event data that packages up the module_list
545 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
546}
547
548void
549Target::ModulesDidUnload (ModuleList &module_list)
550{
551 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Claytona4d78302010-12-06 23:51:26552
553 // Remove the images from the target image list
554 m_images.Remove(module_list);
555
Chris Lattner30fdc8d2010-06-08 16:52:24556 // TODO: make event data that packages up the module_list
557 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
558}
559
560size_t
Greg Claytondb598232011-01-07 01:57:07561Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
562{
563 const Section *section = addr.GetSection();
564 if (section && section->GetModule())
565 {
566 ObjectFile *objfile = section->GetModule()->GetObjectFile();
567 if (objfile)
568 {
569 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
570 addr.GetOffset(),
571 dst,
572 dst_len);
573 if (bytes_read > 0)
574 return bytes_read;
575 else
576 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
577 }
578 else
579 {
580 error.SetErrorString("address isn't from a object file");
581 }
582 }
583 else
584 {
585 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
586 }
587 return 0;
588}
589
590size_t
591Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size_t dst_len, Error &error)
Chris Lattner30fdc8d2010-06-08 16:52:24592{
Chris Lattner30fdc8d2010-06-08 16:52:24593 error.Clear();
Greg Claytondb598232011-01-07 01:57:07594
Greg Claytondda4f7b2010-06-30 23:03:03595 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
596
Greg Claytondb598232011-01-07 01:57:07597 size_t bytes_read = 0;
Greg Clayton357132e2011-03-26 19:14:58598 Address resolved_addr;
599 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03600 {
601 if (process_is_valid)
Greg Claytonf5e56de2010-09-14 23:36:40602 m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr);
Greg Claytondda4f7b2010-06-30 23:03:03603 else
Greg Claytondda4f7b2010-06-30 23:03:03604 m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
Greg Claytondda4f7b2010-06-30 23:03:03605 }
Greg Clayton357132e2011-03-26 19:14:58606 if (!resolved_addr.IsValid())
607 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03608
Greg Claytondb598232011-01-07 01:57:07609 if (prefer_file_cache)
610 {
611 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
612 if (bytes_read > 0)
613 return bytes_read;
614 }
Greg Claytondda4f7b2010-06-30 23:03:03615
616 if (process_is_valid)
617 {
Greg Claytonf5e56de2010-09-14 23:36:40618 lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this);
Greg Claytondda4f7b2010-06-30 23:03:03619 if (load_addr == LLDB_INVALID_ADDRESS)
620 {
621 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
622 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
623 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
624 resolved_addr.GetFileAddress());
625 else
626 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
627 }
628 else
629 {
Greg Claytondb598232011-01-07 01:57:07630 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24631 if (bytes_read != dst_len)
632 {
633 if (error.Success())
634 {
635 if (bytes_read == 0)
Greg Claytondda4f7b2010-06-30 23:03:03636 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24637 else
Greg Claytondda4f7b2010-06-30 23:03:03638 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:24639 }
640 }
Greg Claytondda4f7b2010-06-30 23:03:03641 if (bytes_read)
642 return bytes_read;
643 // If the address is not section offset we have an address that
644 // doesn't resolve to any address in any currently loaded shared
645 // libaries and we failed to read memory so there isn't anything
646 // more we can do. If it is section offset, we might be able to
647 // read cached memory from the object file.
648 if (!resolved_addr.IsSectionOffset())
649 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24650 }
Chris Lattner30fdc8d2010-06-08 16:52:24651 }
Greg Claytondda4f7b2010-06-30 23:03:03652
Greg Claytondb598232011-01-07 01:57:07653 if (!prefer_file_cache)
Greg Claytondda4f7b2010-06-30 23:03:03654 {
Greg Claytondb598232011-01-07 01:57:07655 // If we didn't already try and read from the object file cache, then
656 // try it after failing to read from the process.
657 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03658 }
659 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24660}
661
662
663ModuleSP
664Target::GetSharedModule
665(
666 const FileSpec& file_spec,
667 const ArchSpec& arch,
Greg Clayton60830262011-02-04 18:53:10668 const lldb_private::UUID *uuid_ptr,
Chris Lattner30fdc8d2010-06-08 16:52:24669 const ConstString *object_name,
670 off_t object_offset,
671 Error *error_ptr
672)
673{
674 // Don't pass in the UUID so we can tell if we have a stale value in our list
675 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
676 bool did_create_module = false;
677 ModuleSP module_sp;
678
Chris Lattner30fdc8d2010-06-08 16:52:24679 Error error;
680
Greg Clayton32e0a752011-03-30 18:16:51681 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner30fdc8d2010-06-08 16:52:24682 if (m_image_search_paths.GetSize())
683 {
684 FileSpec transformed_spec;
685 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
686 {
687 transformed_spec.GetFilename() = file_spec.GetFilename();
688 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
689 }
690 }
691
Greg Clayton32e0a752011-03-30 18:16:51692 // The platform is responsible for finding and caching an appropriate
693 // module in the shared module cache.
694 if (m_platform_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24695 {
Greg Clayton32e0a752011-03-30 18:16:51696 FileSpec platform_file_spec;
697 error = m_platform_sp->GetSharedModule (file_spec,
698 arch,
699 uuid_ptr,
700 object_name,
701 object_offset,
702 module_sp,
703 &old_module_sp,
704 &did_create_module);
705 }
706 else
707 {
708 error.SetErrorString("no platform is currently set");
Chris Lattner30fdc8d2010-06-08 16:52:24709 }
710
Greg Clayton32e0a752011-03-30 18:16:51711 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner30fdc8d2010-06-08 16:52:24712 if (module_sp)
713 {
714 m_images.Append (module_sp);
715 if (did_create_module)
716 {
717 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
718 ModuleUpdated(old_module_sp, module_sp);
719 else
720 ModuleAdded(module_sp);
721 }
722 }
723 if (error_ptr)
724 *error_ptr = error;
725 return module_sp;
726}
727
728
729Target *
730Target::CalculateTarget ()
731{
732 return this;
733}
734
735Process *
736Target::CalculateProcess ()
737{
738 return NULL;
739}
740
741Thread *
742Target::CalculateThread ()
743{
744 return NULL;
745}
746
747StackFrame *
748Target::CalculateStackFrame ()
749{
750 return NULL;
751}
752
753void
Greg Clayton0603aa92010-10-04 01:05:56754Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24755{
756 exe_ctx.target = this;
757 exe_ctx.process = NULL; // Do NOT fill in process...
758 exe_ctx.thread = NULL;
759 exe_ctx.frame = NULL;
760}
761
762PathMappingList &
763Target::GetImageSearchPathList ()
764{
765 return m_image_search_paths;
766}
767
768void
769Target::ImageSearchPathsChanged
770(
771 const PathMappingList &path_list,
772 void *baton
773)
774{
775 Target *target = (Target *)baton;
776 if (target->m_images.GetSize() > 1)
777 {
778 ModuleSP exe_module_sp (target->GetExecutableModule());
779 if (exe_module_sp)
780 {
781 target->m_images.Clear();
782 target->SetExecutableModule (exe_module_sp, true);
783 }
784 }
785}
786
787ClangASTContext *
788Target::GetScratchClangASTContext()
789{
790 return m_scratch_ast_context_ap.get();
791}
Caroline Ticedaccaa92010-09-20 20:44:43792
Greg Clayton99d0faf2010-11-18 23:32:35793void
Caroline Tice20bd37f2011-03-10 22:14:10794Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:43795{
Greg Clayton99d0faf2010-11-18 23:32:35796 UserSettingsControllerSP &usc = GetSettingsController();
797 usc.reset (new SettingsController);
798 UserSettingsController::InitializeSettingsController (usc,
799 SettingsController::global_settings_table,
800 SettingsController::instance_settings_table);
Caroline Tice20bd37f2011-03-10 22:14:10801
802 // Now call SettingsInitialize() on each 'child' setting of Target
803 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:35804}
Caroline Ticedaccaa92010-09-20 20:44:43805
Greg Clayton99d0faf2010-11-18 23:32:35806void
Caroline Tice20bd37f2011-03-10 22:14:10807Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35808{
Caroline Tice20bd37f2011-03-10 22:14:10809
810 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
811
812 Process::SettingsTerminate ();
813
814 // Now terminate Target Settings.
815
Greg Clayton99d0faf2010-11-18 23:32:35816 UserSettingsControllerSP &usc = GetSettingsController();
817 UserSettingsController::FinalizeSettingsController (usc);
818 usc.reset();
819}
Caroline Ticedaccaa92010-09-20 20:44:43820
Greg Clayton99d0faf2010-11-18 23:32:35821UserSettingsControllerSP &
822Target::GetSettingsController ()
823{
824 static UserSettingsControllerSP g_settings_controller;
Caroline Ticedaccaa92010-09-20 20:44:43825 return g_settings_controller;
826}
827
828ArchSpec
829Target::GetDefaultArchitecture ()
830{
Greg Clayton64195a22011-02-23 00:35:02831 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
832
833 if (settings_controller_sp)
834 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
835 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:43836}
837
838void
Greg Clayton64195a22011-02-23 00:35:02839Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Ticedaccaa92010-09-20 20:44:43840{
Greg Clayton64195a22011-02-23 00:35:02841 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
842
843 if (settings_controller_sp)
844 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Ticedaccaa92010-09-20 20:44:43845}
846
Greg Clayton0603aa92010-10-04 01:05:56847Target *
848Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
849{
850 // The target can either exist in the "process" of ExecutionContext, or in
851 // the "target_sp" member of SymbolContext. This accessor helper function
852 // will get the target from one of these locations.
853
854 Target *target = NULL;
855 if (sc_ptr != NULL)
856 target = sc_ptr->target_sp.get();
857 if (target == NULL)
858 {
859 if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
860 target = &exe_ctx_ptr->process->GetTarget();
861 }
862 return target;
863}
864
865
Caroline Tice1559a462010-09-27 00:30:10866void
867Target::UpdateInstanceName ()
868{
869 StreamString sstr;
870
871 ModuleSP module_sp = GetExecutableModule();
872 if (module_sp)
873 {
Greg Clayton307de252010-10-27 02:06:37874 sstr.Printf ("%s_%s",
875 module_sp->GetFileSpec().GetFilename().AsCString(),
Greg Clayton64195a22011-02-23 00:35:02876 module_sp->GetArchitecture().GetArchitectureName());
Greg Claytondbe54502010-11-19 03:46:01877 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
878 sstr.GetData());
Caroline Tice1559a462010-09-27 00:30:10879 }
880}
881
Sean Callanan322f5292010-10-29 00:29:03882const char *
883Target::GetExpressionPrefixContentsAsCString ()
884{
Greg Clayton7e14f912011-04-23 02:04:55885 if (m_expr_prefix_contents_sp)
886 return (const char *)m_expr_prefix_contents_sp->GetBytes();
887 return NULL;
Sean Callanan322f5292010-10-29 00:29:03888}
889
Greg Clayton8b2fe6d2010-12-14 02:59:59890ExecutionResults
891Target::EvaluateExpression
892(
893 const char *expr_cstr,
894 StackFrame *frame,
895 bool unwind_on_error,
Sean Callanan92adcac2011-01-13 08:53:35896 bool keep_in_memory,
Jim Ingham2837b762011-05-04 03:43:18897 lldb::DynamicValueType use_dynamic,
Greg Clayton8b2fe6d2010-12-14 02:59:59898 lldb::ValueObjectSP &result_valobj_sp
899)
900{
901 ExecutionResults execution_results = eExecutionSetupError;
902
903 result_valobj_sp.reset();
Jim Ingham6026ca32011-05-12 02:06:14904
905 // We shouldn't run stop hooks in expressions.
906 // Be sure to reset this if you return anywhere within this function.
907 bool old_suppress_value = m_suppress_stop_hooks;
908 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:59909
910 ExecutionContext exe_ctx;
911 if (frame)
912 {
913 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton54979cd2010-12-15 05:08:08914 Error error;
Greg Clayton6d5e68e2011-01-20 19:27:18915 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
916 StackFrame::eExpressionPathOptionsNoFragileObjcIvar;
Jim Ingham2837b762011-05-04 03:43:18917 lldb::VariableSP var_sp;
918 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
919 use_dynamic,
920 expr_path_options,
921 var_sp,
922 error);
Greg Clayton8b2fe6d2010-12-14 02:59:59923 }
924 else if (m_process_sp)
925 {
926 m_process_sp->CalculateExecutionContext(exe_ctx);
927 }
928 else
929 {
930 CalculateExecutionContext(exe_ctx);
931 }
932
933 if (result_valobj_sp)
934 {
935 execution_results = eExecutionCompleted;
936 // We got a result from the frame variable expression path above...
937 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
938
939 lldb::ValueObjectSP const_valobj_sp;
940
941 // Check in case our value is already a constant value
942 if (result_valobj_sp->GetIsConstant())
943 {
944 const_valobj_sp = result_valobj_sp;
945 const_valobj_sp->SetName (persistent_variable_name);
946 }
947 else
Jim Ingham78a685a2011-04-16 00:01:13948 {
Jim Ingham2837b762011-05-04 03:43:18949 if (use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13950 {
Jim Ingham2837b762011-05-04 03:43:18951 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13952 if (dynamic_sp)
953 result_valobj_sp = dynamic_sp;
954 }
955
Jim Ingham6035b672011-03-31 00:19:25956 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Ingham78a685a2011-04-16 00:01:13957 }
Greg Clayton8b2fe6d2010-12-14 02:59:59958
Sean Callanan92adcac2011-01-13 08:53:35959 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
960
Greg Clayton8b2fe6d2010-12-14 02:59:59961 result_valobj_sp = const_valobj_sp;
962
Sean Callanan92adcac2011-01-13 08:53:35963 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
964 assert (clang_expr_variable_sp.get());
965
966 // Set flags and live data as appropriate
967
968 const Value &result_value = live_valobj_sp->GetValue();
969
970 switch (result_value.GetValueType())
971 {
972 case Value::eValueTypeHostAddress:
973 case Value::eValueTypeFileAddress:
974 // we don't do anything with these for now
975 break;
976 case Value::eValueTypeScalar:
977 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
978 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
979 break;
980 case Value::eValueTypeLoadAddress:
981 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
982 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
983 break;
984 }
Greg Clayton8b2fe6d2010-12-14 02:59:59985 }
986 else
987 {
988 // Make sure we aren't just trying to see the value of a persistent
989 // variable (something like "$0")
Greg Clayton3e06bd92011-01-09 21:07:35990 lldb::ClangExpressionVariableSP persistent_var_sp;
991 // Only check for persistent variables the expression starts with a '$'
992 if (expr_cstr[0] == '$')
993 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
994
Greg Clayton8b2fe6d2010-12-14 02:59:59995 if (persistent_var_sp)
996 {
997 result_valobj_sp = persistent_var_sp->GetValueObject ();
998 execution_results = eExecutionCompleted;
999 }
1000 else
1001 {
1002 const char *prefix = GetExpressionPrefixContentsAsCString();
1003
1004 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan92adcac2011-01-13 08:53:351005 unwind_on_error,
Greg Clayton8b2fe6d2010-12-14 02:59:591006 expr_cstr,
1007 prefix,
1008 result_valobj_sp);
1009 }
1010 }
Jim Ingham6026ca32011-05-12 02:06:141011
1012 m_suppress_stop_hooks = old_suppress_value;
1013
Greg Clayton8b2fe6d2010-12-14 02:59:591014 return execution_results;
1015}
1016
Greg Claytonf3ef3d22011-05-22 22:46:531017lldb::addr_t
1018Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1019{
1020 addr_t code_addr = load_addr;
1021 switch (m_arch.GetMachine())
1022 {
1023 case llvm::Triple::arm:
1024 case llvm::Triple::thumb:
1025 switch (addr_class)
1026 {
1027 case eAddressClassData:
1028 case eAddressClassDebug:
1029 return LLDB_INVALID_ADDRESS;
1030
1031 case eAddressClassUnknown:
1032 case eAddressClassInvalid:
1033 case eAddressClassCode:
1034 case eAddressClassCodeAlternateISA:
1035 case eAddressClassRuntime:
1036 // Check if bit zero it no set?
1037 if ((code_addr & 1ull) == 0)
1038 {
1039 // Bit zero isn't set, check if the address is a multiple of 2?
1040 if (code_addr & 2ull)
1041 {
1042 // The address is a multiple of 2 so it must be thumb, set bit zero
1043 code_addr |= 1ull;
1044 }
1045 else if (addr_class == eAddressClassCodeAlternateISA)
1046 {
1047 // We checked the address and the address claims to be the alternate ISA
1048 // which means thumb, so set bit zero.
1049 code_addr |= 1ull;
1050 }
1051 }
1052 break;
1053 }
1054 break;
1055
1056 default:
1057 break;
1058 }
1059 return code_addr;
1060}
1061
1062lldb::addr_t
1063Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1064{
1065 addr_t opcode_addr = load_addr;
1066 switch (m_arch.GetMachine())
1067 {
1068 case llvm::Triple::arm:
1069 case llvm::Triple::thumb:
1070 switch (addr_class)
1071 {
1072 case eAddressClassData:
1073 case eAddressClassDebug:
1074 return LLDB_INVALID_ADDRESS;
1075
1076 case eAddressClassInvalid:
1077 case eAddressClassUnknown:
1078 case eAddressClassCode:
1079 case eAddressClassCodeAlternateISA:
1080 case eAddressClassRuntime:
1081 opcode_addr &= ~(1ull);
1082 break;
1083 }
1084 break;
1085
1086 default:
1087 break;
1088 }
1089 return opcode_addr;
1090}
1091
Jim Ingham9575d842011-03-11 03:53:591092lldb::user_id_t
1093Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1094{
1095 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1096 new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1097 m_stop_hooks[new_uid] = new_hook_sp;
1098 return new_uid;
1099}
1100
1101bool
1102Target::RemoveStopHookByID (lldb::user_id_t user_id)
1103{
1104 size_t num_removed;
1105 num_removed = m_stop_hooks.erase (user_id);
1106 if (num_removed == 0)
1107 return false;
1108 else
1109 return true;
1110}
1111
1112void
1113Target::RemoveAllStopHooks ()
1114{
1115 m_stop_hooks.clear();
1116}
1117
1118Target::StopHookSP
1119Target::GetStopHookByID (lldb::user_id_t user_id)
1120{
1121 StopHookSP found_hook;
1122
1123 StopHookCollection::iterator specified_hook_iter;
1124 specified_hook_iter = m_stop_hooks.find (user_id);
1125 if (specified_hook_iter != m_stop_hooks.end())
1126 found_hook = (*specified_hook_iter).second;
1127 return found_hook;
1128}
1129
1130bool
1131Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1132{
1133 StopHookCollection::iterator specified_hook_iter;
1134 specified_hook_iter = m_stop_hooks.find (user_id);
1135 if (specified_hook_iter == m_stop_hooks.end())
1136 return false;
1137
1138 (*specified_hook_iter).second->SetIsActive (active_state);
1139 return true;
1140}
1141
1142void
1143Target::SetAllStopHooksActiveState (bool active_state)
1144{
1145 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1146 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1147 {
1148 (*pos).second->SetIsActive (active_state);
1149 }
1150}
1151
1152void
1153Target::RunStopHooks ()
1154{
Jim Ingham6026ca32011-05-12 02:06:141155 if (m_suppress_stop_hooks)
1156 return;
1157
Jim Ingham9575d842011-03-11 03:53:591158 if (!m_process_sp)
1159 return;
1160
1161 if (m_stop_hooks.empty())
1162 return;
1163
1164 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1165
1166 // If there aren't any active stop hooks, don't bother either:
1167 bool any_active_hooks = false;
1168 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1169 {
1170 if ((*pos).second->IsActive())
1171 {
1172 any_active_hooks = true;
1173 break;
1174 }
1175 }
1176 if (!any_active_hooks)
1177 return;
1178
1179 CommandReturnObject result;
1180
1181 std::vector<ExecutionContext> exc_ctx_with_reasons;
1182 std::vector<SymbolContext> sym_ctx_with_reasons;
1183
1184 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1185 size_t num_threads = cur_threadlist.GetSize();
1186 for (size_t i = 0; i < num_threads; i++)
1187 {
1188 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1189 if (cur_thread_sp->ThreadStoppedForAReason())
1190 {
1191 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1192 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1193 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1194 }
1195 }
1196
1197 // If no threads stopped for a reason, don't run the stop-hooks.
1198 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1199 if (num_exe_ctx == 0)
1200 return;
1201
Caroline Tice969ed3d12011-05-02 20:41:461202 StreamSP output_stream (new StreamAsynchronousIO (m_debugger.GetCommandInterpreter(),
1203 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
1204 StreamSP error_stream (new StreamAsynchronousIO (m_debugger.GetCommandInterpreter(),
1205 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
1206 result.SetImmediateOutputStream (output_stream);
1207 result.SetImmediateErrorStream (error_stream);
Jim Ingham9575d842011-03-11 03:53:591208
1209 bool keep_going = true;
1210 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:271211 bool print_hook_header;
1212 bool print_thread_header;
1213
1214 if (num_exe_ctx == 1)
1215 print_thread_header = false;
1216 else
1217 print_thread_header = true;
1218
1219 if (m_stop_hooks.size() == 1)
1220 print_hook_header = false;
1221 else
1222 print_hook_header = true;
1223
Jim Ingham9575d842011-03-11 03:53:591224 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1225 {
1226 // result.Clear();
1227 StopHookSP cur_hook_sp = (*pos).second;
1228 if (!cur_hook_sp->IsActive())
1229 continue;
1230
1231 bool any_thread_matched = false;
1232 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1233 {
1234 if ((cur_hook_sp->GetSpecifier () == NULL
1235 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1236 && (cur_hook_sp->GetThreadSpecifier() == NULL
1237 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread)))
1238 {
1239 if (!hooks_ran)
1240 {
Jim Ingham381e25b2011-03-22 01:47:271241 result.AppendMessage("\n** Stop Hooks **");
Jim Ingham9575d842011-03-11 03:53:591242 hooks_ran = true;
1243 }
Jim Ingham381e25b2011-03-22 01:47:271244 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:591245 {
1246 result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
1247 any_thread_matched = true;
1248 }
1249
Jim Ingham381e25b2011-03-22 01:47:271250 if (print_thread_header)
1251 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID());
Jim Ingham9575d842011-03-11 03:53:591252
1253 bool stop_on_continue = true;
1254 bool stop_on_error = true;
1255 bool echo_commands = false;
1256 bool print_results = true;
1257 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton32e0a752011-03-30 18:16:511258 &exc_ctx_with_reasons[i],
1259 stop_on_continue,
1260 stop_on_error,
1261 echo_commands,
1262 print_results,
1263 result);
Jim Ingham9575d842011-03-11 03:53:591264
1265 // If the command started the target going again, we should bag out of
1266 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:511267 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1268 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:591269 {
1270 result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
1271 keep_going = false;
1272 }
1273 }
1274 }
1275 }
1276 if (hooks_ran)
1277 result.AppendMessage ("\n** End Stop Hooks **\n");
Caroline Tice969ed3d12011-05-02 20:41:461278
1279 result.GetImmediateOutputStream()->Flush();
1280 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:591281}
1282
1283//--------------------------------------------------------------
1284// class Target::StopHook
1285//--------------------------------------------------------------
1286
1287
1288Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1289 UserID (uid),
1290 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:591291 m_commands (),
1292 m_specifier_sp (),
Stephen Wilson71c21d12011-04-11 19:41:401293 m_thread_spec_ap(NULL),
1294 m_active (true)
Jim Ingham9575d842011-03-11 03:53:591295{
1296}
1297
1298Target::StopHook::StopHook (const StopHook &rhs) :
1299 UserID (rhs.GetID()),
1300 m_target_sp (rhs.m_target_sp),
1301 m_commands (rhs.m_commands),
1302 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilson71c21d12011-04-11 19:41:401303 m_thread_spec_ap (NULL),
1304 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:591305{
1306 if (rhs.m_thread_spec_ap.get() != NULL)
1307 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1308}
1309
1310
1311Target::StopHook::~StopHook ()
1312{
1313}
1314
1315void
1316Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1317{
1318 m_thread_spec_ap.reset (specifier);
1319}
1320
1321
1322void
1323Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1324{
1325 int indent_level = s->GetIndentLevel();
1326
1327 s->SetIndentLevel(indent_level + 2);
1328
1329 s->Printf ("Hook: %d\n", GetID());
1330 if (m_active)
1331 s->Indent ("State: enabled\n");
1332 else
1333 s->Indent ("State: disabled\n");
1334
1335 if (m_specifier_sp)
1336 {
1337 s->Indent();
1338 s->PutCString ("Specifier:\n");
1339 s->SetIndentLevel (indent_level + 4);
1340 m_specifier_sp->GetDescription (s, level);
1341 s->SetIndentLevel (indent_level + 2);
1342 }
1343
1344 if (m_thread_spec_ap.get() != NULL)
1345 {
1346 StreamString tmp;
1347 s->Indent("Thread:\n");
1348 m_thread_spec_ap->GetDescription (&tmp, level);
1349 s->SetIndentLevel (indent_level + 4);
1350 s->Indent (tmp.GetData());
1351 s->PutCString ("\n");
1352 s->SetIndentLevel (indent_level + 2);
1353 }
1354
1355 s->Indent ("Commands: \n");
1356 s->SetIndentLevel (indent_level + 4);
1357 uint32_t num_commands = m_commands.GetSize();
1358 for (uint32_t i = 0; i < num_commands; i++)
1359 {
1360 s->Indent(m_commands.GetStringAtIndex(i));
1361 s->PutCString ("\n");
1362 }
1363 s->SetIndentLevel (indent_level);
1364}
1365
1366
Caroline Ticedaccaa92010-09-20 20:44:431367//--------------------------------------------------------------
1368// class Target::SettingsController
1369//--------------------------------------------------------------
1370
1371Target::SettingsController::SettingsController () :
1372 UserSettingsController ("target", Debugger::GetSettingsController()),
1373 m_default_architecture ()
1374{
1375 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1376 InstanceSettings::GetDefaultName().AsCString()));
1377}
1378
1379Target::SettingsController::~SettingsController ()
1380{
1381}
1382
1383lldb::InstanceSettingsSP
1384Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1385{
Greg Claytondbe54502010-11-19 03:46:011386 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1387 false,
1388 instance_name);
Caroline Ticedaccaa92010-09-20 20:44:431389 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1390 return new_settings_sp;
1391}
1392
Caroline Ticedaccaa92010-09-20 20:44:431393
Jim Ingham78a685a2011-04-16 00:01:131394#define TSC_DEFAULT_ARCH "default-arch"
1395#define TSC_EXPR_PREFIX "expr-prefix"
Jim Ingham78a685a2011-04-16 00:01:131396#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
Greg Clayton385aa282011-04-22 03:55:061397#define TSC_SKIP_PROLOGUE "skip-prologue"
Greg Clayton7e14f912011-04-23 02:04:551398#define TSC_SOURCE_MAP "source-map"
Greg Claytonbfe5f3b2011-02-18 01:44:251399
1400
1401static const ConstString &
1402GetSettingNameForDefaultArch ()
1403{
1404 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytonbfe5f3b2011-02-18 01:44:251405 return g_const_string;
Caroline Ticedaccaa92010-09-20 20:44:431406}
1407
Greg Claytonbfe5f3b2011-02-18 01:44:251408static const ConstString &
1409GetSettingNameForExpressionPrefix ()
1410{
1411 static ConstString g_const_string (TSC_EXPR_PREFIX);
1412 return g_const_string;
1413}
1414
1415static const ConstString &
Jim Ingham78a685a2011-04-16 00:01:131416GetSettingNameForPreferDynamicValue ()
1417{
1418 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
1419 return g_const_string;
1420}
1421
Greg Clayton7e14f912011-04-23 02:04:551422static const ConstString &
1423GetSettingNameForSourcePathMap ()
1424{
1425 static ConstString g_const_string (TSC_SOURCE_MAP);
1426 return g_const_string;
1427}
Greg Claytonbfe5f3b2011-02-18 01:44:251428
Greg Clayton385aa282011-04-22 03:55:061429static const ConstString &
1430GetSettingNameForSkipPrologue ()
1431{
1432 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
1433 return g_const_string;
1434}
1435
1436
1437
Caroline Ticedaccaa92010-09-20 20:44:431438bool
1439Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1440 const char *index_value,
1441 const char *value,
1442 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:541443 const VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:431444 Error&err)
1445{
Greg Claytonbfe5f3b2011-02-18 01:44:251446 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:431447 {
Greg Claytoneb0103f2011-04-07 22:46:351448 m_default_architecture.SetTriple (value, NULL);
Greg Clayton64195a22011-02-23 00:35:021449 if (!m_default_architecture.IsValid())
1450 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Ticedaccaa92010-09-20 20:44:431451 }
1452 return true;
1453}
1454
1455
1456bool
1457Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1458 StringList &value,
1459 Error &err)
1460{
Greg Claytonbfe5f3b2011-02-18 01:44:251461 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:431462 {
Greg Clayton307de252010-10-27 02:06:371463 // If the arch is invalid (the default), don't show a string for it
1464 if (m_default_architecture.IsValid())
Greg Clayton64195a22011-02-23 00:35:021465 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Ticedaccaa92010-09-20 20:44:431466 return true;
1467 }
1468 else
1469 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1470
1471 return false;
1472}
1473
1474//--------------------------------------------------------------
1475// class TargetInstanceSettings
1476//--------------------------------------------------------------
1477
Greg Clayton85851dd2010-12-04 00:10:171478TargetInstanceSettings::TargetInstanceSettings
1479(
1480 UserSettingsController &owner,
1481 bool live_instance,
1482 const char *name
1483) :
Greg Claytonbfe5f3b2011-02-18 01:44:251484 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Clayton7e14f912011-04-23 02:04:551485 m_expr_prefix_file (),
1486 m_expr_prefix_contents_sp (),
Jim Ingham2837b762011-05-04 03:43:181487 m_prefer_dynamic_value (2),
Greg Clayton7e14f912011-04-23 02:04:551488 m_skip_prologue (true, true),
1489 m_source_map (NULL, NULL)
Caroline Ticedaccaa92010-09-20 20:44:431490{
1491 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1492 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1493 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1494 // This is true for CreateInstanceName() too.
1495
1496 if (GetInstanceName () == InstanceSettings::InvalidName())
1497 {
1498 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1499 m_owner.RegisterInstanceSettings (this);
1500 }
1501
1502 if (live_instance)
1503 {
1504 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1505 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:431506 }
1507}
1508
1509TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton7e14f912011-04-23 02:04:551510 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
1511 m_expr_prefix_file (rhs.m_expr_prefix_file),
1512 m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
1513 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
1514 m_skip_prologue (rhs.m_skip_prologue),
1515 m_source_map (rhs.m_source_map)
Caroline Ticedaccaa92010-09-20 20:44:431516{
1517 if (m_instance_name != InstanceSettings::GetDefaultName())
1518 {
1519 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1520 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:431521 }
1522}
1523
1524TargetInstanceSettings::~TargetInstanceSettings ()
1525{
1526}
1527
1528TargetInstanceSettings&
1529TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1530{
1531 if (this != &rhs)
1532 {
1533 }
1534
1535 return *this;
1536}
1537
Caroline Ticedaccaa92010-09-20 20:44:431538void
1539TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1540 const char *index_value,
1541 const char *value,
1542 const ConstString &instance_name,
1543 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:541544 VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:431545 Error &err,
1546 bool pending)
1547{
Greg Claytonbfe5f3b2011-02-18 01:44:251548 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:031549 {
Greg Clayton7e14f912011-04-23 02:04:551550 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
1551 if (err.Success())
Sean Callanan322f5292010-10-29 00:29:031552 {
Greg Clayton7e14f912011-04-23 02:04:551553 switch (op)
Sean Callanan322f5292010-10-29 00:29:031554 {
Greg Clayton7e14f912011-04-23 02:04:551555 default:
1556 break;
1557 case eVarSetOperationAssign:
1558 case eVarSetOperationAppend:
Sean Callanan322f5292010-10-29 00:29:031559 {
Greg Clayton7e14f912011-04-23 02:04:551560 if (!m_expr_prefix_file.GetCurrentValue().Exists())
1561 {
1562 err.SetErrorToGenericError ();
1563 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1564 return;
1565 }
1566
1567 m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
1568
1569 if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
1570 {
1571 err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
1572 m_expr_prefix_contents_sp.reset();
1573 }
Sean Callanan322f5292010-10-29 00:29:031574 }
Greg Clayton7e14f912011-04-23 02:04:551575 break;
1576 case eVarSetOperationClear:
1577 m_expr_prefix_contents_sp.reset();
Sean Callanan322f5292010-10-29 00:29:031578 }
Sean Callanan322f5292010-10-29 00:29:031579 }
1580 }
Jim Ingham78a685a2011-04-16 00:01:131581 else if (var_name == GetSettingNameForPreferDynamicValue())
1582 {
Jim Ingham2837b762011-05-04 03:43:181583 int new_value;
1584 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
1585 if (err.Success())
1586 m_prefer_dynamic_value = new_value;
Greg Clayton385aa282011-04-22 03:55:061587 }
1588 else if (var_name == GetSettingNameForSkipPrologue())
1589 {
Greg Clayton7e14f912011-04-23 02:04:551590 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
1591 }
1592 else if (var_name == GetSettingNameForSourcePathMap ())
1593 {
1594 switch (op)
1595 {
1596 case eVarSetOperationReplace:
1597 case eVarSetOperationInsertBefore:
1598 case eVarSetOperationInsertAfter:
1599 case eVarSetOperationRemove:
1600 default:
1601 break;
1602 case eVarSetOperationAssign:
1603 m_source_map.Clear(true);
1604 // Fall through to append....
1605 case eVarSetOperationAppend:
1606 {
1607 Args args(value);
1608 const uint32_t argc = args.GetArgumentCount();
1609 if (argc & 1 || argc == 0)
1610 {
1611 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
1612 }
1613 else
1614 {
1615 char resolved_new_path[PATH_MAX];
1616 FileSpec file_spec;
1617 const char *old_path;
1618 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
1619 {
1620 const char *new_path = args.GetArgumentAtIndex(idx+1);
1621 assert (new_path); // We have an even number of paths, this shouldn't happen!
1622
1623 file_spec.SetFile(new_path, true);
1624 if (file_spec.Exists())
1625 {
1626 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
1627 {
1628 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
1629 return;
1630 }
1631 }
1632 else
1633 {
1634 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
1635 return;
1636 }
1637 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
1638 }
1639 }
1640 }
1641 break;
1642
1643 case eVarSetOperationClear:
1644 m_source_map.Clear(true);
1645 break;
1646 }
Jim Ingham78a685a2011-04-16 00:01:131647 }
Caroline Ticedaccaa92010-09-20 20:44:431648}
1649
1650void
Greg Claytonbfe5f3b2011-02-18 01:44:251651TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Ticedaccaa92010-09-20 20:44:431652{
Sean Callanan322f5292010-10-29 00:29:031653 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1654
1655 if (!new_settings_ptr)
1656 return;
1657
Greg Clayton7e14f912011-04-23 02:04:551658 m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
1659 m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
1660 m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
1661 m_skip_prologue = new_settings_ptr->m_skip_prologue;
Caroline Ticedaccaa92010-09-20 20:44:431662}
1663
Caroline Tice12cecd72010-09-20 21:37:421664bool
Caroline Ticedaccaa92010-09-20 20:44:431665TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1666 const ConstString &var_name,
1667 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:421668 Error *err)
Caroline Ticedaccaa92010-09-20 20:44:431669{
Greg Claytonbfe5f3b2011-02-18 01:44:251670 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:031671 {
Greg Clayton7e14f912011-04-23 02:04:551672 char path[PATH_MAX];
1673 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
1674 if (path_len > 0)
1675 value.AppendString (path, path_len);
Sean Callanan322f5292010-10-29 00:29:031676 }
Jim Ingham78a685a2011-04-16 00:01:131677 else if (var_name == GetSettingNameForPreferDynamicValue())
1678 {
Jim Ingham2837b762011-05-04 03:43:181679 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Ingham78a685a2011-04-16 00:01:131680 }
Greg Clayton385aa282011-04-22 03:55:061681 else if (var_name == GetSettingNameForSkipPrologue())
1682 {
1683 if (m_skip_prologue)
1684 value.AppendString ("true");
1685 else
1686 value.AppendString ("false");
1687 }
Greg Clayton7e14f912011-04-23 02:04:551688 else if (var_name == GetSettingNameForSourcePathMap ())
1689 {
1690 }
Sean Callanan322f5292010-10-29 00:29:031691 else
1692 {
1693 if (err)
1694 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1695 return false;
1696 }
1697
1698 return true;
Caroline Ticedaccaa92010-09-20 20:44:431699}
1700
1701const ConstString
1702TargetInstanceSettings::CreateInstanceName ()
1703{
Caroline Ticedaccaa92010-09-20 20:44:431704 StreamString sstr;
Caroline Tice1559a462010-09-27 00:30:101705 static int instance_count = 1;
1706
Caroline Ticedaccaa92010-09-20 20:44:431707 sstr.Printf ("target_%d", instance_count);
1708 ++instance_count;
1709
1710 const ConstString ret_val (sstr.GetData());
1711 return ret_val;
1712}
1713
1714//--------------------------------------------------
1715// Target::SettingsController Variable Tables
1716//--------------------------------------------------
Jim Ingham2837b762011-05-04 03:43:181717OptionEnumValueElement
1718TargetInstanceSettings::g_dynamic_value_types[] =
1719{
Greg Clayton5d2fbfe2011-05-30 00:39:481720{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
1721{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
1722{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham2837b762011-05-04 03:43:181723{ 0, NULL, NULL }
1724};
Caroline Ticedaccaa92010-09-20 20:44:431725
1726SettingEntry
1727Target::SettingsController::global_settings_table[] =
1728{
Greg Claytonbfe5f3b2011-02-18 01:44:251729 // var-name var-type default enum init'd hidden help-text
1730 // ================= ================== =========== ==== ====== ====== =========================================================================
1731 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
1732 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
1733};
1734
Caroline Ticedaccaa92010-09-20 20:44:431735SettingEntry
1736Target::SettingsController::instance_settings_table[] =
1737{
Jim Ingham2837b762011-05-04 03:43:181738 // var-name var-type default enum init'd hidden help-text
1739 // ================= ================== =============== ======================= ====== ====== =========================================================================
1740 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
Greg Clayton5d2fbfe2011-05-30 00:39:481741 { TSC_PREFER_DYNAMIC, eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
1742 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
1743 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
Jim Ingham2837b762011-05-04 03:43:181744 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Ticedaccaa92010-09-20 20:44:431745};