blob: 942d0816585a2086aa1e7310225b678e24343dbf [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/Target.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Breakpoint/BreakpointResolver.h"
17#include "lldb/Breakpoint/BreakpointResolverAddress.h"
18#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
19#include "lldb/Breakpoint/BreakpointResolverName.h"
Greg Clayton427f2902010-12-14 02:59:59 +000020#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Core/Event.h"
22#include "lldb/Core/Log.h"
Caroline Tice4a348082011-05-02 20:41:46 +000023#include "lldb/Core/StreamAsynchronousIO.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
Greg Clayton427f2902010-12-14 02:59:59 +000025#include "lldb/Core/Timer.h"
26#include "lldb/Core/ValueObject.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000027#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Host/Host.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000029#include "lldb/Interpreter/CommandInterpreter.h"
30#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/lldb-private-log.h"
32#include "lldb/Symbol/ObjectFile.h"
33#include "lldb/Target/Process.h"
Greg Clayton427f2902010-12-14 02:59:59 +000034#include "lldb/Target/StackFrame.h"
Jim Inghamd60d94a2011-03-11 03:53:59 +000035#include "lldb/Target/Thread.h"
36#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000037
38using namespace lldb;
39using namespace lldb_private;
40
41//----------------------------------------------------------------------
42// Target constructor
43//----------------------------------------------------------------------
Greg Clayton24bc5d92011-03-30 18:16:51 +000044Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
45 Broadcaster ("lldb.target"),
46 ExecutionContextScope (),
Greg Claytonc0c1b0c2010-11-19 03:46:01 +000047 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton63094e02010-06-23 01:19:29 +000048 m_debugger (debugger),
Greg Clayton24bc5d92011-03-30 18:16:51 +000049 m_platform_sp (platform_sp),
Greg Claytonbdcda462010-12-20 20:49:23 +000050 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton24bc5d92011-03-30 18:16:51 +000051 m_arch (target_arch),
52 m_images (),
Greg Claytoneea26402010-09-14 23:36:40 +000053 m_section_load_list (),
Chris Lattner24943d22010-06-08 16:52:24 +000054 m_breakpoint_list (false),
55 m_internal_breakpoint_list (true),
Greg Clayton24bc5d92011-03-30 18:16:51 +000056 m_process_sp (),
57 m_search_filter_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000058 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton427f2902010-12-14 02:59:59 +000059 m_scratch_ast_context_ap (NULL),
Jim Inghamd60d94a2011-03-11 03:53:59 +000060 m_persistent_variables (),
Greg Clayton24bc5d92011-03-30 18:16:51 +000061 m_stop_hooks (),
62 m_stop_hook_next_id (0)
Chris Lattner24943d22010-06-08 16:52:24 +000063{
Greg Clayton49ce6822010-10-31 03:01:06 +000064 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
65 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
66 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
67
Greg Claytone005f2c2010-11-06 01:53:30 +000068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000069 if (log)
70 log->Printf ("%p Target::Target()", this);
71}
72
73//----------------------------------------------------------------------
74// Destructor
75//----------------------------------------------------------------------
76Target::~Target()
77{
Greg Claytone005f2c2010-11-06 01:53:30 +000078 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000079 if (log)
80 log->Printf ("%p Target::~Target()", this);
81 DeleteCurrentProcess ();
82}
83
84void
Caroline Tice7826c882010-10-26 03:11:13 +000085Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner24943d22010-06-08 16:52:24 +000086{
Greg Clayton3fed8b92010-10-08 00:21:05 +000087// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Tice7826c882010-10-26 03:11:13 +000088 if (description_level != lldb::eDescriptionLevelBrief)
89 {
90 s->Indent();
91 s->PutCString("Target\n");
92 s->IndentMore();
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000093 m_images.Dump(s);
94 m_breakpoint_list.Dump(s);
95 m_internal_breakpoint_list.Dump(s);
96 s->IndentLess();
Caroline Tice7826c882010-10-26 03:11:13 +000097 }
98 else
99 {
Jim Ingham53fe9cc2011-05-12 01:12:28 +0000100 if (GetExecutableModule())
101 s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString());
102 else
103 s->PutCString ("No executable module.");
Caroline Tice7826c882010-10-26 03:11:13 +0000104 }
Chris Lattner24943d22010-06-08 16:52:24 +0000105}
106
107void
108Target::DeleteCurrentProcess ()
109{
110 if (m_process_sp.get())
111 {
Greg Clayton49480b12010-09-14 23:52:43 +0000112 m_section_load_list.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000113 if (m_process_sp->IsAlive())
114 m_process_sp->Destroy();
Jim Ingham88fa7bd2011-02-16 17:54:55 +0000115
116 m_process_sp->Finalize();
Chris Lattner24943d22010-06-08 16:52:24 +0000117
118 // Do any cleanup of the target we need to do between process instances.
119 // NB It is better to do this before destroying the process in case the
120 // clean up needs some help from the process.
121 m_breakpoint_list.ClearAllBreakpointSites();
122 m_internal_breakpoint_list.ClearAllBreakpointSites();
123 m_process_sp.reset();
124 }
125}
126
127const lldb::ProcessSP &
128Target::CreateProcess (Listener &listener, const char *plugin_name)
129{
130 DeleteCurrentProcess ();
131 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
132 return m_process_sp;
133}
134
135const lldb::ProcessSP &
136Target::GetProcessSP () const
137{
138 return m_process_sp;
139}
140
141lldb::TargetSP
142Target::GetSP()
143{
Greg Clayton63094e02010-06-23 01:19:29 +0000144 return m_debugger.GetTargetList().GetTargetSP(this);
Chris Lattner24943d22010-06-08 16:52:24 +0000145}
146
147BreakpointList &
148Target::GetBreakpointList(bool internal)
149{
150 if (internal)
151 return m_internal_breakpoint_list;
152 else
153 return m_breakpoint_list;
154}
155
156const BreakpointList &
157Target::GetBreakpointList(bool internal) const
158{
159 if (internal)
160 return m_internal_breakpoint_list;
161 else
162 return m_breakpoint_list;
163}
164
165BreakpointSP
166Target::GetBreakpointByID (break_id_t break_id)
167{
168 BreakpointSP bp_sp;
169
170 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
171 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
172 else
173 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
174
175 return bp_sp;
176}
177
178BreakpointSP
179Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
180{
181 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
182 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
183 return CreateBreakpoint (filter_sp, resolver_sp, internal);
184}
185
186
187BreakpointSP
Greg Clayton33ed1702010-08-24 00:45:41 +0000188Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000189{
Chris Lattner24943d22010-06-08 16:52:24 +0000190 Address so_addr;
191 // Attempt to resolve our load address if possible, though it is ok if
192 // it doesn't resolve to section/offset.
193
Greg Clayton33ed1702010-08-24 00:45:41 +0000194 // Try and resolve as a load address if possible
Greg Claytoneea26402010-09-14 23:36:40 +0000195 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton33ed1702010-08-24 00:45:41 +0000196 if (!so_addr.IsValid())
197 {
198 // The address didn't resolve, so just set this as an absolute address
199 so_addr.SetOffset (addr);
200 }
201 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner24943d22010-06-08 16:52:24 +0000202 return bp_sp;
203}
204
205BreakpointSP
206Target::CreateBreakpoint (Address &addr, bool internal)
207{
208 TargetSP target_sp = this->GetSP();
209 SearchFilterSP filter_sp(new SearchFilter (target_sp));
210 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
211 return CreateBreakpoint (filter_sp, resolver_sp, internal);
212}
213
214BreakpointSP
Greg Clayton12bec712010-06-28 21:30:43 +0000215Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Chris Lattner24943d22010-06-08 16:52:24 +0000216{
Greg Clayton12bec712010-06-28 21:30:43 +0000217 BreakpointSP bp_sp;
218 if (func_name)
219 {
220 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
221 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact));
222 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
223 }
224 return bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000225}
226
227
228SearchFilterSP
229Target::GetSearchFilterForModule (const FileSpec *containingModule)
230{
231 SearchFilterSP filter_sp;
232 lldb::TargetSP target_sp = this->GetSP();
233 if (containingModule != NULL)
234 {
235 // TODO: We should look into sharing module based search filters
236 // across many breakpoints like we do for the simple target based one
237 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
238 }
239 else
240 {
241 if (m_search_filter_sp.get() == NULL)
242 m_search_filter_sp.reset (new SearchFilter (target_sp));
243 filter_sp = m_search_filter_sp;
244 }
245 return filter_sp;
246}
247
248BreakpointSP
249Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal)
250{
251 SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
252 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex));
253
254 return CreateBreakpoint (filter_sp, resolver_sp, internal);
255}
256
257BreakpointSP
258Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
259{
260 BreakpointSP bp_sp;
261 if (filter_sp && resolver_sp)
262 {
263 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
264 resolver_sp->SetBreakpoint (bp_sp.get());
265
266 if (internal)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000267 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000268 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000269 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000270
Greg Claytone005f2c2010-11-06 01:53:30 +0000271 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000272 if (log)
273 {
274 StreamString s;
275 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
276 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
277 }
278
Chris Lattner24943d22010-06-08 16:52:24 +0000279 bp_sp->ResolveBreakpoint();
280 }
Jim Inghamd1686902010-10-14 23:45:03 +0000281
282 if (!internal && bp_sp)
283 {
284 m_last_created_breakpoint = bp_sp;
285 }
286
Chris Lattner24943d22010-06-08 16:52:24 +0000287 return bp_sp;
288}
289
290void
291Target::RemoveAllBreakpoints (bool internal_also)
292{
Greg Claytone005f2c2010-11-06 01:53:30 +0000293 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000294 if (log)
295 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
296
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000297 m_breakpoint_list.RemoveAll (true);
Chris Lattner24943d22010-06-08 16:52:24 +0000298 if (internal_also)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000299 m_internal_breakpoint_list.RemoveAll (false);
Jim Inghamd1686902010-10-14 23:45:03 +0000300
301 m_last_created_breakpoint.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000302}
303
304void
305Target::DisableAllBreakpoints (bool internal_also)
306{
Greg Claytone005f2c2010-11-06 01:53:30 +0000307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000308 if (log)
309 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
310
311 m_breakpoint_list.SetEnabledAll (false);
312 if (internal_also)
313 m_internal_breakpoint_list.SetEnabledAll (false);
314}
315
316void
317Target::EnableAllBreakpoints (bool internal_also)
318{
Greg Claytone005f2c2010-11-06 01:53:30 +0000319 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000320 if (log)
321 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
322
323 m_breakpoint_list.SetEnabledAll (true);
324 if (internal_also)
325 m_internal_breakpoint_list.SetEnabledAll (true);
326}
327
328bool
329Target::RemoveBreakpointByID (break_id_t break_id)
330{
Greg Claytone005f2c2010-11-06 01:53:30 +0000331 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000332 if (log)
333 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
334
335 if (DisableBreakpointByID (break_id))
336 {
337 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000338 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000339 else
Jim Inghamd1686902010-10-14 23:45:03 +0000340 {
Greg Clayton22c9e0d2011-01-24 23:35:47 +0000341 if (m_last_created_breakpoint)
342 {
343 if (m_last_created_breakpoint->GetID() == break_id)
344 m_last_created_breakpoint.reset();
345 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000346 m_breakpoint_list.Remove(break_id, true);
Jim Inghamd1686902010-10-14 23:45:03 +0000347 }
Chris Lattner24943d22010-06-08 16:52:24 +0000348 return true;
349 }
350 return false;
351}
352
353bool
354Target::DisableBreakpointByID (break_id_t break_id)
355{
Greg Claytone005f2c2010-11-06 01:53:30 +0000356 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000357 if (log)
358 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
359
360 BreakpointSP bp_sp;
361
362 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
363 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
364 else
365 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
366 if (bp_sp)
367 {
368 bp_sp->SetEnabled (false);
369 return true;
370 }
371 return false;
372}
373
374bool
375Target::EnableBreakpointByID (break_id_t break_id)
376{
Greg Claytone005f2c2010-11-06 01:53:30 +0000377 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000378 if (log)
379 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
380 __FUNCTION__,
381 break_id,
382 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
383
384 BreakpointSP bp_sp;
385
386 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
387 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
388 else
389 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
390
391 if (bp_sp)
392 {
393 bp_sp->SetEnabled (true);
394 return true;
395 }
396 return false;
397}
398
399ModuleSP
400Target::GetExecutableModule ()
401{
402 ModuleSP executable_sp;
403 if (m_images.GetSize() > 0)
404 executable_sp = m_images.GetModuleAtIndex(0);
405 return executable_sp;
406}
407
408void
409Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
410{
411 m_images.Clear();
412 m_scratch_ast_context_ap.reset();
413
414 if (executable_sp.get())
415 {
416 Timer scoped_timer (__PRETTY_FUNCTION__,
417 "Target::SetExecutableModule (executable = '%s/%s')",
418 executable_sp->GetFileSpec().GetDirectory().AsCString(),
419 executable_sp->GetFileSpec().GetFilename().AsCString());
420
421 m_images.Append(executable_sp); // The first image is our exectuable file
422
Jim Ingham7508e732010-08-09 23:31:02 +0000423 // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000424 if (!m_arch.IsValid())
425 m_arch = executable_sp->GetArchitecture();
Jim Ingham7508e732010-08-09 23:31:02 +0000426
Chris Lattner24943d22010-06-08 16:52:24 +0000427 FileSpecList dependent_files;
Greg Claytone4b9c1f2011-03-08 22:40:15 +0000428 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Chris Lattner24943d22010-06-08 16:52:24 +0000429
430 if (executable_objfile)
431 {
432 executable_objfile->GetDependentModules(dependent_files);
433 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
434 {
Greg Claytonb1888f22011-03-19 01:12:21 +0000435 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
436 FileSpec platform_dependent_file_spec;
437 if (m_platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000438 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonb1888f22011-03-19 01:12:21 +0000439 else
440 platform_dependent_file_spec = dependent_file_spec;
441
442 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton24bc5d92011-03-30 18:16:51 +0000443 m_arch));
Chris Lattner24943d22010-06-08 16:52:24 +0000444 if (image_module_sp.get())
445 {
446 //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY
447 ObjectFile *objfile = image_module_sp->GetObjectFile();
448 if (objfile)
449 objfile->GetDependentModules(dependent_files);
450 }
451 }
452 }
453
454 // Now see if we know the target triple, and if so, create our scratch AST context:
Greg Clayton24bc5d92011-03-30 18:16:51 +0000455 if (m_arch.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000456 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000457 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Chris Lattner24943d22010-06-08 16:52:24 +0000458 }
459 }
Caroline Tice1ebef442010-09-27 00:30:10 +0000460
461 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +0000462}
463
464
Jim Ingham7508e732010-08-09 23:31:02 +0000465bool
466Target::SetArchitecture (const ArchSpec &arch_spec)
467{
Greg Clayton24bc5d92011-03-30 18:16:51 +0000468 if (m_arch == arch_spec)
Jim Ingham7508e732010-08-09 23:31:02 +0000469 {
470 // If we're setting the architecture to our current architecture, we
471 // don't need to do anything.
472 return true;
473 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000474 else if (!m_arch.IsValid())
Jim Ingham7508e732010-08-09 23:31:02 +0000475 {
476 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton24bc5d92011-03-30 18:16:51 +0000477 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000478 return true;
479 }
480 else
481 {
482 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton24bc5d92011-03-30 18:16:51 +0000483 m_arch = arch_spec;
Jim Ingham7508e732010-08-09 23:31:02 +0000484 ModuleSP executable_sp = GetExecutableModule ();
485 m_images.Clear();
486 m_scratch_ast_context_ap.reset();
Jim Ingham7508e732010-08-09 23:31:02 +0000487 // Need to do something about unsetting breakpoints.
488
489 if (executable_sp)
490 {
491 FileSpec exec_file_spec = executable_sp->GetFileSpec();
492 Error error = ModuleList::GetSharedModule(exec_file_spec,
493 arch_spec,
494 NULL,
495 NULL,
496 0,
497 executable_sp,
498 NULL,
499 NULL);
500
501 if (!error.Fail() && executable_sp)
502 {
503 SetExecutableModule (executable_sp, true);
504 return true;
505 }
506 else
507 {
508 return false;
509 }
510 }
511 else
512 {
513 return false;
514 }
515 }
516}
Chris Lattner24943d22010-06-08 16:52:24 +0000517
Chris Lattner24943d22010-06-08 16:52:24 +0000518void
519Target::ModuleAdded (ModuleSP &module_sp)
520{
521 // A module is being added to this target for the first time
522 ModuleList module_list;
523 module_list.Append(module_sp);
524 ModulesDidLoad (module_list);
525}
526
527void
528Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
529{
530 // A module is being added to this target for the first time
531 ModuleList module_list;
532 module_list.Append (old_module_sp);
533 ModulesDidUnload (module_list);
534 module_list.Clear ();
535 module_list.Append (new_module_sp);
536 ModulesDidLoad (module_list);
537}
538
539void
540Target::ModulesDidLoad (ModuleList &module_list)
541{
542 m_breakpoint_list.UpdateBreakpoints (module_list, true);
543 // TODO: make event data that packages up the module_list
544 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
545}
546
547void
548Target::ModulesDidUnload (ModuleList &module_list)
549{
550 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000551
552 // Remove the images from the target image list
553 m_images.Remove(module_list);
554
Chris Lattner24943d22010-06-08 16:52:24 +0000555 // TODO: make event data that packages up the module_list
556 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
557}
558
559size_t
Greg Clayton26100dc2011-01-07 01:57:07 +0000560Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
561{
562 const Section *section = addr.GetSection();
563 if (section && section->GetModule())
564 {
565 ObjectFile *objfile = section->GetModule()->GetObjectFile();
566 if (objfile)
567 {
568 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
569 addr.GetOffset(),
570 dst,
571 dst_len);
572 if (bytes_read > 0)
573 return bytes_read;
574 else
575 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
576 }
577 else
578 {
579 error.SetErrorString("address isn't from a object file");
580 }
581 }
582 else
583 {
584 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
585 }
586 return 0;
587}
588
589size_t
590Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size_t dst_len, Error &error)
Chris Lattner24943d22010-06-08 16:52:24 +0000591{
Chris Lattner24943d22010-06-08 16:52:24 +0000592 error.Clear();
Greg Clayton26100dc2011-01-07 01:57:07 +0000593
Greg Clayton70436352010-06-30 23:03:03 +0000594 bool process_is_valid = m_process_sp && m_process_sp->IsAlive();
595
Greg Clayton26100dc2011-01-07 01:57:07 +0000596 size_t bytes_read = 0;
Greg Clayton889fbd02011-03-26 19:14:58 +0000597 Address resolved_addr;
598 if (!addr.IsSectionOffset())
Greg Clayton70436352010-06-30 23:03:03 +0000599 {
600 if (process_is_valid)
Greg Claytoneea26402010-09-14 23:36:40 +0000601 m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr);
Greg Clayton70436352010-06-30 23:03:03 +0000602 else
Greg Clayton70436352010-06-30 23:03:03 +0000603 m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
Greg Clayton70436352010-06-30 23:03:03 +0000604 }
Greg Clayton889fbd02011-03-26 19:14:58 +0000605 if (!resolved_addr.IsValid())
606 resolved_addr = addr;
Greg Clayton70436352010-06-30 23:03:03 +0000607
Greg Clayton26100dc2011-01-07 01:57:07 +0000608 if (prefer_file_cache)
609 {
610 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
611 if (bytes_read > 0)
612 return bytes_read;
613 }
Greg Clayton70436352010-06-30 23:03:03 +0000614
615 if (process_is_valid)
616 {
Greg Claytoneea26402010-09-14 23:36:40 +0000617 lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this);
Greg Clayton70436352010-06-30 23:03:03 +0000618 if (load_addr == LLDB_INVALID_ADDRESS)
619 {
620 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
621 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
622 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
623 resolved_addr.GetFileAddress());
624 else
625 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
626 }
627 else
628 {
Greg Clayton26100dc2011-01-07 01:57:07 +0000629 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +0000630 if (bytes_read != dst_len)
631 {
632 if (error.Success())
633 {
634 if (bytes_read == 0)
Greg Clayton70436352010-06-30 23:03:03 +0000635 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000636 else
Greg Clayton70436352010-06-30 23:03:03 +0000637 error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000638 }
639 }
Greg Clayton70436352010-06-30 23:03:03 +0000640 if (bytes_read)
641 return bytes_read;
642 // If the address is not section offset we have an address that
643 // doesn't resolve to any address in any currently loaded shared
644 // libaries and we failed to read memory so there isn't anything
645 // more we can do. If it is section offset, we might be able to
646 // read cached memory from the object file.
647 if (!resolved_addr.IsSectionOffset())
648 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000649 }
Chris Lattner24943d22010-06-08 16:52:24 +0000650 }
Greg Clayton70436352010-06-30 23:03:03 +0000651
Greg Clayton26100dc2011-01-07 01:57:07 +0000652 if (!prefer_file_cache)
Greg Clayton70436352010-06-30 23:03:03 +0000653 {
Greg Clayton26100dc2011-01-07 01:57:07 +0000654 // If we didn't already try and read from the object file cache, then
655 // try it after failing to read from the process.
656 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Clayton70436352010-06-30 23:03:03 +0000657 }
658 return 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000659}
660
661
662ModuleSP
663Target::GetSharedModule
664(
665 const FileSpec& file_spec,
666 const ArchSpec& arch,
Greg Clayton0467c782011-02-04 18:53:10 +0000667 const lldb_private::UUID *uuid_ptr,
Chris Lattner24943d22010-06-08 16:52:24 +0000668 const ConstString *object_name,
669 off_t object_offset,
670 Error *error_ptr
671)
672{
673 // Don't pass in the UUID so we can tell if we have a stale value in our list
674 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
675 bool did_create_module = false;
676 ModuleSP module_sp;
677
Chris Lattner24943d22010-06-08 16:52:24 +0000678 Error error;
679
Greg Clayton24bc5d92011-03-30 18:16:51 +0000680 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner24943d22010-06-08 16:52:24 +0000681 if (m_image_search_paths.GetSize())
682 {
683 FileSpec transformed_spec;
684 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
685 {
686 transformed_spec.GetFilename() = file_spec.GetFilename();
687 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
688 }
689 }
690
Greg Clayton24bc5d92011-03-30 18:16:51 +0000691 // The platform is responsible for finding and caching an appropriate
692 // module in the shared module cache.
693 if (m_platform_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000694 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000695 FileSpec platform_file_spec;
696 error = m_platform_sp->GetSharedModule (file_spec,
697 arch,
698 uuid_ptr,
699 object_name,
700 object_offset,
701 module_sp,
702 &old_module_sp,
703 &did_create_module);
704 }
705 else
706 {
707 error.SetErrorString("no platform is currently set");
Chris Lattner24943d22010-06-08 16:52:24 +0000708 }
709
Greg Clayton24bc5d92011-03-30 18:16:51 +0000710 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner24943d22010-06-08 16:52:24 +0000711 if (module_sp)
712 {
713 m_images.Append (module_sp);
714 if (did_create_module)
715 {
716 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
717 ModuleUpdated(old_module_sp, module_sp);
718 else
719 ModuleAdded(module_sp);
720 }
721 }
722 if (error_ptr)
723 *error_ptr = error;
724 return module_sp;
725}
726
727
728Target *
729Target::CalculateTarget ()
730{
731 return this;
732}
733
734Process *
735Target::CalculateProcess ()
736{
737 return NULL;
738}
739
740Thread *
741Target::CalculateThread ()
742{
743 return NULL;
744}
745
746StackFrame *
747Target::CalculateStackFrame ()
748{
749 return NULL;
750}
751
752void
Greg Claytona830adb2010-10-04 01:05:56 +0000753Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000754{
755 exe_ctx.target = this;
756 exe_ctx.process = NULL; // Do NOT fill in process...
757 exe_ctx.thread = NULL;
758 exe_ctx.frame = NULL;
759}
760
761PathMappingList &
762Target::GetImageSearchPathList ()
763{
764 return m_image_search_paths;
765}
766
767void
768Target::ImageSearchPathsChanged
769(
770 const PathMappingList &path_list,
771 void *baton
772)
773{
774 Target *target = (Target *)baton;
775 if (target->m_images.GetSize() > 1)
776 {
777 ModuleSP exe_module_sp (target->GetExecutableModule());
778 if (exe_module_sp)
779 {
780 target->m_images.Clear();
781 target->SetExecutableModule (exe_module_sp, true);
782 }
783 }
784}
785
786ClangASTContext *
787Target::GetScratchClangASTContext()
788{
789 return m_scratch_ast_context_ap.get();
790}
Caroline Tice5bc8c972010-09-20 20:44:43 +0000791
Greg Clayton990de7b2010-11-18 23:32:35 +0000792void
Caroline Tice2a456812011-03-10 22:14:10 +0000793Target::SettingsInitialize ()
Caroline Tice5bc8c972010-09-20 20:44:43 +0000794{
Greg Clayton990de7b2010-11-18 23:32:35 +0000795 UserSettingsControllerSP &usc = GetSettingsController();
796 usc.reset (new SettingsController);
797 UserSettingsController::InitializeSettingsController (usc,
798 SettingsController::global_settings_table,
799 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +0000800
801 // Now call SettingsInitialize() on each 'child' setting of Target
802 Process::SettingsInitialize ();
Greg Clayton990de7b2010-11-18 23:32:35 +0000803}
Caroline Tice5bc8c972010-09-20 20:44:43 +0000804
Greg Clayton990de7b2010-11-18 23:32:35 +0000805void
Caroline Tice2a456812011-03-10 22:14:10 +0000806Target::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +0000807{
Caroline Tice2a456812011-03-10 22:14:10 +0000808
809 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
810
811 Process::SettingsTerminate ();
812
813 // Now terminate Target Settings.
814
Greg Clayton990de7b2010-11-18 23:32:35 +0000815 UserSettingsControllerSP &usc = GetSettingsController();
816 UserSettingsController::FinalizeSettingsController (usc);
817 usc.reset();
818}
Caroline Tice5bc8c972010-09-20 20:44:43 +0000819
Greg Clayton990de7b2010-11-18 23:32:35 +0000820UserSettingsControllerSP &
821Target::GetSettingsController ()
822{
823 static UserSettingsControllerSP g_settings_controller;
Caroline Tice5bc8c972010-09-20 20:44:43 +0000824 return g_settings_controller;
825}
826
827ArchSpec
828Target::GetDefaultArchitecture ()
829{
Greg Clayton940b1032011-02-23 00:35:02 +0000830 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
831
832 if (settings_controller_sp)
833 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
834 return ArchSpec();
Caroline Tice5bc8c972010-09-20 20:44:43 +0000835}
836
837void
Greg Clayton940b1032011-02-23 00:35:02 +0000838Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Tice5bc8c972010-09-20 20:44:43 +0000839{
Greg Clayton940b1032011-02-23 00:35:02 +0000840 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
841
842 if (settings_controller_sp)
843 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Tice5bc8c972010-09-20 20:44:43 +0000844}
845
Greg Claytona830adb2010-10-04 01:05:56 +0000846Target *
847Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
848{
849 // The target can either exist in the "process" of ExecutionContext, or in
850 // the "target_sp" member of SymbolContext. This accessor helper function
851 // will get the target from one of these locations.
852
853 Target *target = NULL;
854 if (sc_ptr != NULL)
855 target = sc_ptr->target_sp.get();
856 if (target == NULL)
857 {
858 if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
859 target = &exe_ctx_ptr->process->GetTarget();
860 }
861 return target;
862}
863
864
Caroline Tice1ebef442010-09-27 00:30:10 +0000865void
866Target::UpdateInstanceName ()
867{
868 StreamString sstr;
869
870 ModuleSP module_sp = GetExecutableModule();
871 if (module_sp)
872 {
Greg Claytonbf6e2102010-10-27 02:06:37 +0000873 sstr.Printf ("%s_%s",
874 module_sp->GetFileSpec().GetFilename().AsCString(),
Greg Clayton940b1032011-02-23 00:35:02 +0000875 module_sp->GetArchitecture().GetArchitectureName());
Greg Claytonc0c1b0c2010-11-19 03:46:01 +0000876 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(),
877 sstr.GetData());
Caroline Tice1ebef442010-09-27 00:30:10 +0000878 }
879}
880
Sean Callanan77e93942010-10-29 00:29:03 +0000881const char *
882Target::GetExpressionPrefixContentsAsCString ()
883{
Greg Claytonff44ab42011-04-23 02:04:55 +0000884 if (m_expr_prefix_contents_sp)
885 return (const char *)m_expr_prefix_contents_sp->GetBytes();
886 return NULL;
Sean Callanan77e93942010-10-29 00:29:03 +0000887}
888
Greg Clayton427f2902010-12-14 02:59:59 +0000889ExecutionResults
890Target::EvaluateExpression
891(
892 const char *expr_cstr,
893 StackFrame *frame,
894 bool unwind_on_error,
Sean Callanan6a925532011-01-13 08:53:35 +0000895 bool keep_in_memory,
Jim Ingham10de7d12011-05-04 03:43:18 +0000896 lldb::DynamicValueType use_dynamic,
Greg Clayton427f2902010-12-14 02:59:59 +0000897 lldb::ValueObjectSP &result_valobj_sp
898)
899{
900 ExecutionResults execution_results = eExecutionSetupError;
901
902 result_valobj_sp.reset();
903
904 ExecutionContext exe_ctx;
905 if (frame)
906 {
907 frame->CalculateExecutionContext(exe_ctx);
Greg Claytonc3b61d22010-12-15 05:08:08 +0000908 Error error;
Greg Claytonc67efa42011-01-20 19:27:18 +0000909 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
910 StackFrame::eExpressionPathOptionsNoFragileObjcIvar;
Jim Ingham10de7d12011-05-04 03:43:18 +0000911 lldb::VariableSP var_sp;
912 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
913 use_dynamic,
914 expr_path_options,
915 var_sp,
916 error);
Greg Clayton427f2902010-12-14 02:59:59 +0000917 }
918 else if (m_process_sp)
919 {
920 m_process_sp->CalculateExecutionContext(exe_ctx);
921 }
922 else
923 {
924 CalculateExecutionContext(exe_ctx);
925 }
926
927 if (result_valobj_sp)
928 {
929 execution_results = eExecutionCompleted;
930 // We got a result from the frame variable expression path above...
931 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
932
933 lldb::ValueObjectSP const_valobj_sp;
934
935 // Check in case our value is already a constant value
936 if (result_valobj_sp->GetIsConstant())
937 {
938 const_valobj_sp = result_valobj_sp;
939 const_valobj_sp->SetName (persistent_variable_name);
940 }
941 else
Jim Inghame41494a2011-04-16 00:01:13 +0000942 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000943 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000944 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000945 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000946 if (dynamic_sp)
947 result_valobj_sp = dynamic_sp;
948 }
949
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000950 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Inghame41494a2011-04-16 00:01:13 +0000951 }
Greg Clayton427f2902010-12-14 02:59:59 +0000952
Sean Callanan6a925532011-01-13 08:53:35 +0000953 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
954
Greg Clayton427f2902010-12-14 02:59:59 +0000955 result_valobj_sp = const_valobj_sp;
956
Sean Callanan6a925532011-01-13 08:53:35 +0000957 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
958 assert (clang_expr_variable_sp.get());
959
960 // Set flags and live data as appropriate
961
962 const Value &result_value = live_valobj_sp->GetValue();
963
964 switch (result_value.GetValueType())
965 {
966 case Value::eValueTypeHostAddress:
967 case Value::eValueTypeFileAddress:
968 // we don't do anything with these for now
969 break;
970 case Value::eValueTypeScalar:
971 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
972 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
973 break;
974 case Value::eValueTypeLoadAddress:
975 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
976 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
977 break;
978 }
Greg Clayton427f2902010-12-14 02:59:59 +0000979 }
980 else
981 {
982 // Make sure we aren't just trying to see the value of a persistent
983 // variable (something like "$0")
Greg Claytona875b642011-01-09 21:07:35 +0000984 lldb::ClangExpressionVariableSP persistent_var_sp;
985 // Only check for persistent variables the expression starts with a '$'
986 if (expr_cstr[0] == '$')
987 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
988
Greg Clayton427f2902010-12-14 02:59:59 +0000989 if (persistent_var_sp)
990 {
991 result_valobj_sp = persistent_var_sp->GetValueObject ();
992 execution_results = eExecutionCompleted;
993 }
994 else
995 {
996 const char *prefix = GetExpressionPrefixContentsAsCString();
997
998 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan6a925532011-01-13 08:53:35 +0000999 unwind_on_error,
Greg Clayton427f2902010-12-14 02:59:59 +00001000 expr_cstr,
1001 prefix,
1002 result_valobj_sp);
1003 }
1004 }
1005 return execution_results;
1006}
1007
Jim Inghamd60d94a2011-03-11 03:53:59 +00001008lldb::user_id_t
1009Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1010{
1011 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1012 new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1013 m_stop_hooks[new_uid] = new_hook_sp;
1014 return new_uid;
1015}
1016
1017bool
1018Target::RemoveStopHookByID (lldb::user_id_t user_id)
1019{
1020 size_t num_removed;
1021 num_removed = m_stop_hooks.erase (user_id);
1022 if (num_removed == 0)
1023 return false;
1024 else
1025 return true;
1026}
1027
1028void
1029Target::RemoveAllStopHooks ()
1030{
1031 m_stop_hooks.clear();
1032}
1033
1034Target::StopHookSP
1035Target::GetStopHookByID (lldb::user_id_t user_id)
1036{
1037 StopHookSP found_hook;
1038
1039 StopHookCollection::iterator specified_hook_iter;
1040 specified_hook_iter = m_stop_hooks.find (user_id);
1041 if (specified_hook_iter != m_stop_hooks.end())
1042 found_hook = (*specified_hook_iter).second;
1043 return found_hook;
1044}
1045
1046bool
1047Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1048{
1049 StopHookCollection::iterator specified_hook_iter;
1050 specified_hook_iter = m_stop_hooks.find (user_id);
1051 if (specified_hook_iter == m_stop_hooks.end())
1052 return false;
1053
1054 (*specified_hook_iter).second->SetIsActive (active_state);
1055 return true;
1056}
1057
1058void
1059Target::SetAllStopHooksActiveState (bool active_state)
1060{
1061 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1062 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1063 {
1064 (*pos).second->SetIsActive (active_state);
1065 }
1066}
1067
1068void
1069Target::RunStopHooks ()
1070{
1071 if (!m_process_sp)
1072 return;
1073
1074 if (m_stop_hooks.empty())
1075 return;
1076
1077 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1078
1079 // If there aren't any active stop hooks, don't bother either:
1080 bool any_active_hooks = false;
1081 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1082 {
1083 if ((*pos).second->IsActive())
1084 {
1085 any_active_hooks = true;
1086 break;
1087 }
1088 }
1089 if (!any_active_hooks)
1090 return;
1091
1092 CommandReturnObject result;
1093
1094 std::vector<ExecutionContext> exc_ctx_with_reasons;
1095 std::vector<SymbolContext> sym_ctx_with_reasons;
1096
1097 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1098 size_t num_threads = cur_threadlist.GetSize();
1099 for (size_t i = 0; i < num_threads; i++)
1100 {
1101 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1102 if (cur_thread_sp->ThreadStoppedForAReason())
1103 {
1104 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1105 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1106 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1107 }
1108 }
1109
1110 // If no threads stopped for a reason, don't run the stop-hooks.
1111 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1112 if (num_exe_ctx == 0)
1113 return;
1114
Caroline Tice4a348082011-05-02 20:41:46 +00001115 StreamSP output_stream (new StreamAsynchronousIO (m_debugger.GetCommandInterpreter(),
1116 CommandInterpreter::eBroadcastBitAsynchronousOutputData));
1117 StreamSP error_stream (new StreamAsynchronousIO (m_debugger.GetCommandInterpreter(),
1118 CommandInterpreter::eBroadcastBitAsynchronousErrorData));
1119 result.SetImmediateOutputStream (output_stream);
1120 result.SetImmediateErrorStream (error_stream);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001121
1122 bool keep_going = true;
1123 bool hooks_ran = false;
Jim Inghamc54840c2011-03-22 01:47:27 +00001124 bool print_hook_header;
1125 bool print_thread_header;
1126
1127 if (num_exe_ctx == 1)
1128 print_thread_header = false;
1129 else
1130 print_thread_header = true;
1131
1132 if (m_stop_hooks.size() == 1)
1133 print_hook_header = false;
1134 else
1135 print_hook_header = true;
1136
Jim Inghamd60d94a2011-03-11 03:53:59 +00001137 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1138 {
1139 // result.Clear();
1140 StopHookSP cur_hook_sp = (*pos).second;
1141 if (!cur_hook_sp->IsActive())
1142 continue;
1143
1144 bool any_thread_matched = false;
1145 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1146 {
1147 if ((cur_hook_sp->GetSpecifier () == NULL
1148 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1149 && (cur_hook_sp->GetThreadSpecifier() == NULL
1150 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].thread)))
1151 {
1152 if (!hooks_ran)
1153 {
Jim Inghamc54840c2011-03-22 01:47:27 +00001154 result.AppendMessage("\n** Stop Hooks **");
Jim Inghamd60d94a2011-03-11 03:53:59 +00001155 hooks_ran = true;
1156 }
Jim Inghamc54840c2011-03-22 01:47:27 +00001157 if (print_hook_header && !any_thread_matched)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001158 {
1159 result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
1160 any_thread_matched = true;
1161 }
1162
Jim Inghamc54840c2011-03-22 01:47:27 +00001163 if (print_thread_header)
1164 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].thread->GetIndexID());
Jim Inghamd60d94a2011-03-11 03:53:59 +00001165
1166 bool stop_on_continue = true;
1167 bool stop_on_error = true;
1168 bool echo_commands = false;
1169 bool print_results = true;
1170 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton24bc5d92011-03-30 18:16:51 +00001171 &exc_ctx_with_reasons[i],
1172 stop_on_continue,
1173 stop_on_error,
1174 echo_commands,
1175 print_results,
1176 result);
Jim Inghamd60d94a2011-03-11 03:53:59 +00001177
1178 // If the command started the target going again, we should bag out of
1179 // running the stop hooks.
Greg Clayton24bc5d92011-03-30 18:16:51 +00001180 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1181 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Inghamd60d94a2011-03-11 03:53:59 +00001182 {
1183 result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
1184 keep_going = false;
1185 }
1186 }
1187 }
1188 }
1189 if (hooks_ran)
1190 result.AppendMessage ("\n** End Stop Hooks **\n");
Caroline Tice4a348082011-05-02 20:41:46 +00001191
1192 result.GetImmediateOutputStream()->Flush();
1193 result.GetImmediateErrorStream()->Flush();
Jim Inghamd60d94a2011-03-11 03:53:59 +00001194}
1195
1196//--------------------------------------------------------------
1197// class Target::StopHook
1198//--------------------------------------------------------------
1199
1200
1201Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1202 UserID (uid),
1203 m_target_sp (target_sp),
Jim Inghamd60d94a2011-03-11 03:53:59 +00001204 m_commands (),
1205 m_specifier_sp (),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001206 m_thread_spec_ap(NULL),
1207 m_active (true)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001208{
1209}
1210
1211Target::StopHook::StopHook (const StopHook &rhs) :
1212 UserID (rhs.GetID()),
1213 m_target_sp (rhs.m_target_sp),
1214 m_commands (rhs.m_commands),
1215 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilsondbeb3e12011-04-11 19:41:40 +00001216 m_thread_spec_ap (NULL),
1217 m_active (rhs.m_active)
Jim Inghamd60d94a2011-03-11 03:53:59 +00001218{
1219 if (rhs.m_thread_spec_ap.get() != NULL)
1220 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1221}
1222
1223
1224Target::StopHook::~StopHook ()
1225{
1226}
1227
1228void
1229Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1230{
1231 m_thread_spec_ap.reset (specifier);
1232}
1233
1234
1235void
1236Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1237{
1238 int indent_level = s->GetIndentLevel();
1239
1240 s->SetIndentLevel(indent_level + 2);
1241
1242 s->Printf ("Hook: %d\n", GetID());
1243 if (m_active)
1244 s->Indent ("State: enabled\n");
1245 else
1246 s->Indent ("State: disabled\n");
1247
1248 if (m_specifier_sp)
1249 {
1250 s->Indent();
1251 s->PutCString ("Specifier:\n");
1252 s->SetIndentLevel (indent_level + 4);
1253 m_specifier_sp->GetDescription (s, level);
1254 s->SetIndentLevel (indent_level + 2);
1255 }
1256
1257 if (m_thread_spec_ap.get() != NULL)
1258 {
1259 StreamString tmp;
1260 s->Indent("Thread:\n");
1261 m_thread_spec_ap->GetDescription (&tmp, level);
1262 s->SetIndentLevel (indent_level + 4);
1263 s->Indent (tmp.GetData());
1264 s->PutCString ("\n");
1265 s->SetIndentLevel (indent_level + 2);
1266 }
1267
1268 s->Indent ("Commands: \n");
1269 s->SetIndentLevel (indent_level + 4);
1270 uint32_t num_commands = m_commands.GetSize();
1271 for (uint32_t i = 0; i < num_commands; i++)
1272 {
1273 s->Indent(m_commands.GetStringAtIndex(i));
1274 s->PutCString ("\n");
1275 }
1276 s->SetIndentLevel (indent_level);
1277}
1278
1279
Caroline Tice5bc8c972010-09-20 20:44:43 +00001280//--------------------------------------------------------------
1281// class Target::SettingsController
1282//--------------------------------------------------------------
1283
1284Target::SettingsController::SettingsController () :
1285 UserSettingsController ("target", Debugger::GetSettingsController()),
1286 m_default_architecture ()
1287{
1288 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1289 InstanceSettings::GetDefaultName().AsCString()));
1290}
1291
1292Target::SettingsController::~SettingsController ()
1293{
1294}
1295
1296lldb::InstanceSettingsSP
1297Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1298{
Greg Claytonc0c1b0c2010-11-19 03:46:01 +00001299 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1300 false,
1301 instance_name);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001302 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1303 return new_settings_sp;
1304}
1305
Caroline Tice5bc8c972010-09-20 20:44:43 +00001306
Jim Inghame41494a2011-04-16 00:01:13 +00001307#define TSC_DEFAULT_ARCH "default-arch"
1308#define TSC_EXPR_PREFIX "expr-prefix"
Jim Inghame41494a2011-04-16 00:01:13 +00001309#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
Greg Clayton17cd9952011-04-22 03:55:06 +00001310#define TSC_SKIP_PROLOGUE "skip-prologue"
Greg Claytonff44ab42011-04-23 02:04:55 +00001311#define TSC_SOURCE_MAP "source-map"
Greg Claytond284b662011-02-18 01:44:25 +00001312
1313
1314static const ConstString &
1315GetSettingNameForDefaultArch ()
1316{
1317 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytond284b662011-02-18 01:44:25 +00001318 return g_const_string;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001319}
1320
Greg Claytond284b662011-02-18 01:44:25 +00001321static const ConstString &
1322GetSettingNameForExpressionPrefix ()
1323{
1324 static ConstString g_const_string (TSC_EXPR_PREFIX);
1325 return g_const_string;
1326}
1327
1328static const ConstString &
Jim Inghame41494a2011-04-16 00:01:13 +00001329GetSettingNameForPreferDynamicValue ()
1330{
1331 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
1332 return g_const_string;
1333}
1334
Greg Claytonff44ab42011-04-23 02:04:55 +00001335static const ConstString &
1336GetSettingNameForSourcePathMap ()
1337{
1338 static ConstString g_const_string (TSC_SOURCE_MAP);
1339 return g_const_string;
1340}
Greg Claytond284b662011-02-18 01:44:25 +00001341
Greg Clayton17cd9952011-04-22 03:55:06 +00001342static const ConstString &
1343GetSettingNameForSkipPrologue ()
1344{
1345 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
1346 return g_const_string;
1347}
1348
1349
1350
Caroline Tice5bc8c972010-09-20 20:44:43 +00001351bool
1352Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1353 const char *index_value,
1354 const char *value,
1355 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001356 const VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00001357 Error&err)
1358{
Greg Claytond284b662011-02-18 01:44:25 +00001359 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00001360 {
Greg Claytonf15996e2011-04-07 22:46:35 +00001361 m_default_architecture.SetTriple (value, NULL);
Greg Clayton940b1032011-02-23 00:35:02 +00001362 if (!m_default_architecture.IsValid())
1363 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001364 }
1365 return true;
1366}
1367
1368
1369bool
1370Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1371 StringList &value,
1372 Error &err)
1373{
Greg Claytond284b662011-02-18 01:44:25 +00001374 if (var_name == GetSettingNameForDefaultArch())
Caroline Tice5bc8c972010-09-20 20:44:43 +00001375 {
Greg Claytonbf6e2102010-10-27 02:06:37 +00001376 // If the arch is invalid (the default), don't show a string for it
1377 if (m_default_architecture.IsValid())
Greg Clayton940b1032011-02-23 00:35:02 +00001378 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Tice5bc8c972010-09-20 20:44:43 +00001379 return true;
1380 }
1381 else
1382 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1383
1384 return false;
1385}
1386
1387//--------------------------------------------------------------
1388// class TargetInstanceSettings
1389//--------------------------------------------------------------
1390
Greg Clayton638351a2010-12-04 00:10:17 +00001391TargetInstanceSettings::TargetInstanceSettings
1392(
1393 UserSettingsController &owner,
1394 bool live_instance,
1395 const char *name
1396) :
Greg Claytond284b662011-02-18 01:44:25 +00001397 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Claytonff44ab42011-04-23 02:04:55 +00001398 m_expr_prefix_file (),
1399 m_expr_prefix_contents_sp (),
Jim Ingham10de7d12011-05-04 03:43:18 +00001400 m_prefer_dynamic_value (2),
Greg Claytonff44ab42011-04-23 02:04:55 +00001401 m_skip_prologue (true, true),
1402 m_source_map (NULL, NULL)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001403{
1404 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1405 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1406 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1407 // This is true for CreateInstanceName() too.
1408
1409 if (GetInstanceName () == InstanceSettings::InvalidName())
1410 {
1411 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1412 m_owner.RegisterInstanceSettings (this);
1413 }
1414
1415 if (live_instance)
1416 {
1417 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1418 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001419 }
1420}
1421
1422TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Claytonff44ab42011-04-23 02:04:55 +00001423 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
1424 m_expr_prefix_file (rhs.m_expr_prefix_file),
1425 m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
1426 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
1427 m_skip_prologue (rhs.m_skip_prologue),
1428 m_source_map (rhs.m_source_map)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001429{
1430 if (m_instance_name != InstanceSettings::GetDefaultName())
1431 {
1432 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1433 CopyInstanceSettings (pending_settings,false);
Caroline Tice5bc8c972010-09-20 20:44:43 +00001434 }
1435}
1436
1437TargetInstanceSettings::~TargetInstanceSettings ()
1438{
1439}
1440
1441TargetInstanceSettings&
1442TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
1443{
1444 if (this != &rhs)
1445 {
1446 }
1447
1448 return *this;
1449}
1450
Caroline Tice5bc8c972010-09-20 20:44:43 +00001451void
1452TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1453 const char *index_value,
1454 const char *value,
1455 const ConstString &instance_name,
1456 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001457 VarSetOperationType op,
Caroline Tice5bc8c972010-09-20 20:44:43 +00001458 Error &err,
1459 bool pending)
1460{
Greg Claytond284b662011-02-18 01:44:25 +00001461 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00001462 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001463 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
1464 if (err.Success())
Sean Callanan77e93942010-10-29 00:29:03 +00001465 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001466 switch (op)
Sean Callanan77e93942010-10-29 00:29:03 +00001467 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001468 default:
1469 break;
1470 case eVarSetOperationAssign:
1471 case eVarSetOperationAppend:
Sean Callanan77e93942010-10-29 00:29:03 +00001472 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001473 if (!m_expr_prefix_file.GetCurrentValue().Exists())
1474 {
1475 err.SetErrorToGenericError ();
1476 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
1477 return;
1478 }
1479
1480 m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
1481
1482 if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
1483 {
1484 err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
1485 m_expr_prefix_contents_sp.reset();
1486 }
Sean Callanan77e93942010-10-29 00:29:03 +00001487 }
Greg Claytonff44ab42011-04-23 02:04:55 +00001488 break;
1489 case eVarSetOperationClear:
1490 m_expr_prefix_contents_sp.reset();
Sean Callanan77e93942010-10-29 00:29:03 +00001491 }
Sean Callanan77e93942010-10-29 00:29:03 +00001492 }
1493 }
Jim Inghame41494a2011-04-16 00:01:13 +00001494 else if (var_name == GetSettingNameForPreferDynamicValue())
1495 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001496 int new_value;
1497 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
1498 if (err.Success())
1499 m_prefer_dynamic_value = new_value;
Greg Clayton17cd9952011-04-22 03:55:06 +00001500 }
1501 else if (var_name == GetSettingNameForSkipPrologue())
1502 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001503 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
1504 }
1505 else if (var_name == GetSettingNameForSourcePathMap ())
1506 {
1507 switch (op)
1508 {
1509 case eVarSetOperationReplace:
1510 case eVarSetOperationInsertBefore:
1511 case eVarSetOperationInsertAfter:
1512 case eVarSetOperationRemove:
1513 default:
1514 break;
1515 case eVarSetOperationAssign:
1516 m_source_map.Clear(true);
1517 // Fall through to append....
1518 case eVarSetOperationAppend:
1519 {
1520 Args args(value);
1521 const uint32_t argc = args.GetArgumentCount();
1522 if (argc & 1 || argc == 0)
1523 {
1524 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
1525 }
1526 else
1527 {
1528 char resolved_new_path[PATH_MAX];
1529 FileSpec file_spec;
1530 const char *old_path;
1531 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
1532 {
1533 const char *new_path = args.GetArgumentAtIndex(idx+1);
1534 assert (new_path); // We have an even number of paths, this shouldn't happen!
1535
1536 file_spec.SetFile(new_path, true);
1537 if (file_spec.Exists())
1538 {
1539 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
1540 {
1541 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
1542 return;
1543 }
1544 }
1545 else
1546 {
1547 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
1548 return;
1549 }
1550 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
1551 }
1552 }
1553 }
1554 break;
1555
1556 case eVarSetOperationClear:
1557 m_source_map.Clear(true);
1558 break;
1559 }
Jim Inghame41494a2011-04-16 00:01:13 +00001560 }
Caroline Tice5bc8c972010-09-20 20:44:43 +00001561}
1562
1563void
Greg Claytond284b662011-02-18 01:44:25 +00001564TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001565{
Sean Callanan77e93942010-10-29 00:29:03 +00001566 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
1567
1568 if (!new_settings_ptr)
1569 return;
1570
Greg Claytonff44ab42011-04-23 02:04:55 +00001571 m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
1572 m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
1573 m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
1574 m_skip_prologue = new_settings_ptr->m_skip_prologue;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001575}
1576
Caroline Ticebcb5b452010-09-20 21:37:42 +00001577bool
Caroline Tice5bc8c972010-09-20 20:44:43 +00001578TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1579 const ConstString &var_name,
1580 StringList &value,
Caroline Ticebcb5b452010-09-20 21:37:42 +00001581 Error *err)
Caroline Tice5bc8c972010-09-20 20:44:43 +00001582{
Greg Claytond284b662011-02-18 01:44:25 +00001583 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan77e93942010-10-29 00:29:03 +00001584 {
Greg Claytonff44ab42011-04-23 02:04:55 +00001585 char path[PATH_MAX];
1586 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
1587 if (path_len > 0)
1588 value.AppendString (path, path_len);
Sean Callanan77e93942010-10-29 00:29:03 +00001589 }
Jim Inghame41494a2011-04-16 00:01:13 +00001590 else if (var_name == GetSettingNameForPreferDynamicValue())
1591 {
Jim Ingham10de7d12011-05-04 03:43:18 +00001592 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Inghame41494a2011-04-16 00:01:13 +00001593 }
Greg Clayton17cd9952011-04-22 03:55:06 +00001594 else if (var_name == GetSettingNameForSkipPrologue())
1595 {
1596 if (m_skip_prologue)
1597 value.AppendString ("true");
1598 else
1599 value.AppendString ("false");
1600 }
Greg Claytonff44ab42011-04-23 02:04:55 +00001601 else if (var_name == GetSettingNameForSourcePathMap ())
1602 {
1603 }
Sean Callanan77e93942010-10-29 00:29:03 +00001604 else
1605 {
1606 if (err)
1607 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1608 return false;
1609 }
1610
1611 return true;
Caroline Tice5bc8c972010-09-20 20:44:43 +00001612}
1613
1614const ConstString
1615TargetInstanceSettings::CreateInstanceName ()
1616{
Caroline Tice5bc8c972010-09-20 20:44:43 +00001617 StreamString sstr;
Caroline Tice1ebef442010-09-27 00:30:10 +00001618 static int instance_count = 1;
1619
Caroline Tice5bc8c972010-09-20 20:44:43 +00001620 sstr.Printf ("target_%d", instance_count);
1621 ++instance_count;
1622
1623 const ConstString ret_val (sstr.GetData());
1624 return ret_val;
1625}
1626
1627//--------------------------------------------------
1628// Target::SettingsController Variable Tables
1629//--------------------------------------------------
Jim Ingham10de7d12011-05-04 03:43:18 +00001630OptionEnumValueElement
1631TargetInstanceSettings::g_dynamic_value_types[] =
1632{
1633{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
1634{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
1635{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
1636{ 0, NULL, NULL }
1637};
Caroline Tice5bc8c972010-09-20 20:44:43 +00001638
1639SettingEntry
1640Target::SettingsController::global_settings_table[] =
1641{
Greg Claytond284b662011-02-18 01:44:25 +00001642 // var-name var-type default enum init'd hidden help-text
1643 // ================= ================== =========== ==== ====== ====== =========================================================================
1644 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
1645 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
1646};
1647
Caroline Tice5bc8c972010-09-20 20:44:43 +00001648SettingEntry
1649Target::SettingsController::instance_settings_table[] =
1650{
Jim Ingham10de7d12011-05-04 03:43:18 +00001651 // var-name var-type default enum init'd hidden help-text
1652 // ================= ================== =============== ======================= ====== ====== =========================================================================
1653 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
1654 { TSC_PREFER_DYNAMIC, eSetVarTypeEnum , "no-run-target", g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
1655 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean ,"true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
1656 { TSC_SOURCE_MAP , eSetVarTypeArray ,NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
1657 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Tice5bc8c972010-09-20 20:44:43 +00001658};